]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor the mesh exporter to use UVs directly from UV layers
authorMikko Rasa <tdb@tdb.fi>
Sun, 21 Mar 2021 16:14:18 +0000 (18:14 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 21 Mar 2021 16:14:18 +0000 (18:14 +0200)
blender/io_mspgl/mesh.py

index 2296019e4cb3f45062b6bff14e3a147ec6c37c57..f5665256b2eeced61c654abc329d4849e45d82cf 100644 (file)
@@ -83,7 +83,6 @@ class Face:
                self.normal = face.normal
                self.use_smooth = face.use_smooth
                self.material_index = face.material_index
-               self.uvs = []
                self.flag = False
 
        def __cmp__(self, other):
@@ -95,6 +94,9 @@ class Face:
                n = self.vertices.index(v)
                return [(n+i)%len(self.vertices) for i in range(len(self.vertices))]
 
+       def get_loop_index(self, v):
+               return self.loop_indices[self.vertices.index(v)]
+
        def get_edge(self, v1, v2):
                key = make_edge_key(v1.index, v2.index)
                for e in self.edges:
@@ -411,11 +413,6 @@ class Mesh:
                                        for i in f.loop_indices:
                                                l.uvs[i] = mathutils.Vector((*l.uvs[i], layer))
 
-               # Copy UVs from layers to faces
-               for f in self.faces:
-                       for u in self.uv_layers:
-                               f.uvs.append([u.uvs[i] for i in f.loop_indices])
-
                prog_count = len(self.uv_layers)
                prog_step = 0
 
@@ -446,13 +443,13 @@ class Mesh:
                        progress.pop_task()
                        prog_step += 1
 
-               # Copy UVs from faces to vertices
+               # Copy UVs from layers to vertices
                for v in self.vertices:
                        if v.faces:
                                # All faces still connected to the vertex have the same UV value
                                f = v.faces[0]
-                               i = f.vertices.index(v)
-                               v.uvs = [u[i] for u in f.uvs]
+                               i = f.get_loop_index(v)
+                               v.uvs = [u.uvs[i] for u in self.uv_layers]
                        else:
                                v.uvs = [(0.0, 0.0)]*len(self.uv_layers)
 
@@ -530,12 +527,13 @@ class Mesh:
                return group
 
        def find_uv_group(self, vertex, face, index):
-               uv = face.uvs[index][face.vertices.index(vertex)]
+               layer = self.uv_layers[index]
+               uv = layer.uvs[face.get_loop_index(vertex)]
                face.flag = True
 
                group = [face]
                for f in vertex.faces:
-                       if not f.flag and f.uvs[index][f.vertices.index(vertex)]==uv:
+                       if not f.flag and layer.uvs[f.get_loop_index(vertex)]==uv:
                                f.flag = True
                                group.append(f)