加入工作室时师兄给了两道测试题,由于第一道是完善师兄的一个houdini项目管理插件,我只是开发了一些小功能,所以不好意思拿出来。

第二道题就完全是由自己开发的一个小插件,功能是把maya里的灯光导入到houdini里面。刚开始拿到测试题的时候有点慌,毕竟没怎么做过插件开发,还好师兄给了足够的时间,而且后面发现也没那么难,不过生了一场病,接连在床上躺了几天,不过后来都做出来了。基本做出来之后我就佛了,一天一天做一点,顺便学东西,到最后期限,刚好就把测试题交了,也算是有惊无险加入工作室。

插件下载下载地址

接下来就开始讲怎么开发插件:

maya刚开始学插件开发,用的都是cmd这个库,因为伟添师兄博客上有很多学习笔记,确实帮了我很大的忙,而且最后发现师兄给的一个教程里面有一个就是讲灯光的,不过我已经基本按自己的思路做完了,也就没改。

而houdini里面就基本使用了hou模块开发。

由于刚开始学,而且参照师兄给的另一个插件,就都是用绝对路径写代码,可能对于用户很不友好,后来在做另一个插件时也研究了一下怎么使用相对路径,就是采用python的os库,但也不想改了,毕竟也可以记录一下自己的学习路径(更大原因还是因为懒)

首先是在qt里面做一些基本的ui界面,如图,我这里是做了好几个,因为有几种灯光,然后就可以实现灯光界面的切换

然后是写maya里面的代码,在编辑器(这里推荐vscode,或者pycharm)里面写上代码:

