Browse Source

cleaning up time handling in AnimationAction - moving to relative time.

Ben Houston 10 years ago
parent
commit
dff0e17ff4
1 changed files with 14 additions and 10 deletions
  1. 14 10
      src/animation/AnimationAction.js

+ 14 - 10
src/animation/AnimationAction.js

@@ -16,43 +16,49 @@ THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
 	this.enabled = true;	// allow for easy disabling of the action.
 
 	this.time = 0;
+	this.clipTime = 0;
 };
 
 THREE.AnimationAction.prototype = {
 
 	constructor: THREE.AnimationAction,
 
-	toAnimationClipTime: function( time ) {
+	updateTime: function( deltaTime ) {
 
 		//console.log( 'AnimationAction[' + this.clip.name + '].toAnimationClipTime( ' + time + ' )' );
+		this.time += deltaTime;
+		this.clipTime += deltaTime * this.getTimeScaleAt( time );
 
-		var clipTime = ( time - this.startTime ) * this.getTimeScaleAt( time );
 		//console.log( '   clipTime: ' + clipTime );
 
 		var duration = this.clip.duration;
 
 		if( this.loop ) {
 
-			if( clipTime < 0 ) {
+			if( this.clipTime < 0 ) {
 
-				clipTime -= Math.floor( clipTime / duration ) * duration;
+				this.clipTime -= Math.floor( clipTime / duration ) * duration;
 				//console.log( '   clipTime: ' + clipTime );
 
 			}
 
-	   		return clipTime % duration;
+	   		this.clipTime = clipTime % duration;
 
 	   	}
 	   	else {
 
-	   		return Math.min( clipTime, Math.max( duration, 0 ) );
+	   		this.clipTime = Math.min( this.clipTime, Math.max( duration, 0 ) );
 
 	   	}
+
+	   	return this.clipTime;
+
 	},
 
 	init: function( time ) {
 
 		this.time = time;
+		this.clipTime = time - this.startTime;
 
 	},
 
@@ -60,11 +66,9 @@ THREE.AnimationAction.prototype = {
 
 		//console.log( 'AnimationAction[' + this.clip.name + '].getAt( ' + time + ' )' );
 
-		this.time += deltaTime;
-
-		var clipTime = this.toAnimationClipTime( this.time );
+		this.updateTime( deltaTime );
 
-		var clipResults = this.clip.getAt( clipTime );
+		var clipResults = this.clip.getAt( this.clipTime );
 
 		//console.log( "  clipResults: ", clipResults );