I'm trying to get a circular order of connected edges to a vertex.

From the bmesh module, we can have a BMEdgeSeq of linked edges to a vertex with the link_edges function. But the edges list is not ordered (in a circular way)

It is possible from the documentation of BMEdgeSeq to sort with a key, but, where are the possible key ?

Last solution, compute myself an angle between each edge to find a circular order (clockwise or not), but that seems heavy for meshes with a lot of vertices.

Any ideas ?

Thx in advance.

enter image description here

  • $\begingroup$ Clockwise ? But As you might guess, ordering is not necessary for 3 edges and less... $\endgroup$ – minitoine Oct 16 '17 at 12:22
  • $\begingroup$ Have you ever heard about Winged_edge Structure ? Edges are ordered.. Why are you talking about 12 o'clock ? I just need an order. For a cube, it can be 1,2,3 or 2,1,3, or 3,2,1 or 3,1,2, whatever. The important thing to have is to iterate over the edge in a circular way. Why are you talking about a cube ? It's a exception case. Edit: I added a picture, for you and your cube. $\endgroup$ – minitoine Oct 16 '17 at 12:40
  • 1
    $\begingroup$ You have to have some point of reference,. From the winged edge wiki The ordering is such that the surfaces are ordered counter-clockwise with respect to the innate orientation of the intersection edge or using your wonderful images as a guide: The axis of your clock is -vert.normal project the edge vectors onto the plane defined by the normal (the face of the clock) and sort from arbitrary edge. Oh and yeah would only need 12 o'clock if first was needed. $\endgroup$ – batFINGER Oct 16 '17 at 13:09
  • $\begingroup$ Which implies my last solution, that blender don't have this information and that we have to compute it. But a plane projection for each vertex for each vertex edges is very heavy. I am disappointed that such a tool like Blender doesn't give this kind of information. Thx, anyway. $\endgroup$ – minitoine Oct 16 '17 at 13:14
  • 1
    $\begingroup$ Have a look at BMLoops $\endgroup$ – batFINGER Oct 16 '17 at 14:34

Here what i've made for my problem. As pointed out, it uses bmesh and BMLoop structures to do it.

# Return edges around param vertex in counter-clockwise order
def connectedEdgesFromVertex_CCW(vertex):

    first_edge = vertex.link_edges[0]

    edges_CCW_order = []

    edge = first_edge
    while edge not in edges_CCW_order:
        edge = rightEdgeForEdgeRegardToVertex(edge, vertex)

    return edges_CCW_order

# Return the right edge of param edge regard to param vertex
def rightEdgeForEdgeRegardToVertex(edge, vertex):
    right_loop = None

    for loop in edge.link_loops:
        if loop.vert == vertex:
            right_loop = loop
    return loop.link_loop_prev.edge

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.