Skip to content

Commit 122d3f0

Browse files
committed
code review fixes
1 parent 2fd8f55 commit 122d3f0

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

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

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,22 +1148,22 @@ internal static FbxDouble3 ToFbxDouble3(FbxVector4 v)
11481148
return new FbxDouble3(v.X, v.Y, v.Z);
11491149
}
11501150

1151-
internal static FbxVector4 ToFbxVector4(FbxDouble3 v)
1152-
{
1153-
return new FbxVector4(v.X, v.Y, v.Z);
1154-
}
1155-
11561151
/// <summary>
1157-
/// Euler to quaternion without axis conversion.
1152+
/// Euler (roll/pitch/yaw (ZXY rotation order) to quaternion.
11581153
/// </summary>
11591154
/// <returns>a quaternion.</returns>
1160-
/// <param name="euler">Euler.</param>
1155+
/// <param name="euler">ZXY Euler.</param>
11611156
internal static FbxQuaternion EulerToQuaternionZXY(Vector3 euler)
11621157
{
11631158
var unityQuat = Quaternion.Euler(euler);
11641159
return new FbxQuaternion(unityQuat.x, unityQuat.y, unityQuat.z, unityQuat.w);
11651160
}
11661161

1162+
/// <summary>
1163+
/// Euler X/Y/Z rotation order to quaternion.
1164+
/// </summary>
1165+
/// <param name="euler">XYZ Euler.</param>
1166+
/// <returns>a quaternion</returns>
11671167
internal static FbxQuaternion EulerToQuaternionXYZ(FbxVector4 euler)
11681168
{
11691169
FbxAMatrix m = new FbxAMatrix ();
@@ -1174,11 +1174,6 @@ internal static FbxQuaternion EulerToQuaternionXYZ(FbxVector4 euler)
11741174
// get a fbxNode's global default position.
11751175
internal bool ExportTransform (UnityEngine.Transform unityTransform, FbxNode fbxNode, Vector3 newCenter, TransformExportType exportType)
11761176
{
1177-
// Fbx rotation order is XYZ, but Unity rotation order is ZXY.
1178-
// Also, DeepConvert does not convert the rotation order (assumes XYZ), unless RotationActive is true.
1179-
fbxNode.SetRotationOrder (FbxNode.EPivotSet.eSourcePivot, FbxEuler.EOrder.eOrderZXY);
1180-
fbxNode.SetRotationActive(true);
1181-
11821177
UnityEngine.Vector3 unityTranslate;
11831178
FbxDouble3 fbxRotate;
11841179
UnityEngine.Vector3 unityScale;
@@ -1638,7 +1633,7 @@ private bool ExportParentConstraint(IConstraint uniConstraint, FbxScene fbxScene
16381633
var fbxTranslationOffset = ConvertToFbxVector4(uniTranslationOffset, UnitScaleFactor);
16391634
fbxParentConstraint.SetTranslationOffset(uniSource.node, fbxTranslationOffset);
16401635

1641-
var fbxRotationOffset = ToFbxVector4(ToFbxDouble3(uniRotationOffset));
1636+
var fbxRotationOffset = ConvertToFbxVector4(uniRotationOffset);
16421637
fbxParentConstraint.SetRotationOffset(uniSource.node, fbxRotationOffset);
16431638
}
16441639
ExportCommonConstraintProperties(uniParentConstraint, fbxParentConstraint, fbxNode);
@@ -2500,6 +2495,11 @@ private FbxNode CreateFbxNode(GameObject unityGo, FbxScene fbxScene)
25002495
// Use RSrs as the scaling inheritance instead.
25012496
fbxNode.SetTransformationInheritType(FbxTransform.EInheritType.eInheritRSrs);
25022497

2498+
// Fbx rotation order is XYZ, but Unity rotation order is ZXY.
2499+
// Also, DeepConvert does not convert the rotation order (assumes XYZ), unless RotationActive is true.
2500+
fbxNode.SetRotationOrder(FbxNode.EPivotSet.eSourcePivot, FbxEuler.EOrder.eOrderZXY);
2501+
fbxNode.SetRotationActive(true);
2502+
25032503
MapUnityObjectToFbxNode[unityGo] = fbxNode;
25042504

25052505
return fbxNode;
@@ -2708,14 +2708,6 @@ AnimationOnlyExportData exportData
27082708
// cancel silently
27092709
return false;
27102710
}
2711-
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-
}
27192711
ExportBoneTransform(fbxNode, fbxScene, bone.transform, boneInfo);
27202712
}
27212713
}
@@ -3334,13 +3326,8 @@ internal int ExportAll (
33343326
fbxSettings.SetSystemUnit (FbxSystemUnit.cm);
33353327

33363328
// The Unity axis system has Y up, Z forward, X to the right (left handed system with odd parity).
3337-
// The Maya axis system has Y up, Z forward, X to the left (right handed system with odd parity).
3338-
// We need to export right-handed for Maya because ConvertScene can't switch handedness:
3339-
// https://forums.autodesk.com/t5/fbx-forum/get-confused-with-fbxaxissystem-convertscene/td-p/4265472
3340-
var unityAxisSystem = new FbxAxisSystem(
3341-
FbxAxisSystem.EUpVector.eYAxis,
3342-
FbxAxisSystem.EFrontVector.eParityOdd,
3343-
FbxAxisSystem.ECoordSystem.eLeftHanded);
3329+
// DirectX has the same axis system, so use this constant.
3330+
var unityAxisSystem = FbxAxisSystem.DirectX;
33443331
fbxSettings.SetAxisSystem (unityAxisSystem);
33453332

33463333
// export set of object
@@ -3425,6 +3412,10 @@ internal int ExportAll (
34253412
// Set the scene's default camera.
34263413
SetDefaultCamera (fbxScene);
34273414

3415+
// The Maya axis system has Y up, Z forward, X to the left (right handed system with odd parity).
3416+
// We need to export right-handed for Maya because ConvertScene (used by Maya and Max importers) can't switch handedness:
3417+
// https://forums.autodesk.com/t5/fbx-forum/get-confused-with-fbxaxissystem-convertscene/td-p/4265472
3418+
// This needs to be done last so that everything is converted properly.
34283419
FbxAxisSystem.MayaYUp.DeepConvertScene(fbxScene);
34293420

34303421
// Export the scene to the file.

0 commit comments

Comments
 (0)