Browse Source

remove old propertyBindings map and replace it with an array.

Ben Houston 10 năm trước cách đây
mục cha
commit
31bd3bf222
1 tập tin đã thay đổi với 23 bổ sung17 xóa
  1. 23 17
      src/animation/AnimationMixer.js

+ 23 - 17
src/animation/AnimationMixer.js

@@ -38,7 +38,6 @@ THREE.AnimationMixer.prototype = {
 			if( ! this.propertyBindings[ track.name ] ) {
 			
 				propertyBinding = new THREE.PropertyBinding( this.root, track.name );
-				this.propertyBindings[ track.name ] = propertyBinding;
 				this.propertyBindingsArray.push( propertyBinding );
 			
 			}
@@ -52,6 +51,18 @@ THREE.AnimationMixer.prototype = {
 
 	},
 
+	getPropertyBindingIndex: function( trackName ) {
+		
+		for( var k = 0; k < this.propertyBindings.length; k ++ ) {
+			if( this.propertyBindings[k].trackName === trackName ) {
+				return k;
+			}
+		}	
+
+		return -1;
+
+	},
+
 	updatePropertyBindingIndices: function() {
 
 		for( var i = 0; i < this.actions.length; i++ ) {
@@ -61,14 +72,10 @@ THREE.AnimationMixer.prototype = {
 			var propertyBindingIndices = [];
 
 			for( var j = 0; j < action.clip.tracks.length; j ++ ) {
-				var trackName = action.clip.tracks[j].name;
 
-				for( var k = 0; k < this.propertyBindingsArray.length; k ++ ) {
-					if( this.propertyBindingsArray[k].trackName === trackName ) {
-						propertyBindingIndices.push( k );
-						break;
-					}
-				}	
+				var trackName = action.clip.tracks[j].name;
+				propertyBindingIndices.push( this.getPropertyBindingIndex( trackName ) );
+			
 			}
 
 			action.propertyBindingIndices = propertyBindingIndices;
@@ -87,13 +94,12 @@ THREE.AnimationMixer.prototype = {
 		// unbind all property bindings
 		for( var i = 0; i < this.propertyBindingsArray.length; i ++ ) {
 
-			this.propertyBindingsArray[i].unbind();
+			this.propertyBindings[i].unbind();
 
 		}
 
 		this.actions = [];
-		this.propertyBindings = {};
-		this.propertyBindingsArray = [];
+		this.propertyBindings = [];
 
 	},
 
@@ -114,7 +120,8 @@ THREE.AnimationMixer.prototype = {
 		for( var i = 0; i < tracks.length; i ++ ) {
 		
 			var track = tracks[ i ];
-			var propertyBinding = this.propertyBindings[ track.name ];
+			var propertyBindingIndex = this.getPropertyBindingIndex( track.name );
+			var propertyBinding = this.propertyBindings[ propertyBindingIndex ];
 
 			propertyBinding.referenceCount -= 1;
 
@@ -122,8 +129,7 @@ THREE.AnimationMixer.prototype = {
 
 				propertyBinding.unbind();
 
-				delete this.propertyBindings[ track.name ];
-				this.propertyBindingArray.splice( this.propertyBindingArray.indexOf( propertyBinding ), 1 );
+				this.propertyBindings.splice( this.propertyBindings.indexOf( propertyBinding ), 1 );
 
 			}
 		}
@@ -210,16 +216,16 @@ THREE.AnimationMixer.prototype = {
 
 				var name = action.clip.tracks[j].name;
 
-				this.propertyBindingsArray[ action.propertyBindingIndices[ j ] ].accumulate( actionResults[j], weight );
+				this.propertyBindings[ action.propertyBindingIndices[ j ] ].accumulate( actionResults[j], weight );
 
 			}
 
 		}
 	
 		// apply to nodes
-		for ( var i = 0; i < this.propertyBindingsArray.length; i ++ ) {
+		for ( var i = 0; i < this.propertyBindings.length; i ++ ) {
 
-			this.propertyBindingsArray[ i ].apply();
+			this.propertyBindings[ i ].apply();
 
 		}
 	}