From 666f4603ee94148e41b4433a7f7a02d2f79d4651 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 4 Apr 2024 19:57:41 +0100 Subject: Update normals only as required --- game/geoData.cpp | 22 ++++++++++++++++------ game/geoData.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'game') diff --git a/game/geoData.cpp b/game/geoData.cpp index 1d11fda..9211369 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -373,11 +373,19 @@ GeoData::centre(const HalfedgeHandle heh) const void GeoData::update_vertex_normals_only() { - for (auto vh : all_vertices()) { - Normal3D n; - calc_vertex_normal_correct(vh, n); - this->set_normal(vh, glm::normalize(n)); - } + update_vertex_normals_only(vertices_sbegin()); +} + +void +GeoData::update_vertex_normals_only(VertexIter start) +{ + std::for_each(start, vertices_end(), [this](const auto vh) { + if (normal(vh) == Normal3D {}) { + Normal3D n; + calc_vertex_normal_correct(vh, n); + this->set_normal(vh, glm::normalize(n)); + } + }); } bool @@ -462,6 +470,8 @@ GeoData::setHeights(const std::span triangleStrip) return; } + const auto initialVertexCount = static_cast(n_vertices()); + // Create new vertices std::vector newVerts; newVerts.reserve(newVerts.size()); @@ -653,6 +663,6 @@ GeoData::setHeights(const std::span triangleStrip) }); // Tidy up + update_vertex_normals_only(VertexIter {*this, vertex_handle(initialVertexCount), true}); garbage_collection(); - update_vertex_normals_only(); } diff --git a/game/geoData.h b/game/geoData.h index 03bc159..021b4c7 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -180,6 +180,7 @@ protected: [[nodiscard]] GlobalPosition3D centre(const HalfedgeHandle) const; void update_vertex_normals_only(); + void update_vertex_normals_only(VertexIter start); using OpenMesh::TriMesh_ArrayKernelT::split; std::array split(FaceHandle); -- cgit v1.2.3