Skip to content

Commit 4367452

Browse files
committed
add scale support; add unit tests for SRT
1 parent 00f8653 commit 4367452

File tree

2 files changed

+105
-60
lines changed

2 files changed

+105
-60
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,21 @@ public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelP
10041004
return true;
10051005
}
10061006

1007+
if (unityPropertyName.StartsWith ("m_LocalScale.x", ct) || unityPropertyName.EndsWith ("S.x", ct)) {
1008+
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_X);
1009+
return true;
1010+
}
1011+
if (unityPropertyName.StartsWith ("m_LocalScale.y", ct) || unityPropertyName.EndsWith ("S.y", ct)) {
1012+
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_Y);
1013+
return true;
1014+
}
1015+
1016+
if (unityPropertyName.StartsWith ("m_LocalScale.z", ct) || unityPropertyName.EndsWith ("S.z", ct)) {
1017+
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_Z);
1018+
return true;
1019+
}
1020+
1021+
10071022
prop = new FbxPropertyChannelPair ();
10081023
return false;
10091024
}

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 90 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,113 @@ namespace FbxExporters.UnitTests
88
{
99
public class AnimationComponentTestDataClass
1010
{
11-
static float[] m_keydata1 = new float [3 * 2] {1.0f, 0f, 2.0f, 100.0f, 3.0f, 0.0f};
12-
13-
public static IEnumerable TestCases {
14-
get {
15-
yield return new TestCaseData (m_keydata1, typeof(Transform), "m_LocalPosition.x").Returns (1);
16-
}
17-
}
11+
static float [] m_keytimes1 = new float [3] {1f, 2f, 3f};
12+
static float [] m_keyvalues1 = new float [3] {0f, 100f, 0f};
13+
static float [] m_keyvalues2 = new float [3] {1f, 100f, 1f};
14+
15+
public static IEnumerable TestCases {
16+
get {
17+
yield return new TestCaseData (m_keytimes1, m_keyvalues2, typeof(Transform), "m_LocalScale.x").Returns (1);
18+
yield return new TestCaseData (m_keytimes1, m_keyvalues2, typeof(Transform), "m_LocalScale.y").Returns (1);
19+
yield return new TestCaseData (m_keytimes1, m_keyvalues2, typeof(Transform), "m_LocalScale.z").Returns (1);
20+
yield return new TestCaseData (m_keytimes1, m_keyvalues1, typeof(Transform), "m_LocalRotation.x").Returns (1);
21+
yield return new TestCaseData (m_keytimes1, m_keyvalues1, typeof(Transform), "m_LocalRotation.y").Returns (1);
22+
yield return new TestCaseData (m_keytimes1, m_keyvalues1, typeof(Transform), "m_LocalRotation.z").Returns (1);
23+
yield return new TestCaseData (m_keytimes1, m_keyvalues1, typeof(Transform), "m_LocalPosition.x").Returns (1);
24+
yield return new TestCaseData (m_keytimes1, m_keyvalues1, typeof(Transform), "m_LocalPosition.y").Returns (1);
25+
yield return new TestCaseData (m_keytimes1, m_keyvalues1, typeof(Transform), "m_LocalPosition.z").Returns (1);
26+
}
27+
}
1828
}
1929

2030
[TestFixture]
2131
public class FbxAnimationTest : ExporterTestBase
2232
{
23-
protected static void DebugLogAnimCurve (AnimationCurve animCurve)
33+
protected void AnimClipTest (AnimationClip animClipExpected, AnimationClip animClipActual)
34+
{
35+
Assert.That (animClipActual.name, Is.EqualTo(animClipExpected.name));
36+
Assert.That (animClipActual.legacy, Is.EqualTo(animClipExpected.legacy));
37+
Assert.That (animClipActual.isLooping, Is.EqualTo(animClipExpected.isLooping));
38+
Assert.That (animClipActual.wrapMode, Is.EqualTo(animClipExpected.wrapMode));
39+
40+
// TODO: Uni-34489
41+
Assert.That (animClipActual.length, Is.EqualTo(animClipExpected.length).Within (Mathf.Epsilon), "animClip length doesn't match");
42+
}
43+
44+
protected void AnimCurveTest (float [] keyTimesExpected, float [] keyValuesExpected, AnimationCurve animCurveActual)
45+
{
46+
int numKeysExpected = keyTimesExpected.Length;
47+
48+
// TODO : Uni-34492 number of keys don't match
49+
Assert.That (animCurveActual.length, Is.EqualTo(numKeysExpected), "animcurve number of keys doesn't match");
50+
51+
//check imported animation against original
52+
Assert.That(new ListMapper(animCurveActual.keys).Property ("time"), Is.EqualTo(keyTimesExpected), "key time doesn't match");
53+
Assert.That(new ListMapper(animCurveActual.keys).Property ("value"), Is.EqualTo(keyValuesExpected), "key value doesn't match");
54+
55+
return ;
56+
}
57+
58+
[TearDown]
59+
public override void Term ()
2460
{
25-
int idx = 0;
26-
foreach (var key in animCurve.keys) {
27-
Debug.Log (string.Format ("key[{0}] {1} {2}", idx++, key.time, key.value));
28-
}
61+
return;
2962
}
3063

3164
[Test, TestCaseSource (typeof (AnimationComponentTestDataClass), "TestCases")]
32-
public int SinglePropertyLegacyAnimTest (float [] keydata, System.Type propertyType, string propertyName )
65+
public int SinglePropertyLegacyAnimTest (float [] keytimes, float [] keyvalues, System.Type propertyType, string propertyName )
3366
{
34-
string filePath = GetRandomFbxFilePath ();
35-
GameObject go = new GameObject ();
36-
go.name = "orig_"+propertyName;
37-
Animation animOrig = go.AddComponent (typeof (Animation)) as Animation;
67+
string path = GetRandomFbxFilePath ();
3868

39-
int expectedNumKeys = keydata.Length / 2;
69+
// TODO: add extra parent so that we can test export/import of transforms
70+
GameObject goRoot = new GameObject ();
71+
goRoot.name = "root_"+propertyName;
72+
73+
GameObject goModel = new GameObject ();
74+
goModel.name = "model_"+propertyName;
75+
goModel.transform.parent = goRoot.transform;
76+
77+
Animation animOrig = goModel.AddComponent (typeof (Animation)) as Animation;
78+
79+
int numKeys = Mathf.Min(keytimes.Length, keyvalues.Length);
4080

4181
// initialize keys
42-
Keyframe [] keys = new Keyframe [expectedNumKeys];
82+
Keyframe [] keys = new Keyframe [numKeys];
4383

44-
for (int idx = 0; idx < expectedNumKeys; idx++)
84+
for (int idx = 0; idx < numKeys; idx++)
4585
{
46-
keys[idx].time = keydata [(idx*2)+0];
47-
keys[idx].value = keydata [(idx*2)+1];
86+
keys[idx].time = keytimes [idx];
87+
keys[idx].value = keyvalues [idx];
4888
}
4989

50-
AnimationCurve animCurveOrig = new AnimationCurve (keys);
90+
AnimationCurve animCurveOrig = new AnimationCurve (keys);
5191

52-
AnimationClip animClipOrig = new AnimationClip ();
92+
AnimationClip animClipOriginal = new AnimationClip ();
5393

54-
animClipOrig.legacy = true;
94+
animClipOriginal.legacy = true;
95+
animClipOriginal.name = "anim_" + propertyName;
96+
97+
animClipOriginal.SetCurve ("", propertyType, propertyName, animCurveOrig);
5598

56-
animClipOrig.SetCurve ("", propertyType, propertyName, animCurveOrig);
99+
animOrig.AddClip (animClipOriginal, "anim_" + propertyName );
57100

58-
animOrig.AddClip (animClipOrig, "anim_" + propertyName );
101+
//export the object
102+
var exportedFilePath = ModelExporter.ExportObject (path, goRoot);
103+
Assert.That (exportedFilePath, Is.EqualTo(path));
59104

60-
//export the object
61-
var exportedFilePath = ModelExporter.ExportObject (filePath, go);
62-
Assert.AreEqual (exportedFilePath, filePath);
105+
// TODO: Uni-34492 change importer settings of (newly exported model)
106+
// so that it's not resampled and it is legacy animation
107+
{
108+
ModelImporter modelImporter = AssetImporter.GetAtPath (path) as ModelImporter;
109+
modelImporter.resampleCurves = false;
110+
AssetDatabase.ImportAsset (path);
111+
modelImporter.animationType = ModelImporterAnimationType.Legacy;
112+
AssetDatabase.ImportAsset (path);
113+
}
63114

64-
//acquire imported object from exported file
65-
Object[] goAssetImported = AssetDatabase.LoadAllAssetsAtPath (filePath);
66-
Assert.IsNotNull (goAssetImported);
115+
//acquire imported object from exported file
116+
Object[] goAssetImported = AssetDatabase.LoadAllAssetsAtPath (path);
117+
Assert.That(goAssetImported, Is.Not.Null);
67118

68119
// TODO : configure object so that it imports w Legacy Animation
69120

@@ -73,44 +124,23 @@ public int SinglePropertyLegacyAnimTest (float [] keydata, System.Type propertyT
73124
animClipImported = o as AnimationClip;
74125
if (animClipImported) break;
75126
}
76-
Assert.IsNotNull (animClipImported);
127+
Assert.That (animClipImported, Is.Not.Null);
77128

78129
// TODO : configure import settings so we don't need to force legacy
79130
animClipImported.legacy = true;
80-
Assert.AreEqual (animClipImported.legacy, true);
81-
82-
{
83-
var go2 = Object.Instantiate (goAssetImported [0]) as GameObject;
84-
Assert.IsNotNull (go2);
85-
go2.name = "imported_" + propertyName;
86-
Animation anim2 = go2.AddComponent (typeof (Animation)) as Animation;
87-
anim2.AddClip (animClipImported, "anim2_" + propertyName );
88-
}
89-
90-
91-
// TODO : check clip properties match
92131

132+
// check clip properties match
133+
AnimClipTest (animClipOriginal, animClipImported);
134+
93135
// check animCurve & keys
94136
int result = 0;
95137

96138
foreach (EditorCurveBinding curveBinding in AnimationUtility.GetCurveBindings (animClipImported))
97139
{
98140
AnimationCurve animCurveImported = AnimationUtility.GetEditorCurve (animClipImported, curveBinding);
99-
Assert.IsNotNull (animCurveImported);
100-
101-
DebugLogAnimCurve (animCurveImported);
102-
103-
Assert.AreEqual (expectedNumKeys, animCurveImported.length);
104-
105-
//check imported animation against original
106-
int idx = 0;
107-
foreach (var key in animCurveImported.keys)
108-
{
109-
Assert.AreEqual (key.time, keydata [(idx * 2) + 0]);
110-
Assert.AreEqual (key.value, keydata [(idx * 2) + 1]);
141+
Assert.That(animCurveImported, Is.Not.Null);
111142

112-
idx++;
113-
}
143+
AnimCurveTest (keytimes, keyvalues, animCurveImported);
114144

115145
result++;
116146
}

0 commit comments

Comments
 (0)