Skip to content

Commit 00f8653

Browse files
committed
add unit test
1 parent 5a8cb05 commit 00f8653

File tree

2 files changed

+126
-5
lines changed

2 files changed

+126
-5
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ protected void ExportAnimationClip (AnimationClip unityAnimClip, GameObject unit
11541154
if (!unityAnimClip) return;
11551155

11561156
if (Verbose)
1157-
Debug.Log (string.Format ("exporting clip {1} for {0}", unityRoot.name, unityAnimClip.name));
1157+
Debug.Log (string.Format ("Exporting clip {1} for {0}", unityRoot.name, unityAnimClip.name));
11581158

11591159
// setup anim stack
11601160
FbxAnimStack fbxAnimStack = FbxAnimStack.Create (fbxScene, unityAnimClip.name);
@@ -1199,7 +1199,7 @@ protected void ExportAnimationClip (AnimationClip unityAnimClip, GameObject unit
11991199
int index = QuaternionCurve.GetQuaternionIndex (unityCurveBinding.propertyName);
12001200
if (index == -1) {
12011201
if (Verbose)
1202-
Debug.Log (string.Format ("export binding {1} for {0}", unityCurveBinding.propertyName, unityObj.ToString ()));
1202+
Debug.Log (string.Format ("Export animation binding {1} for {0}", unityCurveBinding.propertyName, unityObj.ToString ()));
12031203

12041204
/* Some normal property (e.g. translation), export right away */
12051205
ExportAnimCurve (unityObj, unityAnimCurve, unityCurveBinding.propertyName,
@@ -1261,7 +1261,7 @@ protected void ExportAnimation (GameObject unityRoot, FbxScene fbxScene)
12611261
var director = unityRoot.GetComponent<UnityEngine.Playables.PlayableDirector> ();
12621262
if (director)
12631263
{
1264-
Debug.Log(string.Format("exporting animationclips from playabledirector on {0} not supported", unityRoot.name));
1264+
Debug.LogWarning(string.Format("Exporting animation from PlayableDirector on {0} not supported", unityRoot.name));
12651265
// TODO: export animationclips from playabledirector
12661266
}
12671267

@@ -1367,7 +1367,7 @@ protected int ExportComponents (
13671367
}
13681368

13691369
if (Verbose)
1370-
Debug.Log (string.Format ("exporting {0}", fbxNode.GetName ()));
1370+
Debug.Log (string.Format ("Exporting node {0}", fbxNode.GetName ()));
13711371

13721372
fbxNodeParent.AddChild (fbxNode);
13731373

@@ -2174,7 +2174,7 @@ public void Dispose ()
21742174
{
21752175
}
21762176

2177-
public bool Verbose { private set {;} get { return Debug.unityLogger.logEnabled; } }
2177+
public bool Verbose { private set {;} get { return false; } }
21782178

21792179
/// <summary>
21802180
/// manage the selection of a filename
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using NUnit.Framework;
4+
using System.Collections;
5+
using FbxExporters.Editor;
6+
7+
namespace FbxExporters.UnitTests
8+
{
9+
public class AnimationComponentTestDataClass
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+
}
18+
}
19+
20+
[TestFixture]
21+
public class FbxAnimationTest : ExporterTestBase
22+
{
23+
protected static void DebugLogAnimCurve (AnimationCurve animCurve)
24+
{
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+
}
29+
}
30+
31+
[Test, TestCaseSource (typeof (AnimationComponentTestDataClass), "TestCases")]
32+
public int SinglePropertyLegacyAnimTest (float [] keydata, System.Type propertyType, string propertyName )
33+
{
34+
string filePath = GetRandomFbxFilePath ();
35+
GameObject go = new GameObject ();
36+
go.name = "orig_"+propertyName;
37+
Animation animOrig = go.AddComponent (typeof (Animation)) as Animation;
38+
39+
int expectedNumKeys = keydata.Length / 2;
40+
41+
// initialize keys
42+
Keyframe [] keys = new Keyframe [expectedNumKeys];
43+
44+
for (int idx = 0; idx < expectedNumKeys; idx++)
45+
{
46+
keys[idx].time = keydata [(idx*2)+0];
47+
keys[idx].value = keydata [(idx*2)+1];
48+
}
49+
50+
AnimationCurve animCurveOrig = new AnimationCurve (keys);
51+
52+
AnimationClip animClipOrig = new AnimationClip ();
53+
54+
animClipOrig.legacy = true;
55+
56+
animClipOrig.SetCurve ("", propertyType, propertyName, animCurveOrig);
57+
58+
animOrig.AddClip (animClipOrig, "anim_" + propertyName );
59+
60+
//export the object
61+
var exportedFilePath = ModelExporter.ExportObject (filePath, go);
62+
Assert.AreEqual (exportedFilePath, filePath);
63+
64+
//acquire imported object from exported file
65+
Object[] goAssetImported = AssetDatabase.LoadAllAssetsAtPath (filePath);
66+
Assert.IsNotNull (goAssetImported);
67+
68+
// TODO : configure object so that it imports w Legacy Animation
69+
70+
AnimationClip animClipImported = null;
71+
foreach (Object o in goAssetImported)
72+
{
73+
animClipImported = o as AnimationClip;
74+
if (animClipImported) break;
75+
}
76+
Assert.IsNotNull (animClipImported);
77+
78+
// TODO : configure import settings so we don't need to force legacy
79+
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+
93+
// check animCurve & keys
94+
int result = 0;
95+
96+
foreach (EditorCurveBinding curveBinding in AnimationUtility.GetCurveBindings (animClipImported))
97+
{
98+
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]);
111+
112+
idx++;
113+
}
114+
115+
result++;
116+
}
117+
118+
return result;
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)