Light Rig UI Script
#light_rig_ui.py
isMaya = False
try:
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
except ImportError:
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtUiTools import *
isMaya = True
import sys
import os
import math
import maya.cmds as cmds
import maya.mel as mel
import light_rigs
reload (light_rigs)
import look_dev_spheres
reload (look_dev_spheres)
import lr_camera
reload (lr_camera)
#==============================================================
class lightRig_UI(QDialog):
def __init__(self, parent=None):
#super(lightRig_UI, self).__init__(parent)
QDialog.__init__(self, parent)
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.setWindowTitle("Look Dev Light Rig Generator")
# Define Variables
self.srcImagesPath = ''
self.lightList = []
self.lightindex = 0
self.sphereNames = []
self.skydomeNames = []
self.addWhitePlasticBall = False
self.addBlackPlasticBall = False
self.addGreyClayBall = False
self.addChromeBall = False
# Create the main vertical layout
vlayout = QVBoxLayout()
self.setLayout(vlayout)
# Create Light Panel
self.addLightPresetsPanel(vlayout)
self.addButtonPanel(vlayout)
self.addLightEditorPanel(vlayout)
self.addSpacePanel(30, vlayout)
# Create HDRI/Sky Dome Panel
self.addHDRPanel(vlayout)
self.addSkydome(vlayout)
self.addSpacePanel(30, vlayout)
# Create Look Dev Sphers Panel
self.addLookDevPanel(vlayout)
self.addSpacePanel(30, vlayout)
# Create Camera Panel
self.addCameraPanel(vlayout)
vlayout.addStretch()
# Set window size
self.setFixedSize(400, 460)
self.show()
#----------------------------------------------------------
# Creates a fixed space for UI layout purposes
def addSpacePanel(self, height, parentLayout):
panel = QWidget()
panel.setFixedHeight(height)
parentLayout.addWidget(panel)
#----------------------------------------------------------
def addLightPresetsPanel(self, parentLayout):
hlayout = QHBoxLayout()
#
label = QLabel(self)
label.setText('Lights:')
hlayout.addWidget(label)
#
combo = QComboBox(self)
combo.addItem("Studio") # index = 0
combo.addItem("Sunny Day") # index = 1
combo.addItem("Cloudy Day") # index = 2
combo.addItem("Sunset") # index = 3
combo.activated[int].connect(self.lightAction)
#
hlayout.addWidget(combo)
#
parentLayout.addLayout(hlayout)
#----------------------------------------------------------
def addButtonPanel(self, parentLayout):
hlayout = QHBoxLayout()
#
self.deleteRigButton = QPushButton("Delete Light Rig")
self.deleteRigButton.clicked.connect(self.deleteRigAction)
self.deleteRigButton.setEnabled(False)
#
self.createRigButton = QPushButton("Add Light Rig")
self.createRigButton.clicked.connect(self.createRigAction)
#
hlayout.addWidget(self.createRigButton)
hlayout.addWidget(self.deleteRigButton)
hlayout.addStretch()
#
parentLayout.addLayout(hlayout)
#----------------------------------------------------------
def addLightEditorPanel(self, parentLayout):
hlayout = QHBoxLayout()
#
self.addButton = QPushButton("Open Light Editor")
self.addButton.clicked.connect(self.openEditorAction)
self.addButton.setEnabled(False)
#
hlayout.addWidget(self.addButton)
hlayout.addStretch()
#
parentLayout.addLayout(hlayout)
#----------------------------------------------------------
def addHDRPanel(self, parentLayout):
hlayout = QHBoxLayout()
#
label = QLabel(self)
label.setText('HDRI:')
hlayout.addWidget(label)
#
self.pathText = QLineEdit()
self.pathText.setText('Search for HDRI')
self.pathText.textChanged[str].connect(self.pathChangedAction)
hlayout.addWidget(self.pathText)
#
self.browseButton = QPushButton("Browse")
self.browseButton.clicked.connect(self.browseAction)
#
hlayout.addWidget(self.browseButton)
#
parentLayout.addLayout(hlayout)
#----------------------------------------------------------
def addSkydome(self, parentLayout):
hlayout = QHBoxLayout()
#
self.skydomeAddButton = QPushButton("Add Sky Dome")
self.skydomeAddButton.setEnabled(False)
self.skydomeAddButton.clicked.connect(self.skydomeAddAction)
#
self.skydomeDeleteButton = QPushButton("Delete Sky Dome")
self.skydomeDeleteButton.setEnabled(False)
self.skydomeDeleteButton.clicked.connect(self.skydomeDeleteAction)
#
hlayout.addWidget(self.skydomeAddButton)
hlayout.addWidget(self.skydomeDeleteButton)
hlayout.addStretch()
#
parentLayout.addLayout(hlayout)
#----------------------------------------------------------
def addLookDevPanel(self, parentLayout):
vlayout = QVBoxLayout()
#
label = QLabel(self)
label.setText('Look Dev Spheres:')
vlayout.addWidget(label)
#
checkBox1 = QCheckBox("White Plastic Ball")
checkBox2 = QCheckBox("Black Plastic Ball")
checkBox3 = QCheckBox("Grey Clay Ball")
checkBox4 = QCheckBox("Chrome Ball")
checkBox1.stateChanged.connect(self.chechboxAction)
checkBox2.stateChanged.connect(self.chechboxAction)
checkBox3.stateChanged.connect(self.chechboxAction)
checkBox4.stateChanged.connect(self.chechboxAction)
#
vlayout.addWidget(checkBox1)
vlayout.addWidget(checkBox2)
vlayout.addWidget(checkBox3)
vlayout.addWidget(checkBox4)
self.addSpheresPanel(vlayout)
#
parentLayout.addLayout(vlayout)
#----------------------------------------------------------
def addSpheresPanel(self, parentLayout):
hlayout = QHBoxLayout()
#
self.createSphereButton = QPushButton("Add Spheres")
self.createSphereButton.clicked.connect(self.addSphereAction)
#
self.deleteSphereButton = QPushButton("Delete Spheres")
self.deleteSphereButton.clicked.connect(self.deleteSphereAction)
self.deleteSphereButton.setEnabled(False)
#
hlayout.addWidget(self.createSphereButton)
hlayout.addWidget(self.deleteSphereButton)
hlayout.addStretch()
#
parentLayout.addLayout(hlayout)
#----------------------------------------------------------
def addCameraPanel(self, parentLayout):
hlayout = QHBoxLayout()
#
self.addCameraButton = QPushButton("Add Camera")
self.addCameraButton.clicked.connect(self.addCameraAction)
#
self.deleteCameraButton = QPushButton("Delete Camera")
self.deleteCameraButton.clicked.connect(self.deleteCameraAction)
self.deleteCameraButton.setEnabled(False)
#
hlayout.addWidget(self.addCameraButton)
hlayout.addWidget(self.deleteCameraButton)
#
parentLayout.addLayout(hlayout)
#----------------------------------------------------------
# Called by addLookDevPanel
def chechboxAction(self):
cb = self.sender()
if cb.text() == "White Plastic Ball":
if cb.isChecked():
self.addWhitePlasticBall = True
else:
self.addWhitePlasticBall = False
if cb.text() == "Black Plastic Ball":
if cb.isChecked():
self.addBlackPlasticBall = True
else:
self.addBlackPlasticBall = False
if cb.text() == "Grey Clay Ball":
if cb.isChecked():
self.addGreyClayBall = True
else:
self.addGreyClayBall = False
if cb.text() == "Chrome Ball":
if cb.isChecked():
self.addChromeBall = True
else:
self.addChromeBall = False
#----------------------------------------------------------
# Called by addLightPresetsPanel
def lightAction(self,index):
self.lightindex=index
#----------------------------------------------------------
# Called by Add Sky Dome Button
def skydomeAddAction(self):
if self.srcImagesPath !='':
parentdir = os.path.dirname(self.srcImagesPath)
imagename = os.path.basename(self.srcImagesPath)
root, ext = os.path.splitext (imagename)
index = imagename.find(".")
if os.name == 'nt':
light_rigs.Skydome(self.srcImagesPath)
self.skydomeDeleteButton.setEnabled(True)
#----------------------------------------------------------
# Called by Delete Sky Dome Button
def skydomeDeleteAction(self):
light_rigs.DeleteSkydome()
self.skydomeDeleteButton.setEnabled(False)
#----------------------------------------------------------
# Called by Create Spheres Button
def addSphereAction(self):
lookDev = look_dev_spheres.lookDevSpheres()
if self.addWhitePlasticBall == True:
self.sphereNames.append(lookDev.WhitePlastic())
if self.addBlackPlasticBall == True:
self.sphereNames.append(lookDev.BlackPlastic())
if self.addGreyClayBall == True:
self.sphereNames.append(lookDev.GreyClay())
if self.addChromeBall == True:
self.sphereNames.append(lookDev.Chrome())
if len(self.sphereNames) > 0:
self.deleteSphereButton.setEnabled(True)
else:
self.deleteSphereButton.setEnabled(False)
#----------------------------------------------------------
# Called by Delete Spheres Button
def deleteSphereAction(self):
for name in self.sphereNames:
cmds.delete(name)
self.sphereNames = []
self.deleteSphereButton.setEnabled(False)
#---------------------------------------------------------
# Called by Delete Light Rig Button
def deleteRigAction(self):
print (self.lightList)
for light in self.lightList:
cmds.delete(light)
self.lightList = []
self.deleteRigButton.setEnabled(False)
#----------------------------------------------------------------
# Called by Create Light Rig Button
def createRigAction(self):
if self.lightindex == 0:
lightNames = light_rigs.studioLights("studio_key","studio_fill")
elif self.lightindex == 1:
lightNames = light_rigs.middayLights("midday_key","midday_fill")
elif self.lightindex == 2:
lightNames = light_rigs.cloudyLights("cloudy_key","cloudy_fill")
else:
lightNames = light_rigs.sunsetLights("sunset_key","sunset_fill")
self.lightList.append(lightNames)
self.deleteRigButton.setEnabled(True)
self.addButton.setEnabled(True)
#----------------------------------------------------------------
# Called by Path Panel
def pathChangedAction(self, text):
self.srcImagesPath = ''
if os.path.exists(text) == (False):
self.skydomeAddButton.setEnabled(False)
else:
self.skydomeAddButton.setEnabled(True)
self.srcImagesPath = text
#----------------------------------------------------------------
# Called by Browse Button
def browseAction(self):
fileDialog = QFileDialog.getOpenFileName(self, filter='*.hdr')
self.srcImagesPath = fileDialog[0]
if fileDialog[0] !='':
self.pathText.setText(fileDialog[0])
else:
self.pathText.setText('Browse Cancelled')
#----------------------------------------------------------------
# Called by Add Camera Button
def addCameraAction(self):
lr_camera.CreateCamera()
self.deleteCameraButton.setEnabled(True)
self.addCameraButton.setEnabled(False)
#----------------------------------------------------------------
# Called by Delete Camera Button
def deleteCameraAction(self):
lr_camera.DeleteCamera()
self.deleteCameraButton.setEnabled(False)
self.addCameraButton.setEnabled(True)
#----------------------------------------------------------------
# Called by Open Light Editor Button
def openEditorAction(self):
mel.eval('callPython "maya.app.renderSetup.lightEditor.views.editorUI" "createLightEditorWindow" {};')
#==============================================================
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
demo = lightRig_UI()
demo.show()
sys.exit(app.exec_())