Browse Source

Animation: Clarified code.

tschw 9 years ago
parent
commit
ce2c44d0ea
3 changed files with 23 additions and 12 deletions
  1. 8 4
      src/animation/AnimationMixer.js
  2. 4 4
      src/animation/AnimationUtils.js
  3. 11 4
      src/animation/Interpolant.js

+ 8 - 4
src/animation/AnimationMixer.js

@@ -268,7 +268,8 @@ THREE.AnimationMixer.prototype = {
 		var time = this.time,
 		var time = this.time,
 			times = Float64Array.of( time, time + duration );
 			times = Float64Array.of( time, time + duration );
 
 
-		action.weight = new THREE.LinearInterpolant( times, this._Down, 1, this._tmp );
+		action.weight = new THREE.LinearInterpolant(
+				times, this._FadeOutValues, 1, this._tmp );
 
 
 		return this;
 		return this;
 
 
@@ -279,7 +280,8 @@ THREE.AnimationMixer.prototype = {
 		var time = this.time,
 		var time = this.time,
 			times = Float64Array.of( time, time + duration );
 			times = Float64Array.of( time, time + duration );
 
 
-		action.weight = new THREE.LinearInterpolant( times, this._Up, 1, this._tmp );
+		action.weight = new THREE.LinearInterpolant(
+				times, this._FadeInValues, 1, this._tmp );
 
 
 		return this;
 		return this;
 
 
@@ -403,6 +405,8 @@ THREE.AnimationMixer.prototype = {
 
 
 			if ( mapChanged ) {
 			if ( mapChanged ) {
 
 
+				// when bindingsMap became empty, remove it from bindingsMaps
+
 				remove_empty_map: {
 				remove_empty_map: {
 
 
 					for ( var k in bindingsMap ) break remove_empty_map;
 					for ( var k in bindingsMap ) break remove_empty_map;
@@ -445,8 +449,8 @@ THREE.AnimationMixer.prototype = {
 
 
 	},
 	},
 
 
-	_Up: Float64Array.of( 0, 1 ),
-	_Down: Float64Array.of( 1, 0 ),
+	_FadeInValues: Float64Array.of( 0, 1 ),
+	_FadeOutValues: Float64Array.of( 1, 0 ),
 
 
 	_tmp: new Float64Array( 1 )
 	_tmp: new Float64Array( 1 )
 
 

+ 4 - 4
src/animation/AnimationUtils.js

@@ -9,7 +9,7 @@ THREE.AnimationUtils = {
 	// same as Array.prototype.slice, but also works on typed arrays
 	// same as Array.prototype.slice, but also works on typed arrays
 	arraySlice: function( array, from, to ) {
 	arraySlice: function( array, from, to ) {
 
 
-		if ( array.slice === undefined ) {
+		if ( THREE.AnimationUtils.isTypedArray( array ) ) {
 
 
 			return new array.constructor( array.subarray( from, to ) );
 			return new array.constructor( array.subarray( from, to ) );
 
 
@@ -22,12 +22,12 @@ THREE.AnimationUtils = {
 	// converts an array to a specific type
 	// converts an array to a specific type
 	convertArray: function( array, type, forceClone ) {
 	convertArray: function( array, type, forceClone ) {
 
 
-		if ( ! array ||
+		if ( ! array || // let 'undefined' and 'null' pass
 				! forceClone && array.constructor === type ) return array;
 				! forceClone && array.constructor === type ) return array;
 
 
-		if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
+		if ( typeof type[ 'BYTES_PER_ELEMENT' ] === 'number' ) {
 
 
-			return new type( array );
+			return new type( array ); // create typed array
 
 
 		}
 		}
 
 

+ 11 - 4
src/animation/Interpolant.js

@@ -1,6 +1,6 @@
 /**
 /**
  *
  *
- * Abstract base class for interpolants over timed keyframe values.
+ * Abstract base class for interpolants over timed sample values.
  * It handles seeking of the interval and boundary cases. Concrete
  * It handles seeking of the interval and boundary cases. Concrete
  * subclasses then implement the actual intepolation by filling in
  * subclasses then implement the actual intepolation by filling in
  * the Template Methods.
  * the Template Methods.
@@ -39,6 +39,10 @@ THREE.Interpolant.prototype = {
 
 
 				var right;
 				var right;
 
 
+//- See http://jsperf.com/comparison-to-undefined/2
+//- slower code:
+//-
+//- 			if ( time >= keyTime || keyTime === undefined ) {
 				if ( ! ( time < keyTime ) ) {
 				if ( ! ( time < keyTime ) ) {
 
 
 					// linear scan forward
 					// linear scan forward
@@ -72,6 +76,8 @@ THREE.Interpolant.prototype = {
 					// prepare binary search on the right side of the index
 					// prepare binary search on the right side of the index
 					right = times.length;
 					right = times.length;
 
 
+//- slower code:
+//-				} else if ( time < prevKeyTime || prevKeyTime === undefined ) {
 				} else if ( ! ( time >= prevKeyTime ) ) {
 				} else if ( ! ( time >= prevKeyTime ) ) {
 
 
 					// looping?
 					// looping?
@@ -145,15 +151,16 @@ THREE.Interpolant.prototype = {
 				keyTime = times[ index ];
 				keyTime = times[ index ];
 				prevKeyTime = times[ index - 1 ];
 				prevKeyTime = times[ index - 1 ];
 
 
-				continue; // check boundary cases, again
+				// check boundary cases, again
+//-				continue;
 
 
-			} // seek
+			} // seek loop
 
 
 			this.cachedIndex = index;
 			this.cachedIndex = index;
 
 
 			this._intervalChanged( index, prevKeyTime, keyTime );
 			this._intervalChanged( index, prevKeyTime, keyTime );
 
 
-		}
+		} // validate_interval block
 
 
 		return this._interpolate( index, prevKeyTime, time, keyTime );
 		return this._interpolate( index, prevKeyTime, time, keyTime );