我正在Phyton或Mel寻找一个脚本,可以将不同的材料分配给来自Rhino的OBJ导入文件,并将相同的材料分配给从Rhino导入的下一个OBJ文件。
这可能吗?
以下是我的尝试:
import maya.cmds as cmds
import glob
def importFile(i):
cmds.file(i, i=True, groupReference=True, groupName="myobj")
def materialFile():
cmds.select("myobj")
myMaterial = "blinn2"
cmds.sets( e=True, forceElement= myMaterial + 'SG' )
obj文件部分分组,我需要为每个组分配不同的材料。即:第5组,第6组,第7组
答案 0 :(得分:0)
由于您似乎拥有对象列表和相应的(现有?)着色器,因此没有特别的困难 这是代码。
from maya import cmds
# Here we have the list of all our shaders with the
# polygon shapes or polygon faces on which they are assigned
objectsShaders = {'blinn3': ['pCube4.f[1:3]', 'pCube4.f[5]', 'pCubeShape2'],
'blinn4': ['pCube4.f[0]', 'pCube4.f[4]', 'pCubeShape3'],
'blinn5': ['pSphereShape1']}
# Loop through the dictionary
for shader, allObjs in objectsShaders.items():
# First we retrieve all the shading engine
# connected to the current shader
# (We will assume we only have one)
shaderConnections = cmds.listConnections (shader)
sahdingEngine = ''
for connection in shaderConnections:
if cmds.objectType (connection) == 'shadingEngine':
sahdingEngine = connection
break
# For each object of the list,
# we assign the shader to it
for obj in allObjs:
cmds.sets (obj, edit = True, forceElement = sahdingEngine)
# End statement
print 'All the shaders were successfully re-assigned to their coresponding objects.'
在Maya中指定着色器时,我们实际上将对象形状(或面)连接到shadingEngine,而不是着色器本身。
另一个想法是,你没有将对象添加到集合中,它更像是你将集合分配给对象。这就是原因:
cmds.sets (obj, edit = True, forceElement = sahdingEngine)
而不是(像其他Maya命令一样):
cmds.sets (sahdingEngine, edit = True, forceElement = obj)
修改强>
我使用blinn作为示例,但所有着色器的原理相同(我认为)。