Browse Source

introduce time awareness in AnimationAction.

Ben Houston 10 years ago
parent
commit
e3b2c7593c
2 changed files with 26 additions and 4 deletions
  1. 25 3
      src/animation/AnimationAction.js
  2. 1 1
      src/animation/AnimationMixer.js

+ 25 - 3
src/animation/AnimationAction.js

@@ -14,6 +14,8 @@ THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
 	this.weight = weight || 1;
 	this.loop = loop || clip.loop || false;
 	this.enabled = true;	// allow for easy disabling of the action.
+
+	this.time = 0;
 };
 
 THREE.AnimationAction.prototype = {
@@ -24,7 +26,7 @@ THREE.AnimationAction.prototype = {
 
 		//console.log( 'AnimationAction[' + this.clip.name + '].toAnimationClipTime( ' + time + ' )' );
 
-		var clipTime = ( time - this.startTime ) * this.timeScale;
+		var clipTime = ( time - this.startTime ) * this.getTimeScaleAt( time );
 		//console.log( '   clipTime: ' + clipTime );
 
 		var duration = this.clip.duration;
@@ -48,11 +50,19 @@ THREE.AnimationAction.prototype = {
 	   	}
 	},
 
-	getAt: function( time ) {
+	init: function( time ) {
+
+		this.time = time;
+
+	},
+
+	update: function( deltaTime ) {
 
 		//console.log( 'AnimationAction[' + this.clip.name + '].getAt( ' + time + ' )' );
 
-		var clipTime = this.toAnimationClipTime( time );
+		this.time += deltaTime;
+
+		var clipTime = this.toAnimationClipTime( this.time );
 
 		var clipResults = this.clip.getAt( clipTime );
 
@@ -62,6 +72,18 @@ THREE.AnimationAction.prototype = {
 		
 	},
 
+	getTimeScaleAt: function( time ) {
+
+		if( this.timeScale.getAt ) {
+			// pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
+			return this.timeScale.getAt( time );
+
+		}
+
+		return this.timeScale;
+
+	},
+
 	getWeightAt: function( time ) {
 
 		if( this.weight.getAt ) {

+ 1 - 1
src/animation/AnimationMixer.js

@@ -142,7 +142,7 @@ THREE.AnimationMixer.prototype = {
 			var endStartRatio = 1.0 / startEndRatio;
 
 			this.wrap( fadeOutAction, 1.0, startEndRatio, duration );
-			this.wrap( fadeInAction, endStartRatio, 1.0, duration );
+			this.wrap( action, endStartRatio, 1.0, duration );
 
 		}