Skip to content

Commit eaa79b3

Browse files
committed
move duplicate code to parent class
1 parent bd48a1c commit eaa79b3

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ public virtual void SetCurve(int i, AnimationCurve curve) {
17571757
}
17581758
}
17591759

1760-
protected abstract FbxVector4 GetFinalEulerRotation (float seconds, UnityEngine.Quaternion restRotation, FbxQuaternion preRotationInverse);
1760+
protected abstract FbxQuaternion GetConvertedQuaternionRotation (float seconds, UnityEngine.Quaternion restRotation);
17611761

17621762
private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
17631763
// Get the source pivot pre-rotation if any, so we can
@@ -1781,10 +1781,19 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
17811781
var keys = new Key[keyTimes.Count];
17821782
int i = 0;
17831783
foreach(var seconds in keyTimes) {
1784+
var fbxFinalAnimation = GetConvertedQuaternionRotation (seconds, restRotation);
1785+
1786+
// Cancel out the pre-rotation. Order matters. FBX reads left-to-right.
1787+
// When we run animation we will apply:
1788+
// pre-rotation
1789+
// then pre-rotation inverse
1790+
// then animation.
1791+
var fbxFinalQuat = fbxPreRotationInverse * fbxFinalAnimation;
1792+
17841793
// Store the key so we can sort them later.
17851794
Key key;
17861795
key.time = FbxTime.FromSecondDouble(seconds);
1787-
key.euler = GetFinalEulerRotation (seconds, restRotation, fbxPreRotationInverse);
1796+
key.euler = ModelExporter.QuaternionToEuler (fbxFinalQuat);
17881797
keys[i++] = key;
17891798
}
17901799

@@ -1850,7 +1859,7 @@ public static int GetEulerIndex(string uniPropertyName) {
18501859
}
18511860
}
18521861

1853-
protected override FbxVector4 GetFinalEulerRotation (float seconds, Quaternion restRotation, FbxQuaternion preRotationInverse)
1862+
protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds, Quaternion restRotation)
18541863
{
18551864
var eulerRest = restRotation.eulerAngles;
18561865
// The final animation, including the effect of pre-rotation.
@@ -1865,17 +1874,7 @@ protected override FbxVector4 GetFinalEulerRotation (float seconds, Quaternion r
18651874
// convert the final animation to righthanded coords
18661875
var finalEuler = ModelExporter.ConvertQuaternionToXYZEuler(fbxFinalAnimation);
18671876

1868-
// convert it back to a quaternion for multiplication
1869-
var quat = ModelExporter.EulerToQuaternion (new FbxVector4(finalEuler));
1870-
1871-
// Cancel out the pre-rotation. Order matters. FBX reads left-to-right.
1872-
// When we run animation we will apply:
1873-
// pre-rotation
1874-
// then pre-rotation inverse
1875-
// then animation.
1876-
var fbxFinalQuat = preRotationInverse * quat;
1877-
1878-
return ModelExporter.QuaternionToEuler (fbxFinalQuat);
1877+
return ModelExporter.EulerToQuaternion (new FbxVector4(finalEuler));
18791878
}
18801879
}
18811880

@@ -1919,7 +1918,7 @@ public override void SetCurve(int i, AnimationCurve curve) {
19191918
}
19201919
}
19211920

1922-
protected override FbxVector4 GetFinalEulerRotation (float seconds, Quaternion restRotation, FbxQuaternion preRotationInverse)
1921+
protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds, Quaternion restRotation)
19231922
{
19241923
// The final animation, including the effect of pre-rotation.
19251924
// If we have no curve, assume the node has the correct rotation right now.
@@ -1933,17 +1932,7 @@ protected override FbxVector4 GetFinalEulerRotation (float seconds, Quaternion r
19331932
// convert the final animation to righthanded coords
19341933
var finalEuler = ModelExporter.ConvertQuaternionToXYZEuler(fbxFinalAnimation);
19351934

1936-
// convert it back to a quaternion for multiplication
1937-
fbxFinalAnimation = ModelExporter.EulerToQuaternion (finalEuler);
1938-
1939-
// Cancel out the pre-rotation. Order matters. FBX reads left-to-right.
1940-
// When we run animation we will apply:
1941-
// pre-rotation
1942-
// then pre-rotation inverse
1943-
// then animation.
1944-
var fbxFinalQuat = preRotationInverse * fbxFinalAnimation;
1945-
1946-
return ModelExporter.QuaternionToEuler (fbxFinalQuat);
1935+
return ModelExporter.EulerToQuaternion (finalEuler);
19471936
}
19481937
}
19491938

0 commit comments

Comments
 (0)