@@ -99,6 +99,12 @@ public static IEnumerable AnimOnlyTestCaases {
99
99
yield return new TestCaseData ( "Models/DefaultMale/DefaultMale.prefab" ) ;
100
100
}
101
101
}
102
+
103
+ public static IEnumerable RotationCurveTestCases {
104
+ get {
105
+ yield return new TestCaseData ( "Models/Player/Player.prefab" ) ;
106
+ }
107
+ }
102
108
}
103
109
104
110
[ TestFixture ]
@@ -492,6 +498,21 @@ public static void ClipPropertyTest (AnimationClip animClipExpected, AnimationCl
492
498
Assert . That ( animClipActual . length , Is . EqualTo ( animClipExpected . length ) . Within ( 0.0001f ) , "animClip length doesn't match" ) ;
493
499
}
494
500
501
+ /// <summary>
502
+ /// Compares the properties and curves of multiple animation clips
503
+ /// </summary>
504
+ /// <param name="animClipsOriginal">Animation clips original.</param>
505
+ /// <param name="animClipsImported">Animation clips imported.</param>
506
+ public static void MultiClipTest ( AnimationClip [ ] animClipsOriginal , Dictionary < string , AnimationClip > animClipsImported ) {
507
+ Assert . That ( animClipsImported . Count , Is . EqualTo ( animClipsOriginal . Length ) ) ;
508
+
509
+ foreach ( var clip in animClipsOriginal ) {
510
+ Assert . That ( animClipsImported . ContainsKey ( clip . name ) ) ;
511
+ var fbxClip = animClipsImported [ clip . name ] ;
512
+ AnimTester . ClipTest ( clip , fbxClip ) ;
513
+ }
514
+ }
515
+
495
516
/// <summary>
496
517
/// Compares the properties and curves of two animation clips.
497
518
/// </summary>
@@ -582,7 +603,7 @@ public static void KeyValuesTest (AnimationCurve expectedAnimCurve, AnimationCur
582
603
#if DEBUG_UNITTEST
583
604
Debug . Log ( string . Format ( "key time={0} actual={1} expected={2} delta={3}" , key . time . ToString ( ) , key . value . ToString ( ) , actualKeyValue . ToString ( ) , Mathf . Abs ( key . value - actualKeyValue ) . ToString ( ) ) ) ;
584
605
#endif
585
- Assert . That ( key . value , Is . EqualTo ( actualKeyValue ) . Within ( 0.000001 ) , string . Format ( "{0} key ({1}) doesn't match" , message , key . time ) ) ;
606
+ Assert . That ( key . value , Is . EqualTo ( actualKeyValue ) . Within ( 0.1 ) , string . Format ( "{0} key ({1}) doesn't match" , message , key . time ) ) ;
586
607
}
587
608
}
588
609
@@ -653,20 +674,16 @@ public void LegacySkinnedMeshAnimTest (string fbxPath)
653
674
Assert . That ( fbxPath , Is . Not . Null ) ;
654
675
655
676
// add fbx to scene
656
- GameObject originalFbxObj = AssetDatabase . LoadMainAssetAtPath ( "Assets/" + fbxPath ) as GameObject ;
657
- Assert . IsNotNull ( originalFbxObj ) ;
658
- GameObject originalGO = GameObject . Instantiate ( originalFbxObj ) ;
659
- Assert . IsTrue ( originalGO ) ;
677
+ GameObject originalGO = AddAssetToScene ( fbxPath ) ;
660
678
661
679
// get clip
662
680
AnimationClip animClipOriginal = originalGO . GetComponentInChildren < Animation > ( ) . clip ;
663
681
Assert . That ( animClipOriginal , Is . Not . Null ) ;
664
682
665
683
// export fbx
666
684
// get GameObject
667
- string filename = GetRandomFbxFilePath ( ) ;
668
- var exportedFilePath = ModelExporter . ExportObject ( filename , originalGO ) ;
669
- Assert . That ( exportedFilePath , Is . EqualTo ( filename ) ) ;
685
+ string filename = GetRandomFbxFilePath ( ) ;
686
+ ExportToFbx ( filename , originalGO ) ;
670
687
671
688
// TODO: Uni-34492 change importer settings of (newly exported model)
672
689
// so that it's not resampled and it is legacy animation
@@ -807,29 +824,19 @@ public void AnimOnlyExportTest(string prefabPath)
807
824
Assert . That ( prefabPath , Is . Not . Null ) ;
808
825
809
826
// add prefab to scene
810
- GameObject originalObj = AssetDatabase . LoadMainAssetAtPath ( "Assets/" + prefabPath ) as GameObject ;
811
- Assert . IsNotNull ( originalObj ) ;
812
- GameObject originalGO = GameObject . Instantiate ( originalObj ) ;
813
- Assert . IsTrue ( originalGO ) ;
827
+ GameObject originalGO = AddAssetToScene ( prefabPath ) ;
814
828
815
829
// get clips
816
830
var animator = originalGO . GetComponentInChildren < Animator > ( ) ;
817
- Assert . That ( animator , Is . Not . Null ) ;
818
-
819
- var controller = animator . runtimeAnimatorController ;
820
- Assert . That ( controller , Is . Not . Null ) ;
821
-
822
- var animClips = controller . animationClips ;
823
- Assert . That ( animClips , Is . Not . Null ) ;
831
+ var animClips = GetClipsFromAnimator ( animator ) ;
824
832
825
833
// get the set of GameObject transforms to be exported with the clip
826
834
var animatedObjects = GetAnimatedGameObjects ( animClips , animator . gameObject ) ;
827
835
828
836
// export fbx
829
837
// get GameObject
830
838
string filename = GetRandomFbxFilePath ( ) ;
831
- var exportedFilePath = ModelExporter . ExportObject ( filename , originalGO , animOnly : true ) ;
832
- Assert . That ( exportedFilePath , Is . EqualTo ( filename ) ) ;
839
+ ExportToFbx ( filename , originalGO , true ) ;
833
840
834
841
GameObject fbxObj = AssetDatabase . LoadMainAssetAtPath ( filename ) as GameObject ;
835
842
Assert . IsTrue ( fbxObj ) ;
@@ -854,13 +861,33 @@ public void AnimOnlyExportTest(string prefabPath)
854
861
855
862
// compare clips
856
863
var fbxAnimClips = AnimTester . GetClipsFromFbx ( filename ) ;
857
- Assert . That ( fbxAnimClips . Count , Is . EqualTo ( animClips . Count ( ) ) ) ;
864
+ AnimTester . MultiClipTest ( animClips , fbxAnimClips ) ;
865
+ }
858
866
859
- foreach ( var clip in animClips ) {
860
- Assert . That ( fbxAnimClips . ContainsKey ( clip . name ) ) ;
861
- var fbxClip = fbxAnimClips [ clip . name ] ;
862
- AnimTester . ClipTest ( clip , fbxClip ) ;
863
- }
867
+ public static void ExportToFbx ( string filename , GameObject hierarchy , bool animOnly = false ) {
868
+ var exportedFilePath = ModelExporter . ExportObject ( filename , hierarchy , animOnly ) ;
869
+ Assert . That ( exportedFilePath , Is . EqualTo ( filename ) ) ;
870
+ }
871
+
872
+ public static AnimationClip [ ] GetClipsFromAnimator ( Animator animator ) {
873
+ Assert . That ( animator , Is . Not . Null ) ;
874
+
875
+ var controller = animator . runtimeAnimatorController ;
876
+ Assert . That ( controller , Is . Not . Null ) ;
877
+
878
+ var animClips = controller . animationClips ;
879
+ Assert . That ( animClips , Is . Not . Null ) ;
880
+
881
+ return animClips ;
882
+ }
883
+
884
+ public static GameObject AddAssetToScene ( string assetPath ) {
885
+ GameObject originalObj = AssetDatabase . LoadMainAssetAtPath ( "Assets/" + assetPath ) as GameObject ;
886
+ Assert . IsNotNull ( originalObj ) ;
887
+ GameObject originalGO = GameObject . Instantiate ( originalObj ) ;
888
+ Assert . IsTrue ( originalGO ) ;
889
+
890
+ return originalGO ;
864
891
}
865
892
866
893
private HashSet < string > GetAnimatedGameObjects ( AnimationClip [ ] animClips , GameObject animatorObject ) {
0 commit comments