from PySide2 import QtWidgets, QtCore, QtGui
import pymel.core as pm
import PySide2.QtUiTools as QLoader
import maya.cmds as cmds
import json main_ui = r"C:\Users\huangPeiXin\Desktop\sendLights\src\main.ui"
amibientLight_ui = r"C:\Users\huangPeiXin\Desktop\sendLights\src\amibientLight.ui"
areaLight_ui = r"C:\Users\huangPeiXin\Desktop\sendLights\src\areaLight.ui"
spotLight_ui = r"C:\Users\huangPeiXin\Desktop\sendLights\src\spotLight.ui"
pointLight_ui = r"C:\Users\huangPeiXin\Desktop\sendLights\src\pointLight.ui"
volumeLight_ui = r"C:\Users\huangPeiXin\Desktop\sendLights\src\volumeLight.ui"
directionalLight_ui = r"C:\Users\huangPeiXin\Desktop\sendLights\src\directionalLight.ui"
light_json = r"C:\Users\huangPeiXin\Desktop\sendLights\src\light_json.json" def getLightAttr(light):
#获取灯光属性 #保存灯光名称
lightName = str(light.getTransform()) #用于保存每一盏灯光的属性
lightChild = {} #根据灯光类型加载对应灯光属性
if pm.objectType(light) == "ambientLight":
lightChild["lightType"] = "ambientLight"
lightChild["translate"] = cmds.getAttr(lightName + ".translate")
lightChild["rotate"] = cmds.getAttr(lightName + ".rotate")
lightChild["scale"] = cmds.getAttr(lightName + ".scale")
lightChild["visibility"] = cmds.getAttr(lightName + ".visibility")
lightChild["color"] = cmds.getAttr(lightName + ".color")
lightChild["intensity"] = cmds.getAttr(lightName + ".intensity")
lightChild["useRayTraceShadows"] = cmds.getAttr(lightName + ".useRayTraceShadows")
lightChild["shadColor"] = [cmds.getAttr(lightName + ".shadColorR"),
cmds.getAttr(lightName + ".shadColorG"),cmds.getAttr(lightName + ".shadColorB"),] elif pm.objectType(light) == "pointLight":
lightChild["lightType"] = "pointLight"
lightChild["translate"] = cmds.getAttr(lightName + ".translate")
lightChild["rotate"] = cmds.getAttr(lightName + ".rotate")
lightChild["scale"] = cmds.getAttr(lightName + ".scale")
lightChild["visibility"] = cmds.getAttr(lightName + ".visibility")
lightChild["color"] = cmds.getAttr(lightName + ".color")
lightChild["intensity"] = cmds.getAttr(lightName + ".intensity")
lightChild["useRayTraceShadows"] = cmds.getAttr(lightName + ".useRayTraceShadows")
lightChild["shadColor"] = [cmds.getAttr(lightName + ".shadColorR"),
cmds.getAttr(lightName + ".shadColorG"),cmds.getAttr(lightName + ".shadColorB"),]
lightChild["useDepthMapShadows"] = cmds.getAttr(lightName + ".useDepthMapShadows")
lightChild["dmapBias"] = cmds.getAttr(lightName + ".dmapBias")
lightChild["aiExposure"] = cmds.getAttr(lightName + ".aiExposure")
lightChild["aiRadius"] = cmds.getAttr(lightName + ".aiRadius") elif pm.objectType(light) == "spotLight":
lightChild["lightType"] = "spotLight"
lightChild["translate"] = cmds.getAttr(lightName + ".translate")
lightChild["rotate"] = cmds.getAttr(lightName + ".rotate")
lightChild["scale"] = cmds.getAttr(lightName + ".scale")
lightChild["visibility"] = cmds.getAttr(lightName + ".visibility")
lightChild["color"] = cmds.getAttr(lightName + ".color")
lightChild["intensity"] = cmds.getAttr(lightName + ".intensity")
lightChild["useRayTraceShadows"] = cmds.getAttr(lightName + ".useRayTraceShadows")
lightChild["shadColor"] = [cmds.getAttr(lightName + ".shadColorR"),
cmds.getAttr(lightName + ".shadColorG"),cmds.getAttr(lightName + ".shadColorB"),]
lightChild["useDepthMapShadows"] = cmds.getAttr(lightName + ".useDepthMapShadows")
lightChild["dmapBias"] = cmds.getAttr(lightName + ".dmapBias")
lightChild["aiExposure"] = cmds.getAttr(lightName + ".aiExposure")
lightChild["aiRadius"] = cmds.getAttr(lightName + ".aiRadius")
lightChild["coneAngle"] = cmds.getAttr(lightName + ".coneAngle")
lightChild["penumbraAngle"] = cmds.getAttr(lightName + ".penumbraAngle")
lightChild["dropoff"] = cmds.getAttr(lightName + ".dropoff") elif pm.objectType(light) == "directionalLight":
lightChild["lightType"] = "directionalLight"
lightChild["translate"] = cmds.getAttr(lightName + ".translate")
lightChild["rotate"] = cmds.getAttr(lightName + ".rotate")
lightChild["scale"] = cmds.getAttr(lightName + ".scale")
lightChild["visibility"] = cmds.getAttr(lightName + ".visibility")
lightChild["color"] = cmds.getAttr(lightName + ".color")
lightChild["intensity"] = cmds.getAttr(lightName + ".intensity")
lightChild["useRayTraceShadows"] = cmds.getAttr(lightName + ".useRayTraceShadows")
lightChild["shadColor"] = [cmds.getAttr(lightName + ".shadColorR"),
cmds.getAttr(lightName + ".shadColorG"),cmds.getAttr(lightName + ".shadColorB"),]
lightChild["useDepthMapShadows"] = cmds.getAttr(lightName + ".useDepthMapShadows")
lightChild["dmapBias"] = cmds.getAttr(lightName + ".dmapBias")
lightChild["aiExposure"] = cmds.getAttr(lightName + ".aiExposure")
lightChild["aiAngle"] = cmds.getAttr(lightName + ".aiAngle") elif pm.objectType(light) == "areaLight":
lightChild["lightType"] = "areaLight"
lightChild["translate"] = cmds.getAttr(lightName + ".translate")
lightChild["rotate"] = cmds.getAttr(lightName + ".rotate")
lightChild["scale"] = cmds.getAttr(lightName + ".scale")
lightChild["visibility"] = cmds.getAttr(lightName + ".visibility")
lightChild["color"] = cmds.getAttr(lightName + ".color")
lightChild["intensity"] = cmds.getAttr(lightName + ".intensity")
lightChild["useRayTraceShadows"] = cmds.getAttr(lightName + ".useRayTraceShadows")
lightChild["shadColor"] = [cmds.getAttr(lightName + ".shadColorR"),
cmds.getAttr(lightName + ".shadColorG"),cmds.getAttr(lightName + ".shadColorB"),]
lightChild["useDepthMapShadows"] = cmds.getAttr(lightName + ".useDepthMapShadows")
lightChild["dmapBias"] = cmds.getAttr(lightName + ".dmapBias")
lightChild["aiExposure"] = cmds.getAttr(lightName + ".aiExposure")
lightChild["aiSpread"] = cmds.getAttr(lightName + ".aiSpread")
lightChild["aiRoundness"] = cmds.getAttr(lightName + ".aiRoundness")
lightChild["aiSoftEdge"] = cmds.getAttr(lightName + ".aiSoftEdge") elif pm.objectType(light) == "volumeLight":
lightChild["lightType"] = "volumeLight"
lightChild["translate"] = cmds.getAttr(lightName + ".translate")
lightChild["rotate"] = cmds.getAttr(lightName + ".rotate")
lightChild["scale"] = cmds.getAttr(lightName + ".scale")
lightChild["visibility"] = cmds.getAttr(lightName + ".visibility")
lightChild["color"] = cmds.getAttr(lightName + ".color")
lightChild["intensity"] = cmds.getAttr(lightName + ".intensity")
lightChild["useRayTraceShadows"] = cmds.getAttr(lightName + ".useRayTraceShadows")
lightChild["shadColor"] = [cmds.getAttr(lightName + ".shadColorR"),
cmds.getAttr(lightName + ".shadColorG"),cmds.getAttr(lightName + ".shadColorB"),]
lightChild["useDepthMapShadows"] = cmds.getAttr(lightName + ".useDepthMapShadows")
lightChild["dmapBias"] = cmds.getAttr(lightName + ".dmapBias")
lightChild["aiExposure"] = cmds.getAttr(lightName + ".aiExposure")
lightChild["aiRadius"] = cmds.getAttr(lightName + ".aiRadius") return lightChild class LightManager(QtWidgets.QWidget):
#灯光管理器
def __init__(self):
super(LightManager, self).__init__()
self.setObjectName("project_manager") #加载初始界面
loader = QLoader.QUiLoader()
self.ui = loader.load(main_ui)
self.ui.setParent(self)
self.setMaximumSize(450, 700)
self.setMinimumSize(450, 700) #获取初始界面控件
self.comboBox = self.ui.findChild(QtWidgets.QComboBox, "comboBox")
self.widget = self.ui.findChild(QtWidgets.QWidget, "widget")
self.btn_loadAttr = self.ui.findChild(QtWidgets.QPushButton, "btn_loadAttr")
self.btn_sendAttr = self.ui.findChild(QtWidgets.QPushButton, "btn_sendAttr") #获取灯光列表
self.light_list = self.getLight() #加载灯光
self.creatChild() #如果场景中没有灯光,弹出提示没有灯光,如果有,加载第一盏灯光
if self.light_list == []:
msg = QtWidgets.QMessageBox()
msg.setParent(self)
msg.setText("There is no light") else: self.layout = QtWidgets.QVBoxLayout()
self.widget.setLayout(self.layout)
self.childWin = LightWidget(self.light_list[0],self.light_list,0)
self.childWin.setMaximumSize(600, 800)
self.childWin.setMinimumSize(600, 800)
self.layout.addWidget(self.childWin) self.comboBox.currentIndexChanged.connect(lambda: self.creatChildWin(self.comboBox.currentIndex()))
self.btn_sendAttr.clicked.connect(self.exportLight)
self.btn_loadAttr.clicked.connect(self.changeLight) def creatChildWin(self,index):
#创建子窗口 self.layout.removeWidget(self.childWin)
print pm.objectType(self.light_list[index])
print self.light_list[index]
self.childWin = LightWidget(self.light_list[index],self.light_list,index)
self.childWin.setMaximumSize(420, 530)
self.childWin.setMinimumSize(420, 530)
self.layout.addWidget(self.childWin) def creatChild(self):
#根据灯光的多少为comboBox添加子项目 for light in self.light_list:
self.comboBox.addItem(str(light.getTransform())) def getLight(self):
#获取场景中所有的灯光 light_list = []
for light in pm.ls(type=["ambientLight","areaLight","spotLight","pointLight","directionalLight","volumeLight"]):
light_list.append(light) return light_list def changeLight(self):
#重新加载灯光属性 #移除原有列表
self.comboBox.clear()
#重新加载灯光列表
self.light_list = self.getLight()
self.creatChild() #判断场景是否还有灯光
if self.light_list == []:
return 0 else: self.layout.removeWidget(self.childWin)
self.childWin = LightWidget(self.light_list[0],self.light_list,0)
self.childWin.setMaximumSize(420, 530)
self.childWin.setMinimumSize(420, 530)
self.layout.addWidget(self.childWin) def exportLight(self):
#导出灯光属性到json文件
light_dir = {} #获取场景中所有的灯光
self.light_list = self.getLight() for light in self.light_list: #获取保存灯光名称
lightName = str(light.getTransform()) light_dir[lightName] = getLightAttr(light) #写入到json文件中
with open(light_json,'w') as f:
json.dump(light_dir, f, indent=4) class LightWidget(QtWidgets.QWidget): #灯光界面基类,用于获取灯光的基础属性,
def __init__(self,light,light_list,index): super(LightWidget, self).__init__() # #获取属性
self.light = light
self.light_list = light_list
self.lightAttr = getLightAttr(light) #根据灯光类型,加载不同灯光界面
if pm.objectType(self.light_list[index])=="ambientLight": loader = QLoader.QUiLoader()
self.ui = loader.load(amibientLight_ui)
self.ui.setParent(self)
self.lineEdit_type = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_type")
self.lineEdit_type.setText(pm.objectType(self.light_list[index])) elif pm.objectType(self.light_list[index])=="areaLight": loader = QLoader.QUiLoader()
self.ui = loader.load(areaLight_ui)
self.ui.setParent(self) self.lineEdit_type = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_type")
self.lineEdit_udms = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_udms")
self.lineEdit_db = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_db")
self.lineEdit_ae = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_ae")
self.lineEdit_as = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_as")
self.lineEdit_ar = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_ar")
self.lineEdit_ase = self.ui.findChild(QtWidgets.QLineEdit,"LineEdit_ase") self.lineEdit_type.setText(pm.objectType(self.light_list[index]))
self.lineEdit_udms.setText(str(self.lightAttr["useDepthMapShadows"]))
self.lineEdit_db.setText(str(self.lightAttr["dmapBias"]))
self.lineEdit_ae.setText(str(self.lightAttr["aiExposure"]))
self.lineEdit_as.setText(str(self.lightAttr["aiSpread"]))
self.lineEdit_ar.setText(str(self.lightAttr["aiRoundness"]))
self.lineEdit_ase.setText(str(self.lightAttr["aiSoftEdge"])) elif pm.objectType(self.light_list[index])=="spotLight": loader = QLoader.QUiLoader()
self.ui = loader.load(spotLight_ui)
self.ui.setParent(self) self.lineEdit_type = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_type")
self.lineEdit_udms = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_udms")
self.lineEdit_db = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_db")
self.lineEdit_ae = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_ae")
self.lineEdit_ca = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_ca")
self.lineEdit_pa = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_pa")
self.lineEdit_do = self.ui.findChild(QtWidgets.QLineEdit,"LineEdit_do")
self.lineEdit_ar = self.ui.findChild(QtWidgets.QLineEdit,"LineEdit_ar") self.lineEdit_type.setText(pm.objectType(self.light_list[index]))
self.lineEdit_udms.setText(str(self.lightAttr["useDepthMapShadows"]))
self.lineEdit_db.setText(str(self.lightAttr["dmapBias"]))
self.lineEdit_ae.setText(str(self.lightAttr["aiExposure"]))
self.lineEdit_ca.setText(str(self.lightAttr["coneAngle"]))
self.lineEdit_pa.setText(str(self.lightAttr["penumbraAngle"]))
self.lineEdit_do.setText(str(self.lightAttr["dropoff"]))
self.lineEdit_ar.setText(str(self.lightAttr["aiRadius"])) elif pm.objectType(self.light_list[index])=="pointLight":
loader = QLoader.QUiLoader()
self.ui = loader.load(pointLight_ui)
self.ui.setParent(self) self.lineEdit_type = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_type")
self.lineEdit_udms = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_udms")
self.lineEdit_db = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_db")
self.lineEdit_ae = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_ae")
self.lineEdit_ar = self.ui.findChild(QtWidgets.QLineEdit,"LineEdit_ar") self.lineEdit_type.setText(pm.objectType(self.light_list[index]))
self.lineEdit_udms.setText(str(self.lightAttr["useDepthMapShadows"]))
self.lineEdit_db.setText(str(self.lightAttr["dmapBias"]))
self.lineEdit_ae.setText(str(self.lightAttr["aiExposure"]))
self.lineEdit_ar.setText(str(self.lightAttr["aiRadius"])) elif pm.objectType(self.light_list[index])=="directionalLight":
loader = QLoader.QUiLoader()
self.ui = loader.load(directionalLight_ui)
self.ui.setParent(self) self.lineEdit_type = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_type")
self.lineEdit_udms = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_udms")
self.lineEdit_db = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_db")
self.lineEdit_ae = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_ae")
self.lineEdit_aa = self.ui.findChild(QtWidgets.QLineEdit,"LineEdit_aa") self.lineEdit_type.setText(pm.objectType(self.light_list[index]))
self.lineEdit_udms.setText(str(self.lightAttr["useDepthMapShadows"]))
self.lineEdit_db.setText(str(self.lightAttr["dmapBias"]))
self.lineEdit_ae.setText(str(self.lightAttr["aiExposure"]))
self.lineEdit_aa.setText(str(self.lightAttr["aiAngle"])) elif pm.objectType(self.light_list[index])=="volumeLight":
loader = QLoader.QUiLoader()
self.ui = loader.load(volumeLight_ui)
self.ui.setParent(self) self.lineEdit_type = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_type")
self.lineEdit_udms = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_udms")
self.lineEdit_db = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_db")
self.lineEdit_ae = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_ae")
self.lineEdit_ar = self.ui.findChild(QtWidgets.QLineEdit,"LineEdit_ar") self.lineEdit_type.setText(pm.objectType(self.light_list[index]))
self.lineEdit_udms.setText(str(self.lightAttr["useDepthMapShadows"]))
self.lineEdit_db.setText(str(self.lightAttr["dmapBias"]))
self.lineEdit_ae.setText(str(self.lightAttr["aiExposure"]))
self.lineEdit_ar.setText(str(self.lightAttr["aiRadius"])) #获取界面共有子控件
self.lineEdit_tr_X = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_tr_X")
self.lineEdit_tr_Y = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_tr_Y")
self.lineEdit_tr_Z = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_tr_Z")
self.lineEdit_rt_X = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_rt_X")
self.lineEdit_rt_Y = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_rt_Y")
self.lineEdit_rt_Z = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_rt_Z")
self.lineEdit_sc_X = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_sc_X")
self.lineEdit_sc_Y = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_sc_Y")
self.lineEdit_sc_Z = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_sc_Z")
self.lineEdit_sco_X = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_sco_X")
self.lineEdit_sco_Y = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_sco_Y")
self.lineEdit_sco_Z = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_sco_Z")
self.lineEdit_int = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_int")
self.lineEdit_urt = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_urt")
self.lineEdit_vis = self.ui.findChild(QtWidgets.QLineEdit, "LineEdit_vis") self.setValue() def setValue(self):
#设置控件的值 self.lineEdit_tr_X.setText(str(self.lightAttr["translate"][0][0]))
self.lineEdit_tr_Y.setText(str(self.lightAttr["translate"][0][1]))
self.lineEdit_tr_Z.setText(str(self.lightAttr["translate"][0][2]))
self.lineEdit_rt_X.setText(str(self.lightAttr["rotate"][0][0]))
self.lineEdit_rt_Y.setText(str(self.lightAttr["rotate"][0][1]))
self.lineEdit_rt_Z.setText(str(self.lightAttr["rotate"][0][2]))
self.lineEdit_sc_X.setText(str(self.lightAttr["scale"][0][0]))
self.lineEdit_sc_Y.setText(str(self.lightAttr["scale"][0][1]))
self.lineEdit_sc_Z.setText(str(self.lightAttr["scale"][0][2]))
self.lineEdit_sco_X.setText(str(self.lightAttr["shadColor"][0]))
self.lineEdit_sco_Y.setText(str(self.lightAttr["shadColor"][1]))
self.lineEdit_sco_Z.setText(str(self.lightAttr["shadColor"][2]))
self.lineEdit_int.setText(str(self.lightAttr["intensity"]))
self.lineEdit_vis.setText(str(self.lightAttr["visibility"]))
self.lineEdit_urt.setText(str(self.lightAttr["useRayTraceShadows"])) #创建窗口
win = LightManager() win.show()

