From c355a4730adf40aae3552bc5ec57f7615bb6d5bb Mon Sep 17 00:00:00 2001 From: phkahler <14852918+phkahler@users.noreply.github.com> Date: Mon, 11 May 2020 10:19:38 -0400 Subject: [PATCH] Split quads based on angle. --- src/srf/triangulate.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/srf/triangulate.cpp b/src/srf/triangulate.cpp index b4ea2411..3ebb2bc8 100644 --- a/src/srf/triangulate.cpp +++ b/src/srf/triangulate.cpp @@ -443,6 +443,7 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) { // generate two triangles in the mesh, and cut it out of our polygon. // Quads around the perimeter would be rejected by AnyEdgeCrossings. std::vector bottom(lj.n, false); // did we use this quad? + Vector tu = {0,0,0}, tv = {0,0,0}; int i, j; for(i = 1; i < (li.n-1); i++) { bool prev_flag = false; @@ -480,16 +481,28 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) { if (this_flag) { // Add the quad to our mesh - STriangle tr = {}; - tr.a = a; - tr.b = b; - tr.c = c; - mesh->AddTriangle(&tr); - tr.a = a; - tr.b = c; - tr.c = d; - mesh->AddTriangle(&tr); - + srf->TangentsAt(us,vs, &tu,&tv); + if (tu.Dot(tv) < 0.0) { //split the other way if angle>90 + STriangle tr = {}; + tr.a = a; + tr.b = b; + tr.c = c; + mesh->AddTriangle(&tr); + tr.a = a; + tr.b = c; + tr.c = d; + mesh->AddTriangle(&tr); + } else{ + STriangle tr = {}; + tr.a = a; + tr.b = b; + tr.c = d; + mesh->AddTriangle(&tr); + tr.a = b; + tr.b = c; + tr.c = d; + mesh->AddTriangle(&tr); + } if (!prev_flag) // add our own left edge holes.AddEdge(d, a); if (!bottom[j]) // add our own bottom edge