]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix some errors in the triangulation algorithm
authorMikko Rasa <tdb@tdb.fi>
Mon, 6 May 2019 06:08:19 +0000 (09:08 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 6 May 2019 06:08:19 +0000 (09:08 +0300)
Normals were reversed and edge links were not being updated properly.

blender/io_mspgl/mesh.py

index 08f0bb4ac814ea196d1411de15720c0ff17eb993..c3767bd9f18884718941977115da2d66f3a1a756 100644 (file)
@@ -296,7 +296,7 @@ class Mesh:
 
                        normals = []
                        for j in range(nverts):
-                               normals.append(edge_vecs[j].cross(edge_vecs[j-1]).normalized())
+                               normals.append(edge_vecs[j-1].cross(edge_vecs[j]).normalized())
 
                        # Check which diagonal results in a flatter triangulation
                        flatness1 = normals[0].dot(normals[2])
@@ -333,6 +333,10 @@ class Mesh:
                        else:
                                nf.edges = [f.edges[1], f.edges[2], ne]
                                f.edges = [f.edges[0], ne, f.edges[3]]
+                       for e in nf.edges:
+                               if e!=ne:
+                                       e.faces.remove(f)
+                                       e.faces.append(nf)
 
                        f.normal = normals[1-cut_index]
                        nf.normal = normals[3-cut_index]