From ccce05f213b3e97e18d88c1665c144df7ed1c218 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 26 Jul 2012 23:46:11 +0300 Subject: [PATCH] Adapt exporter to Blender 2.63 --- blender/io_mesh_mspgl/export_mspgl.py | 8 ++++---- blender/io_mesh_mspgl/mesh.py | 28 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/blender/io_mesh_mspgl/export_mspgl.py b/blender/io_mesh_mspgl/export_mspgl.py index 1d7062e6..5a1bbe11 100644 --- a/blender/io_mesh_mspgl/export_mspgl.py +++ b/blender/io_mesh_mspgl/export_mspgl.py @@ -248,15 +248,15 @@ class Exporter: mesh.generate_material_uv() texunits = [] - if mesh.uv_textures and self.export_uv!="NONE": + if mesh.uv_layers and self.export_uv!="NONE": if self.export_uv=="UNIT0": texunits = [0] else: - texunits = list(range(len(mesh.uv_textures))) + texunits = list(range(len(mesh.uv_layers))) tbn_unit = 0 if self.tbn_vecs: - uvtex_names = [u.name for u in mesh.uv_textures] + uvtex_names = [u.name for u in mesh.uv_layers] if self.tbn_uvtex in uvtex_names: tbn_unit = uvtex_names.index(uvtex) del texunits[tbn_unit] @@ -293,7 +293,7 @@ class Exporter: fmt += "_VERTEX3" out_file.begin("vertices", fmt) normal = None - uvs = [None]*len(mesh.uv_textures) + uvs = [None]*len(mesh.uv_layers) tan = None bino = None for v in mesh.vertices: diff --git a/blender/io_mesh_mspgl/mesh.py b/blender/io_mesh_mspgl/mesh.py index f8a55353..ce4a7fd9 100644 --- a/blender/io_mesh_mspgl/mesh.py +++ b/blender/io_mesh_mspgl/mesh.py @@ -99,7 +99,15 @@ class Line: self.flag = False -class FakeUvTex: +class UvLayer: + def __init__(self, l): + self._layer = l + self.name = None + + def __getattr__(self, attr): + return getattr(self._layer, attr) + +class FakeUvLayer: def __init__(self, n): self.name = n @@ -115,20 +123,22 @@ class Mesh: self._mesh = m self.vertices = [Vertex(v) for v in self.vertices] - self.faces = [Face(f) for f in self.faces] + self.faces = [Face(f) for f in self.polygons] self.materials = self.materials[:] - self.uv_textures = [u for u in self.uv_textures if not u.name.endswith(".hidden")] - self.uv_textures.sort(key=uvtex_unit_number) + self.uv_layers = [UvLayer(u) for u in self.uv_layers] + for i in range(len(self.uv_layers)): + self.uv_layers[i].name = self.uv_textures[i].name + self.uv_layers = [u for u in self.uv_layers if not u.name.endswith(".hidden")] + self.uv_layers.sort(key=uvtex_unit_number) for f in self.faces: f.vertices = [self.vertices[i] for i in f.vertices] for v in f.vertices: v.faces.append(f) - for u in self.uv_textures: - r = u.data[f.index].uv_raw; - f.uvs.append([(r[i], r[i+1]) for i in range(0, 8, 2)]) + for u in self.uv_layers: + f.uvs.append([u.data[f.loop_indices[i]].uv for i in range(len(f.vertices))]) self.edges = dict([(e.key, Edge(e)) for e in self.edges]) for f in self.faces: @@ -185,7 +195,7 @@ class Mesh: e.check_smooth(1) def generate_material_uv(self): - self.uv_textures.append(FakeUvTex("material_tex")) + self.uv_layers.append(FakeUvLayer("material_tex")) for f in self.faces: f.uvs.append([((f.material_index+0.5)/len(self.materials), 0.5)]*len(f.vertices)) @@ -302,7 +312,7 @@ class Mesh: v.uvs = [u[i] for u in f.uvs] def compute_tbn(self, index): - if not self.uv_textures: + if not self.uv_layers: return for v in self.vertices: -- 2.45.2