private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node)
        {
            // Get the source pivot pre-rotation if any, so we can
            // remove it from the animation we get from Unity.
            var fbxPreRotationEuler = node.GetRotationActive()
                ? node.GetPreRotation(FbxNode.EPivotSet.eSourcePivot)
                : new FbxVector4();

            // Get the inverse of the prerotation
            var fbxPreRotationInverse = ModelExporter.EulerToQuaternion(fbxPreRotationEuler);

            fbxPreRotationInverse.Inverse();

            // Find when we have keys set.
            var keyTimes =
                (UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportSettings.BakeAnimationProperty)
                ? ModelExporter.GetSampleTimes(GetCurves(), SampleRate)
                : ModelExporter.GetKeyTimes(GetCurves());

            // Convert to the Key type.
            var keys = new Key[keyTimes.Count];
            int i    = 0;

            foreach (var seconds in keyTimes)
            {
                var fbxFinalAnimation = GetConvertedQuaternionRotation(seconds, restRotation);

                // Cancel out the pre-rotation. Order matters. FBX reads left-to-right.
                // When we run animation we will apply:
                //      pre-rotation
                //      then pre-rotation inverse
                //      then animation.
                var fbxFinalQuat = fbxPreRotationInverse * fbxFinalAnimation;

                // Store the key so we can sort them later.
                Key key = new Key();
                key.time  = FbxTime.FromSecondDouble(seconds);
                key.euler = ModelExporter.QuaternionToEuler(fbxFinalQuat);
                keys[i++] = key;
            }

            // Sort the keys by time
            System.Array.Sort(keys, (Key a, Key b) => a.time.CompareTo(b.time));

            return(keys);
        }
        protected override FbxQuaternion GetConvertedQuaternionRotation(float seconds, Quaternion restRotation)
        {
            AnimationCurve x = GetCurves()[0], y = GetCurves()[1], z = GetCurves()[2], w = GetCurves()[3];

            // The final animation, including the effect of pre-rotation.
            // If we have no curve, assume the node has the correct rotation right now.
            // We need to evaluate since we might only have keys in one of the axes.
            var fbxFinalAnimation = new FbxQuaternion(
                (x == null) ? restRotation[0] : x.Evaluate(seconds),
                (y == null) ? restRotation[1] : y.Evaluate(seconds),
                (z == null) ? restRotation[2] : z.Evaluate(seconds),
                (w == null) ? restRotation[3] : w.Evaluate(seconds));

            // convert the final animation to righthanded coords
            var finalEuler = ModelExporter.ConvertQuaternionToXYZEuler(fbxFinalAnimation);

            return(ModelExporter.EulerToQuaternion(finalEuler));
        }