summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-04-12 00:03:15 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-04-12 00:03:15 +0100
commitb44c2d85bb8e46c4a6c65aacd23157c07cb80eca (patch)
tree0674470bfacdc6a5314886e088a2be2dfdb346be /game
parentIntroduce a basic terrain surface type asset (diff)
downloadilt-b44c2d85bb8e46c4a6c65aacd23157c07cb80eca.tar.bz2
ilt-b44c2d85bb8e46c4a6c65aacd23157c07cb80eca.tar.xz
ilt-b44c2d85bb8e46c4a6c65aacd23157c07cb80eca.zip
Create terrain vertices per surface type
Diffstat (limited to 'game')
-rw-r--r--game/geoData.h7
-rw-r--r--game/terrain.cpp24
2 files changed, 23 insertions, 8 deletions
diff --git a/game/geoData.h b/game/geoData.h
index 7a2344d..5586023 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -150,6 +150,13 @@ public:
return std::tie(lowerExtent, upperExtent);
}
+ template<typename HandleT>
+ [[nodiscard]] auto
+ get_surface(const HandleT h)
+ {
+ return property(surface, h);
+ }
+
protected:
template<glm::length_t Dim>
[[nodiscard]] Triangle<Dim>
diff --git a/game/terrain.cpp b/game/terrain.cpp
index 201c732..c19bd0a 100644
--- a/game/terrain.cpp
+++ b/game/terrain.cpp
@@ -27,18 +27,26 @@ Terrain::generateMeshes()
indices.reserve(geoData->n_faces() * 3);
std::vector<Vertex> vertices;
vertices.reserve(geoData->n_vertices());
- std::map<GeoData::VertexHandle, size_t> vertexIndex;
- std::transform(geoData->vertices_sbegin(), geoData->vertices_end(), std::back_inserter(vertices),
- [this, &vertexIndex](const GeoData::VertexHandle v) {
- vertexIndex.emplace(v, vertexIndex.size());
- const auto p = geoData->point(v);
- return Vertex {p, RelativePosition2D(p) / 10000.F, geoData->normal(v)};
+ std::map<std::pair<GeoData::VertexHandle, const Surface *>, size_t> vertexIndex;
+ std::for_each(geoData->vertices_sbegin(), geoData->vertices_end(),
+ [this, &vertexIndex, &vertices](const GeoData::VertexHandle v) {
+ std::for_each(geoData->vf_begin(v), geoData->vf_end(v),
+ [&vertexIndex, v, this, &vertices](const GeoData::FaceHandle f) {
+ if (const auto vertexIndexRef
+ = vertexIndex.emplace(std::make_pair(v, geoData->get_surface(f)), 0);
+ vertexIndexRef.second) {
+ vertexIndexRef.first->second = vertices.size();
+
+ const auto p = geoData->point(v);
+ vertices.emplace_back(p, RelativePosition2D(p) / 10000.F, geoData->normal(v));
+ }
+ });
});
std::for_each(
geoData->faces_sbegin(), geoData->faces_end(), [this, &vertexIndex, &indices](const GeoData::FaceHandle f) {
std::transform(geoData->fv_begin(f), geoData->fv_end(f), std::back_inserter(indices),
- [&vertexIndex](const GeoData::VertexHandle v) {
- return vertexIndex[v];
+ [&vertexIndex, f, this](const GeoData::VertexHandle v) {
+ return vertexIndex[std::make_pair(v, geoData->get_surface(f))];
});
});
meshes.create<Mesh>(vertices, indices);