From: Mikko Rasa Date: Sun, 21 Mar 2021 16:14:18 +0000 (+0200) Subject: Refactor the mesh exporter to use UVs directly from UV layers X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9ab994ab4fedf938cbbdfe1ec1415e6c91844d21;p=libs%2Fgl.git Refactor the mesh exporter to use UVs directly from UV layers --- diff --git a/blender/io_mspgl/mesh.py b/blender/io_mspgl/mesh.py index 2296019e..f5665256 100644 --- a/blender/io_mspgl/mesh.py +++ b/blender/io_mspgl/mesh.py @@ -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)