[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31956] trunk/blender/source/blender: - bone roll now in degrees not radians.

Campbell Barton ideasman42 at gmail.com
Thu Sep 16 06:19:44 CEST 2010


Revision: 31956
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31956
Author:   campbellbarton
Date:     2010-09-16 06:19:22 +0200 (Thu, 16 Sep 2010)

Log Message:
-----------
- bone roll now in degrees not radians.
- rna buttons with units set now use the units base value for snapping. 
- bone head/tail radius could be set negative.

matt: removed a check in ui_is_but_unit() which made angle buttons return false, what was this for?

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_unit.h
    trunk/blender/source/blender/blenkernel/intern/unit.c
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/makesrna/intern/rna_armature.c
    trunk/blender/source/blender/makesrna/intern/rna_object.c

Modified: trunk/blender/source/blender/blenkernel/BKE_unit.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_unit.h	2010-09-15 23:19:21 UTC (rev 31955)
+++ trunk/blender/source/blender/blenkernel/BKE_unit.h	2010-09-16 04:19:22 UTC (rev 31956)
@@ -45,6 +45,9 @@
 /* base scale for these units */
 double bUnit_BaseScalar(int system, int type);
 
+/* return true is the unit system exists */
+int bUnit_IsValid(int system, int type);
+
 /* loop over scales, coudl add names later */
 //double bUnit_Iter(void **unit, char **name, int system, int type);
 
@@ -63,6 +66,7 @@
 #define 	B_UNIT_TIME 6
 #define 	B_UNIT_VELOCITY 7
 #define 	B_UNIT_ACCELERATION 8
+#define 	B_UNIT_MAXDEF 9
 
 #ifdef __cplusplus
 }

Modified: trunk/blender/source/blender/blenkernel/intern/unit.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/unit.c	2010-09-15 23:19:21 UTC (rev 31955)
+++ trunk/blender/source/blender/blenkernel/intern/unit.c	2010-09-16 04:19:22 UTC (rev 31956)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
+#include "BKE_unit.h"
+
 #ifdef WIN32
 #define _USE_MATH_DEFINES
 #endif
@@ -31,6 +33,7 @@
 
 #include "BLI_winstuff.h"
 
+
 #define TEMP_STR_SIZE 256
 
 #define SEP_CHR		'#'
@@ -127,7 +130,8 @@
 };
 static struct bUnitCollection buNaturalRotCollection = {buNaturalRotDef, 0, 0, sizeof(buNaturalRotDef)/sizeof(bUnitDef)};
 
-#define UNIT_SYSTEM_MAX 3
+#define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / 8) / sizeof(void *)) - 1)
+
 static struct bUnitCollection *bUnitSystems[][8] = {
 	{0,0,0,0,0,&buNaturalRotCollection,&buNaturalTimeCollecton,0},
 	{0,&buMetricLenCollecton, 0,0,0, &buNaturalRotCollection, &buNaturalTimeCollecton,0}, /* metric */
@@ -135,6 +139,8 @@
 	{0,0,0,0,0,0,0,0}
 };
 
