From dff6d9e9e3362ea7629ab1ae1ff3f65ca6b3139a Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 11 Apr 2024 21:35:35 +0200 Subject: [PATCH] Added copy pose and paste pose tools to the skeleton editor. Also added separators to it's dropdown menu. --- .../editor/skeleton_editor_plugin.cpp | 35 +++++++++++++++++++ .../editor/skeleton_editor_plugin.h | 9 ++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/skeleton_3d/editor/skeleton_editor_plugin.cpp b/modules/skeleton_3d/editor/skeleton_editor_plugin.cpp index c66696a36..6ff2d7326 100644 --- a/modules/skeleton_3d/editor/skeleton_editor_plugin.cpp +++ b/modules/skeleton_3d/editor/skeleton_editor_plugin.cpp @@ -315,6 +315,12 @@ void SkeletonEditor::_on_click_skeleton_option(int p_skeleton_option) { case SKELETON_OPTION_RENAME_BONE: { rename_bone(); } break; + case SKELETON_OPTION_COPY_POSE: { + copy_pose(); + } break; + case SKELETON_OPTION_PASTE_POSE: { + paste_pose(); + } break; } } @@ -710,10 +716,15 @@ void SkeletonEditor::create_editors() { p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/init_selected_poses", TTR("Init selected Poses")), SKELETON_OPTION_INIT_SELECTED_POSES); p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/all_poses_to_rests", TTR("Apply all poses to rests")), SKELETON_OPTION_ALL_POSES_TO_RESTS); p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/selected_poses_to_rests", TTR("Apply selected poses to rests")), SKELETON_OPTION_SELECTED_POSES_TO_RESTS); + p->add_separator(); p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/create_physical_skeleton", TTR("Create physical skeleton")), SKELETON_OPTION_CREATE_PHYSICAL_SKELETON); + p->add_separator(); p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/add_bone", TTR("Add bone")), SKELETON_OPTION_ADD_BONE); p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/rename_bone", TTR("Rename bone")), SKELETON_OPTION_RENAME_BONE); p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/remove_bone", TTR("Remove bone")), SKELETON_OPTION_REMOVE_BONE); + p->add_separator(); + p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/copy_pose", TTR("Copy Pose")), SKELETON_OPTION_COPY_POSE); + p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/paste_pose", TTR("Paste Pose")), SKELETON_OPTION_PASTE_POSE); skeleton_options->get_popup()->connect("id_pressed", this, "_on_click_skeleton_option"); set_bone_options_enabled(false); @@ -1203,6 +1214,30 @@ void SkeletonEditor::_rename_bone_callback() { update_joint_tree(); } +void SkeletonEditor::copy_pose() { + if (!skeleton) { + return; + } + + _pose_clipboard.clear(); + + for (int i = 0; i < skeleton->get_bone_count(); ++i) { + Transform pose = skeleton->get_bone_pose(i); + _pose_clipboard.push_back(pose); + } +} +void SkeletonEditor::paste_pose() { + if (!skeleton) { + return; + } + + ERR_FAIL_COND(skeleton->get_bone_count() != _pose_clipboard.size()); + + for (int i = 0; i < skeleton->get_bone_count(); ++i) { + skeleton->set_bone_pose(i, _pose_clipboard[i]); + } +} + void SkeletonEditor::create_bone_tool_popups() { _bone_add_dialog = memnew(ConfirmationDialog); _bone_add_dialog->set_title("Add bone"); diff --git a/modules/skeleton_3d/editor/skeleton_editor_plugin.h b/modules/skeleton_3d/editor/skeleton_editor_plugin.h index d2961fd50..6e031cc51 100644 --- a/modules/skeleton_3d/editor/skeleton_editor_plugin.h +++ b/modules/skeleton_3d/editor/skeleton_editor_plugin.h @@ -120,7 +120,9 @@ class SkeletonEditor : public VBoxContainer { SKELETON_OPTION_CREATE_PHYSICAL_SKELETON, SKELETON_OPTION_ADD_BONE, SKELETON_OPTION_REMOVE_BONE, - SKELETON_OPTION_RENAME_BONE + SKELETON_OPTION_RENAME_BONE, + SKELETON_OPTION_COPY_POSE, + SKELETON_OPTION_PASTE_POSE, }; struct BoneInfo { @@ -245,6 +247,11 @@ public: void _add_bone_callback(); void _remove_bone_callback(); void _rename_bone_callback(); + + void copy_pose(); + void paste_pose(); + + Vector _pose_clipboard; void create_bone_tool_popups(); static void _bind_tool_popup_methods();