I’m working on a tool that snaps FK bones to the corresponding IK bones. The code for the arm looks something like this:
matchPoseRotation(uparmFk, uparmIk)
updatePose(uparmFk)
matchPoseRotation(loarmFk, loarmIk)
updatePose(loarmFk)
matchPoseRotation(handFk, handIk)
The matchPoseTransform function sets the posebone’s base matrix (posebone.matrix_basis), and uses its parent’s matrix in global space (posebone.parent.matrix). Therefore we must update the parent’s matrix before doing the calculations for the child. One can do that by forcing a scene update, e.g. by defining
def updatePose(posebone):
deps = bpy.context.evaluated_depsgraph_get()
deps.update()
or the old-fashioned way:
def updatePose(posebone):
bpy.ops.object.posemode_toggle()
bpy.ops.object.posemode_toggle()
These methods work, but the problem is that they update the entire scene, and since I call updatePose many times this takes a very long time. Is there a faster way of doing it? I don’t need to update the entire scene, or even the armature, but only the specified posebone.