top of page

Personal Project

Introduction

​

For this project, I want to create a tool in Houdini that allows a user to set up a 3 point lighting setup based around an object of their choosing. This tool would create a key, fill, and rim light along with a render camera so that test renders can be done efficiently. My hopes for this project is that in the UI, the user can adjust the intensity and color of each light in order to improve the look development pipeline.

​

This tool currently creates 4 different nodes, 3 lights and a camera to be used during render time. The lights are set up based on the bounding box of the object and the camera is front facing.

Screenshot from 2019-03-05 12-04-40.png
Screenshot from 2019-03-05 12-05-04.png
Screenshot from 2019-03-14 09-54-35.png
Screenshot from 2019-03-07 11-35-22.png
Screenshot from 2019-03-08 10-28-13.png

This code is set up to respect the bounding box of any selected object when "Create Light Rig" or "Create Camera" is selected in the UI. When one of those buttons is selected, a Houdini UI pops up allowing the user more control to where and what the lights are illuminating or focusing on.

​

import hou, os
from hou import hscript
from PySide2 import QtCore, QtUiTools, QtWidgets

class MyAsset(QtWidgets.QWidget):
    def __init__(self):
        super(MyAsset,self).__init__()
        ui_file = ('/home/jhenni21/mount/stuhome/tech312/personalProject/lightRig.ui')
        self.ui = QtUiTools.QUiLoader().load(ui_file, parentWidget=self)
        self.setParent(hou.ui.mainQtWindow(), QtCore.Qt.Window)
        #Define Create Light Rig Button
        self.ui.B_lightRig.clicked.connect(self.buttonClicked)
        self.ui.B_camera.clicked.connect(self.cameraClicked)
        
    def buttonClicked(self):
        self.createLightRig()
    
    def cameraClicked(self):
        self.createCamera()
    
    def createLightRig(self):
        sceneRoot = hou.node('/obj/')
        if hou.node('/obj/KEY_LIGHT') == None:
            select = hou.ui.selectNode()
            selected = ("%s" % select)
            keylight = sceneRoot.createNode('hlight', run_init_scripts=False)
            keylight.setName('KEY_LIGHT')
            keylight.parm('light_type').set(0)
            keylight.parm('coneenable').set(1)
            keylight.parm('light_intensity').set(10)
        
            #position the light
            keylight.parm('tx').set(hou.hscriptExpression("bbox('%s', -D_XMAX)-4" % selected))
            keylight.parm('ty').set(hou.hscriptExpression("bbox('%s', D_YMAX)+4" % selected))
            keylight.parm('tz').set(hou.hscriptExpression("bbox('%s', D_ZMAX)+4" % selected))
            keylight.parm('rx').set(-40)
            keylight.parm('ry').set(-46)
                   
        if hou.node('/obj/FILL_LIGHT') == None:
            fill = sceneRoot.createNode('hlight', run_init_scripts=False)
            fill.setName('FILL_LIGHT')
            fill.parm('light_type').set(0)
            fill.parm('coneenable').set(1)
            fill.parm('light_intensity').set(5)
        
            #set position of fill light
            fill.parm('tx').set(hou.hscriptExpression("bbox('%s', D_XMAX)+4" % selected))
            fill.parm('ty').set(hou.hscriptExpression("bbox('%s', D_YMAX)+2" % selected))
            fill.parm('tz').set(hou.hscriptExpression("bbox('%s', D_ZMAX)+4" % selected))
            fill.parm("rx").set(-21)
            fill.parm("ry").set(-305)
        
            
        if hou.node('/obj/RIM_LIGHT') == None:
            rim = sceneRoot.createNode('hlight', run_init_scripts=False)
            rim.setName('BACK_LIGHT')
            rim.parm('light_type').set(0)
            rim.parm('coneenable').set(1)
            rim.parm('light_intensity').set(3)
        
            #set position of rim light
            rim.parm('ty').set(hou.hscriptExpression("bbox('%s', D_YMIN)+0.26" % selected))
            rim.parm('tz').set(hou.hscriptExpression("bbox('%s', D_ZMAX)-10" % selected))
            rim.parm('ry').set(181)
        
        else:
            hou.ui.displayMessage('Hey, a Light Rig already exists.')

    def createCamera(self):
        sceneRoot = hou.node('/obj/')
        if hou.node('/obj/renderCam') == None:
            select = hou.ui.selectNode()
            selected = ("%s" % select)
            myCam = hou.node('/obj/').createNode('cam', 'renderCam')
            hou.hscript('viewcamera -c ' + myCam.name() + '*.*.world.persp1')
            #set position of the camera
            myCam.parm('tz').set(hou.hscriptExpression("bbox('%s', D_ZSIZE)+4" % selected))
            myCam.parm('ty').set(hou.hscriptExpression("bbox('%s', D_YSIZE)+7" % selected))
            myCam.parm('ry').set(0)
            myCam.parm('rx').set(-10)

win = MyAsset()
win.show()

​

Again, when this code is run, the three lights and camera are created and if the code is tried to run again, an error message pops up to alert the user that there is already a light rig present.

​

My main challenges with this code was getting the lights to respect the transformations of a selected object, and making sure that no matter what object was present, the lights would create a quality lighting setup.

bottom of page