Jump to content


Houdini RBD to Maya


  • Please log in to reply
14 replies to this topic

#1 theviolator

theviolator

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 04-October 10
  • Name:Spline Monkey

Posted 08 March 2012 - 06:15 PM

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!

#2 theviolator

theviolator

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 04-October 10
  • Name:Spline Monkey

Posted 08 March 2012 - 06:35 PM

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... :/

#3 Stalkerx777

Stalkerx777

    Initiate

  • Members
  • PipPip
  • 221 posts
  • Joined: 09-June 08
  • Location:Russia, Moscow
  • Name:Alexey Rusev(Sadroutdinov)

Posted 09 March 2012 - 03:53 AM

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 <img src='http://forums.odforce.net/public/style_emoticons/<#EMO_DIR#>/smile.gif' class='bbc_emoticon' alt=':)' />
    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)

#4 theviolator

theviolator

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 04-October 10
  • Name:Spline Monkey

Posted 09 March 2012 - 09:33 PM

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, 10 March 2012 - 01:22 AM.


#5 theviolator

theviolator

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 04-October 10
  • Name:Spline Monkey

Posted 10 March 2012 - 01:37 AM

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!

#6 Netvudu

Netvudu

    Houdini Master

  • Members
  • PipPipPipPip
  • 913 posts
  • Joined: 24-May 06
  • Location:Barcelona, Spain
  • Name:Javier Meroño

Posted 11 March 2012 - 05:45 AM

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

#7 theviolator

theviolator

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 04-October 10
  • Name:Spline Monkey

Posted 11 March 2012 - 10:13 PM

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, 11 March 2012 - 10:13 PM.


#8 Stalkerx777

Stalkerx777

    Initiate

  • Members
  • PipPip
  • 221 posts
  • Joined: 09-June 08
  • Location:Russia, Moscow
  • Name:Alexey Rusev(Sadroutdinov)

Posted 15 March 2012 - 09:10 AM

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, 15 March 2012 - 09:13 AM.


#9 theviolator

theviolator

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 04-October 10
  • Name:Spline Monkey

Posted 16 March 2012 - 02:03 AM

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 :(

#10 edward

edward

    Grand Master

  • Members
  • PipPipPipPipPip
  • 3,833 posts
  • Joined: 10-September 02
  • Name:e.d.w.a.r.d. .

Posted 18 March 2012 - 12:00 PM

hou.frame()
don't panic!

#11 theviolator

theviolator

    Peon

  • Members
  • Pip
  • 25 posts
  • Joined: 04-October 10
  • Name:Spline Monkey

Posted 19 March 2012 - 11:53 PM

still no joy... :(

#12 goshone

goshone

    Peon

  • Members
  • Pip
  • 39 posts
  • Joined: 12-January 09
  • Name:Josh Hatton

Posted 01 May 2012 - 10:27 PM

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 <= 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)

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users