Jump to content

create rig from RBD objects

Recommended Posts

Hello, I am wondering how i can take an object that i have fractured with glue constraints and sim'd and have Houdini automatically create a bone for each fractured object and skin weight it and bake the sim animation into the bones. I tried searching this forum and the interwebs and i'm not finding what i want.



Edited by zarralax

Share this post

Link to post
Share on other sites

Fracture Animation Export? I think that just exports an fbx for Unreal and Unity. I wanted bones to get created for me with auto rigging. 

Share this post

Link to post
Share on other sites

So I was able to use the RBDtoFBX from the Game Dev Toolset shelf to export my baked sim from Houdini into Maya. Then I was able to use this python script in Maya to automatically convert each object piece into a bone and have it auto skinned.

import maya.cmds as mc 
def bakeToSkeleton(): 
    #Set up selection 
    selection = mc.ls(sl = True)
    jointList = []
    locList = [] 
    duplicateList = [] 
    rootJoint = "rootJoint"
    #Create and attach Skeleton to meshes 
    if mc.objExists("rootJoint")==False: 
        rootJoint = "rootJoint"
        mc.joint(n=rootJoint, p=(0, 0, 0)) 
    for selected in selection: 
        if  "|" in selected: 
            nice_name = selected.split("|") 
            nice_name = nice_name[1] 
            nice_name = selected 
        locName = nice_name + "_Loc"
        jointName = nice_name + "_joint"
        mc.joint(n=jointName, p=(0, 0, 0)) 
        mc.parent(jointName, rootJoint) 
        mc.spaceLocator(n=locName, p=(0, 0, 0)) 
    #Bake Animation to joints and remove constraints 
    animStartTime = mc.playbackOptions(q=True, minTime=True) 
    animEndTime = mc.playbackOptions(q=True, maxTime=True) 
    currentFrame = animStartTime
    while(currentFrame <= animEndTime):
        i = 0
        while(i < len(locList)):
            currentT = mc.getAttr(locList[i] + ".translate")
            currentR = mc.getAttr(locList[i] + ".rotate")
            currentS = mc.getAttr(locList[i] + ".scale")
            mc.setKeyframe(jointList[i], at = "translateX", v = currentT[0][0])
            mc.setKeyframe(jointList[i], at = "translateY", v = currentT[0][1])
            mc.setKeyframe(jointList[i], at = "translateZ", v = currentT[0][2])
            mc.setKeyframe(jointList[i], at = "rotateX", v = currentR[0][0])
            mc.setKeyframe(jointList[i], at = "rotateY", v = currentR[0][1])
            mc.setKeyframe(jointList[i], at = "rotateZ", v = currentR[0][2])
            mc.setKeyframe(jointList[i], at = "scaleX", v = currentS[0][0])
            mc.setKeyframe(jointList[i], at = "scaleY", v = currentS[0][1])
            mc.setKeyframe(jointList[i], at = "scaleZ", v = currentS[0][2])
            i += 1
        mc.currentTime(currentFrame, e = True)
        currentFrame += 1
    #Duplicate and attach mesh to joints 
    i = 0
    while i<len(selection): 
        if "|" in selection[i]: 
            nice_dup_name = selection[i].split("|") 
            nice_dup_name = nice_dup_name[1] 
            nice_dup_name = selection[i] 
        dupName = nice_dup_name + "_baked"
        #mc.duplicate(selection[i], n= dupName) 
        shapes = mc.listRelatives(selection[i], s = True)
        tmp = mc.instance(shapes[0])
        mc.duplicate(tmp, n=dupName)
        mc.parent(dupName, world = True)
        mc.makeIdentity(apply = True)
        mc.select(dupName, jointList[i]) 
    #Collect and clean up scene
    for i in locList:
    mc.group("rootJoint", duplicateList, n="Baked Simulation Contents") 
    mc.setAttr("Baked_Simulation_Contents.sz",keyable = False,lock=True, channelBox = False) 
    mc.setAttr("Baked_Simulation_Contents.sy",keyable = False,lock=True, channelBox = False) 
    mc.setAttr("Baked_Simulation_Contents.sx",keyable = False,lock=True, channelBox = False) 
    mc.setAttr("Baked_Simulation_Contents.tz",keyable = False,lock=True, channelBox = False) 
    mc.setAttr("Baked_Simulation_Contents.ty",keyable = False,lock=True, channelBox = False) 
    mc.setAttr("Baked_Simulation_Contents.tx",keyable = False,lock=True, channelBox = False) 
    mc.setAttr("Baked_Simulation_Contents.rz",keyable = False,lock=True, channelBox = False) 
    mc.setAttr("Baked_Simulation_Contents.ry",keyable = False,lock=True, channelBox = False) 
    mc.setAttr("Baked_Simulation_Contents.rx",keyable = False,lock=True, channelBox = False) 
    for i in selection:
        print i 
    print "Baked Animation To Skeleton Conversion Done"


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now