Skip to content

Commit 0d92d74

Browse files
committed
add unit test for continuous rotations
1 parent d25cab7 commit 0d92d74

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ public class AnimationTestDataClass
2626
Where (t => typeof (Component).IsAssignableFrom (t) &&
2727
ModelExporter.MapsToFbxObject.ContainsKey(t)).Except(m_exceptionTypes);
2828

29+
public static string [] m_localRotationNames = new string [4] { "m_LocalRotation.x", "m_LocalRotation.y", "m_LocalRotation.z", "m_LocalRotation.w" };
30+
public static string [] m_localTranslationNames = new string [3] { "m_LocalPosition.x", "m_LocalPosition.y", "m_LocalPosition.z"};
31+
2932
public static float [] m_keytimes1 = new float [3] { 1f, 2f, 3f };
3033
public static float [] m_keyFloatValues1 = new float [3] { 0f, 100f, 0f };
3134
public static float [] m_keyvalues2 = new float [3] { 1f, 100f, 1f };
3235
public static Vector3 [] m_keyEulerValues3 = new Vector3 [3] { new Vector3 (0f, 80f, 0f), new Vector3 (80f, 0f, 0f), new Vector3 (0f, 0f, 80f) };
3336
public static Vector3 [] m_keyEulerValues4 = new Vector3 [3] { new Vector3 (0f, 270f, 0f), new Vector3 (270f, 0f, 0f), new Vector3 (0f, 0f, 270f) };
3437

38+
public static float [] m_keytimes5 = new float [5] { 0f, 30f, 60f, 90f, 120f };
39+
public static Vector3 [] m_keyPosValues5 = new Vector3 [5] { new Vector3 (5.078195f, 0.000915527f, 4.29761f), new Vector3 (0.81f, 0.000915527f, 10.59f), new Vector3 (-3.65f, 0.000915527f, 4.29761f), new Vector3 (0.81f, 0.000915527f, -3.37f), new Vector3 (5.078195f, 0.000915527f, 4.29761f) };
40+
public static Vector3 [] m_keyRotValues5 = new Vector3 [5] { new Vector3 (0f, 0f, 0f), new Vector3 (0f, -90f, 0f), new Vector3 (0f, -180f, 0f), new Vector3 (0f, -270f, 0f), new Vector3 (0f, -360f, 0f) };
41+
3542
public static IEnumerable TestCases1 {
3643
get {
3744
yield return new TestCaseData (m_keytimes1, m_keyvalues2, typeof (Transform), "m_LocalScale.x").Returns (1);
@@ -44,13 +51,13 @@ public static IEnumerable TestCases1 {
4451
}
4552
public static IEnumerable TestCases2 {
4653
get {
47-
yield return new TestCaseData (m_keytimes1, m_keyEulerValues3, typeof (Transform), new string [4] { "m_LocalRotation.x", "m_LocalRotation.y", "m_LocalRotation.z", "m_LocalRotation.w" } ).Returns (3);
54+
yield return new TestCaseData (m_keytimes1, m_keyEulerValues3, typeof (Transform), m_localRotationNames ).Returns (3);
4855
}
4956
}
5057
// specify gimbal conditions for rotation
5158
public static IEnumerable TestCases3 {
5259
get {
53-
yield return new TestCaseData (m_keytimes1, m_keyEulerValues4, typeof (Transform), new string [4] { "m_LocalRotation.x", "m_LocalRotation.y", "m_LocalRotation.z", "m_LocalRotation.w" } ).Returns (3);
60+
yield return new TestCaseData (m_keytimes1, m_keyEulerValues4, typeof (Transform), m_localRotationNames ).Returns (3);
5461
}
5562
}
5663
// specify one of each component type
@@ -60,6 +67,12 @@ public static IEnumerable TestCases4 {
6067
yield return new TestCaseData (cType).Returns(1);
6168
}
6269
}
70+
// specify continuous rotations
71+
public static IEnumerable TestCases5 {
72+
get {
73+
yield return new TestCaseData (m_keytimes5, m_keyRotValues5.Concat(m_keyPosValues5).ToArray(), typeof (Transform), m_localRotationNames.Concat(m_localTranslationNames).ToArray() ).Returns (3);
74+
}
75+
}
6376
}
6477

6578
[TestFixture]
@@ -171,6 +184,46 @@ public override int FindComponent (string name)
171184
}
172185
}
173186

187+
public class TransformKeyData : KeyData
188+
{
189+
public string[] propertyNames;
190+
public Vector3 [] keyValues; // NOTE: first half is Quaternions and second half is Translation
191+
public bool IsRotation(int id) { return id < 4 ; }
192+
193+
public override int NumKeys { get { return Mathf.Min (keyTimesInSeconds.Length, keyValues.Length / 2); } }
194+
public override int NumComponents { get { return propertyNames.Length; } }
195+
public override float [] GetKeyValues (int id)
196+
{
197+
float[] result = new float[NumKeys];
198+
bool isRot = IsRotation(id);
199+
200+
for (int idx=0; idx < NumKeys; idx++)
201+
{
202+
result[idx] = (isRot) ? Quaternion.Euler(keyValues[idx])[id] : keyValues[NumKeys+idx][id-4];
203+
}
204+
205+
return result;
206+
}
207+
public override float [] GetAltKeyValues (int id)
208+
{
209+
float[] result = new float[NumKeys];
210+
bool isRot = IsRotation(id);
211+
212+
for (int idx=0; idx < NumKeys; idx++)
213+
{
214+
result[idx] = (isRot) ? keyValues[idx][id] : keyValues[NumKeys+idx][id-4];
215+
}
216+
217+
return result;
218+
}
219+
220+
public override string GetComponentName (int id) { return propertyNames[id]; }
221+
public override int FindComponent (string name)
222+
{
223+
return System.Array.IndexOf (propertyNames, name);
224+
}
225+
}
226+
174227
GameObject CreateTargetObject (string name, System.Type componentType)
175228
{
176229
GameObject goModel = new GameObject ();
@@ -301,7 +354,16 @@ public int GimbalConditionsAnimTest (float [] keyTimesInSeconds, Vector3 [] keyV
301354
{
302355
KeyData keyData = new QuaternionKeyData { propertyNames = componentNames, componentType = componentType, keyTimesInSeconds = keyTimesInSeconds, keyEulerValues = keyValues };
303356

304-
return AnimTest (keyData, componentType.ToString () + "_Quaternion");
357+
return AnimTest (keyData, componentType.ToString () + "_Gimbal");
358+
}
359+
360+
[Description("Uni-35616 continuous rotations")]
361+
[Test, TestCaseSource (typeof (AnimationTestDataClass), "TestCases5")]
362+
public int ContinuousRotationAnimTest (float [] keyTimesInSeconds, Vector3 [] keyValues, System.Type componentType, string [] propertyNames)
363+
{
364+
KeyData keyData = new TransformKeyData { propertyNames = propertyNames, componentType = componentType, keyTimesInSeconds = keyTimesInSeconds, keyValues = keyValues };
365+
366+
return AnimTest (keyData, componentType.ToString () + "_ContinuousRotations");
305367
}
306368

307369
[Test, TestCaseSource (typeof (AnimationTestDataClass), "TestCases4")]

0 commit comments

Comments
 (0)