Skip to content

Commit ebd74e9

Browse files
author
DESKTOP-F8VO8FK\Austin
committed
[ADDED] unit test for animated camera fov
[ADDED] mapping for camera FOV
1 parent 9308a6c commit ebd74e9

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,12 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
14841484
return true;
14851485
}
14861486

1487+
if (uniPropertyName.StartsWith("field of view", ct))
1488+
{
1489+
prop = new FbxPropertyChannelPair("FieldOfView", null);
1490+
return true;
1491+
}
1492+
14871493
prop = new FbxPropertyChannelPair ();
14881494
return false;
14891495
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using NUnit.Framework;
4+
5+
namespace FbxExporters.UnitTests
6+
{
7+
public class FbxCameraTest : ExporterTestBase
8+
{
9+
10+
[Test]
11+
public void AnimationWithCameraFOVTest()
12+
{
13+
string filename = GetRandomFbxFilePath();
14+
GameObject go = new GameObject();
15+
go.name = "originalCamera";
16+
Camera camera = go.AddComponent(typeof(Camera)) as Camera;
17+
Animation anim = go.AddComponent(typeof(Animation)) as Animation;
18+
Keyframe[] keys = new Keyframe[3];
19+
keys[0] = new Keyframe(0.0f, 1f);
20+
keys[1] = new Keyframe(1.0f, 2f);
21+
keys[2] = new Keyframe(2.0f, 3f);
22+
23+
AnimationCurve curve = new AnimationCurve(keys);
24+
25+
AnimationClip clip = new AnimationClip();
26+
27+
clip.legacy = true;
28+
29+
clip.SetCurve("", typeof(Camera), "field of view", 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+
Assert.IsNotNull(exportedClip);
59+
exportedClip.legacy = true;
60+
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+
for (int i = 0; i < exportedCurve.keys.Length; i++)
68+
{
69+
Assert.That(exportedCurve.keys[i].time == keys[i].time);
70+
Assert.That(exportedCurve.keys[i].value == keys[i].value);
71+
}
72+
}
73+
74+
}
75+
}

0 commit comments

Comments
 (0)