Jump to content

Lops To Obj Lights


Atom

Recommended Posts

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