I have 2 rigs with the exact same bone topology, but with different rest poses, see left image below. The T-Pose Rig is displayed in green, the A-Pose rig is displayed in black. Now i want to align the pose bones of the T-pose rig to the edit bones of the A-Pose rig as shown in the right image below.:
I tried to do this by copying the edit_bone.matrix values of the A-Pose rig to the pose bone matrices of the T-Pose rig and on first sight this seems to work perfectly (if all bones are disconnected).
#Assume the context.object is the t_rig
for bone in t_rig.pose.bones:
bone.matrix = a_rig.data.bones[bone.name].matrix_local
#need to do this, not sure why:
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='POSE')
But...
I have a problem with the Bone Roll. Here is what happens on the upper arm bone in my example:
For the T-Pose Rig the bone roll z-axis of the arm bones is aligned to the world z-axis, while for the A-Pose rig the bone roll is rotated by 45 degree:
So, when i simply copy the bone matrices, then the bone rolls gets rotated as well. But this has an undesired impact on the bound meshes: the mesh gets rotated with the bone roll:
What i really want to achieve is to copy the matrices without changing the longitudinal rotation of the bones so that the arms are not rotated:
One way to do this is by working through the T-pose rig from top to bottom and for each pose bone do:
- move the pose bone head to the corresponding location on the A-Pose rig
- Calculate the rotation difference between the pose bone on the t-pose rig and the edit_bone on the a-pose rig
- Apply the rotation difference to the pose bone on the T-Pose rig.
However i wonder if there is a better way to align the pose bones of one rig to the edit bones of another rig and keeping the longitudinal bone rotation unchanged.