Skip to content

Commit 2de6434

Browse files
committed
add unit test for exporting euler curve on skinned mesh
1 parent db4cc21 commit 2de6434

14 files changed

+3707
-27
lines changed

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ public static IEnumerable AnimOnlyTestCaases {
9999
yield return new TestCaseData ("Models/DefaultMale/DefaultMale.prefab");
100100
}
101101
}
102+
103+
public static IEnumerable RotationCurveTestCases {
104+
get {
105+
yield return new TestCaseData ("Models/Player/Player.prefab");
106+
}
107+
}
102108
}
103109

104110
[TestFixture]
@@ -492,6 +498,21 @@ public static void ClipPropertyTest (AnimationClip animClipExpected, AnimationCl
492498
Assert.That (animClipActual.length, Is.EqualTo (animClipExpected.length).Within (0.0001f), "animClip length doesn't match");
493499
}
494500

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+
495516
/// <summary>
496517
/// Compares the properties and curves of two animation clips.
497518
/// </summary>
@@ -582,7 +603,7 @@ public static void KeyValuesTest (AnimationCurve expectedAnimCurve, AnimationCur
582603
#if DEBUG_UNITTEST
583604
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()));
584605
#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));
586607
}
587608
}
588609

@@ -653,20 +674,16 @@ public void LegacySkinnedMeshAnimTest (string fbxPath)
653674
Assert.That (fbxPath, Is.Not.Null);
654675

655676
// 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);
660678

661679
// get clip
662680
AnimationClip animClipOriginal = originalGO.GetComponentInChildren<Animation>().clip;
663681
Assert.That (animClipOriginal, Is.Not.Null);
664682

665683
// export fbx
666684
// 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);
670687

671688
// TODO: Uni-34492 change importer settings of (newly exported model)
672689
// so that it's not resampled and it is legacy animation
@@ -807,29 +824,19 @@ public void AnimOnlyExportTest(string prefabPath)
807824
Assert.That (prefabPath, Is.Not.Null);
808825

809826
// 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);
814828

815829
// get clips
816830
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);
824832

825833
// get the set of GameObject transforms to be exported with the clip
826834
var animatedObjects = GetAnimatedGameObjects (animClips, animator.gameObject);
827835

828836
// export fbx
829837
// get GameObject
830838
string filename = GetRandomFbxFilePath ();
831-
var exportedFilePath = ModelExporter.ExportObject (filename, originalGO, animOnly: true);
832-
Assert.That (exportedFilePath, Is.EqualTo (filename));
839+
ExportToFbx(filename, originalGO, true);
833840

834841
GameObject fbxObj = AssetDatabase.LoadMainAssetAtPath (filename) as GameObject;
835842
Assert.IsTrue (fbxObj);
@@ -854,13 +861,33 @@ public void AnimOnlyExportTest(string prefabPath)
854861

855862
// compare clips
856863
var fbxAnimClips = AnimTester.GetClipsFromFbx (filename);
857-
Assert.That (fbxAnimClips.Count, Is.EqualTo (animClips.Count()));
864+
AnimTester.MultiClipTest (animClips, fbxAnimClips);
865+
}
858866

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;
864891
}
865892

866893
private HashSet<string> GetAnimatedGameObjects(AnimationClip[] animClips, GameObject animatorObject){

0 commit comments

Comments
 (0)