Fix T73598: Pose options - Auto IK. Bones move on release

The issue was that the code tried to use the bones transformation matrix
as a rotation matrix. This works fine as long as the scale is 1.

Now we simply make sure that we only get a pure rotation matrix when
extracting it for the bone's transformation matrix.
This commit is contained in:
Sebastian Parborg 2020-04-07 13:12:14 +02:00
parent 9fca9b9953
commit c4def7992b
Notes: blender-bot 2023-02-14 05:43:04 +01:00
Referenced by issue #73598, Pose options - Auto IK. Bones move on release
1 changed files with 10 additions and 8 deletions

View File

@ -377,23 +377,25 @@ static short apply_targetless_ik(Object *ob)
}
for (; segcount; segcount--) {
Bone *bone;
float rmat[4][4] /*, tmat[4][4], imat[4][4]*/;
float mat[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) */
/* pose_mat(b) = pose_mat(b-1) * offs_bone * rmat */
/* rmat = pose_mat(b) * inv(pose_mat(b-1) * offs_bone ) */
/* we put in channel the entire result of mat = (channel * constraint * IK) */
/* pose_mat(b) = pose_mat(b-1) * offs_bone * mat */
/* mat = pose_mat(b) * inv(pose_mat(b-1) * offs_bone ) */
parchan = chanlist[segcount - 1];
bone = parchan->bone;
bone->flag |= BONE_TRANSFORM; /* ensures it gets an auto key inserted */
BKE_armature_mat_pose_to_bone(parchan, parchan->pose_mat, rmat);
BKE_armature_mat_pose_to_bone(parchan, parchan->pose_mat, mat);
/* apply and decompose, doesn't work for constraints or non-uniform scale well */
{
float rmat3[3][3], qrmat[3][3], imat3[3][3], smat[3][3];
copy_m3_m4(rmat3, rmat);
copy_m3_m4(rmat3, mat);
/* Make sure that our rotation matrix only contains rotation and not scale. */
normalize_m3(rmat3);
/* rotation */
/* [#22409] is partially caused by this, as slight numeric error introduced during
@ -413,7 +415,7 @@ static short apply_targetless_ik(Object *ob)
/* causes problems with some constraints (e.g. childof), so disable this */
/* as it is IK shouldn't affect location directly */
/* copy_v3_v3(parchan->loc, rmat[3]); */
/* copy_v3_v3(parchan->loc, mat[3]); */
}
}