From 7004ce5816adf4971e7e41c03b8e925cb44df11d Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 17 Jul 2022 20:24:49 +0100 Subject: [PATCH] Auto-assign a mesher in editor for convenience --- terrain/fixed_lod/voxel_terrain.cpp | 14 ++++++++++++++ terrain/variable_lod/voxel_lod_terrain.cpp | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/terrain/fixed_lod/voxel_terrain.cpp b/terrain/fixed_lod/voxel_terrain.cpp index ec852ae5..33e46ab4 100644 --- a/terrain/fixed_lod/voxel_terrain.cpp +++ b/terrain/fixed_lod/voxel_terrain.cpp @@ -18,6 +18,9 @@ #include "../../util/string_funcs.h" #include "../instancing/voxel_instancer.h" #include "../voxel_data_block_enter_info.h" +#ifdef TOOLS_ENABLED +#include "../../meshers/transvoxel/voxel_mesher_transvoxel.h" +#endif #include #include @@ -862,6 +865,17 @@ void VoxelTerrain::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: set_process(true); +#ifdef TOOLS_ENABLED + // In the editor, auto-configure a default mesher, for convenience. + // Because Godot has a property hint to automatically instantiate a resource, but if that resource is + // abstract, it doesn't work... and it cannot be a default value because such practice was deprecated with a + // warning in Godot 4. + if (Engine::get_singleton()->is_editor_hint() && !get_mesher().is_valid()) { + Ref mesher; + mesher.instantiate(); + set_mesher(mesher); + } +#endif break; case NOTIFICATION_PROCESS: diff --git a/terrain/variable_lod/voxel_lod_terrain.cpp b/terrain/variable_lod/voxel_lod_terrain.cpp index 5c2ad7a7..78d7e8dc 100644 --- a/terrain/variable_lod/voxel_lod_terrain.cpp +++ b/terrain/variable_lod/voxel_lod_terrain.cpp @@ -20,6 +20,9 @@ #include "../../util/thread/rw_lock.h" #include "../instancing/voxel_instancer.h" #include "voxel_lod_terrain_update_task.h" +#ifdef TOOLS_ENABLED +#include "../../meshers/transvoxel/voxel_mesher_transvoxel.h" +#endif #include #include @@ -1116,6 +1119,20 @@ void VoxelLodTerrain::_notification(int p_what) { break; } +#ifdef TOOLS_ENABLED + case NOTIFICATION_ENTER_TREE: + // In the editor, auto-configure a default mesher, for convenience. + // Because Godot has a property hint to automatically instantiate a resource, but if that resource is + // abstract, it doesn't work... and it cannot be a default value because such practice was deprecated with a + // warning in Godot 4. + if (Engine::get_singleton()->is_editor_hint() && !get_mesher().is_valid()) { + Ref mesher; + mesher.instantiate(); + set_mesher(mesher); + } + break; +#endif + case NOTIFICATION_EXIT_TREE: break;