Home Technical Talk

Move each UV vertex by vector

set
set
null
Offline / Send Message
set null

I want to create second uv set, and then move each uv vertex in an object by vector (u=0, v=1.0/number of vertices). The new uv vertex coordinates created for 4 vertices plane should go like this: for vertex 0 (u=0,v=0), for vertex 1 (u=0, v=0.25), for vertex 2 (u=0, v=0.5), for vertex 3 (u=0,v=0.75)etc.

I have 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;

As far as my reaserch goesm there is no vectors in python, and now I'm stuck with the soulution. So far I came up this:

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)

but the output I get is the second UV set with every vertex in (0,0) UV coordinates. Can anyone help me? Any MEL/Python solution would be appricieted.


Sign In or Register to comment.