]> git.tdb.fi Git - libs/gl.git/commitdiff
Adapt exporter to Blender 2.63
authorMikko Rasa <tdb@tdb.fi>
Thu, 26 Jul 2012 20:46:11 +0000 (23:46 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 26 Jul 2012 20:46:11 +0000 (23:46 +0300)
blender/io_mesh_mspgl/export_mspgl.py
blender/io_mesh_mspgl/mesh.py

index 1d7062e68eaa2d5bdca07d500a87549965b953e6..5a1bbe1130be97b39acaf49c067679da4798f070 100644 (file)
@@ -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:
index f8a553530f379841a2bf49884bf71c28597d2fc2..ce4a7fd984f8fdffbcf7617c8c17830447ad6779 100644 (file)
@@ -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: