[Bf-extensions-cvs] [dafc79f] master: More elegant solution to the rotation aliasing issue. Also fixes Inherit Rotation issues.

Chris Foster noreply at git.blender.org
Thu Apr 16 18:23:24 CEST 2015


Commit: dafc79fbb0ca814754e0f4698d9eb280cf9f8a53
Author: Chris Foster
Date:   Thu Apr 16 12:22:43 2015 -0400
Branches: master
https://developer.blender.org/rBAdafc79fbb0ca814754e0f4698d9eb280cf9f8a53

More elegant solution to the rotation aliasing issue.  Also fixes Inherit Rotation issues.

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

M	io_scene_x/export_x.py

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

diff --git a/io_scene_x/export_x.py b/io_scene_x/export_x.py
index 8c67538..9c2b23b 100644
--- a/io_scene_x/export_x.py
+++ b/io_scene_x/export_x.py
@@ -18,7 +18,7 @@
 
 # <pep8 compliant>
 
-from math import radians
+from math import radians, pi
 
 import bpy
 from mathutils import *
@@ -1144,19 +1144,21 @@ class ArmatureAnimationGenerator(GenericAnimationGenerator):
             for Bone, BoneAnimation in \
                 zip(ArmatureObject.pose.bones, BoneAnimations):
                 
-                Rotation = ArmatureObject.data.bones[Bone.name] \
-                    .matrix.to_quaternion() * \
-                    Bone.matrix_basis.to_quaternion()
-                
                 PoseMatrix = Matrix()
                 if Bone.parent:
                     PoseMatrix = Bone.parent.matrix.inverted()
                 PoseMatrix *= Bone.matrix
                 
+                Rotation = PoseMatrix.to_quaternion().normalized()
+                OldRotation = BoneAnimation.RotationKeys[-1] if \
+                    len(BoneAnimation.RotationKeys) else Rotation
+                
                 Scale = PoseMatrix.to_scale()
+                
                 Position = PoseMatrix.to_translation()
                 
-                BoneAnimation.RotationKeys.append(Rotation)
+                BoneAnimation.RotationKeys.append(Util.CompatibleQuaternion(
+                    Rotation, OldRotation))
                 BoneAnimation.ScaleKeys.append(Scale)
                 BoneAnimation.PositionKeys.append(Position)
         
@@ -1379,3 +1381,11 @@ class Util:
             return x.name
         
         return sorted(List, key=SortKey)
+    
+    # Make A compatible with B
+    @staticmethod
+    def CompatibleQuaternion(A, B):
+        if (A.normalized().conjugated() * B.normalized()).angle > pi:
+            return -A
+        else:
+            return A



More information about the Bf-extensions-cvs mailing list