add init bone poses
This commit is contained in:
parent
982ff7d925
commit
b27fe6452d
5 changed files with 46 additions and 19 deletions
|
@ -281,6 +281,19 @@
|
||||||
[b]Note:[/b] This does not remove the child bone, but instead it removes the connection it has to the parent bone.
|
[b]Note:[/b] This does not remove the child bone, but instead it removes the connection it has to the parent bone.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="reset_bone_pose">
|
||||||
|
<return type="void" />
|
||||||
|
<param index="0" name="bone_idx" type="int" />
|
||||||
|
<description>
|
||||||
|
Sets the bone pose to rest for [param bone_idx].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="reset_bone_poses">
|
||||||
|
<return type="void" />
|
||||||
|
<description>
|
||||||
|
Sets all bone poses to rests.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="set_bone_children">
|
<method name="set_bone_children">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<param index="0" name="bone_idx" type="int" />
|
<param index="0" name="bone_idx" type="int" />
|
||||||
|
|
|
@ -221,7 +221,7 @@ void Skeleton3DEditor::set_keyable(const bool p_keyable) {
|
||||||
};
|
};
|
||||||
|
|
||||||
void Skeleton3DEditor::set_bone_options_enabled(const bool p_bone_options_enabled) {
|
void Skeleton3DEditor::set_bone_options_enabled(const bool p_bone_options_enabled) {
|
||||||
skeleton_options->get_popup()->set_item_disabled(SKELETON_OPTION_INIT_SELECTED_POSES, !p_bone_options_enabled);
|
skeleton_options->get_popup()->set_item_disabled(SKELETON_OPTION_RESET_SELECTED_POSES, !p_bone_options_enabled);
|
||||||
skeleton_options->get_popup()->set_item_disabled(SKELETON_OPTION_SELECTED_POSES_TO_RESTS, !p_bone_options_enabled);
|
skeleton_options->get_popup()->set_item_disabled(SKELETON_OPTION_SELECTED_POSES_TO_RESTS, !p_bone_options_enabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -231,12 +231,12 @@ void Skeleton3DEditor::_on_click_skeleton_option(int p_skeleton_option) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (p_skeleton_option) {
|
switch (p_skeleton_option) {
|
||||||
case SKELETON_OPTION_INIT_ALL_POSES: {
|
case SKELETON_OPTION_RESET_ALL_POSES: {
|
||||||
init_pose(true);
|
reset_pose(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SKELETON_OPTION_INIT_SELECTED_POSES: {
|
case SKELETON_OPTION_RESET_SELECTED_POSES: {
|
||||||
init_pose(false);
|
reset_pose(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SKELETON_OPTION_ALL_POSES_TO_RESTS: {
|
case SKELETON_OPTION_ALL_POSES_TO_RESTS: {
|
||||||
|
@ -258,7 +258,7 @@ void Skeleton3DEditor::_on_click_skeleton_option(int p_skeleton_option) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skeleton3DEditor::init_pose(const bool p_all_bones) {
|
void Skeleton3DEditor::reset_pose(const bool p_all_bones) {
|
||||||
if (!skeleton) {
|
if (!skeleton) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -271,27 +271,21 @@ void Skeleton3DEditor::init_pose(const bool p_all_bones) {
|
||||||
ur->create_action(TTR("Set Bone Transform"), UndoRedo::MERGE_ENDS);
|
ur->create_action(TTR("Set Bone Transform"), UndoRedo::MERGE_ENDS);
|
||||||
if (p_all_bones) {
|
if (p_all_bones) {
|
||||||
for (int i = 0; i < bone_len; i++) {
|
for (int i = 0; i < bone_len; i++) {
|
||||||
Transform3D rest = skeleton->get_bone_rest(i);
|
|
||||||
ur->add_do_method(skeleton, "set_bone_pose_position", i, rest.origin);
|
|
||||||
ur->add_do_method(skeleton, "set_bone_pose_rotation", i, rest.basis.get_rotation_quaternion());
|
|
||||||
ur->add_do_method(skeleton, "set_bone_pose_scale", i, rest.basis.get_scale());
|
|
||||||
ur->add_undo_method(skeleton, "set_bone_pose_position", i, skeleton->get_bone_pose_position(i));
|
ur->add_undo_method(skeleton, "set_bone_pose_position", i, skeleton->get_bone_pose_position(i));
|
||||||
ur->add_undo_method(skeleton, "set_bone_pose_rotation", i, skeleton->get_bone_pose_rotation(i));
|
ur->add_undo_method(skeleton, "set_bone_pose_rotation", i, skeleton->get_bone_pose_rotation(i));
|
||||||
ur->add_undo_method(skeleton, "set_bone_pose_scale", i, skeleton->get_bone_pose_scale(i));
|
ur->add_undo_method(skeleton, "set_bone_pose_scale", i, skeleton->get_bone_pose_scale(i));
|
||||||
}
|
}
|
||||||
|
ur->add_do_method(skeleton, "reset_bone_poses");
|
||||||
} else {
|
} else {
|
||||||
// Todo: Do method with multiple bone selection.
|
// Todo: Do method with multiple bone selection.
|
||||||
if (selected_bone == -1) {
|
if (selected_bone == -1) {
|
||||||
ur->commit_action();
|
ur->commit_action();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Transform3D rest = skeleton->get_bone_rest(selected_bone);
|
|
||||||
ur->add_do_method(skeleton, "set_bone_pose_position", selected_bone, rest.origin);
|
|
||||||
ur->add_do_method(skeleton, "set_bone_pose_rotation", selected_bone, rest.basis.get_rotation_quaternion());
|
|
||||||
ur->add_do_method(skeleton, "set_bone_pose_scale", selected_bone, rest.basis.get_scale());
|
|
||||||
ur->add_undo_method(skeleton, "set_bone_pose_position", selected_bone, skeleton->get_bone_pose_position(selected_bone));
|
ur->add_undo_method(skeleton, "set_bone_pose_position", selected_bone, skeleton->get_bone_pose_position(selected_bone));
|
||||||
ur->add_undo_method(skeleton, "set_bone_pose_rotation", selected_bone, skeleton->get_bone_pose_rotation(selected_bone));
|
ur->add_undo_method(skeleton, "set_bone_pose_rotation", selected_bone, skeleton->get_bone_pose_rotation(selected_bone));
|
||||||
ur->add_undo_method(skeleton, "set_bone_pose_scale", selected_bone, skeleton->get_bone_pose_scale(selected_bone));
|
ur->add_undo_method(skeleton, "set_bone_pose_scale", selected_bone, skeleton->get_bone_pose_scale(selected_bone));
|
||||||
|
ur->add_do_method(skeleton, "reset_bone_pose", selected_bone);
|
||||||
}
|
}
|
||||||
ur->commit_action();
|
ur->commit_action();
|
||||||
}
|
}
|
||||||
|
@ -721,8 +715,8 @@ void Skeleton3DEditor::create_editors() {
|
||||||
|
|
||||||
// Skeleton options.
|
// Skeleton options.
|
||||||
PopupMenu *p = skeleton_options->get_popup();
|
PopupMenu *p = skeleton_options->get_popup();
|
||||||
p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/init_all_poses", TTR("Init all Poses")), SKELETON_OPTION_INIT_ALL_POSES);
|
p->add_shortcut(ED_SHORTCUT("skeleton_3d_editor/reset_all_poses", TTR("Reset all bone Poses")), SKELETON_OPTION_RESET_ALL_POSES);
|
||||||
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/reset_selected_poses", TTR("Reset selected Poses")), SKELETON_OPTION_RESET_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/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_shortcut(ED_SHORTCUT("skeleton_3d_editor/selected_poses_to_rests", TTR("Apply selected poses to rests")), SKELETON_OPTION_SELECTED_POSES_TO_RESTS);
|
||||||
p->add_item(TTR("Create physical skeleton"), SKELETON_OPTION_CREATE_PHYSICAL_SKELETON);
|
p->add_item(TTR("Create physical skeleton"), SKELETON_OPTION_CREATE_PHYSICAL_SKELETON);
|
||||||
|
|
|
@ -96,8 +96,8 @@ class Skeleton3DEditor : public VBoxContainer {
|
||||||
friend class Skeleton3DEditorPlugin;
|
friend class Skeleton3DEditorPlugin;
|
||||||
|
|
||||||
enum SkeletonOption {
|
enum SkeletonOption {
|
||||||
SKELETON_OPTION_INIT_ALL_POSES,
|
SKELETON_OPTION_RESET_ALL_POSES,
|
||||||
SKELETON_OPTION_INIT_SELECTED_POSES,
|
SKELETON_OPTION_RESET_SELECTED_POSES,
|
||||||
SKELETON_OPTION_ALL_POSES_TO_RESTS,
|
SKELETON_OPTION_ALL_POSES_TO_RESTS,
|
||||||
SKELETON_OPTION_SELECTED_POSES_TO_RESTS,
|
SKELETON_OPTION_SELECTED_POSES_TO_RESTS,
|
||||||
SKELETON_OPTION_CREATE_PHYSICAL_SKELETON,
|
SKELETON_OPTION_CREATE_PHYSICAL_SKELETON,
|
||||||
|
@ -148,7 +148,7 @@ class Skeleton3DEditor : public VBoxContainer {
|
||||||
|
|
||||||
void create_editors();
|
void create_editors();
|
||||||
|
|
||||||
void init_pose(const bool p_all_bones);
|
void reset_pose(const bool p_all_bones);
|
||||||
void pose_to_rest(const bool p_all_bones);
|
void pose_to_rest(const bool p_all_bones);
|
||||||
|
|
||||||
void insert_keys(const bool p_all_bones);
|
void insert_keys(const bool p_all_bones);
|
||||||
|
|
|
@ -762,6 +762,20 @@ Vector3 Skeleton3D::get_bone_pose_scale(int p_bone) const {
|
||||||
return bones[p_bone].pose_scale;
|
return bones[p_bone].pose_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Skeleton3D::reset_bone_pose(int p_bone) {
|
||||||
|
const int bone_size = bones.size();
|
||||||
|
ERR_FAIL_INDEX(p_bone, bone_size);
|
||||||
|
set_bone_pose_position(p_bone, bones[p_bone].rest.origin);
|
||||||
|
set_bone_pose_rotation(p_bone, bones[p_bone].rest.basis.get_rotation_quaternion());
|
||||||
|
set_bone_pose_scale(p_bone, bones[p_bone].rest.basis.get_scale());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Skeleton3D::reset_bone_poses() {
|
||||||
|
for (int i = 0; i < bones.size(); i++) {
|
||||||
|
reset_bone_pose(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Transform3D Skeleton3D::get_bone_pose(int p_bone) const {
|
Transform3D Skeleton3D::get_bone_pose(int p_bone) const {
|
||||||
const int bone_size = bones.size();
|
const int bone_size = bones.size();
|
||||||
ERR_FAIL_INDEX_V(p_bone, bone_size, Transform3D());
|
ERR_FAIL_INDEX_V(p_bone, bone_size, Transform3D());
|
||||||
|
@ -1252,6 +1266,9 @@ void Skeleton3D::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_bone_pose_rotation", "bone_idx"), &Skeleton3D::get_bone_pose_rotation);
|
ClassDB::bind_method(D_METHOD("get_bone_pose_rotation", "bone_idx"), &Skeleton3D::get_bone_pose_rotation);
|
||||||
ClassDB::bind_method(D_METHOD("get_bone_pose_scale", "bone_idx"), &Skeleton3D::get_bone_pose_scale);
|
ClassDB::bind_method(D_METHOD("get_bone_pose_scale", "bone_idx"), &Skeleton3D::get_bone_pose_scale);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("reset_bone_pose", "bone_idx"), &Skeleton3D::reset_bone_pose);
|
||||||
|
ClassDB::bind_method(D_METHOD("reset_bone_poses"), &Skeleton3D::reset_bone_poses);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("is_bone_enabled", "bone_idx"), &Skeleton3D::is_bone_enabled);
|
ClassDB::bind_method(D_METHOD("is_bone_enabled", "bone_idx"), &Skeleton3D::is_bone_enabled);
|
||||||
ClassDB::bind_method(D_METHOD("set_bone_enabled", "bone_idx", "enabled"), &Skeleton3D::set_bone_enabled, DEFVAL(true));
|
ClassDB::bind_method(D_METHOD("set_bone_enabled", "bone_idx", "enabled"), &Skeleton3D::set_bone_enabled, DEFVAL(true));
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,9 @@ public:
|
||||||
Quaternion get_bone_pose_rotation(int p_bone) const;
|
Quaternion get_bone_pose_rotation(int p_bone) const;
|
||||||
Vector3 get_bone_pose_scale(int p_bone) const;
|
Vector3 get_bone_pose_scale(int p_bone) const;
|
||||||
|
|
||||||
|
void reset_bone_pose(int p_bone);
|
||||||
|
void reset_bone_poses();
|
||||||
|
|
||||||
void clear_bones_global_pose_override();
|
void clear_bones_global_pose_override();
|
||||||
Transform3D get_bone_global_pose_override(int p_bone) const;
|
Transform3D get_bone_global_pose_override(int p_bone) const;
|
||||||
void set_bone_global_pose_override(int p_bone, const Transform3D &p_pose, real_t p_amount, bool p_persistent = false);
|
void set_bone_global_pose_override(int p_bone, const Transform3D &p_pose, real_t p_amount, bool p_persistent = false);
|
||||||
|
|
Loading…
Reference in a new issue