|
@@ -8,28 +8,26 @@ import { LinearInterpolant } from '../math/interpolants/LinearInterpolant.js';
|
|
|
import { DiscreteInterpolant } from '../math/interpolants/DiscreteInterpolant.js';
|
|
|
import { AnimationUtils } from './AnimationUtils.js';
|
|
|
|
|
|
-function KeyframeTrack( name, times, values, interpolation ) {
|
|
|
+class KeyframeTrack {
|
|
|
|
|
|
- if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
|
|
|
- if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
|
|
|
+ constructor( name, times, values, interpolation ) {
|
|
|
|
|
|
- this.name = name;
|
|
|
+ if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
|
|
|
+ if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
|
|
|
|
|
|
- this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
|
|
|
- this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
|
|
|
+ this.name = name;
|
|
|
|
|
|
- this.setInterpolation( interpolation || this.DefaultInterpolation );
|
|
|
+ this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
|
|
|
+ this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
-// Static methods
|
|
|
+ this.setInterpolation( interpolation || this.DefaultInterpolation );
|
|
|
|
|
|
-Object.assign( KeyframeTrack, {
|
|
|
+ }
|
|
|
|
|
|
// Serialization (in static context, because of constructor invocation
|
|
|
// and automatic invocation of .toJSON):
|
|
|
|
|
|
- toJSON: function ( track ) {
|
|
|
+ static toJSON( track ) {
|
|
|
|
|
|
const trackType = track.constructor;
|
|
|
|
|
@@ -67,37 +65,25 @@ Object.assign( KeyframeTrack, {
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
-
|
|
|
-Object.assign( KeyframeTrack.prototype, {
|
|
|
-
|
|
|
- constructor: KeyframeTrack,
|
|
|
-
|
|
|
- TimeBufferType: Float32Array,
|
|
|
-
|
|
|
- ValueBufferType: Float32Array,
|
|
|
-
|
|
|
- DefaultInterpolation: InterpolateLinear,
|
|
|
-
|
|
|
- InterpolantFactoryMethodDiscrete: function ( result ) {
|
|
|
+ InterpolantFactoryMethodDiscrete( result ) {
|
|
|
|
|
|
return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- InterpolantFactoryMethodLinear: function ( result ) {
|
|
|
+ InterpolantFactoryMethodLinear( result ) {
|
|
|
|
|
|
return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- InterpolantFactoryMethodSmooth: function ( result ) {
|
|
|
+ InterpolantFactoryMethodSmooth( result ) {
|
|
|
|
|
|
return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setInterpolation: function ( interpolation ) {
|
|
|
+ setInterpolation( interpolation ) {
|
|
|
|
|
|
let factoryMethod;
|
|
|
|
|
@@ -152,9 +138,9 @@ Object.assign( KeyframeTrack.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getInterpolation: function () {
|
|
|
+ getInterpolation() {
|
|
|
|
|
|
switch ( this.createInterpolant ) {
|
|
|
|
|
@@ -172,16 +158,16 @@ Object.assign( KeyframeTrack.prototype, {
|
|
|
|
|
|
}
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getValueSize: function () {
|
|
|
+ getValueSize() {
|
|
|
|
|
|
return this.values.length / this.times.length;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// move all keyframes either forwards or backwards in time
|
|
|
- shift: function ( timeOffset ) {
|
|
|
+ shift( timeOffset ) {
|
|
|
|
|
|
if ( timeOffset !== 0.0 ) {
|
|
|
|
|
@@ -197,10 +183,10 @@ Object.assign( KeyframeTrack.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// scale all keyframe times by a factor (useful for frame <-> seconds conversions)
|
|
|
- scale: function ( timeScale ) {
|
|
|
+ scale( timeScale ) {
|
|
|
|
|
|
if ( timeScale !== 1.0 ) {
|
|
|
|
|
@@ -216,11 +202,11 @@ Object.assign( KeyframeTrack.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// removes keyframes before and after animation without changing any values within the range [startTime, endTime].
|
|
|
// IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
|
|
|
- trim: function ( startTime, endTime ) {
|
|
|
+ trim( startTime, endTime ) {
|
|
|
|
|
|
const times = this.times,
|
|
|
nKeys = times.length;
|
|
@@ -260,10 +246,10 @@ Object.assign( KeyframeTrack.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
|
|
|
- validate: function () {
|
|
|
+ validate() {
|
|
|
|
|
|
let valid = true;
|
|
|
|
|
@@ -337,11 +323,11 @@ Object.assign( KeyframeTrack.prototype, {
|
|
|
|
|
|
return valid;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// removes equivalent sequential keys as common in morph target sequences
|
|
|
// (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
|
|
|
- optimize: function () {
|
|
|
+ optimize() {
|
|
|
|
|
|
// times or values may be shared with other tracks, so overwriting is unsafe
|
|
|
const times = AnimationUtils.arraySlice( this.times ),
|
|
@@ -450,9 +436,9 @@ Object.assign( KeyframeTrack.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- clone: function () {
|
|
|
+ clone() {
|
|
|
|
|
|
const times = AnimationUtils.arraySlice( this.times, 0 );
|
|
|
const values = AnimationUtils.arraySlice( this.values, 0 );
|
|
@@ -467,6 +453,16 @@ Object.assign( KeyframeTrack.prototype, {
|
|
|
|
|
|
}
|
|
|
|
|
|
+}
|
|
|
+
|
|
|
+Object.assign( KeyframeTrack.prototype, {
|
|
|
+
|
|
|
+ TimeBufferType: Float32Array,
|
|
|
+
|
|
|
+ ValueBufferType: Float32Array,
|
|
|
+
|
|
|
+ DefaultInterpolation: InterpolateLinear,
|
|
|
+
|
|
|
} );
|
|
|
|
|
|
export { KeyframeTrack };
|