From 5cd85ed57ea649c58c7c19d709bfc4cae7fffcad Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 19 Feb 2012 11:09:44 +0000 Subject: 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. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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’s just impossible to make conversion code...). So I'll wait and investigate more for this one. --- source/blender/blenkernel/intern/armature.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/blender/blenkernel/intern/armature.c') diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 02b9330d588..036116c54da 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1302,6 +1302,17 @@ void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outm 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 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti /* 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 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti /* 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... */ -- cgit v1.2.3