[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23125] branches/blender2.5/blender: 2. 5 Rotations: As a experiment, enabling Axis-Angle for Bones

Joshua Leung aligorith at gmail.com
Fri Sep 11 14:05:09 CEST 2009


Revision: 23125
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23125
Author:   aligorith
Date:     2009-09-11 14:05:09 +0200 (Fri, 11 Sep 2009)

Log Message:
-----------
2.5 Rotations: As a experiment, enabling Axis-Angle for Bones

The support for this is really quite hacky, and I might disable this later if we cannot get some parts to work nicely. 

Some notes:
* This is currently stored in the same variable that quaternions are stored in, since they both have 4 components. However, in RNA, I've added 2 properties specially for this. 
* There are some shearing issues using certain axes - i.e. (1,1,0) - that will need to be checked on.
* Transform code is really quite temporary for this. Just a quick demo of what can be done...

Modified Paths:
--------------
    branches/blender2.5/blender/release/ui/buttons_data_bone.py
    branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c
    branches/blender2.5/blender/source/blender/editors/transform/transform.c
    branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c
    branches/blender2.5/blender/source/blender/windowmanager/intern/wm_files.c

Modified: branches/blender2.5/blender/release/ui/buttons_data_bone.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_data_bone.py	2009-09-11 11:52:56 UTC (rev 23124)
+++ branches/blender2.5/blender/release/ui/buttons_data_bone.py	2009-09-11 12:05:09 UTC (rev 23125)
@@ -58,6 +58,10 @@
 			col = row.column()
 			if pchan.rotation_mode == 'QUATERNION':
 				col.itemR(pchan, "rotation", text="Rotation")
+			elif pchan.rotation_mode == 'AXIS_ANGLE':
+				col.itemL(text="Rotation")
+				col.itemR(pchan, "rotation_angle", text="Angle")
+				col.itemR(pchan, "rotation_axis", text="Axis")
 			else:
 				col.itemR(pchan, "euler_rotation", text="Rotation")
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c	2009-09-11 11:52:56 UTC (rev 23124)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/armature.c	2009-09-11 12:05:09 UTC (rev 23125)
@@ -1986,11 +1986,15 @@
 	/* get scaling matrix */
 	SizeToMat3(chan->size, smat);
 	
-	/* rotations may either be quats or eulers (no rotation modes for now...) */
+	/* rotations may either be quats, eulers (with various rotation orders), or axis-angle */
 	if (chan->rotmode > 0) {
-		/* euler rotations (will cause gimble lock... no rotation order to solve that yet) */
+		/* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */
 		EulOToMat3(chan->eul, chan->rotmode, rmat);
 	}
+	else if (chan->rotmode == PCHAN_ROT_AXISANGLE) {
+		/* axis-angle - stored in quaternion data, but not really that great for 3D-changing orientations */
+		VecRotToMat3(&chan->quat[1], chan->quat[0], rmat);
+	}
 	else {
 		/* quats are normalised before use to eliminate scaling issues */
 		NormalQuat(chan->quat);

Modified: branches/blender2.5/blender/source/blender/editors/transform/transform.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform.c	2009-09-11 11:52:56 UTC (rev 23124)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform.c	2009-09-11 12:05:09 UTC (rev 23125)
@@ -2663,7 +2663,7 @@
 
 		/* rotation */
 		if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
-			/* euler or quaternion? */
+			/* euler or quaternion/axis-angle? */
 			if (td->flag & TD_USEQUAT) {
 				Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
 
@@ -2672,6 +2672,15 @@
 				QuatMul(td->ext->quat, quat, td->ext->iquat);
 				/* this function works on end result */
 				protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
+				
+				/* if axis-angle, we now convert the quat representation to axis-angle again
+				 * 	- this means that the math above is not totally correct, but it works well enough so far...
+				 */
+				if (td->rotOrder == PCHAN_ROT_AXISANGLE) {	
+					/* make temp copy (since stored in same place) */
+					QuatCopy(quat, td->ext->quat);
+					QuatToAxisAngle(quat, &td->ext->quat[1], &td->ext->quat[0]); 
+				}
 			}
 			else { 
 				float eulmat[3][3];

Modified: branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c	2009-09-11 11:52:56 UTC (rev 23124)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c	2009-09-11 12:05:09 UTC (rev 23125)
@@ -552,8 +552,9 @@
 
 	td->ob = ob;
 	td->flag = TD_SELECTED;
-	if (pchan->rotmode == PCHAN_ROT_QUAT)
+	if ((pchan->rotmode == PCHAN_ROT_QUAT) || (pchan->rotmode == PCHAN_ROT_AXISANGLE)) 
 	{
+		// XXX: for now, axis-angle will be treated like for quats (the only difference is the normalisation)
 		td->flag |= TD_USEQUAT;
 	}
 	if (bone->flag & BONE_HINGE_CHILD_TRANSFORM)
@@ -587,6 +588,7 @@
 		td->ext->quat= pchan->quat;
 		
 		QUATCOPY(td->ext->iquat, pchan->quat);
+		td->rotOrder= pchan->rotmode;
 	}
 	
 

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c	2009-09-11 11:52:56 UTC (rev 23124)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c	2009-09-11 12:05:09 UTC (rev 23125)
@@ -110,26 +110,64 @@
 	return pchan->prop;
 }
 