+
+
 /* internal, has some option not exposed */
 static bUnitCollection *unit_get_system(int system, int type)
 {
@@ -459,7 +465,7 @@
 		bUnitCollection *usys_iter;
 		int system_iter;
 
-		for(system_iter= 0; system_iter<UNIT_SYSTEM_MAX; system_iter++) {
+		for(system_iter= 0; system_iter<UNIT_SYSTEM_TOT; system_iter++) {
 			if (system_iter != system) {
 				usys_iter= unit_get_system(system_iter, type);
 				if (usys_iter) {
@@ -610,6 +616,12 @@
 }
 
 /* external access */
+int bUnit_IsValid(int system, int type)
+{
+	return !(type < 0 || type >= B_UNIT_MAXDEF || system < 0 || system > UNIT_SYSTEM_TOT);
+}
+
+
 void bUnit_GetSystem(void **usys_pt, int *len, int system, int type)
 {
 	bUnitCollection *usys = unit_get_system(system, type);

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2010-09-15 23:19:21 UTC (rev 31955)
+++ trunk/blender/source/blender/editors/interface/interface.c	2010-09-16 04:19:22 UTC (rev 31956)
@@ -1234,11 +1234,13 @@
 	
 	if(but->rnaprop==NULL)
 		return 0;
-	
+
 	unit_type = RNA_SUBTYPE_UNIT(RNA_property_subtype(but->rnaprop));
-	
+
+#if 0 // removed so angle buttons get correct snapping
 	if (scene->unit.flag & USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION)
 		return 0;
+#endif
 	
 	/* for now disable time unit conversion */	
 	if (unit_type == PROP_UNIT_TIME)

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-09-15 23:19:21 UTC (rev 31955)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-09-16 04:19:22 UTC (rev 31956)
@@ -44,6 +44,7 @@
 #include "BKE_idprop.h"
 #include "BKE_report.h"
 #include "BKE_texture.h"
+#include "BKE_unit.h"
 
 #include "ED_screen.h"
 #include "ED_util.h"
@@ -2195,26 +2196,47 @@
 }
 
 /* var names match ui_numedit_but_NUM */
-static float ui_numedit_apply_snapf(float tempf, float softmin, float softmax, float softrange, int snap)
+static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, float softmax, float softrange, int snap)
 {
-	if(tempf==softmin || tempf==softmax)
-		return tempf;
+	if(tempf==softmin || tempf==softmax || snap==0) {
+		/* pass */
+	}
+	else {
+		float fac= 1.0f;
+		
+		if(ui_is_but_unit(but)) {
+			Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
+			int unit_type = RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop));
 
-	switch(snap) {
-	case 0:
-		break;
-	case 1:
-		if(tempf==softmin || tempf==softmax) { }
-		else if(softrange < 2.10) tempf= 0.1*floor(10*tempf);
-		else if(softrange < 21.0) tempf= floor(tempf);
-		else tempf= 10.0*floor(tempf/10.0);
-		break;
-	case 2:
-		if(tempf==softmin || tempf==softmax) { }
-		else if(softrange < 2.10) tempf= 0.01*floor(100.0*tempf);
-		else if(softrange < 21.0) tempf= 0.1*floor(10.0*tempf);
-		else tempf= floor(tempf);
-		break;
+			if(bUnit_IsValid(scene->unit.system, unit_type)) {
+				fac= (float)bUnit_BaseScalar(scene->unit.system, unit_type);
+				if(ELEM3(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) {
+					fac /= scene->unit.scale_length;
+				}
+			}
+		}
+
+		if(fac != 1.0f) {
+			/* snap in unit-space */
+			tempf /= fac;
+			softmin /= fac;
+			softmax /= fac;
+			softrange /= fac;
+		}
+
+		if(snap==1) {
+			if(softrange < 2.10) tempf= 0.1*floor(10*tempf);
+			else if(softrange < 21.0) tempf= floor(tempf);
+			else tempf= 10.0*floor(tempf/10.0);
+		}
+		else if(snap==2) {
+			if(softrange < 2.10) tempf= 0.01*floor(100.0*tempf);
+			else if(softrange < 21.0) tempf= 0.1*floor(10.0*tempf);
+			else tempf= floor(tempf);
+		}
+		
+		if(fac != 1.0f)
+			tempf *= fac;
 	}
 
 	return tempf;
@@ -2267,7 +2289,7 @@
 		if(ui_is_but_float(but)) {
 			fac *= 0.01*but->a1;
 			tempf = data->startvalue + ((mx - data->dragstartx) * fac);
-			tempf= ui_numedit_apply_snapf(tempf, softmin, softmax, softrange, snap);
+			tempf= ui_numedit_apply_snapf(but, tempf, softmin, softmax, softrange, snap);
 
 #if 1		/* fake moving the click start, nicer for dragging back after passing the limit */
 			if(tempf < softmin) {
@@ -2360,7 +2382,7 @@
 		}
 		else {
 			temp= 0;
-			tempf= ui_numedit_apply_snapf(tempf, softmin, softmax, softrange, snap);
+			tempf= ui_numedit_apply_snapf(but, tempf, softmin, softmax, softrange, snap);
 
 			CLAMP(tempf, softmin, softmax);
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_armature.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_armature.c	2010-09-15 23:19:21 UTC (rev 31955)
+++ trunk/blender/source/blender/makesrna/intern/rna_armature.c	2010-09-16 04:19:22 UTC (rev 31956)
@@ -23,6 +23,7 @@
  */
 
 #include <stdlib.h>
+#include <math.h>
 
 #include "RNA_define.h"
 
@@ -468,16 +469,18 @@
 	RNA_def_property_ui_text(prop, "Envelope Deform Weight", "Bone deformation weight (for Envelope deform only)");
 	RNA_def_property_update(prop, 0, "rna_Armature_update_data");
 	
-	prop= RNA_def_property(srna, "head_radius", PROP_FLOAT, PROP_NONE);
+	prop= RNA_def_property(srna, "head_radius", PROP_FLOAT, PROP_UNSIGNED);
 	if(editbone) RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
 	RNA_def_property_float_sdna(prop, NULL, "rad_head");
 	//RNA_def_property_range(prop, 0, 1000);  // XXX range is 0 to lim, where lim= 10000.0f*MAX2(1.0, view3d->grid);
+	RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Envelope Head Radius", "Radius of head of bone (for Envelope deform only)");
 	
-	prop= RNA_def_property(srna, "tail_radius", PROP_FLOAT, PROP_NONE);
+	prop= RNA_def_property(srna, "tail_radius", PROP_FLOAT, PROP_UNSIGNED);
 	if(editbone) RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
 	RNA_def_property_float_sdna(prop, NULL, "rad_tail");
 	//RNA_def_property_range(prop, 0, 1000);  // XXX range is 0 to lim, where lim= 10000.0f*MAX2(1.0, view3d->grid);
+	RNA_def_property_ui_range(prop, 0.01, 100, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Envelope Tail Radius", "Radius of tail of bone (for Envelope deform only)");
 	
 		/* b-bones deform settings */
@@ -601,8 +604,9 @@
 	RNA_def_property_ui_text(prop, "Parent", "Parent edit bone (in same Armature)");
 	RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
 	
-	prop= RNA_def_property(srna, "roll", PROP_FLOAT, PROP_NONE);
+	prop= RNA_def_property(srna, "roll", PROP_FLOAT, PROP_ANGLE);
 	RNA_def_property_float_sdna(prop, NULL, "roll");
+	RNA_def_property_ui_range(prop, -M_PI * 2, M_PI * 2, 0.1, 2);
 	RNA_def_property_ui_text(prop, "Roll", "Bone rotation around head-tail axis");
 	RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_object.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object.c	2010-09-15 23:19:21 UTC (rev 31955)
+++ trunk/blender/source/blender/makesrna/intern/rna_object.c	2010-09-16 04:19:22 UTC (rev 31956)
@@ -1748,6 +1748,7 @@
 	prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
 	RNA_def_property_float_sdna(prop, NULL, "loc");
 	RNA_def_property_editable_array_func(prop, "rna_Object_location_editable");
+	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
 	RNA_def_property_ui_text(prop, "Location", "Location of the object");
 	RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
 	
@@ -1785,6 +1786,7 @@
 	prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
 	RNA_def_property_float_sdna(prop, NULL, "size");
 	RNA_def_property_editable_array_func(prop, "rna_Object_scale_editable");
+	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
 	RNA_def_property_float_array_default(prop, default_scale);
 	RNA_def_property_ui_text(prop, "Scale", "Scaling of the object");
 	RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_internal_update");
@@ -1792,6 +1794,7 @@
 	prop= RNA_def_property(srna, "dimensions", PROP_FLOAT, PROP_XYZ_LENGTH);
 	RNA_def_property_array(prop, 3);
 	RNA_def_property_float_funcs(prop, "rna_Object_dimensions_get", "rna_Object_dimensions_set", NULL);
+	RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
 	RNA_def_property_ui_text(prop, "Dimensions", "Absolute bounding box dimensions of the object");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list