@@ -1737,9 +1737,7 @@ public void Dispose()
1737
1737
/// </summary>
1738
1738
abstract class RotationCurve {
1739
1739
public double sampleRate ;
1740
- public AnimationCurve x ;
1741
- public AnimationCurve y ;
1742
- public AnimationCurve z ;
1740
+ public AnimationCurve [ ] m_curves ;
1743
1741
1744
1742
public struct Key {
1745
1743
public FbxTime time ;
@@ -1748,13 +1746,11 @@ public struct Key {
1748
1746
1749
1747
public RotationCurve ( ) { }
1750
1748
1751
- public virtual void SetCurve ( int i , AnimationCurve curve ) {
1752
- switch ( i ) {
1753
- case 0 : x = curve ; break ;
1754
- case 1 : y = curve ; break ;
1755
- case 2 : z = curve ; break ;
1756
- default : throw new System . IndexOutOfRangeException ( ) ;
1749
+ public void SetCurve ( int i , AnimationCurve curve ) {
1750
+ if ( i < 0 || i >= m_curves . Length ) {
1751
+ throw new System . IndexOutOfRangeException ( ) ;
1757
1752
}
1753
+ m_curves [ i ] = curve ;
1758
1754
}
1759
1755
1760
1756
protected abstract FbxQuaternion GetConvertedQuaternionRotation ( float seconds , UnityEngine . Quaternion restRotation ) ;
@@ -1771,11 +1767,10 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
1771
1767
fbxPreRotationInverse . Inverse ( ) ;
1772
1768
1773
1769
// Find when we have keys set.
1774
- var animCurves = new AnimationCurve [ ] { x , y , z } ;
1775
1770
var keyTimes =
1776
1771
( FbxExporters . Editor . ModelExporter . ExportSettings . BakeAnimation )
1777
- ? ModelExporter . GetSampleTimes ( animCurves , sampleRate )
1778
- : ModelExporter . GetKeyTimes ( animCurves ) ;
1772
+ ? ModelExporter . GetSampleTimes ( m_curves , sampleRate )
1773
+ : ModelExporter . GetKeyTimes ( m_curves ) ;
1779
1774
1780
1775
// Convert to the Key type.
1781
1776
var keys = new Key [ keyTimes . Count ] ;
@@ -1843,8 +1838,14 @@ public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxA
1843
1838
/// prerotation from animated rotation.
1844
1839
/// </summary>
1845
1840
class EulerCurve : RotationCurve {
1846
- public EulerCurve ( ) { }
1841
+ public EulerCurve ( ) { m_curves = new AnimationCurve [ 3 ] ; }
1847
1842
1843
+ /// <summary>
1844
+ /// Gets the index of the euler curve by property name.
1845
+ /// x = 0, y = 1, z = 2
1846
+ /// </summary>
1847
+ /// <returns>The index of the curve, or -1 if property doesn't map to Euler curve.</returns>
1848
+ /// <param name="uniPropertyName">Unity property name.</param>
1848
1849
public static int GetEulerIndex ( string uniPropertyName ) {
1849
1850
System . StringComparison ct = System . StringComparison . CurrentCulture ;
1850
1851
bool isEulerComponent = uniPropertyName . StartsWith ( "localEulerAnglesRaw." , ct ) ;
@@ -1862,17 +1863,19 @@ public static int GetEulerIndex(string uniPropertyName) {
1862
1863
protected override FbxQuaternion GetConvertedQuaternionRotation ( float seconds , Quaternion restRotation )
1863
1864
{
1864
1865
var eulerRest = restRotation . eulerAngles ;
1866
+ AnimationCurve x = m_curves [ 0 ] , y = m_curves [ 1 ] , z = m_curves [ 2 ] ;
1867
+
1865
1868
// The final animation, including the effect of pre-rotation.
1866
1869
// If we have no curve, assume the node has the correct rotation right now.
1867
1870
// We need to evaluate since we might only have keys in one of the axes.
1868
- var fbxFinalAnimation = Quaternion . Euler (
1871
+ var unityFinalAnimation = Quaternion . Euler (
1869
1872
( x == null ) ? eulerRest [ 0 ] : x . Evaluate ( seconds ) ,
1870
1873
( y == null ) ? eulerRest [ 1 ] : y . Evaluate ( seconds ) ,
1871
1874
( z == null ) ? eulerRest [ 2 ] : z . Evaluate ( seconds )
1872
1875
) ;
1873
1876
1874
1877
// convert the final animation to righthanded coords
1875
- var finalEuler = ModelExporter . ConvertQuaternionToXYZEuler ( fbxFinalAnimation ) ;
1878
+ var finalEuler = ModelExporter . ConvertQuaternionToXYZEuler ( unityFinalAnimation ) ;
1876
1879
1877
1880
return ModelExporter . EulerToQuaternion ( new FbxVector4 ( finalEuler ) ) ;
1878
1881
}
@@ -1883,10 +1886,15 @@ protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds,
1883
1886
/// from quaternion to euler. We use this class to help.
1884
1887
/// </summary>
1885
1888
class QuaternionCurve : RotationCurve {
1886
- public AnimationCurve w ;
1887
1889
1888
- public QuaternionCurve ( ) { }
1890
+ public QuaternionCurve ( ) { m_curves = new AnimationCurve [ 4 ] ; }
1889
1891
1892
+ /// <summary>
1893
+ /// Gets the index of the curve by property name.
1894
+ /// x = 0, y = 1, z = 2, w = 3
1895
+ /// </summary>
1896
+ /// <returns>The index of the curve, or -1 if property doesn't map to Quaternion curve.</returns>
1897
+ /// <param name="uniPropertyName">Unity property name.</param>
1890
1898
public static int GetQuaternionIndex ( string uniPropertyName ) {
1891
1899
System . StringComparison ct = System . StringComparison . CurrentCulture ;
1892
1900
bool isQuaternionComponent = false ;
@@ -1908,18 +1916,10 @@ public static int GetQuaternionIndex(string uniPropertyName) {
1908
1916
}
1909
1917
}
1910
1918
1911
- public override void SetCurve ( int i , AnimationCurve curve ) {
1912
- switch ( i ) {
1913
- case 0 : x = curve ; break ;
1914
- case 1 : y = curve ; break ;
1915
- case 2 : z = curve ; break ;
1916
- case 3 : w = curve ; break ;
1917
- default : throw new System . IndexOutOfRangeException ( ) ;
1918
- }
1919
- }
1920
-
1921
1919
protected override FbxQuaternion GetConvertedQuaternionRotation ( float seconds , Quaternion restRotation )
1922
1920
{
1921
+ AnimationCurve x = m_curves [ 0 ] , y = m_curves [ 1 ] , z = m_curves [ 2 ] , w = m_curves [ 3 ] ;
1922
+
1923
1923
// The final animation, including the effect of pre-rotation.
1924
1924
// If we have no curve, assume the node has the correct rotation right now.
1925
1925
// We need to evaluate since we might only have keys in one of the axes.
0 commit comments