Skip to content

Commit 7ec0243

Browse files
committed
Merge pull request #110376 from TokageItLab/mod-keying
Add option to keying modified transform by `SkeletonModifier3D`
2 parents b9a92ca + f4244fd commit 7ec0243

File tree

7 files changed

+105
-28
lines changed

7 files changed

+105
-28
lines changed

editor/icons/InsertKey.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/icons/InsertModKey.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/icons/NewKey.svg

Lines changed: 1 addition & 1 deletion
Loading

editor/icons/NewModKey.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/icons/SkeletonModifier.svg

Lines changed: 1 addition & 0 deletions
Loading

editor/scene/3d/skeleton_3d_editor_plugin.cpp

Lines changed: 86 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,7 @@ void Skeleton3DEditor::_bind_methods() {
366366
}
367367

368368
void Skeleton3DEditor::_on_click_skeleton_option(int p_skeleton_option) {
369-
if (!skeleton) {
370-
return;
371-
}
369+
ERR_FAIL_COND(!skeleton);
372370

373371
switch (p_skeleton_option) {
374372
case SKELETON_OPTION_RESET_ALL_POSES: {
@@ -399,9 +397,8 @@ void Skeleton3DEditor::_on_click_skeleton_option(int p_skeleton_option) {
399397
}
400398

401399
void Skeleton3DEditor::reset_pose(const bool p_all_bones) {
402-
if (!skeleton) {
403-
return;
404-
}
400+
ERR_FAIL_COND(!skeleton);
401+
405402
const int bone_count = skeleton->get_bone_count();
406403
if (!bone_count) {
407404
return;
@@ -434,16 +431,34 @@ void Skeleton3DEditor::reset_pose(const bool p_all_bones) {
434431
ur->commit_action();
435432
}
436433

437-
void Skeleton3DEditor::insert_keys(const bool p_all_bones) {
434+
void Skeleton3DEditor::insert_keys(const bool p_all_bones, const bool p_enable_modifier) {
435+
ERR_FAIL_COND(!skeleton);
436+
438437
AnimationTrackEditor *te = AnimationPlayerEditor::get_singleton()->get_track_editor();
439438
bool is_read_only = te->is_read_only();
440439
if (is_read_only) {
441440
te->popup_read_only_dialog();
442441
return;
443442
}
444-
if (!skeleton) {
445-
return;
443+
if (p_enable_modifier) {
444+
if (!skeleton->is_connected(SceneStringName(skeleton_updated), callable_mp(this, &Skeleton3DEditor::_insert_keys).bind(p_all_bones))) {
445+
skeleton->connect(SceneStringName(skeleton_updated), callable_mp(this, &Skeleton3DEditor::_insert_keys).bind(p_all_bones), CONNECT_ONE_SHOT);
446+
} else {
447+
WARN_PRINT_ED("A skeleton_updated signal is already connected with _insert_keys().");
448+
}
449+
skeleton->force_update_deferred();
450+
skeleton->notification(Skeleton3D::NOTIFICATION_UPDATE_SKELETON);
451+
// Force disconnecting signal if remain the connecting just in case.
452+
if (skeleton->is_connected(SceneStringName(skeleton_updated), callable_mp(this, &Skeleton3DEditor::_insert_keys).bind(p_all_bones))) {
453+
skeleton->disconnect(SceneStringName(skeleton_updated), callable_mp(this, &Skeleton3DEditor::_insert_keys).bind(p_all_bones));
454+
}
455+
} else {
456+
_insert_keys(p_all_bones);
446457
}
458+
}
459+
460+
void Skeleton3DEditor::_insert_keys(const bool p_all_bones) {
461+
ERR_FAIL_COND(!skeleton);
447462

448463
bool pos_enabled = key_loc_button->is_pressed();
449464
bool rot_enabled = key_rot_button->is_pressed();
@@ -453,6 +468,7 @@ void Skeleton3DEditor::insert_keys(const bool p_all_bones) {
453468
Node *root = EditorNode::get_singleton()->get_tree()->get_root();
454469
String path = String(root->get_path_to(skeleton));
455470

471+
AnimationTrackEditor *te = AnimationPlayerEditor::get_singleton()->get_track_editor();
456472
te->make_insert_queue();
457473
for (int i = 0; i < bone_len; i++) {
458474
const String name = skeleton->get_bone_name(i);
@@ -475,9 +491,8 @@ void Skeleton3DEditor::insert_keys(const bool p_all_bones) {
475491
}
476492

477493
void Skeleton3DEditor::pose_to_rest(const bool p_all_bones) {
478-
if (!skeleton) {
479-
return;
480-
}
494+
ERR_FAIL_COND(!skeleton);
495+
481496
const int bone_count = skeleton->get_bone_count();
482497
if (!bone_count) {
483498
return;
@@ -1053,42 +1068,67 @@ void Skeleton3DEditor::create_editors() {
10531068
key_loc_button = memnew(Button);
10541069
key_loc_button->set_theme_type_variation(SceneStringName(FlatButton));
10551070
key_loc_button->set_toggle_mode(true);
1056-
key_loc_button->set_pressed(false);
1071+
key_loc_button->set_pressed(editor_plugin->loc_pressed);
10571072
key_loc_button->set_focus_mode(FOCUS_ACCESSIBILITY);
10581073
key_loc_button->set_tooltip_text(TTR("Translation mask for inserting keys."));
10591074
animation_hb->add_child(key_loc_button);
1075+
if (!key_loc_button->is_connected(SceneStringName(toggled), callable_mp(this, &Skeleton3DEditor::_loc_toggled))) {
1076+
key_loc_button->connect(SceneStringName(toggled), callable_mp(this, &Skeleton3DEditor::_loc_toggled));
1077+
}
10601078

10611079
key_rot_button = memnew(Button);
10621080
key_rot_button->set_theme_type_variation(SceneStringName(FlatButton));
10631081
key_rot_button->set_toggle_mode(true);
1064-
key_rot_button->set_pressed(true);
1082+
key_rot_button->set_pressed(editor_plugin->rot_pressed);
10651083
key_rot_button->set_focus_mode(FOCUS_ACCESSIBILITY);
10661084
key_rot_button->set_tooltip_text(TTR("Rotation mask for inserting keys."));
10671085
animation_hb->add_child(key_rot_button);
1086+
if (!key_rot_button->is_connected(SceneStringName(toggled), callable_mp(this, &Skeleton3DEditor::_rot_toggled))) {
1087+
key_rot_button->connect(SceneStringName(toggled), callable_mp(this, &Skeleton3DEditor::_rot_toggled));
1088+
}
10681089

10691090
key_scale_button = memnew(Button);
10701091
key_scale_button->set_theme_type_variation(SceneStringName(FlatButton));
10711092
key_scale_button->set_toggle_mode(true);
1072-
key_scale_button->set_pressed(false);
1093+
key_scale_button->set_pressed(editor_plugin->scl_pressed);
10731094
key_scale_button->set_focus_mode(FOCUS_ACCESSIBILITY);
10741095
key_scale_button->set_tooltip_text(TTR("Scale mask for inserting keys."));
10751096
animation_hb->add_child(key_scale_button);
1097+
if (!key_scale_button->is_connected(SceneStringName(toggled), callable_mp(this, &Skeleton3DEditor::_scl_toggled))) {
1098+
key_scale_button->connect(SceneStringName(toggled), callable_mp(this, &Skeleton3DEditor::_scl_toggled));
1099+
}
10761100

10771101
key_insert_button = memnew(Button);
10781102
key_insert_button->set_theme_type_variation(SceneStringName(FlatButton));
10791103
key_insert_button->set_focus_mode(FOCUS_ACCESSIBILITY);
1080-
key_insert_button->connect(SceneStringName(pressed), callable_mp(this, &Skeleton3DEditor::insert_keys).bind(false));
1104+
key_insert_button->connect(SceneStringName(pressed), callable_mp(this, &Skeleton3DEditor::insert_keys).bind(false, false));
10811105
key_insert_button->set_tooltip_text(TTRC("Insert key (based on mask) for bones with an existing track."));
10821106
key_insert_button->set_shortcut(ED_SHORTCUT("skeleton_3d_editor/insert_key_to_existing_tracks", TTRC("Insert Key (Existing Tracks)"), Key::INSERT));
10831107
animation_hb->add_child(key_insert_button);
10841108

1085-
key_insert_all_button = memnew(Button);
1086-
key_insert_all_button->set_theme_type_variation(SceneStringName(FlatButton));
1087-
key_insert_all_button->set_focus_mode(FOCUS_ACCESSIBILITY);
1088-
key_insert_all_button->connect(SceneStringName(pressed), callable_mp(this, &Skeleton3DEditor::insert_keys).bind(true));
1089-
key_insert_all_button->set_tooltip_text(TTRC("Insert key (based on mask) for all bones."));
1090-
key_insert_all_button->set_shortcut(ED_SHORTCUT("skeleton_3d_editor/insert_key_of_all_bones", TTRC("Insert Key (All Bones)"), KeyModifierMask::CMD_OR_CTRL + Key::INSERT));
1091-
animation_hb->add_child(key_insert_all_button);
1109+
key_insert_new_button = memnew(Button);
1110+
key_insert_new_button->set_theme_type_variation(SceneStringName(FlatButton));
1111+
key_insert_new_button->set_focus_mode(FOCUS_ACCESSIBILITY);
1112+
key_insert_new_button->connect(SceneStringName(pressed), callable_mp(this, &Skeleton3DEditor::insert_keys).bind(true, false));
1113+
key_insert_new_button->set_tooltip_text(TTRC("Insert key (based on mask) for all bones."));
1114+
key_insert_new_button->set_shortcut(ED_SHORTCUT("skeleton_3d_editor/insert_key_of_all_bones", TTRC("Insert Key (All Bones)"), KeyModifierMask::CMD_OR_CTRL + Key::INSERT));
1115+
animation_hb->add_child(key_insert_new_button);
1116+
1117+
key_mod_insert_button = memnew(Button);
1118+
key_mod_insert_button->set_theme_type_variation(SceneStringName(FlatButton));
1119+
key_mod_insert_button->set_focus_mode(FOCUS_ACCESSIBILITY);
1120+
key_mod_insert_button->connect(SceneStringName(pressed), callable_mp(this, &Skeleton3DEditor::insert_keys).bind(false, true));
1121+
key_mod_insert_button->set_tooltip_text(TTRC("Insert key (based on mask) for modified bones with an existing track."));
1122+
key_mod_insert_button->set_shortcut(ED_SHORTCUT("skeleton_3d_editor/insert_key_to_existing_tracks", TTRC("Insert Key (Existing Tracks)"), Key::INSERT));
1123+
animation_hb->add_child(key_mod_insert_button);
1124+
1125+
key_mod_insert_new_button = memnew(Button);
1126+
key_mod_insert_new_button->set_theme_type_variation(SceneStringName(FlatButton));
1127+
key_mod_insert_new_button->set_focus_mode(FOCUS_ACCESSIBILITY);
1128+
key_mod_insert_new_button->connect(SceneStringName(pressed), callable_mp(this, &Skeleton3DEditor::insert_keys).bind(true, true));
1129+
key_mod_insert_new_button->set_tooltip_text(TTRC("Insert new key (based on mask) for all modified bones."));
1130+
key_mod_insert_new_button->set_shortcut(ED_SHORTCUT("skeleton_3d_editor/insert_key_of_all_bones", TTRC("Insert Key (All Bones)"), KeyModifierMask::CMD_OR_CTRL + Key::INSERT));
1131+
animation_hb->add_child(key_mod_insert_new_button);
10921132

10931133
// Bone tree.
10941134
bones_section = memnew(EditorInspectorSection);
@@ -1122,6 +1162,25 @@ void Skeleton3DEditor::create_editors() {
11221162
set_keyable(te->has_keying());
11231163
}
11241164

1165+
void Skeleton3DEditor::_loc_toggled(bool p_toggled_on) {
1166+
if (!editor_plugin) {
1167+
return;
1168+
}
1169+
editor_plugin->loc_pressed = p_toggled_on;
1170+
}
1171+
void Skeleton3DEditor::_rot_toggled(bool p_toggled_on) {
1172+
if (!editor_plugin) {
1173+
return;
1174+
}
1175+
editor_plugin->rot_pressed = p_toggled_on;
1176+
}
1177+
void Skeleton3DEditor::_scl_toggled(bool p_toggled_on) {
1178+
if (!editor_plugin) {
1179+
return;
1180+
}
1181+
editor_plugin->scl_pressed = p_toggled_on;
1182+
}
1183+
11251184
void Skeleton3DEditor::_notification(int p_what) {
11261185
switch (p_what) {
11271186
case NOTIFICATION_ENTER_TREE: {
@@ -1148,8 +1207,10 @@ void Skeleton3DEditor::_notification(int p_what) {
11481207
key_loc_button->set_button_icon(get_editor_theme_icon(SNAME("KeyPosition")));
11491208
key_rot_button->set_button_icon(get_editor_theme_icon(SNAME("KeyRotation")));
11501209
key_scale_button->set_button_icon(get_editor_theme_icon(SNAME("KeyScale")));
1151-
key_insert_button->set_button_icon(get_editor_theme_icon(SNAME("Key")));
1152-
key_insert_all_button->set_button_icon(get_editor_theme_icon(SNAME("NewKey")));
1210+
key_insert_button->set_button_icon(get_editor_theme_icon(SNAME("InsertKey")));
1211+
key_insert_new_button->set_button_icon(get_editor_theme_icon(SNAME("NewKey")));
1212+
key_mod_insert_button->set_button_icon(get_editor_theme_icon(SNAME("InsertModKey")));
1213+
key_mod_insert_new_button->set_button_icon(get_editor_theme_icon(SNAME("NewModKey")));
11531214
bones_section->set_bg_color(get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
11541215

11551216
update_joint_tree();

editor/scene/3d/skeleton_3d_editor_plugin.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,14 @@ class Skeleton3DEditor : public VBoxContainer {
147147
Button *key_rot_button = nullptr;
148148
Button *key_scale_button = nullptr;
149149
Button *key_insert_button = nullptr;
150-
Button *key_insert_all_button = nullptr;
150+
Button *key_insert_new_button = nullptr;
151+
Button *key_mod_insert_button = nullptr;
152+
Button *key_mod_insert_new_button = nullptr;
153+
154+
// To maintain the status while running editor.
155+
void _loc_toggled(bool p_toggled_on);
156+
void _rot_toggled(bool p_toggled_on);
157+
void _scl_toggled(bool p_toggled_on);
151158

152159
EditorInspectorSection *bones_section = nullptr;
153160

@@ -172,7 +179,8 @@ class Skeleton3DEditor : public VBoxContainer {
172179
void reset_pose(const bool p_all_bones);
173180
void pose_to_rest(const bool p_all_bones);
174181

175-
void insert_keys(const bool p_all_bones);
182+
void _insert_keys(const bool p_all_bones);
183+
void insert_keys(const bool p_all_bones, const bool p_enable_modifier);
176184

177185
void create_physical_skeleton();
178186
PhysicalBone3D *create_physical_bone(int bone_id, int bone_child_id, const Vector<BoneInfo> &bones_infos);
@@ -247,6 +255,10 @@ class EditorInspectorPluginSkeleton : public EditorInspectorPlugin {
247255
Skeleton3DEditor *skel_editor = nullptr;
248256

249257
public:
258+
bool loc_pressed = false;
259+
bool rot_pressed = true;
260+
bool scl_pressed = false;
261+
250262
virtual bool can_handle(Object *p_object) override;
251263
virtual void parse_begin(Object *p_object) override;
252264
};

0 commit comments

Comments
 (0)