[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44246] trunk/blender/source/blender: More pose armature code factorization:

Bastien Montagne montagne29 at wanadoo.fr
Sun Feb 19 12:09:53 CET 2012


Revision: 44246
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44246
Author:   mont29
Date:     2012-02-19 11:09:44 +0000 (Sun, 19 Feb 2012)
Log Message:
-----------
More pose armature code factorization:
* New armature_mat_bone_to_pose, which is just the reverse of armature_mat_pose_to_bone (currently used by armature evaluation code only, but might be used by constraints space conversion code too, see note below).
* Found another place where another (a bit erroneous) pose_to_bone code existed (apply_targetless_ik(), in transform_conversion.c, used by "auto ik" option), replaced it by a call to armature_mat_pose_to_bone.

Notes:
* All those changes leave many #if 0 commented code, I will remove those in a few weeks.
* There is at least one other place where generic armature_mat_(pose_to_bone/bone_to_pose) functions should be usable: the space conversion function of constraints (constraint_mat_convertspace(), in BKE's constraint.c), but here I have some problems (old code is also somewhat erroneous, but using new one makes old rigs using bone space constraints wrong, e.g. sintel one, and it?\226?\128?\153s just impossible to make conversion code...). So I'll wait and investigate more for this one.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_armature.h
    trunk/blender/source/blender/blenkernel/intern/armature.c
    trunk/blender/source/blender/editors/transform/transform_conversions.c

Modified: trunk/blender/source/blender/blenkernel/BKE_armature.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_armature.h	2012-02-19 08:39:11 UTC (rev 44245)
+++ trunk/blender/source/blender/blenkernel/BKE_armature.h	2012-02-19 11:09:44 UTC (rev 44246)
@@ -107,6 +107,7 @@
 void armature_loc_world_to_pose(struct Object *ob, float *inloc, float *outloc);
 void armature_mat_pose_to_bone(struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]);
 void armature_loc_pose_to_bone(struct bPoseChannel *pchan, float *inloc, float *outloc);
+void armature_mat_bone_to_pose(struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]);
 void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float arm_mat[][4]);
 
 void armature_mat_pose_to_bone_ex(struct Object *ob, struct bPoseChannel *pchan, float inmat[][4], float outmat[][4]);

Modified: trunk/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/armature.c	2012-02-19 08:39:11 UTC (rev 44245)
+++ trunk/blender/source/blender/blenkernel/intern/armature.c	2012-02-19 11:09:44 UTC (rev 44246)
@@ -1302,6 +1302,17 @@
 	mul_v3_m4v3(outmat[3], loc_mat, inmat[3]);
 }
 
+/* Convert Bone-Space Matrix to Pose-Space Matrix. */
+void armature_mat_bone_to_pose(bPoseChannel *pchan, float inmat[][4], float outmat[][4])
+{
+	float rotscale_mat[4][4], loc_mat[4][4];
+
+	pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
+
+	mult_m4_m4m4(outmat, rotscale_mat, inmat);
+	mul_v3_m4v3(outmat[3], loc_mat, inmat[3]);
+}
+
 /* Convert Pose-Space Location to Bone-Space Location
  * NOTE: this cannot be used to convert to pose-space location of the supplied
  * 		pose-channel into its local space (i.e. 'visual'-keyframing) 
@@ -2405,6 +2416,8 @@
 
 	/* Construct the posemat based on PoseChannels, that we do before applying constraints. */
 	/* pose_mat(b)= pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b) */
+	armature_mat_bone_to_pose(pchan, pchan->chan_mat, pchan->pose_mat);
+#if 0 /* XXX Old code, will remove this later. */
 	{
 		float rotscale_mat[4][4], loc_mat[4][4];
 		pchan_to_pose_mat(pchan, rotscale_mat, loc_mat);
@@ -2413,6 +2426,7 @@
 		/* Location. */
 		mul_v3_m4v3(pchan->pose_mat[3], loc_mat, pchan->chan_mat[3]);
 	}
+#endif
 
 	/* Only rootbones get the cyclic offset (unless user doesn't want that). */
 	/* XXX That could be a problem for snapping and other "reverse transform" features... */

Modified: trunk/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_conversions.c	2012-02-19 08:39:11 UTC (rev 44245)
+++ trunk/blender/source/blender/editors/transform/transform_conversions.c	2012-02-19 11:09:44 UTC (rev 44246)
@@ -409,7 +409,7 @@
 			}
 			for(;segcount;segcount--) {
 				Bone *bone;
-				float rmat[4][4], tmat[4][4], imat[4][4];
+				float rmat[4][4]/*, tmat[4][4], imat[4][4]*/;
 
 				/* pose_mat(b) = pose_mat(b-1) * offs_bone * channel * constraint * IK  */
 				/* we put in channel the entire result of rmat= (channel * constraint * IK) */
@@ -420,6 +420,8 @@
 				bone= parchan->bone;
 				bone->flag |= BONE_TRANSFORM;	/* ensures it gets an auto key inserted */
 
+	/* XXX Old code. Will remove it later. */
+#if 0
 				if(parchan->parent) {
 					Bone *parbone= parchan->parent->bone;
 					float offs_bone[4][4];
@@ -462,6 +464,8 @@
 				}
 				/* result matrix */
 				mult_m4_m4m4(rmat, imat, parchan->pose_mat);
+#endif
+				armature_mat_pose_to_bone(parchan, parchan->pose_mat, rmat);
 
 				/* apply and decompose, doesn't work for constraints or non-uniform scale well */
 				{




More information about the Bf-blender-cvs mailing list