Skip to content

Commit 1c03bc2

Browse files
committed
code review fixes
- use curve array instead of explicitely defining variable for each curve - add documentation to getindex functions
1 parent eaa79b3 commit 1c03bc2

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,9 +1737,7 @@ public void Dispose()
17371737
/// </summary>
17381738
abstract class RotationCurve {
17391739
public double sampleRate;
1740-
public AnimationCurve x;
1741-
public AnimationCurve y;
1742-
public AnimationCurve z;
1740+
public AnimationCurve[] m_curves;
17431741

17441742
public struct Key {
17451743
public FbxTime time;
@@ -1748,13 +1746,11 @@ public struct Key {
17481746

17491747
public RotationCurve() { }
17501748

1751-
public virtual void SetCurve(int i, AnimationCurve curve) {
1752-
switch(i) {
1753-
case 0: x = curve; break;
1754-
case 1: y = curve; break;
1755-
case 2: z = curve; break;
1756-
default: throw new System.IndexOutOfRangeException();
1749+
public void SetCurve(int i, AnimationCurve curve) {
1750+
if (i < 0 || i >= m_curves.Length) {
1751+
throw new System.IndexOutOfRangeException();
17571752
}
1753+
m_curves [i] = curve;
17581754
}
17591755

17601756
protected abstract FbxQuaternion GetConvertedQuaternionRotation (float seconds, UnityEngine.Quaternion restRotation);
@@ -1771,11 +1767,10 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
17711767
fbxPreRotationInverse.Inverse();
17721768

17731769
// Find when we have keys set.
1774-
var animCurves = new AnimationCurve[]{x,y,z};
17751770
var keyTimes =
17761771
(FbxExporters.Editor.ModelExporter.ExportSettings.BakeAnimation)
1777-
? ModelExporter.GetSampleTimes(animCurves, sampleRate)
1778-
: ModelExporter.GetKeyTimes(animCurves);
1772+
? ModelExporter.GetSampleTimes(m_curves, sampleRate)
1773+
: ModelExporter.GetKeyTimes(m_curves);
17791774

17801775
// Convert to the Key type.
17811776
var keys = new Key[keyTimes.Count];
@@ -1843,8 +1838,14 @@ public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxA
18431838
/// prerotation from animated rotation.
18441839
/// </summary>
18451840
class EulerCurve : RotationCurve {
1846-
public EulerCurve() { }
1841+
public EulerCurve() { m_curves = new AnimationCurve[3]; }
18471842

1843+
/// <summary>
1844+
/// Gets the index of the euler curve by property name.
1845+
/// x = 0, y = 1, z = 2
1846+
/// </summary>
1847+
/// <returns>The index of the curve, or -1 if property doesn't map to Euler curve.</returns>
1848+
/// <param name="uniPropertyName">Unity property name.</param>
18481849
public static int GetEulerIndex(string uniPropertyName) {
18491850
System.StringComparison ct = System.StringComparison.CurrentCulture;
18501851
bool isEulerComponent = uniPropertyName.StartsWith ("localEulerAnglesRaw.", ct);
@@ -1862,17 +1863,19 @@ public static int GetEulerIndex(string uniPropertyName) {
18621863
protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds, Quaternion restRotation)
18631864
{
18641865
var eulerRest = restRotation.eulerAngles;
1866+
AnimationCurve x = m_curves [0], y = m_curves [1], z = m_curves [2];
1867+
18651868
// The final animation, including the effect of pre-rotation.
18661869
// If we have no curve, assume the node has the correct rotation right now.
18671870
// We need to evaluate since we might only have keys in one of the axes.
1868-
var fbxFinalAnimation = Quaternion.Euler (
1871+
var unityFinalAnimation = Quaternion.Euler (
18691872
(x == null) ? eulerRest [0] : x.Evaluate (seconds),
18701873
(y == null) ? eulerRest [1] : y.Evaluate (seconds),
18711874
(z == null) ? eulerRest [2] : z.Evaluate (seconds)
18721875
);
18731876

18741877
// convert the final animation to righthanded coords
1875-
var finalEuler = ModelExporter.ConvertQuaternionToXYZEuler(fbxFinalAnimation);
1878+
var finalEuler = ModelExporter.ConvertQuaternionToXYZEuler(unityFinalAnimation);
18761879

18771880
return ModelExporter.EulerToQuaternion (new FbxVector4(finalEuler));
18781881
}
@@ -1883,10 +1886,15 @@ protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds,
18831886
/// from quaternion to euler. We use this class to help.
18841887
/// </summary>
18851888
class QuaternionCurve : RotationCurve {
1886-
public AnimationCurve w;
18871889

1888-
public QuaternionCurve() { }
1890+
public QuaternionCurve() { m_curves = new AnimationCurve[4]; }
18891891

1892+
/// <summary>
1893+
/// Gets the index of the curve by property name.
1894+
/// x = 0, y = 1, z = 2, w = 3
1895+
/// </summary>
1896+
/// <returns>The index of the curve, or -1 if property doesn't map to Quaternion curve.</returns>
1897+
/// <param name="uniPropertyName">Unity property name.</param>
18901898
public static int GetQuaternionIndex(string uniPropertyName) {
18911899
System.StringComparison ct = System.StringComparison.CurrentCulture;
18921900
bool isQuaternionComponent = false;
@@ -1908,18 +1916,10 @@ public static int GetQuaternionIndex(string uniPropertyName) {
19081916
}
19091917
}
19101918

1911-
public override void SetCurve(int i, AnimationCurve curve) {
1912-
switch(i) {
1913-
case 0: x = curve; break;
1914-
case 1: y = curve; break;
1915-
case 2: z = curve; break;
1916-
case 3: w = curve; break;
1917-
default: throw new System.IndexOutOfRangeException();
1918-
}
1919-
}
1920-
19211919
protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds, Quaternion restRotation)
19221920
{
1921+
AnimationCurve x = m_curves [0], y = m_curves [1], z = m_curves [2], w = m_curves[3];
1922+
19231923
// The final animation, including the effect of pre-rotation.
19241924
// If we have no curve, assume the node has the correct rotation right now.
19251925
// We need to evaluate since we might only have keys in one of the axes.

0 commit comments

Comments
 (0)