diff options
author | Juan Linietsky <reduzio@gmail.com> | 2021-10-13 15:49:14 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 15:49:14 -0300 |
commit | 78cdfff0ec43a13406a7654eaf89aad50ddf8fde (patch) | |
tree | 43014179b44fedcca852bc32ff13ac3cd6929b30 /editor | |
parent | c515fdd0fb480fe4e833ddd6cfe8c8162cd15e81 (diff) | |
parent | 2dc823273e8d7d0eb92049c0d687f6a2c247ce13 (diff) |
Merge pull request #53765 from reduz/skeleton-remove-rest-influence
Remove REST transform influence in skeleton bones
Diffstat (limited to 'editor')
-rw-r--r-- | editor/import/editor_import_collada.cpp | 19 | ||||
-rw-r--r-- | editor/plugins/skeleton_3d_editor_plugin.cpp | 40 | ||||
-rw-r--r-- | editor/plugins/skeleton_3d_editor_plugin.h | 4 |
3 files changed, 13 insertions, 50 deletions
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 022dc899da..d1bacf54de 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -120,6 +120,15 @@ Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p skeleton_bone_map[p_skeleton][joint->sid] = r_bone; + { + Transform3D xform = joint->compute_transform(collada); + collada.fix_transform(xform) * joint->post_transform; + + p_skeleton->set_bone_pose_position(r_bone, xform.origin); + p_skeleton->set_bone_pose_rotation(r_bone, xform.basis.get_rotation_quaternion()); + p_skeleton->set_bone_pose_scale(r_bone, xform.basis.get_scale()); + } + if (collada.state.bone_rest_map.has(joint->sid)) { p_skeleton->set_bone_rest(r_bone, collada.fix_transform(collada.state.bone_rest_map[joint->sid])); //should map this bone to something for animation? @@ -1639,16 +1648,6 @@ void ColladaImport::create_animation(int p_clip, bool p_import_value_tracks) { Transform3D xform = cn->compute_transform(collada); xform = collada.fix_transform(xform) * cn->post_transform; - if (nm.bone >= 0) { - //make bone transform relative to rest (in case of skeleton) - Skeleton3D *sk = Object::cast_to<Skeleton3D>(nm.node); - if (sk) { - xform = sk->get_bone_rest(nm.bone).affine_inverse() * xform; - } else { - ERR_PRINT("Collada: Invalid skeleton"); - } - } - Vector3 s = xform.basis.get_scale(); bool singular_matrix = Math::is_zero_approx(s.x) || Math::is_zero_approx(s.y) || Math::is_zero_approx(s.z); Quaternion q = singular_matrix ? Quaternion() : diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index 3a67c5415c..f9c46d35c4 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -200,12 +200,7 @@ void BoneTransformEditor::_value_changed_transform(const String p_property_name, } void BoneTransformEditor::_change_transform(Transform3D p_new_transform) { - if (property.get_slicec('/', 0) == "bones" && property.get_slicec('/', 2) == "custom_pose") { - undo_redo->create_action(TTR("Set Custom Bone Pose Transform"), UndoRedo::MERGE_ENDS); - undo_redo->add_undo_method(skeleton, "set_bone_custom_pose", property.get_slicec('/', 1).to_int(), skeleton->get_bone_custom_pose(property.get_slicec('/', 1).to_int())); - undo_redo->add_do_method(skeleton, "set_bone_custom_pose", property.get_slicec('/', 1).to_int(), p_new_transform); - undo_redo->commit_action(); - } else if (property.get_slicec('/', 0) == "bones") { + if (property.get_slicec('/', 0) == "bones") { undo_redo->create_action(TTR("Set Bone Transform"), UndoRedo::MERGE_ENDS); undo_redo->add_undo_property(skeleton, property, skeleton->get(property)); undo_redo->add_do_property(skeleton, property, p_new_transform); @@ -236,21 +231,6 @@ void BoneTransformEditor::_update_properties() { _update_transform_properties(tform); } -void BoneTransformEditor::_update_custom_pose_properties() { - if (updating) { - return; - } - - if (!skeleton) { - return; - } - - updating = true; - - Transform3D tform = skeleton->get_bone_custom_pose(property.to_int()); - _update_transform_properties(tform); -} - void BoneTransformEditor::_update_transform_properties(Transform3D tform) { Basis rotation_basis = tform.get_basis(); Vector3 rotation_radians = rotation_basis.get_rotation_euler(); @@ -463,9 +443,7 @@ void Skeleton3DEditor::pose_to_rest() { ur->add_do_method(skeleton, "set_bone_pose", selected_bone, Transform3D()); ur->add_undo_method(skeleton, "set_bone_pose", selected_bone, skeleton->get_bone_pose(selected_bone)); - ur->add_do_method(skeleton, "set_bone_custom_pose", selected_bone, Transform3D()); - ur->add_undo_method(skeleton, "set_bone_custom_pose", selected_bone, skeleton->get_bone_custom_pose(selected_bone)); - ur->add_do_method(skeleton, "set_bone_rest", selected_bone, skeleton->get_bone_rest(selected_bone) * skeleton->get_bone_custom_pose(selected_bone) * skeleton->get_bone_pose(selected_bone)); + ur->add_do_method(skeleton, "set_bone_rest", selected_bone, skeleton->get_bone_rest(selected_bone) * skeleton->get_bone_pose(selected_bone)); ur->add_undo_method(skeleton, "set_bone_rest", selected_bone, skeleton->get_bone_rest(selected_bone)); ur->commit_action(); @@ -654,11 +632,9 @@ void Skeleton3DEditor::_joint_tree_selection_changed() { pose_editor->set_target(bone_path + "pose"); rest_editor->set_target(bone_path + "rest"); - custom_pose_editor->set_target(bone_path + "custom_pose"); pose_editor->set_visible(true); rest_editor->set_visible(true); - custom_pose_editor->set_visible(true); selected_bone = b_idx; } @@ -679,9 +655,6 @@ void Skeleton3DEditor::_update_properties() { if (pose_editor) { pose_editor->_update_properties(); } - if (custom_pose_editor) { - custom_pose_editor->_update_custom_pose_properties(); - } _update_gizmo_transform(); } @@ -820,12 +793,6 @@ void Skeleton3DEditor::create_editors() { rest_editor->set_visible(false); add_child(rest_editor); rest_editor->set_transform_read_only(true); - - custom_pose_editor = memnew(BoneTransformEditor(skeleton)); - custom_pose_editor->set_label(TTR("Bone Custom Pose")); - custom_pose_editor->set_visible(false); - add_child(custom_pose_editor); - custom_pose_editor->set_transform_read_only(true); } void Skeleton3DEditor::_notification(int p_what) { @@ -1289,7 +1256,6 @@ void Skeleton3DGizmoPlugin::set_subgizmo_transform(const EditorNode3DGizmo *p_gi if (parent_idx >= 0) { original_to_local = original_to_local * skeleton->get_bone_global_pose(parent_idx); } - original_to_local = original_to_local * skeleton->get_bone_rest(p_id) * skeleton->get_bone_custom_pose(p_id); Basis to_local = original_to_local.get_basis().inverse(); // Prepare transform. @@ -1518,5 +1484,5 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { } Ref<ArrayMesh> m = surface_tool->commit(); - p_gizmo->add_mesh(m, Ref<Material>(), Transform3D(), skeleton->register_skin(Ref<Skin>())); + p_gizmo->add_mesh(m, Ref<Material>(), Transform3D(), skeleton->register_skin(skeleton->create_skin_from_rest_transforms())); } diff --git a/editor/plugins/skeleton_3d_editor_plugin.h b/editor/plugins/skeleton_3d_editor_plugin.h index e2a1d9a628..2c21aab739 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.h +++ b/editor/plugins/skeleton_3d_editor_plugin.h @@ -102,13 +102,12 @@ public: void set_label(const String &p_label) { label = p_label; } void _update_properties(); - void _update_custom_pose_properties(); void _update_transform_properties(Transform3D p_transform); // Transform can be keyed, whether or not to show the button. void set_keyable(const bool p_keyable); - // When rest mode, pose and custom_pose editor are diasbled. + // When rest mode, pose editor are diasbled. void set_properties_read_only(const bool p_readonly); void set_transform_read_only(const bool p_readonly); @@ -151,7 +150,6 @@ class Skeleton3DEditor : public VBoxContainer { Tree *joint_tree = nullptr; BoneTransformEditor *rest_editor = nullptr; BoneTransformEditor *pose_editor = nullptr; - BoneTransformEditor *custom_pose_editor = nullptr; VSeparator *separator; MenuButton *skeleton_options = nullptr; |