Browse Source

begin fadeIn, fadeOut commands - not tested.

Ben Houston 10 years ago
parent
commit
870588758e
2 changed files with 36 additions and 1 deletions
  1. 12 0
      src/animation/AnimationAction.js
  2. 24 1
      src/animation/AnimationMixer.js

+ 12 - 0
src/animation/AnimationAction.js

@@ -62,4 +62,16 @@ THREE.AnimationAction.prototype = {
 		
 		
 	}
 	}
 
 
+	getWeightAt: function( time ) {
+
+		if( this.weight.getAt ) {
+			// pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
+			return this.weight.getAt( time );
+
+		}
+
+		return this.weight;
+
+	}
+
 };
 };

+ 24 - 1
src/animation/AnimationMixer.js

@@ -64,6 +64,27 @@ THREE.AnimationMixer.prototype = {
 		}
 		}
 	},
 	},
 
 
+	fadeOut: function( action, duration ) {
+
+		var keys = [];
+
+		keys.push( { time: this.time, value: action.getWeightAt( this.time ) } );
+		keys.push( { time: this.time + duration, value: 0 } );
+		
+		action.weight = new THREE.KeyframeTrack( "weight", keys );
+	},
+
+	fadeIn: function( action, duration ) {
+		
+		var keys = [];
+		
+		keys.push( { time: this.time, value: action.getWeightAt( this.time ) } );
+		keys.push( { time: this.time + duration, value: 1 } );
+		
+		action.weight = new THREE.KeyframeTrack( "weight", keys );
+
+	},
+
 	update: function( deltaTime ) {
 	update: function( deltaTime ) {
 
 
 		this.time += deltaTime * this.timeScale;
 		this.time += deltaTime * this.timeScale;
@@ -74,13 +95,15 @@ THREE.AnimationMixer.prototype = {
 
 
 			var action = this.actions[i];
 			var action = this.actions[i];
 
 
+			var weight = action.getWeightAt( this.time );
+			
 			if( action.weight <= 0 || ! action.enabled ) continue;
 			if( action.weight <= 0 || ! action.enabled ) continue;
 
 
 			var actionResults = action.getAt( this.time );
 			var actionResults = action.getAt( this.time );
 
 
 			for( var name in actionResults ) {
 			for( var name in actionResults ) {
 
 
-				this.propertyBindings[name].accumulate( actionResults[name], action.weight );
+				this.propertyBindings[name].accumulate( actionResults[name], weight );
 
 
 			}
 			}