From d71a3c1940ee8e14c714ae44161d76114045112e Mon Sep 17 00:00:00 2001 From: Robert Yevdokimov <105675984+ryevdokimov@users.noreply.github.com> Date: Sun, 2 Feb 2025 08:13:06 +0400 Subject: [PATCH] Do not commit gizmo handles if no changes were made --- editor/plugins/gizmos/soft_body_3d_gizmo_plugin.cpp | 4 ++++ editor/plugins/gizmos/soft_body_3d_gizmo_plugin.h | 1 + editor/plugins/node_3d_editor_gizmos.cpp | 4 ++++ editor/plugins/node_3d_editor_gizmos.h | 1 + editor/plugins/node_3d_editor_plugin.cpp | 6 +++++- 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/editor/plugins/gizmos/soft_body_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/soft_body_3d_gizmo_plugin.cpp index e403e09397a..e860aaec3b3 100644 --- a/editor/plugins/gizmos/soft_body_3d_gizmo_plugin.cpp +++ b/editor/plugins/gizmos/soft_body_3d_gizmo_plugin.cpp @@ -54,6 +54,10 @@ bool SoftBody3DGizmoPlugin::is_selectable_when_hidden() const { return true; } +bool SoftBody3DGizmoPlugin::can_commit_handle_on_click() const { + return true; +} + void SoftBody3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { SoftBody3D *soft_body = Object::cast_to(p_gizmo->get_node_3d()); diff --git a/editor/plugins/gizmos/soft_body_3d_gizmo_plugin.h b/editor/plugins/gizmos/soft_body_3d_gizmo_plugin.h index f56e15287e7..4346bb20833 100644 --- a/editor/plugins/gizmos/soft_body_3d_gizmo_plugin.h +++ b/editor/plugins/gizmos/soft_body_3d_gizmo_plugin.h @@ -41,6 +41,7 @@ public: String get_gizmo_name() const override; int get_priority() const override; bool is_selectable_when_hidden() const override; + bool can_commit_handle_on_click() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const override; diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index 0b56e8ba6ba..b8856332641 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -1125,6 +1125,10 @@ bool EditorNode3DGizmoPlugin::is_selectable_when_hidden() const { return ret; } +bool EditorNode3DGizmoPlugin::can_commit_handle_on_click() const { + return false; +} + void EditorNode3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { GDVIRTUAL_CALL(_redraw, p_gizmo); } diff --git a/editor/plugins/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h index c895b9667f6..1cb7af6f200 100644 --- a/editor/plugins/node_3d_editor_gizmos.h +++ b/editor/plugins/node_3d_editor_gizmos.h @@ -198,6 +198,7 @@ public: virtual int get_priority() const; virtual bool can_be_hidden() const; virtual bool is_selectable_when_hidden() const; + virtual bool can_commit_handle_on_click() const; virtual void redraw(EditorNode3DGizmo *p_gizmo); virtual bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const; diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 2e89bb47061..d14aa36603a 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -1984,7 +1984,11 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (_edit.gizmo.is_valid()) { - _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_handle_secondary, _edit.gizmo_initial_value, false); + //Certain gizmo plugins should be able to commit handles without dragging them. + if (_edit.original_mouse_pos != _edit.mouse_pos || _edit.gizmo->get_plugin()->can_commit_handle_on_click()) { + _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_handle_secondary, _edit.gizmo_initial_value, false); + } + spatial_editor->get_single_selected_node()->update_gizmos(); _edit.gizmo = Ref(); break;