8
$\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$
10
$\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)
| improve this answer | |
$\endgroup$
  • $\begingroup$ and ob = bpy.context.active_object $\endgroup$ – ChameleonScales Aug 13 '17 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.