Skip to content

Commit 6d520ca

Browse files
committed
scaling unit tests pass
1 parent 4367452 commit 6d520ca

File tree

2 files changed

+70
-53
lines changed

2 files changed

+70
-53
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,10 @@ protected void ExportAnimCurve (UnityEngine.Object unityObj,
926926
FbxScene fbxScene,
927927
FbxAnimLayer fbxAnimLayer)
928928
{
929+
if (Verbose) {
930+
Debug.Log ("Exporting animation for " + unityObj.ToString() + " (" + unityPropertyName + ")");
931+
}
932+
929933
FbxPropertyChannelPair fbxPropertyChannelPair;
930934
if (!FbxPropertyChannelPair.TryGetValue (unityPropertyName, out fbxPropertyChannelPair)) {
931935
Debug.LogWarning (string.Format ("no mapping from Unity '{0}' to fbx property", unityPropertyName));
@@ -951,10 +955,6 @@ protected void ExportAnimCurve (UnityEngine.Object unityObj,
951955
return;
952956
}
953957

954-
if (Verbose) {
955-
Debug.Log ("Exporting animation for " + unityObj.ToString() + " (" + unityPropertyName + ")");
956-
}
957-
958958
// Create the AnimCurve on the channel
959959
FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve (fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
960960

@@ -990,20 +990,7 @@ public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelP
990990
{
991991
System.StringComparison ct = System.StringComparison.CurrentCulture;
992992

993-
if (unityPropertyName.StartsWith ("m_LocalPosition.x", ct) || unityPropertyName.EndsWith ("T.x", ct)) {
994-
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_X);
995-
return true;
996-
}
997-
if (unityPropertyName.StartsWith ("m_LocalPosition.y", ct) || unityPropertyName.EndsWith ("T.y", ct)) {
998-
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Y);
999-
return true;
1000-
}
1001-
1002-
if (unityPropertyName.StartsWith ("m_LocalPosition.z", ct) || unityPropertyName.EndsWith ("T.z", ct)) {
1003-
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Z);
1004-
return true;
1005-
}
1006-
993+
// Transform Scaling
1007994
if (unityPropertyName.StartsWith ("m_LocalScale.x", ct) || unityPropertyName.EndsWith ("S.x", ct)) {
1008995
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_X);
1009996
return true;
@@ -1012,12 +999,26 @@ public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelP
1012999
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_Y);
10131000
return true;
10141001
}
1015-
10161002
if (unityPropertyName.StartsWith ("m_LocalScale.z", ct) || unityPropertyName.EndsWith ("S.z", ct)) {
10171003
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_Z);
10181004
return true;
10191005
}
10201006

1007+
// NOTE: Transform Rotation handled by QuaternionCurve
1008+
1009+
// Transform Translation
1010+
if (unityPropertyName.StartsWith ("m_LocalPosition.x", ct) || unityPropertyName.EndsWith ("T.x", ct)) {
1011+
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_X);
1012+
return true;
1013+
}
1014+
if (unityPropertyName.StartsWith ("m_LocalPosition.y", ct) || unityPropertyName.EndsWith ("T.y", ct)) {
1015+
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Y);
1016+
return true;
1017+
}
1018+
if (unityPropertyName.StartsWith ("m_LocalPosition.z", ct) || unityPropertyName.EndsWith ("T.z", ct)) {
1019+
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Z);
1020+
return true;
1021+
}
10211022

