]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_mesh.py
Small optimization for mesh exporter performance
[libs/gl.git] / blender / io_mspgl / export_mesh.py
index 07f457a1e36720c06ee27475fd4176924f07a669..541874b2bd2018c052d286962956a0a0a45f77b6 100644 (file)
@@ -64,6 +64,7 @@ class MeshExporter:
                        cache = VertexCache(self.cache_size)
 
                island = []
+               face_neighbors = []
                island_strips = []
                while 1:
                        if not island:
@@ -83,11 +84,13 @@ class MeshExporter:
                                        face = queue.pop(0)
                                        island.append(face)
 
-                                       for n in f.get_neighbors():
+                                       for n in face.get_neighbors():
                                                if not n.flag:
                                                        n.flag = True
                                                        queue.append(n)
 
+                               face_neighbors = [f.get_neighbors() for f in island]
+
                                # Unflag the island for the next phase
                                for f in island:
                                        f.flag = False
@@ -97,11 +100,11 @@ class MeshExporter:
                        # or along borders of a non-closed island.
                        best = 5
                        face = None
-                       for f in island:
+                       for i, f in enumerate(island):
                                if f.flag:
                                        continue
 
-                               score = sum(not n.flag for n in f.get_neighbors())
+                               score = sum(not n.flag for n in face_neighbors[i])
                                if score>0 and score<best:
                                        face = f
                                        best = score
@@ -195,7 +198,7 @@ class MeshExporter:
 
        def export(self, context, out_file, objs=None, progress=None):
                if objs:
-                       objs = [(o, mathutils.Matrix()) for i in objs]
+                       objs = [(o, mathutils.Matrix()) for o in objs]
 
                if self.compound:
                        if objs is None:
@@ -230,7 +233,10 @@ class MeshExporter:
 
                mesh = None
                bmeshes = []
+               winding_test = False
                for o, m in objs:
+                       if o.data.winding_test:
+                               winding_test = True
                        bmesh = o.to_mesh(context.scene, True, "PREVIEW")
                        bmeshes.append(bmesh)
                        me = Mesh(bmesh)
@@ -318,10 +324,11 @@ class MeshExporter:
                fmt = ["NORMAL3"]
                if texunits:
                        for i, u in texunits:
+                               size = str(len(mesh.vertices[0].uvs[i]))
                                if u.unit==0 or force_unit0:
-                                       fmt.append("TEXCOORD2")
+                                       fmt.append("TEXCOORD"+size)
                                else:
-                                       fmt.append("TEXCOORD2_%d"%u.unit)
+                                       fmt.append("TEXCOORD%s_%d"%(size, u.unit))
                        if self.tbn_vecs:
                                fmt += ["TANGENT3", "BINORMAL3"]
                if self.export_groups:
@@ -339,10 +346,11 @@ class MeshExporter:
                                normal = v.normal
                        for i, u in texunits:
                                if v.uvs[i]!=uvs.get(i):
+                                       size = str(len(v.uvs[i]))
                                        if u.unit==0 or force_unit0:
-                                               out_file.write("texcoord2", *v.uvs[i])
+                                               out_file.write("texcoord"+size, *v.uvs[i])
                                        else:
-                                               out_file.write("multitexcoord2", u.unit, *v.uvs[i])
+                                               out_file.write("multitexcoord"+size, u.unit, *v.uvs[i])
                                        uvs[i] = v.uvs[i]
                        if self.tbn_vecs:
                                if v.tan!=tan:
@@ -387,6 +395,9 @@ class MeshExporter:
                                out_file.write("indices", l.vertices[0].index, l.vertices[1].index)
                        out_file.end()
 
+               if winding_test:
+                       out_file.write("winding", "COUNTERCLOCKWISE")
+
                if progress:
                        progress.set_task("Done", 1.0, 1.0)