From 40373aeee4f17c2aca0cee0f892d904b006752b2 Mon Sep 17 00:00:00 2001 From: yahkr <62478788+yahkr@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:47:29 -0500 Subject: [PATCH] Add option to toggle always showing collision shapes --- doc/classes/EditorSettings.xml | 3 +++ .../physics/collision_shape_3d_gizmo_plugin.cpp | 11 +++++++++++ .../gizmos/physics/collision_shape_3d_gizmo_plugin.h | 3 +++ editor/scene/3d/node_3d_editor_plugin.cpp | 4 ++++ editor/settings/editor_settings.cpp | 1 + 5 files changed, 22 insertions(+) diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index f7f598f101..4be77fca31 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -599,6 +599,9 @@ Size of the disk gizmo displayed when editing [Path3D]'s tilt handles. + + If [code]true[/code], collision shapes in the 3D editor are visible only when selected. If [code]false[/code], collision shapes are always visible. + If [code]true[/code], automatically updates animation tracks' target paths when renaming or reparenting nodes in the Scene tree dock. diff --git a/editor/scene/3d/gizmos/physics/collision_shape_3d_gizmo_plugin.cpp b/editor/scene/3d/gizmos/physics/collision_shape_3d_gizmo_plugin.cpp index 898f3a4013..3cfd29b3ea 100644 --- a/editor/scene/3d/gizmos/physics/collision_shape_3d_gizmo_plugin.cpp +++ b/editor/scene/3d/gizmos/physics/collision_shape_3d_gizmo_plugin.cpp @@ -35,6 +35,7 @@ #include "editor/editor_undo_redo_manager.h" #include "editor/scene/3d/gizmos/gizmo_3d_helper.h" #include "editor/scene/3d/node_3d_editor_plugin.h" +#include "editor/settings/editor_settings.h" #include "scene/3d/physics/collision_shape_3d.h" #include "scene/resources/3d/box_shape_3d.h" #include "scene/resources/3d/capsule_shape_3d.h" @@ -49,6 +50,8 @@ CollisionShape3DGizmoPlugin::CollisionShape3DGizmoPlugin() { helper.instantiate(); + show_only_when_selected = EDITOR_GET("editors/3d_gizmos/gizmo_settings/show_collision_shapes_only_when_selected"); + create_collision_material("shape_material", 2.0); create_collision_material("shape_material_arraymesh", 0.0625); @@ -307,6 +310,10 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { return; } + if (show_only_when_selected && !p_gizmo->is_selected()) { + return; + } + const Ref material = get_material(!cs->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo); const Ref material_arraymesh = @@ -667,3 +674,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->add_lines(lines, material, false, collision_color); } } + +void CollisionShape3DGizmoPlugin::set_show_only_when_selected(bool p_enabled) { + show_only_when_selected = p_enabled; +} diff --git a/editor/scene/3d/gizmos/physics/collision_shape_3d_gizmo_plugin.h b/editor/scene/3d/gizmos/physics/collision_shape_3d_gizmo_plugin.h index e63c6fd736..43d9ce1e44 100644 --- a/editor/scene/3d/gizmos/physics/collision_shape_3d_gizmo_plugin.h +++ b/editor/scene/3d/gizmos/physics/collision_shape_3d_gizmo_plugin.h @@ -41,11 +41,14 @@ class CollisionShape3DGizmoPlugin : public EditorNode3DGizmoPlugin { Ref helper; + inline static bool show_only_when_selected = false; + public: bool has_gizmo(Node3D *p_spatial) override; String get_gizmo_name() const override; int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; + static void set_show_only_when_selected(bool p_enabled); String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override; Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override; diff --git a/editor/scene/3d/node_3d_editor_plugin.cpp b/editor/scene/3d/node_3d_editor_plugin.cpp index 6976e9799c..38fb13c499 100644 --- a/editor/scene/3d/node_3d_editor_plugin.cpp +++ b/editor/scene/3d/node_3d_editor_plugin.cpp @@ -9022,6 +9022,10 @@ void Node3DEditor::_notification(int p_what) { } update_gizmo_opacity(); } + if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d_gizmos/gizmo_settings")) { + CollisionShape3DGizmoPlugin::set_show_only_when_selected(EDITOR_GET("editors/3d_gizmos/gizmo_settings/show_collision_shapes_only_when_selected")); + update_all_gizmos(); + } } break; case NOTIFICATION_PHYSICS_PROCESS: { diff --git a/editor/settings/editor_settings.cpp b/editor/settings/editor_settings.cpp index 0f381c0ff3..9d2ba8e63d 100644 --- a/editor/settings/editor_settings.cpp +++ b/editor/settings/editor_settings.cpp @@ -907,6 +907,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d_gizmos/gizmo_settings/bone_shape", 1, "Wire,Octahedron"); EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size", 0.8, "0.01,4.0,0.001,or_greater", PROPERTY_USAGE_DEFAULT) EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d_gizmos/gizmo_settings/lightmap_gi_probe_size", 0.4, "0.0,1.0,0.001,or_greater", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED) + _initial_set("editors/3d_gizmos/gizmo_settings/show_collision_shapes_only_when_selected", false); // If a line is a multiple of this, it uses the primary grid color. // Use a power of 2 value by default as it's more common to use powers of 2 in level design.