diff options
author | Chris Foster <cdbfoster@gmail.com> | 2015-04-16 19:22:43 +0300 |
---|---|---|
committer | Chris Foster <cdbfoster@gmail.com> | 2015-04-16 19:22:43 +0300 |
commit | dafc79fbb0ca814754e0f4698d9eb280cf9f8a53 (patch) | |
tree | e63e64a61e2c9f0c18280d911442bb575f4943e1 | |
parent | d0628b77f6000e73a86bb61abe02d73df277b664 (diff) |
More elegant solution to the rotation aliasing issue. Also fixes Inherit Rotation issues.
-rw-r--r-- | io_scene_x/export_x.py | 22 |
1 files 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 @@ # <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 |