0
$\begingroup$

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?

$\endgroup$
5
  • $\begingroup$ Investigate usage of numpy and pose.bones.foreach_get / set Bit hard to do too much from info given. $\endgroup$
    – batFINGER
    Sep 29, 2021 at 11:57
  • $\begingroup$ @batFINGER i have added the retarget function that i use. Does this give a clue for why omitting the depsgraph.update() returns bad matrix data ? I am not sure how i could use numpy here or the foreach... functions. $\endgroup$
    – Gaia Clary
    Sep 29, 2021 at 15:04
  • $\begingroup$ Not sure. Bit different to what i imagined. Generally use Object.convert_space for bone matrix calcd across objects. blender.stackexchange.com/a/109852/15543 $\endgroup$
    – batFINGER
    Sep 29, 2021 at 15:14
  • $\begingroup$ well, my way to get the matrix works reliably when i call depsgraph.update() after calculating the matrix. So the question is: does your method avoid calling the depsgraph.update() function ? I suspect that it might get called from the convert_space() function. If that is the case, then then it would not help to speed up the retarget. $\endgroup$
    – Gaia Clary
    Sep 29, 2021 at 15:46
  • $\begingroup$ Doubt very much that convert space, which simply creates a matrix calls an update. (btw wasn't putting forward comment as an answer to question) ...although imagine it would be quicker. A hierarchical approach, leaf nodes up could reduce number of updates. $\endgroup$
    – batFINGER
    Sep 29, 2021 at 15:56

0

You must log in to answer this question.

Browse other questions tagged .