我想创建第二个UV集,然后按向量u=0, v=1.0/number of vertices
移动对象中的每个UV顶点。为4个顶点平面创建的新UV顶点坐标应如下所示:对于顶点0 (u=0,v=0)
,对于顶点1 (u=0,v=0.25)
,对于顶点2 (u=0,v=0.5)
,对于顶点3 (u=0,v=0.75)
等等。
我在C#中有源代码:
Vector2[] UV2 = new Vector2[m.vertexCount];
float HalfTexelSize = (1f/ (float)m.vertexCount)/2f;
for (int i = 0; i < m.vertexCount; i++) {
UV2[i] = new Vector2(0f, (float)i / (float)m.vertexCount) + new Vector2(0f, HalfTexelSize);
}
m.uv2 = UV2;
meshFilter.mesh = m;
就我的研究而言,Python中没有向量,现在我坚持使用解决方案。到目前为止,我提出了这个问题:
import maya.cmds as cmds
cmds.polyUVSet(create=True, uvSet='map2')
vertexCount = cmds.polyEvaluate(v=True)
vertexCount_float = float(vertexCount)
HalfTextureSize = (1.0/vertexCount/2.0)
x = 1.0/vertexCount
sel = cmds.ls(sl=1, fl=1)
for i in sel:
i=0, i<sel
cmds.polyEditUV(uValue=0.0, vValue=x)
但我获得的输出是第二个UV集合,每个顶点都在(0,0)UV坐标中。谁能帮我?任何MEL / Python解决方案将不胜感激。
答案 0 :(得分:0)
默认情况下没有矢量maya pyhon。
如果你想要一个vanilla python-only解决方案this project是一个单文件向量库。
您还可以直接使用API从maya获取3个载体:
from maya.api.OpenMaya import MVector
v1 = MVector(1,2,3)
v2 = MVector(3,4,5)
print v1 + v2
这些是3d矢量,但您可以忽略3d组件
对于实际创建和编辑UV集,需要考虑几个复杂性
最终解决方案将如下所示:
import maya.cmds as cmds
# work on only one selected object at a time
selected_object = cmds.ls(sl=1, fl=1)[0]
vertexCount = cmds.polyEvaluate(selected_object, v=True)
# add a projection so you have 1-1 vert:uv mapping
cmds.polyPlanarProjection(selected_object, cm=True)
# get the name of the current uv set
latest_uvs = cmds.polyUVSet(selected_object, q=True, auv=True)
# it's a unioode by default, has to be a string
new_uv = str(latest_uvs[-1])
# set the current uv set to the newly created one
cmds.polyUVSet(selected_object, e=True, cuv = True, uvs=new_uv)
vert_interval = 1.0 / vertexCount
for vert in range (vertexCount):
uv_vert = "{}.map[{}]".format (selected_object, vert)
cmds.polyEditUV( uv_vert, u= 0, v = vert * vert_interval, relative=False, uvs=new_uv)