Remove degenerate triangles when generating triangle mesh.

This commit is contained in:
EvilSpirit 2017-02-04 17:47:39 +07:00 committed by whitequark
parent 4465bc0270
commit baf9dc0aae
3 changed files with 16 additions and 0 deletions

View File

@ -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);

View File

@ -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();
}

View File

@ -278,6 +278,7 @@ public:
void MakeOutlinesInto(SOutlineList *sol, EdgeKind type);
void PrecomputeTransparency();
void RemoveDegenerateTriangles();
bool IsEmpty() const;
void RemapFaces(Group *g, int remap);