+/* rotation - euler angles */
 static void rna_PoseChannel_euler_rotation_get(PointerRNA *ptr, float *value)
 {
 	bPoseChannel *pchan= ptr->data;
-
-	if(pchan->rotmode == PCHAN_ROT_QUAT)
+	
+	if(pchan->rotmode == PCHAN_ROT_AXISANGLE) {
+		float m[3][3];
+		
+		/* go through a 3x3 matrix */
+		VecRotToMat3(&pchan->quat[1], pchan->quat[0], m);
+		Mat3ToEul(m, value);
+	}
+	else if(pchan->rotmode == PCHAN_ROT_QUAT) /* default XYZ eulers when using axis-angle... */
 		QuatToEul(pchan->quat, value);
 	else
 		VECCOPY(value, pchan->eul);
 }
 
+/* rotation - euler angles */
 static void rna_PoseChannel_euler_rotation_set(PointerRNA *ptr, const float *value)
 {
 	bPoseChannel *pchan= ptr->data;
-
-	if(pchan->rotmode == PCHAN_ROT_QUAT) /* default XYZ eulers when using quats... */
+	
+	if(pchan->rotmode == PCHAN_ROT_AXISANGLE) { /* default XYZ eulers when using axis-angle... */
+		float q[4];
+		
+		/* convert to temp quat, then to axis angle (since stored in same var) */
+		EulToQuat((float *)value, q);
+		QuatToAxisAngle(q, &pchan->quat[1], &pchan->quat[0]);
+	}
+	else if(pchan->rotmode == PCHAN_ROT_QUAT) /* default XYZ eulers when using quats... */
 		EulToQuat((float*)value, pchan->quat);
 	else
 		VECCOPY(pchan->eul, value);
 }
 
+/* rotation - axis angle only */
+static void rna_PoseChannel_rotation_axis_get(PointerRNA *ptr, float *value)
+{
+	bPoseChannel *pchan= ptr->data;
+	
+	if (pchan->rotmode == PCHAN_ROT_AXISANGLE) {
+		/* axis is stord in quat for now */
+		VecCopyf(value, &pchan->quat[1]);
+	}
+}
+
+/* rotation - axis angle only */
+static void rna_PoseChannel_rotation_axis_set(PointerRNA *ptr, const float *value)
+{
+	bPoseChannel *pchan= ptr->data;
+	
+	if (pchan->rotmode == PCHAN_ROT_AXISANGLE) {
+		/* axis is stored in quat for now */
+		VecCopyf(&pchan->quat[1], (float *)value);
+	}
+}
+
 static void rna_PoseChannel_rotation_mode_set(PointerRNA *ptr, int value)
 {
 	bPoseChannel *pchan= ptr->data;
@@ -185,6 +223,12 @@
 			QuatCopy(q, pchan->quat);
 			QuatToAxisAngle(q, &pchan->quat[1], &pchan->quat[0]);
 		}
