feat: implemented chunking
This commit is contained in:
parent
823d70a93c
commit
f5a78e10c7
6 changed files with 188 additions and 45 deletions
50
modules/terrain_editor/terrain_chunk.cpp
Normal file
50
modules/terrain_editor/terrain_chunk.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include "terrain_chunk.h"
|
||||
#include "terrain_editor/terrain_mesh_generator.h"
|
||||
|
||||
void TerrainChunk::_bind_methods() {}
|
||||
|
||||
void TerrainChunk::ready() {
|
||||
if ((this->generator = cast_to<TerrainMeshGenerator>(get_parent()))) {
|
||||
this->generator->connect(TerrainMeshGenerator::sig_primitives_changed, callable_mp(this, &self_type::on_terrain_changed));
|
||||
} else {
|
||||
print_error(vformat("Chunk %s ready without generator.", get_path()));
|
||||
return;
|
||||
}
|
||||
this->set_mesh(this->lod1);
|
||||
on_terrain_changed();
|
||||
}
|
||||
|
||||
void TerrainChunk::on_terrain_changed() {
|
||||
if (this->generator) {
|
||||
Vector3 const position{ get_global_position() };
|
||||
this->generator->generate_grid({ { position.x, position.z }, { this->size, this->size } }, this->mesh, this->lod1_detail);
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainChunk::_notification(int what) {
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_READY:
|
||||
ready();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainChunk::set_size(float size) {
|
||||
this->size = size;
|
||||
on_terrain_changed();
|
||||
}
|
||||
|
||||
float TerrainChunk::get_size() const {
|
||||
return this->size;
|
||||
}
|
||||
|
||||
void TerrainChunk::set_lod1_detail(int detail) {
|
||||
this->lod1_detail = detail;
|
||||
on_terrain_changed();
|
||||
}
|
||||
|
||||
int TerrainChunk::get_lod1_detail() const {
|
||||
return this->lod1_detail;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue