HumanIK automation - deleting of Custom Rigs

amybuc6
Explorer

HumanIK automation - deleting of Custom Rigs

amybuc6
Explorer
Explorer

Hello!
I'm working on a bit of a python wrapper around humanIK for my particular pipeline - namely setting up a pre-defined custom Character rig Definition, a motion capture skeleton definition, swapping the motion source, and baking it - and it all works (yay!)

Except for one small thing. I'd like to be able to bake the motion only for a specific frame range, to preserve existing animation in the scene. The humanIK-specific mel bake command ('hikBakeCharacter') doesn't allow me to do that, and only accepts a character as a parameter - it just bakes the entire time slider range.

can use cmds.bakeSimulation to pass a frame range, but the resultant issue is that cmds bake Simulation is lacking the humanIK specific functions that I'm needing - namely, disentangling the rig from the constraints and additional quatToEuler/pairBlend/etc nodes that humanIK seems to use to retarget motion prior to it's bake process. So the motion bakes, but the rig is still unusable because it's still attached to humanIK.

The crux of the problem: 'hikDeleteCustomRig' does exactly what I want it to do, after I cmds.bakeSimulation, running it deletes the rig definition and detaches the rig from the constraints, but it gives a confirmation popup first - not ideal from a user-experience POV.

 

So my question, and the TLDR - is there a way to completely remove all humanIK-created nodes and constraints from a scene cleanly, preferably without a popup?

0 Likes
Reply
707 Views
4 Replies
Replies (4)

Kahylan
Advisor
Advisor

Hi!

 

So there are two ways I can think of to solve your problem.

 

1) You just delete all the HIK nodes directly.
You can target the nodes that are created by HIK by listing the incoming history for nodes of two specific types "HIKState2SK" and "HIKCharacterNode". Once you found all the nodes, you simply have to delete them.

import maya.cmds as mc


hikSpecificNodes =  mc.ls(type= ["HIKState2SK","HIKCharacterNode"])
hist = mc.listHistory(hikSpecificNodes)

mc.delete(hist)

Depending on your rig, you could also use the same method, by targeting the out of hierarchy constraints that connect your rig to HIK and deleting them as well as all of their incoming history.

But I'm not to sure how this will deal with the quatToEuler/pairBlend/etc nodes that you menitioned, as I'm not too familiar with retargeting with HIK.

 

2) This is a bit more hacky, but actually simpler. Since 'hikBakeCharacter' will just bake the current time slider range. You could just temporarily change the timeslider range and change it back once the baking process is complete:

#storing current start and end time

startT = mc.playbackOptions(q= True, ast = True)
endT = mc.playbackOptions(q= True, aet = True)

#setting new start and end time

mc.playbackOptions(e= True, ast = YourStartTime, est = YourEndTime)

#resetting the timeslider

mc.playbackOptions(e= True, ast = startT, est = endT)

The variables "YourStartTime" and "YourEndTime" would be the range you want to bake, taken from whatever function or UI you are using to determine that.

 

I hope it helps!

 

lee.dunham
Collaborator
Collaborator
Personally, I'd pick the 2nd option. Cleaner and should be more reliable.
0 Likes

amybuc6
Explorer
Explorer

Thank you for your help!! This gave me a bunch to try. I tried your second solution, which seemed like it should have worked - but unfortunately, even after setting a time range, hikBakeCharacter (Or, hikBakeCustomCharacter, as I was using it,) and it does only bake keys into frames on the time range! However, it deletes all other existing keyframes on the timeline, even outside the frame range set by the time slider. I wonder if it happens as a byproduct of the process whereby the constraints are added to retarget the motion before baking.

 

Either way, I ended up going with a pretty roundabout method, for anyone stumbling across this looking for a similar thing: Via code - I created a new temporary scene, imported the given mocap/rig assets, did the retarget, baked it and then copied the motion curves from the rig's controls. From there the tool would go back and open the scene with existing animation, the one the user wanted to tack the new motion onto, finds the next free frame and dumps the copied animation there.

Hacky, probably crazy overcomplicated, and almost certainly slower, but it works 🙂 

Thanks anyway for your help!

lee.dunham
Collaborator
Collaborator

If that's the case then a hacker but likely quicker option would be to bake, copy keyframes, undo rig deletion and paste.

0 Likes