[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26235] trunk/blender/source: Radians -> Degrees (in UI)

Matt Ebb matt at mke3.net
Mon Jan 25 07:24:08 CET 2010


Revision: 26235
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26235
Author:   broken
Date:     2010-01-25 07:24:05 +0100 (Mon, 25 Jan 2010)

Log Message:
-----------
Radians -> Degrees (in UI)

Rotations are now stored internally as radians, while exposing degrees in the UI - 
in the graph editor and UI controls. This is done in two areas:
1) Using the unit system to convert RNA data to display as degrees in the UI controls
2) FCurves now use degrees for rotation, so you can edit in the graph editor what 
you see in the UI.

All rotation data is consistently accessible in DNA and RNA as radians, degrees are only 
used for the UI controls and graph editor.

This commit includes conversions will convert old files (stored data and also fcurve data) 
to the new units, hopefully everything should go smoothly!

Part of this also changes a few properties that were hard-coded as degrees before (such 
as IK pole angle and brush texture rotation) to also use the same consistent system of 
radians (dna/rna) and degrees (ui).

Thanks to Joshua for hints and review here too.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/anim_sys.c
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenkernel/intern/unit.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/ikplugin/intern/iksolver_plugin.c
    trunk/blender/source/blender/makesdna/DNA_anim_types.h
    trunk/blender/source/blender/makesrna/intern/rna_brush.c
    trunk/blender/source/blender/makesrna/intern/rna_constraint.c
    trunk/blender/source/blender/makesrna/intern/rna_curve.c
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
    trunk/blender/source/blender/makesrna/intern/rna_pose.c
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp

Modified: trunk/blender/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2010-01-24 23:18:48 UTC (rev 26234)
+++ trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2010-01-25 06:24:05 UTC (rev 26235)
@@ -730,6 +730,11 @@
 		/* set value - only for animatable numerical values */
 		if (RNA_property_animateable(&new_ptr, prop)) 
 		{
+			/* convert to radians */
+			if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) {
+				value *= M_PI/180.0;
+			}
+			
 			switch (RNA_property_type(prop)) 
 			{
 				case PROP_BOOLEAN:
@@ -1466,6 +1471,11 @@
 		int array_index= nec->index;
 		float value= nec->value;
 		
+		/* convert to radians */
+		if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) {
+			value *= M_PI/180.0;
+		}
+		
 		/* write values - see animsys_write_rna_setting() to sync the code */
 		switch (RNA_property_type(prop)) 
 		{

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2010-01-24 23:18:48 UTC (rev 26234)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2010-01-25 06:24:05 UTC (rev 26235)
@@ -1353,10 +1353,7 @@
 	
 	mat4_to_eulO( eul, cob->rotOrder,cob->matrix);
 	
-	/* eulers: radians to degrees! */
-	eul[0] = (float)(eul[0] / M_PI * 180);
-	eul[1] = (float)(eul[1] / M_PI * 180);
-	eul[2] = (float)(eul[2] / M_PI * 180);
+	/* constraint data uses radians internally */
 	
 	/* limiting of euler values... */
 	if (data->flag & LIMIT_XROT) {
@@ -1381,11 +1378,6 @@
 			eul[2] = data->zmax;
 	}
 		
-	/* eulers: degrees to radians ! */
-	eul[0] = (float)(eul[0] / 180 * M_PI); 
-	eul[1] = (float)(eul[1] / 180 * M_PI);
-	eul[2] = (float)(eul[2] / 180 * M_PI);
-	
 	loc_eulO_size_to_mat4(cob->matrix, loc, eul, size, cob->rotOrder);
 }
 

Modified: trunk/blender/source/blender/blenkernel/intern/unit.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/unit.c	2010-01-24 23:18:48 UTC (rev 26234)
+++ trunk/blender/source/blender/blenkernel/intern/unit.c	2010-01-25 06:24:05 UTC (rev 26235)
@@ -119,11 +119,18 @@
 };
 static struct bUnitCollection buNaturalTimeCollecton = {buNaturalTimeDef, 3, 0, sizeof(buNaturalTimeDef)/sizeof(bUnitDef)};
 
