It doesn’t depend at all on vert order, and that’s by design. Each vert knows its neighbors to both sides regardless of the vertex ordering. The only thing we don’t know is if the left vert, or the right vert is the first neighbor in the list.
Instead of using numbers, I’ll use letters. Hopefully that will illustrate that numbers don’t matter, all that matters is the relationship in neighborDict.
neighborDict = {
a: [e, b],
b: [c, a],
c: [b, d],
d: [c, e],
e: [a, d],
}
Say we start the while loop with vertLoop = [a, b]
. As long as we’ve got 2 verts that are neighbors as the first 2 items in vertLoop
, the code will work (For instance, it would still work if we started with vertLoop = [e, d]
)
So we look in the dict for the last item in the current loop (that’s b
in this case), and see that its neighbors are [c, a]
. So we check, is the first item c
right before b
in vertLoop
? It’s not, so we can append that to vertLoop
.
Now we’ve got vertLoop = [a, b, c]
, so we look in the dict and find c
and see its neighbors are [b, d]
. So we check is b
right before c
in vertLoop
? It is, so we can append the other neighbor to our list. In this case, that’s d
.
This keeps going like that until we get to vertLoop = [a, b, c, d, e, a]
. Notice how a
got added to the end? Well, now the first and last item in the list are the same. That means we’ve come back to where we started, so we’ve got an entire loop! So we can just chop off that ending a
and return.
Now that you’ve got the loop, it’s easy to do something like
vertLoop = reversed(vertLoop)
to reverse it.
Or vertLoop = vertLoop[3:] + vertLoop[:3]
to shift the loop so you’re starting with the item at index 3.