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 +++++ 1 file changed, 5 insertions(+) (limited to 'game/geoData.cpp') 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) { -- 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 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'game/geoData.cpp') 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 -- 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 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'game/geoData.cpp') 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; + }); } -- 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(-) (limited to 'game/geoData.cpp') 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 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(-) (limited to 'game/geoData.cpp') 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