Skip to content

Commit eef9912

Browse files
committed
Merge pull request #109828 from Calinou/editor-softbody3d-pin-undo-redo
Create an undo/redo action when pinning a SoftBody3D point in the editor
2 parents 54a0a94 + edfe631 commit eef9912

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

editor/scene/3d/gizmos/physics/soft_body_3d_gizmo_plugin.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "soft_body_3d_gizmo_plugin.h"
3232

33+
#include "editor/editor_undo_redo_manager.h"
3334
#include "scene/3d/physics/soft_body_3d.h"
3435

3536
SoftBody3DGizmoPlugin::SoftBody3DGizmoPlugin() {
@@ -106,7 +107,15 @@ Variant SoftBody3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo
106107

107108
void SoftBody3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {
108109
SoftBody3D *soft_body = Object::cast_to<SoftBody3D>(p_gizmo->get_node_3d());
109-
soft_body->pin_point_toggle(p_id);
110+
const bool is_pinned = soft_body->is_point_pinned(p_id);
111+
112+
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
113+
undo_redo->create_action(vformat(is_pinned ? TTR("Remove SoftBody3D pinned point %d") : TTR("Add SoftBody3D pinned point %d"), p_id));
114+
undo_redo->add_do_method(soft_body, "set_point_pinned", p_id, !is_pinned);
115+
undo_redo->add_do_method(soft_body, "update_gizmos");
116+
undo_redo->add_undo_method(soft_body, "set_point_pinned", p_id, is_pinned);
117+
undo_redo->add_undo_method(soft_body, "update_gizmos");
118+
undo_redo->commit_action();
110119
}
111120

112121
bool SoftBody3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {

scene/3d/physics/soft_body_3d.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,6 @@ void SoftBody3D::apply_central_force(const Vector3 &p_force) {
704704
PhysicsServer3D::get_singleton()->soft_body_apply_central_force(physics_rid, p_force);
705705
}
706706

707-
void SoftBody3D::pin_point_toggle(int p_point_index) {
708-
pin_point(p_point_index, !(-1 != _has_pinned_point(p_point_index)));
709-
}
710-
711707
void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path, int p_insert_at) {
712708
ERR_FAIL_COND_MSG(p_insert_at < -1 || p_insert_at >= pinned_points.size(), "Invalid index for pin point insertion position.");
713709
_pin_point_on_physics_server(p_point_index, pin);

scene/3d/physics/soft_body_3d.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ class SoftBody3D : public MeshInstance3D {
182182

183183
Vector3 get_point_transform(int p_point_index);
184184

185-
void pin_point_toggle(int p_point_index);
186185
void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath(), int p_insert_at = -1);
187186
bool is_point_pinned(int p_point_index) const;
188187

0 commit comments

Comments
 (0)