10221023
prop = new FbxPropertyChannelPair ();
10231024
return false;
@@ -1169,7 +1170,7 @@ protected void ExportAnimationClip (AnimationClip unityAnimClip, GameObject unit
11691170
if (!unityAnimClip) return;
11701171

11711172
if (Verbose)
1172-
Debug.Log (string.Format ("Exporting clip {1} for {0}", unityRoot.name, unityAnimClip.name));
1173+
Debug.Log (string.Format ("Exporting animation clip ({1}) for {0}", unityRoot.name, unityAnimClip.name));
11731174

11741175
// setup anim stack
11751176
FbxAnimStack fbxAnimStack = FbxAnimStack.Create (fbxScene, unityAnimClip.name);
@@ -1183,7 +1184,7 @@ protected void ExportAnimationClip (AnimationClip unityAnimClip, GameObject unit
11831184
// Custom frame rate isn't really supported in FBX SDK (there's
11841185
// a bug), so try hard to find the nearest time mode.
11851186
FbxTime.EMode timeMode = FbxTime.EMode.eCustom;
1186-
double precision = 1e-6;
1187+
double precision = Mathf.Epsilon;
11871188
while (timeMode == FbxTime.EMode.eCustom && precision < 1000) {
11881189
timeMode = FbxTime.ConvertFrameRateToTimeMode (unityAnimClip.frameRate, precision);
11891190
precision *= 10;
@@ -1212,10 +1213,8 @@ protected void ExportAnimationClip (AnimationClip unityAnimClip, GameObject unit
12121213
if (unityAnimCurve == null) { continue; }
12131214

12141215
int index = QuaternionCurve.GetQuaternionIndex (unityCurveBinding.propertyName);
1215-
if (index == -1) {
1216-
if (Verbose)
1217-
Debug.Log (string.Format ("Export animation binding {1} for {0}", unityCurveBinding.propertyName, unityObj.ToString ()));
1218-
1216+
if (index == -1)
1217+
{
12191218
/* Some normal property (e.g. translation), export right away */
12201219
ExportAnimCurve (unityObj, unityAnimCurve, unityCurveBinding.propertyName,
12211220
fbxScene, fbxAnimLayer);
@@ -2189,7 +2188,7 @@ public void Dispose ()
21892188
{
21902189
}
21912190

2192-
public bool Verbose { private set {;} get { return false; } }
2191+
public bool Verbose { private set {;} get { return true; } }
21932192

21942193
/// <summary>
21952194
/// manage the selection of a filename

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,65 @@ namespace FbxExporters.UnitTests
88
{
99
public class AnimationComponentTestDataClass
1010
{
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};
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 };
1414

1515
public static IEnumerable TestCases {
1616
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);
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);
2626
}
2727
}
2828
}
2929

3030
[TestFixture]
3131
public class FbxAnimationTest : ExporterTestBase
3232
{
33+
[TearDown]
34+
public override void Term ()
35+
{
36+
}
37+
38+
protected void DumpAnimCurve(AnimationCurve animCurve, string message, float [] keyTimesExpected = null, float[] keyValuesExpected = null)
39+
{
40+
int idx = 0;
41+
foreach (var key in animCurve.keys) {
42+
if (keyTimesExpected!=null && keyValuesExpected!=null) {
43+
Debug.Log (string.Format ("{5} keys[{0}] {1}({3}) {2} ({4})",
44+
idx, key.time, key.value,
45+
keyTimesExpected [idx], keyValuesExpected [idx],
46+
message));
47+
} else{
48+
Debug.Log (string.Format ("{3} keys[{0}] {1} {2}", idx, key.time, key.value, message));
49+
}
50+
idx++;
51+
}
52+
}
53+
3354
protected void AnimClipTest (AnimationClip animClipExpected, AnimationClip animClipActual)
3455
{
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));
56+
Assert.That (animClipActual.name, Is.EqualTo (animClipExpected.name));
57+
Assert.That (animClipActual.legacy, Is.EqualTo (animClipExpected.legacy));
58+
Assert.That (animClipActual.isLooping, Is.EqualTo (animClipExpected.isLooping));
59+
Assert.That (animClipActual.wrapMode, Is.EqualTo (animClipExpected.wrapMode));
3960

4061
// TODO: Uni-34489
41-
Assert.That (animClipActual.length, Is.EqualTo(animClipExpected.length).Within (Mathf.Epsilon), "animClip length doesn't match");
62+
Assert.That (animClipActual.length, Is.EqualTo (animClipExpected.length).Within (Mathf.Epsilon), "animClip length doesn't match");
4263
}
4364

44-
protected void AnimCurveTest (float [] keyTimesExpected, float [] keyValuesExpected, AnimationCurve animCurveActual)
65+
protected void AnimCurveTest (float [] keyTimesExpected, float [] keyValuesExpected, AnimationCurve animCurveActual, string message)
4566
{
4667
int numKeysExpected = keyTimesExpected.Length;
4768

69+
DumpAnimCurve (animCurveActual, message, keyTimesExpected, keyValuesExpected);
4870
// TODO : Uni-34492 number of keys don't match
4971
Assert.That (animCurveActual.length, Is.EqualTo(numKeysExpected), "animcurve number of keys doesn't match");
5072

@@ -55,12 +77,6 @@ protected void AnimCurveTest (float [] keyTimesExpected, float [] keyValuesExpec
5577
return ;
5678
}
5779

58-
[TearDown]
59-
public override void Term ()
60-
{
61-
return;
62-
}
63-
6480
[Test, TestCaseSource (typeof (AnimationComponentTestDataClass), "TestCases")]
6581
public int SinglePropertyLegacyAnimTest (float [] keytimes, float [] keyvalues, System.Type propertyType, string propertyName )
6682
{
@@ -140,9 +156,11 @@ public int SinglePropertyLegacyAnimTest (float [] keytimes, float [] keyvalues,
140156
AnimationCurve animCurveImported = AnimationUtility.GetEditorCurve (animClipImported, curveBinding);
141157
Assert.That(animCurveImported, Is.Not.Null);
142158

143-
AnimCurveTest (keytimes, keyvalues, animCurveImported);
144-
145-
result++;
159+
if (propertyName == curveBinding.propertyName)
160+
{
161+
AnimCurveTest (keytimes, keyvalues, animCurveImported, curveBinding.propertyName);
162+
result++;
163+
}
146164
}
147165

148166
return result;

0 commit comments

Comments
 (0)