From f47aff9a43e5267e5ab42a0111df483129aed6ba Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 8 Apr 2024 23:37:17 +0100 Subject: Add GeoData face property for surface type Arbitrary int type for now. --- game/geoData.h | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 021b4c7..e3e9bcb 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -20,7 +20,9 @@ struct GeoDataTraits : public OpenMesh::DefaultTraits { class GeoData : public OpenMesh::TriMesh_ArrayKernelT { private: - GeoData() = default; + GeoData(); + + OpenMesh::FPropHandleT surface; public: static GeoData loadFromAsciiGrid(const std::filesystem::path &); @@ -61,47 +63,41 @@ public: }); } - [[nodiscard]] - glm::vec + [[nodiscard]] glm::vec operator*(BaryPosition bari) const { return p(0) + (difference(p(0), p(1)) * bari.x) + (difference(p(0), p(2)) * bari.y); } - [[nodiscard]] - auto + [[nodiscard]] auto area() const requires(Dim == 3) { return glm::length(crossProduct(difference(p(0), p(1)), difference(p(0), p(2)))) / 2.F; } - [[nodiscard]] - Normal3D + [[nodiscard]] Normal3D normal() const requires(Dim == 3) { return crossProduct(difference(p(0), p(1)), difference(p(0), p(2))); } - [[nodiscard]] - Normal3D + [[nodiscard]] Normal3D nnormal() const requires(Dim == 3) { return glm::normalize(normal()); } - [[nodiscard]] - auto + [[nodiscard]] auto angle(glm::length_t c) const { return Arc {P(c), P(c + 2), P(c + 1)}.length(); } template - [[nodiscard]] - auto + [[nodiscard]] auto angleAt(const GlobalPosition pos) const requires(D <= Dim) { @@ -113,8 +109,7 @@ public: return 0.F; } - [[nodiscard]] - inline auto + [[nodiscard]] inline auto p(const glm::length_t i) const { return base::operator[](i); -- cgit v1.2.3 From 90b3b10170d7a7f278338b74d84ae6efceaacf77 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 10 Apr 2024 08:49:35 +0100 Subject: Introduce a basic terrain surface type asset --- game/geoData.h | 3 ++- game/surface.cpp | 7 +++++++ game/surface.h | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 game/surface.cpp create mode 100644 game/surface.h (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index e3e9bcb..7a2344d 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -3,6 +3,7 @@ #include "collections.h" // IWYU pragma: keep IterableCollection #include "config/types.h" #include "ray.h" +#include "surface.h" #include #include #include @@ -22,7 +23,7 @@ class GeoData : public OpenMesh::TriMesh_ArrayKernelT { private: GeoData(); - OpenMesh::FPropHandleT surface; + OpenMesh::FPropHandleT surface; public: static GeoData loadFromAsciiGrid(const std::filesystem::path &); diff --git a/game/surface.cpp b/game/surface.cpp new file mode 100644 index 0000000..007a9a4 --- /dev/null +++ b/game/surface.cpp @@ -0,0 +1,7 @@ +#include "surface.h" + +bool +Surface::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(colorBias) && STORE_MEMBER(quality) && Asset::persist(store); +} diff --git a/game/surface.h b/game/surface.h new file mode 100644 index 0000000..ccc5c6c --- /dev/null +++ b/game/surface.h @@ -0,0 +1,11 @@ +#pragma once + +#include "assetFactory/asset.h" + +struct Surface : public Asset { + friend Persistence::SelectionPtrBase>; + bool persist(Persistence::PersistenceStore & store) override; + + glm::vec3 colorBias; + float quality; +}; -- cgit v1.2.3 From b44c2d85bb8e46c4a6c65aacd23157c07cb80eca Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 12 Apr 2024 00:03:15 +0100 Subject: Create terrain vertices per surface type --- game/geoData.h | 7 +++++++ game/terrain.cpp | 24 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 7a2344d..5586023 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -150,6 +150,13 @@ public: return std::tie(lowerExtent, upperExtent); } + template + [[nodiscard]] auto + get_surface(const HandleT h) + { + return property(surface, h); + } + protected: template [[nodiscard]] Triangle diff --git a/game/terrain.cpp b/game/terrain.cpp index 201c732..c19bd0a 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -27,18 +27,26 @@ Terrain::generateMeshes() indices.reserve(geoData->n_faces() * 3); std::vector vertices; vertices.reserve(geoData->n_vertices()); - std::map vertexIndex; - std::transform(geoData->vertices_sbegin(), geoData->vertices_end(), std::back_inserter(vertices), - [this, &vertexIndex](const GeoData::VertexHandle v) { - vertexIndex.emplace(v, vertexIndex.size()); - const auto p = geoData->point(v); - return Vertex {p, RelativePosition2D(p) / 10000.F, geoData->normal(v)}; + std::map, size_t> vertexIndex; + std::for_each(geoData->vertices_sbegin(), geoData->vertices_end(), + [this, &vertexIndex, &vertices](const GeoData::VertexHandle v) { + std::for_each(geoData->vf_begin(v), geoData->vf_end(v), + [&vertexIndex, v, this, &vertices](const GeoData::FaceHandle f) { + if (const auto vertexIndexRef + = vertexIndex.emplace(std::make_pair(v, geoData->get_surface(f)), 0); + vertexIndexRef.second) { + vertexIndexRef.first->second = vertices.size(); + + const auto p = geoData->point(v); + vertices.emplace_back(p, RelativePosition2D(p) / 10000.F, geoData->normal(v)); + } + }); }); std::for_each( geoData->faces_sbegin(), geoData->faces_end(), [this, &vertexIndex, &indices](const GeoData::FaceHandle f) { std::transform(geoData->fv_begin(f), geoData->fv_end(f), std::back_inserter(indices), - [&vertexIndex](const GeoData::VertexHandle v) { - return vertexIndex[v]; + [&vertexIndex, f, this](const GeoData::VertexHandle v) { + return vertexIndex[std::make_pair(v, geoData->get_surface(f))]; }); }); meshes.create(vertices, indices); -- cgit v1.2.3 From 7dc3fa64ffe64d5fa01c59f7deed87dbc3b48c45 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 26 Apr 2024 14:50:42 +0100 Subject: Don't return newly created faces from split It's not as simple as it looks as adjacent faces may also be split, making this a bit misleading. --- game/geoData.cpp | 12 +++++------- game/geoData.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.cpp b/game/geoData.cpp index e465ba0..68a1298 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -409,7 +409,7 @@ GeoData::triangleContainsTriangle(const Triangle<2> & a, const Triangle<2> & b) return triangleContainsPoint(a.x, b) && triangleContainsPoint(a.y, b) && triangleContainsPoint(a.z, b); } -std::array +void GeoData::split(FaceHandle _fh) { // Collect halfedges of face @@ -457,12 +457,10 @@ GeoData::split(FaceHandle _fh) } // Retriangulate - return { - add_face(v0, p0, v1), - add_face(p2, v0, v2), - add_face(v2, v1, p1), - add_face(v2, v0, v1), - }; + add_face(v0, p0, v1); + add_face(p2, v0, v2); + add_face(v2, v1, p1); + add_face(v2, v0, v1); } void diff --git a/game/geoData.h b/game/geoData.h index 5586023..0c5cc6c 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -186,7 +186,7 @@ protected: void update_vertex_normals_only(VertexIter start); using OpenMesh::TriMesh_ArrayKernelT::split; - std::array split(FaceHandle); + void split(FaceHandle); private: GlobalPosition3D lowerExtent {}, upperExtent {}; -- cgit v1.2.3 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(-) (limited to 'game/geoData.h') 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