首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用pymel (或maya.cmds)将UV从自定义UVset链接到Maya中的纹理

如何使用pymel (或maya.cmds)将UV从自定义UVset链接到Maya中的纹理
EN

Stack Overflow用户
提问于 2019-09-25 08:02:20
回答 1查看 461关注 0票数 0

我正在写一个工具,它将帮助我在一个模型上制作自定义的uvSets,该模型将链接到将被发送到vray_extraTex render elements的渐变(无插值)。这些将成为遮罩,并以与vRay多遮罩相同的方式使用。但是,我无法使用pymel将我的vray_extraTex纹理渐变链接到自定义uvSet。

我可以在Maya中手动完成所有这些操作,但由于某些原因,我缺少pymel将UV链接到渐变的功能。我在Maya场景中使用一个有两个uvSets且第二个集处于活动状态的pSphere进行测试。这段代码已经被精简了一点:

代码语言:javascript
运行
复制
def main():
    inclusiveSet = None
    renderElements =[]
    ramps = []
    newChannels = ['TestA','TestB','TestC','TestD'] 
    for i, channel in enumerate(newChannels):
        modIndex = i % 3 # 0:Red, 1:Green, 2:Blue
        shapeNode=pm.PyNode('pSphereShape1')
        transformNode=shapeNode.getTransform()

        if modIndex == 0: # the first channel in the new Render Element
            # make an etex render element
            eTexElement = pm.PyNode(pm.mel.eval('vrayAddRenderElement("ExtraTexElement")'))
            eTexElement.vray_name_extratex.set('')
            eTexElement.vray_explicit_name_extratex.set('empty_empty_empy')            
            renderElements.append(eTexElement)
            # make a ramp
            ramp = pm.shadingNode('ramp', asTexture=True, name='eTex_{}_ramp'.format(transformNode.name()))
            ramps.append(ramp)
            ramp.outColor.connect(eTexElement.vray_texture_extratex)
            # make a place2dtexture
            place2d = pm.shadingNode('place2dTexture', asUtility=True)
            place2d.outUV.connect(ramp.uv)
            place2d.translateFrameU.set(len(renderElements) - 1)
            # link UVs to ramp
            # NOT WORKING
            indices = pm.polyUVSet(shapeNode.name(), query=True, allUVSetsIndices=True)
            currentUVSet = pm.polyUVSet(shapeNode, query=True, currentUVSet=True )
            for i in indices:
                if currentUVSet == pm.getAttr("{}.uvSet[{}].uvSetName".format(shapeNode.name(), i)):
                    pm.uvLink(uvSet='{}.uvSet[{}].uvSetName'.format(shapeNode.name(), i) , texture=ramp)

        explicit_name = eTexElement.vray_explicit_name_extratex.get()
        nameTokens = explicit_name.split('_')
        nameTokens[modIndex] = channel
        explicit_name = '_'.join(nameTokens)
        eTexElement.vray_explicit_name_extratex.set(explicit_name)

main()

我没有得到任何错误,但是当我检查UV链接时,渐变仍然设置为map1 uvSet,而不是第二个处于活动状态的集。

我希望看到连接到uvChooser节点并链接到第二个uvSet的渐变。

我在写这篇文章时意识到,也许我需要将渐变附加到指定给geo的着色器上,然后才能将它们与python进行uvlink。接下来我将尝试并测试这一点

EN

回答 1

Stack Overflow用户

发布于 2019-09-25 11:29:47

因此,经过一些测试后,我能够让它工作后,在对象的着色器上分配了一个新的属性,并对我之前发布的代码进行了一些次要的修复。已修复:

