From dafc79fbb0ca814754e0f4698d9eb280cf9f8a53 Mon Sep 17 00:00:00 2001 From: Chris Foster Date: Thu, 16 Apr 2015 12:22:43 -0400 Subject: More elegant solution to the rotation aliasing issue. Also fixes Inherit Rotation issues. --- io_scene_x/export_x.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/io_scene_x/export_x.py b/io_scene_x/export_x.py index 8c675388..9c2b23be 100644 --- a/io_scene_x/export_x.py +++ b/io_scene_x/export_x.py @@ -18,7 +18,7 @@ # -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 -- cgit v1.2.3