我正在使用Adobe的substance painter给出的脚本,该脚本应该导入sbsar文件,并将其转换为着色器 node ,然后将其应用到选定的对象,但当我执行脚本时,它将其应用到场景中的所有对象.

import maya.cmds as cmds 
 
def _connect_place2d(substance_node): 
    """ Connects the place2d texture node to the Substance node """ 
    place_node = cmds.shadingNode('place2dTexture', asUtility=True) 
 
    connect_attrs = [('outUV', 'uvCoord'), ('outUvFilterSize', 'uvFilterSize')] 
 
    for out_attr, in_attr in connect_attrs: 
        cmds.connectAttr('{}.{}'.format(place_node, out_attr), 
                         '{}.{}'.format(substance_node, in_attr)) 
 
def _find_shading_group(node): 
    """ Walks the shader graph to find the shading group """ 
    result = None 
 
    connections = cmds.listConnections(node, source=False) 
 
    if connections: 
        for connection in connections: 
            if cmds.nodeType(connection) == 'shadingEngine': 
                result = connection 
            else: 
                result = _find_shading_group(connection) 
                if result is not None: 
                    break 
 
    return result 
 
def _apply_substance_workflow_to_selected(substance_file, workflow): 
    """ Imports a mesh into Maya and applies the shader from a 
        Substance workflow to it """ 
    geometry = cmds.ls(geometry=True) 
 
    # Create the substance node and connect the place2d texture node 
    substance_node = cmds.shadingNode('substanceNode', asTexture=True) 
    _connect_place2d(substance_node) 
 
    # Load the Substance file 
    cmds.substanceNodeLoadSubstance(substance_node, substance_file) 
 
    # Apply the workflow 
    cmds.substanceNodeApplyWorkflow(substance_node, workflow=workflow) 
 
    # Acquire the shading group and apply it to the mesh 
    shading_group = _find_shading_group(substance_node) 
 
 
def demo_load_sbsar_workflow(): 
    """ Acquires an sbsar from a file dialog, loading and applying it to 
        any selected mesh """ 
    file_filter = 'Substance (*.sbsar);;' 
 
    files = cmds.fileDialog2(cap='Select a Substance file', fm=1, dialogStyle=2, 
                             okc='Open', fileFilter=file_filter) 
 
    if files: 
        substance_file = files[0] 
        _apply_substance_workflow_to_selected(substance_file, 
                                              cmds.substanceGetWorkflow()) 
 
if __name__ == '__main__': 
    demo_load_sbsar_workflow()

我完全期望它能立即将选定的纹理应用到我选定的网格上,而不是每个对象.

推荐答案

geometry = cmds.ls(geometry=True)简单地 Select 所有的几何,如果您将其交换为:

geography = cmds.ls(sl = True,geography = True)

它只 Select 选定的形状,但你必须 Select 形状 node .

Python相关问答推荐

根据条件将新值添加到下面的行或下面新创建的行中

使用新的类型语法正确注释ParamSecdecorator (3.12)

'discord.ext. commanders.cog没有属性监听器'

未删除映射表的行

在Python Attrs包中,如何在field_Transformer函数中添加字段?

如何列举Pandigital Prime Set

C#使用程序从Python中执行Exec文件

在vscode上使用Python虚拟环境时((env))

当递归函数的返回值未绑定到变量时,非局部变量不更新:

Python中的变量每次增加超过1

重置PD帧中的值

如何将数据帧中的timedelta转换为datetime

Polars map_使用多处理对UDF进行批处理

我对这个简单的异步者的例子有什么错误的理解吗?

使用tqdm的进度条

Python—在嵌套列表中添加相同索引的元素,然后计算平均值

如何获得满足掩码条件的第一行的索引?

如何防止html代码出现在quarto gfm报告中的pandas表之上

无法在盐流道中获得柱子

按最大属性值Django对对象进行排序