Browse Source

Few cosmetic changes in Animation and AnimationHandler.

alteredq 13 years ago
parent
commit
f4213e7cfd
2 changed files with 32 additions and 39 deletions
  1. 15 23
      src/extras/animation/Animation.js
  2. 17 16
      src/extras/animation/AnimationHandler.js

+ 15 - 23
src/extras/animation/Animation.js

@@ -4,16 +4,19 @@
  * @author alteredq / http://alteredqualia.com/
  */
 
-THREE.Animation = function( root, data, interpolationType, JITCompile ) {
+THREE.Animation = function( root, name, interpolationType, JITCompile ) {
 
 	this.root = root;
-	this.data = THREE.AnimationHandler.get( data );
+	this.data = THREE.AnimationHandler.get( name );
 	this.hierarchy = THREE.AnimationHandler.parse( root );
+
 	this.currentTime = 0;
 	this.timeScale = 1;
+
 	this.isPlaying = false;
 	this.isPaused = true;
 	this.loop = true;
+
 	this.interpolationType = interpolationType !== undefined ? interpolationType : THREE.AnimationHandler.LINEAR;
 	this.JITCompile = JITCompile !== undefined ? JITCompile : true;
 
@@ -22,23 +25,20 @@ THREE.Animation = function( root, data, interpolationType, JITCompile ) {
 
 };
 
-// Play
-
 THREE.Animation.prototype.play = function( loop, startTimeMS ) {
 
-	if( !this.isPlaying ) {
+	if ( !this.isPlaying ) {
 
 		this.isPlaying = true;
 		this.loop = loop !== undefined ? loop : true;
 		this.currentTime = startTimeMS !== undefined ? startTimeMS : 0;
 
-
 		// reset key cache
 
 		var h, hl = this.hierarchy.length,
 			object;
 
-		for ( h = 0; h < hl; h++ ) {
+		for ( h = 0; h < hl; h ++ ) {
 
 			object = this.hierarchy[ h ];
 
@@ -83,9 +83,6 @@ THREE.Animation.prototype.play = function( loop, startTimeMS ) {
 };
 
 
-
-// Pause
-
 THREE.Animation.prototype.pause = function() {
 
 	if( this.isPaused ) {
@@ -103,18 +100,15 @@ THREE.Animation.prototype.pause = function() {
 };
 
 
-// Stop
-
 THREE.Animation.prototype.stop = function() {
 
 	this.isPlaying = false;
 	this.isPaused  = false;
 	THREE.AnimationHandler.removeFromUpdate( this );
 
-
 	// reset JIT matrix and remove cache
 
-	for ( var h = 0; h < this.hierarchy.length; h++ ) {
+	for ( var h = 0; h < this.hierarchy.length; h ++ ) {
 
 		if ( this.hierarchy[ h ].animationCache !== undefined ) {
 
@@ -138,13 +132,11 @@ THREE.Animation.prototype.stop = function() {
 };
 
 
-// Update
-
 THREE.Animation.prototype.update = function( deltaTimeMS ) {
 
 	// early out
 
-	if( !this.isPlaying ) return;
+	if ( !this.isPlaying ) return;
 
 
 	// vars
@@ -174,7 +166,7 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
 
 	// update
 
-	for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
+	for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
 
 		object = this.hierarchy[ h ];
 		animationCache = object.animationCache;
@@ -207,7 +199,7 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
 
 			if ( this.JITCompile ) {
 
-				if( object instanceof THREE.Bone ) {
+				if ( object instanceof THREE.Bone ) {
 
 					object.skinMatrix = object.animationCache.originalMatrix;
 
@@ -222,7 +214,7 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
 
 			// loop through pos/rot/scl
 
-			for ( var t = 0; t < 3; t++ ) {
+			for ( var t = 0; t < 3; t ++ ) {
 
 				// get keys
 
@@ -363,9 +355,9 @@ THREE.Animation.prototype.update = function( deltaTimeMS ) {
 
 			this.hierarchy[ 0 ].updateMatrixWorld( true );
 
-			for ( var h = 0; h < this.hierarchy.length; h++ ) {
+			for ( var h = 0; h < this.hierarchy.length; h ++ ) {
 
-				if( this.hierarchy[ h ] instanceof THREE.Bone ) {
+				if ( this.hierarchy[ h ] instanceof THREE.Bone ) {
 
 					JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].skinMatrix.clone();
 
@@ -476,7 +468,7 @@ THREE.Animation.prototype.getPrevKeyWith = function( type, h, key ) {
 	}
 
 
-	for ( ; key >= 0; key-- ) {
+	for ( ; key >= 0; key -- ) {
 
 		if ( keys[ key ][ type ] !== undefined ) {
 

+ 17 - 16
src/extras/animation/AnimationHandler.js

@@ -13,7 +13,7 @@ THREE.AnimationHandler = (function() {
 
 	that.update = function( deltaTimeMS ) {
 
-		for( var i = 0; i < playing.length; i++ )
+		for( var i = 0; i < playing.length; i ++ )
 			playing[ i ].update( deltaTimeMS );
 
 	};
@@ -23,7 +23,7 @@ THREE.AnimationHandler = (function() {
 
 	that.addToUpdate = function( animation ) {
 
-		if( playing.indexOf( animation ) === -1 )
+		if ( playing.indexOf( animation ) === -1 )
 			playing.push( animation );
 
 	};
@@ -45,7 +45,7 @@ THREE.AnimationHandler = (function() {
 
 	that.add = function( data ) {
 
-		if( library[ data.name ] !== undefined )
+		if ( library[ data.name ] !== undefined )
 			console.log( "THREE.AnimationHandler.add: Warning! " + data.name + " already exists in library. Overwriting." );
 
 		library[ data.name ] = data;
@@ -58,9 +58,9 @@ THREE.AnimationHandler = (function() {
 
 	that.get = function( name ) {
 
-		if( typeof name === "string" ) {
+		if ( typeof name === "string" ) {
 
-			if( library[ name ] ) {
+			if ( library[ name ] ) {
 
 				return library[ name ];
 
@@ -144,20 +144,21 @@ THREE.AnimationHandler = (function() {
 					data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion( quat[0], quat[1], quat[2], quat[3] );
 
 				}
+
 			}
 
 
 			// prepare morph target keys
 
-			if( data.hierarchy[h].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
+			if( data.hierarchy[ h ].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
 
 				// get all used
 
 				var usedMorphTargets = {};
 
-				for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
+				for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
 
-					for( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
+					for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
 
 						var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
 						usedMorphTargets[ morphTargetName ] = -1;
@@ -171,15 +172,15 @@ THREE.AnimationHandler = (function() {
 
 				// set all used on all frames
 
-				for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
+				for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
 
 					var influences = {};
 
-					for( var morphTargetName in usedMorphTargets ) {
+					for ( var morphTargetName in usedMorphTargets ) {
 
-						for( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
+						for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
 
-							if( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
+							if ( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
 
 								influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
 								break;
@@ -188,7 +189,7 @@ THREE.AnimationHandler = (function() {
 
 						}
 
-						if( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
+						if ( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
 
 							influences[ morphTargetName ] = 0;
 
@@ -205,9 +206,9 @@ THREE.AnimationHandler = (function() {
 
 			// remove all keys that are on the same time
 
-			for( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
+			for ( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
 
-				if( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
+				if ( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
 
 					data.hierarchy[ h ].keys.splice( k, 1 );
 					k --;
@@ -219,7 +220,7 @@ THREE.AnimationHandler = (function() {
 
 			// set index
 
-			for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
+			for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
 
 				data.hierarchy[ h ].keys[ k ].index = k;