@@ -1406,7 +1406,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
14061406 rot[0 ] = post_process_key_value (a, i, rot[0 ], t->object_id , t->bone_idx );
14071407 a->try_rotation_track_interpolate (i, end, &rot[1 ]);
14081408 rot[1 ] = post_process_key_value (a, i, rot[1 ], t->object_id , t->bone_idx );
1409- root_motion_cache.rot = (root_motion_cache.rot * Quaternion (). slerp ( rot[0 ]. inverse () * rot[1 ], blend)). normalized ( );
1409+ root_motion_cache.rot = Animation::slerp_with_rest (root_motion_cache.rot , rot[1 ], blend, rot[0 ] );
14101410 prev_time = start;
14111411 }
14121412 } else {
@@ -1418,7 +1418,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
14181418 rot[0 ] = post_process_key_value (a, i, rot[0 ], t->object_id , t->bone_idx );
14191419 a->try_rotation_track_interpolate (i, start, &rot[1 ]);
14201420 rot[1 ] = post_process_key_value (a, i, rot[1 ], t->object_id , t->bone_idx );
1421- root_motion_cache.rot = (root_motion_cache.rot * Quaternion (). slerp ( rot[0 ]. inverse () * rot[1 ], blend)). normalized ( );
1421+ root_motion_cache.rot = Animation::slerp_with_rest (root_motion_cache.rot , rot[1 ], blend, rot[0 ] );
14221422 prev_time = end;
14231423 }
14241424 }
@@ -1429,7 +1429,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
14291429 rot[0 ] = post_process_key_value (a, i, rot[0 ], t->object_id , t->bone_idx );
14301430 a->try_rotation_track_interpolate (i, time, &rot[1 ]);
14311431 rot[1 ] = post_process_key_value (a, i, rot[1 ], t->object_id , t->bone_idx );
1432- root_motion_cache.rot = (root_motion_cache.rot * Quaternion (). slerp ( rot[0 ]. inverse () * rot[1 ], blend)). normalized ( );
1432+ root_motion_cache.rot = Animation::slerp_with_rest (root_motion_cache.rot , rot[1 ], blend, rot[0 ] );
14331433 prev_time = !backward ? start : end;
14341434 }
14351435 {
@@ -1439,7 +1439,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
14391439 continue ;
14401440 }
14411441 rot = post_process_key_value (a, i, rot, t->object_id , t->bone_idx );
1442- t->rot = (t->rot * Quaternion (). slerp ( t->init_rot . inverse () * rot, blend)). normalized ( );
1442+ t->rot = Animation::slerp_with_rest (t->rot , rot, blend, t->init_rot );
14431443 }
14441444#endif // _3D_DISABLED
14451445 } break ;
@@ -1585,21 +1585,8 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
15851585 // Special case for angle interpolation.
15861586 if (t->is_using_angle ) {
15871587 // For blending consistency, it prevents rotation of more than 180 degrees from init_value.
1588- // This is the same as for Quaternion blends.
1589- float rot_a = t->value ;
1590- float rot_b = value;
1591- float rot_init = t->init_value ;
1592- rot_a = Math::fposmod (rot_a, (float )Math::TAU);
1593- rot_b = Math::fposmod (rot_b, (float )Math::TAU);
1594- rot_init = Math::fposmod (rot_init, (float )Math::TAU);
1595- if (rot_init < Math::PI) {
1596- rot_a = rot_a > rot_init + Math::PI ? rot_a - Math::TAU : rot_a;
1597- rot_b = rot_b > rot_init + Math::PI ? rot_b - Math::TAU : rot_b;
1598- } else {
1599- rot_a = rot_a < rot_init - Math::PI ? rot_a + Math::TAU : rot_a;
1600- rot_b = rot_b < rot_init - Math::PI ? rot_b + Math::TAU : rot_b;
1601- }
1602- t->value = Math::fposmod (rot_a + (rot_b - rot_init) * (float )blend, (float )Math::TAU);
1588+ // This is the same with Quaternion blending.
1589+ t->value = Animation::slerp_with_rest ((double )t->value , (double )value, blend, (double )t->init_value );
16031590 } else {
16041591 value = Animation::cast_to_blendwise (value);
16051592 if (t->init_value .is_array ()) {
0 commit comments