Skip to content

Commit

Permalink
Remove degenerate triangles when generating triangle mesh.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evil-Spirit authored and whitequark committed Feb 5, 2017
1 parent 4465bc0 commit baf9dc0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/groupmesh.cpp
Expand Up @@ -346,6 +346,11 @@ void Group::GenerateShellAndMesh() {
SMesh outm = {};
GenerateForBoolean<SMesh>(&prevm, &thism, &outm, srcg->meshCombine);

// Remove degenerate triangles; if we don't, they'll get split in SnapToMesh
// in every generated group, resulting in polynomial increase in triangle count,
// and corresponding slowdown.
outm.RemoveDegenerateTriangles();

// And make sure that the output mesh is vertex-to-vertex.
SKdNode *root = SKdNode::From(&outm);
root->SnapToMesh(&outm);
Expand Down
10 changes: 10 additions & 0 deletions src/mesh.cpp
Expand Up @@ -1114,3 +1114,13 @@ void SMesh::PrecomputeTransparency() {
return (opaquea != opaqueb && opaquea == true);
});
}

void SMesh::RemoveDegenerateTriangles() {
for(auto &tr : l) {
bool isDegenerate = tr.a.OnLineSegment(tr.b, tr.c) ||
tr.b.OnLineSegment(tr.a, tr.c) ||
tr.c.OnLineSegment(tr.a, tr.b);
tr.tag = (int)isDegenerate;
}
l.RemoveTagged();
}
1 change: 1 addition & 0 deletions src/polygon.h
Expand Up @@ -278,6 +278,7 @@ class SMesh {
void MakeOutlinesInto(SOutlineList *sol, EdgeKind type);

void PrecomputeTransparency();
void RemoveDegenerateTriangles();

bool IsEmpty() const;
void RemapFaces(Group *g, int remap);
Expand Down

0 comments on commit baf9dc0

Please sign in to comment.