Jump to content

Arnold lights instances normal


Recommended Posts

Hi everybody,

i'm facing issues orienting Arnold lights copy to points normal.I'm actually using this .hda (https://www.artstation.com/artwork/zA3BVd)

But no chance to get orientation.I should get the point normal and convert to degrees for the light.

Can anybody point me in the right direction?

Anyone knows a better way to copy arnold lights to points?

Thank you sooo much!

Carlo

The python script that is used is :

from math import sqrt

def destroyInstance(kwargs):
    # Define Variable
    node = kwargs['node'] 
    try:
        scatterNodePath = node.parm('scatterPath').eval()
        scatterNode = hou.node(scatterNodePath)
        scatterGeo = scatterNode.geometry()
    except: 
        hou.ui.displayMessage('I can\'t find the scatter node "' + scatterNodePath + '" !')
        exit()

    scatterNodePath = node.parm('scatterPath').eval()
    scatterNode = hou.node(scatterNodePath)
    scatterGeo = scatterNode.geometry()
    instanceName = node.parm('instanceName').eval()

    # Instance Loop
    try:
        for pt in scatterGeo.points():
                nameInstance = instanceName + '_' + str(pt.number())
                instances = hou.node('/obj/' + nameInstance)
                instances.destroy()
        hou.item('/obj/networkInst').destroy()
        hou.item('/obj/networkMain').destroy()
    except: pass


def createInstance(kwargs):
    node = kwargs['node']
    
    # Define Variable
    try:
        scatterNodePath = node.parm('scatterPath').eval()
        scatterNode = hou.node(scatterNodePath)
        scatterGeo = scatterNode.geometry()
    except: 
        hou.ui.displayMessage('I can\'t find the scatter node "' + scatterNodePath + '" !')
        exit()

    try:
        instanceNodeName = node.parm('nameNode').eval()
        test = hou.node('/obj/').createNode(instanceNodeName, "test")
        test.destroy()
    except: 
        hou.ui.displayMessage('The name of node "' + instanceNodeName + '" doesn\'t exist ! ')
        exit()

    linkPosPts = node.parm('linkPosPts').eval()
    instanceName = node.parm('instanceName').eval()
    linkAttribPt = node.parm('linkAttribPt').eval().split()
    copyPtAttribValue = node.parm('copyPtAttribValue').eval().split()
    linkParmFirstInstance = node.parm('linkParmFirstInstance').eval().split()
    revertParmValue = node.parm('revertParmValue').eval().split()
    parmList = revertParmValue + linkParmFirstInstance + copyPtAttribValue +linkAttribPt
    attribList = linkAttribPt + copyPtAttribValue

    # Instance Loop
    for pt in scatterGeo.points():
        # Create Light
        nameInstance = instanceName + '_' + str(pt.number())
        try: 
            test = hou.node('/obj/' + nameInstance).name()
            networkBoxMain = hou.node('/obj/' + 'networkMain')
            instances = hou.node('/obj/' + nameInstance)
            firstRun = 0
        except:
            # Create Node
            firstRun = 1
            instances = hou.node('/obj/').createNode(instanceNodeName, nameInstance)

        #TEST
        if nameInstance == instanceName + '_0':
            for p in parmList:
                try:
                    instances.parm(p).eval()
                except: 
                    hou.ui.displayMessage('The parameter "' + p + '" doesn\'t exit !')
                    if(firstRun == 1): instances.destroy()
                    exit()
            for a in attribList:
                try:
                    pt.attribValue(a)
                except: 
                    hou.ui.displayMessage('The Attribut "' + a + '" doesn\'t exit !')
                    if(firstRun == 1): instances.destroy()
                    exit()

        # Position Light
        if linkPosPts == 1:
            instances.parm('tx').setExpression('point("' + scatterNodePath + '", ' + str(pt.number()) + ', "' + 'P' + '", 0)')
            instances.parm('ty').setExpression('point("' + scatterNodePath + '", ' + str(pt.number()) + ', "' + 'P' + '", 1)')
            instances.parm('tz').setExpression('point("' + scatterNodePath + '", ' + str(pt.number()) + ', "' + 'P' + '", 2)')
        else :
            instances.parm('tx').deleteAllKeyframes()
            instances.parm('tx').set(pt.position()[0])
            instances.parm('ty').deleteAllKeyframes()
            instances.parm('ty').set(pt.position()[1])
            instances.parm('tz').deleteAllKeyframes()
            instances.parm('tz').set(pt.position()[2])

        # Revert parm value to default value
        for rpv in revertParmValue:
            instances.parm(rpv).deleteAllKeyframes()
            instances.parm(rpv).revertToDefaults()
        
        # Copy Points Value in Paramaters
        for cap in copyPtAttribValue:
            instances.parm(cap).deleteAllKeyframes()
            instances.parm(cap).set(pt.attribValue(cap))

        # Link Points Value in Paramaters
        for lap in linkAttribPt:
            type = scatterGeo.findPointAttrib(lap).dataType()
            if str(type) == "attribData.String" :
                print(type)
                instances.parm(lap).setExpression('points("' + scatterNodePath + '", ' + str(pt.number()) + ', "' + lap + '")')
            else :
                instances.parm(lap).setExpression('point("' + scatterNodePath + '", ' + str(pt.number()) + ', "' + lap + '", 0)')
        
        if pt.number() == 0 :
            # Color Node
            instances.setColor(hou.Color((1.0, 0.72, 0)))
        else : 
            instances.setColor(hou.Color((1, 0.98, 0.67)))
            # Link Paramaters To First Instance's paramaters
            for lpfi in linkParmFirstInstance:
                instances.parm(lpfi).setExpression('chs("/obj/' + instanceName + '_0/' + lpfi + '")')

    # NetworkBox
    networkBoxMain = hou.item('/obj/networkMain')
    networkBoxInst = hou.item('/obj/networkInst')
    try: 
        if networkBoxMain.comment() == instanceName: 
            networkBoxMain.destroy(False)
    except: pass
    try: 
        if networkBoxInst.comment() == (instanceName + "_Instance"): 
            networkBoxInst.destroy(False)
    except: pass

    networkBoxMain = hou.node('/obj/').createNetworkBox('networkMain')
    networkBoxMain.setComment(instanceName)
    networkBoxMain.setColor(hou.Color((0.98, 0.78, 0.26)))
    networkBoxMain.setMinimized(1)
    networkBoxInst = hou.node('/obj/').createNetworkBox('networkInst')
    networkBoxInst.setComment(instanceName + "_Instance")
    networkBoxInst.setColor(hou.Color((1, 0.98, 0.67)))
    networkBoxInst.setMinimized(1)

    col = round(sqrt(len(scatterGeo.points())))

    for pt in scatterGeo.points():
        nameInstance = instanceName + '_' + str(pt.number())
        i = pt.number()
        node = hou.node('/obj/' + instanceName + '_' + str(i))
        if i == 0:
            node.setPosition([.2, .8])
            networkBoxMain.addItem(node)
            networkBoxMain.addNetworkBox(networkBoxInst)

        else :
            networkBoxInst.addItem(node)
            tmpPos = [i%col*3, round((col*col-i / col)-.5)]
            node.setPosition(tmpPos)

    networkBoxInst.resize([1, 1])
    networkBoxInst.setPosition([1.5, 0])
    networkBoxMain.resize([1, 1])
    tmpPos = scatterNode.parent().position()
    tmpPos[0] += 4
    networkBoxMain.setPosition(tmpPos)
    networkBoxMain.setMinimized(0)

Link to comment
Share on other sites

Maibe adding something like this?

dirx:

euler = hou.parmTuple("r").eval()
dir = hou.Vector3((0,1,0)) * hou.hmath.buildRotate(euler)
return dir[0]

diry:

euler = hou.parmTuple("r").eval()
dir = hou.Vector3((0,1,0)) * hou.hmath.buildRotate(euler)
return dir[1]

dirz:

euler = hou.parmTuple("r").eval()
dir = hou.Vector3((0,1,0)) * hou.hmath.buildRotate(euler)
return dir[2]
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...