Hello,
I have an animated armature whose rest position doesn’t match my model’s position; I’m working on a script to modify the rest position without affecting the animation. Apparently, this has been attempted several times before, with less-than-ideal results.
The idea is to have a functionality similar to the “Apply Pose as Rest Pose” feature, but without changing the armature in any way. The steps are:
- Get the orientation of each bone in Pose mode, then in Edit mode.
- Retrieve the difference between the orientations.
- Apply the resulting rotation in Edit mode.
- Apply the rotation in Pose mode, once for every frame.
Right now I’m testing with a single bone. Here is my current script:
## This assumes the armature has just been selected
armature = bpy.context.active_object;
## Edit bone orientation
bpy.ops.object.mode_set( mode = 'EDIT' );
editBone = armature.data.edit_bones[0];
qEdit = editBone.matrix.to_quaternion().copy(); # q1
## Pose bone orientation (for the current frame)
bpy.ops.object.mode_set( mode = 'POSE' );
armature.data.pose_position = "POSE";
poseBones = armature.pose.bones;
poseBone = poseBones[0];
qPose = poseBone.matrix.to_quaternion().copy(); # q2
## Difference between orientations
qDif = qEdit.rotation_difference( qPose );
I’m not sure where to go from here. I can’t change the edit bone’s “matrix” property because it’s read-only. I’ve also tried adding this at the end:
matDif = qDif.to_matrix();
editBone.transform( matrix = matDif );
but the second line consistently makes Blender crash for some reason.
This is the method I’m trying right now, but I’m fairly new to Python scripting. If anyone knows an easier way, I’d be very interested.
How can I modify an armature’s rest pose without altering the transformations in its animation?