@@ -79,7 +79,7 @@ public override void Term ()
79
79
base . Term ( ) ;
80
80
}
81
81
82
- protected void AnimClipTest ( AnimationClip animClipExpected , AnimationClip animClipActual )
82
+ protected void AnimClipPropertyTest ( AnimationClip animClipExpected , AnimationClip animClipActual )
83
83
{
84
84
#if UNITY_EDITOR_WIN
85
85
// TODO: figure out why we get __preview__ on Windows
@@ -109,6 +109,21 @@ protected void AnimCurveTest (float [] keyTimesExpected, float [] keyValuesExpec
109
109
return ;
110
110
}
111
111
112
+ private void AnimCurveTest ( AnimationCurve animCurveImported , AnimationCurve animCurveActual , string message ) {
113
+ // TODO : Uni-34492 number of keys don't match
114
+ //Assert.That (animCurveActual.length, Is.EqualTo (animCurveImported.length), "animcurve number of keys doesn't match");
115
+
116
+ var actualTimeKeys = new ListMapper ( animCurveActual . keys ) . Property ( "time" ) ;
117
+ var actualValueKeys = new ListMapper ( animCurveActual . keys ) . Property ( "value" ) ;
118
+
119
+ var importedTimeKeys = new ListMapper ( animCurveImported . keys ) . Property ( "time" ) ;
120
+ var importedValueKeys = new ListMapper ( animCurveImported . keys ) . Property ( "value" ) ;
121
+
122
+ //check imported animation against original
123
+ Assert . That ( actualTimeKeys , Is . EqualTo ( importedTimeKeys ) , string . Format ( "{0} key time doesn't match" , message ) ) ;
124
+ Assert . That ( actualValueKeys , Is . EqualTo ( importedValueKeys ) , string . Format ( "{0} key value doesn't match" , message ) ) ;
125
+ }
126
+
112
127
public class KeyData
113
128
{
114
129
public float [ ] keyTimesInSeconds ;
@@ -234,23 +249,9 @@ public int AnimTest (KeyData keyData, string testName)
234
249
}
235
250
236
251
//acquire imported object from exported file
237
- Object [ ] goAssetImported = AssetDatabase . LoadAllAssetsAtPath ( path ) ;
238
- Assert . That ( goAssetImported , Is . Not . Null ) ;
239
-
240
- // TODO : configure object so that it imports w Legacy Animation
241
-
242
- AnimationClip animClipImported = null ;
243
- foreach ( Object o in goAssetImported ) {
244
- animClipImported = o as AnimationClip ;
245
- if ( animClipImported ) break ;
246
- }
247
- Assert . That ( animClipImported , Is . Not . Null , "expected imported clip" ) ;
248
-
249
- // TODO : configure import settings so we don't need to force legacy
250
- animClipImported . legacy = true ;
252
+ AnimationClip animClipImported = GetClipFromFbx ( path ) ;
251
253
252
- // check clip properties match
253
- AnimClipTest ( animClipOriginal , animClipImported ) ;
254
+ AnimClipPropertyTest ( animClipOriginal , animClipImported ) ;
254
255
255
256
// check animCurve & keys
256
257
int result = 0 ;
@@ -279,6 +280,82 @@ public int AnimTest (KeyData keyData, string testName)
279
280
return result ;
280
281
}
281
282
283
+ private AnimationClip GetClipFromFbx ( string path ) {
284
+ //acquire imported object from exported file
285
+ Object [ ] goAssetImported = AssetDatabase . LoadAllAssetsAtPath ( path ) ;
286
+ Assert . That ( goAssetImported , Is . Not . Null ) ;
287
+
288
+ // TODO : configure object so that it imports w Legacy Animation
289
+
290
+ AnimationClip animClipImported = null ;
291
+ foreach ( Object o in goAssetImported ) {
292
+ animClipImported = o as AnimationClip ;
293
+ if ( animClipImported ) break ;
294
+ }
295
+ Assert . That ( animClipImported , Is . Not . Null , "expected imported clip" ) ;
296
+
297
+ // TODO : configure import settings so we don't need to force legacy
298
+ animClipImported . legacy = true ;
299
+
300
+ return animClipImported ;
301
+ }
302
+
303
+ [ Test ]
304
+ public void SkinnedMeshAnimTest ( )
305
+ {
306
+ var fbxPath = "FbxExporters/Editor/UnitTests/Models/DefaultMale/Male_DyingHitFromBack_Blend_T3_Cut01_James.fbx" ;
307
+
308
+ // add fbx to scene
309
+ GameObject originalFbxObj = AssetDatabase . LoadMainAssetAtPath ( "Assets/" + fbxPath ) as GameObject ;
310
+ Assert . IsNotNull ( originalFbxObj ) ;
311
+ GameObject originalGO = GameObject . Instantiate ( originalFbxObj ) ;
312
+ Assert . IsTrue ( originalGO ) ;
313
+
314
+ // get clip
315
+ AnimationClip animClipOriginal = originalGO . GetComponentInChildren < Animation > ( ) . clip ;
316
+ Assert . That ( animClipOriginal , Is . Not . Null ) ;
317
+
318
+ // export fbx
319
+ // get GameObject
320
+ string filename = GetRandomFbxFilePath ( ) ;
321
+ var exportedFilePath = ModelExporter . ExportObject ( filename , originalGO ) ;
322
+ Assert . That ( exportedFilePath , Is . EqualTo ( filename ) ) ;
323
+
324
+ // TODO: Uni-34492 change importer settings of (newly exported model)
325
+ // so that it's not resampled and it is legacy animation
326
+ {
327
+ ModelImporter modelImporter = AssetImporter . GetAtPath ( filename ) as ModelImporter ;
328
+ modelImporter . resampleCurves = false ;
329
+ AssetDatabase . ImportAsset ( filename ) ;
330
+ modelImporter . animationType = ModelImporterAnimationType . Legacy ;
331
+ AssetDatabase . ImportAsset ( filename ) ;
332
+ }
333
+
334
+ var animClipImported = GetClipFromFbx ( filename ) ;
335
+
336
+ // check clip properties match
337
+ AnimClipPropertyTest ( animClipOriginal , animClipImported ) ;
338
+
339
+ var result = 0 ;
340
+ foreach ( EditorCurveBinding curveBinding in AnimationUtility . GetCurveBindings ( animClipOriginal ) ) {
341
+ foreach ( EditorCurveBinding impCurveBinding in AnimationUtility . GetCurveBindings ( animClipImported ) ) {
342
+
343
+ // only compare if the path and property names match
344
+ if ( curveBinding . path != impCurveBinding . path || curveBinding . propertyName != impCurveBinding . propertyName ) {
345
+ continue ;
346
+ }
347
+
348
+ AnimationCurve animCurveOrig = AnimationUtility . GetEditorCurve ( animClipOriginal , curveBinding ) ;
349
+ Assert . That ( animCurveOrig , Is . Not . Null ) ;
350
+
351
+ AnimationCurve animCurveImported = AnimationUtility . GetEditorCurve ( animClipImported , impCurveBinding ) ;
352
+ Assert . That ( animCurveImported , Is . Not . Null ) ;
353
+
354
+ AnimCurveTest ( animCurveImported , animCurveOrig , curveBinding . propertyName ) ;
355
+ }
356
+ }
357
+ }
358
+
282
359
[ Test , TestCaseSource ( typeof ( AnimationTestDataClass ) , "TestCases1" ) ]
283
360
public int SimplePropertyAnimTest ( float [ ] keyTimesInSeconds , float [ ] keyValues , System . Type componentType , string componentName )
284
361
{
0 commit comments