Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

theviolator

Houdini RBD to Maya

I know this has been discussed probably hundred times already, but I still could't find a viable answer.

It has been always tricky to export dynamics sims and bake the transforms to keyframes in Houdini. I have done it before but I can't seems to make it work now, and I know I'm probably

doing something stupid, so if anybody remembers, please tell me, because I'm pulling my hair already over this.

So, basically what I'm doing is creating an RBD sim, using a fetch node to get the transforms from the AutoDopNetwork, then in chopnet, have a dynamic node of course and an object

node which has the target object as the fetch node, connected to export node pointing to my simulated object (at scene level) with Path set to (t? r?).

The thing is that this combo works fine with one object, but...oh boy try to pass the transforms to more than one object, it gets confused and produces anything but correct output.

I have tried anything that came to mind /obj/box_object[1,2] /obj/box_object[1-2] /obj/box_object* .....nothing works, basically the problem is in the export node, if you just specify

/obj/box_object1 it passes the transforms correctly to the object and bakes (correctly) the t[xyz] and r[xyz].

Any ideas?

Thanks in advance!

Share this post


Link to post
Share on other sites

Actually it works with two export nodes connected to the object node (in Chopnet), but I can't imagine having hundreds of objects and connecting that many export nodes, has to be a better way... :/

Share this post


Link to post
Share on other sites

Some time ago, i had the same task. Well, it's easy doable with python script.

The basic idea:

1)Iterate over all dop objects

2)Get transform matrix

3)Set this transform matrix back to obj level and set keyframes on channels.

4)Write out .chan files

5)Read .chan files in maya

Step By Step:

--Get DOP Net

DOPNET = hou.node("/obj/dopnet0")
SIM = DOPNET.simulation()

--Get list of all objects, you need to keyframe, for example from selection.

(Note, we did'n check for valid selection)

obj_to_export = hou.selectedNodes()

--Now get data from dops:

F_START = 1
F_END = 100
for obj in obj_to_export:
    hou.setFrame(F_START)
    while hou.frame() <= F_END:
        t_parm = obj.parmTuple("t")
        r_parm = obj.parmTuple("r")
        for t,r,i in zip(t_parm,r_parm,range(3)):
            ## Keyframe object##
            keyframe_r = hou.Keyframe()
            keyframe_t = hou.Keyframe()
            r_parm[i].setKeyframe(keyframe_r)
            t_parm[i].setKeyframe(keyframe_t)

        dopOBJ = SIM.findObject(obj.name())
        dopMatrix = dopOBJ.transform()
        obj.setWorldTransform(dopMatrix)          

        hou.setFrame(hou.frame()+1)

   status = hou.hscript("chwrite -f {0} {1} {2}/r? {2}/t? {3}/{4}.chan".format(F_START,F_END,obj.path(),CHAN_PATH,obj.name()))
   print status
   # CHAN_PATH - where to place .chan files ($JOB/chan)

--Maya can read .chan files with movin command:

CHAN_PATH = "/mnt/proj/chan"
sel = ls(sl=1)
for obj in sel:
    xform(obj,piv=(0,0,0))
    obj_noNameSpace = obj.replace(":","_")  ## Temporary namespace fix (don't remember why is that 
    chanName = "%s/%s.chan" % (CHAN_PATH,obj_noNameSpace)
    movIn("%s.rx"%obj,"%s.ry"%obj,"%s.rz"%obj,"%s.tx"%obj,"%s.ty"%obj,"%s.tz"%obj,f=chanName)

That's it. Pretty rough solution, but works fine. Hope it helps B)

Share this post


Link to post
Share on other sites

WOW, It works, except the simulation jumps to the center of the grid. I know this has to do with the transforms in the DOP network.

So, basically if you copy the transforms of the objects on scene level and paste them into the same object in the DOP network (paste copied relative references) it will sim correctly. How do you solve this thou? Do you have another python script for that, imagine you have to do that for hundreds of objects.

Thanks a lot man! Great help.

P.S. Strange, coping the transforms didn't work this time. The simulation still jumped to the center of the grid :(

Edited by theviolator

Share this post


Link to post
Share on other sites

I got it :) Just had to zero the transforms before I sim. It works like a charm!

Kudos man, very few people are willing to share their python scripts, you rock! ;)

By the way, you can simply use FBX export back to Maya, it preserves the UVs and so on, no need to write out chan files, unless for some reason you don't want to use those objects (I don't

see why though, they are exactly the same).

Thanks, again!

Share this post


Link to post
Share on other sites

yup, it´s a shame the Apprentice HD version doesn´t export FBX, only imports.

Share this post


Link to post
Share on other sites

Well...there's one flaw with this script though, when having hundreds of objects in the sim, it goes through one by one running the whole sim over and over again until keys all the objects.

This can easily take a day, I'm not kidding. It would be better though if you can key all the selected objects simultaneously, running the simulation only once.

Edited by theviolator

Share this post


Link to post
Share on other sites

