之前我曾经问过这个Pyhton脚本,但是现在我遇到了一个新问题:我希望我的脚本的纹理滑块影响我模型的凹凸深度,但我不知道怎么做。那里有人可以帮助我吗?我在我的模型中应用了凹凸贴图纹理,我只需要帮助将下图中的滑块变为Python格式。
import maya.cmds as mc
if mc.window("Mat_Tex", exists=True):
mc.deleteUI(ram)
ram = mc.window("Mat_Tex", 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
matOptionMenu = 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
texBumpDepth = mc.floatSliderGrp(label="Texture", min=-5, max=5, field=True)
def applySlider(*args):
slidervalue = mc.floatSliderGrp(texBumpDepth, q = True, value = True)
# here is where you want to do something with the value
print "setting bump value to", slidervalue
# it will probably look like
mc.setAttr( "bump2d2" + ".bumpDepth", slidervalue)
def set_shader_bump_depth(shader, amount):
bump2ds = mc.listConnections(shader, type = 'bump2d')
# that's always list, so we loop over it
for eachbump2d in bump2ds:
print "editing", eachbump2d
mc.setAttr(eachbump2d + ".bumpDepth", amount)
mc.floatSliderGrp(texBumpDepth, e=True, changeCommand = applySlider)
def applyMaterial(*args):
currentValue = mc.optionMenu(matOptionMenu, query=True, value=True)
if currentValue == "Red":
mc.hyperShade(assign='red')
elif currentValue == "Blue":
mc.hyperShade(assign='blue')
elif currentValue == "Yellow":
mc.hyperShade(assign='yellow')
elif currentValue == "Green":
mc.hyperShade(assign='green')
elif currentValue == "Orange":
mc.hyperShade(assign='orange')
elif currentValue == "Purple":
mc.hyperShade(assign='purple')
# A button to apply any changes
mc.button(label="Apply", command=applyMaterial)
mc.showWindow(ram)
答案 0 :(得分:0)
有几件事情在这里受到影响:
mc.button(label="Apply", command="applyMaterial()" command="applyTexture()")
看起来您真正想要的是按钮上的applyMaterial
和附加到其{的滑块上的applyTexture
{1}} 这里是gui部分的返工,如上所述:
changeCommand
要实际编辑凹凸节点,您需要在使用着色器后执行以下步骤:
import maya.cmds as mc
if mc.window("Mat_Tex", exists=True):
mc.deleteUI(ram)
ram = mc.window("Mat_Tex", 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
matOptionMenu = 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
texBumpDepth = mc.intSliderGrp(label="Texture", min=-5, max=5, field=True)
def applySlider(*args):
slidervalue = mc.intSliderGrp(texBumpDepth, q = True, value = True)
# here is where you want to do something with the value
print "setting bump value to", slidervalue
# it will probably look like
# mc.setAttr( your_bump2dnode_here + ".bumpDepth", slidervalue
mc.intSliderGrp(texBumpDepth, e=True, changeCommand = applySlider)
def applyMaterial(*args):
currentValue = mc.optionMenu(matOptionMenu, query=True, value=True)
if currentValue == "Red":
mc.select('octopusModel')
mc.hyperShade(assign='red')
elif currentValue == "Blue":
mc.select('octopusModel')
mc.hyperShade(assign='blue')
elif currentValue == "Yellow":
mc.select('octopusModel')
mc.hyperShade(assign='yellow')
elif currentValue == "Green":
mc.select('octopusModel')
mc.hyperShade(assign='green')
elif currentValue == "Orange":
mc.select('octopusModel')
mc.hyperShade(assign='orange')
elif currentValue == "Purple":
mc.select('octopusModel')
mc.hyperShade(assign='purple')
# A button to apply any changes
mc.button(label="Apply", command=applyMaterial)
mc.showWindow(ram)
看起来像这样:
1. get the connections from the shader that are `bump2d` nodes
2. use `mc.setAttr` to set the value