@@ -10,18 +10,30 @@ namespace UnityEditor.Formats.Fbx.Exporter
10
10
/// for euler rotation.
11
11
/// </summary>
12
12
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
+
15
27
16
- public struct Key {
28
+ protected struct Key {
17
29
public FbxTime time ;
18
30
public FbxVector4 euler ;
19
31
}
20
32
21
- public RotationCurve ( ) { }
33
+ protected RotationCurve ( ) { }
22
34
23
35
public void SetCurve ( int i , AnimationCurve curve ) {
24
- m_curves [ i ] = curve ;
36
+ Curves [ i ] = curve ;
25
37
}
26
38
27
39
protected abstract FbxQuaternion GetConvertedQuaternionRotation ( float seconds , UnityEngine . Quaternion restRotation ) ;
@@ -40,8 +52,8 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
40
52
// Find when we have keys set.
41
53
var keyTimes =
42
54
( 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 ) ;
45
57
46
58
// Convert to the Key type.
47
59
var keys = new Key [ keyTimes . Count ] ;
@@ -71,6 +83,11 @@ private Key [] ComputeKeys(UnityEngine.Quaternion restRotation, FbxNode node) {
71
83
72
84
public void Animate ( Transform unityTransform , FbxNode fbxNode , FbxAnimLayer fbxAnimLayer , bool Verbose ) {
73
85
86
+ if ( ! unityTransform || fbxNode == null )
87
+ {
88
+ return ;
89
+ }
90
+
74
91
/* Find or create the three curves. */
75
92
var fbxAnimCurveX = fbxNode . LclRotation . GetCurve ( fbxAnimLayer , Globals . FBXSDK_CURVENODE_COMPONENT_X , true ) ;
76
93
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
109
126
/// prerotation from animated rotation.
110
127
/// </summary>
111
128
public class EulerCurve : RotationCurve {
112
- public EulerCurve ( ) { m_curves = new AnimationCurve [ 3 ] ; }
129
+ public EulerCurve ( ) { Curves = new AnimationCurve [ 3 ] ; }
113
130
114
131
/// <summary>
115
132
/// Gets the index of the euler curve by property name.
@@ -118,6 +135,11 @@ public class EulerCurve : RotationCurve {
118
135
/// <returns>The index of the curve, or -1 if property doesn't map to Euler curve.</returns>
119
136
/// <param name="uniPropertyName">Unity property name.</param>
120
137
public static int GetEulerIndex ( string uniPropertyName ) {
138
+ if ( string . IsNullOrEmpty ( uniPropertyName ) )
139
+ {
140
+ return - 1 ;
141
+ }
142
+
121
143
System . StringComparison ct = System . StringComparison . CurrentCulture ;
122
144
bool isEulerComponent = uniPropertyName . StartsWith ( "localEulerAnglesRaw." , ct ) ;
123
145
@@ -134,7 +156,7 @@ public static int GetEulerIndex(string uniPropertyName) {
134
156
protected override FbxQuaternion GetConvertedQuaternionRotation ( float seconds , Quaternion restRotation )
135
157
{
136
158
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 ] ;
138
160
139
161
// The final animation, including the effect of pre-rotation.
140
162
// If we have no curve, assume the node has the correct rotation right now.
@@ -158,7 +180,7 @@ protected override FbxQuaternion GetConvertedQuaternionRotation (float seconds,
158
180
/// </summary>
159
181
public class QuaternionCurve : RotationCurve {
160
182
161
- public QuaternionCurve ( ) { m_curves = new AnimationCurve [ 4 ] ; }
183
+ public QuaternionCurve ( ) { Curves = new AnimationCurve [ 4 ] ; }
162
184
163
185
/// <summary>
164
186
/// Gets the index of the curve by property name.
@@ -167,6 +189,11 @@ public class QuaternionCurve : RotationCurve {
167
189
/// <returns>The index of the curve, or -1 if property doesn't map to Quaternion curve.</returns>
168
190
/// <param name="uniPropertyName">Unity property name.</param>
169
191
public static int GetQuaternionIndex ( string uniPropertyName ) {
192
+ if ( string . IsNullOrEmpty ( uniPropertyName ) )
193
+ {
194
+ return - 1 ;
195
+ }
196
+
170
197
System . StringComparison ct = System . StringComparison . CurrentCulture ;
171
198
bool isQuaternionComponent = false ;
172
199
@@ -189,7 +216,7 @@ public static int GetQuaternionIndex(string uniPropertyName) {
189
216
190
217
protected override FbxQuaternion GetConvertedQuaternionRotation ( float seconds , Quaternion restRotation )
191
218
{
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 ] ;
193
220
194
221
// The final animation, including the effect of pre-rotation.
195
222
// If we have no curve, assume the node has the correct rotation right now.
@@ -233,7 +260,7 @@ public void Dispose()
233
260
System . GC . SuppressFinalize ( this ) ;
234
261
}
235
262
236
- public virtual void Dispose ( bool cleanUpManaged )
263
+ protected virtual void Dispose ( bool cleanUpManaged )
237
264
{
238
265
foreach ( var curve in Curves )
239
266
curve . KeyModifyEnd ( ) ;
0 commit comments