Browse Source

bones work! various optimizations.

Ben Houston 10 years ago
parent
commit
9eb5ca1554

+ 11 - 6
src/animation/AnimationClip.js

@@ -14,8 +14,8 @@ THREE.AnimationClip = function ( name, duration, tracks ) {
 
 	// TODO: maybe only do these on demand, as doing them here could potentially slow down loading
 	// but leaving these here during development as this ensures a lot of testing of these functions
-	//this.trim();
-	//this.optimize();
+	this.trim();
+	this.optimize();
 
 	this.results = {};
 	
@@ -172,8 +172,8 @@ THREE.AnimationClip.FromJSONLoaderAnimation = function( jsonLoader ) {
 		}
 		else {
 
-			var boneName = '.bone[' + boneList[ h ].name + ']';
-			console.log( 'boneName', boneName );
+			var boneName = '.bones[' + boneList[ h ].name + ']';
+			//console.log( 'boneName', boneName );
 		
 			// track contains positions...
 			var positionTrack = convertTrack( boneName + '.position', animationKeys, 'pos', function( animationKey ) {
@@ -184,7 +184,12 @@ THREE.AnimationClip.FromJSONLoaderAnimation = function( jsonLoader ) {
 			
 			// track contains quaternions...
 			var quaternionTrack = convertTrack( boneName + '.quaternion', animationKeys, 'rot', function( animationKey ) {
-					return new THREE.Quaternion().fromArray( animationKey.rot )
+					if( animationKey.rot.slerp ) {
+						return animationKey.rot.clone();
+					}
+					else {
+						return new THREE.Quaternion().fromArray( animationKey.rot );
+					}
 				} );
 
 			if( quaternionTrack ) tracks.push( quaternionTrack );
@@ -200,7 +205,7 @@ THREE.AnimationClip.FromJSONLoaderAnimation = function( jsonLoader ) {
 	}
 
 	var clip = new THREE.AnimationClip( clipName, duration, tracks );
-	console.log( 'clipFromJSONLoaderAnimation', clip );
+	//console.log( 'clipFromJSONLoaderAnimation', clip );
 
 	return clip;
 

+ 1 - 7
src/animation/AnimationMixer.js

@@ -64,12 +64,6 @@ THREE.AnimationMixer.prototype = {
 
 		//console.log( this.root.name + ".AnimationMixer.update( " + time + " )" );
 
-		for ( var i = 0; i < this.propertyBindingsArray.length; i ++ ) {
-
-			this.propertyBindingsArray[ i ].reset();
-
-		}
-
 		for( var i = 0; i < this.actions.length; i ++ ) {
 
 			var action = this.actions[i];
@@ -90,7 +84,7 @@ THREE.AnimationMixer.prototype = {
 		for ( var i = 0; i < this.propertyBindingsArray.length; i ++ ) {
 
 			this.propertyBindingsArray[ i ].apply();
-			
+
 		}
 	}
 

+ 3 - 3
src/animation/KeyframeTrack.js

@@ -155,13 +155,13 @@ THREE.KeyframeTrack.prototype = {
 			// if prevKey & currKey are the same time, remove currKey.  If you want immediate adjacent keys, use an epsilon offset
 			// it is not possible to have two keys at the same time as we sort them.  The sort is not stable on keys with the same time.
 			if( ( prevKey.time === currKey.time ) ) {
-				console.log(  'removing key at the same time', currKey );
+				//console.log(  'removing key at the same time', currKey );
 				continue;
 			}
 
 			// remove completely unnecessary keyframes that are the same as their prev and next keys
 			if( equalsFunc( prevKey.value, currKey.value ) && equalsFunc( currKey.value, nextKey.value ) ) {
-				console.log(  'removing key identical to prev and next', currKey );
+				//console.log(  'removing key identical to prev and next', currKey );
 				continue;
 			}
 
@@ -205,7 +205,7 @@ THREE.KeyframeTrack.prototype = {
 		if( ( firstKeysToRemove + lastKeysToRemove ) > 0 ) {
 			console.log(  '  triming removed keys: first and last', firstKeysToRemove, lastKeysToRemove, this.keys );
 			this.keys = this.keys.splice( firstKeysToRemove, this.keys.length - lastKeysToRemove - firstKeysToRemove );;
-			console.log(  '  result', this.keys );
+			//console.log(  '  result', this.keys );
 		}
 
 	}

+ 16 - 12
src/animation/PropertyBinding.js

@@ -13,11 +13,11 @@ THREE.PropertyBinding = function ( rootNode, trackName ) {
 
 	var parseResults = THREE.PropertyBinding.parseTrackName( trackName );
 
-	console.log( parseResults );
+	//console.log( parseResults );
 	this.directoryName = parseResults.directoryName;
 	this.nodeName = parseResults.nodeName;
-	this.material = parseResults.material;
-	this.materialIndex = parseResults.materialIndex;
+	this.objectName = parseResults.objectName;
+	this.objectIndex = parseResults.objectIndex;
 	this.propertyName = parseResults.propertyName;
 	this.propertyIndex = parseResults.propertyIndex;
 
@@ -68,7 +68,7 @@ THREE.PropertyBinding.prototype = {
 		// for speed capture the setter pattern as a closure (sort of a memoization pattern: https://en.wikipedia.org/wiki/Memoization)
 		if( ! this.internalApply ) {
 
-			 //console.log( "PropertyBinding.set( " + value + ")" );
+			 //console.log( "PropertyBinding", this );
 
 			 var equalsFunc = THREE.AnimationUtils.getEqualsFunc( this.cumulativeValue );
 
@@ -102,10 +102,10 @@ THREE.PropertyBinding.prototype = {
 					// TODO/OPTIMIZE, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
 					
 					// support resolving morphTarget names into indices.
-					console.log( "  resolving bone name: ", this.objectIndex );
+					//console.log( "  resolving bone name: ", this.objectIndex );
 					for( var i = 0; i < this.node.skeleton.bones.length; i ++ ) {
 						if( this.node.skeleton.bones[i].name === this.objectIndex ) {
-							console.log( "  resolved to index: ", i );
+							//console.log( "  resolved to index: ", i );
 							this.objectIndex = i;
 							break;
 						}
@@ -212,15 +212,19 @@ THREE.PropertyBinding.prototype = {
 		}
 
 		// early exit if there is nothing to apply.
-		if( this.cumulativeWeight <= 0 ) {
-			return;
-		}
+		if( this.cumulativeWeight > 0 ) {
+		
+			var valueChanged = this.internalApply();
 
-		var valueChanged = this.internalApply();
+			if( valueChanged && this.triggerDirty ) {
+				this.triggerDirty();
+			}
 
-		if( valueChanged && this.triggerDirty ) {
-			this.triggerDirty();
 		}
+
+		// reset accumulator
+		this.cumulativeValue = null;
+		this.cumulativeWeight = 0;
 	},
 
 	get: function() {