diff options
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 62 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 41 |
2 files changed, 54 insertions, 49 deletions
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 922ac3fd3a4..36646c85dc1 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1129,6 +1129,24 @@ void armature_loc_world_to_pose(Object *ob, float *inloc, float *outloc) copy_v3_v3(outloc, nLocMat[3]); } +/* Simple helper, computes the offset bone matrix. + * offs_bone = yoffs(b-1) + root(b) + bonemat(b). + * Not exported, as it is only used in this file currently... */ +static void get_offset_bone_mat(Bone *bone, float offs_bone[][4]) +{ + if (!bone->parent) + return; + + /* Bone transform itself. */ + copy_m4_m3(offs_bone, bone->bone_mat); + + /* The bone's root offset (is in the parent's coordinate system). */ + copy_v3_v3(offs_bone[3], bone->head); + + /* Get the length translation of parent (length along y axis). */ + offs_bone[3][1] += bone->parent->length; +} + /* Construct the matrices (rot/scale and loc) to apply the PoseChannels into the armature (object) space. * I.e. (roughly) the "pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b)" in the * pose_mat(b)= pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b) @@ -1157,16 +1175,9 @@ void pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float loc_m parchan = pchan->parent; if (parchan) { - float offs_bone[4][4]; /* yoffs(b-1) + root(b) + bonemat(b). */ - - /* Bone transform itself. */ - copy_m4_m3(offs_bone, bone->bone_mat); - - /* The bone's root offset (is in the parent's coordinate system). */ - copy_v3_v3(offs_bone[3], bone->head); - - /* Get the length translation of parent (length along y axis). */ - offs_bone[3][1] += parbone->length; + float offs_bone[4][4]; + /* yoffs(b-1) + root(b) + bonemat(b). */ + get_offset_bone_mat(bone, offs_bone); /* Compose the rotscale matrix for this bone. */ if ((bone->flag & BONE_HINGE) && (bone->flag & BONE_NO_SCALE)) { @@ -1297,25 +1308,31 @@ void pchan_to_pose_mat(bPoseChannel *pchan, float rotscale_mat[][4], float loc_m * pose-channel into its local space (i.e. 'visual'-keyframing) */ void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outmat[][4]) { - float rotscale_mat[4][4], loc_mat[4][4]; + float rotscale_mat[4][4], loc_mat[4][4], inmat_[4][4]; + + /* Security, this allows to call with inmat == outmat! */ + copy_m4_m4(inmat_, inmat); pchan_to_pose_mat(pchan, rotscale_mat, loc_mat); invert_m4(rotscale_mat); invert_m4(loc_mat); - mult_m4_m4m4(outmat, rotscale_mat, inmat); - mul_v3_m4v3(outmat[3], loc_mat, inmat[3]); + mult_m4_m4m4(outmat, rotscale_mat, inmat_); + 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]; + float rotscale_mat[4][4], loc_mat[4][4], inmat_[4][4]; + + /* Security, this allows to call with inmat == outmat! */ + copy_m4_m4(inmat_, inmat); 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]); + mult_m4_m4m4(outmat, rotscale_mat, inmat_); + mul_v3_m4v3(outmat[3], loc_mat, inmat_[3]); } /* Convert Pose-Space Location to Bone-Space Location @@ -1546,16 +1563,9 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone) } if (prevbone) { - float offs_bone[4][4]; /* yoffs(b-1) + root(b) + bonemat(b) */ - - /* bone transform itself */ - copy_m4_m3(offs_bone, bone->bone_mat); - - /* The bone's root offset (is in the parent's coordinate system) */ - copy_v3_v3(offs_bone[3], bone->head); - - /* Get the length translation of parent (length along y axis) */ - offs_bone[3][1] += prevbone->length; + float offs_bone[4][4]; + /* yoffs(b-1) + root(b) + bonemat(b) */ + get_offset_bone_mat(bone, offs_bone); /* Compose the matrix for this bone */ mult_m4_m4m4(bone->arm_mat, prevbone->arm_mat, offs_bone); diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 833f14ff074..e8c6ec8d3ed 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -223,6 +223,7 @@ void constraints_clear_evalob (bConstraintOb *cob) /* -------------- Space-Conversion API -------------- */ +#if 0 /* XXX Old code, does the same as one in armature.c, will remove it later. */ static void constraint_pchan_diff_mat(bPoseChannel *pchan, float diff_mat[4][4]) { if (pchan->parent) { @@ -265,7 +266,7 @@ static void constraint_pchan_diff_mat(bPoseChannel *pchan, float diff_mat[4][4]) copy_m4_m4(diff_mat, pchan->bone->arm_mat); } } - +#endif /* This function is responsible for the correct transformations/conversions * of a matrix from one space to another for constraint evaluation. @@ -273,7 +274,6 @@ static void constraint_pchan_diff_mat(bPoseChannel *pchan, float diff_mat[4][4]) */ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4], short from, short to) { - float tempmat[4][4]; float diff_mat[4][4]; float imat[4][4]; @@ -290,8 +290,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 { /* world to pose */ invert_m4_m4(imat, ob->obmat); - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, imat, tempmat); + mult_m4_m4m4(mat, imat, mat); /* use pose-space as stepping stone for other spaces... */ if (ELEM(to, CONSTRAINT_SPACE_LOCAL, CONSTRAINT_SPACE_PARLOCAL)) { @@ -304,32 +303,31 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 { /* pose to world */ if (to == CONSTRAINT_SPACE_WORLD) { - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, ob->obmat, tempmat); + mult_m4_m4m4(mat, ob->obmat, mat); } /* pose to local */ else if (to == CONSTRAINT_SPACE_LOCAL) { if (pchan->bone) { + armature_mat_pose_to_bone(pchan, mat, mat); +#if 0 /* XXX Old code, will remove it later. */ constraint_pchan_diff_mat(pchan, diff_mat); invert_m4_m4(imat, diff_mat); - - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, imat, tempmat); + mult_m4_m4m4(mat, imat, mat); /* override with local location */ if ((pchan->parent) && (pchan->bone->flag & BONE_NO_LOCAL_LOCATION)) { armature_mat_pose_to_bone_ex(ob, pchan, pchan->pose_mat, tempmat); copy_v3_v3(mat[3], tempmat[3]); } +#endif } } /* pose to local with parent */ else if (to == CONSTRAINT_SPACE_PARLOCAL) { if (pchan->bone) { invert_m4_m4(imat, pchan->bone->arm_mat); - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, imat, tempmat); + mult_m4_m4m4(mat, imat, mat); } } } @@ -339,10 +337,12 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 /* local to pose - do inverse procedure that was done for pose to local */ if (pchan->bone) { /* we need the posespace_matrix = local_matrix + (parent_posespace_matrix + restpos) */ + armature_mat_bone_to_pose(pchan, mat, mat); +#if 0 constraint_pchan_diff_mat(pchan, diff_mat); - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, diff_mat, tempmat); + mult_m4_m4m4(mat, diff_mat, mat); +#endif } /* use pose-space as stepping stone for other spaces */ @@ -357,8 +357,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 /* local + parent to pose */ if (pchan->bone) { copy_m4_m4(diff_mat, pchan->bone->arm_mat); - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, tempmat, diff_mat); + mult_m4_m4m4(mat, mat, diff_mat); } /* use pose-space as stepping stone for other spaces */ @@ -378,8 +377,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 /* 'subtract' parent's effects from owner */ mult_m4_m4m4(diff_mat, ob->parent->obmat, ob->parentinv); invert_m4_m4(imat, diff_mat); - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, imat, tempmat); + mult_m4_m4m4(mat, imat, mat); } else { /* Local space in this case will have to be defined as local to the owner's @@ -390,17 +388,15 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 zero_v3(diff_mat[3]); invert_m4_m4(imat, diff_mat); - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, imat, tempmat); + mult_m4_m4m4(mat, imat, mat); } } else if (from==CONSTRAINT_SPACE_LOCAL && to==CONSTRAINT_SPACE_WORLD) { /* check that object has a parent - otherwise this won't work */ if (ob->parent) { /* 'add' parent's effect back to owner */ - copy_m4_m4(tempmat, mat); mult_m4_m4m4(diff_mat, ob->parent->obmat, ob->parentinv); - mult_m4_m4m4(mat, diff_mat, tempmat); + mult_m4_m4m4(mat, diff_mat, mat); } else { /* Local space in this case will have to be defined as local to the owner's @@ -410,8 +406,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 normalize_m4(diff_mat); zero_v3(diff_mat[3]); - copy_m4_m4(tempmat, mat); - mult_m4_m4m4(mat, diff_mat, tempmat); + mult_m4_m4m4(mat, diff_mat, mat); } } } |