Skip to content

Commit ec8112e

Browse files
committed
add skinned mesh animation unit test
1 parent f4d2ee3 commit ec8112e

File tree

4 files changed

+339
-17
lines changed

4 files changed

+339
-17
lines changed

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 94 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public override void Term ()
7979
base.Term ();
8080
}
8181

82-
protected void AnimClipTest (AnimationClip animClipExpected, AnimationClip animClipActual)
82+
protected void AnimClipPropertyTest (AnimationClip animClipExpected, AnimationClip animClipActual)
8383
{
8484
#if UNITY_EDITOR_WIN
8585
// TODO: figure out why we get __preview__ on Windows
@@ -109,6 +109,21 @@ protected void AnimCurveTest (float [] keyTimesExpected, float [] keyValuesExpec
109109
return ;
110110
}
111111

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+
112127
public class KeyData
113128
{
114129
public float [] keyTimesInSeconds;
@@ -234,23 +249,9 @@ public int AnimTest (KeyData keyData, string testName)
234249
}
235250

236251
//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);
251253

252-
// check clip properties match
253-
AnimClipTest (animClipOriginal, animClipImported);
254+
AnimClipPropertyTest (animClipOriginal, animClipImported);
254255

255256
// check animCurve & keys
256257
int result = 0;
@@ -279,6 +280,82 @@ public int AnimTest (KeyData keyData, string testName)
279280
return result;
280281
}
281282

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+
282359
[Test, TestCaseSource (typeof (AnimationTestDataClass), "TestCases1")]
283360
public int SimplePropertyAnimTest (float [] keyTimesInSeconds, float [] keyValues, System.Type componentType, string componentName)
284361
{

Assets/FbxExporters/Editor/UnitTests/Models/DefaultMale.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/UnitTests/Models/DefaultMale/Male_DyingHitFromBack_Blend_T3_Cut01_James.fbx.meta

Lines changed: 235 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)