i have programmed a retarget operator in python, but it needs dozens of depsgraph updates while calculating a single pose, so its super slow. I have a code snippet here:
for tpbone in arm.pose.bones:
matrix = retarget(...) #transfer the pose matrix
tpbone.matrix = matrix
depsgraph.update() # needed to recalculate matrix for all pose bones
def retarget(src_rig, src_pose_bone,
tgt_rig, tgt_pose_bone):
scpbm = src_pose_bone.matrix
scdbm = src_pose_bone.bone.matrix_local
tcdbm = tgt_pose_bone.bone.matrix_local
sm_world = src_rig.matrix_world
sm_apply_rotscale = sm_world.inverted()
sm_apply_rotscale.translation=((0,0,0))
tm_world = tgt_rig.matrix_world
tm_apply_rotscale = tm_world.inverted()
tm_apply_rotscale.translation=((0,0,0))
SD = sm_world @ scdbm @ sm_apply_rotscale
TD = tm_world @ tcdbm @ tm_apply_rotscale
SP = sm_world @ scpbm @ sm_apply_rotscale
Q = SD.to_quaternion().rotation_difference(TD.to_quaternion())
ROT = Q.to_matrix().to_4x4()
matrix = SP @ ROT
return matrix
When i do not call depsgraph.update then the matrix data returned by the retarget() function is wrong. However, can i avoid the depsgraph updates to make this run faster?
numpyandpose.bones.foreach_get / setBit hard to do too much from info given. – batFINGER Sep 29 '21 at 11:57Object.convert_spacefor bone matrix calcd across objects. https://blender.stackexchange.com/a/109852/15543 – batFINGER Sep 29 '21 at 15:14