Browse Source

add *KeyframeTrack.clone().

Ben Houston 10 years ago
parent
commit
a185475c35

+ 0 - 42
src/animation/BooleanKeyframeTrack.js

@@ -1,42 +0,0 @@
-/**
- *
- * A Track that interpolates Boolean
- * 
- * @author Ben Houston / http://clara.io/
- * @author David Sarno / http://lighthaus.us/
- */
-
-THREE.BooleanKeyframeTrack = function ( name, keys ) {
-
-	THREE.KeyframeTrack.call( this, name, keys );
-
-	// local cache of value type to avoid allocations during runtime.
-	this.result = this.keys[0].value;
-
-};
-
-THREE.BooleanKeyframeTrack.prototype = {
-
-	constructor: THREE.BooleanKeyframeTrack,
-
-	setResult: function( value ) {
-
-		this.result = value;
-
-	},
-
-	// memoization of the lerp function for speed.
-	// NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
-	lerpValues: function( value0, value1, alpha ) {
-
-		return ( alpha < 1.0 ) ? value0 : value1;
-
-	},
-
-	compareValues: function( value0, value1 ) {
-
-		return ( value0 === value1 );
-
-	}
-
-};

+ 1 - 1
src/animation/KeyframeTrack.js

@@ -88,7 +88,7 @@ THREE.KeyframeTrack.prototype = {
 	// scale all keyframe times by a factor (useful for frame <-> seconds conversions)
 	// scale all keyframe times by a factor (useful for frame <-> seconds conversions)
 	scale: function( timeScale ) {
 	scale: function( timeScale ) {
 
 
-		if( timeTime !== 1.0 ) {
+		if( timeScale !== 1.0 ) {
 
 
 			for( var i = 1; i < this.keys.length; i ++ ) {
 			for( var i = 1; i < this.keys.length; i ++ ) {
 				this.keys[i].time *= timeScale;
 				this.keys[i].time *= timeScale;

+ 2 - 4
src/animation/tracks/BooleanKeyframeTrack.js

@@ -47,17 +47,15 @@ THREE.BooleanKeyframeTrack.prototype.clone = function() {
 		
 		
 		var key = this.keys[i];
 		var key = this.keys[i];
 		clonedKeys.push( {
 		clonedKeys.push( {
-			time: key.time
+			time: key.time,
 			value: key.value
 			value: key.value
 		} );
 		} );
 	}
 	}
 
 
-	var result = new THREE.BooleanKeyframeTrack( this.name );
-	return ( value0 === value1 );
+	return new THREE.BooleanKeyframeTrack( this.name );
 
 
 };
 };
 
 
-
 THREE.BooleanKeyframeTrack.parse = function( name, jsonKeys ) {
 THREE.BooleanKeyframeTrack.parse = function( name, jsonKeys ) {
 
 
 	return new THREE.BooleanKeyframeTrack( name, jsonKeys );
 	return new THREE.BooleanKeyframeTrack( name, jsonKeys );

+ 17 - 0
src/animation/tracks/ColorKeyframeTrack.js

@@ -39,6 +39,23 @@ THREE.ColorKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
 
 
 };
 };
 
 
+THREE.ColorKeyframeTrack.prototype.clone = function() {
+
+	var clonedKeys = [];
+
+	for( var i = 0; i < this.keys.length; i ++ ) {
+		
+		var key = this.keys[i];
+		clonedKeys.push( {
+			time: key.time,
+			value: key.value.clone()
+		} );
+	}
+
+	return new THREE.ColorKeyframeTrack( this.name );
+
+};
+
 THREE.ColorKeyframeTrack.parse = function( name, jsonKeys ) {
 THREE.ColorKeyframeTrack.parse = function( name, jsonKeys ) {
 
 
 	var keys = [];
 	var keys = [];

+ 17 - 0
src/animation/tracks/NumberKeyframeTrack.js

@@ -39,6 +39,23 @@ THREE.NumberKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
 
 
 };
 };
 
 
+THREE.NumberKeyframeTrack.prototype.clone = function() {
+
+	var clonedKeys = [];
+
+	for( var i = 0; i < this.keys.length; i ++ ) {
+		
+		var key = this.keys[i];
+		clonedKeys.push( {
+			time: key.time,
+			value: key.value
+		} );
+	}
+
+	return new THREE.NumberKeyframeTrack( this.name );
+
+};
+
 THREE.NumberKeyframeTrack.parse = function( name, jsonKeys ) {
 THREE.NumberKeyframeTrack.parse = function( name, jsonKeys ) {
 
 
 	return new THREE.NumberKeyframeTrack( name, jsonKeys );
 	return new THREE.NumberKeyframeTrack( name, jsonKeys );

+ 17 - 0
src/animation/tracks/QuaternionKeyframeTrack.js

@@ -39,6 +39,23 @@ THREE.QuaternionKeyframeTrack.prototype.compareValues = function( value0, value1
 
 
 };
 };
 
 
+THREE.QuaternionKeyframeTrack.prototype.clone = function() {
+
+	var clonedKeys = [];
+
+	for( var i = 0; i < this.keys.length; i ++ ) {
+		
+		var key = this.keys[i];
+		clonedKeys.push( {
+			time: key.time,
+			value: key.value.clone()
+		} );
+	}
+
+	return new THREE.QuaternionKeyframeTrack( this.name );
+
+};
+
 THREE.QuaternionKeyframeTrack.parse = function( name, jsonKeys ) {
 THREE.QuaternionKeyframeTrack.parse = function( name, jsonKeys ) {
 
 
 	var keys = [];
 	var keys = [];

+ 17 - 0
src/animation/tracks/StringKeyframeTrack.js

@@ -39,6 +39,23 @@ THREE.StringKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
 
 
 };
 };
 
 
+THREE.StringKeyframeTrack.prototype.clone = function() {
+
+	var clonedKeys = [];
+
+	for( var i = 0; i < this.keys.length; i ++ ) {
+		
+		var key = this.keys[i];
+		clonedKeys.push( {
+			time: key.time,
+			value: key.value
+		} );
+	}
+
+	return new THREE.StringKeyframeTrack( this.name );
+
+};
+
 THREE.StringKeyframeTrack.parse = function( name, jsonKeys ) {
 THREE.StringKeyframeTrack.parse = function( name, jsonKeys ) {
 
 
 	return new THREE.StringKeyframeTrack( name, jsonKeys );
 	return new THREE.StringKeyframeTrack( name, jsonKeys );

+ 17 - 0
src/animation/tracks/VectorKeyframeTrack.js

@@ -39,6 +39,23 @@ THREE.VectorKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
 
 
 };
 };
 
 
+THREE.VectorKeyframeTrack.prototype.clone = function() {
+
+	var clonedKeys = [];
+
+	for( var i = 0; i < this.keys.length; i ++ ) {
+		
+		var key = this.keys[i];
+		clonedKeys.push( {
+			time: key.time,
+			value: key.value.clone()
+		} );
+	}
+
+	return new THREE.VectorKeyframeTrack( this.name );
+
+};
+
 THREE.VectorKeyframeTrack.parse = function( name, jsonKeys ) {
 THREE.VectorKeyframeTrack.parse = function( name, jsonKeys ) {
 
 
 	var elementCount = jsonKeys[0].value.length;
 	var elementCount = jsonKeys[0].value.length;