|
4 | 4 | using NUnit.Framework;
|
5 | 5 | using System.IO;
|
6 | 6 | using System.Collections.Generic;
|
| 7 | +using FbxSdk; |
7 | 8 |
|
8 | 9 | namespace FbxExporters.UnitTests
|
9 | 10 | {
|
@@ -76,6 +77,22 @@ public void Term ()
|
76 | 77 | [Test]
|
77 | 78 | public void TestDefaultSelection ()
|
78 | 79 | {
|
| 80 | + // Default selection behavior: |
| 81 | + // - Export descendants |
| 82 | + // - Don't export siblings |
| 83 | + // - Don't export parents |
| 84 | + // - If both a parent and descendant are selected, |
| 85 | + // then result will be the same as if just the parent |
| 86 | + // were selected |
| 87 | + // |
| 88 | + // Default transform export: |
| 89 | + // - if there is only one root GameObject being exported |
| 90 | + // then zero out the root transform, leave all descendants |
| 91 | + // with local transform |
| 92 | + // - if there are multiple root GameObjects, then export |
| 93 | + // the global transform of each, and local transform |
| 94 | + // of descendants |
| 95 | + |
79 | 96 | m_root = CreateHierarchy ();
|
80 | 97 | Assert.IsNotNull (m_root);
|
81 | 98 |
|
@@ -119,21 +136,32 @@ public void TestDefaultSelection ()
|
119 | 136 | /// <summary>
|
120 | 137 | /// Compares the global transform of expected
|
121 | 138 | /// to the local transform of actual.
|
| 139 | + /// If expected is null, then compare to the identity matrix. |
122 | 140 | /// </summary>
|
123 | 141 | /// <param name="actual">Actual.</param>
|
124 | 142 | /// <param name="expected">Expected.</param>
|
125 | 143 | private void CompareGlobalTransform(Transform actual, Transform expected=null){
|
126 |
| - if (!expected) { |
127 |
| - // test that actual is zeroed out |
128 |
| - Assert.AreEqual(Vector3.zero, actual.localPosition); |
129 |
| - Assert.AreEqual (Vector3.zero, actual.localEulerAngles); |
130 |
| - Assert.AreEqual (Vector3.one, actual.localScale); |
131 |
| - return; |
132 |
| - } |
133 |
| - float epsilon = 0.0001f; |
134 |
| - Assert.IsTrue (Vector3.SqrMagnitude(expected.position - actual.localPosition) < epsilon); |
135 |
| - Assert.IsTrue (Vector3.SqrMagnitude(expected.rotation.eulerAngles - actual.localEulerAngles) < epsilon); |
136 |
| - Assert.IsTrue (Vector3.SqrMagnitude(expected.lossyScale - actual.localScale) < epsilon); |
| 144 | + var actualMatrix = ConstructTRSMatrix (actual); |
| 145 | + var expectedMatrix = expected == null? new FbxAMatrix() : ConstructTRSMatrix (expected, false); |
| 146 | + Assert.AreEqual (expectedMatrix, actualMatrix); |
| 147 | + } |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// Constructs a TRS matrix (as an FbxAMatrix) from a tranform. |
| 151 | + /// </summary> |
| 152 | + /// <returns>The TRS matrix.</returns> |
| 153 | + /// <param name="t">Transform.</param> |
| 154 | + /// <param name="local">If set to <c>true</c> use local transform.</param> |
| 155 | + private FbxAMatrix ConstructTRSMatrix(Transform t, bool local=true) |
| 156 | + { |
| 157 | + var translation = local? t.localPosition : t.position; |
| 158 | + var rotation = local? t.localEulerAngles : t.eulerAngles; |
| 159 | + var scale = local? t.localScale : t.lossyScale; |
| 160 | + return new FbxAMatrix ( |
| 161 | + new FbxVector4 (translation.x, translation.y, translation.z), |
| 162 | + new FbxVector4 (rotation.x, rotation.y, rotation.z), |
| 163 | + new FbxVector4 (scale.x, scale.y, scale.z) |
| 164 | + ); |
137 | 165 | }
|
138 | 166 |
|
139 | 167 | private GameObject CreateHierarchy ()
|
|
0 commit comments