然后再写houdini里的脚本:

import json
import hou
#加载json文件
with open(r"C:\Users\Administrator\Desktop\sendLights\src\light_json.json") as js:
data = json.load(js) class Light():
""" 灯光基类"""
def __init__(self, key): self.obj = hou.node("obj")
self.key = key #创建灯光
def createLight(self):
print self.key
self.light = self.obj.createNode("hlight")
self.light.setName(self.key) #设置灯光位置
def setPostition(self):
self.posX = self.light.parm("tx")
self.posY = self.light.parm("ty")
self.posZ = self.light.parm("tz")
self.posX.set(data[self.key]["translate"][0][0])
self.posY.set(data[self.key]["translate"][0][1])
self.posZ.set(data[self.key]["translate"][0][2]) #设置灯光旋转
def setRotate(self):
self.posX = self.light.parm("rx")
self.posY = self.light.parm("ry")
self.posZ = self.light.parm("rz")
self.posX.set(data[self.key]["rotate"][0][0])
self.posY.set(data[self.key]["rotate"][0][1])
self.posZ.set(data[self.key]["rotate"][0][2]) #设置投影
def setShadow(self): self.st = self.light.parm("shadow_type") if data[self.key]["useDepthMapShadows"]:
self.st.set(2)
self.bias = self.light.parm("shadow_bias")
self.bias.set(data[self.key]["dmapBias"]) elif data[self.key]["useRayTraceShadows"]:
self.st.set(1) self.scr = self.light.parm("shadow_colorr")
self.scg = self.light.parm("shadow_colorg")
self.scb = self.light.parm("shadow_colorb")
self.scr.set(data[self.key]["shadColor"][0])
self.scg.set(data[self.key]["shadColor"][1])
self.scb.set(data[self.key]["shadColor"][2]) #设置显示模式
def setDisplay(self): self.tdis = self.light.parm("tdisplay") self.tdis.set(True)
self.dis = self.light.parm("display")
if data[self.key]["visibility"]:
self.dis.set(1)
else:
self.dis.set(0) #设置扩散
def setExposure(self):
self.le = self.light.parm("light_exposure")
self.le.set(data[self.key]["aiExposure"]) #设置颜色属性
def setColor(self): self.colX = self.light.parm("light_colorr")
self.colY = self.light.parm("light_colorg")
self.colZ = self.light.parm("light_colorb")
self.colX.set(data[self.key]["color"][0][0])
self.colY.set(data[self.key]["color"][0][1])
self.colZ.set(data[self.key]["color"][0][2]) #灯光强度
def setIntensity(self): self.inte = self.light.parm("light_intensity")
self.inte.set(data[self.key]["intensity"]) class AmbientLight(Light):
"""环境光类,继承自灯光基类"""
def __init__(self,key):
Light.__init__(self,key) self.createLight()
self.setPostition()
self.setRotate()
self.setScale()
self.setColor()
self.setIntensity()
self.setDisplay() #重写创建灯光
def createLight(self):
print self.key #创建节点,并且重命名
self.light = self.obj.createNode("ambient")
self.light.setName(self.key)
self.file = self.light.children()[0]
self.transform = self.light.createNode("xform") #连接节点
self.transform.setFirstInput(self.file) #按下L键
self.light.layoutChildren() #设置显示模式
self.transform.setDisplayFlag(True)
self.transform.setRenderFlag(True) #重写位置属性
def setPostition(self): self.posX = self.transform.parm("tx")
self.posY = self.transform.parm("ty")
self.posZ = self.transform.parm("tz")
self.posX.set(data[self.key]["translate"][0][0])
self.posY.set(data[self.key]["translate"][0][1])
self.posZ.set(data[self.key]["translate"][0][2]) #重写旋转属性
def setRotate(self): self.rotX = self.transform.parm("rx")
self.rotY = self.transform.parm("ry")
self.rotZ = self.transform.parm("rz")
self.rotX.set(data[self.key]["rotate"][0][0])
self.rotY.set(data[self.key]["rotate"][0][1])
self.rotZ.set(data[self.key]["rotate"][0][2]) #设置大小属性
def setScale(self):
self.rotX = self.transform.parm("sx")
self.rotY = self.transform.parm("sy")
self.rotZ = self.transform.parm("sz")
self.rotX.set(data[self.key]["scale"][0][0])
self.rotY.set(data[self.key]["scale"][0][1])
self.rotZ.set(data[self.key]["scale"][0][2]) #重写显示属性
def setDisplay(self):
self.dis = self.light.parm("l_tdisplay")
self.dis.set(True)
self.disd = self.light.parm("l_display")
if data[self.key]["visibility"]:
self.disd.set(1)
else:
self.disd.set(0) class DirectionalLight(Light):
"""平行光,继承自灯光基类"""
def __init__(self,key):
Light.__init__(self,key) self.createLight()
self.setPostition()
self.setRotate()
self.setColor()
self.setIntensity()
self.setDisplay()
self.setShadow()
self.setExposure() #重写创建灯光
def createLight(self):
print self.key
self.light = self.obj.createNode("hlight")
self.light.setName(self.key)
self.lightType = self.light.parm("light_type")
self.lightType.set(7) #scale aiAngle class PointLight(Light):
"""点光源,继承自灯光基类"""
def __init__(self,key):
Light.__init__(self,key) self.createLight()
self.setPostition()
self.setRotate()
self.setColor()
self.setIntensity()
self.setDisplay()
self.setShadow()
self.setExposure() #scale aiRadius class SpotLight(Light):
"""聚光灯,继承自灯光基类"""
def __init__(self,key):
Light.__init__(self,key) self.createLight()
self.setPostition()
self.setRotate()
self.setColor()
self.setIntensity()
self.setDisplay()
self.setShadow()
self.setExposure()
self.setAngle()
self.setDropoff()
#重写创建灯光
def createLight(self):
print self.key
self.light = self.obj.createNode("hlight")
self.light.setName(self.key)
#设置为聚光灯
self.coneenable = self.light.parm("coneenable")
self.coneenable.set(True) #设置灯光角度
def setAngle(self):
self.angle = self.light.parm("coneangle")
self.angle.set(data[self.key]["coneAngle"]) #设置灯光衰减
def setDropoff(self):
self.coneroll = self.light.parm("coneroll")
self.coneroll.set(data[self.key]["dropoff"]) #scale aiRadius penumbraAngle class AreaLight(Light):
"""平面光,继承自灯光基类"""
def __init__(self,key):
Light.__init__(self,key) self.createLight()
self.setPostition()
self.setRotate()
self.setColor()
self.setIntensity()
self.setDisplay()
self.setShadow()
self.setExposure()
self.setSize() #重写创建灯光
def createLight(self):
print self.key
self.light = self.obj.createNode("hlight")
self.light.setName(self.key)
#设置为平面光
self.lightType = self.light.parm("light_type")
self.lightType.set(2) #设置灯光角度
def setAngle(self):
self.angle = self.light.parm("coneangle")
self.angle.set(data[self.key]["coneAngle"]) #设置灯光衰减
def setDropoff(self):
self.coneroll = self.light.parm("coneroll")
self.coneroll.set(data[self.key]["dropoff"]) #设置大小
def setSize(self):
self.areasize1 = self.light.parm("areasize1")
self.areasize1.set(data[self.key]["scale"][0][0])
self.areasize2 = self.light.parm("areasize2")
self.areasize2.set(data[self.key]["scale"][0][1]) # aiSpread aiRoundness aiSoftEdge class VolumeLight(Light):
"""体积光,继承自灯光基类"""
def __init__(self,key):
Light.__init__(self,key) self.createLight()
self.setPostition()
self.setRotate()
self.setColor()
self.setIntensity()
self.setDisplay()
self.setShadow()
self.setExposure() #重写创建灯光
def createLight(self):
print self.key
self.geo = self.obj.createNode("geo")
self.geo.setName(self.key + "_sphere") self.light = self.obj.createNode("hlight")
self.lightType = self.light.parm("light_type")
self.lightType.set(6) self.areageometry = self.light.parm("areageometry")
self.areageometry.set("./" + self.key + "_sphere") self.light.setName(self.key) # airadius def createLight():
#遍历字典,创建灯光
for key in data:
#根据灯光类型创建灯光
if data[key]["lightType"]=="ambientLight":
light = AmbientLight(key)
elif data[key]["lightType"] == "directionalLight":
light = DirectionalLight(key)
elif data[key]["lightType"] == "pointLight":
light = PointLight(key)
elif data[key]["lightType"] == "spotLight":
light = SpotLight(key)
elif data[key]["lightType"] == "areaLight":
light = AreaLight(key)
elif data[key]["lightType"] == "volumeLight":
light = VolumeLight(key) obj = hou.node("obj")
#排列节点
obj.layoutChildren()

