Add interpolate_via_rest static func to Animation class

This commit is contained in:
Silc Lizard (Tokage) Renew
2025-06-12 05:01:00 +09:00
parent ccf414ecb4
commit 4f255fa7d7
4 changed files with 37 additions and 20 deletions

View File

@ -1425,7 +1425,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
rot[0] = post_process_key_value(a, i, rot[0], t->object_id, t->bone_idx);
a->try_rotation_track_interpolate(i, end, &rot[1]);
rot[1] = post_process_key_value(a, i, rot[1], t->object_id, t->bone_idx);
root_motion_cache.rot = (root_motion_cache.rot * Quaternion().slerp(rot[0].inverse() * rot[1], blend)).normalized();
root_motion_cache.rot = Animation::interpolate_via_rest(root_motion_cache.rot, rot[1], blend, rot[0]);
prev_time = start;
}
} else {
@ -1437,7 +1437,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
rot[0] = post_process_key_value(a, i, rot[0], t->object_id, t->bone_idx);
a->try_rotation_track_interpolate(i, start, &rot[1]);
rot[1] = post_process_key_value(a, i, rot[1], t->object_id, t->bone_idx);
root_motion_cache.rot = (root_motion_cache.rot * Quaternion().slerp(rot[0].inverse() * rot[1], blend)).normalized();
root_motion_cache.rot = Animation::interpolate_via_rest(root_motion_cache.rot, rot[1], blend, rot[0]);
prev_time = end;
}
}
@ -1448,7 +1448,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
rot[0] = post_process_key_value(a, i, rot[0], t->object_id, t->bone_idx);
a->try_rotation_track_interpolate(i, time, &rot[1]);
rot[1] = post_process_key_value(a, i, rot[1], t->object_id, t->bone_idx);
root_motion_cache.rot = (root_motion_cache.rot * Quaternion().slerp(rot[0].inverse() * rot[1], blend)).normalized();
root_motion_cache.rot = Animation::interpolate_via_rest(root_motion_cache.rot, rot[1], blend, rot[0]);
prev_time = !backward ? start : end;
}
{
@ -1458,7 +1458,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
continue;
}
rot = post_process_key_value(a, i, rot, t->object_id, t->bone_idx);
t->rot = (t->rot * Quaternion().slerp(t->init_rot.inverse() * rot, blend)).normalized();
t->rot = Animation::interpolate_via_rest(t->rot, rot, blend, t->init_rot);
}
#endif // _3D_DISABLED
} break;
@ -1604,21 +1604,8 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
// Special case for angle interpolation.
if (t->is_using_angle) {
// For blending consistency, it prevents rotation of more than 180 degrees from init_value.
// This is the same as for Quaternion blends.
float rot_a = t->value;
float rot_b = value;
float rot_init = t->init_value;
rot_a = Math::fposmod(rot_a, (float)Math::TAU);
rot_b = Math::fposmod(rot_b, (float)Math::TAU);
rot_init = Math::fposmod(rot_init, (float)Math::TAU);
if (rot_init < Math::PI) {
rot_a = rot_a > rot_init + Math::PI ? rot_a - Math::TAU : rot_a;
rot_b = rot_b > rot_init + Math::PI ? rot_b - Math::TAU : rot_b;
} else {
rot_a = rot_a < rot_init - Math::PI ? rot_a + Math::TAU : rot_a;
rot_b = rot_b < rot_init - Math::PI ? rot_b + Math::TAU : rot_b;
}
t->value = Math::fposmod(rot_a + (rot_b - rot_init) * (float)blend, (float)Math::TAU);
// This is the same with Quaternion blending.
t->value = Animation::interpolate_via_rest((double)t->value, (double)value, blend, (double)t->init_value);
} else {
value = Animation::cast_to_blendwise(value);
if (t->init_value.is_array()) {