+
+static struct bUnitDef buNaturalRotDef[] = {
+	{"degree", "degrees",			"°", NULL, "Degrees",		M_PI/180.f, 0.0,	B_UNIT_DEF_NONE},
+	{NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}
+};
+static struct bUnitCollection buNaturalRotCollection = {buNaturalRotDef, 0, 0, sizeof(buNaturalRotDef)/sizeof(bUnitDef)};
+
 #define UNIT_SYSTEM_MAX 3
 static struct bUnitCollection *bUnitSystems[][8] = {
-	{0,0,0,0,0,0,0,0},
-	{0,&buMetricLenCollecton, 0,0,0,0, &buNaturalTimeCollecton,0}, /* metric */
-	{0,&buImperialLenCollecton, 0,0,0,0, &buNaturalTimeCollecton,0}, /* imperial */
+	{0,0,0,0,0,&buNaturalRotCollection,&buNaturalTimeCollecton,0},
+	{0,&buMetricLenCollecton, 0,0,0, &buNaturalRotCollection, &buNaturalTimeCollecton,0}, /* metric */
+	{0,&buImperialLenCollecton, 0,0,0,&buNaturalRotCollection, &buNaturalTimeCollecton,0}, /* imperial */
 	{0,0,0,0,0,0,0,0}
 };
 
@@ -451,23 +458,25 @@
 		bUnitCollection *usys_iter;
 		int system_iter;
 
-		for(system_iter= 1; system_iter<UNIT_SYSTEM_MAX; system_iter++) {
+		for(system_iter= 0; system_iter<UNIT_SYSTEM_MAX; system_iter++) {
 			if (system_iter != system) {
 				usys_iter= unit_get_system(system_iter, type);
-				for(unit= usys_iter->units; unit->name; unit++) {
+				if (usys_iter) {
+					for(unit= usys_iter->units; unit->name; unit++) {
 
-					if((unit->flag & B_UNIT_DEF_SUPPRESS) == 0) {
-						int ofs = 0;
-						/* incase there are multiple instances */
-						while((ofs=unit_replace(str+ofs, len_max-ofs, str_tmp, scale_pref, unit)))
-							change= 1;
+						if((unit->flag & B_UNIT_DEF_SUPPRESS) == 0) {
+							int ofs = 0;
+							/* incase there are multiple instances */
+							while((ofs=unit_replace(str+ofs, len_max-ofs, str_tmp, scale_pref, unit)))
+								change= 1;
+						}
 					}
 				}
 			}
 		}
 	}
 	unit= NULL;
-
+	
 	if(change==0) {
 		/* no units given so infer a unit from the previous string or default */
 		if(str_prev) {
@@ -482,9 +491,10 @@
 			}
 		}
 
-		if(unit==NULL)
+		if(unit==NULL || unit->name == NULL)
 			unit= unit_default(usys);
 
+
 		/* add the unit prefix and re-run, use brackets incase there was an expression given */
 		if(snprintf(str_tmp, sizeof(str_tmp), "(%s)%s", str, unit->name) < sizeof(str_tmp)) {
 			strncpy(str, str_tmp, len_max);
@@ -530,7 +540,6 @@
 		}
 	}
 
-	// printf("replace %s\n", str);
 	return change;
 }
 

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2010-01-24 23:18:48 UTC (rev 26234)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2010-01-25 06:24:05 UTC (rev 26235)
@@ -6439,6 +6439,30 @@
 	}
 }
 
