[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23523] trunk/blender: Durian Feature Request: Rotation Modes for Objects

Joshua Leung aligorith at gmail.com
Mon Sep 28 12:19:21 CEST 2009


Revision: 23523
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23523
Author:   aligorith
Date:     2009-09-28 12:19:20 +0200 (Mon, 28 Sep 2009)

Log Message:
-----------
Durian Feature Request: Rotation Modes for Objects

This (biggish) commit generalises the rotation modes functionality added for Bones, allowing Objects to use the various Euler Rotation orders, Axis-Angle, and Quaternion rotation representations.

I've also cleaned up the nomenclature of the rotation-related settings so that the naming styles are more consistent with each other. Unfortunately, this will break all files involving object or bone rotation animation made in 2.5 versions (2.4x will still get correctly converted).

General Notes:
* By default, Objects still default to using Eulers, while Bones will use Quaternions by default still.
* I've fixed all areas that I'm currently aware of to work with these changes. However, there are probably a few places where I've missed a few changes (i.e. auto-keyframing will need attention later).
* Removed the old "IPO-Keys" stuff from Transform code. I'm unlikely to restore this in the near future, and trying to fix that to include support for this commit would have been too much work.

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/buttons_data_bone.py
    trunk/blender/release/scripts/ui/buttons_object.py
    trunk/blender/source/blender/blenkernel/BKE_armature.h
    trunk/blender/source/blender/blenkernel/intern/armature.c
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenkernel/intern/ipo.c
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenlib/BLI_arithb.h
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/editors/animation/keyingsets.c
    trunk/blender/source/blender/editors/armature/editarmature.c
    trunk/blender/source/blender/editors/armature/poseSlide.c
    trunk/blender/source/blender/editors/armature/poseobject.c
    trunk/blender/source/blender/editors/object/object_transform.c
    trunk/blender/source/blender/editors/space_graph/graph_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_buttons.c
    trunk/blender/source/blender/editors/transform/transform.c
    trunk/blender/source/blender/editors/transform/transform.h
    trunk/blender/source/blender/editors/transform/transform_conversions.c
    trunk/blender/source/blender/editors/transform/transform_generics.c
    trunk/blender/source/blender/ikplugin/intern/itasc_plugin.cpp
    trunk/blender/source/blender/makesdna/DNA_action_types.h
    trunk/blender/source/blender/makesdna/DNA_anim_types.h
    trunk/blender/source/blender/makesdna/DNA_object_types.h
    trunk/blender/source/blender/makesrna/RNA_types.h
    trunk/blender/source/blender/makesrna/intern/makesrna.c
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/makesrna/intern/rna_object.c
    trunk/blender/source/blender/makesrna/intern/rna_pose.c

Modified: trunk/blender/release/scripts/ui/buttons_data_bone.py
===================================================================
--- trunk/blender/release/scripts/ui/buttons_data_bone.py	2009-09-28 09:59:21 UTC (rev 23522)
+++ trunk/blender/release/scripts/ui/buttons_data_bone.py	2009-09-28 10:19:20 UTC (rev 23523)
@@ -57,20 +57,16 @@
 
 			col = row.column()
 			if pchan.rotation_mode == 'QUATERNION':
