5
$\begingroup$

I'm trying to iterate through each face on a mesh sequentially.

This works fine with a grid (bpy.ops.mesh.primitive_plane_add(radius = 8)) and it loops through the faces row by row.

Subdividing a mesh though, the faces aren't numbered the same way.

Looping through the faces:

0:1

0:1

0:1

0:2

0:7

So it starts on the right, jumps all the way over to the left, completes the rest of the row, jumps to the beginning of the first row going in the other direction and then fills out the rest of the faces that same way. I guess on behalf of an algorithm.

How can I order them normally? The way a grid does?

.sort.faces() isn't doing anything. I may not be using it right, though

$\endgroup$
5
$\begingroup$

Blender offers a way to sort mesh elements, which you can find in the Mesh menu. This is available as bpy.ops.mesh.sort_elements in python.

The obvious choice of sorting by view X Axis probably won't give you the result you expect at first. Sorting a grid by x axis values gives you multiple rows with the same x location, these tend to get sorted out of order. The trick is to rotate the mesh slightly, say 0.2, then sort the elements, and rotate by -0.2 to align it back again, this gets a nice predictable sorting. Note that the sorting is on the "View Axis", so you can also rotate the view slightly (easier in camera view) before sorting, only what is selected is sorted and the selection type also effects what is sorted, so if you are in vertex select then only the selected vertices are sorted, enable each selection type to sort all elements.

$\endgroup$

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.