@@ -8,28 +8,26 @@ import { LinearInterpolant } from '../math/interpolants/LinearInterpolant.js';
88import { DiscreteInterpolant } from '../math/interpolants/DiscreteInterpolant.js' ;
99import { AnimationUtils } from './AnimationUtils.js' ;
1010
11- function KeyframeTrack ( name , times , values , interpolation ) {
11+ class KeyframeTrack {
1212
13- if ( name === undefined ) throw new Error ( 'THREE.KeyframeTrack: track name is undefined' ) ;
14- if ( times === undefined || times . length === 0 ) throw new Error ( 'THREE.KeyframeTrack: no keyframes in track named ' + name ) ;
13+ constructor ( name , times , values , interpolation ) {
1514
16- this . name = name ;
15+ if ( name === undefined ) throw new Error ( 'THREE.KeyframeTrack: track name is undefined' ) ;
16+ if ( times === undefined || times . length === 0 ) throw new Error ( 'THREE.KeyframeTrack: no keyframes in track named ' + name ) ;
1717
18- this . times = AnimationUtils . convertArray ( times , this . TimeBufferType ) ;
19- this . values = AnimationUtils . convertArray ( values , this . ValueBufferType ) ;
18+ this . name = name ;
2019
21- this . setInterpolation ( interpolation || this . DefaultInterpolation ) ;
20+ this . times = AnimationUtils . convertArray ( times , this . TimeBufferType ) ;
21+ this . values = AnimationUtils . convertArray ( values , this . ValueBufferType ) ;
2222
23- }
24-
25- // Static methods
23+ this . setInterpolation ( interpolation || this . DefaultInterpolation ) ;
2624
27- Object . assign ( KeyframeTrack , {
25+ }
2826
2927 // Serialization (in static context, because of constructor invocation
3028 // and automatic invocation of .toJSON):
3129
32- toJSON : function ( track ) {
30+ static toJSON ( track ) {
3331
3432 const trackType = track . constructor ;
3533
@@ -67,37 +65,25 @@ Object.assign( KeyframeTrack, {
6765
6866 }
6967
70- } ) ;
71-
72- Object . assign ( KeyframeTrack . prototype , {
73-
74- constructor : KeyframeTrack ,
75-
76- TimeBufferType : Float32Array ,
77-
78- ValueBufferType : Float32Array ,
79-
80- DefaultInterpolation : InterpolateLinear ,
81-
82- InterpolantFactoryMethodDiscrete : function ( result ) {
68+ InterpolantFactoryMethodDiscrete ( result ) {
8369
8470 return new DiscreteInterpolant ( this . times , this . values , this . getValueSize ( ) , result ) ;
8571
86- } ,
72+ }
8773
88- InterpolantFactoryMethodLinear : function ( result ) {
74+ InterpolantFactoryMethodLinear ( result ) {
8975
9076 return new LinearInterpolant ( this . times , this . values , this . getValueSize ( ) , result ) ;
9177
92- } ,
78+ }
9379
94- InterpolantFactoryMethodSmooth : function ( result ) {
80+ InterpolantFactoryMethodSmooth ( result ) {
9581
9682 return new CubicInterpolant ( this . times , this . values , this . getValueSize ( ) , result ) ;
9783
98- } ,
84+ }
9985
100- setInterpolation : function ( interpolation ) {
86+ setInterpolation ( interpolation ) {
10187
10288 let factoryMethod ;
10389
@@ -152,9 +138,9 @@ Object.assign( KeyframeTrack.prototype, {
152138
153139 return this ;
154140
155- } ,
141+ }
156142
157- getInterpolation : function ( ) {
143+ getInterpolation ( ) {
158144
159145 switch ( this . createInterpolant ) {
160146
@@ -172,16 +158,16 @@ Object.assign( KeyframeTrack.prototype, {
172158
173159 }
174160
175- } ,
161+ }
176162
177- getValueSize : function ( ) {
163+ getValueSize ( ) {
178164
179165 return this . values . length / this . times . length ;
180166
181- } ,
167+ }
182168
183169 // move all keyframes either forwards or backwards in time
184- shift : function ( timeOffset ) {
170+ shift ( timeOffset ) {
185171
186172 if ( timeOffset !== 0.0 ) {
187173
@@ -197,10 +183,10 @@ Object.assign( KeyframeTrack.prototype, {
197183
198184 return this ;
199185
200- } ,
186+ }
201187
202188 // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
203- scale : function ( timeScale ) {
189+ scale ( timeScale ) {
204190
205191 if ( timeScale !== 1.0 ) {
206192
@@ -216,11 +202,11 @@ Object.assign( KeyframeTrack.prototype, {
216202
217203 return this ;
218204
219- } ,
205+ }
220206
221207 // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
222208 // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
223- trim : function ( startTime , endTime ) {
209+ trim ( startTime , endTime ) {
224210
225211 const times = this . times ,
226212 nKeys = times . length ;
@@ -260,10 +246,10 @@ Object.assign( KeyframeTrack.prototype, {
260246
261247 return this ;
262248
263- } ,
249+ }
264250
265251 // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
266- validate : function ( ) {
252+ validate ( ) {
267253
268254 let valid = true ;
269255
@@ -337,11 +323,11 @@ Object.assign( KeyframeTrack.prototype, {
337323
338324 return valid ;
339325
340- } ,
326+ }
341327
342328 // removes equivalent sequential keys as common in morph target sequences
343329 // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
344- optimize : function ( ) {
330+ optimize ( ) {
345331
346332 // times or values may be shared with other tracks, so overwriting is unsafe
347333 const times = AnimationUtils . arraySlice ( this . times ) ,
@@ -450,9 +436,9 @@ Object.assign( KeyframeTrack.prototype, {
450436
451437 return this ;
452438
453- } ,
439+ }
454440
455- clone : function ( ) {
441+ clone ( ) {
456442
457443 const times = AnimationUtils . arraySlice ( this . times , 0 ) ;
458444 const values = AnimationUtils . arraySlice ( this . values , 0 ) ;
@@ -467,6 +453,16 @@ Object.assign( KeyframeTrack.prototype, {
467453
468454 }
469455
456+ }
457+
458+ Object . assign ( KeyframeTrack . prototype , {
459+
460+ TimeBufferType : Float32Array ,
461+
462+ ValueBufferType : Float32Array ,
463+
464+ DefaultInterpolation : InterpolateLinear ,
465+
470466} ) ;
471467
472468export { KeyframeTrack } ;
0 commit comments