Fixed IK rotation issue
This commit is contained in:
parent
c450d4d3bb
commit
277696d6c5
4 changed files with 15 additions and 6 deletions
|
@ -44,10 +44,7 @@ void SkeletonIKEditorPlugin::_play() {
|
||||||
skeleton_ik->start();
|
skeleton_ik->start();
|
||||||
} else {
|
} else {
|
||||||
skeleton_ik->stop();
|
skeleton_ik->stop();
|
||||||
|
skeleton_ik->get_parent_skeleton()->clear_bones_global_pose_override();
|
||||||
for (int i = 0; i < skeleton_ik->get_parent_skeleton()->get_bone_count(); ++i) {
|
|
||||||
skeleton_ik->get_parent_skeleton()->set_bone_global_pose_override(i, Transform(), 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
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());
|
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("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("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("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);
|
ClassDB::bind_method(D_METHOD("get_bone_global_pose", "bone_idx"), &Skeleton::get_bone_global_pose);
|
||||||
|
|
||||||
|
|
|
@ -178,6 +178,7 @@ public:
|
||||||
Transform get_bone_rest(int p_bone) const;
|
Transform get_bone_rest(int p_bone) const;
|
||||||
Transform get_bone_global_pose(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_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);
|
void set_bone_enabled(int p_bone, bool p_enabled);
|
||||||
|
|
|
@ -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->initial_transform = p_sk->get_bone_global_pose(p_chain_item->bone);
|
||||||
p_chain_item->current_pos = p_chain_item->initial_transform.origin;
|
p_chain_item->current_pos = p_chain_item->initial_transform.origin;
|
||||||
|
|
||||||
for (int i = p_chain_item->children.size() - 1; 0 <= i; --i) {
|
ChainItem *items = p_chain_item->children.ptrw();
|
||||||
update_chain(p_sk, &p_chain_item->children.write[i]);
|
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
|
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);
|
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);
|
update_chain(p_task->skeleton, &p_task->chain.chain_root);
|
||||||
|
|
Loading…
Reference in a new issue