From e75b8bc4b8494c1295a29dbafa6c7876a2bec0ce Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 16 Nov 2024 00:32:18 +0000 Subject: Reuse existing vertices when processing strip vertices --- game/geoData.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/game/geoData.cpp b/game/geoData.cpp index fcaea64..f070391 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -481,9 +481,23 @@ GeoData::setHeights(const std::span triangleStrip, const // New vertices for each vertex in triangleStrip std::vector newVerts; newVerts.reserve(newVerts.size()); - std::transform( - triangleStrip.begin(), triangleStrip.end(), std::back_inserter(newVerts), [this](const auto tsPoint) { - return split(findPoint(tsPoint), tsPoint); + std::transform(triangleStrip.begin(), triangleStrip.end(), std::back_inserter(newVerts), + [this, &newVerts](const auto tsPoint) { + const auto face = findPoint(tsPoint); + if (const auto nearest = std::ranges::min(std::views::iota(fv_begin(face), fv_end(face)) + | std::views::filter([&newVerts](const auto v) { + return !std::ranges::contains(newVerts, *v); + }) + | std::views::transform([this, &tsPoint](const auto v) { + return std::make_pair( + *v, glm::length(difference(this->point(*v).xy(), tsPoint.xy()))); + }), + {}, &std::pair::second); + nearest.second < 500.F) { + point(nearest.first) = tsPoint; + return nearest.first; + } + return split(face, tsPoint); }); // Create temporary triangles from triangleStrip -- cgit v1.2.3