Skip to content

Commit dffa561

Browse files
committed
code review fixes
-Added comment about what default selection behavior is -compare transform using FbxAMatrix
1 parent f423ac4 commit dffa561

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

Assets/FbxExporters/Editor/UnitTests/DefaultSelectionTest.cs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NUnit.Framework;
55
using System.IO;
66
using System.Collections.Generic;
7+
using FbxSdk;
78

89
namespace FbxExporters.UnitTests
910
{
@@ -76,6 +77,22 @@ public void Term ()
7677
[Test]
7778
public void TestDefaultSelection ()
7879
{
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+
7996
m_root = CreateHierarchy ();
8097
Assert.IsNotNull (m_root);
8198

@@ -119,21 +136,32 @@ public void TestDefaultSelection ()
119136
/// <summary>
120137
/// Compares the global transform of expected
121138
/// to the local transform of actual.
139+
/// If expected is null, then compare to the identity matrix.
122140
/// </summary>
123141
/// <param name="actual">Actual.</param>
124142
/// <param name="expected">Expected.</param>
125143
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+
);
137165
}
138166

139167
private GameObject CreateHierarchy ()

0 commit comments

Comments
 (0)