Jump to content

bake and composite textures script


sschoellhammer

Recommended Posts

Hello there!

I'm trying to bake textures for a directory full of models. I'm rendering some types (occlusion and curvature in this case)

and I also want to composite those 2 into one map while I'm at it.

I got all the parts working in my scene and set values with this script accordingly:

 

import os
import hou

root = 'E:/Items/'

fbxs = []
for root, dirs, files in os.walk(root):
    for f in files:
        if f.endswith(".fbx"):
            fbxs.append(os.path.join(root,f))


importNode = hou.node('/obj/geo1/import');
bakeNode = hou.node('out/baketexture1');

temp_dir = 'E:/temp'

for fbx in fbxs:
    importNode.parm('file').set(fbx)   
    outputFilepath = os.path.join(temp_dir, os.path.split(fbx)[1].replace('.fbx','.png'))
    
    print('Baking: ' + outputFilepath)
    bakeNode.render();
    compnode = hou.node('img/img1/composite_channels')    
    compnode.parm('copoutput').set(outputFilepath)
    print ('Comping')
    compnode.render()

My problem is that the comp rop is executing without waiting for the bake to finish.

I tried several things..

Using a post-render script that i would modify to set the outputfilename the comp node should use, something like this:

post_script_t = """
import hou
compnode = hou.node('img/img1/composite_channels')    
compnode.parm('copoutput').set(\"outputFilepath\")
compnode.render()
"""

but then it seems the script cannot find the comp node (do these render scripts have a different environment?) 

I tried checking for the resulting bakes to continue once the files are there but if I do something like this:

bakeNode.render();
    # wait for the textures
    while(True):
        time.sleep(5)
        if os.path.exists(f1) and os.path.exists(f2):
            break;

the bake  doesn't even seem to start.

Mmh, my last resort would be to do the whole thing in 2 passes, first baking, then compositing but I was curious what's the best 

solution here :)

 

Thanks for any enlightenment!

Seb

PS: first time python in houdini - it's awesome! 

 

 

Edited by sschoellhammer
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...