Don't destroy and re-generate meshes in TerrainChunk's _enter and _exit_tree, just hide / show them. This makes scene tab swithing with TerrainWorlds in the editor a lot simpler.

This commit is contained in:
Relintai 2025-04-18 19:50:17 +02:00
parent ae18822f95
commit 64696b534b
4 changed files with 19 additions and 24 deletions

View File

@ -766,10 +766,7 @@ void TerrainChunkDefault::_visibility_changed(bool visible) {
void TerrainChunkDefault::_exit_tree() {
TerrainChunk::_exit_tree();
if (!_is_generating) {
rids_free();
rids_clear();
}
visibility_changed(false);
}
void TerrainChunkDefault::_world_transform_changed() {

View File

@ -168,9 +168,6 @@ public:
void draw_debug_voxel_lights();
void draw_debug_mdr_colliders();
//Visibility
void visibility_changed(bool visible);
//free
void free_chunk();

View File

@ -76,7 +76,7 @@ void TerrainChunk::set_visible(const bool value) {
if (_is_visible == value) {
return;
}
_is_visible = value;
visibility_changed(value);
@ -1977,6 +1977,15 @@ TerrainChunk::TerrainChunk() {
}
TerrainChunk::~TerrainChunk() {
if (_library.is_valid() && _library->supports_caching()) {
if (material_cache_key_has()) {
_library->material_cache_unref(material_cache_key_get());
material_cache_key_set(0);
material_cache_key_has_set(false);
}
}
if (_library.is_valid()) {
_library.unref();
}
@ -2048,6 +2057,8 @@ void TerrainChunk::_enter_tree() {
}
}
#endif
visibility_changed(_is_visible);
}
void TerrainChunk::_exit_tree() {
@ -2067,15 +2078,6 @@ void TerrainChunk::_exit_tree() {
}
}
if (_library.is_valid() && _library->supports_caching()) {
if (material_cache_key_has()) {
_library->material_cache_unref(material_cache_key_get());
material_cache_key_set(0);
material_cache_key_has_set(false);
}
}
#ifdef MODULE_VERTEX_LIGHTS_3D_ENABLED
TerrainWorld *world = get_voxel_world();

View File

@ -54,8 +54,8 @@
#include "../../props/props/prop_data_scene.h"
#ifdef MODULE_ENTITY_SPELL_SYSTEM_ENABLED
#include "modules/entity_spell_system/props/prop_data_ess_entity_world_spawner_3d_single.h"
#include "modules/entity_spell_system/props/prop_data_ess_entity_world_spawner_3d_area.h"
#include "modules/entity_spell_system/props/prop_data_ess_entity_world_spawner_3d_single.h"
#endif
#endif
@ -75,8 +75,6 @@
#include "scene/resources/world_3d.h"
#endif
const String TerrainWorld::BINDING_STRING_CHANNEL_TYPE_INFO = "Type,Isolevel,Liquid,Liquid Level";
bool TerrainWorld::get_active() const {
@ -883,7 +881,7 @@ void TerrainWorld::prop_add(Transform transform, const Ref<PropData> &prop, cons
/*
TODO Chunks will need a new api for this. Props that should just create nodes using processor_get_node_for().
node_props / managed_props / instanced_props?
Ref<PropDataESSEntityWorldSpawner3DSingle> world_Spawner_single_data = entry;
if (world_Spawner_single_data.is_valid()) {
@ -895,7 +893,7 @@ void TerrainWorld::prop_add(Transform transform, const Ref<PropData> &prop, cons
continue;
}
Ref<PropDataESSEntityWorldSpawner3DArea> world_Spawner_area_data = entry;
*/
#endif
@ -1610,13 +1608,15 @@ void TerrainWorld::_notification(int p_what) {
for (int i = 0; i < _chunks_vector.size(); ++i) {
Ref<TerrainChunk> chunk = _chunks_vector[i];
if (chunk.is_valid()) {
if (chunk.is_valid() && !chunk->get_is_setup()) {
chunk_setup(chunk);
chunk->set_voxel_world(this);
chunk->enter_tree();
chunk->build();
} else {
chunk->enter_tree();
}
}
break;
@ -1725,7 +1725,6 @@ void TerrainWorld::_notification(int p_what) {
if (chunk.is_valid()) {
if (chunk->get_voxel_world() == this) {
chunk->exit_tree();
chunk->set_voxel_world(NULL);
}
}
}