|
@@ -1,92 +1,93 @@
|
|
|
import { WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, LoopPingPong, LoopOnce, LoopRepeat, NormalAnimationBlendMode, AdditiveAnimationBlendMode } from '../constants.js';
|
|
|
|
|
|
-function AnimationAction( mixer, clip, localRoot, blendMode ) {
|
|
|
|
|
|
- this._mixer = mixer;
|
|
|
- this._clip = clip;
|
|
|
- this._localRoot = localRoot || null;
|
|
|
- this.blendMode = blendMode || clip.blendMode;
|
|
|
+class AnimationAction {
|
|
|
|
|
|
- const tracks = clip.tracks,
|
|
|
- nTracks = tracks.length,
|
|
|
- interpolants = new Array( nTracks );
|
|
|
+ constructor( mixer, clip, localRoot, blendMode ) {
|
|
|
|
|
|
- const interpolantSettings = {
|
|
|
- endingStart: ZeroCurvatureEnding,
|
|
|
- endingEnd: ZeroCurvatureEnding
|
|
|
- };
|
|
|
+ this._mixer = mixer;
|
|
|
+ this._clip = clip;
|
|
|
+ this._localRoot = localRoot || null;
|
|
|
+ this.blendMode = blendMode || clip.blendMode;
|
|
|
|
|
|
- for ( let i = 0; i !== nTracks; ++ i ) {
|
|
|
+ const tracks = clip.tracks,
|
|
|
+ nTracks = tracks.length,
|
|
|
+ interpolants = new Array( nTracks );
|
|
|
|
|
|
- const interpolant = tracks[ i ].createInterpolant( null );
|
|
|
- interpolants[ i ] = interpolant;
|
|
|
- interpolant.settings = interpolantSettings;
|
|
|
+ const interpolantSettings = {
|
|
|
+ endingStart: ZeroCurvatureEnding,
|
|
|
+ endingEnd: ZeroCurvatureEnding
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
+ for ( let i = 0; i !== nTracks; ++ i ) {
|
|
|
|
|
|
- this._interpolantSettings = interpolantSettings;
|
|
|
+ const interpolant = tracks[ i ].createInterpolant( null );
|
|
|
+ interpolants[ i ] = interpolant;
|
|
|
+ interpolant.settings = interpolantSettings;
|
|
|
|
|
|
- this._interpolants = interpolants; // bound by the mixer
|
|
|
+ }
|
|
|
|
|
|
- // inside: PropertyMixer (managed by the mixer)
|
|
|
- this._propertyBindings = new Array( nTracks );
|
|
|
+ this._interpolantSettings = interpolantSettings;
|
|
|
|
|
|
- this._cacheIndex = null; // for the memory manager
|
|
|
- this._byClipCacheIndex = null; // for the memory manager
|
|
|
+ this._interpolants = interpolants; // bound by the mixer
|
|
|
|
|
|
- this._timeScaleInterpolant = null;
|
|
|
- this._weightInterpolant = null;
|
|
|
+ // inside: PropertyMixer (managed by the mixer)
|
|
|
+ this._propertyBindings = new Array( nTracks );
|
|
|
|
|
|
- this.loop = LoopRepeat;
|
|
|
- this._loopCount = - 1;
|
|
|
+ this._cacheIndex = null; // for the memory manager
|
|
|
+ this._byClipCacheIndex = null; // for the memory manager
|
|
|
|
|
|
- // global mixer time when the action is to be started
|
|
|
- // it's set back to 'null' upon start of the action
|
|
|
- this._startTime = null;
|
|
|
+ this._timeScaleInterpolant = null;
|
|
|
+ this._weightInterpolant = null;
|
|
|
|
|
|
- // scaled local time of the action
|
|
|
- // gets clamped or wrapped to 0..clip.duration according to loop
|
|
|
- this.time = 0;
|
|
|
+ this.loop = LoopRepeat;
|
|
|
+ this._loopCount = - 1;
|
|
|
|
|
|
- this.timeScale = 1;
|
|
|
- this._effectiveTimeScale = 1;
|
|
|
+ // global mixer time when the action is to be started
|
|
|
+ // it's set back to 'null' upon start of the action
|
|
|
+ this._startTime = null;
|
|
|
|
|
|
- this.weight = 1;
|
|
|
- this._effectiveWeight = 1;
|
|
|
+ // scaled local time of the action
|
|
|
+ // gets clamped or wrapped to 0..clip.duration according to loop
|
|
|
+ this.time = 0;
|
|
|
|
|
|
- this.repetitions = Infinity; // no. of repetitions when looping
|
|
|
+ this.timeScale = 1;
|
|
|
+ this._effectiveTimeScale = 1;
|
|
|
|
|
|
- this.paused = false; // true -> zero effective time scale
|
|
|
- this.enabled = true; // false -> zero effective weight
|
|
|
+ this.weight = 1;
|
|
|
+ this._effectiveWeight = 1;
|
|
|
|
|
|
- this.clampWhenFinished = false;// keep feeding the last frame?
|
|
|
+ this.repetitions = Infinity; // no. of repetitions when looping
|
|
|
|
|
|
- this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
|
|
|
- this.zeroSlopeAtEnd = true;// clips for start, loop and end
|
|
|
+ this.paused = false; // true -> zero effective time scale
|
|
|
+ this.enabled = true; // false -> zero effective weight
|
|
|
|
|
|
-}
|
|
|
+ this.clampWhenFinished = false;// keep feeding the last frame?
|
|
|
|
|
|
-Object.assign( AnimationAction.prototype, {
|
|
|
+ this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
|
|
|
+ this.zeroSlopeAtEnd = true;// clips for start, loop and end
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
// State & Scheduling
|
|
|
|
|
|
- play: function () {
|
|
|
+ play() {
|
|
|
|
|
|
this._mixer._activateAction( this );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- stop: function () {
|
|
|
+ stop() {
|
|
|
|
|
|
this._mixer._deactivateAction( this );
|
|
|
|
|
|
return this.reset();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- reset: function () {
|
|
|
+ reset() {
|
|
|
|
|
|
this.paused = false;
|
|
|
this.enabled = true;
|
|
@@ -97,45 +98,45 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
return this.stopFading().stopWarping();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- isRunning: function () {
|
|
|
+ isRunning() {
|
|
|
|
|
|
return this.enabled && ! this.paused && this.timeScale !== 0 &&
|
|
|
this._startTime === null && this._mixer._isActiveAction( this );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// return true when play has been called
|
|
|
- isScheduled: function () {
|
|
|
+ isScheduled() {
|
|
|
|
|
|
return this._mixer._isActiveAction( this );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- startAt: function ( time ) {
|
|
|
+ startAt( time ) {
|
|
|
|
|
|
this._startTime = time;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setLoop: function ( mode, repetitions ) {
|
|
|
+ setLoop( mode, repetitions ) {
|
|
|
|
|
|
this.loop = mode;
|
|
|
this.repetitions = repetitions;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// Weight
|
|
|
|
|
|
// set the weight stopping any scheduled fading
|
|
|
// although .enabled = false yields an effective weight of zero, this
|
|
|
// method does *not* change .enabled, because it would be confusing
|
|
|
- setEffectiveWeight: function ( weight ) {
|
|
|
+ setEffectiveWeight( weight ) {
|
|
|
|
|
|
this.weight = weight;
|
|
|
|
|
@@ -144,28 +145,28 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
return this.stopFading();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// return the weight considering fading and .enabled
|
|
|
- getEffectiveWeight: function () {
|
|
|
+ getEffectiveWeight() {
|
|
|
|
|
|
return this._effectiveWeight;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- fadeIn: function ( duration ) {
|
|
|
+ fadeIn( duration ) {
|
|
|
|
|
|
return this._scheduleFading( duration, 0, 1 );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- fadeOut: function ( duration ) {
|
|
|
+ fadeOut( duration ) {
|
|
|
|
|
|
return this._scheduleFading( duration, 1, 0 );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- crossFadeFrom: function ( fadeOutAction, duration, warp ) {
|
|
|
+ crossFadeFrom( fadeOutAction, duration, warp ) {
|
|
|
|
|
|
fadeOutAction.fadeOut( duration );
|
|
|
this.fadeIn( duration );
|
|
@@ -185,15 +186,15 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- crossFadeTo: function ( fadeInAction, duration, warp ) {
|
|
|
+ crossFadeTo( fadeInAction, duration, warp ) {
|
|
|
|
|
|
return fadeInAction.crossFadeFrom( this, duration, warp );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- stopFading: function () {
|
|
|
+ stopFading() {
|
|
|
|
|
|
let weightInterpolant = this._weightInterpolant;
|
|
|
|
|
@@ -206,53 +207,53 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// Time Scale Control
|
|
|
|
|
|
// set the time scale stopping any scheduled warping
|
|
|
// although .paused = true yields an effective time scale of zero, this
|
|
|
// method does *not* change .paused, because it would be confusing
|
|
|
- setEffectiveTimeScale: function ( timeScale ) {
|
|
|
+ setEffectiveTimeScale( timeScale ) {
|
|
|
|
|
|
this.timeScale = timeScale;
|
|
|
this._effectiveTimeScale = this.paused ? 0 : timeScale;
|
|
|
|
|
|
return this.stopWarping();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// return the time scale considering warping and .paused
|
|
|
- getEffectiveTimeScale: function () {
|
|
|
+ getEffectiveTimeScale() {
|
|
|
|
|
|
return this._effectiveTimeScale;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setDuration: function ( duration ) {
|
|
|
+ setDuration( duration ) {
|
|
|
|
|
|
this.timeScale = this._clip.duration / duration;
|
|
|
|
|
|
return this.stopWarping();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- syncWith: function ( action ) {
|
|
|
+ syncWith( action ) {
|
|
|
|
|
|
this.time = action.time;
|
|
|
this.timeScale = action.timeScale;
|
|
|
|
|
|
return this.stopWarping();
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- halt: function ( duration ) {
|
|
|
+ halt( duration ) {
|
|
|
|
|
|
return this.warp( this._effectiveTimeScale, 0, duration );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- warp: function ( startTimeScale, endTimeScale, duration ) {
|
|
|
+ warp( startTimeScale, endTimeScale, duration ) {
|
|
|
|
|
|
const mixer = this._mixer,
|
|
|
now = mixer.time,
|
|
@@ -278,9 +279,9 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- stopWarping: function () {
|
|
|
+ stopWarping() {
|
|
|
|
|
|
let timeScaleInterpolant = this._timeScaleInterpolant;
|
|
|
|
|
@@ -293,31 +294,31 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// Object Accessors
|
|
|
|
|
|
- getMixer: function () {
|
|
|
+ getMixer() {
|
|
|
|
|
|
return this._mixer;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getClip: function () {
|
|
|
+ getClip() {
|
|
|
|
|
|
return this._clip;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getRoot: function () {
|
|
|
+ getRoot() {
|
|
|
|
|
|
return this._localRoot || this._mixer._root;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
// Interna
|
|
|
|
|
|
- _update: function ( time, deltaTime, timeDirection, accuIndex ) {
|
|
|
+ _update( time, deltaTime, timeDirection, accuIndex ) {
|
|
|
|
|
|
// called by the mixer
|
|
|
|
|
@@ -392,9 +393,9 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
}
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- _updateWeight: function ( time ) {
|
|
|
+ _updateWeight( time ) {
|
|
|
|
|
|
let weight = 0;
|
|
|
|
|
@@ -429,9 +430,9 @@ Object.assign( AnimationAction.prototype, {
|
|
|
this._effectiveWeight = weight;
|
|
|
return weight;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- _updateTimeScale: function ( time ) {
|
|
|
+ _updateTimeScale( time ) {
|
|
|
|
|
|
let timeScale = 0;
|
|
|
|
|
@@ -472,9 +473,9 @@ Object.assign( AnimationAction.prototype, {
|
|
|
this._effectiveTimeScale = timeScale;
|
|
|
return timeScale;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- _updateTime: function ( deltaTime ) {
|
|
|
+ _updateTime( deltaTime ) {
|
|
|
|
|
|
const duration = this._clip.duration;
|
|
|
const loop = this.loop;
|
|
@@ -629,9 +630,9 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
return time;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- _setEndings: function ( atStart, atEnd, pingPong ) {
|
|
|
+ _setEndings( atStart, atEnd, pingPong ) {
|
|
|
|
|
|
const settings = this._interpolantSettings;
|
|
|
|
|
@@ -666,9 +667,9 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
}
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- _scheduleFading: function ( duration, weightNow, weightThen ) {
|
|
|
+ _scheduleFading( duration, weightNow, weightThen ) {
|
|
|
|
|
|
const mixer = this._mixer, now = mixer.time;
|
|
|
let interpolant = this._weightInterpolant;
|
|
@@ -692,7 +693,7 @@ Object.assign( AnimationAction.prototype, {
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
+}
|
|
|
|
|
|
|
|
|
export { AnimationAction };
|