]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix some errors introduced in the refactoring
authorMikko Rasa <tdb@tdb.fi>
Sat, 4 May 2019 13:39:26 +0000 (16:39 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 4 May 2019 13:39:26 +0000 (16:39 +0300)
blender/io_mspgl/mesh.py

index 62d7506303b349d9e3af9f914f5b4e39d0e6319f..a303db9983811b398bf21e2c6255bd2d9487d283 100644 (file)
@@ -99,6 +99,10 @@ class Face:
                        return 1
                return cmp(self.index, other.index)
 
+       def pivot_vertex(self, v):
+               n = self.vertices.index(v)
+               return [(n+i)%len(self.vertices) for i in range(len(self.vertices))]
+
        def pivot_vertices(self, *vt):
                flags = [(v in vt) for v in self.vertices]
                l = len(self.vertices)
@@ -170,9 +174,9 @@ class Mesh:
                self.loops = self.loops[:]
 
                self.materials = self.materials[:]
-               if self.use_uv=='NONE':
+               if self.use_uv=='NONE' or not self.uv_layers:
                        self.uv_layers = []
-               elif self.uv_layers:
+               else:
                        self.uv_layers = [UvLayer(u) for u in self.uv_layers]
                        self.uv_layers = sorted([u for u in self.uv_layers if not u.hidden], key=(lambda u: (u.unit or 1000, u.name)))
 
@@ -468,16 +472,16 @@ class Mesh:
                        v.tan = mathutils.Vector()
                        v.bino = mathutils.Vector()
                        for f in v.faces:
-                               vi = f.vertices.index(v)
-                               uv0 = layer_uvs[f.loop_indices[vi]]
-                               uv1 = layer_uvs[f.loop_indices[vi+1]]
-                               uv2 = layer_uvs[f.loop_indices[vi-1]]
+                               vi = f.pivot_vertex(v)
+                               uv0 = layer_uvs[f.loop_indices[vi[0]]]
+                               uv1 = layer_uvs[f.loop_indices[vi[1]]]
+                               uv2 = layer_uvs[f.loop_indices[vi[-1]]]
                                du1 = uv1[0]-uv0[0]
                                du2 = uv2[0]-uv0[0]
                                dv1 = uv1[1]-uv0[1]
                                dv2 = uv2[1]-uv0[1]
-                               edge1 = f.vertices[vi+1].co-f.vertices[vi].co
-                               edge2 = f.vertices[vi-1].co-f.vertices[vi].co
+                               edge1 = f.vertices[vi[1]].co-f.vertices[vi[0]].co
+                               edge2 = f.vertices[vi[-1]].co-f.vertices[vi[0]].co
                                div = (du1*dv2-du2*dv1)
                                if div:
                                        mul = edge1.angle(edge2)/div
@@ -565,6 +569,17 @@ def create_mesh_from_object(context, obj, progress=None):
        for o, m in objs:
                bmesh = o.to_mesh(context.scene, True, "PREVIEW")
                bmeshes.append(bmesh)
+
+               # Object.to_mesh does not copy custom properties
+               bmesh.winding_test = o.data.winding_test
+               bmesh.smoothing = o.data.smoothing
+               bmesh.use_lines = o.data.use_lines
+               bmesh.vertex_groups = o.data.vertex_groups
+               bmesh.max_groups_per_vertex = o.data.max_groups_per_vertex
+               bmesh.use_uv = o.data.use_uv
+               bmesh.tbn_vecs = o.data.tbn_vecs
+               bmesh.tbn_uvtex = o.data.tbn_uvtex
+
                me = Mesh(bmesh)
                me.transform(m)