13
$\begingroup$

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

$\endgroup$

1 Answer 1

20
$\begingroup$

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)
$\endgroup$
1
  • $\begingroup$ and ob = bpy.context.active_object $\endgroup$ Aug 13, 2017 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .