]> git.tdb.fi Git - libs/gl.git/commitdiff
Simplify the vertex splitting algorithm
authorMikko Rasa <tdb@tdb.fi>
Sat, 4 May 2019 20:16:58 +0000 (23:16 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 4 May 2019 20:16:58 +0000 (23:16 +0300)
It now uses single-pass loops instead of temporary lists where feasible.

blender/io_mspgl/mesh.py

index a05d4537c384ab6fb5517a7f360f0084636df9d1..077acc2e57014227a652ad64ff268061b18c1e7b 100644 (file)
@@ -378,61 +378,54 @@ class Mesh:
                                v.uvs = [(0.0, 0.0)]*len(self.uv_layers)
 
        def split_vertices(self, find_group_func, progress, *args):
-               groups = []
-               for i in range(len(self.vertices)):
+               vertex_count = len(self.vertices)
+               for i in range(vertex_count):
                        v = self.vertices[i]
                        for f in v.faces:
                                f.flag = False
 
-                       vg = []
+                       groups = []
                        for f in v.faces:
                                if not f.flag:
-                                       vg.append(find_group_func(v, f, *args))
+                                       groups.append(find_group_func(v, f, *args))
 
-                       groups.append(vg)
+                       for g in groups[1:]:
+                               nv = Vertex(v)
+                               nv.index = len(self.vertices)
+                               self.vertices.append(nv)
 
-                       progress.set_progress(i*0.5/len(self.vertices))
-
-               for i in range(len(self.vertices)):
-                       for g in groups[i][1:]:
-                               v = Vertex(self.vertices[i])
-                               v.index = len(self.vertices)
-                               self.vertices.append(v)
-
-                               v_edges = []
-                               for e in self.vertices[i].edges:
+                               for e in v.edges:
                                        e_faces_in_g = [f for f in e.faces if f in g]
-                                       if e_faces_in_g:
-                                               boundary = len(e_faces_in_g)<len(e.faces)
-                                               v_edges.append((e, boundary, e_faces_in_g))
+                                       if not e_faces_in_g:
+                                               continue
 
-                               for e, boundary, e_faces_in_g in v_edges:
-                                       if boundary:
+                                       if len(e_faces_in_g)<len(e.faces):
                                                ne = Edge(e)
                                                ne.index = len(self.edges)
                                                self.edges.append(ne)
 
-                                               ne.other_vertex(self.vertices[i]).edges.append(ne)
+                                               ne.other_vertex(v).edges.append(ne)
 
                                                for f in e_faces_in_g:
                                                        e.faces.remove(f)
                                                        f.edges[f.edges.index(e)] = ne
                                                        ne.faces.append(f)
+
                                                e = ne
-                                       else:
-                                               self.vertices[i].edges.remove(e)
 
-                                       e.vertices[e.vertices.index(self.vertices[i])] = v
-                                       v.edges.append(e)
+                                       e.vertices[e.vertices.index(v)] = nv
+                                       nv.edges.append(e)
 
                                        e.key = make_edge_key(e.vertices[0].index, e.vertices[1].index)
 
+                               v.edges = [e for e in v.edges if v in e.vertices]
+
                                for f in g:
-                                       self.vertices[i].faces.remove(f)
-                                       f.vertices[f.vertices.index(self.vertices[i])] = v
-                                       v.faces.append(f)
+                                       v.faces.remove(f)
+                                       f.vertices[f.vertices.index(v)] = nv
+                                       nv.faces.append(f)
 
-                       progress.set_progress(0.5+i*0.5/len(self.vertices))
+                       progress.set_progress(i/vertex_count)
 
        def find_smooth_group(self, vertex, face):
                face.flag = True