@@ -8,62 +8,113 @@ namespace FbxExporters.UnitTests
8
8
{
9
9
public class AnimationComponentTestDataClass
10
10
{
11
- static float [ ] m_keydata1 = new float [ 3 * 2 ] { 1.0f , 0f , 2.0f , 100.0f , 3.0f , 0.0f } ;
12
-
13
- public static IEnumerable TestCases {
14
- get {
15
- yield return new TestCaseData ( m_keydata1 , typeof ( Transform ) , "m_LocalPosition.x" ) . Returns ( 1 ) ;
16
- }
17
- }
11
+ static float [ ] m_keytimes1 = new float [ 3 ] { 1f , 2f , 3f } ;
12
+ static float [ ] m_keyvalues1 = new float [ 3 ] { 0f , 100f , 0f } ;
13
+ static float [ ] m_keyvalues2 = new float [ 3 ] { 1f , 100f , 1f } ;
14
+
15
+ public static IEnumerable TestCases {
16
+ get {
17
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues2 , typeof ( Transform ) , "m_LocalScale.x" ) . Returns ( 1 ) ;
18
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues2 , typeof ( Transform ) , "m_LocalScale.y" ) . Returns ( 1 ) ;
19
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues2 , typeof ( Transform ) , "m_LocalScale.z" ) . Returns ( 1 ) ;
20
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues1 , typeof ( Transform ) , "m_LocalRotation.x" ) . Returns ( 1 ) ;
21
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues1 , typeof ( Transform ) , "m_LocalRotation.y" ) . Returns ( 1 ) ;
22
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues1 , typeof ( Transform ) , "m_LocalRotation.z" ) . Returns ( 1 ) ;
23
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues1 , typeof ( Transform ) , "m_LocalPosition.x" ) . Returns ( 1 ) ;
24
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues1 , typeof ( Transform ) , "m_LocalPosition.y" ) . Returns ( 1 ) ;
25
+ yield return new TestCaseData ( m_keytimes1 , m_keyvalues1 , typeof ( Transform ) , "m_LocalPosition.z" ) . Returns ( 1 ) ;
26
+ }
27
+ }
18
28
}
19
29
20
30
[ TestFixture ]
21
31
public class FbxAnimationTest : ExporterTestBase
22
32
{
23
- protected static void DebugLogAnimCurve ( AnimationCurve animCurve )
33
+ protected void AnimClipTest ( AnimationClip animClipExpected , AnimationClip animClipActual )
34
+ {
35
+ Assert . That ( animClipActual . name , Is . EqualTo ( animClipExpected . name ) ) ;
36
+ Assert . That ( animClipActual . legacy , Is . EqualTo ( animClipExpected . legacy ) ) ;
37
+ Assert . That ( animClipActual . isLooping , Is . EqualTo ( animClipExpected . isLooping ) ) ;
38
+ Assert . That ( animClipActual . wrapMode , Is . EqualTo ( animClipExpected . wrapMode ) ) ;
39
+
40
+ // TODO: Uni-34489
41
+ Assert . That ( animClipActual . length , Is . EqualTo ( animClipExpected . length ) . Within ( Mathf . Epsilon ) , "animClip length doesn't match" ) ;
42
+ }
43
+
44
+ protected void AnimCurveTest ( float [ ] keyTimesExpected , float [ ] keyValuesExpected , AnimationCurve animCurveActual )
45
+ {
46
+ int numKeysExpected = keyTimesExpected . Length ;
47
+
48
+ // TODO : Uni-34492 number of keys don't match
49
+ Assert . That ( animCurveActual . length , Is . EqualTo ( numKeysExpected ) , "animcurve number of keys doesn't match" ) ;
50
+
51
+ //check imported animation against original
52
+ Assert . That ( new ListMapper ( animCurveActual . keys ) . Property ( "time" ) , Is . EqualTo ( keyTimesExpected ) , "key time doesn't match" ) ;
53
+ Assert . That ( new ListMapper ( animCurveActual . keys ) . Property ( "value" ) , Is . EqualTo ( keyValuesExpected ) , "key value doesn't match" ) ;
54
+
55
+ return ;
56
+ }
57
+
58
+ [ TearDown ]
59
+ public override void Term ( )
24
60
{
25
- int idx = 0 ;
26
- foreach ( var key in animCurve . keys ) {
27
- Debug . Log ( string . Format ( "key[{0}] {1} {2}" , idx ++ , key . time , key . value ) ) ;
28
- }
61
+ return ;
29
62
}
30
63
31
64
[ Test , TestCaseSource ( typeof ( AnimationComponentTestDataClass ) , "TestCases" ) ]
32
- public int SinglePropertyLegacyAnimTest ( float [ ] keydata , System . Type propertyType , string propertyName )
65
+ public int SinglePropertyLegacyAnimTest ( float [ ] keytimes , float [ ] keyvalues , System . Type propertyType , string propertyName )
33
66
{
34
- string filePath = GetRandomFbxFilePath ( ) ;
35
- GameObject go = new GameObject ( ) ;
36
- go . name = "orig_" + propertyName ;
37
- Animation animOrig = go . AddComponent ( typeof ( Animation ) ) as Animation ;
67
+ string path = GetRandomFbxFilePath ( ) ;
38
68
39
- int expectedNumKeys = keydata . Length / 2 ;
69
+ // TODO: add extra parent so that we can test export/import of transforms
70
+ GameObject goRoot = new GameObject ( ) ;
71
+ goRoot . name = "root_" + propertyName ;
72
+
73
+ GameObject goModel = new GameObject ( ) ;
74
+ goModel . name = "model_" + propertyName ;
75
+ goModel . transform . parent = goRoot . transform ;
76
+
77
+ Animation animOrig = goModel . AddComponent ( typeof ( Animation ) ) as Animation ;
78
+
79
+ int numKeys = Mathf . Min ( keytimes . Length , keyvalues . Length ) ;
40
80
41
81
// initialize keys
42
- Keyframe [ ] keys = new Keyframe [ expectedNumKeys ] ;
82
+ Keyframe [ ] keys = new Keyframe [ numKeys ] ;
43
83
44
- for ( int idx = 0 ; idx < expectedNumKeys ; idx ++ )
84
+ for ( int idx = 0 ; idx < numKeys ; idx ++ )
45
85
{
46
- keys [ idx ] . time = keydata [ ( idx * 2 ) + 0 ] ;
47
- keys [ idx ] . value = keydata [ ( idx * 2 ) + 1 ] ;
86
+ keys [ idx ] . time = keytimes [ idx ] ;
87
+ keys [ idx ] . value = keyvalues [ idx ] ;
48
88
}
49
89
50
- AnimationCurve animCurveOrig = new AnimationCurve ( keys ) ;
90
+ AnimationCurve animCurveOrig = new AnimationCurve ( keys ) ;
51
91
52
- AnimationClip animClipOrig = new AnimationClip ( ) ;
92
+ AnimationClip animClipOriginal = new AnimationClip ( ) ;
53
93
54
- animClipOrig . legacy = true ;
94
+ animClipOriginal . legacy = true ;
95
+ animClipOriginal . name = "anim_" + propertyName ;
96
+
97
+ animClipOriginal . SetCurve ( "" , propertyType , propertyName , animCurveOrig ) ;
55
98
56
- animClipOrig . SetCurve ( "" , propertyType , propertyName , animCurveOrig ) ;
99
+ animOrig . AddClip ( animClipOriginal , "anim_" + propertyName ) ;
57
100
58
- animOrig . AddClip ( animClipOrig , "anim_" + propertyName ) ;
101
+ //export the object
102
+ var exportedFilePath = ModelExporter . ExportObject ( path , goRoot ) ;
103
+ Assert . That ( exportedFilePath , Is . EqualTo ( path ) ) ;
59
104
60
- //export the object
61
- var exportedFilePath = ModelExporter . ExportObject ( filePath , go ) ;
62
- Assert . AreEqual ( exportedFilePath , filePath ) ;
105
+ // TODO: Uni-34492 change importer settings of (newly exported model)
106
+ // so that it's not resampled and it is legacy animation
107
+ {
108
+ ModelImporter modelImporter = AssetImporter . GetAtPath ( path ) as ModelImporter ;
109
+ modelImporter . resampleCurves = false ;
110
+ AssetDatabase . ImportAsset ( path ) ;
111
+ modelImporter . animationType = ModelImporterAnimationType . Legacy ;
112
+ AssetDatabase . ImportAsset ( path ) ;
113
+ }
63
114
64
- //acquire imported object from exported file
65
- Object [ ] goAssetImported = AssetDatabase . LoadAllAssetsAtPath ( filePath ) ;
66
- Assert . IsNotNull ( goAssetImported ) ;
115
+ //acquire imported object from exported file
116
+ Object [ ] goAssetImported = AssetDatabase . LoadAllAssetsAtPath ( path ) ;
117
+ Assert . That ( goAssetImported , Is . Not . Null ) ;
67
118
68
119
// TODO : configure object so that it imports w Legacy Animation
69
120
@@ -73,44 +124,23 @@ public int SinglePropertyLegacyAnimTest (float [] keydata, System.Type propertyT
73
124
animClipImported = o as AnimationClip ;
74
125
if ( animClipImported ) break ;
75
126
}
76
- Assert . IsNotNull ( animClipImported ) ;
127
+ Assert . That ( animClipImported , Is . Not . Null ) ;
77
128
78
129
// TODO : configure import settings so we don't need to force legacy
79
130
animClipImported . legacy = true ;
80
- Assert . AreEqual ( animClipImported . legacy , true ) ;
81
-
82
- {
83
- var go2 = Object . Instantiate ( goAssetImported [ 0 ] ) as GameObject ;
84
- Assert . IsNotNull ( go2 ) ;
85
- go2 . name = "imported_" + propertyName ;
86
- Animation anim2 = go2 . AddComponent ( typeof ( Animation ) ) as Animation ;
87
- anim2 . AddClip ( animClipImported , "anim2_" + propertyName ) ;
88
- }
89
-
90
-
91
- // TODO : check clip properties match
92
131
132
+ // check clip properties match
133
+ AnimClipTest ( animClipOriginal , animClipImported ) ;
134
+
93
135
// check animCurve & keys
94
136
int result = 0 ;
95
137
96
138
foreach ( EditorCurveBinding curveBinding in AnimationUtility . GetCurveBindings ( animClipImported ) )
97
139
{
98
140
AnimationCurve animCurveImported = AnimationUtility . GetEditorCurve ( animClipImported , curveBinding ) ;
99
- Assert . IsNotNull ( animCurveImported ) ;
100
-
101
- DebugLogAnimCurve ( animCurveImported ) ;
102
-
103
- Assert . AreEqual ( expectedNumKeys , animCurveImported . length ) ;
104
-
105
- //check imported animation against original
106
- int idx = 0 ;
107
- foreach ( var key in animCurveImported . keys )
108
- {
109
- Assert . AreEqual ( key . time , keydata [ ( idx * 2 ) + 0 ] ) ;
110
- Assert . AreEqual ( key . value , keydata [ ( idx * 2 ) + 1 ] ) ;
141
+ Assert . That ( animCurveImported , Is . Not . Null ) ;
111
142
112
- idx ++ ;
113
- }
143
+ AnimCurveTest ( keytimes , keyvalues , animCurveImported ) ;
114
144
115
145
result ++ ;
116
146
}
0 commit comments