transform parent PoseBone without affecting the child PoseBone?

I use PoseBone.localMatrix to assign animation matrices from my animation files. All works fine until I assign them to Armatures which have bone hierarchies (child/parent) bones. In that case transforming the parents also transforms the children, which get their own transforms (poseMatrices) as well and I end up with corrupt animations.

So how to assign matrices to parent PoseBones without them “dragging their children” with them?

(using 2.49 API, will switch soon, but names should be the same)

how about calculating proper relative matrices for children?

i believe this is how 2.63 BVH addon does…

I’m not so good at the whole matrix math thing but my guess is you’d have to apply the inverse transform to the children to ‘undo’ the transform they inherit from the parent…somehow.

I posted the bone snapping code in another thread. This can be used here. Snap dummy bones to the children, transform the parent, snap the children back to the dummies.

maybe this is not clear enough how to solve this riddle?
Like batFINGER notes, this sample shows how to do it and “the only thing is now to do it without a helper bone”.
So the way is to look into this code-sample, check the way the matrix are calculated and use the matrizes to do the adjustment without a helper-bone.
Sounds easy, but needs a good knowledge of those matrix-calculations and this is not the same like normal numeric math. There are math-samples about this without armature-bones in normal math-lessons. It is always the transformation from one 3D-coord-system to another one done with matrix-calculations.

I’d much rather try a matrix math solution and keep the dublicating bones idea for last, as that would mean more confusing code and messed up armature with placeholder bones if error occurs in the middle of the script (happens).

To get the local space matrix, you multiply global space matrix with the inverse of the parent’s global space matrix. If bone has no parent, global space matrix equals to local space matrix.
But kinda confusing when you need more multiplication for animation matrices.

This works (bones have no parent):


# myMatrix is the animation matrix read from the file
bone_matrix_inverse = armature.bones['bonename'].matrix['ARMATURESPACE'].copy().invert()
pose.bones['bonename'].localMatrix = myMatrix * bone_matrix_inverse

This doesn’t (bones have parent):


# myMatrix is the animation matrix read from the file
bone_matrix_inverse   = armature.bones['bonename'].matrix['ARMATURESPACE'].copy().invert()
parent_matrix_inverse = armature.bones['bonename'].parent.matrix['ARMATURESPACE'].copy().invert()

pose.bones['bonename'].localMatrix = myMatrix * bone_matrix_inverse * parent_matrix_inverse