+		
+		/* when converting to axis-angle, we need a special exception for the case when there is no axis */
+		if (IS_EQ(pchan->quat[1], pchan->quat[2]) && IS_EQ(pchan->quat[2], pchan->quat[3])) {
+			/* for now, rotate around y-axis then (so that it simply becomes the roll) */
+			pchan->quat[2]= 1.0f;
+		}
 	}
 	
 	/* finally, set the new rotation type */
@@ -421,7 +465,7 @@
 		{PCHAN_ROT_YZX, "YZX", 0, "YZX Euler", "YZX Rotation Order. Prone to Gimbal Lock"},
 		{PCHAN_ROT_ZXY, "ZXY", 0, "ZXY Euler", "ZXY Rotation Order. Prone to Gimbal Lock"},
 		{PCHAN_ROT_ZYX, "ZYX", 0, "ZYX Euler", "ZYX Rotation Order. Prone to Gimbal Lock"},
-		//{PCHAN_ROT_AXISANGLE, "AXIS_ANGLE", 0, "Axis Angle", "Axis Angle (W+XYZ). Defines a rotation around some axis defined by 3D-Vector."},
+		{PCHAN_ROT_AXISANGLE, "AXIS_ANGLE", 0, "Axis Angle", "Axis Angle (W+XYZ). Defines a rotation around some axis defined by 3D-Vector."},
 		{0, NULL, 0, NULL, NULL}};
 	
 	StructRNA *srna;
@@ -493,6 +537,18 @@
 	RNA_def_property_ui_text(prop, "Rotation", "Rotation in Quaternions.");
 	RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update");
 	
+	prop= RNA_def_property(srna, "rotation_angle", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "quat[0]");
+	RNA_def_property_ui_text(prop, "Rotation Angle", "Angle of Rotation for Axis-Angle rotation representation.");
+	RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update");
+	
+	prop= RNA_def_property(srna, "rotation_axis", PROP_FLOAT, PROP_XYZ);
+	RNA_def_property_float_sdna(prop, NULL, "quat");
+	RNA_def_property_float_funcs(prop, "rna_PoseChannel_rotation_axis_get", "rna_PoseChannel_rotation_axis_set", NULL);
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_ui_text(prop, "Rotation Axis", "Axis for Axis-Angle rotation representation.");
+	RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update");
+	
 	prop= RNA_def_property(srna, "euler_rotation", PROP_FLOAT, PROP_EULER);
 	RNA_def_property_float_sdna(prop, NULL, "eul");
 	RNA_def_property_float_funcs(prop, "rna_PoseChannel_euler_rotation_get", "rna_PoseChannel_euler_rotation_set", NULL);
@@ -662,8 +718,14 @@
 	prop= RNA_def_property(srna, "lock_rotation", PROP_BOOLEAN, PROP_XYZ);
 	RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTX);
 	RNA_def_property_array(prop, 3);
-	RNA_def_property_ui_text(prop, "Lock Rotation", "Lock editing of rotation in the interface.");
+	RNA_def_property_ui_text(prop, "Lock Rotation", "Lock editing of rotation (with three components) in the interface.");
 	RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
+	
+	//prop= RNA_def_property(srna, "lock_rotation_4d", PROP_BOOLEAN, PROP_XYZ);
+	//RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTW);
+	//RNA_def_property_array(prop, 4);
+	//RNA_def_property_ui_text(prop, "Lock Rotation (4D)", "Lock editing of rotations (with four components) in the interface.");
+	//RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
 
 	prop= RNA_def_property(srna, "lock_scale", PROP_BOOLEAN, PROP_XYZ);
 	RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_SCALEX);

Modified: branches/blender2.5/blender/source/blender/windowmanager/intern/wm_files.c
===================================================================
--- branches/blender2.5/blender/source/blender/windowmanager/intern/wm_files.c	2009-09-11 11:52:56 UTC (rev 23124)
+++ branches/blender2.5/blender/source/blender/windowmanager/intern/wm_files.c	2009-09-11 12:05:09 UTC (rev 23125)
@@ -281,7 +281,7 @@
 
 
 /* called on startup,  (context entirely filled with NULLs) */
-/* or called for 'Erase All' */
+/* or called for 'New File' */
 /* op can be NULL */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list