@@ -26,8 +26,9 @@ public class AnimationTestDataClass
26
26
Where ( t => typeof ( Component ) . IsAssignableFrom ( t ) &&
27
27
ModelExporter . MapsToFbxObject . ContainsKey ( t ) ) . Except ( m_exceptionTypes ) ;
28
28
29
- public static string [ ] m_localRotationNames = new string [ 4 ] { "m_LocalRotation.x" , "m_LocalRotation.y" , "m_LocalRotation.z" , "m_LocalRotation.w" } ;
30
- public static string [ ] m_localTranslationNames = new string [ 3 ] { "m_LocalPosition.x" , "m_LocalPosition.y" , "m_LocalPosition.z" } ;
29
+ public static string [ ] m_quaternionRotationNames = new string [ 4 ] { "m_LocalRotation.x" , "m_LocalRotation.y" , "m_LocalRotation.z" , "m_LocalRotation.w" } ;
30
+ public static string [ ] m_eulerRotationNames = new string [ 3 ] { "localEulerAnglesRaw.x" , "localEulerAnglesRaw.y" , "localEulerAnglesRaw.z" } ;
31
+ public static string [ ] m_translationNames = new string [ 3 ] { "m_LocalPosition.x" , "m_LocalPosition.y" , "m_LocalPosition.z" } ;
31
32
32
33
public static float [ ] m_keytimes1 = new float [ 3 ] { 1f , 2f , 3f } ;
33
34
public static float [ ] m_keyFloatValues1 = new float [ 3 ] { 0f , 100f , 0f } ;
@@ -51,13 +52,13 @@ public static IEnumerable TestCases1 {
51
52
}
52
53
public static IEnumerable TestCases2 {
53
54
get {
54
- yield return new TestCaseData ( m_keytimes1 , m_keyEulerValues3 , typeof ( Transform ) , m_localRotationNames ) . Returns ( 3 ) ;
55
+ yield return new TestCaseData ( m_keytimes1 , m_keyEulerValues3 , typeof ( Transform ) , m_quaternionRotationNames ) . Returns ( 3 ) ;
55
56
}
56
57
}
57
58
// specify gimbal conditions for rotation
58
59
public static IEnumerable TestCases3 {
59
60
get {
60
- yield return new TestCaseData ( m_keytimes1 , m_keyEulerValues4 , typeof ( Transform ) , m_localRotationNames ) . Returns ( 3 ) ;
61
+ yield return new TestCaseData ( m_keytimes1 , m_keyEulerValues4 , typeof ( Transform ) , m_quaternionRotationNames ) . Returns ( 3 ) ;
61
62
}
62
63
}
63
64
// specify one of each component type
@@ -70,7 +71,7 @@ public static IEnumerable TestCases4 {
70
71
// specify continuous rotations
71
72
public static IEnumerable TestCases5 {
72
73
get {
73
- yield return new TestCaseData ( m_keytimes5 , m_keyRotValues5 . Concat ( m_keyPosValues5 ) . ToArray ( ) , typeof ( Transform ) , m_localRotationNames . Concat ( m_localTranslationNames ) . ToArray ( ) ) . Returns ( 3 ) ;
74
+ yield return new TestCaseData ( m_keytimes5 , m_keyRotValues5 . Concat ( m_keyPosValues5 ) . ToArray ( ) , typeof ( Transform ) , m_eulerRotationNames . Concat ( m_translationNames ) . ToArray ( ) ) . Returns ( 3 ) ;
74
75
}
75
76
}
76
77
}
@@ -89,7 +90,7 @@ public class FbxAnimationTest : ExporterTestBase
89
90
public override void Term ( )
90
91
{
91
92
// NOTE: comment out the next line to leave temporary FBX files on disk
92
- base . Term ( ) ;
93
+ // base.Term ();
93
94
}
94
95
95
96
protected void AnimClipTest ( AnimationClip animClipExpected , AnimationClip animClipActual )
@@ -116,8 +117,8 @@ protected void AnimCurveTest (float [] keyTimesExpected, float [] keyValuesExpec
116
117
Assert . That ( animCurveActual . length , Is . EqualTo ( numKeysExpected ) , "animcurve number of keys doesn't match" ) ;
117
118
118
119
//check imported animation against original
119
- Assert . That ( new ListMapper ( animCurveActual . keys ) . Property ( "time" ) , Is . EqualTo ( keyTimesExpected ) , string . Format ( "{0} key time doesn't match" , message ) ) ;
120
- Assert . That ( new ListMapper ( animCurveActual . keys ) . Property ( "value" ) , Is . EqualTo ( keyValuesExpected ) , string . Format ( "{0} key value doesn't match" , message ) ) ;
120
+ Assert . That ( List . Map ( animCurveActual . keys ) . Property ( "time" ) , Is . EqualTo ( keyTimesExpected ) , string . Format ( "{0} key time doesn't match" , message ) ) ;
121
+ Assert . That ( List . Map ( animCurveActual . keys ) . Property ( "value" ) , Is . EqualTo ( keyValuesExpected ) . Within ( 0.000005f ) , string . Format ( "{0} key value doesn't match" , message ) ) ;
121
122
122
123
return ;
123
124
}
@@ -186,32 +187,66 @@ public override int FindComponent (string name)
186
187
187
188
public class TransformKeyData : KeyData
188
189
{
190
+ public const int kNumQuatRotFields = 4 ;
191
+ public const int kNumEulerRotFields = 3 ;
192
+ public bool useQuaternion = false ;
193
+
194
+ public int NumRotationFields { get { return ( ( useQuaternion ) ? kNumQuatRotFields : kNumEulerRotFields ) ; } }
195
+
189
196
public string [ ] propertyNames ;
190
- public Vector3 [ ] keyValues ; // NOTE: first half is Quaternions and second half is Translation
191
- public bool IsRotation ( int id ) { return id < 4 ; }
197
+ public Vector3 [ ] keyValues ; // NOTE: first half is Euler Rotation and second half is Translation
198
+ private Quaternion [ ] keyQuatValues ;
199
+
200
+ public bool IsRotation ( int id ) { return id < NumRotationFields ; }
192
201
193
202
public override int NumKeys { get { return Mathf . Min ( keyTimesInSeconds . Length , keyValues . Length / 2 ) ; } }
194
203
public override int NumComponents { get { return propertyNames . Length ; } }
195
204
public override float [ ] GetKeyValues ( int id )
196
205
{
206
+ if ( ! useQuaternion ) return GetAltKeyValues ( id ) ;
207
+
208
+ // compute continous rotations
209
+ if ( keyQuatValues == null )
210
+ {
211
+ keyQuatValues = new Quaternion [ NumKeys ] ;
212
+ Quaternion currQuat = new Quaternion ( ) ;
213
+
214
+ for ( int idx = 0 ; idx < NumKeys ; idx ++ )
215
+ {
216
+ if ( idx == 0 )
217
+ {
218
+ keyQuatValues [ idx ] = Quaternion . Euler ( keyValues [ idx ] ) ;
219
+ currQuat = keyQuatValues [ idx ] ;
220
+ }
221
+ else
222
+ {
223
+ Vector3 deltaRot = keyValues [ idx ] - keyValues [ idx - 1 ] ;
224
+ currQuat *= Quaternion . Euler ( deltaRot ) ;
225
+ keyQuatValues [ idx ] = currQuat ;
226
+ }
227
+ Debug . Log ( string . Format ( "{0} rot[{1},{2},{3}] quat[{4},{5},{6},{7}]" , idx ,
228
+ keyValues [ idx ] [ 0 ] , keyValues [ idx ] [ 1 ] , keyValues [ idx ] [ 2 ] ,
229
+ keyQuatValues [ idx ] [ 0 ] , keyQuatValues [ idx ] [ 1 ] , keyQuatValues [ idx ] [ 2 ] , keyQuatValues [ idx ] [ 3 ]
230
+ ) ) ;
231
+ }
232
+ }
233
+
197
234
float [ ] result = new float [ NumKeys ] ;
198
- bool isRot = IsRotation ( id ) ;
199
235
200
236
for ( int idx = 0 ; idx < NumKeys ; idx ++ )
201
237
{
202
- result [ idx ] = ( isRot ) ? Quaternion . Euler ( keyValues [ idx ] ) [ id ] : keyValues [ NumKeys + idx ] [ id - 4 ] ;
238
+ result [ idx ] = IsRotation ( id ) ? keyQuatValues [ idx ] [ id ] : keyValues [ NumKeys + idx ] [ id - NumRotationFields ] ;
203
239
}
204
240
205
241
return result ;
206
242
}
207
243
public override float [ ] GetAltKeyValues ( int id )
208
244
{
209
245
float [ ] result = new float [ NumKeys ] ;
210
- bool isRot = IsRotation ( id ) ;
211
246
212
247
for ( int idx = 0 ; idx < NumKeys ; idx ++ )
213
248
{
214
- result [ idx ] = ( isRot ) ? keyValues [ idx ] [ id ] : keyValues [ NumKeys + idx ] [ id - 4 ] ;
249
+ result [ idx ] = IsRotation ( id ) ? keyValues [ idx ] [ id ] : keyValues [ NumKeys + idx ] [ id - NumRotationFields ] ;
215
250
}
216
251
217
252
return result ;
0 commit comments