Well...there's one flaw with this script though, when having hundreds of objects in the sim, it goes through one by one running the whole sim over and over again until keys all the objects.

This can easily take a day, I'm not kidding. It would be better though if you can key all the selected objects simultaneously, running the simulation only once.

Yes, it can take much time. This was temporary solution for me, and it works at that moment. Right now, every object runs trough all frames, which is not good....To speed things up, we can fix code a little bit to let it loop over all objects in one frame step:

while frame < end_frame:
    hou.setFrame(0)
    for obj in obj_to_export:
        #Extract transform and so on

Edited by Stalkerx777

Share this post


Link to post
Share on other sites

Yes, it can take much time. This was temporary solution for me, and it works at that moment. Right now, every object runs trough all frames, which is not good....To speed things up, we can fix code a little bit to let it loop over all objects in one frame step:

while frame < end_frame:
    hou.setFrame(0)
    for obj in obj_to_export:
        #Extract transform and so on

Hmm....there's something wrong with the code, I inserted it like this:

F_START = 1

F_END = 100

for obj in obj_to_export:

while hou.frame < F_END:

hou.setFrame(0)

Couldn't get it to work :(

Share this post


Link to post
Share on other sites

So I was able to get this working with some tinkering. The script was relatively easy, simply needed to work out the loops. A bigger issue was how to get the object to transform correctly before and after baking the keyframes. The solution was to set the initial state of the RBDs to be the transform values of the original objects, and uncheck the "Use object transform" option. This would start the RBDs in the right world space so you get corresponding keyframe values. The I had some strange bug that caused the houdini python session window to not run the script properly. I included a file which has the script in the python session window. You just need to delete the last comment and accept to get the script to refresh for whatever reason. Then just select your objects and run

hou.session.simToKeys()

in the python terminal. I didn't include the writing of the chan files, but I think you could easily add that, and encapsulate it into a better external script.

cheers

G1

ps. here is the code

def simToKeys(obj_to_export = hou.selectedNodes()):
    DOPNET = hou.node("/obj/AutoDopNetwork")
    SIM = DOPNET.simulation()
    F_START = 1
    F_END = 100
    frm = 1.0
    while frm &lt;= F_END:
        hou.setFrame(frm)    
        for obj in obj_to_export:
            t_parm = obj.parmTuple("t")
            r_parm = obj.parmTuple("r")
            for t,r,i in zip(t_parm,r_parm,range(3)):
                ## Keyframe object##
                keyframe_r = hou.Keyframe()
                keyframe_t = hou.Keyframe()
                r_parm[i].setKeyframe(keyframe_r)
                t_parm[i].setKeyframe(keyframe_t)

            dopOBJ = SIM.findObject(obj.name())
            dopMatrix = dopOBJ.transform()
            obj.setWorldTransform(dopMatrix)

            ### delete this comment ###

        frm = (frm+1)

rbd_xfer_v01.hip

Share this post


Link to post
Share on other sites

Hey man,

its not working! I dont know how you got it to work only with those two lines...

First off.. you need to get to the DOP network, the script before ---> DOPNET = hou.node("/obj/AutoDopNetwork")

SIM = DOPNET.simulation()

Then... you say, just select your object and execute ----> hou.session.simToKeys()

I think it should be ----> obj_to_export = hou.selectedNodes()

Then when I paste the script in the python window, nothing happens..no error but no keying either :(

and for the file attachment, cant open it, it asks for "Apprentice License?"

Im sure Im not doing it right, so please enlighten me :P

Edited by theviolator

Share this post


Link to post
Share on other sites

Then when I paste the script in the python window, nothing happens..no error but no keying either :(

The reason nothing happens when you paste the script is because all this script is doing is defining a procedure, which you have to call to execute. I didn't have much luck pasting the code into the python shell because the formatting got thrown off in the previous post, but you could save it as an external script in your python path, import it (eg. import simToKeys as stk ) and select your objects and run the script (eg. stk.simToKeys() )

Now this is hard coding the name of the DopNetwork, so modify for your own uses of course.

I'm not sure why the file isn't working, but that has the script contained in the file via the python source window (houdini python session), which is rather convenient for changing names of the autodop for example, but beware of the bug I mentioned previously.

good luck!

Share this post


Link to post
Share on other sites

Hello!!!

First of all, thanks a lot goshone for the script it really is a timesaver and does very well a feature that should a one click within houdini in my opinion. I have however come across some dificulties, and the thing is that whenever I want to export the simulated (and now keyframed objects) in an FBX format so I can import them in Maya, every value that was keyframed shows up in maya multiplied by .5, say, if the TX position in Houdini was 10, in Maya it is 5, and this stays true for Scale, Rotation and such.

I have tried to do some Houdini Python research, but I just can't figure out how could I multiply by 2 the values that are written for each keyframe, is there anyway to access those values?

Also whenever I export them I have a warning that says: Untied Keyframes - This is not supported, anyone has some idea why this is ocurring?

Edited by zeekindustries

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