Skip to content

Commit 6a2d5b8

Browse files
committed
fix FbxRotationCurve warnings
1 parent ff3db28 commit 6a2d5b8

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

Assets/com.unity.formats.fbx.tests/RotationCurveTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public void TestBasics() {
2323
var animCurve = new AnimationCurve();
2424

2525
eulerCurve.SetCurve (2, animCurve);
26-
Assert.That (eulerCurve.m_curves [2], Is.EqualTo (animCurve));
26+
Assert.That (eulerCurve.Curves [2], Is.EqualTo (animCurve));
2727

2828
Assert.That(() => eulerCurve.SetCurve (-1, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
2929
Assert.That(() => eulerCurve.SetCurve (3, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
3030

3131
quaternionCurve.SetCurve (3, animCurve);
32-
Assert.That (quaternionCurve.m_curves [3], Is.EqualTo (animCurve));
32+
Assert.That (quaternionCurve.Curves [3], Is.EqualTo (animCurve));
3333

3434
Assert.That(() => quaternionCurve.SetCurve (-5, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
3535
Assert.That(() => quaternionCurve.SetCurve (4, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ ref Dictionary<GameObject, RotationCurve> rotations
24112411
{
24122412
RotationCurve rotCurve;
24132413
if (!rotations.TryGetValue (uniGO, out rotCurve)) {
2414-
rotCurve = new T { sampleRate = frameRate };
2414+
rotCurve = new T { SampleRate = frameRate };
24152415
rotations.Add (uniGO, rotCurve);
24162416
}
24172417
return rotCurve;

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

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,30 @@ namespace UnityEditor.Formats.Fbx.Exporter
1010
/// for euler rotation.
1111
/// </summary>
1212
public abstract class RotationCurve {
13-
public double sampleRate;
14-
public AnimationCurve[] m_curves;
13+
private double m_sampleRate;
14+
public double SampleRate
15+
{
16+
get { return m_sampleRate; }
17+
set { m_sampleRate = value; }
18+
}
19+
20+
private AnimationCurve[] m_curves;
21+
public AnimationCurve[] Curves
22+
{
23+
get { return m_curves; }
24+
set { m_curves = value; }
25+
}
26+
1527

16-
public struct Key {
28+
protected struct Key {
1729
public FbxTime time;
1830
public FbxVector4 euler;
1931
}
2032

21-
public RotationCurve() { }
33+
protected RotationCurve() { }
2234

2335
public void SetCurve(int i, AnimationCurve curve) {
24-
m_curves [i] = curve;
36+
Curves [i] = curve;
2537
}
2638

2739
protected abstract FbxQuaternion GetConvertedQuaternionRotation (float seconds, UnityEngine.Quaternion restRotation);
@@ -40,8 +52,8 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
4052
// Find when we have keys set.
4153
var keyTimes =
4254
(UnityEditor.Formats.Fbx.Exporter.ModelExporter.ExportSettings.BakeAnimation)
43-
? ModelExporter.GetSampleTimes(m_curves, sampleRate)
44-
: ModelExporter.GetKeyTimes(m_curves);
55+
? ModelExporter.GetSampleTimes(Curves, SampleRate)
56+
: ModelExporter.GetKeyTimes(Curves);
4557

4658
// Convert to the Key type.
4759
var keys = new Key[keyTimes.Count];
@@ -71,6 +83,11 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
7183

7284
public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxAnimLayer, bool Verbose) {
7385

86+
if(!unityTransform || fbxNode == null)
87+
{
88+
return;
89+
}
90+
7491
/* Find or create the three curves. */
7592
var fbxAnimCurveX = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_X, true);
7693
var fbxAnimCurveY = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_Y, true);
@@ -109,7 +126,7 @@ public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxA
109126
/// prerotation from animated rotation.
110127
/// </summary>
111128
public class EulerCurve : RotationCurve {
112-
public EulerCurve() { m_curves = new AnimationCurve[3]; }
129+
public EulerCurve() { Curves = new AnimationCurve[3]; }
113130

114131
/// <summary>
115132
/// Gets the index of the euler curve by property name.
@@ -118,6 +135,11 @@ public class EulerCurve : RotationCurve {
118135
/// <returns>The index of the curve, or -1 if property doesn't map to Euler curve.</returns>
119136
/// <param name="uniPropertyName">Unity property name.</param>
120137
public static int GetEulerIndex(string uniPropertyName) {
138+
if (string.IsNullOrEmpty(uniPropertyName))
139+
{
140+
return -1;
141+
}
142+
121143
System.StringComparison ct = System.StringComparison.CurrentCulture;
122144
bool isEulerComponent = uniPropertyName.StartsWith ("localEulerAnglesRaw.", ct);
123145

@@ -134,7 +156,7 @@ public static int GetEulerIndex(string uniPropertyName) {
134156
protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds, Quaternion restRotation)
135157
{
136158
var eulerRest = restRotation.eulerAngles;
137-
AnimationCurve x = m_curves [0], y = m_curves [1], z = m_curves [2];
159+
AnimationCurve x = Curves [0], y = Curves [1], z = Curves [2];
138160

139161
// The final animation, including the effect of pre-rotation.
140162
// If we have no curve, assume the node has the correct rotation right now.
@@ -158,7 +180,7 @@ protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds,
158180
/// </summary>
159181
public class QuaternionCurve : RotationCurve {
160182

161-
public QuaternionCurve() { m_curves = new AnimationCurve[4]; }
183+
public QuaternionCurve() { Curves = new AnimationCurve[4]; }
162184

163185
/// <summary>
164186
/// Gets the index of the curve by property name.
@@ -167,6 +189,11 @@ public class QuaternionCurve : RotationCurve {
167189
/// <returns>The index of the curve, or -1 if property doesn't map to Quaternion curve.</returns>
168190
/// <param name="uniPropertyName">Unity property name.</param>
169191
public static int GetQuaternionIndex(string uniPropertyName) {
192+
if (string.IsNullOrEmpty(uniPropertyName))
193+
{
194+
return -1;
195+
}
196+
170197
System.StringComparison ct = System.StringComparison.CurrentCulture;
171198
bool isQuaternionComponent = false;
172199

@@ -189,7 +216,7 @@ public static int GetQuaternionIndex(string uniPropertyName) {
189216

190217
protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds, Quaternion restRotation)
191218
{
192-
AnimationCurve x = m_curves [0], y = m_curves [1], z = m_curves [2], w = m_curves[3];
219+
AnimationCurve x = Curves [0], y = Curves [1], z = Curves [2], w = Curves[3];
193220

194221
// The final animation, including the effect of pre-rotation.
195222
// If we have no curve, assume the node has the correct rotation right now.
@@ -233,7 +260,7 @@ public void Dispose()
233260
System.GC.SuppressFinalize(this);
234261
}
235262

236-
public virtual void Dispose(bool cleanUpManaged)
263+
protected virtual void Dispose(bool cleanUpManaged)
237264
{
238265
foreach (var curve in Curves)
239266
curve.KeyModifyEnd();

0 commit comments

Comments
 (0)