Skip to content

Commit 3f1ede8

Browse files
committed
fix skinned mesh animation export
- fix test failing because of precision - fix player controller example having an extra unconnected animation
1 parent 4068219 commit 3f1ede8

File tree

4 files changed

+49
-16
lines changed

4 files changed

+49
-16
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,21 +1160,15 @@ internal static FbxVector4 ToFbxVector4(FbxDouble3 v)
11601160
/// <param name="euler">Euler.</param>
11611161
internal static FbxQuaternion EulerToQuaternion(FbxVector4 euler)
11621162
{
1163-
FbxAMatrix m = new FbxAMatrix ();
1164-
m.SetR (euler);
1165-
return m.GetQ ();
1163+
var unityQuat = Quaternion.Euler(new Vector3((float)euler.X, (float)euler.Y, (float)euler.Z));
1164+
return new FbxQuaternion(unityQuat.x, unityQuat.y, unityQuat.z, unityQuat.w);
11661165
}
11671166

1168-
/// <summary>
1169-
/// Quaternion to euler without axis conversion.
1170-
/// </summary>
1171-
/// <returns>a euler.</returns>
1172-
/// <param name="quat">Quaternion.</param>
1173-
internal static FbxVector4 QuaternionToEuler(FbxQuaternion quat)
1167+
internal static FbxQuaternion EulerToQuaternionXYZ(FbxVector4 euler)
11741168
{
11751169
FbxAMatrix m = new FbxAMatrix ();
1176-
m.SetQ (quat);
1177-
return m.GetR ();
1170+
m.SetR (euler);
1171+
return m.GetQ ();
11781172
}
11791173

11801174
// get a fbxNode's global default position.
@@ -2715,6 +2709,13 @@ AnimationOnlyExportData exportData
27152709
return false;
27162710
}
27172711

2712+
// Rotation order and rotation active must be set before setting the transform, otherwise
2713+
// values may change if setting the rotation order afterwards.
2714+
if (!fbxNode.GetRotationActive())
2715+
{
2716+
fbxNode.SetRotationOrder(FbxNode.EPivotSet.eSourcePivot, FbxEuler.EOrder.eOrderZXY);
2717+
fbxNode.SetRotationActive(true);
2718+
}
27182719
ExportBoneTransform(fbxNode, fbxScene, bone.transform, boneInfo);
27192720
}
27202721
}
@@ -3336,10 +3337,11 @@ internal int ExportAll (
33363337
// The Maya axis system has Y up, Z forward, X to the left (right handed system with odd parity).
33373338
// We need to export right-handed for Maya because ConvertScene can't switch handedness:
33383339
// https://forums.autodesk.com/t5/fbx-forum/get-confused-with-fbxaxissystem-convertscene/td-p/4265472
3339-
fbxSettings.SetAxisSystem (new FbxAxisSystem(
3340+
var unityAxisSystem = new FbxAxisSystem(
33403341
FbxAxisSystem.EUpVector.eYAxis,
33413342
FbxAxisSystem.EFrontVector.eParityOdd,
3342-
FbxAxisSystem.ECoordSystem.eLeftHanded));
3343+
FbxAxisSystem.ECoordSystem.eLeftHanded);
3344+
fbxSettings.SetAxisSystem (unityAxisSystem);
33433345

33443346
// export set of object
33453347
FbxNode fbxRootNode = fbxScene.GetRootNode ();

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

Lines changed: 4 additions & 2 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

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/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: []

0 commit comments

Comments
 (0)