最后在maya与houdini里面加载这些脚本即可,至于怎么加载,可以参考我另外一篇博文maya灯光导入houdini插件开发——技术文档

maya灯光导入houdini插件开发的更多相关文章

  1. 70部MAYA灯光材质渲染教程合集

    MAYA灯光材质渲染教程合集 教程格式:MP4和flv 两种格式 使用版本:教程不是一年出的教程,各个版本都有 (教程软件为英文版) 清晰度:可以看清软件上的文字 语言:部分中文字幕,其他英文(通过看 ...

  2. 从Maya中导入LightMap到unity中

    导入步骤 1.在Maya中为每一个模型烘焙好帖图(tif格式),会发现烘焙好的图和UV是一一对应的 2.把模型和烘焙帖图导入到Unity中 3.选中材质,修改Shader为 Legacy Shader ...

  3. 游戏开发之UDK引擎介绍和模型导入

    2014-09-18 10:01:3 3.7.5" style="border:0px; vertical-align:middle; max-width:100%"&g ...

  4. CG资源网 - Maya教程

    Maya中mentalray灯光渲染终极训练视频教程 http://www.cgtsj.com/cg/f/vx3627/index.html Maya无人机建模制作训练视频教程第一季 http://w ...

  5. Houdini技术体系 基础管线(三) :UE4以选择区域的方式对地形做生成和更新 上篇

    背景     前一节里,解决了Houdini地形无缝导入到UE4的流程问题.但这种方法也有它的局限性,在实际游戏项目里,LA和LD还是偏向在游戏引擎编辑器里工作,他们的一些设计也会影响到地形的信息,那 ...

  6. cg tut

    Gesture Drawing with Alex Woo Gesture Drawing with Alex Woo and Louis Gonzales http://eisneim.com/?p ...

  7. 游戏引擎架构 (Jason Gregory 著)

    第一部分 基础 第1章 导论 (已看) 第2章 专业工具 (已看) 第3章 游戏软件工程基础 (已看) 第4章 游戏所需的三维数学 (已看) 第二部分 低阶引擎系统 第5章 游戏支持系统 (已看) 第 ...

  8. 十三、File Translator怎么写

    ---恢复内容开始--- 1. File Translator可以将信息从maya中导入和导出. 2. 创建一个file translator需要从MPxFileTranslator继承. 3. 函数 ...

  9. OBJ解析

    OBJ文件是Alias|Wavefront公司为它的一套基于工作站的3D建模和动画软件"Advanced Visualizer"开发的一种标准3D模型文件格式,很适合用于3D软件模 ...

  10. Rasterization 学习笔记

    ======================Barycentric interpolation====================================== <1>2d/3d ...

随机推荐

  1. COOP/COHP(上)-PROOUT

    晶体轨道重叠布居 COOP(crystal orbital overlap population)的一个更为直观的名称是 重叠布居权重的态密度 (overlap population-weighted ...

  2. pytest_runtest_makereport 获取pytest的测试结果和caseid

    目的: 自动获取pytest case执行结果和caseid 存为变量,后续可以和case管理工具集成 @pytest.hookimpl(hookwrapper=True, tryfirst=True ...

  3. k8s_使用k8s部署博客系统svc、secret、configmap(三)

    service service是抽象Pod对外提供服务的地址,将其固化的作用:屏蔽因pod的创删以及扩缩容带来ip变化.service通过自身定义文件的selector的标签配置匹配到需要提供服务的对 ...

  4. mybatis-关联查询1-一对多关联查询

    或者多表单独查询方式

  5. uniapp 跳转链接

    安装 uni-link 超链接 组件在异步里需要 跳转页面 或者 app里打开浏览器,不能自动跳转, 如充值:增加一个弹窗,获取到地址之后,手动点击link,打开app <uni-link :h ...

  6. 理解函数调用_使用argument参数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. We've detected suspicious behavior from phone numbers similar to yours. Please try again later or contact us through our help center at help.openai.com.

    原因 很多人使用该地区号码,被限制住了 解决办法 过会儿再试,或者换个地区接码

  8. vs2010 项目属性窗口

    配置一些项目编译输出的类型(比如是编库还是编demo).编译输出结果的名字.编译输出结果的路径等等 Configuration Properties->General 配置在编译工程所需要的头文 ...

  9. python的global用法

    在python中,我们在函数外定义了一个变量,如果我们想在函数内对这个变量进行操作,就需要在函数内部将这个变量声明为global. 例1 x = 1 def func(): x = 2 func() ...

  10. MySQL 常用命令(2)------数据库操作

    四.数据库操作 1.创建数据库 注意:创建数据库前要先连接mysql数据库 语法:create database <数据库名> 例:创建数据库并分配用户 1.create database ...