13

I got this UV map, and I want to set the position coordinates for all the four vertices to x=0.5 and y=0.5 (in the center of the green pixel).

I've already tried to use bpy.ops.transform.translate(value=(0,0,0)), but this moves the vertices relative to the current position. Is there a way to set specific coordinates/position for the UV vertices?

enter image description here

Jaroslav Jerryno Novotny
  • 51,077
  • 7
  • 129
  • 218
Nils Söderman
  • 586
  • 2
  • 4
  • 11

1 Answers1

20

The uv coordinates are stored in 'loops':

You set ob.data.uv_layers.active.data[loop_index].uv = (0.5, 0.5)

You can see how loops work here:

# Loops per face
for face in ob.data.polygons:
    for vert_idx, loop_idx in zip(face.vertices, face.loop_indices):
        uv_coords = ob.data.uv_layers.active.data[loop_idx].uv
        print("face idx: %i, vert idx: %i, uvs: %f, %f" % (face.index, vert_idx, uv_coords.x, uv_coords.y))

# Or just cycle all loops
for loop in ob.data.loops :
    uv_coords = ob.data.uv_layers.active.data[loop.index].uv
    print(uv_coords)
Jaroslav Jerryno Novotny
  • 51,077
  • 7
  • 129
  • 218