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.EulerToQuaternionXYZ(fbxPreRotationEuler); fbxPreRotationInverse.Inverse(); // Find when we have keys set. var keyTimes = ModelExporter.GetSampleTimes(GetCurves(), SampleRate); // 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; var finalUnityQuat = new Quaternion((float)fbxFinalQuat.X, (float)fbxFinalQuat.Y, (float)fbxFinalQuat.Z, (float)fbxFinalQuat.W); // Store the key so we can sort them later. Key key = new Key(); key.time = FbxTime.FromSecondDouble(seconds); key.euler = ModelExporter.ConvertToFbxVector4(finalUnityQuat.eulerAngles); keys[i++] = key; } // Sort the keys by time System.Array.Sort(keys, (Key a, Key b) => a.time.CompareTo(b.time)); return(keys); }