-				col.itemR(pchan, "rotation", text="Rotation")
+				col.itemR(pchan, "rotation_quaternion", 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")
+				#col.itemL(text="Rotation")
+				#col.itemR(pchan, "rotation_angle", text="Angle")
+				#col.itemR(pchan, "rotation_axis", text="Axis")
+				col.itemR(pchan, "rotation_axis_angle", text="Rotation")
 			else:
-				col.itemR(pchan, "euler_rotation", text="Rotation")
+				col.itemR(pchan, "rotation_euler", text="Rotation")
 
 			row.column().itemR(pchan, "scale")
-
-			if pchan.rotation_mode == 'QUATERNION':
-				col = layout.column(align=True)
-				col.itemL(text="Euler:")
-				col.row().itemR(pchan, "euler_rotation", text="")
 				
 class BONE_PT_transform_locks(BoneButtonsPanel):
 	__label__ = "Transform Locks"

Modified: trunk/blender/release/scripts/ui/buttons_object.py
===================================================================
--- trunk/blender/release/scripts/ui/buttons_object.py	2009-09-28 09:59:21 UTC (rev 23522)
+++ trunk/blender/release/scripts/ui/buttons_object.py	2009-09-28 10:19:20 UTC (rev 23523)
@@ -25,11 +25,48 @@
 		layout = self.layout
 		
 		ob = context.object
+		
+		layout.itemR(ob, "rotation_mode")
 
 		row = layout.row()
+		
 		row.column().itemR(ob, "location")
-		row.column().itemR(ob, "rotation")
+		if ob.rotation_mode == 'QUATERNION':
+			row.column().itemR(ob, "rotation_quaternion", text="Rotation")
+		elif ob.rotation_mode == 'AXIS_ANGLE':
+			#row.column().itemL(text="Rotation")
+			#row.column().itemR(pchan, "rotation_angle", text="Angle")
+			#row.column().itemR(pchan, "rotation_axis", text="Axis")
+			row.column().itemR(ob, "rotation_axis_angle", text="Rotation")
+		else:
+			row.column().itemR(ob, "rotation_euler", text="Rotation")
+			
 		row.column().itemR(ob, "scale")
+		
+class OBJECT_PT_transform_locks(ObjectButtonsPanel):
+	__label__ = "Transform Locks"
+	__default_closed__ = True
+	
+	def draw(self, context):
+		layout = self.layout
+		
+		ob = context.object
+		
+		row = layout.row()
+		
+		col = row.column()
+		col.itemR(ob, "lock_location")
+		
+		col = row.column()
+		if ob.rotation_mode in ('QUATERNION', 'AXIS_ANGLE'):
+			col.itemR(ob, "lock_rotations_4d", text="Lock Rotation")
+			if ob.lock_rotations_4d:
+				col.itemR(ob, "lock_rotation_w", text="W")
+			col.itemR(ob, "lock_rotation", text="")
+		else:
+			col.itemR(ob, "lock_rotation", text="Rotation")
+		
+		row.column().itemR(ob, "lock_scale")
 
 class OBJECT_PT_relations(ObjectButtonsPanel):
 	__label__ = "Relations"
@@ -178,6 +215,7 @@
 
 bpy.types.register(OBJECT_PT_context_object)
 bpy.types.register(OBJECT_PT_transform)
+bpy.types.register(OBJECT_PT_transform_locks)
 bpy.types.register(OBJECT_PT_relations)
 bpy.types.register(OBJECT_PT_groups)
 bpy.types.register(OBJECT_PT_display)

Modified: trunk/blender/source/blender/blenkernel/BKE_armature.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_armature.h	2009-09-28 09:59:21 UTC (rev 23522)
+++ trunk/blender/source/blender/blenkernel/BKE_armature.h	2009-09-28 10:19:20 UTC (rev 23523)
@@ -103,6 +103,9 @@
 void armature_loc_pose_to_bone(struct bPoseChannel *pchan, float *inloc, float *outloc);
 void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float arm_mat[][4]);
 
+/* Rotation Mode Conversions - Used for PoseChannels + Objects... */
+void BKE_rotMode_change_values(float quat[4], float eul[3], short oldMode, short newMode);
+
 /* B-Bone support */
 typedef struct Mat4 {
 	float mat[4][4];

Modified: trunk/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/armature.c	2009-09-28 09:59:21 UTC (rev 23522)
+++ trunk/blender/source/blender/blenkernel/intern/armature.c	2009-09-28 10:19:20 UTC (rev 23523)
@@ -1279,7 +1279,66 @@
  	Mat4MulMat4(delta_mat, pose_mat, imat);
 }
 
+/* **************** Rotation Mode Conversions ****************************** */
+/* Used for Objects and Pose Channels, since both can have multiple rotation representations */
 
