Skip to content

Commit

Permalink
Added copy pose and paste pose tools to the skeleton editor. Also add…
Browse files Browse the repository at this point in the history
…ed separators to it's dropdown menu.
  • Loading branch information
Relintai committed Apr 11, 2024
1 parent 3b25f0c commit dff6d9e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
35 changes: 35 additions & 0 deletions modules/skeleton_3d/editor/skeleton_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 8 additions & 1 deletion modules/skeleton_3d/editor/skeleton_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -245,6 +247,11 @@ class SkeletonEditor : public VBoxContainer {
void _add_bone_callback();
void _remove_bone_callback();
void _rename_bone_callback();

void copy_pose();
void paste_pose();

Vector<Transform> _pose_clipboard;

void create_bone_tool_popups();
static void _bind_tool_popup_methods();
Expand Down

0 comments on commit dff6d9e

Please sign in to comment.