Jump to content
Sign in to follow this  
Atom

Lops To Obj Lights

Recommended Posts

Posted (edited)

With the Karma ROP available in the /out context, I wanted to conduct a few test renders to compare Lops Karma with Sops Karma.

Here is a /out/karma1 render of the patchwork pig that Konstantin presented with the lights extracted from Lops.

km_pig_patchwork.thumb.jpg.1a37df51631797b8706a76dad35423b8.jpg

You can place this short script in a shelf tool. It tries to extract the lights from Lops and generate companion ones in Sops.

# Scan the /stage context for any lights and create companion lights in /obj.
# Atom 01-06-2022

import hou, re

def returnValidHoudiniNodeName(passedItem):
    # Thanks to Graham on OdForce for this function!
    # Replace any illegal characters for node names here.
    return re.sub("[^0-9a-zA-Z\.]+", "_", passedItem)

def childrenOfNode(node, filter):
    # Return nodes of type matching the filter (i.e. geo etc...).
    result = []
    if node != None:
        for n in node.children():
            t = str(n.type())
            if t != None:
                for filter_item in filter:
                    if (t.find(filter_item) != -1):
                        # Filter nodes based upon passed list of strings.
                        result.append((n.name(), t))
                    result += childrenOfNode(n, filter)
    return result

def migrateLights(node_path):
    node_target = hou.node("/obj")
    if node_target != None:
        light_nodes = childrenOfNode(hou.node(node_path),["Lop light"]) #Other valid filters are Sop, Object, cam.
        for (name, type) in light_nodes:
            node_candidate = "%s/%s" % (node_path, name)
            n = hou.node(node_candidate)
            if n !=None:
                # Create the Houdini light node.
                light_name = returnValidHoudiniNodeName("%s" % name)
                node_light = hou.node("%s/%s" % ("/obj", light_name))
                if node_light == None:
                    # Create new light.
                    node_light = node_target.createNode('hlight::2.0',light_name)
                else:
                    print ("skipping creation of %s." % light_name)
                  
                # Position and rotate light.    
                node_light.parm("tx").set(n.parm("tx").eval())
                node_light.parm("ty").set(n.parm("ty").eval())
                node_light.parm("tz").set(n.parm("tz").eval())
                node_light.parm("rx").set(n.parm("rx").eval())
                node_light.parm("ry").set(n.parm("ry").eval())
                node_light.parm("rz").set(n.parm("rz").eval())
                
                # Migrate light type.
                lop_index = n.parm("lighttype").eval()
                ary_remap_index = [5,7,2,0,3,4]
                ary_lops_types = ["cylinder","distant","disk","point","rectangle","sphere"]
                ary_hlight_types =  ["point","line","disk","grid","sphere","tube","geometry","distant","sun"]
                t = ary_hlight_types[ary_remap_index[lop_index]]
                node_light.parm("light_type").set(t)
                node_light.moveToGoodPosition()
                    
# Program starts here.
path = "/stage"
#path = "/obj/lopnet1"
migrateLights(path)

 

Edited by Atom

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
Sign in to follow this  

×