2
$\begingroup$

I'm trying to get edge loop, starting from one edge and continuing as far as the loop goes.

This atrocity (below) doesn't work, because vertex index order is disrupted. So I have no apparent way of telling which edge of link_edges is continuing the loop.

v = bm.verts[0] # vertex at the start of edge loop
ov = edge.other_vert(v)
le = ov.link_edges

while len(le) == 4:

    e = ov.link_edges[-1]
    ov = e.other_vert(ov)

    le = ov.link_edges
$\endgroup$
  • $\begingroup$ What about bpy.ops.mesh.loop_select $\endgroup$ – sambler May 22 '17 at 2:16
  • $\begingroup$ @sambler Mesh operators are not accessible from BMesh. And I do not need to select those edges, I need to add them to the list. $\endgroup$ – Mikhail Rachinskiy May 22 '17 at 8:20
4
$\begingroup$

The solution is to use BMLoop, as it's the only element that has constant direction and doesn't depend on the order of other elements.

This example code works only with manifold geometry where all face normals facing one direction. For more information and examples look in the comments.

e = bm.edges[0] # edge at the start of the edge loop

# get BMLoop that points to the right direction
for loop in e.link_loops:
    if len(loop.vert.link_edges) == 4:
        break

# stop when reach the end of the edge loop
while len(loop.vert.link_edges) == 4:

    # jump between BMLoops to the next BMLoop we need
    loop = loop.link_loop_prev.link_loop_radial_prev.link_loop_prev

    # following edge in the edge loop
    e_next = loop.edge
$\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.