[Bf-blender-cvs] [9467c0dcf9b] master: Fix T71924: Baking quaternion keyframes gives discontinuous values

Campbell Barton noreply at git.blender.org
Tue Nov 26 16:01:17 CET 2019


Commit: 9467c0dcf9bd0d91d40a63e885a565274323daef
Author: Campbell Barton
Date:   Wed Nov 27 01:57:14 2019 +1100
Branches: master
https://developer.blender.org/rB9467c0dcf9bd0d91d40a63e885a565274323daef

Fix T71924: Baking quaternion keyframes gives discontinuous values

===================================================================

M	release/scripts/modules/bpy_extras/anim_utils.py

===================================================================

diff --git a/release/scripts/modules/bpy_extras/anim_utils.py b/release/scripts/modules/bpy_extras/anim_utils.py
index 1ef97b24a3f..e402c9cb53c 100644
--- a/release/scripts/modules/bpy_extras/anim_utils.py
+++ b/release/scripts/modules/bpy_extras/anim_utils.py
@@ -268,8 +268,9 @@ def bake_action_iter(
                 while pbone.constraints:
                     pbone.constraints.remove(pbone.constraints[0])
 
-            # create compatible eulers
+            # Create compatible eulers, quats.
             euler_prev = None
+            quat_prev = None
 
             for (f, matrix, bbones) in pose_info:
                 pbone.matrix_basis = matrix[name].copy()
@@ -278,6 +279,14 @@ def bake_action_iter(
 
                 rotation_mode = pbone.rotation_mode
                 if rotation_mode == 'QUATERNION':
+                    if quat_prev is not None:
+                        quat = pbone.rotation_quaternion.copy()
+                        quat.make_compatible(quat_prev)
+                        pbone.rotation_quaternion = quat
+                        quat_prev = quat
+                        del quat
+                    else:
+                        quat_prev = pbone.rotation_quaternion.copy()
                     pbone.keyframe_insert("rotation_quaternion", index=-1, frame=f, group=name, options=options)
                 elif rotation_mode == 'AXIS_ANGLE':
                     pbone.keyframe_insert("rotation_axis_angle", index=-1, frame=f, group=name, options=options)
@@ -308,8 +317,9 @@ def bake_action_iter(
             while obj.constraints:
                 obj.constraints.remove(obj.constraints[0])
 
-        # create compatible eulers
+        # Create compatible eulers, quats.
         euler_prev = None
+        quat_prev = None
 
         for (f, matrix) in obj_info:
             name = "Action Bake"  # XXX: placeholder
@@ -319,6 +329,15 @@ def bake_action_iter(
 
             rotation_mode = obj.rotation_mode
             if rotation_mode == 'QUATERNION':
+                if quat_prev is not None:
+                    quat = obj.rotation_quaternion.copy()
+                    quat.make_compatible(quat_prev)
+                    obj.rotation_quaternion = quat
+                    quat_prev = quat
+                    del quat
+                    print ("quat_prev", quat_prev)
+                else:
+                    quat_prev = obj.rotation_quaternion.copy()
                 obj.keyframe_insert("rotation_quaternion", index=-1, frame=f, group=name, options=options)
             elif rotation_mode == 'AXIS_ANGLE':
                 obj.keyframe_insert("rotation_axis_angle", index=-1, frame=f, group=name, options=options)



More information about the Bf-blender-cvs mailing list