Home Technical Talk

Move each UV vertex by vector

set
set
null
Offline / Send Message
set null
Hi there
I'm trying to get a similar output in maya of the c#code below:

basicly I'm trying to create a second UVset and then move each vertex by a given vector, (u=0, v=1/vertexCount) in which vertexCount is a number of vertices. Each vertex v posision is actually offset by v=1/vertex count, so for 4vertex plane  vertx's 0 uv is0,0, for vertex 1 uv(0,0.25), for vertex 2 uv(0, 0.5) for vertex 3 uv(0,0.75) etc.
As far as my reaserch went, python doesn't run on vectors, and instead I should do an array of the list and then run a for loop, but I'm getting stuck in setting a virable in the for loop which would be corresponding to the csharp vector 2
There is a source code in 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;

So far i got this
#creating second UVset
cmds.polyUVSet( create=True, uvSet='map2' )
#getting number of vertices
vertexCount = cmds.polyEvaluate (v=True)
vertexCount_float= float(vertexCount)
#setting a vriable
offset=1.0/vertexCount
#getting an array of selected vertices
sel=cmds.ls(sl=1, fl=1)
#move each uv vertex
for i in sel:
    i=0, i<sel
    cmds.polyEditUV(uValue=0.0, vValue=offset)

The output is that I get a second uvset, but coordinates of each vertex are (0,0) - thay don't offset as I assmed. Can anyone help? Any MEL/Python solutuion would be appreciated.
   




Sign In or Register to comment.