From 1572e1ed7173d139df03df93bd6423ffdcc9e757 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 3 Nov 2024 14:13:00 +0000 Subject: Reuse close vertices when deforming terrain --- game/geoData.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'game') diff --git a/game/geoData.cpp b/game/geoData.cpp index d212651..8975d46 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -524,21 +524,29 @@ GeoData::setHeights(const std::span triangleStrip, const const auto doExtrusion = [this](VertexHandle & extrusionVertex, Direction2D direction, GlobalPosition3D boundaryVertex, RelativeDistance vert) { const auto extrusionDir = glm::normalize(direction || vert); + const auto intersectAsNeeded = [this, &extrusionVertex](FaceHandle face, GlobalPosition3D pos) { + if (const auto closeVertex = std::find_if(fv_begin(face), fv_end(face), + [this, pos](const auto & vertex) { + return glm::length(::difference(pos, this->point(vertex))) < 10.F; + }); + closeVertex != fv_end(face)) { + extrusionVertex = *closeVertex; + return; + } + extrusionVertex = split(face, pos); + }; if (!extrusionVertex.is_valid()) { if (const auto intersect = intersectRay({boundaryVertex, extrusionDir})) { - auto splitVertex = split(intersect->second, intersect->first); - extrusionVertex = splitVertex; + intersectAsNeeded(intersect->second, intersect->first); } else if (const auto intersect = intersectRay({boundaryVertex + GlobalPosition3D {1, 1, 0}, extrusionDir})) { - auto splitVertex = split(intersect->second, intersect->first); - extrusionVertex = splitVertex; + intersectAsNeeded(intersect->second, intersect->first); } else if (const auto intersect = intersectRay({boundaryVertex + GlobalPosition3D {1, 0, 0}, extrusionDir})) { - auto splitVertex = split(intersect->second, intersect->first); - extrusionVertex = splitVertex; + intersectAsNeeded(intersect->second, intersect->first); } } -- cgit v1.2.3