Don't create redundant edges in UvGridTriangulate into.
This commit is contained in:
parent
05aa649508
commit
a7e0a174e3
@ -437,13 +437,17 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) {
|
|||||||
srf->MakeTriangulationGridInto(&li, 0, 1, /*swapped=*/true);
|
srf->MakeTriangulationGridInto(&li, 0, 1, /*swapped=*/true);
|
||||||
lj.Add(&v);
|
lj.Add(&v);
|
||||||
srf->MakeTriangulationGridInto(&lj, 0, 1, /*swapped=*/false);
|
srf->MakeTriangulationGridInto(&lj, 0, 1, /*swapped=*/false);
|
||||||
|
if ((li.n > 3) && (lj.n > 3)) {
|
||||||
// Now iterate over each quad in the grid. If it's outside the polygon,
|
// Now iterate over each quad in the grid. If it's outside the polygon,
|
||||||
// or if it intersects the polygon, then we discard it. Otherwise we
|
// or if it intersects the polygon, then we discard it. Otherwise we
|
||||||
// generate two triangles in the mesh, and cut it out of our polygon.
|
// generate two triangles in the mesh, and cut it out of our polygon.
|
||||||
|
// Quads around the perimeter would be rejected by AnyEdgeCrossings.
|
||||||
|
std::vector<bool> bottom(lj.n, false); // did we use this quad?
|
||||||
int i, j;
|
int i, j;
|
||||||
for(i = 0; i < (li.n - 1); i++) {
|
for(i = 1; i < (li.n-1); i++) {
|
||||||
for(j = 0; j < (lj.n - 1); j++) {
|
bool prev_flag = false;
|
||||||
|
for(j = 1; j < (lj.n-1); j++) {
|
||||||
|
bool this_flag = true;
|
||||||
double us = li[i], uf = li[i+1],
|
double us = li[i], uf = li[i+1],
|
||||||
vs = lj[j], vf = lj[j+1];
|
vs = lj[j], vf = lj[j+1];
|
||||||
|
|
||||||
@ -452,20 +456,29 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) {
|
|||||||
c = Vector::From(uf, vf, 0),
|
c = Vector::From(uf, vf, 0),
|
||||||
d = Vector::From(uf, vs, 0);
|
d = Vector::From(uf, vs, 0);
|
||||||
|
|
||||||
if(orig.AnyEdgeCrossings(a, b, NULL) ||
|
// | d-----c
|
||||||
|
// | | |
|
||||||
|
// | | |
|
||||||
|
// | a-----b
|
||||||
|
// |
|
||||||
|
// +-------------> j/v axis
|
||||||
|
|
||||||
|
if( (i==(li.n-2)) || (j==(lj.n-2)) ||
|
||||||
|
orig.AnyEdgeCrossings(a, b, NULL) ||
|
||||||
orig.AnyEdgeCrossings(b, c, NULL) ||
|
orig.AnyEdgeCrossings(b, c, NULL) ||
|
||||||
orig.AnyEdgeCrossings(c, d, NULL) ||
|
orig.AnyEdgeCrossings(c, d, NULL) ||
|
||||||
orig.AnyEdgeCrossings(d, a, NULL))
|
orig.AnyEdgeCrossings(d, a, NULL))
|
||||||
{
|
{
|
||||||
continue;
|
this_flag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// There's no intersections, so it doesn't matter which point
|
// There's no intersections, so it doesn't matter which point
|
||||||
// we decide to test.
|
// we decide to test.
|
||||||
if(!this->ContainsPoint(a)) {
|
if(!this->ContainsPoint(a)) {
|
||||||
continue;
|
this_flag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this_flag) {
|
||||||
// Add the quad to our mesh
|
// Add the quad to our mesh
|
||||||
STriangle tr = {};
|
STriangle tr = {};
|
||||||
tr.a = a;
|
tr.a = a;
|
||||||
@ -477,14 +490,22 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) {
|
|||||||
tr.c = d;
|
tr.c = d;
|
||||||
mesh->AddTriangle(&tr);
|
mesh->AddTriangle(&tr);
|
||||||
|
|
||||||
holes.AddEdge(a, b);
|
if (!prev_flag) // add our own left edge
|
||||||
holes.AddEdge(b, c);
|
|
||||||
holes.AddEdge(c, d);
|
|
||||||
holes.AddEdge(d, a);
|
holes.AddEdge(d, a);
|
||||||
|
if (!bottom[j]) // add our own bottom edge
|
||||||
|
holes.AddEdge(a, b);
|
||||||
|
} else {
|
||||||
|
if (prev_flag) // add our left neighbots right edge
|
||||||
|
holes.AddEdge(a, d);
|
||||||
|
if (bottom[j]) // add our bottom neighbors top edge
|
||||||
|
holes.AddEdge(b, a);
|
||||||
|
}
|
||||||
|
prev_flag = this_flag;
|
||||||
|
bottom[j] = this_flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
holes.CullExtraneousEdges();
|
// Because no duplicate edges were created we do not need to cull them.
|
||||||
SPolygon hp = {};
|
SPolygon hp = {};
|
||||||
holes.AssemblePolygon(&hp, NULL, /*keepDir=*/true);
|
holes.AssemblePolygon(&hp, NULL, /*keepDir=*/true);
|
||||||
|
|
||||||
@ -492,13 +513,12 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) {
|
|||||||
for(sc = hp.l.First(); sc; sc = hp.l.NextAfter(sc)) {
|
for(sc = hp.l.First(); sc; sc = hp.l.NextAfter(sc)) {
|
||||||
l.Add(sc);
|
l.Add(sc);
|
||||||
}
|
}
|
||||||
|
hp.l.Clear();
|
||||||
|
}
|
||||||
orig.Clear();
|
orig.Clear();
|
||||||
holes.Clear();
|
holes.Clear();
|
||||||
li.Clear();
|
li.Clear();
|
||||||
lj.Clear();
|
lj.Clear();
|
||||||
hp.l.Clear();
|
|
||||||
|
|
||||||
UvTriangulateInto(mesh, srf);
|
UvTriangulateInto(mesh, srf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user