diff options
-rw-r--r-- | game/geoData.cpp | 22 | ||||
-rw-r--r-- | game/geoData.h | 1 |
2 files changed, 17 insertions, 6 deletions
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<const GlobalPosition3D> triangleStrip) return; } + const auto initialVertexCount = static_cast<unsigned int>(n_vertices()); + // Create new vertices std::vector<VertexHandle> newVerts; newVerts.reserve(newVerts.size()); @@ -653,6 +663,6 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> 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<GeoDataTraits>::split; std::array<FaceHandle, 4> split(FaceHandle); |