+/* Called from RNA when rotation mode changes 
+ *	- the result should be that the rotations given in the provided pointers have had conversions 
+ *	  applied (as appropriate), such that the rotation of the element hasn't 'visually' changed 
+ *
+ *	- as in SDNA data, quat is used to store quaternions AND axis-angle rotations...
+ */
+void BKE_rotMode_change_values (float quat[4], float eul[3], short oldMode, short newMode)
+{
+	/* check if any change - if so, need to convert data */
+	if (newMode > 0) { /* to euler */
+		if (oldMode == ROT_MODE_AXISANGLE) {
+			/* axis-angle to euler */
+			AxisAngleToEulO(&quat[1], quat[0], eul, newMode);
+		}
+		else if (oldMode == ROT_MODE_QUAT) {
+			/* quat to euler */
+			QuatToEulO(quat, eul, newMode);
+		}
+		/* else { no conversion needed } */
+	}
+	else if (newMode == ROT_MODE_QUAT) { /* to quat */
+		if (oldMode == ROT_MODE_AXISANGLE) {
+			/* axis angle to quat */
+			float q[4];
+			
+			/* copy to temp var first, since quats and axis-angle are stored in same place */
+			QuatCopy(q, quat);
+			AxisAngleToQuat(q, &quat[1], quat[0]);
+		}
+		else if (oldMode > 0) {
+			/* euler to quat */
+			EulOToQuat(eul, oldMode, quat);
+		}
+		/* else { no conversion needed } */
+	}
+	else { /* to axis-angle */
+		if (oldMode > 0) {
+			/* euler to axis angle */
+			EulOToAxisAngle(eul, oldMode, &quat[1], &quat[0]);
+		}
+		else if (oldMode == ROT_MODE_QUAT) {
+			/* quat to axis angle */
+			float q[4];
+			
+			/* copy to temp var first, since quats and axis-angle are stored in same place */
+			QuatCopy(q, quat);
+			QuatToAxisAngle(q, &quat[1], &quat[0]);
+		}
+		
+		/* when converting to axis-angle, we need a special exception for the case when there is no axis */
+		if (IS_EQ(quat[1], quat[2]) && IS_EQ(quat[2], quat[3])) {
+			/* for now, rotate around y-axis then (so that it simply becomes the roll) */
+			quat[2]= 1.0f;
+		}
+	}
+}
+
 /* **************** The new & simple (but OK!) armature evaluation ********* */ 
 
 /*  ****************** And how it works! ****************************************
@@ -1591,7 +1650,7 @@
 		/* 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) {
+	else if (chan->rotmode == ROT_MODE_AXISANGLE) {
 		/* axis-angle - stored in quaternion data, but not really that great for 3D-changing orientations */
 		AxisAngleToMat3(&chan->quat[1], chan->quat[0], rmat);
 	}

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2009-09-28 09:59:21 UTC (rev 23522)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2009-09-28 10:19:20 UTC (rev 23523)
@@ -692,9 +692,11 @@
 			}\
 			else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) { \
 				ct->type = CONSTRAINT_OBTYPE_VERT; \
+				ct->rotOrder = EULER_ORDER_DEFAULT; \
 			} \
 			else {\
 				ct->type = CONSTRAINT_OBTYPE_OBJECT; \
+				ct->rotOrder= ct->tar->rotmode; \
 			} \
 		} \
 		 \

Modified: trunk/blender/source/blender/blenkernel/intern/ipo.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/ipo.c	2009-09-28 09:59:21 UTC (rev 23522)
+++ trunk/blender/source/blender/blenkernel/intern/ipo.c	2009-09-28 10:19:20 UTC (rev 23523)
@@ -213,17 +213,17 @@
 			*array_index= 2; return "delta_location";
 		
 		case OB_ROT_X:
-			*array_index= 0; return "rotation";
+			*array_index= 0; return "rotation_euler";
 		case OB_ROT_Y:
-			*array_index= 1; return "rotation";
+			*array_index= 1; return "rotation_euler";
 		case OB_ROT_Z:
-			*array_index= 2; return "rotation";
+			*array_index= 2; return "rotation_euler";
 		case OB_DROT_X:
-			*array_index= 0; return "delta_rotation";
+			*array_index= 0; return "delta_rotation_euler";
 		case OB_DROT_Y:
-			*array_index= 1; return "delta_rotation";
+			*array_index= 1; return "delta_rotation_euler";
 		case OB_DROT_Z:
-			*array_index= 2; return "delta_rotation";
+			*array_index= 2; return "delta_rotation_euler";
 			
 		case OB_SIZE_X:
 			*array_index= 0; return "scale";
@@ -281,23 +281,23 @@
 	/* result depends on adrcode */
 	switch (adrcode) {
 		case AC_QUAT_W:
-			*array_index= 0; return "rotation";
+			*array_index= 0; return "rotation_quaternion";
 		case AC_QUAT_X:
-			*array_index= 1; return "rotation";
+			*array_index= 1; return "rotation_quaternion";
 		case AC_QUAT_Y:
-			*array_index= 2; return "rotation";
+			*array_index= 2; return "rotation_quaternion";
 		case AC_QUAT_Z:
-			*array_index= 3; return "rotation";
+			*array_index= 3; return "rotation_quaternion";
 			
 		case AC_EUL_X:
-			*array_index= 0; return "euler_rotation";
+			*array_index= 0; return "rotation_euler";
 		case AC_EUL_Y:
-			*array_index= 1; return "euler_rotation";
+			*array_index= 1; return "rotation_euler";
 		case AC_EUL_Z:
-			*array_index= 2; return "euler_rotation";
+			*array_index= 2; return "rotation_euler";
 			
 		case -1: /* special case for euler-rotations used by old drivers */
-			*array_index= 0; return "euler_rotation";
+			*array_index= 0; return "rotation_euler";
 			
 		case AC_LOC_X:
 			*array_index= 0; return "location";

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2009-09-28 09:59:21 UTC (rev 23522)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2009-09-28 10:19:20 UTC (rev 23523)
@@ -127,8 +127,8 @@
 {
 	memset(workob, 0, sizeof(Object));
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list