Light From Camera

This script creates a light from a selected cameras’ view. GUI will give you the option to create a VRay Rect Light, Spot Light, Directional Light, or Area Light.

New: Version 2 allows you to create a locator with a selected mesh, camera, or light.

Coming Soon: Arnold Light Support

To Run: Select the camera you want to create the light from. Run the script.

#Create Light from Camera View version 3.0.0
#For Maya. Tested in version 2014. With Vray Light support
#Bryanna London www.bryannalondon.com
#!/usr/bin/env python

#2.0 has VRay Sphere light support
#3.0 has locator support. Create locators from selected objects or cameras.

#TO USE: Select the camera you want to create the light from then run the script

import maya.cmds as cmds

#delete window if a window already exisits
if cmds.window('lightCamWindow', exists=True):
    cmds.deleteUI('lightCamWindow')

#Create my GUI
def createGUI():
    #window layout
    lightCamWindow = cmds.window('lightCamWindow',title="What Light", rtf=True)
    cmds.columnLayout(adjustableColumn= True, rowSpacing= 3)
    cmds.checkBox('rectLight',label= "VRay Rect Light", value=True)
    cmds.checkBox('sphereLight',label= "VRay Sphere Light", value=False)
    cmds.checkBox('spotLight', label= "Spot Light", value=False)
    cmds.checkBox('directionalLight',label= "Directional Light", value=False)
    cmds.checkBox('areaLight',label= "Area Light", value=False)
    cmds.checkBox('locator',label= "Locator", value=False)
    cmds.button( label='Run', width= 224, command=('lightFromCamera()'))
    cmds.setParent('..')
    cmds.setParent('..')
    cmds.showWindow('lightCamWindow')

createGUI()

def queryValues():

    #Query which checkboxes were checked
    rectValue = cmds.checkBox('rectLight', query = True, value = True)
    sphereValue = cmds.checkBox('sphereLight', query = True, value = True)
    spotValue = cmds.checkBox('spotLight', query = True, value = True)
    directValue = cmds.checkBox('directionalLight', query = True, value = True)
    areaValue = cmds.checkBox('areaLight', query = True, value = True)
    locatorValue = cmds.checkBox('locator', query = True, value = True)

    return rectValue, sphereValue, spotValue, directValue, areaValue, locatorValue

def lightFromCamera():

    #Define Selected Camera
    currentCamera = cmds.ls(selection = True, type = 'transform')

    #Query Translate and Rotation Values
    trans = cmds.xform(currentCamera, query = True, worldSpace = True, rotatePivot = True)
    rot = cmds.xform(currentCamera, query = True, worldSpace = True, rotation = True)

    #Run query to find which checkboxes were checked
    rectValue, sphereValue, spotValue, directValue, areaValue, locatorValue = queryValues()
    #queryValues()

    #If Rect Light checkbox is selected
    if rectValue == True:

        #Create VRay Rect Light
        rectLight = cmds.shadingNode( 'VRayLightRectShape' , asLight=True )

        #Apply camera transforms to Rect Light
        cmds.xform(rectLight, relative = True, rotation = rot, translation = trans)

        #Set some default values
        cmds.setAttr('%s.invisible' %(rectLight), 1)
        cmds.setAttr('%s.intensityMult' %(rectLight), 10)
        cmds.setAttr('%s.uSize' %(rectLight), 3)
        cmds.setAttr('%s.vSize' %(rectLight), 3)

    #Sphere Light
    if sphereValue == True:

        #Create VRay Rect Light
        sphereLight = cmds.shadingNode( 'VRayLightSphereShape' , asLight=True )

        #Apply camera transforms to Sphere Light
        cmds.xform(sphereLight, relative = True, rotation = rot, translation = trans, scale = (3,3,3))

        #Set some default values
        cmds.setAttr('%s.invisible' %(sphereLight), 1)
        cmds.setAttr('%s.intensityMult' %(sphereLight), 10)
        cmds.setAttr('%s.radius' %(sphereLight), 30)    

    #Spot Light
    if spotValue == True:

        #Create Spot Light
        spotLight = cmds.spotLight(name = 'spotLight')

        #Apply camera transforms to Spot Light
        cmds.xform('spotLight' , relative = True, rotation = rot, translation = trans, scale = (3,3,3))

    #Directional Light
    if directValue == True:

        #Create Directional Light
        directionLight = cmds.directionalLight(name = 'directionalLight')

        #Apply camera transforms to Directional Light
        cmds.xform('directionalLight' , relative = True, rotation = rot, translation = trans, scale = (3,3,3))

    #Area Light
    if areaValue == True:

        #Create Area Light
        areaLightShape = cmds.createNode("areaLight", name = 'areaLightShape')

        #Get Area Light Transform Node
        areaTrans = cmds.listRelatives('areaLightShape', parent = True)

        #Apply camera transforms to Area Light
        cmds.xform(areaTrans , relative = True, rotation = rot, translation = trans, scale = (3,3,3))

    #Locator
    if locatorValue == True:

        locator = cmds.spaceLocator(name = 'locator')
        #Apply camera transforms to Directional Light
        cmds.xform('locator' , relative = True, rotation = rot, translation = trans, scale = (3,3,3))
        #rename locator
        cmds.rename('locator', 'locator_0')

© 2016 Bryanna London

Advertisement