summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-03-25 08:25:44 +0100
committerGitHub <noreply@github.com>2020-03-25 08:25:44 +0100
commit5fede4a81c67961c6fb2309b9b0ceb753d143566 (patch)
tree00ccc91077555d4286a42e6f88fa1bed851dc0f5 /scene
parent00e4f88e416f850dfc93d3e0a78e5399d08c099a (diff)
parent277696d6c50eba68ca11cf3c0988be0213e5c65d (diff)
Merge pull request #37272 from AndreaCatania/fix_ik_rot
Fixed IK rotation issue
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/skeleton.cpp8
-rw-r--r--scene/3d/skeleton.h1
-rw-r--r--scene/animation/skeleton_ik.cpp7
3 files changed, 14 insertions, 2 deletions
diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp
index b2252bcb04..8e954ddc80 100644
--- a/scene/3d/skeleton.cpp
+++ b/scene/3d/skeleton.cpp
@@ -396,6 +396,13 @@ void Skeleton::_notification(int p_what) {
}
}
+void Skeleton::clear_bones_global_pose_override() {
+ for (int i = 0; i < bones.size(); i += 1) {
+ bones.write[i].global_pose_override_amount = 0;
+ }
+ _make_dirty();
+}
+
void Skeleton::set_bone_global_pose_override(int p_bone, const Transform &p_pose, float p_amount, bool p_persistent) {
ERR_FAIL_INDEX(p_bone, bones.size());
@@ -909,6 +916,7 @@ void Skeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bone_pose", "bone_idx"), &Skeleton::get_bone_pose);
ClassDB::bind_method(D_METHOD("set_bone_pose", "bone_idx", "pose"), &Skeleton::set_bone_pose);
+ ClassDB::bind_method(D_METHOD("clear_bones_global_pose_override"), &Skeleton::clear_bones_global_pose_override);
ClassDB::bind_method(D_METHOD("set_bone_global_pose_override", "bone_idx", "pose", "amount", "persistent"), &Skeleton::set_bone_global_pose_override, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_bone_global_pose", "bone_idx"), &Skeleton::get_bone_global_pose);
diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h
index 76fd96f30a..11fc9fff2e 100644
--- a/scene/3d/skeleton.h
+++ b/scene/3d/skeleton.h
@@ -178,6 +178,7 @@ public:
Transform get_bone_rest(int p_bone) const;
Transform get_bone_global_pose(int p_bone) const;
+ void clear_bones_global_pose_override();
void set_bone_global_pose_override(int p_bone, const Transform &p_pose, float p_amount, bool p_persistent = false);
void set_bone_enabled(int p_bone, bool p_enabled);
diff --git a/scene/animation/skeleton_ik.cpp b/scene/animation/skeleton_ik.cpp
index 5cdb38b5c2..5800b41ae6 100644
--- a/scene/animation/skeleton_ik.cpp
+++ b/scene/animation/skeleton_ik.cpp
@@ -144,8 +144,9 @@ void FabrikInverseKinematic::update_chain(const Skeleton *p_sk, ChainItem *p_cha
p_chain_item->initial_transform = p_sk->get_bone_global_pose(p_chain_item->bone);
p_chain_item->current_pos = p_chain_item->initial_transform.origin;
- for (int i = p_chain_item->children.size() - 1; 0 <= i; --i) {
- update_chain(p_sk, &p_chain_item->children.write[i]);
+ ChainItem *items = p_chain_item->children.ptrw();
+ for (int i = 0; i < p_chain_item->children.size(); i += 1) {
+ update_chain(p_sk, items + i);
}
}
@@ -286,6 +287,8 @@ void FabrikInverseKinematic::solve(Task *p_task, real_t blending_delta, bool ove
return; // Skip solving
}
+ p_task->skeleton->clear_bones_global_pose_override();
+
make_goal(p_task, p_task->skeleton->get_global_transform().affine_inverse().scaled(p_task->skeleton->get_global_transform().get_basis().get_scale()), blending_delta);
update_chain(p_task->skeleton, &p_task->chain.chain_root);