@@ -31,11 +31,19 @@ void TerrainChunk::fetch_updates(const time::time_t & /* time */) {
3131 if (not this ->render_entity ->is_changed ()) {
3232 return ;
3333 }
34+
35+ // Get the terrain data from the render entity
36+ auto terrain_size = this ->render_entity ->get_size ();
37+ auto terrain_paths = this ->render_entity ->get_terrain_paths ();
38+ auto tiles = this ->render_entity ->get_tiles ();
39+ auto heightmap_verts = this ->render_entity ->get_vertices ();
40+
41+ // Recreate the mesh data
3442 // TODO: Change mesh instead of recreating it
3543 // TODO: Multiple meshes
3644 this ->meshes .clear ();
37- for (const auto &terrain_path : this -> render_entity -> get_terrain_paths () ) {
38- auto new_mesh = this ->create_mesh (terrain_path);
45+ for (const auto &terrain_path : terrain_paths ) {
46+ auto new_mesh = this ->create_mesh (terrain_size, tiles, heightmap_verts, terrain_path);
3947 new_mesh->create_model_matrix (this ->offset );
4048 this ->meshes .push_back (new_mesh);
4149 }
@@ -59,13 +67,12 @@ const std::vector<std::shared_ptr<TerrainRenderMesh>> &TerrainChunk::get_meshes(
5967 return this ->meshes ;
6068}
6169
62- std::shared_ptr<TerrainRenderMesh> TerrainChunk::create_mesh (const std::string &texture_path) {
63- auto size = this ->render_entity ->get_size ();
64- auto v_width = size[0 ];
65- auto v_height = size[1 ];
66-
67- auto tiles = this ->render_entity ->get_tiles ();
68- auto heightmap_verts = this ->render_entity ->get_vertices ();
70+ std::shared_ptr<TerrainRenderMesh> TerrainChunk::create_mesh (const util::Vector2s vert_size,
71+ const RenderEntity::tiles_t &tiles,
72+ const std::vector<coord::scene3> &heightmap_verts,
73+ const std::string &texture_path) {
74+ auto v_width = vert_size[0 ];
75+ auto v_height = vert_size[1 ];
6976
7077 // vertex data for the mesh
7178 std::vector<float > mesh_verts{};
0 commit comments