4
$\begingroup$

Let's suppose I create a bmesh with the following commands:

import bmesh
bm = bmesh.new()
bm.from_mesh(obj.data)
bmesh.ops.triangulate(bm, faces=bm.faces)

Have a look at the following picture to get to know what counterclockwise (CCW) and clockwise (CW) indexing means:

CCW vs CW

Now when I iterate over the meshes faces after triangulating it is there any indication/standard in what order (CCW or CW) relative to the faces front/normal I will iterate over the loops of each face? Is it safe to assume that I will the following script will either always output [1,2,3] or [3,2,1] for a triangle like seen above?

l = []
for face in bm.faces:
    for loop in face.loops:
        l.append(loop.vert.index)
assert l==[1,2,3] // Or [3,2,1], or one of those lists rotated

PS: Can anyone propose a nice solution that will always guarantee CCW indexing for the faces loops?

$\endgroup$
2

1 Answer 1

3
$\begingroup$

From https://wiki.blender.org/wiki/Source/Modeling/BMesh/Design:

Loops store several handy pointers:

  • v - pointer to the vertex at the start of the edge (where "start" is defined by CCW order)

this means that CCW indexing can be assumed if I don't get it wrong. Also note that the loop-list on the face is circular according to this:

Faces link to a loop in the loop cycle, the circular linked list of loops defining the boundary of the face.

$\endgroup$

You must log in to answer this question.

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