#include "terrain_chunk.h" #include "terrain_editor/terrain_mesh_generator.h" void TerrainChunk::_bind_methods() {} void TerrainChunk::ready() { if ((this->generator = cast_to(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; }