模型无法赋予材质


import pymel.core as pm

def get_mesh_shading_groups(mesh_name):
    # 获取mesh形状节点
    shape_node = pm.listRelatives(mesh_name, shapes=True, fullPath=True)
    if not shape_node:
        return []
    
    # 获取连接到形状节点的shading engines
    shading_engines = pm.listConnections(shape_node[0], type='shadingEngine')
    return shading_engines

def get_shading_group_material(shading_group):
    # 获取连接到shading group的材料
    materials = pm.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
 

sg = get_material(pm.PyNode('HeiYvMao_geo_01')).listConnections(type='shadingEngine')
sg.attr('partition') >> pm.PyNode('renderPartition').sets

评论
  目录