Skip to content

Commit 7c049cc

Browse files
committed
move duplicate code into function
1 parent f3d8b03 commit 7c049cc

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,18 +1947,8 @@ private void TransferMotion(Transform source, Transform dest, float sampleRate,
19471947
// child * parent
19481948
var newLocalMatrix = sourceLocalMatrix * destLocalMatrix;
19491949

1950-
// FBX is transposed relative to Unity: transpose as we convert.
1951-
FbxMatrix matrix = new FbxMatrix ();
1952-
matrix.SetColumn (0, new FbxVector4 (newLocalMatrix.GetRow (0).x, newLocalMatrix.GetRow (0).y, newLocalMatrix.GetRow (0).z, newLocalMatrix.GetRow (0).w));
1953-
matrix.SetColumn (1, new FbxVector4 (newLocalMatrix.GetRow (1).x, newLocalMatrix.GetRow (1).y, newLocalMatrix.GetRow (1).z, newLocalMatrix.GetRow (1).w));
1954-
matrix.SetColumn (2, new FbxVector4 (newLocalMatrix.GetRow (2).x, newLocalMatrix.GetRow (2).y, newLocalMatrix.GetRow (2).z, newLocalMatrix.GetRow (2).w));
1955-
matrix.SetColumn (3, new FbxVector4 (newLocalMatrix.GetRow (3).x, newLocalMatrix.GetRow (3).y, newLocalMatrix.GetRow (3).z, newLocalMatrix.GetRow (3).w));
1956-
1957-
// FBX wants translation, rotation (in euler angles) and scale.
1958-
// We assume there's no real shear, just rounding error.
1959-
FbxVector4 translation, rotation, shear, scale;
1960-
double sign;
1961-
matrix.GetElements (out translation, out rotation, out shear, out scale, out sign);
1950+
FbxVector4 translation, rotation, scale;
1951+
GetTRSFromMatrix (newLocalMatrix, out translation, out rotation, out scale);
19621952

19631953
// get rotation directly from matrix, as otherwise causes issues
19641954
// with negative rotations.
@@ -2624,18 +2614,8 @@ private bool ExportBoneTransform(
26242614
pose = parentBindPose * bindPose.inverse;
26252615
}
26262616

2627-
// FBX is transposed relative to Unity: transpose as we convert.
2628-
FbxMatrix matrix = new FbxMatrix ();
2629-
matrix.SetColumn (0, new FbxVector4 (pose.GetRow (0).x, pose.GetRow (0).y, pose.GetRow (0).z, pose.GetRow (0).w));
2630-
matrix.SetColumn (1, new FbxVector4 (pose.GetRow (1).x, pose.GetRow (1).y, pose.GetRow (1).z, pose.GetRow (1).w));
2631-
matrix.SetColumn (2, new FbxVector4 (pose.GetRow (2).x, pose.GetRow (2).y, pose.GetRow (2).z, pose.GetRow (2).w));
2632-
matrix.SetColumn (3, new FbxVector4 (pose.GetRow (3).x, pose.GetRow (3).y, pose.GetRow (3).z, pose.GetRow (3).w));
2633-
2634-
// FBX wants translation, rotation (in euler angles) and scale.
2635-
// We assume there's no real shear, just rounding error.
2636-
FbxVector4 translation, rotation, shear, scale;
2637-
double sign;
2638-
matrix.GetElements (out translation, out rotation, out shear, out scale, out sign);
2617+
FbxVector4 translation, rotation, scale;
2618+
GetTRSFromMatrix (pose, out translation, out rotation, out scale);
26392619

26402620
// Export bones with zero rotation, using a pivot instead to set the rotation
26412621
// so that the bones are easier to animate and the rotation shows up as the "joint orientation" in Maya.
@@ -2651,6 +2631,21 @@ private bool ExportBoneTransform(
26512631
return true;
26522632
}
26532633

2634+
private void GetTRSFromMatrix(Matrix4x4 unityMatrix, out FbxVector4 translation, out FbxVector4 rotation, out FbxVector4 scale){
2635+
// FBX is transposed relative to Unity: transpose as we convert.
2636+
FbxMatrix matrix = new FbxMatrix ();
2637+
matrix.SetColumn (0, new FbxVector4 (unityMatrix.GetRow (0).x, unityMatrix.GetRow (0).y, unityMatrix.GetRow (0).z, unityMatrix.GetRow (0).w));
2638+
matrix.SetColumn (1, new FbxVector4 (unityMatrix.GetRow (1).x, unityMatrix.GetRow (1).y, unityMatrix.GetRow (1).z, unityMatrix.GetRow (1).w));
2639+
matrix.SetColumn (2, new FbxVector4 (unityMatrix.GetRow (2).x, unityMatrix.GetRow (2).y, unityMatrix.GetRow (2).z, unityMatrix.GetRow (2).w));
2640+
matrix.SetColumn (3, new FbxVector4 (unityMatrix.GetRow (3).x, unityMatrix.GetRow (3).y, unityMatrix.GetRow (3).z, unityMatrix.GetRow (3).w));
2641+
2642+
// FBX wants translation, rotation (in euler angles) and scale.
2643+
// We assume there's no real shear, just rounding error.
2644+
FbxVector4 shear;
2645+
double sign;
2646+
matrix.GetElements (out translation, out rotation, out shear, out scale, out sign);
2647+
}
2648+
26542649
/// <summary>
26552650
/// Counts how many objects are between this object and the root (exclusive).
26562651
/// </summary>

0 commit comments

Comments
 (0)