+static void do_version_fcurve_radians_degrees_250(FCurve *fcu)
+{
+	int i;
+	
+	if (fcu->bezt) {
+		for (i=0; i<fcu->totvert; i++) {
+			BezTriple *bt = fcu->bezt+i;
+			
+			bt->vec[0][1] *= 180.0/M_PI;
+			bt->vec[1][1] *= 180.0/M_PI;
+			bt->vec[2][1] *= 180.0/M_PI;
+		}
+	}
+	else if (fcu->fpt) {
+		for (i=0; i<fcu->totvert; i++) {
+			FPoint *fpt = fcu->fpt+i;
+			
+			fpt->vec[1] *= 180.0/M_PI;
+		}
+	}
+	
+	fcu->flag |= FCURVE_ROTATION_DEGREES;
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
 	/* WATCH IT!!!: pointers from libdata have not been converted */
@@ -10493,7 +10517,68 @@
 	
 	/* put 2.50 compatibility code here until next subversion bump */
 	if (1) {
-		;
+		{
+			/* still missing:
+			   - Pose channel IK (min x/y/z, max x/y/z)
+			 */
+			bAction *act;
+			Object *ob;
+			
+			float rads_per_deg = M_PI / 180.0;
+			
+			/* convert degrees to radians for internal use */
+			for (ob=main->object.first; ob; ob=ob->id.next) {
+				AnimData *adt = BKE_animdata_from_id((ID *)ob);
+				bConstraint *con;
+				
+				for	(con=ob->constraints.first; con; con=con->next) {
+					
+					if(con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) {
+						bRigidBodyJointConstraint *data = con->data;
+						data->axX *= rads_per_deg;
+						data->axY *= rads_per_deg;
+						data->axZ *= rads_per_deg;
+					}
+					else if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
+						bKinematicConstraint *data = con->data;
+						data->poleangle *= rads_per_deg;
+					}
+					else if(con->type==CONSTRAINT_TYPE_ROTLIMIT) {
+						bRotLimitConstraint *data = con->data;
+						FCurve *fcu;
+
+						/* do it here, slightly less chance of getting a false positive */
+						for (fcu=adt->action->curves.first; fcu; fcu=fcu->next) {
+							if (strcmp(fcu->rna_path, "minimum_x")==0)
+								do_version_fcurve_radians_degrees_250(fcu);
+						}
+						
+						data->xmin *= rads_per_deg;
+						data->xmax *= rads_per_deg;
+						data->ymin *= rads_per_deg;
+						data->ymax *= rads_per_deg;
+						data->zmin *= rads_per_deg;
+						data->zmax *= rads_per_deg;
+
+					}
+				}
+			}
+			
+			/* convert fcurve values to be stored in degrees */
+			for (act = main->action.first; act; act=act->id.next) {
+				FCurve *fcu;
+				
+				/* convert over named properties with PROP_UNIT_ROTATION time of this change */
+				for (fcu=act->curves.first; fcu; fcu=fcu->next) {
+					if (strcmp(fcu->rna_path, "rotation_euler")==0)
+						do_version_fcurve_radians_degrees_250(fcu);
+					else if (strcmp(fcu->rna_path, "delta_rotation_euler")==0)
+						do_version_fcurve_radians_degrees_250(fcu);
+					else if (strcmp(fcu->rna_path, "pole_angle")==0)
+						do_version_fcurve_radians_degrees_250(fcu);
+				}
+			}
+		}
 	}
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

Modified: trunk/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframing.c	2010-01-24 23:18:48 UTC (rev 26234)
+++ trunk/blender/source/blender/editors/animation/keyframing.c	2010-01-25 06:24:05 UTC (rev 26235)
@@ -783,6 +783,11 @@
 		curval= setting_get_rna_value(&ptr, prop, fcu->array_index);
 	}
 	
+	/* convert to degrees */
+	if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) {
+		curval *= 180.0/M_PI;
+	}
+	
 	/* only insert keyframes where they are needed */
 	if (flag & INSERTKEY_NEEDED) {
 		short insert_mode;
@@ -895,6 +900,10 @@
 			}
 		}
 		
+		/* mark the curve if it's a new rotation curve */
+		if ((fcu->totvert == 0) && (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION))
+			fcu->flag |= FCURVE_ROTATION_DEGREES;
+		
 		/* insert keyframe */
 		ret += insert_keyframe_direct(ptr, prop, fcu, cfra, flag);
 	}

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2010-01-24 23:18:48 UTC (rev 26234)
+++ trunk/blender/source/blender/editors/interface/interface.c	2010-01-25 06:24:05 UTC (rev 26235)
@@ -1225,13 +1225,19 @@
 int ui_is_but_unit(uiBut *but)
 {
 	Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
-	if(scene->unit.system == USER_UNIT_NONE)
-		return 0;
-
+	int unit_type;
+	
 	if(but->rnaprop==NULL)
 		return 0;
+	
+	unit_type = RNA_SUBTYPE_UNIT(RNA_property_subtype(but->rnaprop));
+	
+	if(scene->unit.system == USER_UNIT_NONE) {
+	   if (unit_type != PROP_UNIT_ROTATION)
+			return 0;
+	}
 
-	if(RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop))==0)
+	if(unit_type == PROP_UNIT_NONE)
 		return 0;
 
 	return 1;
@@ -1406,12 +1412,12 @@
 static double ui_get_but_scale_unit(uiBut *but, double value)
 {
 	Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
-	int subtype= RNA_property_subtype(but->rnaprop);
+	int subtype= RNA_SUBTYPE_UNIT(RNA_property_subtype(but->rnaprop));
 
-	if(subtype & PROP_UNIT_LENGTH) {
+	if(subtype == PROP_UNIT_LENGTH) {
 		return value * scene->unit.scale_length;
 	}
-	else if(subtype & PROP_UNIT_TIME) { /* WARNING - using evil_C :| */
+	else if(subtype == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */
 		return FRA2TIME(value);
 	}
 	else {
@@ -1596,7 +1602,7 @@
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list