Browse Source

move towards delta time.

Ben Houston 10 years ago
parent
commit
39beddae37

+ 2 - 4
examples/webgl_animation_track_clip_mixer.html

@@ -63,8 +63,7 @@
 			var mesh, helper;
 			var mesh, helper;
 
 
 			var mixer;
 			var mixer;
-			var time1 = 0;
-
+		
 			var mouseX = 0, mouseY = 0;
 			var mouseX = 0, mouseY = 0;
 
 
 			var windowHalfX = window.innerWidth / 2;
 			var windowHalfX = window.innerWidth / 2;
@@ -318,8 +317,7 @@
 				//THREE.AnimationHandler.update( delta );
 				//THREE.AnimationHandler.update( delta );
 
 
 				if( mixer ) {
 				if( mixer ) {
-					time1 += delta;
-					mixer.update( time1 );
+					mixer.update( delta );
 				}
 				}
 				
 				
 				//if ( helper !== undefined ) helper.update();
 				//if ( helper !== undefined ) helper.update();

+ 0 - 1
src/animation/AnimationAction.js

@@ -14,7 +14,6 @@ THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
 	this.weight = weight || 1;
 	this.weight = weight || 1;
 	this.loop = loop || clip.loop || false;
 	this.loop = loop || clip.loop || false;
 	this.enabled = true;	// allow for easy disabling of the action.
 	this.enabled = true;	// allow for easy disabling of the action.
-
 };
 };
 
 
 THREE.AnimationAction.prototype = {
 THREE.AnimationAction.prototype = {

+ 7 - 2
src/animation/AnimationMixer.js

@@ -11,6 +11,8 @@
 THREE.AnimationMixer = function( root ) {
 THREE.AnimationMixer = function( root ) {
 
 
 	this.root = root;
 	this.root = root;
+	this.time = 0;
+	this.timeScale = 1.0;
 	this.actions = [];
 	this.actions = [];
 	this.propertyBindings = {};
 	this.propertyBindings = {};
 
 
@@ -49,7 +51,10 @@ THREE.AnimationMixer.prototype = {
 		}
 		}
 	},
 	},
 
 
-	update: function( time ) {
+	update: function( deltaTime ) {
+
+		this.time += deltaTime * this.timeScale;
+
 		//console.log( this.root.name + ".AnimationMixer.update( " + time + " )" );
 		//console.log( this.root.name + ".AnimationMixer.update( " + time + " )" );
 
 
 		for ( var name in this.propertyBindings ) {
 		for ( var name in this.propertyBindings ) {
@@ -64,7 +69,7 @@ THREE.AnimationMixer.prototype = {
 
 
 			if( action.weight <= 0 || ! action.enabled ) continue;
 			if( action.weight <= 0 || ! action.enabled ) continue;
 
 
-			var actionResults = action.getAt( time );
+			var actionResults = action.getAt( this.time );
 
 
 			for( var name in actionResults ) {
 			for( var name in actionResults ) {
 
 

+ 6 - 6
src/animation/AnimationUtils.js

@@ -5,21 +5,22 @@
 
 
  THREE.AnimationUtils = {
  THREE.AnimationUtils = {
 
 
- 	getLerpFunc: function( accumulator, b, alpha, interTrack ) {
+ 	// TODO/OPTIMIZATION: do the switch statement once per user of this and cache the resulting function and call it directly.
+ 	// TODO/OPTIMIZATION: Accumulator should be writable and it will get rid of the *.clone() calls that are likely slow.
+ 	lerp: function( accumulator, b, alpha, interTrack ) {
 
 
-		
-		var typeName = typeof true;
+		var typeName = typeof accumulator;
 		switch( typeName ) {
 		switch( typeName ) {
 		 	case "object": {
 		 	case "object": {
 
 
 				if( accumulator.lerp ) {
 				if( accumulator.lerp ) {
 
 
-					return accumulator.lerp( b, alpha );
+					return accumulator.clone().lerp( b, alpha );
 
 
 				}
 				}
 				if( accumulator.slerp ) {
 				if( accumulator.slerp ) {
 
 
-					return accumulator.lerp( b, alpha );
+					return accumulator.clone().slerp( b, alpha );
 
 
 				}
 				}
 				break;
 				break;
@@ -45,7 +46,6 @@
 		 	}
 		 	}
 		};
 		};
 
 
-
 	}
 	}
 	
 	
 };
 };

+ 0 - 1
src/animation/KeyframeTrack.js

@@ -52,7 +52,6 @@ THREE.KeyframeTrack.prototype = {
 				// linear interpolation to start with
 				// linear interpolation to start with
 				var alpha = ( time - this.keys[ i - 1 ].time ) / ( this.keys[ i ].time - this.keys[ i - 1 ].time );
 				var alpha = ( time - this.keys[ i - 1 ].time ) / ( this.keys[ i ].time - this.keys[ i - 1 ].time );
 
 
-
 				var interpolatedValue = THREE.AnimationUtils.lerp( this.keys[ i - 1 ].value, this.keys[ i ].value, alpha );
 				var interpolatedValue = THREE.AnimationUtils.lerp( this.keys[ i - 1 ].value, this.keys[ i ].value, alpha );
 
 
 				/*console.log( '   interpolated: ', {
 				/*console.log( '   interpolated: ', {

+ 10 - 0
src/animation/Time.js

@@ -0,0 +1,10 @@
+
+
+time - time since the start of the game
+timeScale - the time scale currently going on, allows for slow motion effects
+deltaTime - the time since the last frame
+
+timeSinceLevelLoad - time since the start of the most recent level
+
+unscaledTime
+unscaledDeltaTime