From edfe631c7c800a338514d3a943f85780e5b23367 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Fri, 4 Jul 2025 13:07:55 -0700 Subject: [PATCH] Create an undo/redo action when pinning a SoftBody3D point in the editor Previously, if you pinned a point by clicking on one of the soft body vertex handles, the scene was not marked as modified, and the action could not be undone by hitting Ctrl + Z. Co-authored-by: Tomasz Chabora --- .../3d/gizmos/physics/soft_body_3d_gizmo_plugin.cpp | 11 ++++++++++- scene/3d/physics/soft_body_3d.cpp | 4 ---- scene/3d/physics/soft_body_3d.h | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/editor/scene/3d/gizmos/physics/soft_body_3d_gizmo_plugin.cpp b/editor/scene/3d/gizmos/physics/soft_body_3d_gizmo_plugin.cpp index c15675b603..ceec5d9bd6 100644 --- a/editor/scene/3d/gizmos/physics/soft_body_3d_gizmo_plugin.cpp +++ b/editor/scene/3d/gizmos/physics/soft_body_3d_gizmo_plugin.cpp @@ -30,6 +30,7 @@ #include "soft_body_3d_gizmo_plugin.h" +#include "editor/editor_undo_redo_manager.h" #include "scene/3d/physics/soft_body_3d.h" SoftBody3DGizmoPlugin::SoftBody3DGizmoPlugin() { @@ -106,7 +107,15 @@ Variant SoftBody3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo void SoftBody3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) { SoftBody3D *soft_body = Object::cast_to(p_gizmo->get_node_3d()); - soft_body->pin_point_toggle(p_id); + const bool is_pinned = soft_body->is_point_pinned(p_id); + + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(vformat(is_pinned ? TTR("Remove SoftBody3D pinned point %d") : TTR("Add SoftBody3D pinned point %d"), p_id)); + undo_redo->add_do_method(soft_body, "set_point_pinned", p_id, !is_pinned); + undo_redo->add_do_method(soft_body, "update_gizmos"); + undo_redo->add_undo_method(soft_body, "set_point_pinned", p_id, is_pinned); + undo_redo->add_undo_method(soft_body, "update_gizmos"); + undo_redo->commit_action(); } bool SoftBody3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const { diff --git a/scene/3d/physics/soft_body_3d.cpp b/scene/3d/physics/soft_body_3d.cpp index 32f2b4e689..7f6928e694 100644 --- a/scene/3d/physics/soft_body_3d.cpp +++ b/scene/3d/physics/soft_body_3d.cpp @@ -704,10 +704,6 @@ void SoftBody3D::apply_central_force(const Vector3 &p_force) { PhysicsServer3D::get_singleton()->soft_body_apply_central_force(physics_rid, p_force); } -void SoftBody3D::pin_point_toggle(int p_point_index) { - pin_point(p_point_index, !(-1 != _has_pinned_point(p_point_index))); -} - void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path, int p_insert_at) { ERR_FAIL_COND_MSG(p_insert_at < -1 || p_insert_at >= pinned_points.size(), "Invalid index for pin point insertion position."); _pin_point_on_physics_server(p_point_index, pin); diff --git a/scene/3d/physics/soft_body_3d.h b/scene/3d/physics/soft_body_3d.h index 1eb10a6804..3672010391 100644 --- a/scene/3d/physics/soft_body_3d.h +++ b/scene/3d/physics/soft_body_3d.h @@ -182,7 +182,6 @@ public: Vector3 get_point_transform(int p_point_index); - void pin_point_toggle(int p_point_index); void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath(), int p_insert_at = -1); bool is_point_pinned(int p_point_index) const;