From 0d0a9b2f56bedc0b9394b2ad9a1199ef2907f8f2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 26 Apr 2024 16:34:19 +0100 Subject: Set the face surface type when setting height --- game/geoData.cpp | 12 +++++++++++- game/geoData.h | 2 +- test/test-geoData.cpp | 4 +++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/game/geoData.cpp b/game/geoData.cpp index 68a1298..59feac1 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -464,7 +464,7 @@ GeoData::split(FaceHandle _fh) } void -GeoData::setHeights(const std::span triangleStrip) +GeoData::setHeights(const std::span triangleStrip, const Surface & newFaceSurface) { static const RelativeDistance MAX_SLOPE = 1.5F; static const RelativeDistance MIN_ARC = 0.01F; @@ -482,6 +482,7 @@ GeoData::setHeights(const std::span triangleStrip) return add_vertex(tsVert); }); // Create new faces + const auto initialFaceCount = static_cast(n_faces()); std::for_each(strip_begin(newVerts), strip_end(newVerts), [this](const auto & newVert) { const auto [a, b, c] = newVert; add_face(a, b, c); @@ -497,6 +498,11 @@ GeoData::setHeights(const std::span triangleStrip) });) { ; } + std::vector newFaces; + std::copy_if(FaceIter {*this, FaceHandle {initialFaceCount}, true}, faces_end(), std::back_inserter(newFaces), + [this](FaceHandle fh) { + return !this->status(fh).deleted(); + }); // Extrude corners struct Extrusion { @@ -667,4 +673,8 @@ GeoData::setHeights(const std::span triangleStrip) // Tidy up update_vertex_normals_only(VertexIter {*this, vertex_handle(initialVertexCount), true}); + + std::for_each(newFaces.begin(), newFaces.end(), [&newFaceSurface, this](const auto fh) { + property(surface, fh) = &newFaceSurface; + }); } diff --git a/game/geoData.h b/game/geoData.h index 0c5cc6c..ed1734c 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -142,7 +142,7 @@ public: [[nodiscard]] HalfedgeHandle findEntry(const GlobalPosition2D from, const GlobalPosition2D to) const; - void setHeights(const std::span triangleStrip); + void setHeights(const std::span triangleStrip, const Surface &); [[nodiscard]] auto getExtents() const diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index fb9aba0..11d634d 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -229,8 +229,10 @@ BOOST_TEST_DECORATOR(*boost::unit_test::timeout(2)); BOOST_DATA_TEST_CASE(deform, loadFixtureJson("geoData/deform/1.json"), points, cams) { + Surface surface; + surface.colorBias = RGB {0, 0, 1}; auto gd = std::make_shared(GeoData::createFlat({0, 0}, {1000000, 1000000}, 100)); - BOOST_CHECK_NO_THROW(gd->setHeights(points)); + BOOST_CHECK_NO_THROW(gd->setHeights(points, surface)); ApplicationBase ab; TestMainWindow tmw; -- cgit v1.2.3