From c2b5834e233a505910047e9c80070853b40091d3 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 4 May 2019 16:39:26 +0300 Subject: [PATCH] Fix some errors introduced in the refactoring --- blender/io_mspgl/mesh.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/blender/io_mspgl/mesh.py b/blender/io_mspgl/mesh.py index 62d75063..a303db99 100644 --- a/blender/io_mspgl/mesh.py +++ b/blender/io_mspgl/mesh.py @@ -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) -- 2.45.2