diff --git a/source/blender/io/fbx/importer/fbx_import_anim.cc b/source/blender/io/fbx/importer/fbx_import_anim.cc index dda440b9871..75d3086f96d 100644 --- a/source/blender/io/fbx/importer/fbx_import_anim.cc +++ b/source/blender/io/fbx/importer/fbx_import_anim.cc @@ -345,6 +345,7 @@ static void create_transform_curve_data(const FbxElementMapping &mapping, } /* Evaluate transforms at all the key times. */ + math::Quaternion quat_prev = math::Quaternion::identity(); for (int64_t i = 0; i < sorted_key_times.size(); i++) { double t = sorted_key_times[i]; float tf = float(t * fps + anim_offset); @@ -362,6 +363,11 @@ static void create_transform_curve_data(const FbxElementMapping &mapping, math::Quaternion quat(xform.rotation.w, xform.rotation.x, xform.rotation.y, xform.rotation.z); switch (rot_mode) { case ROT_MODE_QUAT: + /* Ensure shortest interpolation path between consecutive quaternions. */ + if (i != 0 && math::dot(quat, quat_prev) < 0.0f) { + quat = -quat; + } + quat_prev = quat; set_curve_sample(curves[rot_index + 0], i, tf, quat.w); set_curve_sample(curves[rot_index + 1], i, tf, quat.x); set_curve_sample(curves[rot_index + 2], i, tf, quat.y); diff --git a/tests/files/io_tests/fbx/reference/ufbx_maya_dq_weights_75b.txt b/tests/files/io_tests/fbx/reference/ufbx_maya_dq_weights_75b.txt index 1b3f848918c..9bcca7caf61 100644 --- a/tests/files/io_tests/fbx/reference/ufbx_maya_dq_weights_75b.txt +++ b/tests/files/io_tests/fbx/reference/ufbx_maya_dq_weights_75b.txt @@ -119,10 +119,10 @@ - (25.000, 0.000) lh:(17.333, 0.000 AUTO_CLAMPED) rh:(32.667, 0.000 AUTO_CLAMPED) - fcu 'pose.bones["joint2"].rotation_quaternion[0]' smooth:CONT_ACCEL extra:CONSTANT keyframes:2 grp:'joint2' - (2.000, 0.728) lh:(-5.667, 0.728 AUTO_CLAMPED) rh:(9.667, 0.728 AUTO_CLAMPED) - - (25.000, 0.675) lh:(17.333, 0.675 AUTO_CLAMPED) rh:(32.667, 0.675 AUTO_CLAMPED) + - (25.000, -0.675) lh:(17.333, -0.675 AUTO_CLAMPED) rh:(32.667, -0.675 AUTO_CLAMPED) - fcu 'pose.bones["joint2"].rotation_quaternion[1]' smooth:CONT_ACCEL extra:CONSTANT keyframes:2 grp:'joint2' - (2.000, 0.685) lh:(-5.667, 0.685 AUTO_CLAMPED) rh:(9.667, 0.685 AUTO_CLAMPED) - - (25.000, -0.737) lh:(17.333, -0.737 AUTO_CLAMPED) rh:(32.667, -0.737 AUTO_CLAMPED) + - (25.000, 0.737) lh:(17.333, 0.737 AUTO_CLAMPED) rh:(32.667, 0.737 AUTO_CLAMPED) ==== Armatures: 1 - Armature 'Armature' 6 bones