@@ -1757,7 +1757,7 @@ public virtual void SetCurve(int i, AnimationCurve curve) {
1757
1757
}
1758
1758
}
1759
1759
1760
- protected abstract FbxVector4 GetFinalEulerRotation ( float seconds , UnityEngine . Quaternion restRotation , FbxQuaternion preRotationInverse ) ;
1760
+ protected abstract FbxQuaternion GetConvertedQuaternionRotation ( float seconds , UnityEngine . Quaternion restRotation ) ;
1761
1761
1762
1762
private Key [ ] ComputeKeys ( UnityEngine . Quaternion restRotation , FbxNode node ) {
1763
1763
// Get the source pivot pre-rotation if any, so we can
@@ -1781,10 +1781,19 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
1781
1781
var keys = new Key [ keyTimes . Count ] ;
1782
1782
int i = 0 ;
1783
1783
foreach ( var seconds in keyTimes ) {
1784
+ var fbxFinalAnimation = GetConvertedQuaternionRotation ( seconds , restRotation ) ;
1785
+
1786
+ // Cancel out the pre-rotation. Order matters. FBX reads left-to-right.
1787
+ // When we run animation we will apply:
1788
+ // pre-rotation
1789
+ // then pre-rotation inverse
1790
+ // then animation.
1791
+ var fbxFinalQuat = fbxPreRotationInverse * fbxFinalAnimation ;
1792
+
1784
1793
// Store the key so we can sort them later.
1785
1794
Key key ;
1786
1795
key . time = FbxTime . FromSecondDouble ( seconds ) ;
1787
- key . euler = GetFinalEulerRotation ( seconds , restRotation , fbxPreRotationInverse ) ;
1796
+ key . euler = ModelExporter . QuaternionToEuler ( fbxFinalQuat ) ;
1788
1797
keys [ i ++ ] = key ;
1789
1798
}
1790
1799
@@ -1850,7 +1859,7 @@ public static int GetEulerIndex(string uniPropertyName) {
1850
1859
}
1851
1860
}
1852
1861
1853
- protected override FbxVector4 GetFinalEulerRotation ( float seconds , Quaternion restRotation , FbxQuaternion preRotationInverse )
1862
+ protected override FbxQuaternion GetConvertedQuaternionRotation ( float seconds , Quaternion restRotation )
1854
1863
{
1855
1864
var eulerRest = restRotation . eulerAngles ;
1856
1865
// The final animation, including the effect of pre-rotation.
@@ -1865,17 +1874,7 @@ protected override FbxVector4 GetFinalEulerRotation (float seconds, Quaternion r
1865
1874
// convert the final animation to righthanded coords
1866
1875
var finalEuler = ModelExporter . ConvertQuaternionToXYZEuler ( fbxFinalAnimation ) ;
1867
1876
1868
- // convert it back to a quaternion for multiplication
1869
- var quat = ModelExporter . EulerToQuaternion ( new FbxVector4 ( finalEuler ) ) ;
1870
-
1871
- // Cancel out the pre-rotation. Order matters. FBX reads left-to-right.
1872
- // When we run animation we will apply:
1873
- // pre-rotation
1874
- // then pre-rotation inverse
1875
- // then animation.
1876
- var fbxFinalQuat = preRotationInverse * quat ;
1877
-
1878
- return ModelExporter . QuaternionToEuler ( fbxFinalQuat ) ;
1877
+ return ModelExporter . EulerToQuaternion ( new FbxVector4 ( finalEuler ) ) ;
1879
1878
}
1880
1879
}
1881
1880
@@ -1919,7 +1918,7 @@ public override void SetCurve(int i, AnimationCurve curve) {
1919
1918
}
1920
1919
}
1921
1920
1922
- protected override FbxVector4 GetFinalEulerRotation ( float seconds , Quaternion restRotation , FbxQuaternion preRotationInverse )
1921
+ protected override FbxQuaternion GetConvertedQuaternionRotation ( float seconds , Quaternion restRotation )
1923
1922
{
1924
1923
// The final animation, including the effect of pre-rotation.
1925
1924
// If we have no curve, assume the node has the correct rotation right now.
@@ -1933,17 +1932,7 @@ protected override FbxVector4 GetFinalEulerRotation (float seconds, Quaternion r
1933
1932
// convert the final animation to righthanded coords
1934
1933
var finalEuler = ModelExporter . ConvertQuaternionToXYZEuler ( fbxFinalAnimation ) ;
1935
1934
1936
- // convert it back to a quaternion for multiplication
1937
- fbxFinalAnimation = ModelExporter . EulerToQuaternion ( finalEuler ) ;
1938
-
1939
- // Cancel out the pre-rotation. Order matters. FBX reads left-to-right.
1940
- // When we run animation we will apply:
1941
- // pre-rotation
1942
- // then pre-rotation inverse
1943
- // then animation.
1944
- var fbxFinalQuat = preRotationInverse * fbxFinalAnimation ;
1945
-
1946
- return ModelExporter . QuaternionToEuler ( fbxFinalQuat ) ;
1935
+ return ModelExporter . EulerToQuaternion ( finalEuler ) ;
1947
1936
}
1948
1937
}
1949
1938
0 commit comments