通过Python在Maya中更改多边形的颜色 [英] Changing polygons' colors in Maya via Python

查看:317
本文介绍了通过Python在Maya中更改多边形的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的唯一方法是使用滑块:

The only way I know is to use a slider:

import maya.cmds as cmds

cmds.colorSliderGrp( 'polygonColour', label = "Colour", hsv = ( 1, 1, 1 ) )

然后从中获取RGB值:

Then taking the RGB value from that:

rgb = cmds.colorSliderGrp( 'polygonColour', query = True, rgbValue = True )

然后将材质分配给多边形,并为其赋予颜色:

And then assigning a material to the polygon and giving that material the color:

myShader = cmds.shadingNode( 'lambert', asShader = True, name = "polygonMaterial" )
cmds.setAttr( 'polygon1' + ":blockMaterial.color", rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], type = 'double3' )

有没有使用滑块和/或不分配材料的简便方法?

Is there an easier approach without using a slider and/or without assigning a material?

推荐答案

如果只想为现有的着色器分配新的颜色,则它很简单setAttr().每个着色器都有自己的属性集,因此需要设置的确切值取决于所需的着色器类型,但是对于常见情况(lambert,phong和blinn),它只是.color属性.设置颜色就像传入所需的RGB值一样简单:

If you just want to assign a new color to the existing shader(s), it's a simple setAttr(). Every shader has it's own attribute set, so the exact values you need to set depend on the type of shader you want, but for common cases (lambert, phong, and blinn) it's just the .color attribute. Setting the color is as simple as passing in the RGB values you want:

 cmds.setAttr(shader + '.color', 0, 1, 0)  # green

在特定的面部上获取着色器并不容易.最简单的方法是露出脸并检查所有shadingEngine节点:

Getting the shader on a particular face is not easy. The easiest thing to do is to get your face and check all the shadingEngine nodes :

 for shadingEngine in cmds.ls(type="shadingEngine"):
     if cmds.sets('pCube1.f[0]', im=shadingEngine):
        shaderball = cmds.listConnections(sshadingEngine, type = 'lambert')[0]
        print "face is assigned to %s" % shaderball

您可以通过以下方式将着色器分配给面部 一世 cmds.sets('pCube1.f [99]',fe ='initialShadingGroup')

You can assign a shader to a face by i cmds.sets('pCube1.f[99]', fe='initialShadingGroup')

其中,fe的参数是shadingEngine节点.着色器球-您用手编辑的东西-连接到shadingEngine的.surfaceMaterial属性,您可以像我上面所做的那样获得它.

where the argument to fe is the shadingEngine node. The shader ball - the thing you edit by hand - is connected to the shadingEngine's .surfaceMaterial attribute, you can get it the way I did above.

如果要在没有着色器分配的情况下更改面的颜色,则要改用顶点颜色.菜单为颜色>应用颜色,命令为polyColorPerVertex (faces, rgb=(r,g,b).因此,在多维数据集上设置一张脸的颜色看起来像

If you want to change the color of a face without shader assignment you want to make vertex colors instead. The menu is Color > Apply Color, the command is polyColorPerVertex (faces, rgb=(r,g,b). So setting the color of one face on a cube looks like

 cmds.polyColorPerVertex('pCube1', rgb=(1,0,0)) # red

视口中顶点颜色的显示由.displayColors属性或颜色">切换显示颜色"属性菜单项控制.

The display of the vertex colors in the viewport is controlled by the .displayColors attribute or the Colors > Toggle Display Colors Attribute menu item.

这篇关于通过Python在Maya中更改多边形的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