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.cpp | 5 +++++ game/geoData.h | 25 ++++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/game/geoData.cpp b/game/geoData.cpp index 2313342..e465ba0 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -6,6 +6,11 @@ #include #include +GeoData::GeoData() +{ + add_property(surface); +} + GeoData GeoData::loadFromAsciiGrid(const std::filesystem::path & input) { 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 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(-) 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 741bb027df58fd9f30f4d94cdaf2d6416e11e3ee Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 16 Apr 2024 00:23:43 +0100 Subject: Custom vertex, vertex shader and fragment shader for landmass Handles global position type, colourBias for surface types --- game/terrain.cpp | 22 ++++++++++++++++------ game/terrain.h | 9 ++++++++- gfx/gl/sceneShader.cpp | 3 ++- gfx/gl/shaders/landmass.fs | 23 +++++++++++++++-------- gfx/gl/shaders/landmass.vs | 23 +++++++++++++++++++++++ gfx/gl/shaders/shadowFixedPoint.vs | 9 --------- gfx/gl/shaders/shadowLandmass.vs | 13 +++++++++++++ gfx/gl/shadowMapper.cpp | 6 +++--- gfx/gl/shadowMapper.h | 2 +- 9 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 gfx/gl/shaders/landmass.vs delete mode 100644 gfx/gl/shaders/shadowFixedPoint.vs create mode 100644 gfx/gl/shaders/shadowLandmass.vs diff --git a/game/terrain.cpp b/game/terrain.cpp index c19bd0a..3b16e79 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -15,11 +15,21 @@ #include #include +static constexpr RGB openSurface {-1}; + Terrain::Terrain(std::shared_ptr tm) : geoData {std::move(tm)}, grass {std::make_shared("grass.png")} { generateMeshes(); } +template<> +VertexArrayObject & +VertexArrayObject::addAttribsFor(const GLuint arrayBuffer, const GLuint divisor) +{ + return addAttribs( + arrayBuffer, divisor); +} + void Terrain::generateMeshes() { @@ -32,13 +42,13 @@ Terrain::generateMeshes() [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); + const auto surface = geoData->get_surface(f); + if (const auto vertexIndexRef = vertexIndex.emplace(std::make_pair(v, surface), 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)); + vertices.emplace_back(geoData->point(v), geoData->normal(v), + surface ? surface->colorBias : openSurface); } }); }); @@ -49,7 +59,7 @@ Terrain::generateMeshes() return vertexIndex[std::make_pair(v, geoData->get_surface(f))]; }); }); - meshes.create(vertices, indices); + meshes.create>(vertices, indices); } void @@ -68,6 +78,6 @@ Terrain::render(const SceneShader & shader) const void Terrain::shadows(const ShadowMapper & shadowMapper) const { - shadowMapper.fixedPoint.use(); + shadowMapper.landmess.use(); meshes.apply(&Mesh::Draw); } diff --git a/game/terrain.h b/game/terrain.h index 54593fc..d088f89 100644 --- a/game/terrain.h +++ b/game/terrain.h @@ -2,6 +2,7 @@ #include "chronology.h" #include "collection.h" +#include "config/types.h" #include "game/worldobject.h" #include #include @@ -20,10 +21,16 @@ public: void tick(TickDuration) override; + struct Vertex { + GlobalPosition3D pos; + Normal3D normal; + RGB colourBias; + }; + private: void generateMeshes(); std::shared_ptr geoData; - Collection meshes; + Collection, false> meshes; std::shared_ptr grass; }; diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 2dd9612..985faa0 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,7 @@ SceneShader::allPrograms(auto member, auto &&... ps) const } SceneShader::SceneShader() : - basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs}, + basicInst {dynamicPointInst_vs, material_fs}, landmass {landmass_vs, landmass_fs}, absolute {fixedPoint_vs, material_fs}, spotLightInst {spotLight_vs, spotLight_gs, spotLight_fs}, pointLightInst {pointLight_vs, pointLight_gs, pointLight_fs}, networkStraight {networkStraight_vs, networkStraight_gs, network_fs}, diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.fs index fc43bf2..55e3c24 100644 --- a/gfx/gl/shaders/landmass.fs +++ b/gfx/gl/shaders/landmass.fs @@ -1,9 +1,12 @@ #version 330 core -include(`materialInterface.glsl') include(`materialOut.glsl') +in vec3 FragPos; +in vec3 Normal; +flat in vec3 ColourBias; uniform sampler2D texture0; +uniform ivec3 viewPoint; const vec3 grass = vec3(.1, .4, .05); const vec3 slope = vec3(.6, .6, .4); @@ -11,9 +14,9 @@ const vec3 rock = vec3(.2, .2, .1); const vec3 sand = vec3(.76, .7, .5); const vec3 snow = vec3(.97, .97, .99); -const float beachline = 500; -const float snowline_low = 28000; -const float snowline_high = 30000; +const int beachline = 500; +const int snowline_low = 28000; +const int snowline_high = 30000; const float slope_min = .99; const float slope_mid = .95; @@ -28,10 +31,14 @@ mixBetween(vec3 colA, vec3 colB, float blend, float low, float high) void main() { - vec3 color = texture(texture0, TexCoords).rgb; + ivec3 position = ivec3(FragPos) + viewPoint; + vec3 color = texture(texture0, vec2(position.xy % 10000) / 10000.0).rgb; - float height = FragPos.z; - if (height < beachline) { // Sandy beach + int height = position.z; + if (ColourBias.r >= 0) { + color *= ColourBias; + } + else if (height < beachline) { // Sandy beach color *= sand; } else if (Normal.z < slope_max) { // Dark rocky face @@ -60,7 +67,7 @@ main() } } - gPosition = ivec4(FragPos, 1); + gPosition = ivec4(position, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = vec4(color, 1); } diff --git a/gfx/gl/shaders/landmass.vs b/gfx/gl/shaders/landmass.vs new file mode 100644 index 0000000..9617cb9 --- /dev/null +++ b/gfx/gl/shaders/landmass.vs @@ -0,0 +1,23 @@ +#version 330 core +#extension GL_ARB_shading_language_420pack : enable + +layout(location = 0) in ivec3 position; +layout(location = 1) in vec3 normal; +layout(location = 2) in vec3 colourBias; + +out vec3 FragPos; +out vec3 Normal; +flat out vec3 ColourBias; + +uniform mat4 viewProjection; +uniform ivec3 viewPoint; + +void +main() +{ + FragPos = position - viewPoint; + Normal = normal; + ColourBias = colourBias; + + gl_Position = viewProjection * vec4(FragPos, 1); +} diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs deleted file mode 100644 index 1376388..0000000 --- a/gfx/gl/shaders/shadowFixedPoint.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 330 core - -include(`meshIn.glsl') - -uniform ivec3 viewPoint; -const mat3 model = mat3(1); -const ivec3 modelPos = ivec3(0); - -include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowLandmass.vs b/gfx/gl/shaders/shadowLandmass.vs new file mode 100644 index 0000000..becf142 --- /dev/null +++ b/gfx/gl/shaders/shadowLandmass.vs @@ -0,0 +1,13 @@ +#version 330 core + +layout(location = 0) in ivec3 position; + +uniform ivec3 viewPoint; + +out vec4 vworldPos; + +void +main() +{ + vworldPos = vec4(position - viewPoint, 1); +} diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 4dbee8d..206e4a7 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -4,7 +4,7 @@ #include "gfx/gl/shaders/gs-commonShadowPoint.h" #include "gfx/gl/shaders/vs-shadowDynamicPoint.h" #include "gfx/gl/shaders/vs-shadowDynamicPointInst.h" -#include "gfx/gl/shaders/vs-shadowFixedPoint.h" +#include "gfx/gl/shaders/vs-shadowLandmass.h" #include "gl_traits.h" #include "location.h" #include "maths.h" @@ -18,7 +18,7 @@ #include ShadowMapper::ShadowMapper(const TextureAbsCoord & s) : - fixedPoint {shadowFixedPoint_vs}, dynamicPointInst {shadowDynamicPointInst_vs}, size {s} + landmess {shadowLandmass_vs}, dynamicPointInst {shadowDynamicPointInst_vs}, size {s} { glBindTexture(GL_TEXTURE_2D_ARRAY, depthMap); glTexImage3D( @@ -92,7 +92,7 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const return lightProjection * lightViewDir; }); - for (const auto p : std::initializer_list {&fixedPoint, &dynamicPoint, &dynamicPointInst}) { + for (const auto p : std::initializer_list {&landmess, &dynamicPoint, &dynamicPointInst}) { p->setView(out, lightViewPoint); } scene.shadows(*this); diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index a95d4c1..dcf7e3f 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -50,7 +50,7 @@ public: RequiredUniformLocation modelPosLoc; }; - FixedPoint fixedPoint, dynamicPointInst; + FixedPoint landmess, dynamicPointInst; DynamicPoint dynamicPoint; // NOLINTNEXTLINE(hicpp-explicit-conversions) -- cgit v1.2.3 From 3b5450676b61efd2ee8eaab09ee95eba34a39870 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 18 Apr 2024 19:53:33 +0100 Subject: Define some initial surface types --- res/surfaces.xml | 7 +++++++ test/test-assetFactory.cpp | 15 +++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 res/surfaces.xml diff --git a/res/surfaces.xml b/res/surfaces.xml new file mode 100644 index 0000000..459eb9c --- /dev/null +++ b/res/surfaces.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 8341fbf..6061723 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -12,6 +12,7 @@ #include "game/scenary/illuminator.h" #include "game/scenary/light.h" #include "game/scenary/plant.h" +#include "game/surface.h" #include "game/vehicles/railVehicle.h" #include "game/vehicles/railVehicleClass.h" #include "gfx/gl/sceneRenderer.h" @@ -80,6 +81,20 @@ private: BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture); +BOOST_AUTO_TEST_CASE(surfaces, *boost::unit_test::timeout(5)) +{ + auto mf = AssetFactory::loadXML(RESDIR "/surfaces.xml"); + BOOST_REQUIRE(mf); + BOOST_CHECK_EQUAL(4, mf->assets.size()); + auto gravelAsset = mf->assets.at("terrain.surface.gravel"); + BOOST_REQUIRE(gravelAsset); + auto gravel = std::dynamic_pointer_cast(gravelAsset); + BOOST_REQUIRE(gravel); + BOOST_REQUIRE_EQUAL(gravel->name, "Gravel"); + BOOST_REQUIRE_EQUAL(gravel->colorBias, RGB {.9F}); + BOOST_REQUIRE_EQUAL(gravel->quality, 1.F); +} + BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5)) { auto mf = AssetFactory::loadXML(RESDIR "/brush47.xml"); -- 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(-) 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(-) 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 From 1cf26dffe9dd5f94c7fd5fb812d498349bfda152 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 26 Apr 2024 22:17:59 +0100 Subject: Simplify new face split loop --- game/geoData.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/game/geoData.cpp b/game/geoData.cpp index 59feac1..5beac94 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -487,16 +487,12 @@ GeoData::setHeights(const std::span triangleStrip, const const auto [a, b, c] = newVert; add_face(a, b, c); }); - for (auto start = faces_sbegin(); std::any_of(start, faces_end(), [this, &start](const auto fh) { - static constexpr auto MAX_FACE_AREA = 100'000'000.F; - if (triangle<3>(fh).area() > MAX_FACE_AREA) { - split(fh); - start = FaceIter {*this, FaceHandle(fh), true}; - return true; - } - return false; - });) { - ; + for (auto fhi = FaceIter {*this, FaceHandle {initialFaceCount}, true}; fhi != faces_end(); fhi++) { + static constexpr auto MAX_FACE_AREA = 100'000'000.F; + const auto fh = *fhi; + if (triangle<3>(fh).area() > MAX_FACE_AREA) { + split(fh); + } } std::vector newFaces; std::copy_if(FaceIter {*this, FaceHandle {initialFaceCount}, true}, faces_end(), std::back_inserter(newFaces), -- cgit v1.2.3 From 54c16af4136fcc0cf2aff6c89ba1d5e4a832415a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 May 2024 12:54:45 +0100 Subject: Update to std c++23 for good ranges --- Jamroot.jam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jamroot.jam b/Jamroot.jam index 7a2fe16..712ad63 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -16,7 +16,7 @@ lib OpenMeshCore ; variant coverage : debug ; project : requirements - 20 + 23 -Wl,-z,defs release:on profile:on -- cgit v1.2.3 From ad9671c3d71f7bea55c3a36fc4fcca7d55f88258 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 May 2024 15:34:58 +0100 Subject: Remove abuse of std::adjacent_find from cylinder --- assetFactory/cylinder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp index fd96c8b..f41bfd4 100644 --- a/assetFactory/cylinder.cpp +++ b/assetFactory/cylinder.cpp @@ -1,6 +1,7 @@ #include "cylinder.h" #include "maths.h" #include "modelFactoryMesh.h" +#include Cylinder::CreatedFaces Cylinder::createMesh(ModelFactoryMesh & mesh, Scale3D lodf) const @@ -40,13 +41,12 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, Scale3D lodf) const // Wrap around edge.back() = edge.front(); // Transform adjacent pairs of top/bottom pairs to faces - std::adjacent_find(edge.begin(), edge.end(), [&mesh, &surface](const auto & first, const auto & second) { + for (const auto & [first, second] : edge | std::views::adjacent<2>) { const auto fh = surface.insert(mesh.add_namedFace("edge", first.first, first.second, second.second, second.first)) ->second; mesh.property(mesh.smoothFaceProperty, fh) = true; - return false; - }); + } } return surface; -- cgit v1.2.3 From 78a83e1792735e0f1cfa4d1d6219ca791c418551 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 May 2024 15:47:31 +0100 Subject: Remove abuse of std::adjacent_find from geoData --- game/geoData.cpp | 121 +++++++++++++++++++++++++++---------------------------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/game/geoData.cpp b/game/geoData.cpp index 5beac94..72aa056 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include GeoData::GeoData() @@ -571,15 +572,14 @@ GeoData::setHeights(const std::span triangleStrip, const // Cut existing terrain extrusionExtents.emplace_back(extrusionExtents.front()); // Circular next std::vector> boundaryFaces; - std::adjacent_find(extrusionExtents.begin(), extrusionExtents.end(), - [this, &boundaryFaces](const auto & first, const auto & second) { - const auto p0 = point(first.boundaryVertex); - const auto p1 = point(second.boundaryVertex); - const auto bdir = RelativePosition3D(p1 - p0); - const auto make_plane = [p0](auto y, auto z) { - return GeometricPlaneT {p0, crossProduct(y, z)}; - }; - const auto planes = ((first.boundaryVertex == second.boundaryVertex) + for (const auto & [first, second] : extrusionExtents | std::views::adjacent<2>) { + const auto p0 = point(first.boundaryVertex); + const auto p1 = point(second.boundaryVertex); + const auto bdir = RelativePosition3D(p1 - p0); + const auto make_plane = [p0](auto y, auto z) { + return GeometricPlaneT {p0, crossProduct(y, z)}; + }; + const auto planes = ((first.boundaryVertex == second.boundaryVertex) ? std::array {make_plane(second.lowerLimit, first.lowerLimit), make_plane(second.upperLimit, first.upperLimit), } @@ -587,58 +587,57 @@ GeoData::setHeights(const std::span triangleStrip, const make_plane(bdir, second.lowerLimit), make_plane(bdir, second.upperLimit), }); - assert(planes.front().normal.z > 0.F); - assert(planes.back().normal.z > 0.F); - - auto & out = boundaryFaces.emplace_back(); - out.emplace_back(first.boundaryVertex); - out.emplace_back(first.extrusionVertex); - for (auto currentVertex = first.extrusionVertex; - !find_halfedge(currentVertex, second.extrusionVertex).is_valid();) { - [[maybe_unused]] const auto n = std::any_of( - voh_begin(currentVertex), voh_end(currentVertex), [&](const auto currentVertexOut) { - const auto next = next_halfedge_handle(currentVertexOut); - const auto nextVertex = to_vertex_handle(next); - const auto startVertex = from_vertex_handle(next); - if (nextVertex == *++out.rbegin()) { - // This half edge goes back to the previous vertex - return false; - } - const auto edge = edge_handle(next); - const auto ep0 = point(startVertex); - const auto ep1 = point(nextVertex); - if (planes.front().getRelation(ep1) == GeometricPlane::PlaneRelation::Below - || planes.back().getRelation(ep1) == GeometricPlane::PlaneRelation::Above) { - return false; - } - const auto diff = RelativePosition3D(ep1 - ep0); - const auto length = glm::length(diff); - const auto dir = diff / length; - const Ray r {ep1, -dir}; - const auto dists = planes * [r](const auto & plane) { - RelativeDistance dist {}; - if (r.intersectPlane(plane.origin, plane.normal, dist)) { - return dist; - } - return INFINITY; - }; - const auto dist = *std::min_element(dists.begin(), dists.end()); - const auto splitPos = ep1 - (dir * dist); - if (dist <= length) { - currentVertex = split(edge, splitPos); - out.emplace_back(currentVertex); - return true; - } - return false; - }); - assert(n); - } - out.emplace_back(second.extrusionVertex); - if (first.boundaryVertex != second.boundaryVertex) { - out.emplace_back(second.boundaryVertex); - } - return false; - }); + assert(planes.front().normal.z > 0.F); + assert(planes.back().normal.z > 0.F); + + auto & out = boundaryFaces.emplace_back(); + out.emplace_back(first.boundaryVertex); + out.emplace_back(first.extrusionVertex); + for (auto currentVertex = first.extrusionVertex; + !find_halfedge(currentVertex, second.extrusionVertex).is_valid();) { + [[maybe_unused]] const auto n + = std::any_of(voh_begin(currentVertex), voh_end(currentVertex), [&](const auto currentVertexOut) { + const auto next = next_halfedge_handle(currentVertexOut); + const auto nextVertex = to_vertex_handle(next); + const auto startVertex = from_vertex_handle(next); + if (nextVertex == *++out.rbegin()) { + // This half edge goes back to the previous vertex + return false; + } + const auto edge = edge_handle(next); + const auto ep0 = point(startVertex); + const auto ep1 = point(nextVertex); + if (planes.front().getRelation(ep1) == GeometricPlane::PlaneRelation::Below + || planes.back().getRelation(ep1) == GeometricPlane::PlaneRelation::Above) { + return false; + } + const auto diff = RelativePosition3D(ep1 - ep0); + const auto length = glm::length(diff); + const auto dir = diff / length; + const Ray r {ep1, -dir}; + const auto dists = planes * [r](const auto & plane) { + RelativeDistance dist {}; + if (r.intersectPlane(plane.origin, plane.normal, dist)) { + return dist; + } + return INFINITY; + }; + const auto dist = *std::min_element(dists.begin(), dists.end()); + const auto splitPos = ep1 - (dir * dist); + if (dist <= length) { + currentVertex = split(edge, splitPos); + out.emplace_back(currentVertex); + return true; + } + return false; + }); + assert(n); + } + out.emplace_back(second.extrusionVertex); + if (first.boundaryVertex != second.boundaryVertex) { + out.emplace_back(second.boundaryVertex); + } + } // Remove old faces std::set visited; -- cgit v1.2.3 From c1a2a2fdf3c8b16e2235962ffefad010d9c9f8ed Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 27 May 2024 13:43:47 +0100 Subject: Surface asset test doesn't need render dump --- test/test-assetFactory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 6061723..73370c8 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -79,8 +79,6 @@ private: SceneRenderer sceneRenderer; }; -BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture); - BOOST_AUTO_TEST_CASE(surfaces, *boost::unit_test::timeout(5)) { auto mf = AssetFactory::loadXML(RESDIR "/surfaces.xml"); @@ -95,6 +93,8 @@ BOOST_AUTO_TEST_CASE(surfaces, *boost::unit_test::timeout(5)) BOOST_REQUIRE_EQUAL(gravel->quality, 1.F); } +BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture); + BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5)) { auto mf = AssetFactory::loadXML(RESDIR "/brush47.xml"); -- cgit v1.2.3