42
42
import java .io .IOException ;
43
43
44
44
/**
45
- * Contains a list of transforms and times for each keyframe.
45
+ * An AnimTrack that transforms a Joint or Spatial
46
+ * using a list of transforms and times for keyframes.
46
47
*
47
48
* @author Rémy Bouquet
48
49
*/
49
50
public class TransformTrack implements AnimTrack <Transform > {
50
51
51
52
private double length ;
53
+ private FrameInterpolator interpolator = FrameInterpolator .DEFAULT ;
52
54
private HasLocalTransform target ;
53
55
54
56
/**
55
- * Transforms and times for track .
57
+ * Transforms and times for keyframes .
56
58
*/
57
59
private CompactVector3Array translations ;
58
60
private CompactQuaternionArray rotations ;
59
61
private CompactVector3Array scales ;
60
- private FrameInterpolator interpolator = FrameInterpolator .DEFAULT ;
61
62
private float [] times ;
62
63
63
64
/**
@@ -67,39 +68,42 @@ protected TransformTrack() {
67
68
}
68
69
69
70
/**
70
- * Creates a transform track for the given bone index
71
+ * Creates a transform track for the given target.
71
72
*
72
73
* @param target the target Joint or Spatial of the new track
73
- * @param times a float array with the time of each frame
74
- * @param translations the translation of the bone for each frame
75
- * @param rotations the rotation of the bone for each frame
76
- * @param scales the scale of the bone for each frame
74
+ * @param times the time for each keyframe, or null for none
75
+ * @param translations the translation of the target for each keyframe
76
+ * (same length as times) or null for no translation
77
+ * @param rotations the rotation of the target for each keyframe
78
+ * (same length as times) or null for no rotation
79
+ * @param scales the scale of the target for each keyframe
80
+ * (same length as times) or null for no scaling
77
81
*/
78
82
public TransformTrack (HasLocalTransform target , float [] times , Vector3f [] translations , Quaternion [] rotations , Vector3f [] scales ) {
79
83
this .target = target ;
80
84
this .setKeyframes (times , translations , rotations , scales );
81
85
}
82
86
83
87
/**
84
- * return the array of rotations of this track
88
+ * Copies the rotations.
85
89
*
86
- * @return an array, or null if no rotations
90
+ * @return a new array, or null if no rotations
87
91
*/
88
92
public Quaternion [] getRotations () {
89
93
return rotations == null ? null : rotations .toObjectArray ();
90
94
}
91
95
92
96
/**
93
- * returns the array of scales for this track
97
+ * Copies the scales.
94
98
*
95
- * @return an array or null
99
+ * @return a new array, or null if no scales
96
100
*/
97
101
public Vector3f [] getScales () {
98
102
return scales == null ? null : scales .toObjectArray ();
99
103
}
100
104
101
105
/**
102
- * returns the arrays of time for this track
106
+ * Gives access to the keyframe times.
103
107
*
104
108
* @return the pre-existing array
105
109
*/
@@ -108,19 +112,19 @@ public float[] getTimes() {
108
112
}
109
113
110
114
/**
111
- * returns the array of translations of this track
115
+ * Copies the translations.
112
116
*
113
- * @return an array, or null if no translations
117
+ * @return a new array, or null if no translations
114
118
*/
115
119
public Vector3f [] getTranslations () {
116
120
return translations == null ? null : translations .toObjectArray ();
117
121
}
118
122
119
123
120
124
/**
121
- * Sets the keyframes times for this Joint track
125
+ * Sets the keyframe times.
122
126
*
123
- * @param times the keyframes times
127
+ * @param times the desired keyframe times (alias created, not null, not empty)
124
128
*/
125
129
public void setTimes (float [] times ) {
126
130
if (times == null || times .length == 0 ) {
@@ -132,9 +136,10 @@ public void setTimes(float[] times) {
132
136
}
133
137
134
138
/**
135
- * Set the translations for this joint track
139
+ * Sets the translations.
136
140
*
137
- * @param translations the translation of the bone for each frame
141
+ * @param translations the desired translation of the target for each
142
+ * keyframe (not null, same length as "times")
138
143
*/
139
144
public void setKeyframesTranslation (Vector3f [] translations ) {
140
145
if (times == null ) {
@@ -154,9 +159,10 @@ public void setKeyframesTranslation(Vector3f[] translations) {
154
159
}
155
160
156
161
/**
157
- * Set the scales for this joint track
162
+ * Sets the scales.
158
163
*
159
- * @param scales the scales of the bone for each frame
164
+ * @param scales the desired scale of the target for each keyframe (not
165
+ * null, same length as "times")
160
166
*/
161
167
public void setKeyframesScale (Vector3f [] scales ) {
162
168
if (times == null ) {
@@ -176,9 +182,10 @@ public void setKeyframesScale(Vector3f[] scales) {
176
182
}
177
183
178
184
/**
179
- * Set the rotations for this joint track
185
+ * Sets the rotations.
180
186
*
181
- * @param rotations the rotations of the bone for each frame
187
+ * @param rotations the desired rotation of the target for each keyframe
188
+ * (not null, same length as "times")
182
189
*/
183
190
public void setKeyframesRotation (Quaternion [] rotations ) {
184
191
if (times == null ) {
@@ -199,12 +206,19 @@ public void setKeyframesRotation(Quaternion[] rotations) {
199
206
200
207
201
208
/**
202
- * Set the translations, rotations and scales for this bone track
209
+ * Sets the translations, rotations, and/or scales.
203
210
*
204
- * @param times a float array with the time of each frame
205
- * @param translations the translation of the bone for each frame
206
- * @param rotations the rotation of the bone for each frame
207
- * @param scales the scale of the bone for each frame
211
+ * @param times the desired time for each keyframe,
212
+ * or null to leave the times unchanged
213
+ * @param translations the desired translation of the target for each
214
+ * keyframe (same length as times)
215
+ * or null to leave the translations unchanged
216
+ * @param rotations the desired rotation of the target for each keyframe
217
+ * (same length as times)
218
+ * or null to leave the rotations unchanged
219
+ * @param scales the desired scale of the target for each keyframe
220
+ * (same length as times)
221
+ * or null to leave the scales unchanged
208
222
*/
209
223
public void setKeyframes (float [] times , Vector3f [] translations , Quaternion [] rotations , Vector3f [] scales ) {
210
224
if (times != null ) {
@@ -248,7 +262,7 @@ public void getDataAtTime(double t, Transform transform) {
248
262
int endFrame = 1 ;
249
263
float blend = 0 ;
250
264
if (time >= times [lastFrame ]) {
251
- // extrapolate beyond the final frame of the animation
265
+ // extrapolate beyond the final keyframe of the animation
252
266
startFrame = lastFrame ;
253
267
254
268
float inferredInterval = times [lastFrame ] - times [lastFrame - 1 ];
@@ -281,7 +295,7 @@ public void getDataAtTime(double t, Transform transform) {
281
295
}
282
296
283
297
/**
284
- * Replace the frame interpolator.
298
+ * Replaces the frame interpolator.
285
299
*
286
300
* @param interpolator the interpolator to use (alias created)
287
301
*/
@@ -290,8 +304,7 @@ public void setFrameInterpolator(FrameInterpolator interpolator) {
290
304
}
291
305
292
306
/**
293
- * Access the target affected by this track, which might be a Joint or a
294
- * Spatial.
307
+ * Gives access to the target, which might be a Joint or a Spatial.
295
308
*
296
309
* @return the pre-existing instance
297
310
*/
@@ -300,7 +313,7 @@ public HasLocalTransform getTarget() {
300
313
}
301
314
302
315
/**
303
- * Replace the target of this track , which might be a Joint or a Spatial.
316
+ * Replaces the target, which might be a Joint or a Spatial.
304
317
*
305
318
* @param target the target to use (alias created)
306
319
*/
@@ -309,7 +322,7 @@ public void setTarget(HasLocalTransform target) {
309
322
}
310
323
311
324
/**
312
- * Serialize this track to the specified exporter, for example when
325
+ * Serializes this track to the specified exporter, for example when
313
326
* saving to a J3O file.
314
327
*
315
328
* @param ex the exporter to write to (not null)
@@ -326,7 +339,7 @@ public void write(JmeExporter ex) throws IOException {
326
339
}
327
340
328
341
/**
329
- * De-serialize this track from the specified importer, for example when
342
+ * De-serializes this track from the specified importer, for example when
330
343
* loading from a J3O file.
331
344
*
332
345
* @param im the importer to read from (not null)
0 commit comments