]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/mesh.py
Add properties to export materials as texture array layers
[libs/gl.git] / blender / io_mspgl / mesh.py
index 88758730881d0c734373ae081b50ea48b60cf760..d05b9de844d91eeccf113fe9e961386041fb3baf 100644 (file)
@@ -45,6 +45,7 @@ class Vertex:
        def __init__(self, mv):
                if mv.__class__==Vertex:
                        self._mvert = mv._mvert
+                       self.co = mv.co
                        self.normal = mv.normal
                        self.uvs = mv.uvs[:]
                        self.tan = mv.tan
@@ -52,6 +53,8 @@ class Vertex:
                        self.group_weight_scale = mv.group_weight_scale
                else:
                        self._mvert = mv
+                       self.co = mv.co
+                       self.normal = mv.normal
                        self.uvs = []
                        self.tan = None
                        self.bino = None
@@ -148,11 +151,20 @@ class Mesh:
                self.assign_texture_units()
 
                for f in self.faces:
+                       if len(f.vertices)>4:
+                               raise ValueError("Ngons are not supported")
                        f.vertices = [self.vertices[i] for i in f.vertices]
                        for v in f.vertices:
                                v.faces.append(f)
                        for u in self.uv_layers:
                                f.uvs.append([u.data[f.loop_indices[i]].uv for i in range(len(f.vertices))])
+                       if f.material_index<len(self.materials):
+                               mat = self.materials[f.material_index]
+                               if mat and mat.array_atlas:
+                                       layer = (mat.array_layer,)
+                                       print(f.uvs, layer)
+                                       for i in range(len(f.uvs)):
+                                               f.uvs[i] = [mathutils.Vector(tuple(u)+layer) for u in f.uvs[i]]
 
                self.edges = dict([(e.key, Edge(e)) for e in self.edges])
                for f in self.faces:
@@ -162,6 +174,8 @@ class Mesh:
                                f.edges.append(e)
 
                self.lines = [Line(e) for e in self.edges.values() if not e.faces]
+               for l in self.lines:
+                       l.vertices = [self.vertices[i] for i in l.vertices]
 
                if self.use_auto_smooth:
                        smooth_limit = math.cos(self.auto_smooth_angle)
@@ -175,6 +189,10 @@ class Mesh:
        def __getattr__(self, attr):
                return getattr(self._mesh, attr)
 
+       def transform(self, matrix):
+               for v in self.vertices:
+                       v.co = matrix*v.co
+
        def splice(self, other):
                material_map = []
                for m in other.materials:
@@ -290,10 +308,10 @@ class Mesh:
                        if progress:
                                progress.set_progress(0.5+i*0.5/len(self.vertices))
 
-       def split_smooth(self, progress = None):
+       def split_smooth(self, progress=None):
                self.split_vertices(self.find_smooth_group, progress)
 
-       def split_uv(self, index, progress = None):
+       def split_uv(self, index, progress=None):
                self.split_vertices(self.find_uv_group, progress, index)
 
        def find_smooth_group(self, vertex, face):