Skip to content

Commit 16fdf4e

Browse files
author
DESKTOP-F8VO8FK\Austin
committed
[CHANGED] test to have correct import settings, and test thekeyframes
[ADDED] entry for light intensity
1 parent b4f99b5 commit 16fdf4e

File tree

2 files changed

+86
-48
lines changed

2 files changed

+86
-48
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -920,55 +920,74 @@ protected bool ExportLight (GameObject unityGo, FbxScene fbxScene, FbxNode fbxNo
920920
/// NOTE: This is not used for rotations, because we need to convert from
921921
/// quaternion to euler and various other stuff.
922922
/// </summary>
923-
protected void ExportAnimCurve (UnityEngine.Object unityObj,
923+
protected void ExportAnimCurve(UnityEngine.Object unityObj,
924924
AnimationCurve unityAnimCurve,
925925
string unityPropertyName,
926926
FbxScene fbxScene,
927927
FbxAnimLayer fbxAnimLayer)
928928
{
929929
FbxPropertyChannelPair fbxPropertyChannelPair;
930-
if (!FbxPropertyChannelPair.TryGetValue (unityPropertyName, out fbxPropertyChannelPair)) {
931-
Debug.LogWarning (string.Format ("no mapping from Unity '{0}' to fbx property", unityPropertyName));
930+
if (!FbxPropertyChannelPair.TryGetValue(unityPropertyName, out fbxPropertyChannelPair))
931+
{
932+
Debug.LogWarning(string.Format("no mapping from Unity '{0}' to fbx property", unityPropertyName));
932933
return;
933934
}
934935

935-
GameObject unityGo = GetGameObject (unityObj);
936-
if (unityGo == null) {
937-
Debug.LogError (string.Format ("cannot find gameobject for {0}", unityObj.ToString()));
936+
GameObject unityGo = GetGameObject(unityObj);
937+
if (unityGo == null && !unityObj)
938+
{
939+
Debug.LogError(string.Format("cannot find gameobject for {0}", unityObj.ToString()));
938940
return;
939941
}
940942

941943
FbxNode fbxNode;
942-
if (!MapUnityObjectToFbxNode.TryGetValue (unityGo, out fbxNode)) {
943-
Debug.LogError ( string.Format("no fbx node for {0}", unityGo.ToString()));
944+
if (!MapUnityObjectToFbxNode.TryGetValue(unityGo, out fbxNode))
945+
{
946+
Debug.LogError(string.Format("no fbx node for {0}", unityGo.ToString()));
944947
return;
945948
}
946-
947949
// map unity property name to fbx property
948-
var fbxProperty = fbxNode.FindProperty (fbxPropertyChannelPair.Property, false);
949-
if (!fbxProperty.IsValid ()) {
950-
Debug.LogError (string.Format ("no fbx property {0} found on {1} ", fbxPropertyChannelPair.Property, fbxNode.GetName ()));
950+
var fbxProperty = fbxNode.FindProperty(fbxPropertyChannelPair.Property, false);
951+
if (!fbxProperty.IsValid())
952+
{
953+
var fbxNodeAttribute = fbxNode.GetNodeAttribute();
954+
if (fbxNodeAttribute != null)
955+
{
956+
fbxProperty = fbxNodeAttribute.FindProperty(fbxPropertyChannelPair.Property, false);
957+
}
958+
}
959+
if (!fbxProperty.IsValid())
960+
{
961+
Debug.LogError(string.Format("no fbx property {0} found on {1} node or nodeAttribute ", fbxPropertyChannelPair.Property, fbxNode.GetName()));
951962
return;
952963
}
953964

954-
if (Verbose) {
955-
Debug.Log ("Exporting animation for " + unityObj.ToString() + " (" + unityPropertyName + ")");
965+
if (Verbose)
966+
{
967+
Debug.Log("Exporting animation for " + unityObj.ToString() + " (" + unityPropertyName + ")");
956968
}
957969

970+
FbxAnimCurve fbxAnimCurve;
958971
// Create the AnimCurve on the channel
959-
FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve (fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
972+
if (fbxPropertyChannelPair.Channel != null)
973+
fbxAnimCurve = fbxProperty.GetCurve(fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
974+
else
975+
{
976+
fbxAnimCurve = fbxProperty.GetCurve(fbxAnimLayer, true);
977+
}
960978

961979
// copy Unity AnimCurve to FBX AnimCurve.
962-
fbxAnimCurve.KeyModifyBegin ();
980+
fbxAnimCurve.KeyModifyBegin();
963981

964-
for (int keyIndex = 0, n = unityAnimCurve.length; keyIndex < n; ++keyIndex) {
965-
var key = unityAnimCurve [keyIndex];
966-
var fbxTime = FbxTime.FromSecondDouble (key.time);
967-
fbxAnimCurve.KeyAdd (fbxTime);
968-
fbxAnimCurve.KeySet (keyIndex, fbxTime, key.value);
982+
for (int keyIndex = 0, n = unityAnimCurve.length; keyIndex < n; ++keyIndex)
983+
{
984+
var key = unityAnimCurve[keyIndex];
985+
var fbxTime = FbxTime.FromSecondDouble(key.time);
986+
fbxAnimCurve.KeyAdd(fbxTime);
987+
fbxAnimCurve.KeySet(keyIndex, fbxTime, key.value);
969988
}
970989

971-
fbxAnimCurve.KeyModifyEnd ();
990+
fbxAnimCurve.KeyModifyEnd();
972991
}
973992

974993
/// <summary>
@@ -994,6 +1013,7 @@ public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelP
9941013
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_X);
9951014
return true;
9961015
}
1016+
9971017
if (unityPropertyName.StartsWith ("m_LocalPosition.y", ct) || unityPropertyName.EndsWith ("T.y", ct)) {
9981018
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Y);
9991019
return true;
@@ -1004,6 +1024,12 @@ public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelP
10041024
return true;
10051025
}
10061026

1027+
if (unityPropertyName.StartsWith("m_Intensity", ct) || unityPropertyName.EndsWith("T.z", ct))
1028+
{
1029+
prop = new FbxPropertyChannelPair("Intensity", null);
1030+
return true;
1031+
}
1032+
10071033
prop = new FbxPropertyChannelPair ();
10081034
return false;
10091035
}
@@ -1945,9 +1971,9 @@ private static GameObject GetGameObject (Object obj)
19451971
return xform.gameObject;
19461972
} else if (obj is UnityEngine.GameObject) {
19471973
return obj as UnityEngine.GameObject;
1948-
} else if (obj is MonoBehaviour) {
1949-
var mono = obj as MonoBehaviour;
1950-
return mono.gameObject;
1974+
} else if (obj is Behaviour) {
1975+
var behaviour = obj as Behaviour;
1976+
return behaviour.gameObject;
19511977
}
19521978

19531979
return null;

Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,13 @@ private void CompareLightValues(Light light, Light fbxLight, float delta=0.001f)
441441
[Test]
442442
public void AnimationWithLightTest()
443443
{
444-
string filename = GetRandomFbxFilePath ();
444+
string filename = GetRandomFbxFilePath();
445445
GameObject go = new GameObject ();
446+
go.name = "original";
446447
Light light = go.AddComponent(typeof (Light)) as Light;
447448
Animation anim = go.AddComponent (typeof(Animation)) as Animation;
448449

449-
Keyframe[] keys;
450-
keys = new Keyframe[3];
450+
Keyframe[] keys = new Keyframe[3];
451451
keys[0] = new Keyframe(0.0f, 0.25f);
452452
keys[1] = new Keyframe(1.0f, 0.5f);
453453
keys[2] = new Keyframe(2.0f, 1.0f);
@@ -463,35 +463,47 @@ public void AnimationWithLightTest()
463463
anim.AddClip (clip, "test");
464464

465465
//export the object
466-
var exported = FbxExporters.Editor.ModelExporter.ExportObject(filename , go);
466+
var exported = ModelExporter.ExportObject(filename , go);
467467

468-
//acquire exported file
469-
GameObject asset = AssetDatabase.LoadMainAssetAtPath(filename) as GameObject;
468+
Assert.That(exported, Is.EqualTo(filename));
470469

471-
//access the exported game objects' light
472-
Light foundLight = asset.GetComponent (typeof(Light)) as Light;
473-
474-
//Check that the light exists
475-
Assert.IsNotNull (foundLight);
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);
476482

477-
//Set the time of the animation to 0 seconds
478-
clip.SampleAnimation(asset, 0.0f);
483+
AnimationClip exportedClip = null;
484+
foreach (Object o in objects)
485+
{
486+
exportedClip = o as AnimationClip;
487+
if (exportedClip != null) break;
488+
}
479489

480-
//check that the value matches the key at 0 seconds
481-
Assert.AreEqual (foundLight.intensity, 0.25f);
490+
exportedClip.legacy = true;
482491

483-
//Set the time of the animation to 1 second
484-
clip.SampleAnimation(asset, 1.0f);
492+
Assert.IsNotNull(exportedClip);
493+
EditorCurveBinding exportedEditorCurveBinding = AnimationUtility.GetCurveBindings(exportedClip)[0];
485494

486-
//check that the value matches the key at 1 second
487-
Assert.AreEqual (foundLight.intensity, 0.5f);
495+
AnimationCurve exportedCurve = AnimationUtility.GetEditorCurve(exportedClip, exportedEditorCurveBinding);
488496

489-
//Set the time of the animation to 2 seconds
490-
clip.SampleAnimation(asset, 2.0f);
497+
Assert.That(exportedCurve.keys.Length, Is.EqualTo(keys.Length));
491498

492-
//check that the value matches the key at 2 seconds
493-
Assert.AreEqual (foundLight.intensity, 1.0f);
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);
494501

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+
}
495507
}
496508

497509
[Test]

0 commit comments

Comments
 (0)