Browse Source

Clean up.

Mr.doob 9 years ago
parent
commit
275f339a64
33 changed files with 336 additions and 350 deletions
  1. 1 0
      examples/webgl_camera_logarithmicdepthbuffer.html
  2. 21 22
      src/animation/AnimationAction.js
  3. 39 41
      src/animation/AnimationClip.js
  4. 32 32
      src/animation/AnimationMixer.js
  5. 35 39
      src/animation/AnimationUtils.js
  6. 27 27
      src/animation/KeyframeTrack.js
  7. 96 98
      src/animation/PropertyBinding.js
  8. 3 4
      src/animation/tracks/BooleanKeyframeTrack.js
  9. 4 5
      src/animation/tracks/ColorKeyframeTrack.js
  10. 3 4
      src/animation/tracks/NumberKeyframeTrack.js
  11. 7 8
      src/animation/tracks/QuaternionKeyframeTrack.js
  12. 3 4
      src/animation/tracks/StringKeyframeTrack.js
  13. 4 5
      src/animation/tracks/VectorKeyframeTrack.js
  14. 2 2
      src/core/Raycaster.js
  15. 6 7
      src/extras/FontUtils.js
  16. 8 8
      src/extras/ImageUtils.js
  17. 1 1
      src/extras/core/Path.js
  18. 3 2
      src/extras/geometries/EdgesGeometry.js
  19. 3 2
      src/extras/geometries/WireframeGeometry.js
  20. 2 2
      src/extras/helpers/CameraHelper.js
  21. 2 2
      src/loaders/AnimationLoader.js
  22. 8 9
      src/loaders/JSONLoader.js
  23. 2 2
      src/loaders/ObjectLoader.js
  24. 3 3
      src/math/Color.js
  25. 1 1
      src/renderers/shaders/ShaderChunk/hemilight_fragment.glsl
  26. 1 1
      src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  27. 3 3
      src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  28. 1 1
      src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  29. 1 1
      src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  30. 2 2
      src/renderers/webgl/WebGLShader.js
  31. 8 8
      src/renderers/webgl/plugins/LensFlarePlugin.js
  32. 2 2
      src/renderers/webgl/plugins/SpritePlugin.js
  33. 2 2
      src/textures/VideoTexture.js

+ 1 - 0
examples/webgl_camera_logarithmicdepthbuffer.html

