From aad2f0df2d2f8d47c46417c69aa26bc2863451ce Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Mon, 16 May 2022 22:07:57 +0100 Subject: [PATCH] Fix transition meshes not removed from the world --- terrain/variable_lod/voxel_mesh_block_vlt.cpp | 13 +++++++++++++ terrain/variable_lod/voxel_mesh_block_vlt.h | 1 + terrain/voxel_mesh_block.h | 3 +++ 3 files changed, 17 insertions(+) diff --git a/terrain/variable_lod/voxel_mesh_block_vlt.cpp b/terrain/variable_lod/voxel_mesh_block_vlt.cpp index 4d8fef1c..f0bec6cf 100644 --- a/terrain/variable_lod/voxel_mesh_block_vlt.cpp +++ b/terrain/variable_lod/voxel_mesh_block_vlt.cpp @@ -102,6 +102,19 @@ void VoxelMeshBlockVLT::set_transition_mesh(Ref mesh, int side, DirectMesh } } +void VoxelMeshBlockVLT::set_world(Ref p_world) { + if (_world != p_world) { + _world = p_world; + + // To update world. I replaced visibility by presence in world because Godot 3 culling performance is horrible + _set_visible(_visible && _parent_visible); + + if (_static_body.is_valid()) { + _static_body.set_world(*p_world); + } + } +} + void VoxelMeshBlockVLT::set_visible(bool visible) { if (_visible == visible) { return; diff --git a/terrain/variable_lod/voxel_mesh_block_vlt.h b/terrain/variable_lod/voxel_mesh_block_vlt.h index 66419e0d..f3d7928c 100644 --- a/terrain/variable_lod/voxel_mesh_block_vlt.h +++ b/terrain/variable_lod/voxel_mesh_block_vlt.h @@ -36,6 +36,7 @@ public: VoxelMeshBlockVLT(const Vector3i bpos, unsigned int size, unsigned int p_lod_index); ~VoxelMeshBlockVLT(); + void set_world(Ref p_world); void set_visible(bool visible); bool update_fading(float speed); diff --git a/terrain/voxel_mesh_block.h b/terrain/voxel_mesh_block.h index b70194e4..51030ef4 100644 --- a/terrain/voxel_mesh_block.h +++ b/terrain/voxel_mesh_block.h @@ -8,6 +8,9 @@ #include "../util/godot/direct_static_body.h" #include "../util/ref_count.h" #include "../util/span.h" + +#include + #include class Node3D;