我尝试在mayapython中创建一个脚本,通过下拉菜单更改模型的材质,通过滑块更改粗糙度参数来更改模型的纹理。我正在把它应用到我的模型上。任何帮助将不胜感激!在
import maya.cmds as mc
if mc.window("ram", exists=True):
mc.deleteUI(ram)
ram = mc.window("Material and Texture", t="Material and Texture", w=300, h=300)
mc.columnLayout(adj=True)
imagePath = mc.internalVar(upd=True) + "icons/scriptlogo.jpg"
mc.image(w=300, h=200, image=imagePath)
# A dropdown menu deisnged to change material/color of octopus
mc.optionMenu(label="Material",)
myBlinn = mc.menuItem(label="Red")
myBlinn = mc.menuItem(label="Blue")
myBlinn = mc.menuItem(label="Yellow")
myBlinn = mc.menuItem(label="Green")
myBlinn = mc.menuItem(label="Orange")
myBlinn = mc.menuItem(label="Purple")
# A slider designed to alter the intensity of the octopus' texture
mc.intSliderGrp(label="Texture", min=0, max=10, field=True)
# A button to apply any changes
mc.button(label="Apply" a="applyMaterial ()")
mc.showWindow(ram)
def applyMaterial():
currentValue = mc.optionMenu("Material", query=True, value=True)
if currentValue == "Red":
mc.hyperShade(objects='lambert1')
mc.hyperShade(assign='red')
elif currentValue == "Blue":
mc.hyperShade(objects='lambert1')
mc.hyperShade(assign='blue')
elif currentValue == "Yellow":
mc.hyperShade(objects='lambert1')
mc.hyperShade(assign='yellow')
elif currentValue == "Green":
mc.hyperShade(objects='lambert1')
mc.hyperShade(assign='green')
elif currentValue == "Orange":
mc.hyperShade(objects='lambert1')
mc.hyperShade(assign='orange')
elif currentValue == "Purple":
mc.hyperShade(objects='lambert1')
mc.hyperShade(assign='purple')
有一些问题。在
1:按钮语法错误。你忘了逗号。在
2:按钮的参数“a”不存在。使用
command
而不是在函数被单击时运行它。在3:您需要为您的
optionMenu
分配一个变量才能获得其全名。以后要查询此变量的当前值时,可以传递该变量。您应该将变量分配给接口的其余项。在4:没有错误检查。如果lambert1不存在或您的任何其他材质不存在,则此操作将失败。您可以使用
mc.objExists
查看它们是否在场景中。如果没有,向用户抛出一条错误消息,告诉他们创建它,或者让脚本自己创建材质。在如果材料在场景中,以下内容对我来说是可行的:
相关问题 更多 >
编程相关推荐