我有一个变通的方法来连接Metrial的透明度到Maya中的关键帧栏。我创建一个新的材料按 "s "的关键帧得到了关键帧10,设置透明度为0,并再次按 "s"。
因此,你能够在1和10关键帧之间淡化透明度。
我想在Python中编写这个脚本,但我不知道怎么做。
这是我做的。我用基本的Maya材质进行了测试,但它应该适用于任何具有以下功能的材质。transparency
属性(注意,它不能用于曲面着色器,因为透明度属性被称为 outTransparency
但你可以通过修改函数来解决这个问题,这样你也可以传递属性名)。)
我得到了 getShaderFrom (obj)
作用于 本专题 并且刚刚在Python中进行了转换(它在MEL中)。
我把它做得尽可能的简单和详细,但它可能会被优化。总之,希望这能回答你的问题
from maya import cmds
def getShaderFrom (obj):
'''
List all materials for the given object
'''
# List the shapes of the given object
shapes = cmds.ls (obj, objectsOnly = 1, dagObjects = 1, shapes = 1)
# List the shading engines connected to the shapes
shadingEngines = cmds.listConnections (shapes, type = "shadingEngine")
# List the materails connected to the shading engines
rawMaterials = cmds.ls ((cmds.listConnections (shadingEngines)), materials = 1)
# Remove duplicated occurences of materials
materials = []
for mat in rawMaterials:
if mat not in materials:
materials.append(mat)
return materials
def keyTransparency (startFrame, endFrame, material):
'''
Will key the transparency of
a given materials between
selected frames
'''
# Set transparency value at 1
cmds.setAttr (material + ".transparency", 1,1,1, type = "double3")
# Add a keyframe at last frame
cmds.setKeyframe (material, attribute = "transparency", time = endFrame, inTangentType = "linear", outTangentType = "linear")
# Add a keyframe at first frame
cmds.setKeyframe (material, attribute = "transparency", time = startFrame, inTangentType = "linear", outTangentType = "linear")
# Set transparency value at 0
cmds.setAttr (material + ".transparency", 0,0,0, type = "double3")
def doKeyTransparencyForMaterials (startTime, endTime):
'''
Main function
Call functions: 'getShaderFrom', 'keyTransparency'
'''
if ((not isinstance(startTime, int)) or (not isinstance(endTime, int))):
cmds.error ("You must provide start and end frame numbers (int).")
# List selected objects
selection = cmds.ls (selection = 1)
if len(selection) == 0:
cmds.error ("Nothing is selected.")
# List all materials
for obj in selection:
materials = getShaderFrom (obj)
# Key transparency
for mat in materials:
keyTransparency (startTime, endTime, mat)
print "Transparency has been successfully keyed for: " + (", ".join(materials)) + "\n",
doKeyTransparencyForMaterials (1, 10)
我是这样做的。
import maya.cmds as cmds
######### Delete all existing Shader ##############
cmds.delete (cmds.ls(type='shadingDependNode'))
cmds.delete (cmds.ls(type='shadingEngine'))
######### Delete all existing Shader ##############
######### Delete all Keyframes between 0 and 20 ##############
cmds.setKeyframe( 'lambert1', t='1', at='transparency' )
cmds.cutKey ( t=(0,20) )
######### Delete all Keyframes ##############
#create Blau shader
Blau = cmds.shadingNode('phong', asShader=True, n='Blau', )
cmds.setAttr(Blau + '.color', 0.163,0.284,0.5)
#create KeyFrame Transparency ###Blau####
cmds.setKeyframe( 'Blau', t='1', at='transparency' )
cmds.setAttr ( 'Blau.transparency', 1,1,1, type = "double3")
cmds.setKeyframe( 'Blau', t='15', at='transparency' )
######### update Time to 2 and back to 0 ##############
cmds.currentTime ( 2, update=True )
cmds.currentTime ( 0, update=True )
######### update Time to 2 and back to 0 ##############
lambert1的setKeyFrame一行是为了让脚本在之前没有Key的情况下运行。
我调整了当前时间,因为如果你第一次应用的话,你的素材会显示为透明。
PS:Blau在德语中是蓝色的