import maya.cmds as cmds
def get_mesh_shading_groups(mesh_name):
# 获取mesh形状节点
shape_node = cmds.listRelatives(mesh_name, shapes=True, fullPath=True)
if not shape_node:
return []
# 获取连接到形状节点的shading engines
shading_engines = cmds.listConnections(shape_node[0], type='shadingEngine')
return shading_engines
def get_shading_group_material(shading_group):
# 获取连接到shading group的材料
materials = cmds.listConnections(shading_group + ".surfaceShader")
if not materials:
return None
return materials[0]
def get_material(mesh):
mesh_name = mesh.name()
shading_groups = get_mesh_shading_groups(mesh_name)
for shading_group in shading_groups:
material = get_shading_group_material(shading_group)
return material
get_material('mesh')
上一篇
获取uv的udim象限
2024-05-10
下一篇
获取物体上是否有关键帧
2024-05-10