@@ -337,6 +337,7 @@
 			}
 			function onMouseWheel(ev) {
 				var amount = -ev.wheelDeltaY || ev.detail;
+				if ( amount === 0 ) return;
 				var dir = amount / Math.abs(amount);
 				zoomspeed = dir/10;
 

+ 21 - 22
src/animation/AnimationAction.js

@@ -1,14 +1,14 @@
 /**
  *
  * A clip that has been explicitly scheduled.
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
 
 THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
 
-	if( clip === undefined ) throw new Error( 'clip is null' );
+	if ( clip === undefined ) throw new Error( 'clip is null' );
 	this.clip = clip;
 	this.localRoot = null;
 	this.startTime = startTime || 0;
@@ -39,7 +39,7 @@ THREE.AnimationAction.prototype = {
 		this.localRoot = localRoot;
 
 		return this;
-		
+
 	},
 
 	updateTime: function( clipDeltaTime ) {
@@ -49,23 +49,22 @@ THREE.AnimationAction.prototype = {
    		var previousActionTime = this.actionTime;
 
 		var duration = this.clip.duration;
-	
+
 		this.actionTime = this.actionTime + clipDeltaTime;
-	
-		if( this.loop === THREE.LoopOnce ) {
+
+		if ( this.loop === THREE.LoopOnce ) {
 
 			this.loopCount = 0;
 			this.clipTime = Math.min( Math.max( this.actionTime, 0 ), duration );
-	
+
 			// if time is changed since last time, see if we have hit a start/end limit
-			if( this.clipTime !== previousClipTime ) {
+			if ( this.clipTime !== previousClipTime ) {
 
-				if( this.clipTime === duration ) {
+				if ( this.clipTime === duration ) {
 
 					this.mixer.dispatchEvent( { type: 'finished', action: this, direction: 1 } );
 
-				}
-				else if( this.clipTime === 0 ) {
+				} else if ( this.clipTime === 0 ) {
 
 					this.mixer.dispatchEvent( { type: 'finished', action: this, direction: -1 } );
 
@@ -73,20 +72,20 @@ THREE.AnimationAction.prototype = {
 
 			}
 
-		
+
 			return this.clipTime;
 
 		}
-		
+
 		this.loopCount = Math.floor( this.actionTime / duration );
-	
+
 		var newClipTime = this.actionTime - this.loopCount * duration;
 		newClipTime = newClipTime % duration;
-	
+
 		// if we are ping pong looping, ensure that we go backwards when appropriate
-		if( this.loop == THREE.LoopPingPong ) {
+		if ( this.loop == THREE.LoopPingPong ) {
 
-			if( Math.abs( this.loopCount % 2 ) === 1 ) {
+			if ( Math.abs( this.loopCount % 2 ) === 1 ) {
 
 				newClipTime = duration - newClipTime;
 
@@ -96,12 +95,12 @@ THREE.AnimationAction.prototype = {
 
 		this.clipTime = newClipTime;
 
-		if( this.loopCount !== previousLoopCount ) {
+		if ( this.loopCount !== previousLoopCount ) {
 
    			this.mixer.dispatchEvent( { type: 'loop', action: this, loopDelta: ( this.loopCount - this.loopCount ) } );
 
    		}
-	
+
 	   	return this.clipTime;
 
 	},
@@ -136,12 +135,12 @@ THREE.AnimationAction.prototype = {
 		var clipResults = this.clip.getAt( this.clipTime );
 
 		return clipResults;
-		
+
 	},
 
 	getTimeScaleAt: function( time ) {
 
-		if( this.timeScale.getAt ) {
+		if ( this.timeScale.getAt ) {
 			// pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
 			return this.timeScale.getAt( time );
 
@@ -153,7 +152,7 @@ THREE.AnimationAction.prototype = {
 
 	getWeightAt: function( time ) {
 
-		if( this.weight.getAt ) {
+		if ( this.weight.getAt ) {
 			// pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
 			return this.weight.getAt( time );
 

+ 39 - 41
src/animation/AnimationClip.js

@@ -1,7 +1,7 @@
 /**
  *
  * Reusable set of Tracks that represent an animation.
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -13,8 +13,8 @@ THREE.AnimationClip = function ( name, duration, tracks ) {
 	this.duration = ( duration !== undefined ) ? duration : -1;
 
 	// this means it should figure out its duration by scanning the tracks
-	if( this.duration < 0 ) {
-		for( var i = 0; i < this.tracks.length; i ++ ) {
+	if ( this.duration < 0 ) {
+		for ( var i = 0; i < this.tracks.length; i ++ ) {
 			var track = this.tracks[i];
 			this.duration = Math.max( track.keys[ track.keys.length - 1 ].time );
 		}
@@ -26,7 +26,7 @@ THREE.AnimationClip = function ( name, duration, tracks ) {
 	this.optimize();
 
 	this.results = [];
-	
+
 };
 
 THREE.AnimationClip.prototype = {
@@ -37,7 +37,7 @@ THREE.AnimationClip.prototype = {
 
 		clipTime = Math.max( 0, Math.min( clipTime, this.duration ) );
 
-		for( var i = 0; i < this.tracks.length; i ++ ) {
+		for ( var i = 0; i < this.tracks.length; i ++ ) {
 
 			var track = this.tracks[ i ];
 
@@ -50,7 +50,7 @@ THREE.AnimationClip.prototype = {
 
 	trim: function() {
 
-		for( var i = 0; i < this.tracks.length; i ++ ) {
+		for ( var i = 0; i < this.tracks.length; i ++ ) {
 
 			this.tracks[ i ].trim( 0, this.duration );
 
@@ -62,7 +62,7 @@ THREE.AnimationClip.prototype = {
 
 	optimize: function() {
 
-		for( var i = 0; i < this.tracks.length; i ++ ) {
+		for ( var i = 0; i < this.tracks.length; i ++ ) {
 
 			this.tracks[ i ].optimize();
 
@@ -81,7 +81,7 @@ THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetS
 	var numMorphTargets = morphTargetSequence.length;
 	var tracks = [];
 
-	for( var i = 0; i < numMorphTargets; i ++ ) {
+	for ( var i = 0; i < numMorphTargets; i ++ ) {
 
 		var keys = [];
 
@@ -92,7 +92,7 @@ THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetS
 		keys.sort( THREE.KeyframeTrack.keyComparer );
 
 		// if there is a key at the first frame, duplicate it as the last frame as well for perfect loop.
-		if( keys[0].time === 0 ) {
+		if ( keys[0].time === 0 ) {
 			keys.push( {
 				time: numMorphTargets,
 				value: keys[0].value
@@ -108,9 +108,9 @@ THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetS
 
 THREE.AnimationClip.findByName = function( clipArray, name ) {
 
-	for( var i = 0; i < clipArray.length; i ++ ) {
+	for ( var i = 0; i < clipArray.length; i ++ ) {
 
-		if( clipArray[i].name === name ) {
+		if ( clipArray[i].name === name ) {
 
 			return clipArray[i];
 
@@ -122,7 +122,7 @@ THREE.AnimationClip.findByName = function( clipArray, name ) {
 };
 
 THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets, fps ) {
-	
+
 	var animationToMorphTargets = {};
 
 	// tested with https://regex101.com/ on trick sequences such flamingo_flyA_003, flamingo_run1_003, crdeath0059
@@ -133,13 +133,13 @@ THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets
 
 		var morphTarget = morphTargets[ i ];
 		var parts = morphTarget.name.match( pattern );
-	
+
 		if ( parts && parts.length > 1 ) {
 
 			var name = parts[ 1 ];
 
 			var animationMorphTargets = animationToMorphTargets[ name ];
-			if( ! animationMorphTargets ) {
+			if ( ! animationMorphTargets ) {
 				animationToMorphTargets[ name ] = animationMorphTargets = [];
 			}
 
@@ -151,7 +151,7 @@ THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets
 
 	var clips = [];
 
-	for( var name in animationToMorphTargets ) {
+	for ( var name in animationToMorphTargets ) {
 
 		clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
 	}
@@ -165,7 +165,7 @@ THREE.AnimationClip.parse = function( json ) {
 
 	var tracks = [];
 
-	for( var i = 0; i < json.tracks.length; i ++ ) {
+	for ( var i = 0; i < json.tracks.length; i ++ ) {
 
 		tracks.push( THREE.KeyframeTrack.parse( json.tracks[i] ).scale( 1.0 / json.fps ) );
 
@@ -179,7 +179,7 @@ THREE.AnimationClip.parse = function( json ) {
 // parse the animation.hierarchy format
 THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
 
-	if( ! animation ) {
+	if ( ! animation ) {
 		console.error( "  no animation in JSONLoader data" );
 		return null;
 	}
@@ -188,20 +188,20 @@ THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
 
 		var keys = [];
 
-		for( var k = 0; k < animationKeys.length; k ++ ) {
+		for ( var k = 0; k < animationKeys.length; k ++ ) {
 
 			var animationKey = animationKeys[k];
 
-			if( animationKey[propertyName] !== undefined ) {
+			if ( animationKey[propertyName] !== undefined ) {
 
 				keys.push( { time: animationKey.time, value: animationKeyToValueFunc( animationKey ) } );
 			}
-	
+
 		}
 
 		// only return track if there are actually keys.
-		if( keys.length > 0 ) {
-		
+		if ( keys.length > 0 ) {
+
 			return new trackType( trackName, keys );
 
 		}
@@ -223,19 +223,19 @@ THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
 		var animationKeys = hierarchyTracks[ h ].keys;
 
 		// skip empty tracks
-		if( ! animationKeys || animationKeys.length == 0 ) {
+		if ( ! animationKeys || animationKeys.length == 0 ) {
 			continue;
 		}
 
 		// process morph targets in a way exactly compatible with AnimationHandler.init( animation )
-		if( animationKeys[0].morphTargets ) {
+		if ( animationKeys[0].morphTargets ) {
 
 			// figure out all morph targets used in this track
 			var morphTargetNames = {};
-			for( var k = 0; k < animationKeys.length; k ++ ) {
+			for ( var k = 0; k < animationKeys.length; k ++ ) {
 
-				if( animationKeys[k].morphTargets ) {
-					for( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
+				if ( animationKeys[k].morphTargets ) {
+					for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
 
 						morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
 					}
@@ -244,11 +244,11 @@ THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
 			}
 
 			// create a track for each morph target with all zero morphTargetInfluences except for the keys in which the morphTarget is named.
-			for( var morphTargetName in morphTargetNames ) {
+			for ( var morphTargetName in morphTargetNames ) {
 
 				var keys = [];
 
-				for( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
+				for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
 
 					var animationKey = animationKeys[k];
 
@@ -256,7 +256,7 @@ THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
 							time: animationKey.time,
 							value: (( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
 						});
-				
+
 				}
 
 				tracks.push( new THREE.NumberKeyframeTrack( nodeName + '.morphTargetInfluence[' + morphTargetName + ']', keys ) );
@@ -265,41 +265,39 @@ THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
 
 			duration = morphTargetNames.length * ( fps || 1.0 );
 
-		}
-		else {
+		} else {
 
 			var boneName = nodeName + '.bones[' + bones[ h ].name + ']';
-		
+
 			// track contains positions...
 			var positionTrack = convertTrack( boneName + '.position', animationKeys, 'pos', THREE.VectorKeyframeTrack, function( animationKey ) {
 					return new THREE.Vector3().fromArray( animationKey.pos )
 				} );
 
-			if( positionTrack ) tracks.push( positionTrack );
-			
+			if ( positionTrack ) tracks.push( positionTrack );
+
 			// track contains quaternions...
 			var quaternionTrack = convertTrack( boneName + '.quaternion', animationKeys, 'rot', THREE.QuaternionKeyframeTrack, function( animationKey ) {
-					if( animationKey.rot.slerp ) {
+					if ( animationKey.rot.slerp ) {
 						return animationKey.rot.clone();
-					}
-					else {
+					} else {
 						return new THREE.Quaternion().fromArray( animationKey.rot );
 					}
 				} );
 
-			if( quaternionTrack ) tracks.push( quaternionTrack );
+			if ( quaternionTrack ) tracks.push( quaternionTrack );
 
 			// track contains quaternions...
 			var scaleTrack = convertTrack( boneName + '.scale', animationKeys, 'scl', THREE.VectorKeyframeTrack, function( animationKey ) {
 					return new THREE.Vector3().fromArray( animationKey.scl )
 				} );
 
-			if( scaleTrack ) tracks.push( scaleTrack );
+			if ( scaleTrack ) tracks.push( scaleTrack );
 
 		}
 	}
 
-	if( tracks.length === 0 ) {
+	if ( tracks.length === 0 ) {
 
 		return null;
 

+ 32 - 32
src/animation/AnimationMixer.js

@@ -33,23 +33,23 @@ THREE.AnimationMixer.prototype = {
 
 		var root = action.localRoot || this.root;
 
-		for( var i = 0; i < tracks.length; i ++ ) {
+		for ( var i = 0; i < tracks.length; i ++ ) {
 
 			var track = tracks[ i ];
 
-			var propertyBindingKey = root.uuid + '-' + track.name;			
+			var propertyBindingKey = root.uuid + '-' + track.name;
 			var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
 
-			if( propertyBinding === undefined ) {
-			
+			if ( propertyBinding === undefined ) {
+
 				propertyBinding = new THREE.PropertyBinding( root, track.name );
 				this.propertyBindingMap[ propertyBindingKey ] = propertyBinding;
-			
+
 			}
 
 			// push in the same order as the tracks.
 			action.propertyBindings.push( propertyBinding );
-			
+
 			// track usages of shared property bindings, because if we leave too many around, the mixer can get slow
 			propertyBinding.referenceCount += 1;
 
@@ -59,14 +59,14 @@ THREE.AnimationMixer.prototype = {
 
 	removeAllActions: function() {
 
-		for( var i = 0; i < this.actions.length; i ++ ) {
+		for ( var i = 0; i < this.actions.length; i ++ ) {
 
 			this.actions[i].mixer = null;
-			
+
 		}
 
 		// unbind all property bindings
-		for( var properyBindingKey in this.propertyBindingMap ) {
+		for ( var properyBindingKey in this.propertyBindingMap ) {
 
 			this.propertyBindingMap[ properyBindingKey ].unbind();
 
@@ -95,16 +95,16 @@ THREE.AnimationMixer.prototype = {
 		var root = action.localRoot || this.root;
 		var tracks = action.clip.tracks;
 
-		for( var i = 0; i < tracks.length; i ++ ) {
-		
+		for ( var i = 0; i < tracks.length; i ++ ) {
+
 			var track = tracks[ i ];
 
-			var propertyBindingKey = root.uuid + '-' + track.name;			
+			var propertyBindingKey = root.uuid + '-' + track.name;
 			var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
-	
+
 			propertyBinding.referenceCount -= 1;
 
-			if( propertyBinding.referenceCount <= 0 ) {
+			if ( propertyBinding.referenceCount <= 0 ) {
 
 				propertyBinding.unbind();
 
@@ -120,9 +120,9 @@ THREE.AnimationMixer.prototype = {
 	// can be optimized if needed
 	findActionByName: function( name ) {
 
-		for( var i = 0; i < this.actions.length; i ++ ) {
+		for ( var i = 0; i < this.actions.length; i ++ ) {
 
-			if( this.actions[i].name === name ) return this.actions[i];
+			if ( this.actions[i].name === name ) return this.actions[i];
 
 		}
 
@@ -145,7 +145,7 @@ THREE.AnimationMixer.prototype = {
 
 		keys.push( { time: this.time, value: 1 } );
 		keys.push( { time: this.time + duration, value: 0 } );
-		
+
 		action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
 
 		return this;
@@ -153,12 +153,12 @@ THREE.AnimationMixer.prototype = {
 	},
 
 	fadeIn: function( action, duration ) {
-		
+
 		var keys = [];
-		
+
 		keys.push( { time: this.time, value: 0 } );
 		keys.push( { time: this.time + duration, value: 1 } );
-		
+
 		action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
 
 		return this;
@@ -168,10 +168,10 @@ THREE.AnimationMixer.prototype = {
 	warp: function( action, startTimeScale, endTimeScale, duration ) {
 
 		var keys = [];
-		
+
 		keys.push( { time: this.time, value: startTimeScale } );
 		keys.push( { time: this.time + duration, value: endTimeScale } );
-		
+
 		action.timeScale = new THREE.NumberKeyframeTrack( "timeScale", keys );
 
 		return this;
@@ -183,8 +183,8 @@ THREE.AnimationMixer.prototype = {
 		this.fadeOut( fadeOutAction, duration );
 		this.fadeIn( fadeInAction, duration );
 
-		if( warp ) {
-	
+		if ( warp ) {
+
 			var startEndRatio = fadeOutAction.clip.duration / fadeInAction.clip.duration;
 			var endStartRatio = 1.0 / startEndRatio;
 
@@ -194,7 +194,7 @@ THREE.AnimationMixer.prototype = {
 		}
 
 		return this;
-		
+
 	},
 
 	update: function( deltaTime ) {
@@ -202,7 +202,7 @@ THREE.AnimationMixer.prototype = {
 		var mixerDeltaTime = deltaTime * this.timeScale;
 		this.time += mixerDeltaTime;
 
-		for( var i = 0; i < this.actions.length; i ++ ) {
+		for ( var i = 0; i < this.actions.length; i ++ ) {
 
 			var action = this.actions[i];
 
@@ -210,12 +210,12 @@ THREE.AnimationMixer.prototype = {
 
 			var actionTimeScale = action.getTimeScaleAt( this.time );
 			var actionDeltaTime = mixerDeltaTime * actionTimeScale;
-		
+
 			var actionResults = action.update( actionDeltaTime );
 
-			if( action.weight <= 0 || ! action.enabled ) continue;
+			if ( action.weight <= 0 || ! action.enabled ) continue;
 
-			for( var j = 0; j < actionResults.length; j ++ ) {
+			for ( var j = 0; j < actionResults.length; j ++ ) {
 
 				var name = action.clip.tracks[j].name;
 
@@ -224,16 +224,16 @@ THREE.AnimationMixer.prototype = {
 			}
 
 		}
-	
+
 		// apply to nodes
-		for( var propertyBindingKey in this.propertyBindingMap ) {
+		for ( var propertyBindingKey in this.propertyBindingMap ) {
 
 			this.propertyBindingMap[ propertyBindingKey ].apply();
 
 		}
 
 		return this;
-		
+
 	}
 
 };

+ 35 - 39
src/animation/AnimationUtils.js

@@ -3,27 +3,27 @@
  * @author David Sarno / http://lighthaus.us/
  */
 
- THREE.AnimationUtils = {
+THREE.AnimationUtils = {
 
- 	getEqualsFunc: function( exemplarValue ) {
+	getEqualsFunc: function( exemplarValue ) {
 
-		if( exemplarValue.equals ) {
+		if ( exemplarValue.equals ) {
 			return function equals_object( a, b ) {
 				return a.equals( b );
 			}
 		}
 
 		return function equals_primitive( a, b ) {
-			return ( a === b );	
+			return ( a === b );
 		};
 
 	},
 
- 	clone: function( exemplarValue ) {
+	clone: function( exemplarValue ) {
 
- 		var typeName = typeof exemplarValue;
-		if( typeName === "object" ) {
-			if( exemplarValue.clone ) {
+		var typeName = typeof exemplarValue;
+		if ( typeName === "object" ) {
+			if ( exemplarValue.clone ) {
 				return exemplarValue.clone();
 			}
 			console.error( "can not figure out how to copy exemplarValue", exemplarValue );
@@ -33,7 +33,7 @@
 
 	},
 
- 	lerp: function( a, b, alpha, interTrack ) {
+	lerp: function( a, b, alpha, interTrack ) {
 
 		var lerpFunc = THREE.AnimationUtils.getLerpFunc( a, interTrack );
 
@@ -44,7 +44,7 @@
 	lerp_object: function( a, b, alpha ) {
 		return a.lerp( b, alpha );
 	},
-	
+
 	slerp_object: function( a, b, alpha ) {
 		return a.slerp( b, alpha );
 	},
@@ -60,57 +60,53 @@
 	lerp_boolean_immediate: function( a, b, alpha ) {
 		return a;
 	},
-	
+
 	lerp_string: function( a, b, alpha ) {
 		return ( alpha < 0.5 ) ? a : b;
 	},
-	
+
 	lerp_string_immediate: function( a, b, alpha ) {
- 		return a;		 		
+ 		return a;
  	},
 
-	// NOTE: this is an accumulator function that modifies the first argument (e.g. a).  This is to minimize memory alocations.
+	// NOTE: this is an accumulator function that modifies the first argument (e.g. a).	This is to minimize memory alocations.
 	getLerpFunc: function( exemplarValue, interTrack ) {
 
-		if( exemplarValue === undefined || exemplarValue === null ) throw new Error( "examplarValue is null" );
+		if ( exemplarValue === undefined || exemplarValue === null ) throw new Error( "examplarValue is null" );
 
 		var typeName = typeof exemplarValue;
-		switch( typeName ) {
-		 	case "object": {
 
-				if( exemplarValue.lerp ) {
+		switch( typeName ) {
 
+			case "object":
+				if ( exemplarValue.lerp ) {
 					return THREE.AnimationUtils.lerp_object;
-
 				}
-				if( exemplarValue.slerp ) {
 
+				if ( exemplarValue.slerp ) {
 					return THREE.AnimationUtils.slerp_object;
-
 				}
 				break;
-			}
-		 	case "number": {
+
+			case "number":
 				return THREE.AnimationUtils.lerp_number;
-		 	}	
-		 	case "boolean": {
-		 		if( interTrack ) {
+
+			case "boolean":
+				if ( interTrack ) {
 					return THREE.AnimationUtils.lerp_boolean;
-		 		}
-		 		else {
+				} else {
 					return THREE.AnimationUtils.lerp_boolean_immediate;
-		 		}
-		 	}
-		 	case "string": {
-		 		if( interTrack ) {
+				}
+
+			case "string":
+				if ( interTrack ) {
 					return THREE.AnimationUtils.lerp_string;
-		 		}
-		 		else {
+				} else {
 					return THREE.AnimationUtils.lerp_string_immediate;
-			 	}
-		 	}
-		};
+				}
+
+		}
 
 	}
-	
-};
+
+};

+ 27 - 27
src/animation/KeyframeTrack.js

@@ -8,8 +8,8 @@
 
 THREE.KeyframeTrack = function ( name, keys ) {
 
-	if( name === undefined ) throw new Error( "track name is undefined" );
-	if( keys === undefined || keys.length === 0 ) throw new Error( "no keys in track named " + name );
+	if ( name === undefined ) throw new Error( "track name is undefined" );
+	if ( keys === undefined || keys.length === 0 ) throw new Error( "no keys in track named " + name );
 
 	this.name = name;
 	this.keys = keys;	// time in seconds, value as value
@@ -19,6 +19,7 @@ THREE.KeyframeTrack = function ( name, keys ) {
 
 	this.validate();
 	this.optimize();
+
 };
 
 THREE.KeyframeTrack.prototype = {
@@ -38,7 +39,7 @@ THREE.KeyframeTrack.prototype = {
 			this.lastIndex --;
 		}
 
-		if( this.lastIndex >= this.keys.length ) {
+		if ( this.lastIndex >= this.keys.length ) {
 
 			this.setResult( this.keys[ this.keys.length - 1 ].value );
 
@@ -46,7 +47,7 @@ THREE.KeyframeTrack.prototype = {
 
 		}
 
-		if( this.lastIndex === 0 ) {
+		if ( this.lastIndex === 0 ) {
 
 			this.setResult( this.keys[ 0 ].value );
 
@@ -58,7 +59,7 @@ THREE.KeyframeTrack.prototype = {
 		this.setResult( prevKey.value );
 
 		// if true, means that prev/current keys are identical, thus no interpolation required.
-		if( prevKey.constantToNext ) {
+		if ( prevKey.constantToNext ) {
 
 			return this.result;
 
@@ -76,9 +77,9 @@ THREE.KeyframeTrack.prototype = {
 	// move all keyframes either forwards or backwards in time
 	shift: function( timeOffset ) {
 
-		if( timeOffset !== 0.0 ) {
+		if ( timeOffset !== 0.0 ) {
 
-			for( var i = 0; i < this.keys.length; i ++ ) {
+			for ( var i = 0; i < this.keys.length; i ++ ) {
 				this.keys[i].time += timeOffset;
 			}
 
@@ -91,9 +92,9 @@ THREE.KeyframeTrack.prototype = {
 	// scale all keyframe times by a factor (useful for frame <-> seconds conversions)
 	scale: function( timeScale ) {
 
-		if( timeScale !== 1.0 ) {
+		if ( timeScale !== 1.0 ) {
 
-			for( var i = 0; i < this.keys.length; i ++ ) {
+			for ( var i = 0; i < this.keys.length; i ++ ) {
 				this.keys[i].time *= timeScale;
 			}
 
@@ -108,24 +109,23 @@ THREE.KeyframeTrack.prototype = {
  	trim: function( startTime, endTime ) {
 
 		var firstKeysToRemove = 0;
-		for( var i = 1; i < this.keys.length; i ++ ) {
-			if( this.keys[i] <= startTime ) {
+		for ( var i = 1; i < this.keys.length; i ++ ) {
+			if ( this.keys[i] <= startTime ) {
 				firstKeysToRemove ++;
 			}
 		}
 
 		var lastKeysToRemove = 0;
-		for( var i = this.keys.length - 2; i > 0; i ++ ) {
-			if( this.keys[i] >= endTime ) {
+		for ( var i = this.keys.length - 2; i > 0; i ++ ) {
+			if ( this.keys[i] >= endTime ) {
 				lastKeysToRemove ++;
-			}
-			else {
+			} else {
 				break;
 			}
 		}
 
 		// remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
-		if( ( firstKeysToRemove + lastKeysToRemove ) > 0 ) {
+		if ( ( firstKeysToRemove + lastKeysToRemove ) > 0 ) {
 			this.keys = this.keys.splice( firstKeysToRemove, this.keys.length - lastKeysToRemove - firstKeysToRemove );;
 		}
 
@@ -149,31 +149,31 @@ THREE.KeyframeTrack.prototype = {
 
 		var prevKey = null;
 
-		if( this.keys.length === 0 ) {
+		if ( this.keys.length === 0 ) {
 			console.error( "  track is empty, no keys", this );
 			return;
 		}
 
-		for( var i = 0; i < this.keys.length; i ++ ) {
+		for ( var i = 0; i < this.keys.length; i ++ ) {
 
 			var currKey = this.keys[i];
 
-			if( ! currKey ) {
+			if ( ! currKey ) {
 				console.error( "  key is null in track", this, i );
 				return;
 			}
 
-			if( ( typeof currKey.time ) !== 'number' || Number.isNaN( currKey.time ) ) {
+			if ( ( typeof currKey.time ) !== 'number' || Number.isNaN( currKey.time ) ) {
 				console.error( "  key.time is not a valid number", this, i, currKey );
 				return;
 			}
 
-			if( currKey.value === undefined || currKey.value === null) {
+			if ( currKey.value === undefined || currKey.value === null) {
 				console.error( "  key.value is null in track", this, i, currKey );
 				return;
 			}
 
-			if( prevKey && prevKey.time > currKey.time ) {
+			if ( prevKey && prevKey.time > currKey.time ) {
 				console.error( "  key.time is less than previous key time, out of order keys", this, i, currKey, prevKey );
 				return;
 			}
@@ -195,20 +195,20 @@ THREE.KeyframeTrack.prototype = {
 
 		var equalsFunc = THREE.AnimationUtils.getEqualsFunc( prevKey.value );
 
-		for( var i = 1; i < this.keys.length - 1; i ++ ) {
+		for ( var i = 1; i < this.keys.length - 1; i ++ ) {
 			var currKey = this.keys[i];
 			var nextKey = this.keys[i+1];
 
 			// 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 ) ) {
+			if ( ( prevKey.time === currKey.time ) ) {
 
 				continue;
 
 			}
 
 			// remove completely unnecessary keyframes that are the same as their prev and next keys
-			if( this.compareValues( prevKey.value, currKey.value ) && this.compareValues( currKey.value, nextKey.value ) ) {
+			if ( this.compareValues( prevKey.value, currKey.value ) && this.compareValues( currKey.value, nextKey.value ) ) {
 
 				continue;
 
@@ -236,7 +236,7 @@ THREE.KeyframeTrack.keyComparer = function keyComparator(key0, key1) {
 
 THREE.KeyframeTrack.parse = function( json ) {
 
-	if( json.type === undefined ) throw new Error( "track type undefined, can not parse" );
+	if ( json.type === undefined ) throw new Error( "track type undefined, can not parse" );
 
 	var trackType = THREE.KeyframeTrack.GetTrackTypeForTypeName( json.type );
 
@@ -271,4 +271,4 @@ THREE.KeyframeTrack.GetTrackTypeForTypeName = function( typeName ) {
 	};
 
 	throw new Error( "Unsupported typeName: " + typeName );
-};
+};

+ 96 - 98
src/animation/PropertyBinding.js

@@ -1,7 +1,7 @@
 /**
  *
  * A track bound to a real value in the scene graph.
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -23,7 +23,7 @@ THREE.PropertyBinding = function ( rootNode, trackName ) {
 	this.propertyIndex = parseResults.propertyIndex;
 
 	this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName ) || rootNode;
-	
+
 	this.cumulativeValue = null;
 	this.cumulativeWeight = 0;
 };
@@ -40,22 +40,21 @@ THREE.PropertyBinding.prototype = {
 	},
 
 	accumulate: function( value, weight ) {
-		
-		if( ! this.isBound ) this.bind();
 
-		if( this.cumulativeWeight === 0 ) {
+		if ( ! this.isBound ) this.bind();
+
+		if ( this.cumulativeWeight === 0 ) {
 
-			if( weight > 0 ) {
+			if ( weight > 0 ) {
 
-				if( this.cumulativeValue === null ) {
+				if ( this.cumulativeValue === null ) {
 					this.cumulativeValue = THREE.AnimationUtils.clone( value );
 				}
 				this.cumulativeWeight = weight;
 
 			}
 
-		}
-		else {
+		} else {
 
 			var lerpAlpha = weight / ( this.cumulativeWeight + weight );
 			this.cumulativeValue = this.lerpValue( this.cumulativeValue, value, lerpAlpha );
@@ -67,7 +66,7 @@ THREE.PropertyBinding.prototype = {
 
 	unbind: function() {
 
-		if( ! this.isBound ) return;
+		if ( ! this.isBound ) return;
 
 		this.setValue( this.originalValue );
 
@@ -75,7 +74,7 @@ THREE.PropertyBinding.prototype = {
 		this.getValue = null;
 		this.lerpValue = null;
 		this.equalsValue = null;
-		this.triggerDirty = null;	
+		this.triggerDirty = null;
 		this.isBound = false;
 
 	},
@@ -83,59 +82,57 @@ THREE.PropertyBinding.prototype = {
 	// bind to the real property in the scene graph, remember original value, memorize various accessors for speed/inefficiency
 	bind: function() {
 
-		if( this.isBound ) return;
+		if ( this.isBound ) return;
 
 		var targetObject = this.node;
 
  		// ensure there is a value node
-		if( ! targetObject ) {
+		if ( ! targetObject ) {
 			console.error( "  trying to update node for track: " + this.trackName + " but it wasn't found." );
 			return;
 		}
 
-		if( this.objectName ) {
+		if ( this.objectName ) {
 			// special case were we need to reach deeper into the hierarchy to get the face materials....
-			if( this.objectName === "materials" ) {
-				if( ! targetObject.material ) {
+			if ( this.objectName === "materials" ) {
+				if ( ! targetObject.material ) {
 					console.error( '  can not bind to material as node does not have a material', this );
-					return;				
+					return;
 				}
-				if( ! targetObject.material.materials ) {
+				if ( ! targetObject.material.materials ) {
 					console.error( '  can not bind to material.materials as node.material does not have a materials array', this );
-					return;				
+					return;
 				}
 				targetObject = targetObject.material.materials;
-			}
-			else if( this.objectName === "bones" ) {
-				if( ! targetObject.skeleton ) {
+			} else if ( this.objectName === "bones" ) {
+				if ( ! targetObject.skeleton ) {
 					console.error( '  can not bind to bones as node does not have a skeleton', this );
 					return;
 				}
 				// potential future optimization: skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
-				
+
 				targetObject = targetObject.skeleton.bones;
 
 				// support resolving morphTarget names into indices.
-				for( var i = 0; i < targetObject.length; i ++ ) {
-					if( targetObject[i].name === this.objectIndex ) {
+				for ( var i = 0; i < targetObject.length; i ++ ) {
+					if ( targetObject[i].name === this.objectIndex ) {
 						this.objectIndex = i;
 						break;
 					}
 				}
-			}
-			else {
+			} else {
 
-				if( targetObject[ this.objectName ] === undefined ) {
-					console.error( '  can not bind to objectName of node, undefined', this );			
+				if ( targetObject[ this.objectName ] === undefined ) {
+					console.error( '  can not bind to objectName of node, undefined', this );
 					return;
 				}
 				targetObject = targetObject[ this.objectName ];
 			}
-			
-			if( this.objectIndex !== undefined ) {
-				if( targetObject[ this.objectIndex ] === undefined ) {
+
+			if ( this.objectIndex !== undefined ) {
+				if ( targetObject[ this.objectIndex ] === undefined ) {
 					console.error( "  trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
-					return;				
+					return;
 				}
 
 				targetObject = targetObject[ this.objectIndex ];
@@ -145,27 +142,27 @@ THREE.PropertyBinding.prototype = {
 
  		// special case mappings
  		var nodeProperty = targetObject[ this.propertyName ];
-		if( ! nodeProperty ) {
-			console.error( "  trying to update property for track: " + this.nodeName + '.' + this.propertyName + " but it wasn't found.", targetObject );				
+		if ( ! nodeProperty ) {
+			console.error( "  trying to update property for track: " + this.nodeName + '.' + this.propertyName + " but it wasn't found.", targetObject );
 			return;
 		}
 
 		// access a sub element of the property array (only primitives are supported right now)
-		if( this.propertyIndex !== undefined ) {
+		if ( this.propertyIndex !== undefined ) {
 
-			if( this.propertyName === "morphTargetInfluences" ) {
+			if ( this.propertyName === "morphTargetInfluences" ) {
 				// potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
-				
+
 				// support resolving morphTarget names into indices.
-				if( ! targetObject.geometry ) {
-					console.error( '  can not bind to morphTargetInfluences becasuse node does not have a geometry', this );				
+				if ( ! targetObject.geometry ) {
+					console.error( '  can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
 				}
-				if( ! targetObject.geometry.morphTargets ) {
-					console.error( '  can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );				
+				if ( ! targetObject.geometry.morphTargets ) {
+					console.error( '  can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
 				}
-				
-				for( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
-					if( targetObject.geometry.morphTargets[i].name === this.propertyIndex ) {
+
+				for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
+					if ( targetObject.geometry.morphTargets[i].name === this.propertyIndex ) {
 						this.propertyIndex = i;
 						break;
 					}
@@ -173,7 +170,7 @@ THREE.PropertyBinding.prototype = {
 			}
 
 			this.setValue = function setValue_propertyIndexed( value ) {
-				if( ! this.equalsValue( nodeProperty[ this.propertyIndex ], value ) ) {
+				if ( ! this.equalsValue( nodeProperty[ this.propertyIndex ], value ) ) {
 					nodeProperty[ this.propertyIndex ] = value;
 					return true;
 				}
@@ -185,11 +182,11 @@ THREE.PropertyBinding.prototype = {
 			};
 
 		}
-		// must use copy for Object3D.Euler/Quaternion		
-		else if( nodeProperty.copy ) {
-			
+		// must use copy for Object3D.Euler/Quaternion
+		else if ( nodeProperty.copy ) {
+
 			this.setValue = function setValue_propertyObject( value ) {
-				if( ! this.equalsValue( nodeProperty, value ) ) {
+				if ( ! this.equalsValue( nodeProperty, value ) ) {
 					nodeProperty.copy( value );
 					return true;
 				}
@@ -205,8 +202,8 @@ THREE.PropertyBinding.prototype = {
 		else {
 
 			this.setValue = function setValue_property( value ) {
-				if( ! this.equalsValue( targetObject[ this.propertyName ], value ) ) {
-					targetObject[ this.propertyName ] = value;	
+				if ( ! this.equalsValue( targetObject[ this.propertyName ], value ) ) {
+					targetObject[ this.propertyName ] = value;
 					return true;
 				}
 				return false;
@@ -218,16 +215,15 @@ THREE.PropertyBinding.prototype = {
 
 		}
 
-		// trigger node dirty			
-		if( targetObject.needsUpdate !== undefined ) { // material
-			
+		// trigger node dirty
+		if ( targetObject.needsUpdate !== undefined ) { // material
+
 			this.triggerDirty = function triggerDirty_needsUpdate() {
 				this.node.needsUpdate = true;
 			}
 
-		}			
-		else if( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
-			
+		} else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
+
 			this.triggerDirty = function triggerDirty_matrixWorldNeedsUpdate() {
 				targetObject.matrixWorldNeedsUpdate = true;
 			}
@@ -246,13 +242,13 @@ THREE.PropertyBinding.prototype = {
 	apply: function() {
 
 		// for speed capture the setter pattern as a closure (sort of a memoization pattern: https://en.wikipedia.org/wiki/Memoization)
-		if( ! this.isBound ) this.bind();
+		if ( ! this.isBound ) this.bind();
 
 		// early exit if there is nothing to apply.
-		if( this.cumulativeWeight > 0 ) {
-		
+		if ( this.cumulativeWeight > 0 ) {
+
 			// blend with original value
-			if( this.cumulativeWeight < 1 ) {
+			if ( this.cumulativeWeight < 1 ) {
 
 				var remainingWeight = 1 - this.cumulativeWeight;
 				var lerpAlpha = remainingWeight / ( this.cumulativeWeight + remainingWeight );
@@ -262,7 +258,7 @@ THREE.PropertyBinding.prototype = {
 
 			var valueChanged = this.setValue( this.cumulativeValue );
 
-			if( valueChanged && this.triggerDirty ) {
+			if ( valueChanged && this.triggerDirty ) {
 				this.triggerDirty();
 			}
 
@@ -289,10 +285,10 @@ THREE.PropertyBinding.parseTrackName = function( trackName ) {
 	//	  .bone[Armature.DEF_cog].position
 	// created and tested via https://regex101.com/#javascript
 
-	var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/; 
+	var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
 	var matches = re.exec(trackName);
 
-	if( ! matches ) {
+	if ( ! matches ) {
 		throw new Error( "cannot parse trackName at all: " + trackName );
 	}
 
@@ -309,7 +305,7 @@ THREE.PropertyBinding.parseTrackName = function( trackName ) {
 		propertyIndex: matches[11]	// allowed to be null, specifies that the whole property is set.
 	};
 
-	if( results.propertyName === null || results.propertyName.length === 0 ) {
+	if ( results.propertyName === null || results.propertyName.length === 0 ) {
 		throw new Error( "can not parse propertyName from trackName: " + trackName );
 	}
 
@@ -319,69 +315,71 @@ THREE.PropertyBinding.parseTrackName = function( trackName ) {
 
 THREE.PropertyBinding.findNode = function( root, nodeName ) {
 
-	if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
+	function searchSkeleton( skeleton ) {
 
-		return root;
+		for ( var i = 0; i < skeleton.bones.length; i ++ ) {
 
-	}
+			var bone = skeleton.bones[i];
 
-	// search into skeleton bones.
-	if( root.skeleton ) {
+			if ( bone.name === nodeName ) {
 
-		var searchSkeleton = function( skeleton ) {
+				return bone;
 
-			for( var i = 0; i < skeleton.bones.length; i ++ ) {
+			}
+		}
 
-				var bone = skeleton.bones[i];
+		return null;
 
-				if( bone.name === nodeName ) {
+	}
 
-					return bone;
+	function searchNodeSubtree( children ) {
 
-				}
-			}
+		for ( var i = 0; i < children.length; i ++ ) {
 
-			return null;
+			var childNode = children[i];
 
-		};
+			if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
 
-		var bone = searchSkeleton( root.skeleton );
+				return childNode;
 
-		if( bone ) {
+			}
 
-			return bone;
+			var result = searchNodeSubtree( childNode.children );
+
+			if ( result ) return result;
 
 		}
-	}
 
-	// search into node subtree.
-	if( root.children ) {
+		return null;
 
-		var searchNodeSubtree = function( children ) {
+	}
 
-			for( var i = 0; i < children.length; i ++ ) {
+	//
 
-				var childNode = children[i];
+	if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
 
-				if( childNode.name === nodeName || childNode.uuid === nodeName ) {
+		return root;
 
-					return childNode;
+	}
 
-				}
+	// search into skeleton bones.
+	if ( root.skeleton ) {
 
-				var result = searchNodeSubtree( childNode.children );
+		var bone = searchSkeleton( root.skeleton );
 
-				if( result ) return result;
+		if ( bone ) {
 
-			}
+			return bone;
 
-			return null;	
+		}
+	}
 
-		};
+	// search into node subtree.
+	if ( root.children ) {
 
 		var subTreeNode = searchNodeSubtree( root.children );
 
-		if( subTreeNode ) {
+		if ( subTreeNode ) {
 
 			return subTreeNode;
 

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

@@ -1,7 +1,7 @@
 /**
  *
  * A Track that interpolates Boolean
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -43,8 +43,8 @@ THREE.BooleanKeyframeTrack.prototype.clone = function() {
 
 	var clonedKeys = [];
 
-	for( var i = 0; i < this.keys.length; i ++ ) {
-		
+	for ( var i = 0; i < this.keys.length; i ++ ) {
+
 		var key = this.keys[i];
 		clonedKeys.push( {
 			time: key.time,
@@ -61,4 +61,3 @@ THREE.BooleanKeyframeTrack.parse = function( json ) {
 	return new THREE.BooleanKeyframeTrack( json.name, json.keys );
 
 };
- 

+ 4 - 5
src/animation/tracks/ColorKeyframeTrack.js

@@ -1,7 +1,7 @@
 /**
  *
  * A Track that interpolates Color
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -43,8 +43,8 @@ THREE.ColorKeyframeTrack.prototype.clone = function() {
 
 	var clonedKeys = [];
 
-	for( var i = 0; i < this.keys.length; i ++ ) {
-		
+	for ( var i = 0; i < this.keys.length; i ++ ) {
+
 		var key = this.keys[i];
 		clonedKeys.push( {
 			time: key.time,
@@ -60,7 +60,7 @@ THREE.ColorKeyframeTrack.parse = function( json ) {
 
 	var keys = [];
 
-	for( var i = 0; i < json.keys.length; i ++ ) {
+	for ( var i = 0; i < json.keys.length; i ++ ) {
 		var jsonKey = json.keys[i];
 		keys.push( {
 			value: new THREE.Color().fromArray( jsonKey.value ),
@@ -71,4 +71,3 @@ THREE.ColorKeyframeTrack.parse = function( json ) {
 	return new THREE.ColorKeyframeTrack( json.name, keys );
 
 };
- 

+ 3 - 4
src/animation/tracks/NumberKeyframeTrack.js

@@ -1,7 +1,7 @@
 /**
  *
  * A Track that interpolates Numbers
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -43,8 +43,8 @@ THREE.NumberKeyframeTrack.prototype.clone = function() {
 
 	var clonedKeys = [];
 
-	for( var i = 0; i < this.keys.length; i ++ ) {
-		
+	for ( var i = 0; i < this.keys.length; i ++ ) {
+
 		var key = this.keys[i];
 		clonedKeys.push( {
 			time: key.time,
@@ -61,4 +61,3 @@ THREE.NumberKeyframeTrack.parse = function( json ) {
 	return new THREE.NumberKeyframeTrack( json.name, json.keys );
 
 };
- 

+ 7 - 8
src/animation/tracks/QuaternionKeyframeTrack.js

@@ -1,7 +1,7 @@
 /**
  *
  * A Track that interpolates Quaternion
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -14,7 +14,7 @@ THREE.QuaternionKeyframeTrack = function ( name, keys ) {
 	this.result = this.keys[0].value.clone();
 
 };
- 
+
 THREE.QuaternionKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
 
 THREE.QuaternionKeyframeTrack.prototype.constructor = THREE.QuaternionKeyframeTrack;
@@ -41,10 +41,10 @@ THREE.QuaternionKeyframeTrack.prototype.compareValues = function( value0, value1
 
 THREE.QuaternionKeyframeTrack.prototype.multiply = function( quat ) {
 
-	for( var i = 0; i < this.keys.length; i ++ ) {
+	for ( var i = 0; i < this.keys.length; i ++ ) {
 
 		this.keys[i].value.multiply( quat );
-		
+
 	}
 
 	return this;
@@ -55,8 +55,8 @@ THREE.QuaternionKeyframeTrack.prototype.clone = function() {
 
 	var clonedKeys = [];
 
-	for( var i = 0; i < this.keys.length; i ++ ) {
-		
+	for ( var i = 0; i < this.keys.length; i ++ ) {
+
 		var key = this.keys[i];
 		clonedKeys.push( {
 			time: key.time,
@@ -72,7 +72,7 @@ THREE.QuaternionKeyframeTrack.parse = function( json ) {
 
 	var keys = [];
 
-	for( var i = 0; i < json.keys.length; i ++ ) {
+	for ( var i = 0; i < json.keys.length; i ++ ) {
 		var jsonKey = json.keys[i];
 		keys.push( {
 			value: new THREE.Quaternion().fromArray( jsonKey.value ),
@@ -83,4 +83,3 @@ THREE.QuaternionKeyframeTrack.parse = function( json ) {
 	return new THREE.QuaternionKeyframeTrack( json.name, keys );
 
 };
- 

+ 3 - 4
src/animation/tracks/StringKeyframeTrack.js

@@ -1,7 +1,7 @@
 /**
  *
  * A Track that interpolates Strings
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -43,8 +43,8 @@ THREE.StringKeyframeTrack.prototype.clone = function() {
 
 	var clonedKeys = [];
 
-	for( var i = 0; i < this.keys.length; i ++ ) {
-		
+	for ( var i = 0; i < this.keys.length; i ++ ) {
+
 		var key = this.keys[i];
 		clonedKeys.push( {
 			time: key.time,
@@ -61,4 +61,3 @@ THREE.StringKeyframeTrack.parse = function( json ) {
 	return new THREE.StringKeyframeTrack( json.name, json.keys );
 
 };
- 

+ 4 - 5
src/animation/tracks/VectorKeyframeTrack.js

@@ -1,7 +1,7 @@
 /**
  *
  * A Track that interpolates Vectors
- * 
+ *
  * @author Ben Houston / http://clara.io/
  * @author David Sarno / http://lighthaus.us/
  */
@@ -43,8 +43,8 @@ THREE.VectorKeyframeTrack.prototype.clone = function() {
 
 	var clonedKeys = [];
 
-	for( var i = 0; i < this.keys.length; i ++ ) {
-		
+	for ( var i = 0; i < this.keys.length; i ++ ) {
+
 		var key = this.keys[i];
 		clonedKeys.push( {
 			time: key.time,
@@ -63,7 +63,7 @@ THREE.VectorKeyframeTrack.parse = function( json ) {
 
 	var keys = [];
 
-	for( var i = 0; i < json.keys.length; i ++ ) {
+	for ( var i = 0; i < json.keys.length; i ++ ) {
 		var jsonKey = json.keys[i];
 		keys.push( {
 			value: new valueType().fromArray( jsonKey.value ),
@@ -74,4 +74,3 @@ THREE.VectorKeyframeTrack.parse = function( json ) {
 	return new THREE.VectorKeyframeTrack( json.name, keys );
 
 };
- 

+ 2 - 2
src/core/Raycaster.js

@@ -39,7 +39,7 @@
 
 	}
 
-	var intersectObject = function ( object, raycaster, intersects, recursive ) {
+	function intersectObject( object, raycaster, intersects, recursive ) {
 
 		if ( object.visible === false ) return;
 
@@ -57,7 +57,7 @@
 
 		}
 
-	};
+	}
 
 	//
 

+ 6 - 7
src/extras/FontUtils.js

@@ -289,7 +289,7 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
 
 	// takes in an contour array and returns
 
-	var process = function ( contour, indices ) {
+	function process( contour, indices ) {
 
 		var n = contour.length;
 
@@ -383,11 +383,11 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
 		if ( indices ) return vertIndices;
 		return result;
 
-	};
+	}
 
 	// calculate area of the contour polygon
 
-	var area = function ( contour ) {
+	function area( contour ) {
 
 		var n = contour.length;
 		var a = 0.0;
@@ -400,9 +400,9 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
 
 		return a * 0.5;
 
-	};
+	}
 
-	var snip = function ( contour, u, v, w, n, verts ) {
+	function snip( contour, u, v, w, n, verts ) {
 
 		var p;
 		var ax, ay, bx, by;
@@ -452,8 +452,7 @@ THREE.FontUtils.generateShapes = function ( text, parameters ) {
 
 		return true;
 
-	};
-
+	}
 
 	namespace.Triangulate = process;
 	namespace.Triangulate.area = area;

+ 8 - 8
src/extras/ImageUtils.js

@@ -45,7 +45,7 @@ THREE.ImageUtils = {
 
 		var loaded = 0;
 
-		var loadTexture = function ( i ) {
+		function loadTexture( i ) {
 
 			loader.load( array[ i ], function ( image ) {
 
@@ -63,7 +63,7 @@ THREE.ImageUtils = {
 
 			}, undefined, onError );
 
-		};
+		}
 
 		for ( var i = 0, il = array.length; i < il; ++ i ) {
 
@@ -91,24 +91,24 @@ THREE.ImageUtils = {
 
 		// Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
 
-		var cross = function ( a, b ) {
+		function cross( a, b ) {
 
 			return [ a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ], a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ], a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ] ];
 
-		};
+		}
 
-		var subtract = function ( a, b ) {
+		function subtract( a, b ) {
 
 			return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
 
-		};
+		}
 
-		var normalize = function ( a ) {
+		function normalize( a ) {
 
 			var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
 			return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
 
-		};
+		}
 
 		depth = depth | 1;
 

+ 1 - 1
src/extras/core/Path.js

@@ -197,7 +197,7 @@ THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
 
 		points.push( this.getPoint( i / divisions ) );
 
-		//if( !this.getPoint( i / divisions ) ) throw "DIE";
+		//if ( !this.getPoint( i / divisions ) ) throw "DIE";
 
 	}
 

+ 3 - 2
src/extras/geometries/EdgesGeometry.js

@@ -11,11 +11,12 @@ THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
 	var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
 
 	var edge = [ 0, 0 ], hash = {};
-	var sortFunction = function ( a, b ) {
+
+	function sortFunction( a, b ) {
 
 		return a - b;
 
-	};
+	}
 
 	var keys = [ 'a', 'b', 'c' ];
 

+ 3 - 2
src/extras/geometries/WireframeGeometry.js

@@ -7,11 +7,12 @@ THREE.WireframeGeometry = function ( geometry ) {
 	THREE.BufferGeometry.call( this );
 
 	var edge = [ 0, 0 ], hash = {};
-	var sortFunction = function ( a, b ) {
+
+	function sortFunction( a, b ) {
 
 		return a - b;
 
-	};
+	}
 
 	var keys = [ 'a', 'b', 'c' ];
 

+ 2 - 2
src/extras/helpers/CameraHelper.js

@@ -113,7 +113,7 @@ THREE.CameraHelper.prototype.update = function () {
 	var vector = new THREE.Vector3();
 	var camera = new THREE.Camera();
 
-	var setPoint = function ( point, x, y, z ) {
+	function setPoint( point, x, y, z ) {
 
 		vector.set( x, y, z ).unproject( camera );
 
@@ -129,7 +129,7 @@ THREE.CameraHelper.prototype.update = function () {
 
 		}
 
-	};
+	}
 
 	return function () {
 

+ 2 - 2
src/loaders/AnimationLoader.js

@@ -36,7 +36,7 @@ THREE.AnimationLoader.prototype = {
 
 		var animations = [];
 
-		for( var i = 0; i < json.length; i ++ ) {
+		for ( var i = 0; i < json.length; i ++ ) {
 
 			var clip = THREE.AnimationClip.parse( json[i] );
 
@@ -48,4 +48,4 @@ THREE.AnimationLoader.prototype = {
 
 	}
 
-};
+};

+ 8 - 9
src/loaders/JSONLoader.js

@@ -509,27 +509,26 @@ THREE.JSONLoader.prototype = {
 
 			// parse old style Bone/Hierarchy animations
 			var animations = [];
-			if( json.animation !== undefined ) {
+			if ( json.animation !== undefined ) {
 				animations.push( json.animation );
 			}
-			if( json.animations !== undefined ) {
-				if( json.animations.length ) {
+			if ( json.animations !== undefined ) {
+				if ( json.animations.length ) {
 					animations = animations.concat( json.animations );
-				}
-				else {
+				} else {
 					animations.push( json.animations );
 				}
 			}
 
-			for( var i = 0; i < animations.length; i ++ ) {
+			for ( var i = 0; i < animations.length; i ++ ) {
 
 				var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
-				if( clip ) outputAnimations.push( clip );
+				if ( clip ) outputAnimations.push( clip );
 
 			}
 
 			// parse implicit morph animations
-			if( geometry.morphTargets ) {
+			if ( geometry.morphTargets ) {
 
 				// TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
 				var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
@@ -537,7 +536,7 @@ THREE.JSONLoader.prototype = {
 
 			}
 
-			if( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
+			if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
 
 		};
 

+ 2 - 2
src/loaders/ObjectLoader.js

@@ -60,7 +60,7 @@ THREE.ObjectLoader.prototype = {
 
 		var object = this.parseObject( json.object, geometries, materials );
 
-		if( json.animations ) {
+		if ( json.animations ) {
 
 			object.animations = this.parseAnimations( json.animations );
 
@@ -327,7 +327,7 @@ THREE.ObjectLoader.prototype = {
 
 		var animations = [];
 
-		for( var i = 0; i < json.length; i ++ ) {
+		for ( var i = 0; i < json.length; i ++ ) {
 
 			var clip = THREE.AnimationClip.parse( json[i] );
 

+ 3 - 3
src/math/Color.js

@@ -6,7 +6,7 @@ THREE.Color = function ( color ) {
 
 	if ( arguments.length === 3 ) {
 
-		return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
+		return this.fromArray( arguments );
 
 	}
 
@@ -64,7 +64,7 @@ THREE.Color.prototype = {
 
 	setHSL: function () {
 
-		function hue2rgb ( p, q, t ) {
+		function hue2rgb( p, q, t ) {
 
 			if ( t < 0 ) t += 1;
 			if ( t > 1 ) t -= 1;
@@ -105,7 +105,7 @@ THREE.Color.prototype = {
 
 	setStyle: function ( style ) {
 
-		var parseAlpha = function ( strAlpha ) {
+		function parseAlpha( strAlpha ) {
 
 			var alpha = parseFloat( strAlpha );
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/hemilight_fragment.glsl

@@ -1,6 +1,6 @@
 #if MAX_HEMI_LIGHTS > 0
 
-	for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
+	for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
 
 		vec3 lightDir = hemisphereLightDirection[ i ];
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl

@@ -76,7 +76,7 @@ vec3 totalSpecularLight = vec3( 0.0 );
 
 #if MAX_DIR_LIGHTS > 0
 
-	for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
+	for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
 
 		vec3 lightColor = directionalLightColor[ i ];
 

+ 3 - 3
src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl

@@ -2,7 +2,7 @@
 
 	vec3 shadowMask = vec3( 1.0 );
 
-	for( int i = 0; i < MAX_SHADOWS; i ++ ) {
+	for ( int i = 0; i < MAX_SHADOWS; i ++ ) {
 		
 		float texelSizeY =  1.0 / shadowMapSize[ i ].y;
 
@@ -14,7 +14,7 @@
 		// whether or not this light is a point light ( shadowDarkness[ i ] < 0 == point light)
 		bool isPointLight = shadowDarkness[ i ] < 0.0;	
 
-		if( isPointLight ) {
+		if ( isPointLight ) {
 
 			// get the real shadow darkness
 			float realShadowDarkness = abs( shadowDarkness[ i ] );
@@ -99,7 +99,7 @@
 
 			bool frustumTest = all( frustumTestVec );
 
-			if( frustumTest ) {
+			if ( frustumTest ) {
 
 	#if defined( SHADOWMAP_TYPE_PCF )
 		

+ 1 - 1
src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl

@@ -25,7 +25,7 @@
 		void adjustShadowValue1K( const float testDepth, const vec4 textureData, const float bias, inout float shadowValue ) {
 
 			const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );
-			if( testDepth >= dot( textureData, bitSh ) * 1000.0 + bias )
+			if ( testDepth >= dot( textureData, bitSh ) * 1000.0 + bias )
 				shadowValue += 1.0;
 
 		}

+ 1 - 1
src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl

@@ -1,6 +1,6 @@
 #ifdef USE_SHADOWMAP
 
-	for( int i = 0; i < MAX_SHADOWS; i ++ ) {
+	for ( int i = 0; i < MAX_SHADOWS; i ++ ) {
 
 			vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;
 

+ 2 - 2
src/renderers/webgl/WebGLShader.js

@@ -1,6 +1,6 @@
 THREE.WebGLShader = ( function () {
 
-	var addLineNumbers = function ( string ) {
+	function addLineNumbers( string ) {
 
 		var lines = string.split( '\n' );
 
@@ -12,7 +12,7 @@ THREE.WebGLShader = ( function () {
 
 		return lines.join( '\n' );
 
-	};
+	}
 
 	return function WebGLShader( gl, type, string ) {
 

+ 8 - 8
src/renderers/webgl/plugins/LensFlarePlugin.js

@@ -14,7 +14,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
 
 	var tempTexture, occlusionTexture;
 
-	var init = function () {
+	function init() {
 
 		var vertices = new Float32Array( [
 			- 1, - 1,  0, 0,
@@ -88,7 +88,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
 
 						"vec2 pos = position;",
 
-						"if( renderType == 2 ) {",
+						"if ( renderType == 2 ) {",
 
 							"vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
 							"visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
@@ -131,13 +131,13 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
 
 						// pink square
 
-						"if( renderType == 0 ) {",
+						"if ( renderType == 0 ) {",
 
 							"gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
 
 						// restore
 
-						"} else if( renderType == 1 ) {",
+						"} else if ( renderType == 1 ) {",
 
 							"gl_FragColor = texture2D( map, vUV );",
 
@@ -181,7 +181,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
 
 						"vec2 pos = position;",
 
-						"if( renderType == 2 ) {",
+						"if ( renderType == 2 ) {",
 
 							"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
 							"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
@@ -211,13 +211,13 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
 
 						// pink square
 
-						"if( renderType == 0 ) {",
+						"if ( renderType == 0 ) {",
 
 							"gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
 
 						// restore
 
-						"} else if( renderType == 1 ) {",
+						"} else if ( renderType == 1 ) {",
 
 							"gl_FragColor = texture2D( map, vUV );",
 
@@ -264,7 +264,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
 			screenPosition: gl.getUniformLocation( program, "screenPosition" )
 		};
 
-	};
+	}
 
 	/*
 	 * Render lens flares

+ 2 - 2
src/renderers/webgl/plugins/SpritePlugin.js

@@ -19,7 +19,7 @@ THREE.SpritePlugin = function ( renderer, sprites ) {
 	var spriteRotation = new THREE.Quaternion();
 	var spriteScale = new THREE.Vector3();
 
-	var init = function () {
+	function init() {
 
 		var vertices = new Float32Array( [
 			- 0.5, - 0.5,  0, 0,
@@ -83,7 +83,7 @@ THREE.SpritePlugin = function ( renderer, sprites ) {
 		texture = new THREE.Texture( canvas );
 		texture.needsUpdate = true;
 
-	};
+	}
 
 	this.render = function ( scene, camera ) {
 

+ 2 - 2
src/textures/VideoTexture.js

@@ -10,7 +10,7 @@ THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilt
 
 	var scope = this;
 
-	var update = function () {
+	function update() {
 
 		requestAnimationFrame( update );
 
@@ -20,7 +20,7 @@ THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilt
 
 		}
 
-	};
+	}
 
 	update();