From 70ec7cc257acaaa0580b9c948343e42cebedb36f Mon Sep 17 00:00:00 2001 From: ruevs Date: Wed, 13 May 2020 00:36:26 +0300 Subject: [PATCH] Improve triangle mesh (splitting of quads based on angle). When checking the dot product of the tangents `tu` and `tv` to decide in which direction to split a quad compare it to to LENGTH_EPS instead of zero to avoid alternating triangle "orientations" when the tangents are orthogonal (revolve, lathe etc.). This improves the quality of the resulting triangle mesh. --- src/srf/triangulate.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/srf/triangulate.cpp b/src/srf/triangulate.cpp index 3ebb2bc..51a31dd 100644 --- a/src/srf/triangulate.cpp +++ b/src/srf/triangulate.cpp @@ -482,7 +482,11 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) { if (this_flag) { // Add the quad to our mesh srf->TangentsAt(us,vs, &tu,&tv); - if (tu.Dot(tv) < 0.0) { //split the other way if angle>90 + if(tu.Dot(tv) < LENGTH_EPS) { + /* Split "the other way" if angle>90 + compare to LENGTH_EPS instead of zero to avoid alternating triangle + "orientations" when the tangents are orthogonal (revolve, lathe etc.) + this results in a higher quality mesh. */ STriangle tr = {}; tr.a = a; tr.b = b;