Skip to content

Commit a901c05

Browse files
author
DESKTOP-F8VO8FK\Austin
committed
[ADDED] seperate file for animation/light unit tests
2 parents 16fdf4e + 6d520ca commit a901c05

File tree

3 files changed

+79
-68
lines changed

3 files changed

+79
-68
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,9 @@ protected void ExportAnimCurve(UnityEngine.Object unityObj,
970970
FbxAnimCurve fbxAnimCurve;
971971
// Create the AnimCurve on the channel
972972
if (fbxPropertyChannelPair.Channel != null)
973+
{
973974
fbxAnimCurve = fbxProperty.GetCurve(fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
975+
}
974976
else
975977
{
976978
fbxAnimCurve = fbxProperty.GetCurve(fbxAnimLayer, true);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using NUnit.Framework;
4+
5+
namespace FbxExporters.UnitTests
6+
{
7+
public class FbxLightTest : ExporterTestBase
8+
{
9+
[Test]
10+
public void AnimationWithLightTest()
11+
{
12+
string filename = GetRandomFbxFilePath();
13+
GameObject go = new GameObject();
14+
go.name = "original";
15+
Light light = go.AddComponent(typeof(Light)) as Light;
16+
Animation anim = go.AddComponent(typeof(Animation)) as Animation;
17+
18+
Keyframe[] keys = new Keyframe[3];
19+
keys[0] = new Keyframe(0.0f, 0.25f);
20+
keys[1] = new Keyframe(1.0f, 0.5f);
21+
keys[2] = new Keyframe(2.0f, 1.0f);
22+
23+
AnimationCurve curve = new AnimationCurve(keys);
24+
25+
AnimationClip clip = new AnimationClip();
26+
27+
clip.legacy = true;
28+
29+
clip.SetCurve("", typeof(Light), "m_Intensity", curve);
30+
31+
anim.AddClip(clip, "test");
32+
33+
//export the object
34+
var exported = FbxExporters.Editor.ModelExporter.ExportObject(filename, go);
35+
36+
Assert.That(exported, Is.EqualTo(filename));
37+
38+
// TODO: Uni-34492 change importer settings of (newly exported model)
39+
// so that it's not resampled and it is legacy animation
40+
{
41+
ModelImporter modelImporter = AssetImporter.GetAtPath(filename) as ModelImporter;
42+
Assert.That(modelImporter, Is.Not.Null);
43+
modelImporter.resampleCurves = false;
44+
AssetDatabase.ImportAsset(filename);
45+
modelImporter.animationType = ModelImporterAnimationType.Legacy;
46+
AssetDatabase.ImportAsset(filename);
47+
}
48+
49+
Object[] objects = AssetDatabase.LoadAllAssetsAtPath(filename);
50+
51+
AnimationClip exportedClip = null;
52+
foreach (Object o in objects)
53+
{
54+
exportedClip = o as AnimationClip;
55+
if (exportedClip != null) break;
56+
}
57+
58+
exportedClip.legacy = true;
59+
60+
Assert.IsNotNull(exportedClip);
61+
EditorCurveBinding exportedEditorCurveBinding = AnimationUtility.GetCurveBindings(exportedClip)[0];
62+
63+
AnimationCurve exportedCurve = AnimationUtility.GetEditorCurve(exportedClip, exportedEditorCurveBinding);
64+
65+
Assert.That(exportedCurve.keys.Length, Is.EqualTo(keys.Length));
66+
67+
Debug.Log(AnimationUtility.GetEditorCurve(clip, AnimationUtility.GetCurveBindings(clip)[0]).keys[1].value);
68+
Debug.Log(AnimationUtility.GetEditorCurve(exportedClip, AnimationUtility.GetCurveBindings(exportedClip)[0]).keys[1].value);
69+
70+
for (int i = 0; i < exportedCurve.keys.Length; i++)
71+
{
72+
Assert.That(exportedCurve.keys[i].time == keys[i].time);
73+
Assert.That(exportedCurve.keys[i].value == keys[i].value);
74+
}
75+
}
76+
}
77+
}

Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -438,74 +438,6 @@ private void CompareLightValues(Light light, Light fbxLight, float delta=0.001f)
438438
Assert.IsTrue (light.transform.rotation == fbxLight.transform.rotation);
439439
}
440440

441-
[Test]
442-
public void AnimationWithLightTest()
443-
{
444-
string filename = GetRandomFbxFilePath();
445-
GameObject go = new GameObject ();
446-
go.name = "original";
447-
Light light = go.AddComponent(typeof (Light)) as Light;
448-
Animation anim = go.AddComponent (typeof(Animation)) as Animation;
449-
450-
Keyframe[] keys = new Keyframe[3];
451-
keys[0] = new Keyframe(0.0f, 0.25f);
452-
keys[1] = new Keyframe(1.0f, 0.5f);
453-
keys[2] = new Keyframe(2.0f, 1.0f);
454-
455-
AnimationCurve curve = new AnimationCurve (keys);
456-
457-
AnimationClip clip = new AnimationClip ();
458-
459-
clip.legacy = true;
460-
461-
clip.SetCurve ("", typeof(Light), "m_Intensity", curve);
462-
463-
anim.AddClip (clip, "test");
464-
465-
//export the object
466-
var exported = ModelExporter.ExportObject(filename , go);
467-
468-
Assert.That(exported, Is.EqualTo(filename));
469-
470-
// TODO: Uni-34492 change importer settings of (newly exported model)
471-
// so that it's not resampled and it is legacy animation
472-
{
473-
ModelImporter modelImporter = AssetImporter.GetAtPath(filename) as ModelImporter;
474-
Assert.That(modelImporter, Is.Not.Null);
475-
modelImporter.resampleCurves = false;
476-
AssetDatabase.ImportAsset(filename);
477-
modelImporter.animationType = ModelImporterAnimationType.Legacy;
478-
AssetDatabase.ImportAsset(filename);
479-
}
480-
481-
Object[] objects = AssetDatabase.LoadAllAssetsAtPath(filename);
482-
483-
AnimationClip exportedClip = null;
484-
foreach (Object o in objects)
485-
{
486-
exportedClip = o as AnimationClip;
487-
if (exportedClip != null) break;
488-
}
489-
490-
exportedClip.legacy = true;
491-
492-
Assert.IsNotNull(exportedClip);
493-
EditorCurveBinding exportedEditorCurveBinding = AnimationUtility.GetCurveBindings(exportedClip)[0];
494-
495-
AnimationCurve exportedCurve = AnimationUtility.GetEditorCurve(exportedClip, exportedEditorCurveBinding);
496-
497-
Assert.That(exportedCurve.keys.Length, Is.EqualTo(keys.Length));
498-
499-
Debug.Log(AnimationUtility.GetEditorCurve(clip, AnimationUtility.GetCurveBindings(clip)[0]).keys[1].value);
500-
Debug.Log(AnimationUtility.GetEditorCurve(exportedClip, AnimationUtility.GetCurveBindings(exportedClip)[0]).keys[1].value);
501-
502-
for (int i = 0; i < exportedCurve.keys.Length; i++)
503-
{
504-
Assert.That(exportedCurve.keys[i].time == keys[i].time);
505-
Assert.That(exportedCurve.keys[i].value == keys[i].value);
506-
}
507-
}
508-
509441
[Test]
510442
public void TestComponentAttributeExport()
511443
{

0 commit comments

Comments
 (0)