代码语言:javascript
运行
复制
def connectTexture(layeredTex, shapeNode):
    shadingGrps = pm.listConnections(shapeNode,type='shadingEngine')
    shaders = pm.ls(pm.listConnections(shadingGrps),materials=1)
    shader = shaders[0]
    pm.addAttr(shader, longName='eTexLayeredTex', usedAsColor=True, attributeType='float3' )
    pm.addAttr(shader, longName='eTexLayeredTexR', attributeType='float', parent='eTexLayeredTex' )
    pm.addAttr(shader, longName='eTexLayeredTexG', attributeType='float', parent='eTexLayeredTex' )
    pm.addAttr(shader, longName='eTexLayeredTexB', attributeType='float', parent='eTexLayeredTex' )
    layeredTex.outColor.connect(shader.eTexLayeredTex)


def main():
    inclusiveSet=None
    renderElements=[]
    ramps=[]
    newChannels = ['TestA','TestB','TestC','TestD']
    shapeNode=pm.PyNode('pSphereShape1')
    transformNode=shapeNode.getTransform()

    # make a layeredTexture
    layeredTexture = pm.shadingNode('layeredTexture', asTexture=True, name='eTex_{}_layeredTexture'.format(transformNode.name()))
    layeredTexture.attr('inputs')[0].color.set(0,0,0)
    layeredTexture.attr('inputs')[0].alpha.set(1)
    layeredTexture.attr('inputs')[0].blendMode.set(1)
    connectTexture(layeredTexture, shapeNode)
    for i, channel in enumerate(newChannels):
        modIndex = i % 3 # 0:Red, 1:Green, 2:Blue
        if modIndex == 0: # the first channel in the new Render Element

            # make an etex render element
            eTexElement = pm.PyNode(pm.mel.eval('vrayAddRenderElement("ExtraTexElement")'))
            eTexElement.vray_name_extratex.set('')
            eTexElement.vray_explicit_name_extratex.set('empty_empty_empy')            
            renderElements.append(eTexElement)

            # make a ramp
            ramp = pm.shadingNode('ramp', asTexture=True, name='eTex_{}_ramp'.format(transformNode.name()))
            ramps.append(ramp)
            ramp.interpolation.set(0)
            ramp.colorEntryList[0].position.set(0.0)
            ramp.colorEntryList[1].position.set((1.0 / 3.0))
            ramp.colorEntryList[2].position.set((2.0 / 3.0))
            ramp.colorEntryList[0].color.set(1,0,0)
            ramp.colorEntryList[1].color.set(0,1,0)
            ramp.colorEntryList[2].color.set(0,0,1)
            ramp.defaultColor.set(0,0,0)            
            ramp.outColor.connect(eTexElement.vray_texture_extratex)
            ramp.outColor.connect( layeredTexture.attr( 'inputs[{}].color'.format( 1 + i // 3)))

            # make a place2dtexture
            place2d = pm.shadingNode('place2dTexture', asUtility=True)
            place2d.outUV.connect(ramp.uv)
            place2d.outUvFilterSize.connect(ramp.uvFilterSize)
            place2d.wrapU.set(0)
            place2d.wrapV.set(0)
            place2d.translateFrameU.set(len(renderElements) - 1)

            # link UVs to ramp
            indices = pm.polyUVSet(shapeNode.name(), query=True, allUVSetsIndices=True)
            currentUVSet = pm.polyUVSet(shapeNode, query=True, currentUVSet=True )[0]
            for index in indices:
                if currentUVSet == pm.getAttr('{}.uvSet[{}].uvSetName'.format(shapeNode.name(), index)):
                    pm.uvLink(uvSet='{}.uvSet[{}].uvSetName'.format(shapeNode.name(), index) , texture=ramp)

        explicit_name = eTexElement.vray_explicit_name_extratex.get()
        nameTokens = explicit_name.split('_')
        nameTokens[modIndex] = channel
        explicit_name = '_'.join(nameTokens)
        eTexElement.vray_explicit_name_extratex.set(explicit_name)

main()

关键是将渐变连接到指定给对象的材质。奇怪的是,在制作了uvLinks之后,您可以删除渐变和材质之间的连接,并且uvLinks仍然可以正常工作。我发了这篇文章,以防有人遇到类似的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58089498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档