Jump to content
sschoellhammer

bake and composite textures script

Recommended Posts

Posted (edited)

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

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

×