theviolator Posted March 9, 2012 Share Posted March 9, 2012 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! Quote Link to comment Share on other sites More sharing options...
theviolator Posted March 9, 2012 Author Share Posted March 9, 2012 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... :/ Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted March 9, 2012 Share Posted March 9, 2012 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 Quote Link to comment Share on other sites More sharing options...
theviolator Posted March 10, 2012 Author Share Posted March 10, 2012 (edited) 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 March 10, 2012 by theviolator Quote Link to comment Share on other sites More sharing options...
theviolator Posted March 10, 2012 Author Share Posted March 10, 2012 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! Quote Link to comment Share on other sites More sharing options...
Netvudu Posted March 11, 2012 Share Posted March 11, 2012 yup, it´s a shame the Apprentice HD version doesn´t export FBX, only imports. Quote Link to comment Share on other sites More sharing options...
theviolator Posted March 12, 2012 Author Share Posted March 12, 2012 (edited) 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 March 12, 2012 by theviolator Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted March 15, 2012 Share Posted March 15, 2012 (edited) 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 March 15, 2012 by Stalkerx777 Quote Link to comment Share on other sites More sharing options...
theviolator Posted March 16, 2012 Author Share Posted March 16, 2012 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 Quote Link to comment Share on other sites More sharing options...
edward Posted March 18, 2012 Share Posted March 18, 2012 hou.frame() Quote Link to comment Share on other sites More sharing options...
theviolator Posted March 20, 2012 Author Share Posted March 20, 2012 still no joy... Quote Link to comment Share on other sites More sharing options...
goshone Posted May 2, 2012 Share Posted May 2, 2012 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) rbd_xfer_v01.hip Quote Link to comment Share on other sites More sharing options...
theviolator Posted May 3, 2012 Author Share Posted May 3, 2012 (edited) 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 Edited May 3, 2012 by theviolator Quote Link to comment Share on other sites More sharing options...
goshone Posted May 3, 2012 Share Posted May 3, 2012 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! Quote Link to comment Share on other sites More sharing options...
zeekindustries Posted October 5, 2013 Share Posted October 5, 2013 (edited) 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 October 5, 2013 by zeekindustries Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.