Skip to content

Commit 1c906e9

Browse files
author
DESKTOP-F8VO8FK\Austin
committed
[ADDED] spot angle test
[ADDED] beginnings of color test
1 parent 27eb533 commit 1c906e9

File tree

2 files changed

+102
-10
lines changed

2 files changed

+102
-10
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -977,21 +977,17 @@ protected void ExportAnimCurve(UnityEngine.Object unityObj,
977977
{
978978
fbxAnimCurve = fbxProperty.GetCurve(fbxAnimLayer, true);
979979
}
980-
981980
// copy Unity AnimCurve to FBX AnimCurve.
982981
fbxAnimCurve.KeyModifyBegin();
983982

984983
for (int keyIndex = 0, n = unityAnimCurve.length; keyIndex < n; ++keyIndex)
985984
{
986985
var key = unityAnimCurve[keyIndex];
987986

988-
switch (fbxProperty.GetName())
987+
if (fbxProperty.GetName() == "Intensity")
989988
{
990-
case "Intensity":
991989
key.value *= 100.0f;
992-
break;
993990
}
994-
995991
var fbxTime = FbxTime.FromSecondDouble(key.time);
996992
fbxAnimCurve.KeyAdd(fbxTime);
997993
fbxAnimCurve.KeySet(keyIndex, fbxTime, key.value);
@@ -1040,6 +1036,36 @@ public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelP
10401036
return true;
10411037
}
10421038

1039+
if (unityPropertyName.StartsWith("m_SpotAngle", ct) || unityPropertyName.EndsWith("T.z", ct))
1040+
{
1041+
prop = new FbxPropertyChannelPair("OuterAngle", null);
1042+
return true;
1043+
}
1044+
1045+
if (unityPropertyName.StartsWith("m_Color", ct) || unityPropertyName.EndsWith("T.z", ct))
1046+
{
1047+
prop = new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR);
1048+
return true;
1049+
}
1050+
1051+
if (unityPropertyName.StartsWith("m_Color.r", ct) || unityPropertyName.EndsWith("T.z", ct))
1052+
{
1053+
prop = new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_RED);
1054+
return true;
1055+
}
1056+
1057+
if (unityPropertyName.StartsWith("m_Color.g", ct) || unityPropertyName.EndsWith("T.z", ct))
1058+
{
1059+
prop = new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_GREEN);
1060+
return true;
1061+
}
1062+
1063+
if (unityPropertyName.StartsWith("m_Color.b", ct) || unityPropertyName.EndsWith("T.z", ct))
1064+
{
1065+
prop = new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_BLUE);
1066+
return true;
1067+
}
1068+
10431069
prop = new FbxPropertyChannelPair ();
10441070
return false;
10451071
}

Assets/FbxExporters/Editor/UnitTests/FbxLightTest.cs

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,27 @@ namespace FbxExporters.UnitTests
77
public class FbxLightTest : ExporterTestBase
88
{
99
[Test]
10-
public void AnimationWithLightTest()
10+
public void AnimationWithLightSpotAngleTest()
1111
{
1212
string filename = GetRandomFbxFilePath();
1313
GameObject go = new GameObject();
1414
go.name = "original";
1515
Light light = go.AddComponent(typeof(Light)) as Light;
16+
light.type = LightType.Spot;
1617
Animation anim = go.AddComponent(typeof(Animation)) as Animation;
1718

1819
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);
20+
keys[0] = new Keyframe(0.0f, 1f);
21+
keys[1] = new Keyframe(1.0f, 2f);
22+
keys[2] = new Keyframe(2.0f, 3f);
2223

2324
AnimationCurve curve = new AnimationCurve(keys);
2425

2526
AnimationClip clip = new AnimationClip();
2627

2728
clip.legacy = true;
2829

29-
clip.SetCurve("", typeof(Light), "m_Intensity", curve);
30+
clip.SetCurve("", typeof(Light), "m_SpotAngle", curve);
3031

3132
anim.AddClip(clip, "test");
3233

@@ -55,9 +56,74 @@ public void AnimationWithLightTest()
5556
if (exportedClip != null) break;
5657
}
5758

59+
Assert.IsNotNull(exportedClip);
5860
exportedClip.legacy = true;
61+
62+
EditorCurveBinding exportedEditorCurveBinding = AnimationUtility.GetCurveBindings(exportedClip)[0];
63+
64+
AnimationCurve exportedCurve = AnimationUtility.GetEditorCurve(exportedClip, exportedEditorCurveBinding);
65+
66+
Assert.That(exportedCurve.keys.Length, Is.EqualTo(keys.Length));
67+
68+
for (int i = 0; i < exportedCurve.keys.Length; i++)
69+
{
70+
Assert.That(exportedCurve.keys[i].time == keys[i].time);
71+
Assert.That(exportedCurve.keys[i].value == keys[i].value);
72+
}
73+
}
74+
75+
[Test]
76+
public void AnimationWithLightIntensityTest()
77+
{
78+
string filename = GetRandomFbxFilePath();
79+
GameObject go = new GameObject();
80+
go.name = "original";
81+
Light light = go.AddComponent(typeof(Light)) as Light;
82+
Animation anim = go.AddComponent(typeof(Animation)) as Animation;
83+
84+
Keyframe[] keys = new Keyframe[3];
85+
keys[0] = new Keyframe(0.0f, 1f);
86+
keys[1] = new Keyframe(1.0f, 2f);
87+
keys[2] = new Keyframe(2.0f, 3f);
88+
89+
AnimationCurve curve = new AnimationCurve(keys);
90+
91+
AnimationClip clip = new AnimationClip();
92+
93+
clip.legacy = true;
94+
95+
clip.SetCurve("", typeof(Light), "m_Intensity", curve);
96+
97+
anim.AddClip(clip, "test");
98+
99+
//export the object
100+
var exported = FbxExporters.Editor.ModelExporter.ExportObject(filename, go);
101+
102+
Assert.That(exported, Is.EqualTo(filename));
103+
104+
// TODO: Uni-34492 change importer settings of (newly exported model)
105+
// so that it's not resampled and it is legacy animation
106+
{
107+
ModelImporter modelImporter = AssetImporter.GetAtPath(filename) as ModelImporter;
108+
Assert.That(modelImporter, Is.Not.Null);
109+
modelImporter.resampleCurves = false;
110+
AssetDatabase.ImportAsset(filename);
111+
modelImporter.animationType = ModelImporterAnimationType.Legacy;
112+
AssetDatabase.ImportAsset(filename);
113+
}
114+
115+
Object[] objects = AssetDatabase.LoadAllAssetsAtPath(filename);
116+
117+
AnimationClip exportedClip = null;
118+
foreach (Object o in objects)
119+
{
120+
exportedClip = o as AnimationClip;
121+
if (exportedClip != null) break;
122+
}
59123

60124
Assert.IsNotNull(exportedClip);
125+
exportedClip.legacy = true;
126+
61127
EditorCurveBinding exportedEditorCurveBinding = AnimationUtility.GetCurveBindings(exportedClip)[0];
62128

63129
AnimationCurve exportedCurve = AnimationUtility.GetEditorCurve(exportedClip, exportedEditorCurveBinding);

0 commit comments

Comments
 (0)