Skip to content

Commit dfaad3b

Browse files
committed
Merge branch 'UT-3102-use-deepconvert' into UT-2995-export-anim-curve-tangents
2 parents cb533ab + 260508b commit dfaad3b

File tree

6 files changed

+118
-144
lines changed

6 files changed

+118
-144
lines changed

com.unity.formats.fbx/Editor/FbxExporter.cs

Lines changed: 53 additions & 114 deletions
Large diffs are not rendered by default.

com.unity.formats.fbx/Editor/FbxRotationCurve.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
5454
: new FbxVector4();
5555

5656
// Get the inverse of the prerotation
57-
var fbxPreRotationInverse = ModelExporter.EulerToQuaternion (fbxPreRotationEuler);
57+
var fbxPreRotationInverse = ModelExporter.EulerToQuaternionXYZ (fbxPreRotationEuler);
5858
fbxPreRotationInverse.Inverse();
5959

6060
// Find when we have keys set.
@@ -76,10 +76,12 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
7676
// then animation.
7777
var fbxFinalQuat = fbxPreRotationInverse * fbxFinalAnimation;
7878

79+
var finalUnityQuat = new Quaternion((float)fbxFinalQuat.X, (float)fbxFinalQuat.Y, (float)fbxFinalQuat.Z, (float)fbxFinalQuat.W);
80+
7981
// Store the key so we can sort them later.
8082
Key key = new Key();
8183
key.time = FbxTime.FromSecondDouble(seconds);
82-
key.euler = ModelExporter.QuaternionToEuler (fbxFinalQuat);
84+
key.euler = ModelExporter.ConvertToFbxVector4(finalUnityQuat.eulerAngles);
8385
keys[i++] = key;
8486
}
8587

@@ -121,9 +123,6 @@ public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxA
121123
// Uni-35616 unroll curves to preserve continuous rotations
122124
var fbxCurveNode = fbxNode.LclRotation.GetCurveNode(fbxAnimLayer, false /*should already exist*/);
123125

124-
FbxAnimCurveFilterUnroll fbxAnimUnrollFilter = new FbxAnimCurveFilterUnroll();
125-
fbxAnimUnrollFilter.Apply(fbxCurveNode);
126-
127126
if (Verbose) {
128127
Debug.Log("Exported rotation animation for " + fbxNode.GetName());
129128
}
@@ -170,16 +169,15 @@ protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds,
170169
// The final animation, including the effect of pre-rotation.
171170
// If we have no curve, assume the node has the correct rotation right now.
172171
// We need to evaluate since we might only have keys in one of the axes.
173-
var unityFinalAnimation = Quaternion.Euler (
172+
var unityFinalAnimation = new Vector3 (
174173
(x == null) ? eulerRest [0] : x.Evaluate (seconds),
175174
(y == null) ? eulerRest [1] : y.Evaluate (seconds),
176175
(z == null) ? eulerRest [2] : z.Evaluate (seconds)
177176
);
178177

179178
// convert the final animation to righthanded coords
180-
var finalEuler = ModelExporter.ConvertQuaternionToXYZEuler(unityFinalAnimation);
181179

182-
return ModelExporter.EulerToQuaternion (new FbxVector4(finalEuler));
180+
return ModelExporter.EulerToQuaternionZXY (unityFinalAnimation);
183181
}
184182
}
185183

@@ -236,10 +234,7 @@ protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds,
236234
(z == null) ? restRotation[2] : z.Evaluate(seconds),
237235
(w == null) ? restRotation[3] : w.Evaluate(seconds));
238236

239-
// convert the final animation to righthanded coords
240-
var finalEuler = ModelExporter.ConvertQuaternionToXYZEuler(fbxFinalAnimation);
241-
242-
return ModelExporter.EulerToQuaternion (finalEuler);
237+
return fbxFinalAnimation;
243238
}
244239
}
245240

com.unity.formats.fbx/Tests/FbxTests/FbxAnimationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public static void KeyValuesTest (float [] expectedKeyTimes, float [] expectedKe
557557
#if DEBUG_UNITTEST
558558
Debug.Log(string.Format("key time={0} expected={1} actual={2} delta={3}", expectedKeyTime.ToString(), expectedKeyValue.ToString(), actualKeyValue.ToString(), Mathf.Abs(expectedKeyValue-actualKeyValue).ToString()));
559559
#endif
560-
Assert.That(expectedKeyValue, Is.EqualTo(actualKeyValue).Within(0.000001), string.Format("{0} key ({1}) doesn't match", message, expectedKeyTime));
560+
Assert.That(expectedKeyValue, Is.EqualTo(actualKeyValue).Within(0.0001), string.Format("{0} key ({1}) doesn't match", message, expectedKeyTime));
561561
}
562562
}
563563

com.unity.formats.fbx/Tests/FbxTests/ModelExporterTest.cs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ public void TestBasics ()
4343
var b = new Vector3(0,0,1);
4444
var crossLeft = Vector3.Cross(a,b);
4545

