summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-04-04 19:57:41 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-04-04 19:57:41 +0100
commit666f4603ee94148e41b4433a7f7a02d2f79d4651 (patch)
tree2426dcaa65b47e5d206a56d2e5e00b2950228d00 /game
parentTests for triangle helpers (diff)
downloadilt-666f4603ee94148e41b4433a7f7a02d2f79d4651.tar.bz2
ilt-666f4603ee94148e41b4433a7f7a02d2f79d4651.tar.xz
ilt-666f4603ee94148e41b4433a7f7a02d2f79d4651.zip
Update normals only as required
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp22
-rw-r--r--game/geoData.h1
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);