1
- using UnityEngine ;
1
+ using UnityEngine ;
2
2
using UnityEditor ;
3
3
using NUnit . Framework ;
4
4
using System . Collections ;
@@ -84,6 +84,12 @@ public static IEnumerable TestCases5 {
84
84
// yield return new TestCaseData (RotationInterpolation.kQuaternion /*use quaternion values*/, m_keytimes5, m_keyPosValues5, m_keyRotValues5).Returns (3);
85
85
}
86
86
}
87
+
88
+ public static IEnumerable SkinnedMeshTestCases {
89
+ get {
90
+ yield return "Models/DefaultMale/Male_DyingHitFromBack_Blend_T3_Cut01_James.fbx" ;
91
+ }
92
+ }
87
93
}
88
94
89
95
[ TestFixture ]
@@ -103,7 +109,7 @@ public override void Term ()
103
109
base . Term ( ) ;
104
110
}
105
111
106
- protected void AnimClipTest ( AnimationClip animClipExpected , AnimationClip animClipActual )
112
+ protected void AnimClipPropertyTest ( AnimationClip animClipExpected , AnimationClip animClipActual )
107
113
{
108
114
#if UNITY_EDITOR_WIN
109
115
// TODO: figure out why we get __preview__ on Windows
@@ -135,6 +141,21 @@ protected void AnimCurveTest (float [] keyTimesExpected, float [] keyValuesExpec
135
141
return ;
136
142
}
137
143
144
+ private void AnimCurveTest ( AnimationCurve animCurveImported , AnimationCurve animCurveActual , string message ) {
145
+ // TODO : Uni-34492 number of keys don't match
146
+ //Assert.That (animCurveActual.length, Is.EqualTo (animCurveImported.length), "animcurve number of keys doesn't match");
147
+
148
+ var actualTimeKeys = new ListMapper ( animCurveActual . keys ) . Property ( "time" ) ;
149
+ var actualValueKeys = new ListMapper ( animCurveActual . keys ) . Property ( "value" ) ;
150
+
151
+ var importedTimeKeys = new ListMapper ( animCurveImported . keys ) . Property ( "time" ) ;
152
+ var importedValueKeys = new ListMapper ( animCurveImported . keys ) . Property ( "value" ) ;
153
+
154
+ //check imported animation against original
155
+ Assert . That ( actualTimeKeys , Is . EqualTo ( importedTimeKeys ) , string . Format ( "{0} key time doesn't match" , message ) ) ;
156
+ Assert . That ( actualValueKeys , Is . EqualTo ( importedValueKeys ) , string . Format ( "{0} key value doesn't match" , message ) ) ;
157
+ }
158
+
138
159
public class KeyData
139
160
{
140
161
public float [ ] keyTimesInSeconds ;
@@ -357,23 +378,9 @@ public int AnimTest (KeyData keyData, string testName)
357
378
}
358
379
359
380
//acquire imported object from exported file
360
- Object [ ] goAssetImported = AssetDatabase . LoadAllAssetsAtPath ( path ) ;
361
- Assert . That ( goAssetImported , Is . Not . Null ) ;
362
-
363
- // TODO : configure object so that it imports w Legacy Animation
364
-
365
- AnimationClip animClipImported = null ;
366
- foreach ( Object o in goAssetImported ) {
367
- animClipImported = o as AnimationClip ;
368
- if ( animClipImported ) break ;
369
- }
370
- Assert . That ( animClipImported , Is . Not . Null , "expected imported clip" ) ;
381
+ AnimationClip animClipImported = GetClipFromFbx ( path ) ;
371
382
372
- // TODO : configure import settings so we don't need to force legacy
373
- animClipImported . legacy = true ;
374
-
375
- // check clip properties match
376
- AnimClipTest ( animClipOriginal , animClipImported ) ;
383
+ AnimClipPropertyTest ( animClipOriginal , animClipImported ) ;
377
384
378
385
// check animCurve & keys
379
386
int result = 0 ;
@@ -402,6 +409,83 @@ public int AnimTest (KeyData keyData, string testName)
402
409
return result ;
403
410
}
404
411
412
+ private AnimationClip GetClipFromFbx ( string path ) {
413
+ //acquire imported object from exported file
414
+ Object [ ] goAssetImported = AssetDatabase . LoadAllAssetsAtPath ( path ) ;
415
+ Assert . That ( goAssetImported , Is . Not . Null ) ;
416
+
417
+ // TODO : configure object so that it imports w Legacy Animation
418
+
419
+ AnimationClip animClipImported = null ;
420
+ foreach ( Object o in goAssetImported ) {
421
+ animClipImported = o as AnimationClip ;
422
+ if ( animClipImported ) break ;
423
+ }
424
+ Assert . That ( animClipImported , Is . Not . Null , "expected imported clip" ) ;
425
+
426
+ // TODO : configure import settings so we don't need to force legacy
427
+ animClipImported . legacy = true ;
428
+
429
+ return animClipImported ;
430
+ }
431
+
432
+ [ Ignore ( "Uni-34804 gimbal conditions, and Uni-34492 number of keys don't match" ) ]
433
+ [ Test , TestCaseSource ( typeof ( AnimationTestDataClass ) , "SkinnedMeshTestCases" ) ]
434
+ public void LegacySkinnedMeshAnimTest ( string fbxPath )
435
+ {
436
+ fbxPath = FindPathInUnitTests ( fbxPath ) ;
437
+ Assert . That ( fbxPath , Is . Not . Null ) ;
438
+
439
+ // add fbx to scene
440
+ GameObject originalFbxObj = AssetDatabase . LoadMainAssetAtPath ( "Assets/" + fbxPath ) as GameObject ;
441
+ Assert . IsNotNull ( originalFbxObj ) ;
442
+ GameObject originalGO = GameObject . Instantiate ( originalFbxObj ) ;
443
+ Assert . IsTrue ( originalGO ) ;
444
+
445
+ // get clip
446
+ AnimationClip animClipOriginal = originalGO . GetComponentInChildren < Animation > ( ) . clip ;
447
+ Assert . That ( animClipOriginal , Is . Not . Null ) ;
448
+
449
+ // export fbx
450
+ // get GameObject
451
+ string filename = GetRandomFbxFilePath ( ) ;
452
+ var exportedFilePath = ModelExporter . ExportObject ( filename , originalGO ) ;
453
+ Assert . That ( exportedFilePath , Is . EqualTo ( filename ) ) ;
454
+
455
+ // TODO: Uni-34492 change importer settings of (newly exported model)
456
+ // so that it's not resampled and it is legacy animation
457
+ {
458
+ ModelImporter modelImporter = AssetImporter . GetAtPath ( filename ) as ModelImporter ;
459
+ modelImporter . resampleCurves = false ;
460
+ AssetDatabase . ImportAsset ( filename ) ;
461
+ modelImporter . animationType = ModelImporterAnimationType . Legacy ;
462
+ AssetDatabase . ImportAsset ( filename ) ;
463
+ }
464
+
465
+ var animClipImported = GetClipFromFbx ( filename ) ;
466
+
467
+ // check clip properties match
468
+ AnimClipPropertyTest ( animClipOriginal , animClipImported ) ;
469
+
470
+ foreach ( EditorCurveBinding curveBinding in AnimationUtility . GetCurveBindings ( animClipOriginal ) ) {
471
+ foreach ( EditorCurveBinding impCurveBinding in AnimationUtility . GetCurveBindings ( animClipImported ) ) {
472
+
473
+ // only compare if the path and property names match
474
+ if ( curveBinding . path != impCurveBinding . path || curveBinding . propertyName != impCurveBinding . propertyName ) {
475
+ continue ;
476
+ }
477
+
478
+ AnimationCurve animCurveOrig = AnimationUtility . GetEditorCurve ( animClipOriginal , curveBinding ) ;
479
+ Assert . That ( animCurveOrig , Is . Not . Null ) ;
480
+
481
+ AnimationCurve animCurveImported = AnimationUtility . GetEditorCurve ( animClipImported , impCurveBinding ) ;
482
+ Assert . That ( animCurveImported , Is . Not . Null ) ;
483
+
484
+ AnimCurveTest ( animCurveImported , animCurveOrig , curveBinding . propertyName ) ;
485
+ }
486
+ }
487
+ }
488
+
405
489
[ Test , TestCaseSource ( typeof ( AnimationTestDataClass ) , "TestCases1" ) ]
406
490
public int SimplePropertyAnimTest ( float [ ] keyTimesInSeconds , float [ ] keyValues , System . Type componentType , string componentName )
407
491
{
0 commit comments