diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-11-14 02:53:00 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-11-14 02:53:00 +0000 |
commit | 692d569eae8f199cad609dbde8161998e8586ede (patch) | |
tree | 54d2157752541dfe33b04d0416c18eb24b0ecf3f | |
parent | Fix do bounary part iteration (diff) | |
download | ilt-692d569eae8f199cad609dbde8161998e8586ede.tar.bz2 ilt-692d569eae8f199cad609dbde8161998e8586ede.tar.xz ilt-692d569eae8f199cad609dbde8161998e8586ede.zip |
Reuse existing vertices when processing boundary parts
-rw-r--r-- | game/geoData.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp index f84f4e2..fcaea64 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -506,27 +506,35 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const // Cut along each edge of triangleStrip AB, AC, BC, BD, CD, CE etc std::map<VertexHandle, const Triangle<3> *> boundaryTriangles; - auto doBoundaryPart - = [this, &boundaryTriangles](VertexHandle start, VertexHandle end, const Triangle<3> & triangle) { - boundaryTriangles.emplace(start, &triangle); - const auto endPoint = point(end); - while (!std::ranges::contains(vv_range(start), end) - && std::ranges::any_of(voh_range(start), [&](const auto & outHalf) { - const auto next = next_halfedge_handle(outHalf); - const auto startPoint = point(start); - const auto nextStartPoint = point(from_vertex_handle(next)); - const auto nextEndPoint = point(to_vertex_handle(next)); - if (linesCross(startPoint, endPoint, nextStartPoint, nextEndPoint)) { - if (const auto intersection = linesIntersectAt(startPoint.xy(), endPoint.xy(), - nextStartPoint.xy(), nextEndPoint.xy())) { - start = split(edge_handle(next), positionOnTriangle(*intersection, triangle)); - boundaryTriangles.emplace(start, &triangle); - return true; - } - } - return false; - })) { } - }; + auto doBoundaryPart = [this, &boundaryTriangles]( + VertexHandle start, VertexHandle end, const Triangle<3> & triangle) { + boundaryTriangles.emplace(start, &triangle); + const auto endPoint = point(end); + while (!std::ranges::contains(vv_range(start), end) + && std::ranges::any_of(voh_range(start), [&](const auto & outHalf) { + const auto next = next_halfedge_handle(outHalf); + const auto startPoint = point(start); + const auto nextStartPoint = point(from_vertex_handle(next)); + const auto nextEndPoint = point(to_vertex_handle(next)); + if (linesCross(startPoint, endPoint, nextStartPoint, nextEndPoint)) { + if (const auto intersection = linesIntersectAt( + startPoint.xy(), endPoint.xy(), nextStartPoint.xy(), nextEndPoint.xy())) { + const auto distS = glm::length(difference(*intersection, nextStartPoint.xy())); + const auto distE = glm::length(difference(*intersection, nextEndPoint.xy())); + if (const auto mdist = std::min({distS, distE}); mdist < 500.F) { + start = (mdist == distS) ? from_vertex_handle(next) : to_vertex_handle(next); + point(start) = positionOnTriangle(*intersection, triangle); + } + else { + start = split(edge_handle(next), positionOnTriangle(*intersection, triangle)); + } + boundaryTriangles.emplace(start, &triangle); + return true; + } + } + return false; + })) { } + }; auto doBoundary = [&doBoundaryPart, triangle = strip.begin()](const auto & verts) mutable { const auto & [a, b, c] = verts; doBoundaryPart(a, b, *triangle); |