46-
var afbx = ModelExporter.ConvertToRightHanded(a);
47-
var bfbx = ModelExporter.ConvertToRightHanded(b);
48-
Assert.AreEqual(ModelExporter.ConvertToRightHanded(crossLeft), bfbx.CrossProduct(afbx));
49-
50-
// Test scale conversion. Nothing complicated here...
51-
var afbxPosition = ModelExporter.ConvertToRightHanded(a, ModelExporter.UnitScaleFactor);
52-
Assert.AreEqual(100, afbxPosition.Length());
53-
54-
// Test rotation conversion.
55-
var q = Quaternion.Euler(new Vector3(0, 90, 0));
56-
var fbxAngles = ModelExporter.ConvertQuaternionToXYZEuler(q);
57-
Assert.AreEqual(fbxAngles.X, 0);
58-
Assert.That(fbxAngles.Y, Is.InRange(-90.001, -89.999));
59-
Assert.AreEqual(fbxAngles.Z, 0);
60-
6146
Assert.That(ModelExporter.DefaultMaterial);
6247

6348
// Test non-static functions.
@@ -103,6 +88,32 @@ public void TestBasics ()
10388
ModelExporter.ExportObject(GetRandomFbxFilePath(), character);
10489
Assert.AreEqual(meshCount, Object.FindObjectsOfType<Mesh>().Length);
10590
}
91+
92+
// Test euler to quaternion conversion
93+
{
94+
// EulerToQuaternionZXY
95+
var v = new Vector3(50, 45, 190);
96+
var quat = ModelExporter.EulerToQuaternionZXY(v);
97+
var unityQuat = Quaternion.Euler(v);
98+
Assert.That((float)quat.X, Is.EqualTo(unityQuat.x));
99+
Assert.That((float)quat.Y, Is.EqualTo(unityQuat.y));
100+
Assert.That((float)quat.Z, Is.EqualTo(unityQuat.z));
101+
Assert.That((float)quat.W, Is.EqualTo(unityQuat.w));
102+
103+
// EulerToQuaternionXYZ
104+
var fbxV = new FbxVector4(v.x, v.y, v.z);
105+
var xyzQuat = ModelExporter.EulerToQuaternionXYZ(fbxV);
106+
107+
// get the vector from the quaternion
108+
FbxAMatrix m = new FbxAMatrix();
109+
m.SetR(fbxV);
110+
var actualQuat = m.GetQ();
111+
112+
// since this quaternion is XYZ instead of ZXY, it should not match the quaternion
113+
// created with EulerToQuaternionZXY
114+
Assert.That(xyzQuat, Is.Not.EqualTo(quat));
115+
Assert.That(xyzQuat, Is.EqualTo(actualQuat));
116+
}
106117
}
107118

108119
[Test]

com.unity.formats.fbx/Tests/Models/Player/Player.controller

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ AnimatorController:
2222
m_IKPass: 0
2323
m_SyncedLayerAffectsTiming: 0
2424
m_Controller: {fileID: 9100000}
25+
--- !u!1102 &380199431843810593
26+
AnimatorState:
27+
serializedVersion: 5
28+
m_ObjectHideFlags: 1
29+
m_CorrespondingSourceObject: {fileID: 0}
30+
m_PrefabInstance: {fileID: 0}
31+
m_PrefabAsset: {fileID: 0}
32+
m_Name: EulerAnimation 0
33+
m_Speed: 1
34+
m_CycleOffset: 0
35+
m_Transitions: []
36+
m_StateMachineBehaviours: []
37+
m_Position: {x: 50, y: 50, z: 0}
38+
m_IKOnFeet: 0
39+
m_WriteDefaultValues: 1
40+
m_Mirror: 0
41+
m_SpeedParameterActive: 0
42+
m_MirrorParameterActive: 0
43+
m_CycleOffsetParameterActive: 0
44+
m_TimeParameterActive: 0
45+
m_Motion: {fileID: 7400000, guid: dfbbf56ceff8a4b31b6f69b12073eefc, type: 2}
46+
m_Tag:
47+
m_SpeedParameter:
48+
m_MirrorParameter:
49+
m_CycleOffsetParameter:
50+
m_TimeParameter:
2551
--- !u!1102 &1102573189940394992
2652
AnimatorState:
2753
serializedVersion: 5
@@ -60,6 +86,9 @@ AnimatorStateMachine:
6086
- serializedVersion: 1
6187
m_State: {fileID: 1102573189940394992}
6288
m_Position: {x: 250, y: 170, z: 0}
89+
- serializedVersion: 1
90+
m_State: {fileID: 380199431843810593}
91+
m_Position: {x: 285, y: 235, z: 0}
6392
m_ChildStateMachines: []
6493
m_AnyStateTransitions: []
6594
m_EntryTransitions: []

com.unity.formats.fbx/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "2.0.3-preview.3",
55
"dependencies": {
66
"com.unity.timeline": "1.0.0",
7-
"com.autodesk.fbx": "2.0.1-preview.1"
7+
"com.autodesk.fbx": "3.0.0-preview.1"
88
},
99
"unity": "2018.3",
1010
"unityRelease": "4f1",
@@ -16,4 +16,4 @@
1616
"maya",
1717
"max"
1818
]
19-
}
19+
}

0 commit comments

Comments
 (0)