]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mesh_mspgl/mesh.py
Refactor strip generation code and add comments
[libs/gl.git] / blender / io_mesh_mspgl / mesh.py
index 8b3ad37052a62eba8d03237a5386a43cf8775e22..d674dbdb24975c25c2ca9fafca7e61b3e4a5d2cb 100644 (file)
@@ -90,6 +90,10 @@ class Face:
                                return e
                raise KeyError("No edge %s"%(key,))
 
+       def get_neighbors(self):
+               neighbors = [e.other_face(f) for e in self.edges]
+               return list(filter(bool, neighbors))
+
 
 class Line:
        def __init__(self, e):
@@ -358,6 +362,7 @@ class Mesh:
                                v.bino.normalize()
 
        def create_strip(self, face, max_len):
+               # Find an edge with another unused face next to it
                edge = None
                for e in face.edges:
                        other = e.other_face(face)
@@ -368,6 +373,8 @@ class Mesh:
                if not edge:
                        return None
 
+               # Add initial vertices so that we'll complete the edge on the first
+               # iteration
                vertices = face.pivot_vertices(*edge.vertices)
                if len(vertices)==3:
                        result = [vertices[-1], vertices[0]]
@@ -375,10 +382,13 @@ class Mesh:
                        result = [vertices[-2], vertices[-1]]
 
                while 1:
+                       face.flag = True
+
                        vertices = face.pivot_vertices(*result[-2:])
                        k = len(result)%2
 
-                       face.flag = True
+                       # Quads need special handling because the winding of every other
+                       # triangle in the strip is reversed
                        if len(vertices)==4 and not k:
                                result.append(vertices[3])
                        result.append(vertices[2])
@@ -388,11 +398,10 @@ class Mesh:
                        if len(result)>=max_len:
                                break
 
+                       # Hop over the last edge
                        edge = face.get_edge(*result[-2:])
-
-                       next = edge.other_face(face)
-                       if not next or next.flag:
+                       face = edge.other_face(face)
+                       if not face or face.flag:
                                break
-                       face = next
 
                return result