From d16a1c7579960c6af4e96cd10bb2fbe9341045d2 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 13 Jan 2023 18:19:26 +0800 Subject: [PATCH] Make CollisionShape selection box use shape AABB --- scene/3d/collision_shape.cpp | 12 ++++++++++++ scene/3d/collision_shape.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/scene/3d/collision_shape.cpp b/scene/3d/collision_shape.cpp index a1614282bc35..f7e754457f66 100644 --- a/scene/3d/collision_shape.cpp +++ b/scene/3d/collision_shape.cpp @@ -141,6 +141,18 @@ String CollisionShape::get_configuration_warning() const { return warning; } +#ifdef TOOLS_ENABLED +AABB CollisionShape::get_fallback_gizmo_aabb() const { + if (shape.is_null()) { + return Spatial::get_fallback_gizmo_aabb(); + } + + // get_debug_mesh() is not const because the mesh is lazy initialized and cached. + // It would be better if we can mark the cache mutable and make get_debug_mesh() const. + return const_cast(this)->shape->get_debug_mesh()->get_aabb(); +} +#endif + void CollisionShape::_bind_methods() { //not sure if this should do anything ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &CollisionShape::resource_changed); diff --git a/scene/3d/collision_shape.h b/scene/3d/collision_shape.h index 6a5d9fc6b627..e6b1c5be4f15 100644 --- a/scene/3d/collision_shape.h +++ b/scene/3d/collision_shape.h @@ -64,6 +64,10 @@ class CollisionShape : public Spatial { String get_configuration_warning() const; +#ifdef TOOLS_ENABLED + virtual AABB get_fallback_gizmo_aabb() const; +#endif + CollisionShape(); ~CollisionShape(); };