diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-04-04 19:57:41 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-04-04 19:57:41 +0100 |
commit | 666f4603ee94148e41b4433a7f7a02d2f79d4651 (patch) | |
tree | 2426dcaa65b47e5d206a56d2e5e00b2950228d00 /game/geoData.cpp | |
parent | Tests for triangle helpers (diff) | |
download | ilt-666f4603ee94148e41b4433a7f7a02d2f79d4651.tar.bz2 ilt-666f4603ee94148e41b4433a7f7a02d2f79d4651.tar.xz ilt-666f4603ee94148e41b4433a7f7a02d2f79d4651.zip |
Update normals only as required
Diffstat (limited to 'game/geoData.cpp')
-rw-r--r-- | game/geoData.cpp | 22 |
1 files changed, 16 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(); } |