Skip to content

Commit f479d61

Browse files
committed
add weight animation unit test
- test both the constraint's weight and the source's weight
1 parent 70cc8ea commit f479d61

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,10 @@ public static void ConfigureImportSettings(string filename, object customSetting
347347
if (customSettings==null)
348348
{
349349
customSettings = new {
350-
resampleCurves = false,
351-
animationType= ModelImporterAnimationType.Legacy,
352-
animationCompression = ModelImporterAnimationCompression.Off
350+
resampleCurves = false,
351+
animationType = ModelImporterAnimationType.Legacy,
352+
animationCompression = ModelImporterAnimationCompression.Off,
353+
importConstraints = true
353354
};
354355
}
355356

@@ -358,6 +359,7 @@ public static void ConfigureImportSettings(string filename, object customSetting
358359
AssetDatabase.ImportAsset (filename);
359360
modelImporter.animationType = (ModelImporterAnimationType)customSettings.GetType().GetProperty("animationType").GetValue(customSettings,null);
360361
modelImporter.animationCompression = (ModelImporterAnimationCompression)customSettings.GetType().GetProperty("animationCompression").GetValue(customSettings,null);
362+
modelImporter.importConstraints = (bool)customSettings.GetType().GetProperty("importConstraints").GetValue(customSettings, null);
361363
AssetDatabase.ImportAsset (filename);
362364
}
363365

Assets/FbxExporters/Editor/UnitTests/FbxConstraintTest.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
using UnityEngine;
22
using UnityEditor;
33
using NUnit.Framework;
4+
using System.Collections;
45
using System.Collections.Generic;
56
using UnityEngine.Animations;
67

78
namespace FbxExporters.UnitTests
89
{
10+
public class ConstraintAnimationTestDataClass
11+
{
12+
public static IEnumerable TestCases
13+
{
14+
get
15+
{
16+
yield return new TestCaseData(new float[] { 1f, 20f, 30f }, new float[] { 0f, 0.5f, 1f }, "m_Weight").Returns(1);
17+
yield return new TestCaseData(new float[] { 2, 9, 33 }, new float[] { 0.1f, 0.67f, 0.2f }, "m_Sources.Array.data[0].weight").Returns(1);
18+
}
19+
}
20+
}
21+
922
public class FbxConstraintTest : ExporterTestBase
1023
{
1124
/// <summary>
@@ -174,6 +187,35 @@ public void TestAimConstraintExport()
174187
Assert.That(expConstraint.worldUpVector, Is.EqualTo(aimConstraint.worldUpVector));
175188
}
176189

190+
[Test, TestCaseSource(typeof(ConstraintAnimationTestDataClass), "TestCases")]
191+
public int TestWeightAnimation(float[] keyTimes, float[] keyValues, string propertyName)
192+
{
193+
var go = new GameObject("root");
194+
var source = new GameObject("source");
195+
196+
source.transform.parent = go.transform;
197+
198+
var constraint = go.AddComponent<RotationConstraint>();
199+
Assert.That(constraint, Is.Not.Null);
200+
201+
var cSource = new ConstraintSource();
202+
cSource.sourceTransform = source.transform;
203+
204+
int index = constraint.AddSource(cSource);
205+
Assert.That(index, Is.EqualTo(0));
206+
207+
var keyData = new FbxAnimationTest.PropertyKeyData
208+
{
209+
targetObject = go,
210+
componentType = typeof(RotationConstraint),
211+
propertyName = propertyName,
212+
keyTimes = keyTimes,
213+
keyFloatValues = keyValues
214+
};
215+
var tester = new FbxAnimationTest.AnimTester { keyData = keyData, testName = "ConstraintWeightAnim_" + propertyName, path = GetRandomFbxFilePath() };
216+
217+
return tester.DoIt();
218+
}
177219

178220
public bool AreEqual(Vector3 a, Vector3 b, double epsilon = 0.0001)
179221
{

0 commit comments

Comments
 (0)