2
$\begingroup$

I want to iterate over the square blocks of the UV map from left to right (and then top to bottom) and find the index in bmesh of the face(s) contained in each of the block (one block can contain multiple faces and vice versa).
Is it possible?

Edit: Even better would be to be able to find the bmesh face indices corresponding to the UV islands.

$\endgroup$
2
  • $\begingroup$ Uv data can be found in the bmesh custom data loops. $\endgroup$
    – sambler
    Commented Sep 6, 2018 at 9:42
  • $\begingroup$ The APIs mentioned here start from bm.faces and map to UV. My need is starting from (or iterating over) UV and mapping on to bmesh. $\endgroup$ Commented Sep 6, 2018 at 9:52

1 Answer 1

1
$\begingroup$

Each Bmesh Face has it's loop of vertices. You get to the UV coords through them:

uv_layer = bm.loops.layers.uv.active
for face in bm.faces:
    for loop in face.loops:
        print(loop[uv_layer].uv)

There is no UV Face Index, this is all that is exposed from python API. You don't get access to what is displayed in UV editor.

You can make your own class of UV_Face and populate an array with it. Each UV_Face will carry the index of Bmesh face and UV coordinates of its vertices. Then you can calculate a median center for each UV_Face and sort the array based on that to have it in left-right top-down order if you need.

If you need UV islands, you will have to match UV coordinates of same values, see what UV_Faces touch at least in an edge, and construct the islands from there.

$\endgroup$

You must log in to answer this question.

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