Просмотр исходного кода

Merge branch 'dev' of [email protected]:mrdoob/three.js.git into modernAnimationSystem

Ben Houston 10 лет назад
Родитель
Сommit
907c6980ef
100 измененных файлов с 5873 добавлено и 4033 удалено
  1. 339 214
      build/three.js
  2. 165 163
      build/three.min.js
  3. 42 20
      docs/api/math/Quaternion.html
  4. 5 1
      docs/api/renderers/WebGLRenderer.html
  5. 6 4
      docs/manual/introduction/Creating-a-scene.html
  6. 1 0
      editor/css/dark.css
  7. 1 0
      editor/css/light.css
  8. 9 15
      editor/js/Viewport.js
  9. 4 0
      examples/index.html
  10. 2 2
      examples/js/AudioObject.js
  11. 11 22
      examples/js/BlendCharacter.js
  12. 33 27
      examples/js/BlendCharacterGui.js
  13. 52 16
      examples/js/Car.js
  14. 137 92
      examples/js/Cloth.js
  15. 96 92
      examples/js/CurveExtras.js
  16. 13 1
      examples/js/Detector.js
  17. 1 1
      examples/js/MD2Character.js
  18. 10 6
      examples/js/MD2CharacterComplex.js
  19. 267 263
      examples/js/MarchingCubes.js
  20. 27 26
      examples/js/Mirror.js
  21. 143 104
      examples/js/Ocean.js
  22. 69 46
      examples/js/Octree.js
  23. 15 3
      examples/js/PRNG.js
  24. 72 57
      examples/js/ParametricGeometries.js
  25. 29 29
      examples/js/ShaderDeferred.js
  26. 6 6
      examples/js/ShaderGodRays.js
  27. 34 34
      examples/js/ShaderSkin.js
  28. 22 22
      examples/js/ShaderTerrain.js
  29. 177 177
      examples/js/ShaderToon.js
  30. 28 14
      examples/js/SimulationRenderer.js
  31. 8 8
      examples/js/SkyShader.js
  32. 355 209
      examples/js/Sparks.js
  33. 18 10
      examples/js/TypedArrayUtils.js
  34. 17 1
      examples/js/UCSCharacter.js
  35. 36 26
      examples/js/WaterShader.js
  36. 7 6
      examples/js/cameras/CombinedCamera.js
  37. 8 7
      examples/js/controls/DragControls.js
  38. 18 8
      examples/js/controls/EditorControls.js
  39. 8 4
      examples/js/controls/FirstPersonControls.js
  40. 14 10
      examples/js/controls/FlyControls.js
  41. 7 7
      examples/js/controls/MouseControls.js
  42. 646 417
      examples/js/controls/OrbitControls.js
  43. 33 23
      examples/js/controls/OrthographicTrackballControls.js
  44. 1 1
      examples/js/controls/PointerLockControls.js
  45. 39 29
      examples/js/controls/TrackballControls.js
  46. 87 79
      examples/js/controls/TransformControls.js
  47. 2 2
      examples/js/controls/VRControls.js
  48. 14 14
      examples/js/crossfade/gui.js
  49. 10 8
      examples/js/crossfade/scenes.js
  50. 28 26
      examples/js/crossfade/transition.js
  51. 20 12
      examples/js/curves/NURBSCurve.js
  52. 15 9
      examples/js/curves/NURBSSurface.js
  53. 190 112
      examples/js/curves/NURBSUtils.js
  54. 13 11
      examples/js/effects/AnaglyphEffect.js
  55. 68 51
      examples/js/effects/AsciiEffect.js
  56. 10 10
      examples/js/effects/ParallaxBarrierEffect.js
  57. 11 3
      examples/js/effects/StereoEffect.js
  58. 23 22
      examples/js/effects/VREffect.js
  59. 16 14
      examples/js/exporters/STLBinaryExporter.js
  60. 6 2
      examples/js/geometries/ConvexGeometry.js
  61. 32 6
      examples/js/geometries/DecalGeometry.js
  62. 7 3
      examples/js/geometries/hilbert2D.js
  63. 6 2
      examples/js/geometries/hilbert3D.js
  64. 294 172
      examples/js/loaders/AWDLoader.js
  65. 171 85
      examples/js/loaders/AssimpJSONLoader.js
  66. 115 115
      examples/js/loaders/BinaryLoader.js
  67. 183 150
      examples/js/loaders/ColladaLoader.js
  68. 40 23
      examples/js/loaders/DDSLoader.js
  69. 7 6
      examples/js/loaders/MTLLoader.js
  70. 4 0
      examples/js/loaders/OBJLoader.js
  71. 18 16
      examples/js/loaders/OBJMTLLoader.js
  72. 2 2
      examples/js/loaders/PDBLoader.js
  73. 61 47
      examples/js/loaders/PLYLoader.js
  74. 54 39
      examples/js/loaders/PVRLoader.js
  75. 111 65
      examples/js/loaders/RGBELoader.js
  76. 147 88
      examples/js/loaders/STLLoader.js
  77. 129 77
      examples/js/loaders/TGALoader.js
  78. 155 85
      examples/js/loaders/VRMLLoader.js
  79. 7 7
      examples/js/loaders/deprecated/SceneLoader.js
  80. 53 4
      examples/js/loaders/sea3d/SEA3D.js
  81. 201 125
      examples/js/loaders/sea3d/SEA3DLoader.js
  82. 3 2
      examples/js/math/ColorConverter.js
  83. 60 28
      examples/js/math/Lut.js
  84. 19 12
      examples/js/modifiers/SubdivisionModifier.js
  85. 5 5
      examples/js/objects/ShadowMesh.js
  86. 62 11
      examples/js/postprocessing/AdaptiveToneMappingPass.js
  87. 1 1
      examples/js/postprocessing/BloomPass.js
  88. 5 3
      examples/js/postprocessing/BokehPass.js
  89. 3 3
      examples/js/postprocessing/DotScreenPass.js
  90. 1 1
      examples/js/postprocessing/EffectComposer.js
  91. 1 1
      examples/js/postprocessing/FilmPass.js
  92. 49 43
      examples/js/postprocessing/GlitchPass.js
  93. 1 1
      examples/js/postprocessing/SavePass.js
  94. 2 2
      examples/js/postprocessing/ShaderPass.js
  95. 1 1
      examples/js/postprocessing/TexturePass.js
  96. 74 68
      examples/js/renderers/CanvasRenderer.js
  97. 4 2
      examples/js/renderers/Projector.js
  98. 1 1
      examples/js/renderers/RaytracingRenderer.js
  99. 6 6
      examples/js/renderers/SVGRenderer.js
  100. 234 127
      examples/js/renderers/SoftwareRenderer.js

Разница между файлами не показана из-за своего большого размера
+ 339 - 214
build/three.js


Разница между файлами не показана из-за своего большого размера
+ 165 - 163
build/three.min.js


+ 42 - 20
docs/api/math/Quaternion.html

@@ -120,26 +120,6 @@
 		Clones this quaternion.
 		</div>
 
-
-		<h2>Static methods</h2>
-
-		<h3>[method:Quaternion slerp]( [page:Quaternion qa], [page:Quaternion qb], [page:Quaternion qm], [page:Float t] )</h3>
-		<div>
-		Adapted from [link:http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/].
-		</div>
-
-
-		<h3>[method:Quaternion slerp]([page:Quaternion qb], [page:float t])</h3>
-		<div>
-		qb -- Target quaternion rotation.<br />
-		t -- Normalized [0..1] interpolation factor.
-		</div>
-		<div>
-		Handles the spherical linear interpolation between this quaternion's configuration
-		and that of *qb*. *t* represents how close to the current (0) or target (1) rotation the
-		result should be.
-		</div>
-
 		<h3>[method:Array toArray]( [page:Array array] )</h3>
 		<div>
 		array -- Array to store the quaternion.
@@ -176,6 +156,48 @@
 		represents the same rotation in the opposite direction about the rotational axis.
 		</div>
 
+		<h3>[method:Quaternion slerp]([page:Quaternion quaternionB], [page:float t])</h3>
+		<div>
+		quaternionB -- The other quaternion rotation<br />
+		t -- Normalized 0 to 1 interpolation factor
+		</div>
+		<div>
+		Handles the spherical linear interpolation between quaternions. *t* represents the amount of rotation
+		between this quaternion (where *t* is 0) and quaternionB (where *t* is 1). This quaternion is set to
+		the result. Also see the static version of the *slerp* below.
+		</div>
+		<code>
+		// rotate a mesh towards a target quaternion
+		mesh.quaternion.slerp( endQuaternion, 0.01 );
+		</code>
+		
+		
+		<h2>Static Methods</h2>
+
+		<h3>[method:Quaternion slerp]( [page:Quaternion qStart], [page:Quaternion qEnd], [page:Quaternion qTarget], [page:Float t] )</h3>
+		<div>
+		qStart -- The starting quaternion (where *t* is 0)<br />
+		qEnd -- The ending quaternion (where *t* is 1)<br />
+		qTarget -- The target quaternion that gets set with the result<br />
+		t -- Normalized 0 to 1 interpolation factor
+		</div>
+		<div>
+		Unlike the normal method, the static version of slerp sets a target quaternion to the result of the slerp operation.
+		</div>
+		<code>
+		// Code setup
+		var startQuaternion = new THREE.Quaternion().set( 0, 0, 0, 1 ).normalize();
+		var endQuaternion = new THREE.Quaternion().set( 1, 1, 1, 1 ).normalize();
+		var t = 0;
+		</code>
+		<code>
+		// Update a mesh's rotation in the loop
+		t = ( t + 0.01 ) % 1; // constant angular momentum
+		THREE.Quaternion.slerp( startQuaternion, endQuaternion, mesh.quaternion, t );
+		</code>
+		
+		<!-- Note: Do not add non-static methods to the bottom of this page. Put them above the <h2>Static Methods</h2> -->
+
 		<h2>Source</h2>
 
 		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

+ 5 - 1
docs/api/renderers/WebGLRenderer.html

@@ -161,12 +161,16 @@
 		Return the WebGL context.
 		</div>
 
+		<h3>[method:WebGLContextAttributes getContextAttributes]()</h3>
+		<div>
+		Returns an object that describes the attributes set on the WebGL context when it was created.
+		</div>
+
 		<h3>[method:Boolean supportsVertexTextures]()</h3>
 		<div>
 		Return a [page:Boolean] true if the context supports vertex textures.
 		</div>
 
-
 		<h3>[method:null setSize]( [page:Integer width], [page:Integer height] )</h3>
 		<div>Resizes the output canvas to (width, height), and also sets the viewport to fit that size, starting in (0, 0).</div>
 

+ 6 - 4
docs/manual/introduction/Creating-a-scene.html

@@ -60,12 +60,14 @@
 
 		<div>The second one is the <strong>aspect ratio</strong>. You almost always want to use the width of the element divided by the height, or you'll get the same result as when you play old movies on a widescreen TV - the image looks squished.</div>
 
-		<div>The next two attributes are the <strong>near</strong> and <strong>far</strong> clipping plane. What that means, is that objects further away from the camera than the value of <strong>far</strong> or closer than <strong>near</strong> won't be rendered. You don't have to worry about this now, but you may want to use other values in your games to get better performance.</div>
+		<div>The next two attributes are the <strong>near</strong> and <strong>far</strong> clipping plane. What that means, is that objects further away from the camera than the value of <strong>far</strong> or closer than <strong>near</strong> won't be rendered. You don't have to worry about this now, but you may want to use other values in your apps to get better performance.</div>
 
 		<div>Next up is the renderer. This is where the magic happens. In addition to the WebGLRenderer we use here, Three.js comes with a few others, often used as fallbacks for users with older browsers or for those who don't have WebGL support for some reason.</div>
 
-		<div>In addition to creating the renderer instance, we also need to set the size at which we want it to render our app. It's a good idea to use the width and height of the area we want to fill with our game - in this case, the width and height of the browser window. For performance intensive games, you can also give <strong>setSize</strong> smaller values, like <strong>window.innerWidth/2</strong> and <strong>window.innerHeight/2</strong>, for half the resolution. This does not mean that the game will only fill half the window, but rather look a bit blurry and scaled up.</div>
-
+		<div>In addition to creating the renderer instance, we also need to set the size at which we want it to render our app. It's a good idea to use the width and height of the area we want to fill with our app - in this case, the width and height of the browser window. For performance intensive apps, you can also give <strong>setSize</strong> smaller values, like <strong>window.innerWidth/2</strong> and <strong>window.innerHeight/2</strong>, which will make the app render at half size.</div>
+		
+		<div>If you wish to keep the size of your app but render it at a lower resolution, you can do so by calling <strong>setSize</strong> with false as <strong>updateStyle</strong>. For example, <strong>setSize(window.innerWidth/2, window.innerHeight/2, false)</strong> will render your app at half resolution, given that your &lt;canvas&gt; has 100% width and height.</div>
+		
 		<div>Last but not least, we add the <strong>renderer</strong> element to our HTML document. This is a &lt;canvas&gt; element the renderer uses to display the scene to us.</div>
 
 		<div><em>"That's all good, but where's that cube you promised?"</em> Let's add it now.</div>
@@ -112,7 +114,7 @@
 		cube.rotation.y += 0.1;
 		</code>
 
-		<div>This will be run every frame (60 times per second), and give the cube a nice rotation animation. Basically, anything you want to move or change while the game / app is running has to go through the render loop. You can of course call other functions from there, so that you don't end up with a <strong>render</strong> function that's hundreds of lines.
+		<div>This will be run every frame (60 times per second), and give the cube a nice rotation animation. Basically, anything you want to move or change while the app is running has to go through the render loop. You can of course call other functions from there, so that you don't end up with a <strong>render</strong> function that's hundreds of lines.
 		</div>
 
 		<h2>The result</h2>

+ 1 - 0
editor/css/dark.css

@@ -46,6 +46,7 @@ input.Number {
 
 	#viewport #info {
 		text-shadow: 1px 1px 0px rgba(0,0,0,0.25);
+		pointer-events: none;
 	}
 
 #script {

+ 1 - 0
editor/css/light.css

@@ -39,6 +39,7 @@ input.Number {
 
 	#viewport #info {
 		text-shadow: 1px 1px 0px rgba(0,0,0,0.25);
+		pointer-events: none;
 	}
 
 #script {

+ 9 - 15
editor/js/Viewport.js

@@ -85,19 +85,13 @@ var Viewport = function ( editor ) {
 
 	// events
 
-	var getIntersects = function ( point, object ) {
+	function getIntersects( point, objects ) {
 
 		mouse.set( ( point.x * 2 ) - 1, - ( point.y * 2 ) + 1 );
 
 		raycaster.setFromCamera( mouse, camera );
 
-		if ( Array.isArray( object ) ) {
-
-			return raycaster.intersectObjects( object );
-
-		}
-
-		return raycaster.intersectObject( object );
+		return raycaster.intersectObjects( objects );
 
 	};
 
@@ -105,14 +99,14 @@ var Viewport = function ( editor ) {
 	var onUpPosition = new THREE.Vector2();
 	var onDoubleClickPosition = new THREE.Vector2();
 
-	var getMousePosition = function ( dom, x, y ) {
+	function getMousePosition( dom, x, y ) {
 
 		var rect = dom.getBoundingClientRect();
 		return [ ( x - rect.left ) / rect.width, ( y - rect.top ) / rect.height ];
 
 	};
 
-	var handleClick = function () {
+	function handleClick() {
 
 		if ( onDownPosition.distanceTo( onUpPosition ) == 0 ) {
 
@@ -146,7 +140,7 @@ var Viewport = function ( editor ) {
 
 	};
 
-	var onMouseDown = function ( event ) {
+	function onMouseDown( event ) {
 
 		event.preventDefault();
 
@@ -157,7 +151,7 @@ var Viewport = function ( editor ) {
 
 	};
 
-	var onMouseUp = function ( event ) {
+	function onMouseUp( event ) {
 
 		var array = getMousePosition( container.dom, event.clientX, event.clientY );
 		onUpPosition.fromArray( array );
@@ -168,7 +162,7 @@ var Viewport = function ( editor ) {
 
 	};
 
-	var onTouchStart = function ( event ) {
+	function onTouchStart( event ) {
 
 		var touch = event.changedTouches[ 0 ];
 
@@ -179,7 +173,7 @@ var Viewport = function ( editor ) {
 
 	};
 
-	var onTouchEnd = function ( event ) {
+	function onTouchEnd( event ) {
 
 		var touch = event.changedTouches[ 0 ];
 
@@ -192,7 +186,7 @@ var Viewport = function ( editor ) {
 
 	};
 
-	var onDoubleClick = function ( event ) {
+	function onDoubleClick( event ) {
 
 		var array = getMousePosition( container.dom, event.clientX, event.clientY );
 		onDoubleClickPosition.fromArray( array );

+ 4 - 0
examples/index.html

@@ -264,6 +264,10 @@
 				"webgl_loader_pdb",
 				"webgl_loader_ply",
 				"webgl_loader_sea3d",
+				"webgl_loader_sea3d_hierarchy",
+				"webgl_loader_sea3d_keyframe",
+				"webgl_loader_sea3d_skinning",
+				"webgl_loader_sea3d_sound",
 				"webgl_loader_scene",
 				"webgl_loader_stl",
 				"webgl_loader_utf8",

+ 2 - 2
examples/js/AudioObject.js

@@ -118,7 +118,7 @@ THREE.AudioObject = function ( url, volume, playbackRate, loop ) {
 
 		cameraUp.copy( camera.up );
 
-		cameraFront.set( 0, 0, -1 );
+		cameraFront.set( 0, 0, - 1 );
 		cameraFront.transformDirection( camera.matrixWorld );
 
 		this.listener.setPosition( cameraPosition.x, cameraPosition.y, cameraPosition.z );
@@ -130,7 +130,7 @@ THREE.AudioObject = function ( url, volume, playbackRate, loop ) {
 
 		if ( this.directionalSource ) {
 
-			soundFront.set( 0, 0, -1 );
+			soundFront.set( 0, 0, - 1 );
 			soundFront.transformDirection( this.matrixWorld );
 
 			soundUp.copy( this.up );

+ 11 - 22
examples/js/BlendCharacter.js

@@ -29,14 +29,6 @@ THREE.BlendCharacter = function () {
 
 			}
 
-			// Create the debug visualization
-
-			scope.skeletonHelper = new THREE.SkeletonHelper( scope );
-			scope.skeletonHelper.material.linewidth = 3;
-			scope.add( scope.skeletonHelper );
-
-			scope.showSkeleton( false );
-
 			// Loading is complete, fire the callback
 			if ( onLoad !== undefined ) onLoad();
 
@@ -70,14 +62,13 @@ THREE.BlendCharacter = function () {
 
 				// interpolate the weight for the current time
 
-				data.anim.weight = data.startWeight + (data.endWeight - data.startWeight) * data.timeElapsed / data.duration;
+				data.anim.weight = data.startWeight + ( data.endWeight - data.startWeight ) * data.timeElapsed / data.duration;
 
 			}
 
 		}
 
 		this.updateWarps( dt );
-		this.skeletonHelper.update();
 
 	};
 
@@ -126,7 +117,7 @@ THREE.BlendCharacter = function () {
 
 	};
 
-	this.play = function(animName, weight) {
+	this.play = function( animName, weight ) {
 
 		this.animations[ animName ].play( 0, weight );
 
@@ -181,7 +172,7 @@ THREE.BlendCharacter = function () {
 
 	};
 
-	this.applyWeight = function(animName, weight) {
+	this.applyWeight = function( animName, weight ) {
 
 		this.animations[ animName ].weight = weight;
 
@@ -221,7 +212,9 @@ THREE.BlendCharacter = function () {
 		for ( a in this.animations ) {
 
 			if ( this.animations[ a ].isPlaying ) {
-				this.animations[ a ].stop(0);
+
+				this.animations[ a ].stop( 0 );
+
 			}
 
 			this.animations[ a ].weight = 0;
@@ -233,12 +226,6 @@ THREE.BlendCharacter = function () {
 
 	};
 
-	this.showSkeleton = function( boolean ) {
-
-		this.skeletonHelper.visible = boolean;
-
-	};
-
 	this.showModel = function( boolean ) {
 
 		this.visible = boolean;
@@ -259,12 +246,14 @@ THREE.BlendCharacter.prototype.getForward = function() {
 
 		// pull the character's forward basis vector out of the matrix
 		forward.set(
-			-this.matrix.elements[ 8 ],
-			-this.matrix.elements[ 9 ],
-			-this.matrix.elements[ 10 ]
+			- this.matrix.elements[ 8 ],
+			- this.matrix.elements[ 9 ],
+			- this.matrix.elements[ 10 ]
 		);
 
 		return forward;
+
 	}
+
 };
 

+ 33 - 27
examples/js/BlendCharacterGui.js

@@ -2,7 +2,7 @@
  * @author Michael Guerrero / http://realitymeltdown.com
  */
 
-function BlendCharacterGui(animations) {
+function BlendCharacterGui( animations ) {
 
 	var controls = {
 
@@ -22,27 +22,27 @@ function BlendCharacterGui(animations) {
 
 	this.showModel = function() {
 
-		return controls['Show Model'];
+		return controls[ 'Show Model' ];
 
 	};
 
 	this.showSkeleton = function() {
 
-		return controls['Show Skeleton'];
+		return controls[ 'Show Skeleton' ];
 
 	};
 
 	this.getTimeScale = function() {
 
-		return controls['Time Scale'];
+		return controls[ 'Time Scale' ];
 
 	};
 
 	this.update = function() {
 
-		controls[ 'idle'] = animations[ 'idle' ].weight;
-		controls[ 'walk'] = animations[ 'walk' ].weight;
-		controls[ 'run'] = animations[ 'run' ].weight;
+		controls[ 'idle' ] = animations[ 'idle' ].weight;
+		controls[ 'walk' ] = animations[ 'walk' ].weight;
+		controls[ 'run' ] = animations[ 'run' ].weight;
 
 	};
 
@@ -68,9 +68,9 @@ function BlendCharacterGui(animations) {
 		playback.add( controls, "walk to run" );
 		playback.add( controls, "warp walk to run" );
 
-		blending.add( controls, "idle", 0, 1, 0.01).listen().onChange( controls.weight );
-		blending.add( controls, "walk", 0, 1, 0.01).listen().onChange( controls.weight );
-		blending.add( controls, "run", 0, 1, 0.01).listen().onChange( controls.weight );
+		blending.add( controls, "idle", 0, 1, 0.01 ).listen().onChange( controls.weight );
+		blending.add( controls, "walk", 0, 1, 0.01 ).listen().onChange( controls.weight );
+		blending.add( controls, "run", 0, 1, 0.01 ).listen().onChange( controls.weight );
 
 		settings.open();
 		playback.open();
@@ -86,18 +86,19 @@ function BlendCharacterGui(animations) {
 
 				anims: [ "idle", "walk", "run" ],
 
-				weights: [ controls['idle'],
-						   controls['walk'],
-						   controls['run'] ]
+				weights: [ controls[ 'idle' ],
+						   controls[ 'walk' ],
+						   controls[ 'run' ] ]
 			}
 
 		};
+
 	};
 
 	controls.start = function() {
 
 		var startEvent = new CustomEvent( 'start-animation', getAnimationData() );
-		window.dispatchEvent(startEvent);
+		window.dispatchEvent( startEvent );
 
 	};
 
@@ -117,21 +118,22 @@ function BlendCharacterGui(animations) {
 
 	controls.step = function() {
 
-		var stepData = { detail: { stepSize: controls['Step Size'] } };
-		window.dispatchEvent( new CustomEvent('step-animation', stepData ));
+		var stepData = { detail: { stepSize: controls[ 'Step Size' ] } };
+		window.dispatchEvent( new CustomEvent( 'step-animation', stepData ) );
 
 	};
 
 	controls.weight = function() {
 
 		// renormalize
-		var sum = controls['idle'] + controls['walk'] + controls['run'];
-		controls['idle'] /= sum;
-		controls['walk'] /= sum;
-		controls['run'] /= sum;
+		var sum = controls[ 'idle' ] + controls[ 'walk' ] + controls[ 'run' ];
+		controls[ 'idle' ] /= sum;
+		controls[ 'walk' ] /= sum;
+		controls[ 'run' ] /= sum;
 
 		var weightEvent = new CustomEvent( 'weight-animation', getAnimationData() );
-		window.dispatchEvent(weightEvent);
+		window.dispatchEvent( weightEvent );
+
 	};
 
 	controls.crossfade = function( from, to ) {
@@ -142,6 +144,7 @@ function BlendCharacterGui(animations) {
 		fadeData.detail.time = controls[ "Crossfade Time" ];
 
 		window.dispatchEvent( new CustomEvent( 'crossfade', fadeData ) );
+
 	};
 
 	controls.warp = function( from, to ) {
@@ -152,21 +155,22 @@ function BlendCharacterGui(animations) {
 		warpData.detail.time = controls[ "Crossfade Time" ];
 
 		window.dispatchEvent( new CustomEvent( 'warp', warpData ) );
+
 	};
 
-	controls['idle to walk'] = function() {
+	controls[ 'idle to walk' ] = function() {
 
 		controls.crossfade( 'idle', 'walk' );
 
 	};
 
-	controls['walk to run'] = function() {
+	controls[ 'walk to run' ] = function() {
 
 		controls.crossfade( 'walk', 'run' );
 
 	};
 
-	controls['warp walk to run'] = function() {
+	controls[ 'warp walk to run' ] = function() {
 
 		controls.warp( 'walk', 'run' );
 
@@ -176,11 +180,12 @@ function BlendCharacterGui(animations) {
 
 		var data = {
 			detail: {
-				shouldShow: controls['Show Skeleton']
+				shouldShow: controls[ 'Show Skeleton' ]
 			}
 		};
 
 		window.dispatchEvent( new CustomEvent( 'toggle-show-skeleton', data ) );
+
 	};
 
 
@@ -188,14 +193,15 @@ function BlendCharacterGui(animations) {
 
 		var data = {
 			detail: {
-				shouldShow: controls['Show Model']
+				shouldShow: controls[ 'Show Model' ]
 			}
 		};
 
 		window.dispatchEvent( new CustomEvent( 'toggle-show-model', data ) );
+
 	};
 
 
-	init.call(this);
+	init.call( this );
 
 }

+ 52 - 16
examples/js/Car.js

@@ -27,7 +27,7 @@ THREE.Car = function () {
 	// car "feel" parameters
 
 	this.MAX_SPEED = 2200;
-	this.MAX_REVERSE_SPEED = -1500;
+	this.MAX_REVERSE_SPEED = - 1500;
 
 	this.MAX_WHEEL_ROTATION = 0.6;
 
@@ -107,8 +107,16 @@ THREE.Car = function () {
 
 		var loader = new THREE.JSONLoader();
 
-		loader.load( bodyURL, function( geometry, materials ) { createBody( geometry, materials ) } );
-		loader.load( wheelURL, function( geometry, materials ) { createWheels( geometry, materials ) } );
+		loader.load( bodyURL, function( geometry, materials ) {
+
+			createBody( geometry, materials )
+
+		} );
+		loader.load( wheelURL, function( geometry, materials ) {
+
+			createWheels( geometry, materials )
+
+		} );
 
 	};
 
@@ -116,8 +124,16 @@ THREE.Car = function () {
 
 		var loader = new THREE.BinaryLoader();
 
-		loader.load( bodyURL, function( geometry, materials ) { createBody( geometry, materials ) } );
-		loader.load( wheelURL, function( geometry, materials ) { createWheels( geometry, materials ) } );
+		loader.load( bodyURL, function( geometry, materials ) {
+
+			createBody( geometry, materials )
+
+		} );
+		loader.load( wheelURL, function( geometry, materials ) {
+
+			createWheels( geometry, materials )
+
+		} );
 
 	};
 
@@ -128,7 +144,7 @@ THREE.Car = function () {
 		if ( controls.moveForward ) {
 
 			this.speed = THREE.Math.clamp( this.speed + delta * this.FRONT_ACCELERATION, this.MAX_REVERSE_SPEED, this.MAX_SPEED );
-			this.acceleration = THREE.Math.clamp( this.acceleration + delta, -1, 1 );
+			this.acceleration = THREE.Math.clamp( this.acceleration + delta, - 1, 1 );
 
 		}
 
@@ -136,7 +152,7 @@ THREE.Car = function () {
 
 
 			this.speed = THREE.Math.clamp( this.speed - delta * this.BACK_ACCELERATION, this.MAX_REVERSE_SPEED, this.MAX_SPEED );
-			this.acceleration = THREE.Math.clamp( this.acceleration - delta, -1, 1 );
+			this.acceleration = THREE.Math.clamp( this.acceleration - delta, - 1, 1 );
 
 		}
 
@@ -168,7 +184,7 @@ THREE.Car = function () {
 				var k = exponentialEaseOut( this.speed / this.MAX_REVERSE_SPEED );
 
 				this.speed = THREE.Math.clamp( this.speed + k * delta * this.BACK_ACCELERATION, this.MAX_REVERSE_SPEED, 0 );
-				this.acceleration = THREE.Math.clamp( this.acceleration + k * delta, -1, 0 );
+				this.acceleration = THREE.Math.clamp( this.acceleration + k * delta, - 1, 0 );
 
 			}
 
@@ -307,7 +323,7 @@ THREE.Car = function () {
 
 			// front right wheel
 
-			delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( -s, s, s ) );
+			delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( - s, s, s ) );
 
 			scope.frontRightWheelRoot.position.add( delta );
 
@@ -321,7 +337,7 @@ THREE.Car = function () {
 
 			// back left wheel
 
-			delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( s, s, -s ) );
+			delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( s, s, - s ) );
 			delta.z -= scope.backWheelOffset;
 
 			scope.backLeftWheelMesh = new THREE.Mesh( scope.wheelGeometry, wheelFaceMaterial );
@@ -333,7 +349,7 @@ THREE.Car = function () {
 
 			// back right wheel
 
-			delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( -s, s, -s ) );
+			delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( - s, s, - s ) );
 			delta.z -= scope.backWheelOffset;
 
 			scope.backRightWheelMesh = new THREE.Mesh( scope.wheelGeometry, wheelFaceMaterial );
@@ -362,10 +378,30 @@ THREE.Car = function () {
 
 	}
 
-	function quadraticEaseOut( k ) { return - k * ( k - 2 ); }
-	function cubicEaseOut( k ) { return -- k * k * k + 1; }
-	function circularEaseOut( k ) { return Math.sqrt( 1 - -- k * k ); }
-	function sinusoidalEaseOut( k ) { return Math.sin( k * Math.PI / 2 ); }
-	function exponentialEaseOut( k ) { return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1; }
+	function quadraticEaseOut( k ) {
+
+		return - k * ( k - 2 );
+
+	}
+	function cubicEaseOut( k ) {
+
+		return -- k * k * k + 1;
+
+	}
+	function circularEaseOut( k ) {
+
+		return Math.sqrt( 1 - -- k * k );
+
+	}
+	function sinusoidalEaseOut( k ) {
+
+		return Math.sin( k * Math.PI / 2 );
+
+	}
+	function exponentialEaseOut( k ) {
+
+		return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1;
+
+	}
 
 };

+ 137 - 92
examples/js/Cloth.js

@@ -19,12 +19,12 @@ var restDistance = 25;
 var xSegs = 10; //
 var ySegs = 10; //
 
-var clothFunction = plane(restDistance * xSegs, restDistance * ySegs);
+var clothFunction = plane( restDistance * xSegs, restDistance * ySegs );
 
-var cloth = new Cloth(xSegs, ySegs);
+var cloth = new Cloth( xSegs, ySegs );
 
 var GRAVITY = 981 * 1.4; // 
-var gravity = new THREE.Vector3( 0, -GRAVITY, 0 ).multiplyScalar(MASS);
+var gravity = new THREE.Vector3( 0, - GRAVITY, 0 ).multiplyScalar( MASS );
 
 
 var TIMESTEP = 18 / 1000;
@@ -35,9 +35,9 @@ var pins = [];
 
 var wind = true;
 var windStrength = 2;
-var windForce = new THREE.Vector3(0,0,0);
+var windForce = new THREE.Vector3( 0, 0, 0 );
 
-var ballPosition = new THREE.Vector3(0, -45, 0);
+var ballPosition = new THREE.Vector3( 0, - 45, 0 );
 var ballSize = 60; //40
 
 var tmpForce = new THREE.Vector3();
@@ -45,64 +45,76 @@ var tmpForce = new THREE.Vector3();
 var lastTime;
 
 
-function plane(width, height) {
+function plane( width, height ) {
 
-	return function(u, v) {
-		var x = (u - 0.5) * width;
-		var y = (v + 0.5) * height;
+	return function( u, v ) {
+
+		var x = ( u - 0.5 ) * width;
+		var y = ( v + 0.5 ) * height;
 		var z = 0;
 
-		return new THREE.Vector3(x, y, z);
+		return new THREE.Vector3( x, y, z );
+
 	};
+
 }
 
-function Particle(x, y, z, mass) {
-	this.position = clothFunction(x, y); // position
-	this.previous = clothFunction(x, y); // previous
-	this.original = clothFunction(x, y); 
-	this.a = new THREE.Vector3(0, 0, 0); // acceleration
+function Particle( x, y, z, mass ) {
+
+	this.position = clothFunction( x, y ); // position
+	this.previous = clothFunction( x, y ); // previous
+	this.original = clothFunction( x, y ); 
+	this.a = new THREE.Vector3( 0, 0, 0 ); // acceleration
 	this.mass = mass;
 	this.invMass = 1 / mass;
 	this.tmp = new THREE.Vector3();
 	this.tmp2 = new THREE.Vector3();
+
 }
 
 // Force -> Acceleration
-Particle.prototype.addForce = function(force) {
+Particle.prototype.addForce = function( force ) {
+
 	this.a.add(
-		this.tmp2.copy(force).multiplyScalar(this.invMass)
+		this.tmp2.copy( force ).multiplyScalar( this.invMass )
 	);
+
 };
 
 
 // Performs verlet integration
-Particle.prototype.integrate = function(timesq) {
-	var newPos = this.tmp.subVectors(this.position, this.previous);
-	newPos.multiplyScalar(DRAG).add(this.position);
-	newPos.add(this.a.multiplyScalar(timesq));
+Particle.prototype.integrate = function( timesq ) {
+
+	var newPos = this.tmp.subVectors( this.position, this.previous );
+	newPos.multiplyScalar( DRAG ).add( this.position );
+	newPos.add( this.a.multiplyScalar( timesq ) );
 
 	this.tmp = this.previous;
 	this.previous = this.position;
 	this.position = newPos;
 
-	this.a.set(0, 0, 0);
+	this.a.set( 0, 0, 0 );
+
 };
 
 
 var diff = new THREE.Vector3();
 
-function satisifyConstrains(p1, p2, distance) {
-	diff.subVectors(p2.position, p1.position);
+function satisifyConstrains( p1, p2, distance ) {
+
+	diff.subVectors( p2.position, p1.position );
 	var currentDist = diff.length();
-	if (currentDist == 0) return; // prevents division by 0
-	var correction = diff.multiplyScalar(1 - distance / currentDist);
-	var correctionHalf = correction.multiplyScalar(0.5);
-	p1.position.add(correctionHalf);
-	p2.position.sub(correctionHalf);
+	if ( currentDist == 0 ) return; // prevents division by 0
+	var correction = diff.multiplyScalar( 1 - distance / currentDist );
+	var correctionHalf = correction.multiplyScalar( 0.5 );
+	p1.position.add( correctionHalf );
+	p2.position.sub( correctionHalf );
+
 }
 
 
-function Cloth(w, h) {
+function Cloth( w, h ) {
+
 	w = w || 10;
 	h = h || 10;
 	this.w = w;
@@ -114,49 +126,59 @@ function Cloth(w, h) {
 	var u, v;
 
 	// Create particles
-	for (v = 0; v <= h; v ++) {
-		for (u = 0; u <= w; u ++) {
+	for ( v = 0; v <= h; v ++ ) {
+
+		for ( u = 0; u <= w; u ++ ) {
+
 			particles.push(
-				new Particle(u / w, v / h, 0, MASS)
+				new Particle( u / w, v / h, 0, MASS )
 			);
+
 		}
+
 	}
 
 	// Structural
 
-	for (v = 0; v < h; v ++) {
-		for (u = 0; u < w; u ++) {
+	for ( v = 0; v < h; v ++ ) {
+
+		for ( u = 0; u < w; u ++ ) {
 
-			constrains.push([
-				particles[index(u, v)],
-				particles[index(u, v + 1)],
+			constrains.push( [
+				particles[ index( u, v ) ],
+				particles[ index( u, v + 1 ) ],
 				restDistance
-			]);
+			] );
 
-			constrains.push([
-				particles[index(u, v)],
-				particles[index(u + 1, v)],
+			constrains.push( [
+				particles[ index( u, v ) ],
+				particles[ index( u + 1, v ) ],
 				restDistance
-			]);
+			] );
 
 		}
+
 	}
 
-	for (u = w, v = 0; v < h; v ++) {
-		constrains.push([
-			particles[index(u, v)],
-			particles[index(u, v + 1)],
+	for ( u = w, v = 0; v < h; v ++ ) {
+
+		constrains.push( [
+			particles[ index( u, v ) ],
+			particles[ index( u, v + 1 ) ],
 			restDistance
 
-		]);
+		] );
+
 	}
 
-	for (v = h, u = 0; u < w; u ++) {
-		constrains.push([
-			particles[index(u, v)],
-			particles[index(u + 1, v)],
+	for ( v = h, u = 0; u < w; u ++ ) {
+
+		constrains.push( [
+			particles[ index( u, v ) ],
+			particles[ index( u + 1, v ) ],
 			restDistance
-		]);
+		] );
+
 	}
 
 
@@ -189,91 +211,114 @@ function Cloth(w, h) {
 	this.particles = particles;
 	this.constrains = constrains;
 
-	function index(u, v) {
-		return u + v * (w + 1);
+	function index( u, v ) {
+
+		return u + v * ( w + 1 );
+
 	}
 
 	this.index = index;
 
 }
 
-function simulate(time) {
-	if (!lastTime) {
+function simulate( time ) {
+
+	if ( ! lastTime ) {
+
 		lastTime = time;
 		return;
+
 	}
 	
 	var i, il, particles, particle, pt, constrains, constrain;
 
 	// Aerodynamics forces
-	if (wind) {
+	if ( wind ) {
+
 		var face, faces = clothGeometry.faces, normal;
 
 		particles = cloth.particles;
 
-		for (i = 0,il = faces.length; i < il; i ++) {
-			face = faces[i];
+		for ( i = 0, il = faces.length; i < il; i ++ ) {
+
+			face = faces[ i ];
 			normal = face.normal;
 
-			tmpForce.copy(normal).normalize().multiplyScalar(normal.dot(windForce));
-			particles[face.a].addForce(tmpForce);
-			particles[face.b].addForce(tmpForce);
-			particles[face.c].addForce(tmpForce);
+			tmpForce.copy( normal ).normalize().multiplyScalar( normal.dot( windForce ) );
+			particles[ face.a ].addForce( tmpForce );
+			particles[ face.b ].addForce( tmpForce );
+			particles[ face.c ].addForce( tmpForce );
+
 		}
+
 	}
 	
-	for (particles = cloth.particles, i = 0, il = particles.length
-			; i < il; i ++) {
-		particle = particles[i];
-		particle.addForce(gravity);
+	for ( particles = cloth.particles, i = 0, il = particles.length
+			; i < il; i ++ ) {
+
+		particle = particles[ i ];
+		particle.addForce( gravity );
+
+		particle.integrate( TIMESTEP_SQ );
 
-		particle.integrate(TIMESTEP_SQ);
 	}
 
 	// Start Constrains
 
 	constrains = cloth.constrains,
 	il = constrains.length;
-	for (i = 0; i < il; i ++) {
-		constrain = constrains[i];
-		satisifyConstrains(constrain[0], constrain[1], constrain[2]);
+	for ( i = 0; i < il; i ++ ) {
+
+		constrain = constrains[ i ];
+		satisifyConstrains( constrain[ 0 ], constrain[ 1 ], constrain[ 2 ] );
+
 	}
 
 	// Ball Constrains
 
 
-	ballPosition.z = -Math.sin(Date.now() / 600) * 90 ; //+ 40;
-	ballPosition.x = Math.cos(Date.now() / 400) * 70;
+	ballPosition.z = - Math.sin( Date.now() / 600 ) * 90 ; //+ 40;
+	ballPosition.x = Math.cos( Date.now() / 400 ) * 70;
+
+	if ( sphere.visible )
+	for ( particles = cloth.particles, i = 0, il = particles.length
+			; i < il; i ++ ) {
 
-	if (sphere.visible)
-	for (particles = cloth.particles, i = 0, il = particles.length
-			; i < il; i ++) {
-		particle = particles[i];
+		particle = particles[ i ];
 		pos = particle.position;
-		diff.subVectors(pos, ballPosition);
-		if (diff.length() < ballSize) {
+		diff.subVectors( pos, ballPosition );
+		if ( diff.length() < ballSize ) {
+
 			// collided
-			diff.normalize().multiplyScalar(ballSize);
-			pos.copy(ballPosition).add(diff);
+			diff.normalize().multiplyScalar( ballSize );
+			pos.copy( ballPosition ).add( diff );
+
 		}
+
 	}
 
 	// Floor Constains
-	for (particles = cloth.particles, i = 0, il = particles.length
-			; i < il; i ++) {
-		particle = particles[i];
+	for ( particles = cloth.particles, i = 0, il = particles.length
+			; i < il; i ++ ) {
+
+		particle = particles[ i ];
 		pos = particle.position;
-		if (pos.y < -250) {
-			pos.y = -250;
+		if ( pos.y < - 250 ) {
+
+			pos.y = - 250;
+
 		}
+
 	}
 
 	// Pin Constrains
-	for (i = 0, il = pins.length; i < il; i ++) {
-		var xy = pins[i];
-		var p = particles[xy];
-		p.position.copy(p.original);
-		p.previous.copy(p.original);
+	for ( i = 0, il = pins.length; i < il; i ++ ) {
+
+		var xy = pins[ i ];
+		var p = particles[ xy ];
+		p.position.copy( p.original );
+		p.previous.copy( p.original );
+
 	}
 
 

+ 96 - 92
examples/js/CurveExtras.js

@@ -17,32 +17,34 @@ THREE.Curves = {};
 
  THREE.Curves.GrannyKnot = THREE.Curve.create( function() {},
 
-	 function(t) {
+	 function( t ) {
+
 		t = 2 * Math.PI * t;
 
-		var x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t);
-		var y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t);
-		var z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t);
-		return new THREE.Vector3(x, y, z).multiplyScalar(20);
+		var x = - 0.22 * Math.cos( t ) - 1.28 * Math.sin( t ) - 0.44 * Math.cos( 3 * t ) - 0.78 * Math.sin( 3 * t );
+		var y = - 0.1 * Math.cos( 2 * t ) - 0.27 * Math.sin( 2 * t ) + 0.38 * Math.cos( 4 * t ) + 0.46 * Math.sin( 4 * t );
+		var z = 0.7 * Math.cos( 3 * t ) - 0.4 * Math.sin( 3 * t );
+		return new THREE.Vector3( x, y, z ).multiplyScalar( 20 );
+
 	}
 );
 
 THREE.Curves.HeartCurve = THREE.Curve.create(
 
-function(s) {
+function( s ) {
 
-	this.scale = (s === undefined) ? 5 : s;
+	this.scale = ( s === undefined ) ? 5 : s;
 
 },
 
-function(t) {
+function( t ) {
 
 	t *= 2 * Math.PI;
 
-	var tx = 16 * Math.pow(Math.sin(t), 3);
-	var ty = 13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t), tz = 0;
+	var tx = 16 * Math.pow( Math.sin( t ), 3 );
+	var ty = 13 * Math.cos( t ) - 5 * Math.cos( 2 * t ) - 2 * Math.cos( 3 * t ) - Math.cos( 4 * t ), tz = 0;
 
-	return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
+	return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
 
 }
 
@@ -53,20 +55,21 @@ function(t) {
 // Viviani's Curve
 THREE.Curves.VivianiCurve = THREE.Curve.create(
 
-	function(radius) {
+	function( radius ) {
 
 		this.radius = radius;
+
 	},
 
-	function(t) {
+	function( t ) {
 
 		t = t * 4 * Math.PI; // Normalized to 0..1
 		var a = this.radius / 2;
-		var tx = a * (1 + Math.cos(t)),
-			ty = a * Math.sin(t),
-			tz = 2 * a * Math.sin(t / 2);
+		var tx = a * ( 1 + Math.cos( t ) ),
+			ty = a * Math.sin( t ),
+			tz = 2 * a * Math.sin( t / 2 );
 
-		return new THREE.Vector3(tx, ty, tz);
+		return new THREE.Vector3( tx, ty, tz );
 
 	}
 
@@ -79,17 +82,17 @@ THREE.Curves.KnotCurve = THREE.Curve.create(
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		t *= 2 * Math.PI;
 
 		var R = 10;
 		var s = 50;
-		var tx = s * Math.sin(t),
-			ty = Math.cos(t) * (R + s * Math.cos(t)),
-			tz = Math.sin(t) * (R + s * Math.cos(t));
+		var tx = s * Math.sin( t ),
+			ty = Math.cos( t ) * ( R + s * Math.cos( t ) ),
+			tz = Math.sin( t ) * ( R + s * Math.cos( t ) );
 
-		return new THREE.Vector3(tx, ty, tz);
+		return new THREE.Vector3( tx, ty, tz );
 
 	}
 
@@ -101,16 +104,16 @@ THREE.Curves.HelixCurve = THREE.Curve.create(
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		var a = 30; // radius
 		var b = 150; //height
 		var t2 = 2 * Math.PI * t * b / 30;
-		var tx = Math.cos(t2) * a,
-			ty = Math.sin(t2) * a,
+		var tx = Math.cos( t2 ) * a,
+			ty = Math.sin( t2 ) * a,
 			tz = b * t;
 
-		return new THREE.Vector3(tx, ty, tz);
+		return new THREE.Vector3( tx, ty, tz );
 
 	}
 
@@ -118,20 +121,20 @@ THREE.Curves.HelixCurve = THREE.Curve.create(
 
 THREE.Curves.TrefoilKnot = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 10 : s;
+		this.scale = ( s === undefined ) ? 10 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		t *= Math.PI * 2;
-		var tx = (2 + Math.cos(3 * t)) * Math.cos(2 * t),
-			ty = (2 + Math.cos(3 * t)) * Math.sin(2 * t),
-			tz = Math.sin(3 * t);
+		var tx = ( 2 + Math.cos( 3 * t ) ) * Math.cos( 2 * t ),
+			ty = ( 2 + Math.cos( 3 * t ) ) * Math.sin( 2 * t ),
+			tz = Math.sin( 3 * t );
 
-		return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
+		return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
 
 	}
 
@@ -139,22 +142,22 @@ THREE.Curves.TrefoilKnot = THREE.Curve.create(
 
 THREE.Curves.TorusKnot = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 10 : s;
+		this.scale = ( s === undefined ) ? 10 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		var p = 3,
 			q = 4;
 		t *= Math.PI * 2;
-		var tx = (2 + Math.cos(q * t)) * Math.cos(p * t),
-			ty = (2 + Math.cos(q * t)) * Math.sin(p * t),
-			tz = Math.sin(q * t);
+		var tx = ( 2 + Math.cos( q * t ) ) * Math.cos( p * t ),
+			ty = ( 2 + Math.cos( q * t ) ) * Math.sin( p * t ),
+			tz = Math.sin( q * t );
 
-		return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
+		return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
 
 	}
 
@@ -163,22 +166,22 @@ THREE.Curves.TorusKnot = THREE.Curve.create(
 
 THREE.Curves.CinquefoilKnot = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 10 : s;
+		this.scale = ( s === undefined ) ? 10 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		var p = 2,
 			q = 5;
 		t *= Math.PI * 2;
-		var tx = (2 + Math.cos(q * t)) * Math.cos(p * t),
-			ty = (2 + Math.cos(q * t)) * Math.sin(p * t),
-			tz = Math.sin(q * t);
+		var tx = ( 2 + Math.cos( q * t ) ) * Math.cos( p * t ),
+			ty = ( 2 + Math.cos( q * t ) ) * Math.sin( p * t ),
+			tz = Math.sin( q * t );
 
-		return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
+		return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
 
 	}
 
@@ -187,20 +190,20 @@ THREE.Curves.CinquefoilKnot = THREE.Curve.create(
 
 THREE.Curves.TrefoilPolynomialKnot = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 10 : s;
+		this.scale = ( s === undefined ) ? 10 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		t = t * 4 - 2;
-		var tx = Math.pow(t, 3) - 3 * t,
-			ty = Math.pow(t, 4) - 4 * t * t,
-			tz = 1 / 5 * Math.pow(t, 5) - 2 * t;
+		var tx = Math.pow( t, 3 ) - 3 * t,
+			ty = Math.pow( t, 4 ) - 4 * t * t,
+			tz = 1 / 5 * Math.pow( t, 5 ) - 2 * t;
 
-		return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
+		return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
 
 	}
 
@@ -212,7 +215,7 @@ THREE.Curves.TrefoilPolynomialKnot = THREE.Curve.create(
 //     t * r + x;
 //   };
 // }
-var scaleTo = function(x, y, t) {
+var scaleTo = function( x, y, t ) {
 
 	var r = y - x;
 	return t * r + x;
@@ -221,20 +224,20 @@ var scaleTo = function(x, y, t) {
 
 THREE.Curves.FigureEightPolynomialKnot = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 1 : s;
+		this.scale = ( s === undefined ) ? 1 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
 
-		t = scaleTo(-4, 4, t);
-		var tx = 2 / 5 * t * (t * t - 7) * (t * t - 10),
-			ty = Math.pow(t, 4) - 13 * t * t,
-			tz = 1 / 10 * t * (t * t - 4) * (t * t - 9) * (t * t - 12);
+		t = scaleTo( - 4, 4, t );
+		var tx = 2 / 5 * t * ( t * t - 7 ) * ( t * t - 10 ),
+			ty = Math.pow( t, 4 ) - 13 * t * t,
+			tz = 1 / 10 * t * ( t * t - 4 ) * ( t * t - 9 ) * ( t * t - 12 );
 
-		return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
+		return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
 
 	}
 
@@ -242,21 +245,21 @@ THREE.Curves.FigureEightPolynomialKnot = THREE.Curve.create(
 
 THREE.Curves.DecoratedTorusKnot4a = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 40 : s;
+		this.scale = ( s === undefined ) ? 40 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		t *= Math.PI * 2;
 		var
-		x = Math.cos(2 * t) * (1 + 0.6 * (Math.cos(5 * t) + 0.75 * Math.cos(10 * t))),
-			y = Math.sin(2 * t) * (1 + 0.6 * (Math.cos(5 * t) + 0.75 * Math.cos(10 * t))),
-			z = 0.35 * Math.sin(5 * t);
+		x = Math.cos( 2 * t ) * ( 1 + 0.6 * ( Math.cos( 5 * t ) + 0.75 * Math.cos( 10 * t ) ) ),
+			y = Math.sin( 2 * t ) * ( 1 + 0.6 * ( Math.cos( 5 * t ) + 0.75 * Math.cos( 10 * t ) ) ),
+			z = 0.35 * Math.sin( 5 * t );
 
-		return new THREE.Vector3(x, y, z).multiplyScalar(this.scale);
+		return new THREE.Vector3( x, y, z ).multiplyScalar( this.scale );
 
 	}
 
@@ -265,19 +268,20 @@ THREE.Curves.DecoratedTorusKnot4a = THREE.Curve.create(
 
 THREE.Curves.DecoratedTorusKnot4b = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 40 : s;
+		this.scale = ( s === undefined ) ? 40 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
+
 		var fi = t * Math.PI * 2;
-		var x = Math.cos(2 * fi) * (1 + 0.45 * Math.cos(3 * fi) + 0.4 * Math.cos(9 * fi)),
-			y = Math.sin(2 * fi) * (1 + 0.45 * Math.cos(3 * fi) + 0.4 * Math.cos(9 * fi)),
-			z = 0.2 * Math.sin(9 * fi);
+		var x = Math.cos( 2 * fi ) * ( 1 + 0.45 * Math.cos( 3 * fi ) + 0.4 * Math.cos( 9 * fi ) ),
+			y = Math.sin( 2 * fi ) * ( 1 + 0.45 * Math.cos( 3 * fi ) + 0.4 * Math.cos( 9 * fi ) ),
+			z = 0.2 * Math.sin( 9 * fi );
 
-		return new THREE.Vector3(x, y, z).multiplyScalar(this.scale);
+		return new THREE.Vector3( x, y, z ).multiplyScalar( this.scale );
 
 	}
 
@@ -286,20 +290,20 @@ THREE.Curves.DecoratedTorusKnot4b = THREE.Curve.create(
 
 THREE.Curves.DecoratedTorusKnot5a = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 40 : s;
+		this.scale = ( s === undefined ) ? 40 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		var fi = t * Math.PI * 2;
-		var x = Math.cos(3 * fi) * (1 + 0.3 * Math.cos(5 * fi) + 0.5 * Math.cos(10 * fi)),
-			y = Math.sin(3 * fi) * (1 + 0.3 * Math.cos(5 * fi) + 0.5 * Math.cos(10 * fi)),
-			z = 0.2 * Math.sin(20 * fi);
+		var x = Math.cos( 3 * fi ) * ( 1 + 0.3 * Math.cos( 5 * fi ) + 0.5 * Math.cos( 10 * fi ) ),
+			y = Math.sin( 3 * fi ) * ( 1 + 0.3 * Math.cos( 5 * fi ) + 0.5 * Math.cos( 10 * fi ) ),
+			z = 0.2 * Math.sin( 20 * fi );
 
-		return new THREE.Vector3(x, y, z).multiplyScalar(this.scale);
+		return new THREE.Vector3( x, y, z ).multiplyScalar( this.scale );
 
 	}
 
@@ -307,21 +311,21 @@ THREE.Curves.DecoratedTorusKnot5a = THREE.Curve.create(
 
 THREE.Curves.DecoratedTorusKnot5c = THREE.Curve.create(
 
-	function(s) {
+	function( s ) {
 
-		this.scale = (s === undefined) ? 40 : s;
+		this.scale = ( s === undefined ) ? 40 : s;
 
 	},
 
-	function(t) {
+	function( t ) {
 
 		var fi = t * Math.PI * 2;
-		var x = Math.cos(4 * fi) * (1 + 0.5 * (Math.cos(5 * fi) + 0.4 * Math.cos(20 * fi))),
-			y = Math.sin(4 * fi) * (1 + 0.5 * (Math.cos(5 * fi) + 0.4 * Math.cos(20 * fi))),
-			z = 0.35 * Math.sin(15 * fi);
+		var x = Math.cos( 4 * fi ) * ( 1 + 0.5 * ( Math.cos( 5 * fi ) + 0.4 * Math.cos( 20 * fi ) ) ),
+			y = Math.sin( 4 * fi ) * ( 1 + 0.5 * ( Math.cos( 5 * fi ) + 0.4 * Math.cos( 20 * fi ) ) ),
+			z = 0.35 * Math.sin( 15 * fi );
 
-		return new THREE.Vector3(x, y, z).multiplyScalar(this.scale);
+		return new THREE.Vector3( x, y, z ).multiplyScalar( this.scale );
 
 	}
 
-);
+);

+ 13 - 1
examples/js/Detector.js

@@ -6,7 +6,19 @@
 var Detector = {
 
 	canvas: !! window.CanvasRenderingContext2D,
-	webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) ); } catch ( e ) { return false; } } )(),
+	webgl: ( function () {
+
+		try {
+
+			var canvas = document.createElement( 'canvas' ); return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) );
+
+		} catch ( e ) {
+
+			return false;
+
+		}
+
+	} )(),
 	workers: !! window.Worker,
 	fileapi: window.File && window.FileReader && window.FileList && window.Blob,
 

+ 1 - 1
examples/js/MD2Character.js

@@ -209,7 +209,7 @@ THREE.MD2Character = function () {
 		//
 
 		var mesh = new THREE.MorphAnimMesh( geometry, materialTexture );
-		mesh.rotation.y = -Math.PI / 2;
+		mesh.rotation.y = - Math.PI / 2;
 
 		mesh.castShadow = true;
 		mesh.receiveShadow = true;

+ 10 - 6
examples/js/MD2CharacterComplex.js

@@ -16,7 +16,7 @@ THREE.MD2CharacterComplex = function () {
 	// movement model parameters
 
 	this.maxSpeed = 275;
-	this.maxReverseSpeed = -275;
+	this.maxReverseSpeed = - 275;
 
 	this.frontAcceleration = 600;
 	this.backAcceleration = 600;
@@ -261,7 +261,7 @@ THREE.MD2CharacterComplex = function () {
 
 	this.setAnimation = function ( animationName ) {
 
-		if ( animationName === this.activeAnimation || !animationName ) return;
+		if ( animationName === this.activeAnimation || ! animationName ) return;
 
 		if ( this.meshBody ) {
 
@@ -388,7 +388,7 @@ THREE.MD2CharacterComplex = function () {
 		}
 
 
-		if ( Math.abs( this.speed ) < 0.2 * this.maxSpeed && !( controls.moveLeft || controls.moveRight || controls.moveForward || controls.moveBackward ) ) {
+		if ( Math.abs( this.speed ) < 0.2 * this.maxSpeed && ! ( controls.moveLeft || controls.moveRight || controls.moveForward || controls.moveBackward ) ) {
 
 			if ( this.activeAnimation !== idleAnimation ) {
 
@@ -447,7 +447,7 @@ THREE.MD2CharacterComplex = function () {
 		if ( controls.crouch ) 	this.maxSpeed = this.crouchSpeed;
 		else this.maxSpeed = this.walkSpeed;
 
-		this.maxReverseSpeed = -this.maxSpeed;
+		this.maxReverseSpeed = - this.maxSpeed;
 
 		if ( controls.moveForward )  this.speed = THREE.Math.clamp( this.speed + delta * this.frontAcceleration, this.maxReverseSpeed, this.maxSpeed );
 		if ( controls.moveBackward ) this.speed = THREE.Math.clamp( this.speed - delta * this.backAcceleration, this.maxReverseSpeed, this.maxSpeed );
@@ -532,7 +532,7 @@ THREE.MD2CharacterComplex = function () {
 		//
 
 		var mesh = new THREE.MorphBlendMesh( geometry, materialTexture );
-		mesh.rotation.y = -Math.PI / 2;
+		mesh.rotation.y = - Math.PI / 2;
 
 		//
 
@@ -554,6 +554,10 @@ THREE.MD2CharacterComplex = function () {
 
 	}
 
-	function exponentialEaseOut( k ) { return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1; }
+	function exponentialEaseOut( k ) {
+
+		return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1;
+
+	}
 
 };

+ 267 - 263
examples/js/MarchingCubes.js

@@ -80,7 +80,11 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
 	// Polygonization
 	///////////////////////
 
-	this.lerp = function( a, b, t ) { return a + ( b - a ) * t; };
+	this.lerp = function( a, b, t ) {
+
+		return a + ( b - a ) * t;
+
+	};
 
 	this.VIntX = function( q, pout, nout, offset, isol, x, y, z, valp1, valp2 ) {
 
@@ -137,7 +141,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
 
 		if ( this.normal_cache[ q3 ] === 0.0 ) {
 
-			this.normal_cache[ q3     ] = this.field[ q - 1  ] 	    - this.field[ q + 1 ];
+			this.normal_cache[ q3 ] = this.field[ q - 1 ] 	    - this.field[ q + 1 ];
 			this.normal_cache[ q3 + 1 ] = this.field[ q - this.yd ] - this.field[ q + this.yd ];
 			this.normal_cache[ q3 + 2 ] = this.field[ q - this.zd ] - this.field[ q + this.zd ];
 
@@ -296,7 +300,7 @@ THREE.MarchingCubes = function ( resolution, material, enableUvs, enableColors )
 
 		// here is where triangles are created
 
-		while ( THREE.triTable[ cubeindex + i ] != -1 ) {
+		while ( THREE.triTable[ cubeindex + i ] != - 1 ) {
 
 			o1 = cubeindex + i;
 			o2 = o1 + 1;
@@ -762,7 +766,7 @@ THREE.MarchingCubes.prototype.constructor = THREE.MarchingCubes;
 // http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/
 // who in turn got them from Cory Gene Bloyd.
 
-THREE.edgeTable = new Int32Array([
+THREE.edgeTable = new Int32Array( [
 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
@@ -794,262 +798,262 @@ THREE.edgeTable = new Int32Array([
 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99, 0x190,
 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
-0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 ]);
-
-THREE.triTable = new Int32Array([
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1,
-3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1,
-3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1,
-3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1,
-9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1,
-9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1,
-2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1,
-8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1,
-9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1,
-4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1,
-3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1,
-1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1,
-4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1,
-4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1,
-9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1,
-5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1,
-2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1,
-9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1,
-0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1,
-2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1,
-10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1,
-4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1,
-5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1,
-5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1,
-9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1,
-0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1,
-1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1,
-10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1,
-8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1,
-2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1,
-7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1,
-9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1,
-2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1,
-11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1,
-9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1,
-5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1,
-11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1,
-11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1,
-1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1,
-9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1,
-5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1,
-2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1,
-0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1,
-5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1,
-6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1,
-3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1,
-6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1,
-5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1,
-1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1,
-10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1,
-6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1,
-8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1,
-7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1,
-3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1,
-5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1,
-0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1,
-9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1,
-8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1,
-5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1,
-0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1,
-6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1,
-10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1,
-10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1,
-8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1,
-1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1,
-3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1,
-0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1,
-10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1,
-3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1,
-6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1,
-9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1,
-8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1,
-3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1,
-6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1,
-0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1,
-10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1,
-10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1,
-2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1,
-7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1,
-7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1,
-2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1,
-1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1,
-11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1,
-8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1,
-0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1,
-7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1,
-10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1,
-2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1,
-6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1,
-7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1,
-2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1,
-1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1,
-10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1,
-10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1,
-0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1,
-7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1,
-6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1,
-8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1,
-9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1,
-6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1,
-4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1,
-10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1,
-8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1,
-0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1,
-1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1,
-8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1,
-10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1,
-4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1,
-10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1,
-5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1,
-11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1,
-9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1,
-6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1,
-7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1,
-3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1,
-7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1,
-9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1,
-3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1,
-6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1,
-9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1,
-1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1,
-4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1,
-7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1,
-6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1,
-3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1,
-0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1,
-6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1,
-0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1,
-11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1,
-6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1,
-5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1,
-9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1,
-1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1,
-1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1,
-10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1,
-0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1,
-5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1,
-10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1,
-11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1,
-9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1,
-7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1,
-2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1,
-8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1,
-9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1,
-9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1,
-1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1,
-9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1,
-9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1,
-5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1,
-0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1,
-10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1,
-2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1,
-0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1,
-0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1,
-9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1,
-5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1,
-3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1,
-5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1,
-8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1,
-0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1,
-9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1,
-0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1,
-1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1,
-3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1,
-4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1,
-9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1,
-11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1,
-11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1,
-2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1,
-9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1,
-3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1,
-1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1,
-4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1,
-4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1,
-0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1,
-3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1,
-3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1,
-0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1,
-9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1,
-1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ]);
+0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 ] );
+
+THREE.triTable = new Int32Array( [
+- 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 1, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 8, 3, 9, 8, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 3, 1, 2, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 2, 10, 0, 2, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 8, 3, 2, 10, 8, 10, 9, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 11, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 11, 2, 8, 11, 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 9, 0, 2, 3, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 11, 2, 1, 9, 11, 9, 8, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 10, 1, 11, 10, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 10, 1, 0, 8, 10, 8, 11, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 9, 0, 3, 11, 9, 11, 10, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 8, 10, 10, 8, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 7, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 3, 0, 7, 3, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 1, 9, 8, 4, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 1, 9, 4, 7, 1, 7, 3, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 10, 8, 4, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 4, 7, 3, 0, 4, 1, 2, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 2, 10, 9, 0, 2, 8, 4, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, - 1, - 1, - 1, - 1,
+8, 4, 7, 3, 11, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+11, 4, 7, 11, 2, 4, 2, 0, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 0, 1, 8, 4, 7, 2, 3, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, - 1, - 1, - 1, - 1,
+3, 10, 1, 3, 11, 10, 7, 8, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, - 1, - 1, - 1, - 1,
+4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, - 1, - 1, - 1, - 1,
+4, 7, 11, 4, 11, 9, 9, 11, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 5, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 5, 4, 0, 8, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 5, 4, 1, 5, 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+8, 5, 4, 8, 3, 5, 3, 1, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 10, 9, 5, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 0, 8, 1, 2, 10, 4, 9, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 2, 10, 5, 4, 2, 4, 0, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, - 1, - 1, - 1, - 1,
+9, 5, 4, 2, 3, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 11, 2, 0, 8, 11, 4, 9, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 5, 4, 0, 1, 5, 2, 3, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, - 1, - 1, - 1, - 1,
+10, 3, 11, 10, 1, 3, 9, 5, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, - 1, - 1, - 1, - 1,
+5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, - 1, - 1, - 1, - 1,
+5, 4, 8, 5, 8, 10, 10, 8, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 7, 8, 5, 7, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 3, 0, 9, 5, 3, 5, 7, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 7, 8, 0, 1, 7, 1, 5, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 5, 3, 3, 5, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 7, 8, 9, 5, 7, 10, 1, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, - 1, - 1, - 1, - 1,
+8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, - 1, - 1, - 1, - 1,
+2, 10, 5, 2, 5, 3, 3, 5, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+7, 9, 5, 7, 8, 9, 3, 11, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, - 1, - 1, - 1, - 1,
+2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, - 1, - 1, - 1, - 1,
+11, 2, 1, 11, 1, 7, 7, 1, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, - 1, - 1, - 1, - 1,
+5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, - 1,
+11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, - 1,
+11, 10, 5, 7, 11, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 6, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 3, 5, 10, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 0, 1, 5, 10, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 8, 3, 1, 9, 8, 5, 10, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 6, 5, 2, 6, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 6, 5, 1, 2, 6, 3, 0, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 6, 5, 9, 0, 6, 0, 2, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, - 1, - 1, - 1, - 1,
+2, 3, 11, 10, 6, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+11, 0, 8, 11, 2, 0, 10, 6, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 1, 9, 2, 3, 11, 5, 10, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, - 1, - 1, - 1, - 1,
+6, 3, 11, 6, 5, 3, 5, 1, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, - 1, - 1, - 1, - 1,
+3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, - 1, - 1, - 1, - 1,
+6, 5, 9, 6, 9, 11, 11, 9, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 10, 6, 4, 7, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 3, 0, 4, 7, 3, 6, 5, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 9, 0, 5, 10, 6, 8, 4, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, - 1, - 1, - 1, - 1,
+6, 1, 2, 6, 5, 1, 4, 7, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, - 1, - 1, - 1, - 1,
+8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, - 1, - 1, - 1, - 1,
+7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, - 1,
+3, 11, 2, 7, 8, 4, 10, 6, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, - 1, - 1, - 1, - 1,
+0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, - 1, - 1, - 1, - 1,
+9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, - 1,
+8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, - 1, - 1, - 1, - 1,
+5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, - 1,
+0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, - 1,
+6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, - 1, - 1, - 1, - 1,
+10, 4, 9, 6, 4, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 10, 6, 4, 9, 10, 0, 8, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 0, 1, 10, 6, 0, 6, 4, 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, - 1, - 1, - 1, - 1,
+1, 4, 9, 1, 2, 4, 2, 6, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, - 1, - 1, - 1, - 1,
+0, 2, 4, 4, 2, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+8, 3, 2, 8, 2, 4, 4, 2, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 4, 9, 10, 6, 4, 11, 2, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, - 1, - 1, - 1, - 1,
+3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, - 1, - 1, - 1, - 1,
+6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, - 1,
+9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, - 1, - 1, - 1, - 1,
+8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, - 1,
+3, 11, 6, 3, 6, 0, 0, 6, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+6, 4, 8, 11, 6, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+7, 10, 6, 7, 8, 10, 8, 9, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, - 1, - 1, - 1, - 1,
+10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, - 1, - 1, - 1, - 1,
+10, 6, 7, 10, 7, 1, 1, 7, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, - 1, - 1, - 1, - 1,
+2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, - 1,
+7, 8, 0, 7, 0, 6, 6, 0, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+7, 3, 2, 6, 7, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, - 1, - 1, - 1, - 1,
+2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, - 1,
+1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, - 1,
+11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, - 1, - 1, - 1, - 1,
+8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, - 1,
+0, 9, 1, 11, 6, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, - 1, - 1, - 1, - 1,
+7, 11, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+7, 6, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 0, 8, 11, 7, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 1, 9, 11, 7, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+8, 1, 9, 8, 3, 1, 11, 7, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 1, 2, 6, 11, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 10, 3, 0, 8, 6, 11, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 9, 0, 2, 10, 9, 6, 11, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, - 1, - 1, - 1, - 1,
+7, 2, 3, 6, 2, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+7, 0, 8, 7, 6, 0, 6, 2, 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 7, 6, 2, 3, 7, 0, 1, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, - 1, - 1, - 1, - 1,
+10, 7, 6, 10, 1, 7, 1, 3, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, - 1, - 1, - 1, - 1,
+0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, - 1, - 1, - 1, - 1,
+7, 6, 10, 7, 10, 8, 8, 10, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+6, 8, 4, 11, 8, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 6, 11, 3, 0, 6, 0, 4, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+8, 6, 11, 8, 4, 6, 9, 0, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, - 1, - 1, - 1, - 1,
+6, 8, 4, 6, 11, 8, 2, 10, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, - 1, - 1, - 1, - 1,
+4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, - 1, - 1, - 1, - 1,
+10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, - 1,
+8, 2, 3, 8, 4, 2, 4, 6, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 4, 2, 4, 6, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, - 1, - 1, - 1, - 1,
+1, 9, 4, 1, 4, 2, 2, 4, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, - 1, - 1, - 1, - 1,
+10, 1, 0, 10, 0, 6, 6, 0, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, - 1,
+10, 9, 4, 6, 10, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 9, 5, 7, 6, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 3, 4, 9, 5, 11, 7, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 0, 1, 5, 4, 0, 7, 6, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, - 1, - 1, - 1, - 1,
+9, 5, 4, 10, 1, 2, 7, 6, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, - 1, - 1, - 1, - 1,
+7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, - 1, - 1, - 1, - 1,
+3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, - 1,
+7, 2, 3, 7, 6, 2, 5, 4, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, - 1, - 1, - 1, - 1,
+3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, - 1, - 1, - 1, - 1,
+6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, - 1,
+9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, - 1, - 1, - 1, - 1,
+1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, - 1,
+4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, - 1,
+7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, - 1, - 1, - 1, - 1,
+6, 9, 5, 6, 11, 9, 11, 8, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, - 1, - 1, - 1, - 1,
+0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, - 1, - 1, - 1, - 1,
+6, 11, 3, 6, 3, 5, 5, 3, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, - 1, - 1, - 1, - 1,
+0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, - 1,
+11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, - 1,
+6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, - 1, - 1, - 1, - 1,
+5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, - 1, - 1, - 1, - 1,
+9, 5, 6, 9, 6, 0, 0, 6, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, - 1,
+1, 5, 6, 2, 1, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, - 1,
+10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, - 1, - 1, - 1, - 1,
+0, 3, 8, 5, 6, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 5, 6, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+11, 5, 10, 7, 5, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+11, 5, 10, 11, 7, 5, 8, 3, 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 11, 7, 5, 10, 11, 1, 9, 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, - 1, - 1, - 1, - 1,
+11, 1, 2, 11, 7, 1, 7, 5, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, - 1, - 1, - 1, - 1,
+9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, - 1, - 1, - 1, - 1,
+7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, - 1,
+2, 5, 10, 2, 3, 5, 3, 7, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, - 1, - 1, - 1, - 1,
+9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, - 1, - 1, - 1, - 1,
+9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, - 1,
+1, 3, 5, 3, 7, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 7, 0, 7, 1, 1, 7, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 0, 3, 9, 3, 5, 5, 3, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 8, 7, 5, 9, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 8, 4, 5, 10, 8, 10, 11, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, - 1, - 1, - 1, - 1,
+0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, - 1, - 1, - 1, - 1,
+10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, - 1,
+2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, - 1, - 1, - 1, - 1,
+0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, - 1,
+0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, - 1,
+9, 4, 5, 2, 11, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, - 1, - 1, - 1, - 1,
+5, 10, 2, 5, 2, 4, 4, 2, 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, - 1,
+5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, - 1, - 1, - 1, - 1,
+8, 4, 5, 8, 5, 3, 3, 5, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 4, 5, 1, 0, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, - 1, - 1, - 1, - 1,
+9, 4, 5, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 11, 7, 4, 9, 11, 9, 10, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, - 1, - 1, - 1, - 1,
+1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, - 1, - 1, - 1, - 1,
+3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, - 1,
+4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, - 1, - 1, - 1, - 1,
+9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, - 1,
+11, 7, 4, 11, 4, 2, 2, 4, 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, - 1, - 1, - 1, - 1,
+2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, - 1, - 1, - 1, - 1,
+9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, - 1,
+3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, - 1,
+1, 10, 2, 8, 7, 4, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 9, 1, 4, 1, 7, 7, 1, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, - 1, - 1, - 1, - 1,
+4, 0, 3, 7, 4, 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+4, 8, 7, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 10, 8, 10, 11, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 0, 9, 3, 9, 11, 11, 9, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 1, 10, 0, 10, 8, 8, 10, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 1, 10, 11, 3, 10, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 2, 11, 1, 11, 9, 9, 11, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, - 1, - 1, - 1, - 1,
+0, 2, 11, 8, 0, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+3, 2, 11, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 3, 8, 2, 8, 10, 10, 8, 9, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+9, 10, 2, 0, 9, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, - 1, - 1, - 1, - 1,
+1, 10, 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+1, 3, 8, 9, 1, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 9, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+0, 3, 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1,
+- 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1 ] );

+ 27 - 26
examples/js/Mirror.js

@@ -2,9 +2,9 @@
  * @author Slayvin / http://slayvin.net
  */
 
-THREE.ShaderLib['mirror'] = {
+THREE.ShaderLib[ 'mirror' ] = {
 
-	uniforms: { "mirrorColor": { type: "c", value: new THREE.Color(0x7F7F7F) },
+	uniforms: { "mirrorColor": { type: "c", value: new THREE.Color( 0x7F7F7F ) },
 				"mirrorSampler": { type: "t", value: null },
 				"textureMatrix" : { type: "m4", value: new THREE.Matrix4() }
 	},
@@ -25,7 +25,7 @@ THREE.ShaderLib['mirror'] = {
 
 		"}"
 
-	].join("\n"),
+	].join( "\n" ),
 
 	fragmentShader: [
 
@@ -47,7 +47,7 @@ THREE.ShaderLib['mirror'] = {
 
 		"}"
 
-	].join("\n")
+	].join( "\n" )
 
 };
 
@@ -66,7 +66,7 @@ THREE.Mirror = function ( renderer, camera, options ) {
 
 	this.clipBias = options.clipBias !== undefined ? options.clipBias : 0.0;
 
-	var mirrorColor = options.color !== undefined ? new THREE.Color(options.color) : new THREE.Color(0x7F7F7F);
+	var mirrorColor = options.color !== undefined ? new THREE.Color( options.color ) : new THREE.Color( 0x7F7F7F );
 
 	this.renderer = renderer;
 	this.mirrorPlane = new THREE.Plane();
@@ -74,7 +74,7 @@ THREE.Mirror = function ( renderer, camera, options ) {
 	this.mirrorWorldPosition = new THREE.Vector3();
 	this.cameraWorldPosition = new THREE.Vector3();
 	this.rotationMatrix = new THREE.Matrix4();
-	this.lookAtPosition = new THREE.Vector3(0, 0, -1);
+	this.lookAtPosition = new THREE.Vector3( 0, 0, - 1 );
 	this.clipPlane = new THREE.Vector4();
 	
 	// For debug only, show the normal and plane of the mirror
@@ -82,17 +82,17 @@ THREE.Mirror = function ( renderer, camera, options ) {
 
 	if ( debugMode ) {
 
-		var arrow = new THREE.ArrowHelper(new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, 0 ), 10, 0xffff80 );
+		var arrow = new THREE.ArrowHelper( new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, 0 ), 10, 0xffff80 );
 		var planeGeometry = new THREE.Geometry();
-		planeGeometry.vertices.push( new THREE.Vector3( -10, -10, 0 ) );
-		planeGeometry.vertices.push( new THREE.Vector3( 10, -10, 0 ) );
+		planeGeometry.vertices.push( new THREE.Vector3( - 10, - 10, 0 ) );
+		planeGeometry.vertices.push( new THREE.Vector3( 10, - 10, 0 ) );
 		planeGeometry.vertices.push( new THREE.Vector3( 10, 10, 0 ) );
-		planeGeometry.vertices.push( new THREE.Vector3( -10, 10, 0 ) );
-		planeGeometry.vertices.push( planeGeometry.vertices[0] );
+		planeGeometry.vertices.push( new THREE.Vector3( - 10, 10, 0 ) );
+		planeGeometry.vertices.push( planeGeometry.vertices[ 0 ] );
 		var plane = new THREE.Line( planeGeometry, new THREE.LineBasicMaterial( { color: 0xffff80 } ) );
 
-		this.add(arrow);
-		this.add(plane);
+		this.add( arrow );
+		this.add( plane );
 
 	}
 
@@ -132,7 +132,7 @@ THREE.Mirror = function ( renderer, camera, options ) {
 	this.material.uniforms.mirrorColor.value = mirrorColor;
 	this.material.uniforms.textureMatrix.value = this.textureMatrix;
 
-	if ( !THREE.Math.isPowerOfTwo(width) || !THREE.Math.isPowerOfTwo( height ) ) {
+	if ( ! THREE.Math.isPowerOfTwo( width ) || ! THREE.Math.isPowerOfTwo( height ) ) {
 
 		this.texture.generateMipmaps = false;
 		this.tempTexture.generateMipmaps = false;
@@ -171,6 +171,7 @@ THREE.Mirror.prototype.renderWithMirror = function ( otherMirror ) {
 
 	// restore texture matrix of other mirror
 	otherMirror.updateTextureMatrix();
+
 };
 
 THREE.Mirror.prototype.updateTextureMatrix = function () {
@@ -192,7 +193,7 @@ THREE.Mirror.prototype.updateTextureMatrix = function () {
 
 	this.rotationMatrix.extractRotation( this.camera.matrixWorld );
 
-	this.lookAtPosition.set(0, 0, -1);
+	this.lookAtPosition.set( 0, 0, - 1 );
 	this.lookAtPosition.applyMatrix4( this.rotationMatrix );
 	this.lookAtPosition.add( this.cameraWorldPosition );
 
@@ -200,7 +201,7 @@ THREE.Mirror.prototype.updateTextureMatrix = function () {
 	target.reflect( this.normal ).negate();
 	target.add( this.mirrorWorldPosition );
 
-	this.up.set( 0, -1, 0 );
+	this.up.set( 0, - 1, 0 );
 	this.up.applyMatrix4( this.rotationMatrix );
 	this.up.reflect( this.normal ).negate();
 
@@ -230,20 +231,20 @@ THREE.Mirror.prototype.updateTextureMatrix = function () {
 	var q = new THREE.Vector4();
 	var projectionMatrix = this.mirrorCamera.projectionMatrix;
 
-	q.x = ( Math.sign(this.clipPlane.x) + projectionMatrix.elements[8] ) / projectionMatrix.elements[0];
-	q.y = ( Math.sign(this.clipPlane.y) + projectionMatrix.elements[9] ) / projectionMatrix.elements[5];
+	q.x = ( Math.sign( this.clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
+	q.y = ( Math.sign( this.clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
 	q.z = - 1.0;
-	q.w = ( 1.0 + projectionMatrix.elements[10] ) / projectionMatrix.elements[14];
+	q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ];
 
 	// Calculate the scaled plane vector
 	var c = new THREE.Vector4();
-	c = this.clipPlane.multiplyScalar( 2.0 / this.clipPlane.dot(q) );
+	c = this.clipPlane.multiplyScalar( 2.0 / this.clipPlane.dot( q ) );
 
 	// Replacing the third row of the projection matrix
-	projectionMatrix.elements[2] = c.x;
-	projectionMatrix.elements[6] = c.y;
-	projectionMatrix.elements[10] = c.z + 1.0 - this.clipBias;
-	projectionMatrix.elements[14] = c.w;
+	projectionMatrix.elements[ 2 ] = c.x;
+	projectionMatrix.elements[ 6 ] = c.y;
+	projectionMatrix.elements[ 10 ] = c.z + 1.0 - this.clipBias;
+	projectionMatrix.elements[ 14 ] = c.w;
 
 };
 
@@ -262,7 +263,7 @@ THREE.Mirror.prototype.render = function () {
 
 	}
 
-	if ( scene !== undefined && scene instanceof THREE.Scene) {
+	if ( scene !== undefined && scene instanceof THREE.Scene ) {
 
 		// We can't render ourself to ourself
 		var visible = this.material.visible;
@@ -291,7 +292,7 @@ THREE.Mirror.prototype.renderTemp = function () {
 
 	}
 
-	if ( scene !== undefined && scene instanceof THREE.Scene) {
+	if ( scene !== undefined && scene instanceof THREE.Scene ) {
 
 		this.renderer.render( scene, this.mirrorCamera, this.tempTexture, true );
 

+ 143 - 104
examples/js/Ocean.js

@@ -1,4 +1,5 @@
-THREE.Ocean = function (renderer, camera, scene, options) {
+THREE.Ocean = function ( renderer, camera, scene, options ) {
+
 	// flag used to trigger parameter changes
 	this.changed = true;
 	this.initial = true;
@@ -12,36 +13,38 @@
 	this.scene = new THREE.Scene();
 	
 	// Enable necessary extensions
-	this.renderer.context.getExtension('OES_texture_float');
-	this.renderer.context.getExtension('OES_texture_float_linear');
+	this.renderer.context.getExtension( 'OES_texture_float' );
+	this.renderer.context.getExtension( 'OES_texture_float_linear' );
 	
 	// Assign optional parameters as variables and object properties
-	function optionalParameter(value, defaultValue) {
+	function optionalParameter( value, defaultValue ) {
+
 		return value !== undefined ? value : defaultValue;
+
 	}
 	options = options || {};
-	this.clearColor = optionalParameter(options.CLEAR_COLOR, [ 1.0, 1.0, 1.0, 0.0 ]);
-	this.geometryOrigin = optionalParameter(options.GEOMETRY_ORIGIN, [ -1000.0, -1000.0 ]);
-	this.sunDirectionX = optionalParameter(options.SUN_DIRECTION[0], -1.0);
-	this.sunDirectionY = optionalParameter(options.SUN_DIRECTION[1], 1.0);
-	this.sunDirectionZ = optionalParameter(options.SUN_DIRECTION[2], 1.0);
-	this.oceanColor = optionalParameter(options.OCEAN_COLOR, new THREE.Vector3(0.004, 0.016, 0.047));
-	this.skyColor = optionalParameter(options.SKY_COLOR, new THREE.Vector3(3.2, 9.6, 12.8));
-	this.exposure = optionalParameter(options.EXPOSURE, 0.35);
-	this.geometryResolution = optionalParameter(options.GEOMETRY_RESOLUTION, 32);
-	this.geometrySize = optionalParameter(options.GEOMETRY_SIZE, 2000);
-	this.resolution = optionalParameter(options.RESOLUTION, 64);
-	this.floatSize = optionalParameter(options.SIZE_OF_FLOAT, 4);
-	this.windX = optionalParameter(options.INITIAL_WIND[0], 10.0),
-	this.windY = optionalParameter(options.INITIAL_WIND[1], 10.0),
-	this.size = optionalParameter(options.INITIAL_SIZE, 250.0),
-	this.choppiness = optionalParameter(options.INITIAL_CHOPPINESS, 1.5);
+	this.clearColor = optionalParameter( options.CLEAR_COLOR, [ 1.0, 1.0, 1.0, 0.0 ] );
+	this.geometryOrigin = optionalParameter( options.GEOMETRY_ORIGIN, [ - 1000.0, - 1000.0 ] );
+	this.sunDirectionX = optionalParameter( options.SUN_DIRECTION[ 0 ], - 1.0 );
+	this.sunDirectionY = optionalParameter( options.SUN_DIRECTION[ 1 ], 1.0 );
+	this.sunDirectionZ = optionalParameter( options.SUN_DIRECTION[ 2 ], 1.0 );
+	this.oceanColor = optionalParameter( options.OCEAN_COLOR, new THREE.Vector3( 0.004, 0.016, 0.047 ) );
+	this.skyColor = optionalParameter( options.SKY_COLOR, new THREE.Vector3( 3.2, 9.6, 12.8 ) );
+	this.exposure = optionalParameter( options.EXPOSURE, 0.35 );
+	this.geometryResolution = optionalParameter( options.GEOMETRY_RESOLUTION, 32 );
+	this.geometrySize = optionalParameter( options.GEOMETRY_SIZE, 2000 );
+	this.resolution = optionalParameter( options.RESOLUTION, 64 );
+	this.floatSize = optionalParameter( options.SIZE_OF_FLOAT, 4 );
+	this.windX = optionalParameter( options.INITIAL_WIND[ 0 ], 10.0 ),
+	this.windY = optionalParameter( options.INITIAL_WIND[ 1 ], 10.0 ),
+	this.size = optionalParameter( options.INITIAL_SIZE, 250.0 ),
+	this.choppiness = optionalParameter( options.INITIAL_CHOPPINESS, 1.5 );
 	
 	// 
 	this.matrixNeedsUpdate = false;
 	
 	// Setup framebuffer pipeline
-	var renderTargetType = optionalParameter(options.USE_HALF_FLOAT, false) ? THREE.HalfFloatType : THREE.FloatType;
+	var renderTargetType = optionalParameter( options.USE_HALF_FLOAT, false ) ? THREE.HalfFloatType : THREE.FloatType;
 	var LinearClampParams = {
 		minFilter: THREE.LinearFilter,
 		magFilter: THREE.LinearFilter,
@@ -61,7 +64,7 @@
 		format: THREE.RGBAFormat,
 		stencilBuffer: false,
 		depthBuffer: false,
-		premultiplyAlpha:false,
+		premultiplyAlpha: false,
 		type: renderTargetType
 	};
 	var NearestRepeatParams = {
@@ -75,104 +78,104 @@
 		premultiplyAlpha: false,
 		type: renderTargetType
 	};
-	this.initialSpectrumFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, NearestRepeatParams);
-	this.spectrumFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, NearestClampParams);
-	this.pingPhaseFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, NearestClampParams);
-	this.pongPhaseFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, NearestClampParams);
-	this.pingTransformFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, NearestClampParams);
-	this.pongTransformFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, NearestClampParams);
-	this.displacementMapFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, LinearClampParams);
-	this.normalMapFramebuffer = new THREE.WebGLRenderTarget(this.resolution, this.resolution, LinearClampParams);
+	this.initialSpectrumFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestRepeatParams );
+	this.spectrumFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
+	this.pingPhaseFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
+	this.pongPhaseFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
+	this.pingTransformFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
+	this.pongTransformFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
+	this.displacementMapFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, LinearClampParams );
+	this.normalMapFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, LinearClampParams );
 	
 	// Define shaders and constant uniforms
 	////////////////////////////////////////
 	
 	// 0 - The vertex shader used in all of the simulation steps
-	var fullscreeenVertexShader = THREE.ShaderLib["ocean_sim_vertex"];
+	var fullscreeenVertexShader = THREE.ShaderLib[ "ocean_sim_vertex" ];
 		
 	// 1 - Horizontal wave vertices used for FFT
-	var oceanHorizontalShader = THREE.ShaderLib["ocean_subtransform"];
-	var oceanHorizontalUniforms = THREE.UniformsUtils.clone(oceanHorizontalShader.uniforms);
-	this.materialOceanHorizontal = new THREE.ShaderMaterial({
+	var oceanHorizontalShader = THREE.ShaderLib[ "ocean_subtransform" ];
+	var oceanHorizontalUniforms = THREE.UniformsUtils.clone( oceanHorizontalShader.uniforms );
+	this.materialOceanHorizontal = new THREE.ShaderMaterial( {
 		uniforms: oceanHorizontalUniforms,
 		vertexShader: fullscreeenVertexShader.vertexShader,
 		fragmentShader: "#define HORIZONTAL \n" + oceanHorizontalShader.fragmentShader
-	});
+	} );
 	this.materialOceanHorizontal.uniforms.u_transformSize = { type: "f", value: this.resolution };
 	this.materialOceanHorizontal.uniforms.u_subtransformSize = { type: "f", value: null };
 	this.materialOceanHorizontal.uniforms.u_input = { type: "t", value: null };
 	this.materialOceanHorizontal.depthTest = false;
 	
 	// 2 - Vertical wave vertices used for FFT
-	var oceanVerticalShader = THREE.ShaderLib["ocean_subtransform"];
-	var oceanVerticalUniforms = THREE.UniformsUtils.clone(oceanVerticalShader.uniforms);
-	this.materialOceanVertical = new THREE.ShaderMaterial({
+	var oceanVerticalShader = THREE.ShaderLib[ "ocean_subtransform" ];
+	var oceanVerticalUniforms = THREE.UniformsUtils.clone( oceanVerticalShader.uniforms );
+	this.materialOceanVertical = new THREE.ShaderMaterial( {
 		uniforms: oceanVerticalUniforms,
 		vertexShader: fullscreeenVertexShader.vertexShader,
 		fragmentShader: oceanVerticalShader.fragmentShader
-	});
+	} );
 	this.materialOceanVertical.uniforms.u_transformSize = { type: "f", value: this.resolution };
 	this.materialOceanVertical.uniforms.u_subtransformSize = { type: "f", value: null };
 	this.materialOceanVertical.uniforms.u_input = { type: "t", value: null };
 	this.materialOceanVertical.depthTest = false;
 	
 	// 3 - Initial spectrum used to generate height map
-	var initialSpectrumShader = THREE.ShaderLib["ocean_initial_spectrum"];
-	var initialSpectrumUniforms = THREE.UniformsUtils.clone(initialSpectrumShader.uniforms);
-	this.materialInitialSpectrum = new THREE.ShaderMaterial({
+	var initialSpectrumShader = THREE.ShaderLib[ "ocean_initial_spectrum" ];
+	var initialSpectrumUniforms = THREE.UniformsUtils.clone( initialSpectrumShader.uniforms );
+	this.materialInitialSpectrum = new THREE.ShaderMaterial( {
 		uniforms: initialSpectrumUniforms,
 		vertexShader: fullscreeenVertexShader.vertexShader,
-		fragmentShader:initialSpectrumShader.fragmentShader
-	});
+		fragmentShader: initialSpectrumShader.fragmentShader
+	} );
 	this.materialInitialSpectrum.uniforms.u_wind = { type: "v2", value: new THREE.Vector2() };
 	this.materialInitialSpectrum.uniforms.u_resolution = { type: "f", value: this.resolution };
 	this.materialInitialSpectrum.depthTest = false;
 	
 	// 4 - Phases used to animate heightmap
-	var phaseShader = THREE.ShaderLib["ocean_phase"];
-	var phaseUniforms = THREE.UniformsUtils.clone(phaseShader.uniforms);
-	this.materialPhase = new THREE.ShaderMaterial({
+	var phaseShader = THREE.ShaderLib[ "ocean_phase" ];
+	var phaseUniforms = THREE.UniformsUtils.clone( phaseShader.uniforms );
+	this.materialPhase = new THREE.ShaderMaterial( {
 		uniforms: phaseUniforms,
 		vertexShader: fullscreeenVertexShader.vertexShader,
 		fragmentShader: phaseShader.fragmentShader
-	});
+	} );
 	this.materialPhase.uniforms.u_resolution = { type: "f", value: this.resolution };
 	this.materialPhase.depthTest = false;
 	
 	// 5 - Shader used to update spectrum
-	var spectrumShader = THREE.ShaderLib["ocean_spectrum"];
-	var spectrumUniforms = THREE.UniformsUtils.clone(spectrumShader.uniforms);
-	this.materialSpectrum = new THREE.ShaderMaterial({
+	var spectrumShader = THREE.ShaderLib[ "ocean_spectrum" ];
+	var spectrumUniforms = THREE.UniformsUtils.clone( spectrumShader.uniforms );
+	this.materialSpectrum = new THREE.ShaderMaterial( {
 		uniforms: spectrumUniforms,
 		vertexShader: fullscreeenVertexShader.vertexShader,
 		fragmentShader: spectrumShader.fragmentShader
-	});
+	} );
 	this.materialSpectrum.uniforms.u_initialSpectrum = { type: "t", value: null };
 	this.materialSpectrum.uniforms.u_resolution = { type: "f", value: this.resolution };
 	this.materialSpectrum.depthTest = false;
 
 	// 6 - Shader used to update spectrum normals
-	var normalShader = THREE.ShaderLib["ocean_normals"];
-	var normalUniforms = THREE.UniformsUtils.clone(normalShader.uniforms);
-	this.materialNormal = new THREE.ShaderMaterial({
+	var normalShader = THREE.ShaderLib[ "ocean_normals" ];
+	var normalUniforms = THREE.UniformsUtils.clone( normalShader.uniforms );
+	this.materialNormal = new THREE.ShaderMaterial( {
 		uniforms: normalUniforms,
 		vertexShader: fullscreeenVertexShader.vertexShader,
 		fragmentShader: normalShader.fragmentShader
-	});
+	} );
 	this.materialNormal.uniforms.u_displacementMap = { type: "t", value: null };
 	this.materialNormal.uniforms.u_resolution = { type: "f", value: this.resolution };
 	this.materialNormal.depthTest = false;
 
 	// 7 - Shader used to update normals
-	var oceanShader = THREE.ShaderLib["ocean_main"];
-	var oceanUniforms = THREE.UniformsUtils.clone(oceanShader.uniforms);
-	var oceanAttributes = THREE.UniformsUtils.clone(oceanShader.attributes);
-	this.materialOcean = new THREE.ShaderMaterial({
+	var oceanShader = THREE.ShaderLib[ "ocean_main" ];
+	var oceanUniforms = THREE.UniformsUtils.clone( oceanShader.uniforms );
+	var oceanAttributes = THREE.UniformsUtils.clone( oceanShader.attributes );
+	this.materialOcean = new THREE.ShaderMaterial( {
 		attributes: oceanAttributes,
 		uniforms: oceanUniforms,
 		vertexShader: oceanShader.vertexShader,
 		fragmentShader: oceanShader.fragmentShader
-	});
+	} );
 	// this.materialOcean.wireframe = true;
 	this.materialOcean.uniforms.u_geometrySize = { type: "f", value: this.resolution };
 	this.materialOcean.uniforms.u_displacementMap = { type: "t", value: this.displacementMapFramebuffer };
@@ -193,13 +196,14 @@
 
 	// Create the simulation plane
 	this.screenQuad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ) );
-	this.scene.add(this.screenQuad);
+	this.scene.add( this.screenQuad );
 
 	// Initialise spectrum data
 	this.generateSeedPhaseTexture();
 
 	// Generate the ocean mesh
 	this.generateMesh();
+
 };
 
 THREE.Ocean.prototype.generateMesh = function () {
@@ -209,12 +213,14 @@ THREE.Ocean.prototype.generateMesh = function () {
 	geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
 
 	this.oceanMesh = new THREE.Mesh( geometry, this.materialOcean );
+
 };
 
 THREE.Ocean.prototype.render = function () {
+
 	this.scene.overrideMaterial = null;
 	
-	if (this.changed)
+	if ( this.changed )
 		this.renderInitialSpectrum();
 	
 	this.renderWavePhase();
@@ -222,107 +228,140 @@ THREE.Ocean.prototype.render = function () {
 	this.renderSpectrumFFT();
 	this.renderNormalMap();
 	this.scene.overrideMaterial = null;
+
 };
 
 THREE.Ocean.prototype.generateSeedPhaseTexture = function() {
+
 	// Setup the seed texture
 	this.pingPhase = true;
-	var phaseArray = new window.Float32Array(this.resolution * this.resolution * 4);
-	for (var i = 0; i < this.resolution; i ++) {
-		for (var j = 0; j < this.resolution; j ++) {
-			phaseArray[i * this.resolution * 4 + j * 4] =  Math.random() * 2.0 * Math.PI;
-			phaseArray[i * this.resolution * 4 + j * 4 + 1] = 0.0;
-			phaseArray[i * this.resolution * 4 + j * 4 + 2] = 0.0;
-			phaseArray[i * this.resolution * 4 + j * 4 + 3] = 0.0;
+	var phaseArray = new window.Float32Array( this.resolution * this.resolution * 4 );
+	for ( var i = 0; i < this.resolution; i ++ ) {
+
+		for ( var j = 0; j < this.resolution; j ++ ) {
+
+			phaseArray[ i * this.resolution * 4 + j * 4 ] =  Math.random() * 2.0 * Math.PI;
+			phaseArray[ i * this.resolution * 4 + j * 4 + 1 ] = 0.0;
+			phaseArray[ i * this.resolution * 4 + j * 4 + 2 ] = 0.0;
+			phaseArray[ i * this.resolution * 4 + j * 4 + 3 ] = 0.0;
+
 		}
+
 	}
 	
-	this.pingPhaseTexture = new THREE.DataTexture(phaseArray, this.resolution, this.resolution, THREE.RGBAFormat);
+	this.pingPhaseTexture = new THREE.DataTexture( phaseArray, this.resolution, this.resolution, THREE.RGBAFormat );
 	this.pingPhaseTexture.minFilter = THREE.NearestFilter;
 	this.pingPhaseTexture.magFilter = THREE.NearestFilter;
 	this.pingPhaseTexture.wrapS = THREE.ClampToEdgeWrapping;
 	this.pingPhaseTexture.wrapT = THREE.ClampToEdgeWrapping;
 	this.pingPhaseTexture.type = THREE.FloatType;
 	this.pingPhaseTexture.needsUpdate = true;
+
 };
 
 THREE.Ocean.prototype.renderInitialSpectrum = function () {
+
 	this.scene.overrideMaterial = this.materialInitialSpectrum;
 	this.materialInitialSpectrum.uniforms.u_wind.value.set( this.windX, this.windY );
 	this.materialInitialSpectrum.uniforms.u_size.value = this.size;
-	this.renderer.render(this.scene, this.oceanCamera, this.initialSpectrumFramebuffer, true);
+	this.renderer.render( this.scene, this.oceanCamera, this.initialSpectrumFramebuffer, true );
+
 };
 
 THREE.Ocean.prototype.renderWavePhase = function () {
+
 	this.scene.overrideMaterial = this.materialPhase;
 	this.screenQuad.material = this.materialPhase;
-	if (this.initial) {
+	if ( this.initial ) {
+
 		this.materialPhase.uniforms.u_phases.value = this.pingPhaseTexture;
 		this.initial = false;
+
 	}else {
+
 		this.materialPhase.uniforms.u_phases.value = this.pingPhase ? this.pingPhaseFramebuffer  : this.pongPhaseFramebuffer;
+
 	}
 	this.materialPhase.uniforms.u_deltaTime.value = this.deltaTime;
 	this.materialPhase.uniforms.u_size.value = this.size;
-	this.renderer.render(this.scene, this.oceanCamera, this.pingPhase ? this.pongPhaseFramebuffer : this.pingPhaseFramebuffer);
-	this.pingPhase = !this.pingPhase;
+	this.renderer.render( this.scene, this.oceanCamera, this.pingPhase ? this.pongPhaseFramebuffer : this.pingPhaseFramebuffer );
+	this.pingPhase = ! this.pingPhase;
+
 };
 
 THREE.Ocean.prototype.renderSpectrum = function () {
+
 	this.scene.overrideMaterial = this.materialSpectrum;
 	this.materialSpectrum.uniforms.u_initialSpectrum.value = this.initialSpectrumFramebuffer;
 	this.materialSpectrum.uniforms.u_phases.value = this.pingPhase ? this.pingPhaseFramebuffer : this.pongPhaseFramebuffer;
 	this.materialSpectrum.uniforms.u_choppiness.value = this.choppiness ;
 	this.materialSpectrum.uniforms.u_size.value = this.size ;
-	this.renderer.render(this.scene, this.oceanCamera, this.spectrumFramebuffer);
+	this.renderer.render( this.scene, this.oceanCamera, this.spectrumFramebuffer );
+
 };
 
 THREE.Ocean.prototype.renderSpectrumFFT = function() {
+
 	// GPU FFT using Stockham formulation
-	var iterations = Math.log( this.resolution ) / Math.log(2); // log2
+	var iterations = Math.log( this.resolution ) / Math.log( 2 ); // log2
 	
 	this.scene.overrideMaterial = this.materialOceanHorizontal;
 
-	for (var i = 0; i < iterations; i ++) {
-		if (i === 0) {
+	for ( var i = 0; i < iterations; i ++ ) {
+
+		if ( i === 0 ) {
+
 			this.materialOceanHorizontal.uniforms.u_input.value = this.spectrumFramebuffer;
-			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow(2, (i % (iterations)) + 1);
-			this.renderer.render(this.scene, this.oceanCamera, this.pingTransformFramebuffer);
-		} 
-		else if (i % 2 === 1) {
+			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
+			this.renderer.render( this.scene, this.oceanCamera, this.pingTransformFramebuffer );
+
+		} else if ( i % 2 === 1 ) {
+
 			this.materialOceanHorizontal.uniforms.u_input.value = this.pingTransformFramebuffer;
-			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow(2, (i % (iterations)) + 1);
-			this.renderer.render(this.scene, this.oceanCamera, this.pongTransformFramebuffer);
-		}
-		else {
+			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
+			this.renderer.render( this.scene, this.oceanCamera, this.pongTransformFramebuffer );
+
+		} else {
+
 			this.materialOceanHorizontal.uniforms.u_input.value = this.pongTransformFramebuffer;
-			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow(2, (i % (iterations)) + 1);
-			this.renderer.render(this.scene, this.oceanCamera, this.pingTransformFramebuffer);
+			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
+			this.renderer.render( this.scene, this.oceanCamera, this.pingTransformFramebuffer );
+
 		}
+
 	}
 	this.scene.overrideMaterial = this.materialOceanVertical;
-	for (var i = iterations; i < iterations * 2; i ++) {
-		if (i === iterations * 2 - 1) {
-			this.materialOceanVertical.uniforms.u_input.value = (iterations % 2 === 0) ? this.pingTransformFramebuffer : this.pongTransformFramebuffer;
-			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow(2, (i % (iterations)) + 1);
-			this.renderer.render(this.scene, this.oceanCamera, this.displacementMapFramebuffer);
-		}
-		else if (i % 2 === 1) {
+	for ( var i = iterations; i < iterations * 2; i ++ ) {
+
+		if ( i === iterations * 2 - 1 ) {
+
+			this.materialOceanVertical.uniforms.u_input.value = ( iterations % 2 === 0 ) ? this.pingTransformFramebuffer : this.pongTransformFramebuffer;
+			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
+			this.renderer.render( this.scene, this.oceanCamera, this.displacementMapFramebuffer );
+
+		} else if ( i % 2 === 1 ) {
+
 			this.materialOceanVertical.uniforms.u_input.value = this.pingTransformFramebuffer;
-			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow(2, (i % (iterations)) + 1);
-			this.renderer.render(this.scene, this.oceanCamera, this.pongTransformFramebuffer);
-		}
-		else {
+			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
+			this.renderer.render( this.scene, this.oceanCamera, this.pongTransformFramebuffer );
+
+		} else {
+
 			this.materialOceanVertical.uniforms.u_input.value = this.pongTransformFramebuffer;
-			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow(2, (i % (iterations)) + 1);
-			this.renderer.render(this.scene, this.oceanCamera, this.pingTransformFramebuffer);
+			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
+			this.renderer.render( this.scene, this.oceanCamera, this.pingTransformFramebuffer );
+
 		}
+
 	}
+
 };
 
 THREE.Ocean.prototype.renderNormalMap = function () {
+
 	this.scene.overrideMaterial = this.materialNormal;
-	if (this.changed) this.materialNormal.uniforms.u_size.value = this.size;
+	if ( this.changed ) this.materialNormal.uniforms.u_size.value = this.size;
 	this.materialNormal.uniforms.u_displacementMap.value = this.displacementMapFramebuffer;
-	this.renderer.render(this.scene, this.oceanCamera, this.normalMapFramebuffer, true);
+	this.renderer.render( this.scene, this.oceanCamera, this.normalMapFramebuffer, true );
+
 };

+ 69 - 46
examples/js/Octree.js

@@ -7,7 +7,9 @@
  * based on Dynamic Octree by Piko3D @ http://www.piko3d.com/ and Octree by Marek Pawlowski @ pawlowski.it
  *
  */
- ( function ( THREE ) { "use strict";
+ ( function ( THREE ) {
+
+	"use strict";
 	
 	/*===================================================
 
@@ -16,15 +18,21 @@
 	=====================================================*/
 	
 	function isNumber ( n ) {
-		return !isNaN( n ) && isFinite( n );
+
+		return ! isNaN( n ) && isFinite( n );
+
 	}
 	
 	function isArray ( target ) {
+
 		return Object.prototype.toString.call( target ) === '[object Array]';
+
 	}
 	
 	function toArray ( target ) {
+
 		return target ? ( isArray ( target ) !== true ? [ target ] : target ) : [];
+
 	}
 	
 	function indexOfValue( array, value ) {
@@ -39,7 +47,7 @@
 			
 		}
 		
-		return -1;
+		return - 1;
 		
 	}
 	
@@ -55,7 +63,7 @@
 			
 		}
 		
-		return -1;
+		return - 1;
 		
 	}
 
@@ -77,7 +85,7 @@
 		
 		this.nodeCount = 0;
 		
-		this.INDEX_INSIDE_CROSS = -1;
+		this.INDEX_INSIDE_CROSS = - 1;
 		this.INDEX_OUTSIDE_OFFSET = 2;
 		
 		this.INDEX_OUTSIDE_POS_X = isNumber( parameters.INDEX_OUTSIDE_POS_X ) ? parameters.INDEX_OUTSIDE_POS_X : 0;
@@ -89,11 +97,11 @@
 		
 		this.INDEX_OUTSIDE_MAP = [];
 		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_X ] = { index: this.INDEX_OUTSIDE_POS_X, count: 0, x: 1, y: 0, z: 0 };
-		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_X ] = { index: this.INDEX_OUTSIDE_NEG_X, count: 0, x: -1, y: 0, z: 0 };
+		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_X ] = { index: this.INDEX_OUTSIDE_NEG_X, count: 0, x: - 1, y: 0, z: 0 };
 		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_Y ] = { index: this.INDEX_OUTSIDE_POS_Y, count: 0, x: 0, y: 1, z: 0 };
-		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Y ] = { index: this.INDEX_OUTSIDE_NEG_Y, count: 0, x: 0, y: -1, z: 0 };
+		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Y ] = { index: this.INDEX_OUTSIDE_NEG_Y, count: 0, x: 0, y: - 1, z: 0 };
 		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_Z ] = { index: this.INDEX_OUTSIDE_POS_Z, count: 0, x: 0, y: 0, z: 1 };
-		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Z ] = { index: this.INDEX_OUTSIDE_NEG_Z, count: 0, x: 0, y: 0, z: -1 };
+		this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Z ] = { index: this.INDEX_OUTSIDE_NEG_Z, count: 0, x: 0, y: 0, z: - 1 };
 		
 		this.FLAG_POS_X = 1 << ( this.INDEX_OUTSIDE_POS_X + 1 );
 		this.FLAG_NEG_X = 1 << ( this.INDEX_OUTSIDE_NEG_X + 1 );
@@ -194,13 +202,13 @@
 			
 			// check uuid to avoid duplicates
 			
-			if ( !object.uuid ) {
+			if ( ! object.uuid ) {
 				
 				object.uuid = THREE.Math.generateUUID();
 				
 			}
 			
-			if ( !this.objectsMap[ object.uuid ] ) {
+			if ( ! this.objectsMap[ object.uuid ] ) {
 				
 				// store
 				
@@ -287,7 +295,7 @@
 				
 				index = indexOfValue( this.objects, object );
 				
-				if ( index !== -1 ) {
+				if ( index !== - 1 ) {
 					
 					this.objects.splice( index, 1 );
 					
@@ -303,7 +311,7 @@
 						
 						index = indexOfValue( this.objectsData, objectData );
 						
-						if ( index !== -1 ) {
+						if ( index !== - 1 ) {
 							
 							this.objectsData.splice( index, 1 );
 							
@@ -319,7 +327,7 @@
 				
 				index = indexOfPropertyWithValue( this.objectsDeferred, 'object', object );
 				
-				if ( index !== -1 ) {
+				if ( index !== - 1 ) {
 					
 					this.objectsDeferred.splice( index, 1 );
 					
@@ -378,7 +386,7 @@
 				
 				// if position has changed since last organization of object in tree
 				
-				if ( node instanceof THREE.OctreeNode && !objectData.positionLast.equals( objectData.position ) ) {
+				if ( node instanceof THREE.OctreeNode && ! objectData.positionLast.equals( objectData.position ) ) {
 					
 					// get octant index of object within current node
 					
@@ -477,7 +485,7 @@
 			
 			// ensure radius (i.e. distance of ray) is a number
 			
-			if ( !( radius > 0 ) ) {
+			if ( ! ( radius > 0 ) ) {
 				
 				radius = Number.MAX_VALUE;
 				
@@ -520,7 +528,7 @@
 					
 					// if needed, create new result data
 					
-					if ( resultObjectIndex === -1 ) {
+					if ( resultObjectIndex === - 1 ) {
 						
 						resultData = {
 							object: object,
@@ -860,7 +868,7 @@
 			
 			node.indexOctant = indexOctant;
 			
-			if ( indexOfValue( this.nodesIndices, indexOctant ) === -1 ) {
+			if ( indexOfValue( this.nodesIndices, indexOctant ) === - 1 ) {
 				
 				this.nodesIndices.push( indexOctant );
 				
@@ -908,13 +916,13 @@
 			indexOctant = this.getOctantIndex( object );
 			
 			// if object fully contained by an octant, add to subtree
-			if ( indexOctant > -1 && this.nodesIndices.length > 0 ) {
+			if ( indexOctant > - 1 && this.nodesIndices.length > 0 ) {
 				
 				node = this.branch( indexOctant );
 				
 				node.addObject( object );
 				
-			} else if ( indexOctant < -1 && this.parent instanceof THREE.OctreeNode ) {
+			} else if ( indexOctant < - 1 && this.parent instanceof THREE.OctreeNode ) {
 				
 				// if object lies outside bounds, add to parent node
 				
@@ -926,7 +934,7 @@
 				
 				index = indexOfValue( this.objects, object );
 				
-				if ( index === -1 ) {
+				if ( index === - 1 ) {
 					
 					this.objects.push( object );
 					
@@ -992,7 +1000,7 @@
 		removeObjectRecursive: function ( object, removeData ) {
 			
 			var i, l,
-				index = -1,
+				index = - 1,
 				objectData,
 				node,
 				objectRemoved;
@@ -1006,7 +1014,7 @@
 				
 				index = indexOfValue( this.objects, object );
 				
-				if ( index !== -1 ) {
+				if ( index !== - 1 ) {
 					
 					this.objects.splice( index, 1 );
 					object.node = undefined;
@@ -1034,7 +1042,7 @@
 						
 						objectRemoved = true;
 						
-						if ( !objectData.faces && !objectData.vertices ) {
+						if ( ! objectData.faces && ! objectData.vertices ) {
 							
 							removeData.searchComplete = true;
 							break;
@@ -1115,12 +1123,12 @@
 				indexOctant = this.getOctantIndex( object );
 				
 				// if lies within octant
-				if ( indexOctant > -1 ) {
+				if ( indexOctant > - 1 ) {
 					
 					objectsSplit.push( object );
 					objectsSplitOctants.push( indexOctant );
 				
-				} else if ( indexOctant < -1 ) {
+				} else if ( indexOctant < - 1 ) {
 					
 					// lies outside radius
 					
@@ -1139,7 +1147,7 @@
 			
 			// if has objects to split
 			
-			if ( objectsSplit.length > 0) {
+			if ( objectsSplit.length > 0 ) {
 				
 				objectsRemaining = objectsRemaining.concat( this.split( objectsSplit, objectsSplitOctants ) );
 				
@@ -1147,7 +1155,7 @@
 			
 			// if has objects to expand
 			
-			if ( objectsExpand.length > 0) {
+			if ( objectsExpand.length > 0 ) {
 				
 				objectsRemaining = objectsRemaining.concat( this.expand( objectsExpand, objectsExpandOctants ) );
 				
@@ -1193,7 +1201,7 @@
 					
 					// if object contained by octant, branch this tree
 					
-					if ( indexOctant > -1 ) {
+					if ( indexOctant > - 1 ) {
 						
 						node = this.branch( indexOctant );
 						
@@ -1247,7 +1255,7 @@
 				radius = ( this.radiusOverlap ) * 0.5;
 				overlap = radius * this.tree.overlapPct;
 				radiusOffset = radius - overlap;
-				offset = this.utilVec31Branch.set( indexOctant & 1 ? radiusOffset : -radiusOffset, indexOctant & 2 ? radiusOffset : -radiusOffset, indexOctant & 4 ? radiusOffset : -radiusOffset );
+				offset = this.utilVec31Branch.set( indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset );
 				position = new THREE.Vector3().addVectors( this.position, offset );
 				
 				// node
@@ -1332,11 +1340,11 @@
 					
 					// if object outside this, include in calculations
 					
-					if ( indexOctant < -1 ) {
+					if ( indexOctant < - 1 ) {
 						
 						// convert octant index to outside flags
 						
-						flagsOutside = -indexOctant - this.tree.INDEX_OUTSIDE_OFFSET;
+						flagsOutside = - indexOctant - this.tree.INDEX_OUTSIDE_OFFSET;
 						
 						// check against bitwise flags
 						
@@ -1438,7 +1446,7 @@
 					// get this octant indices based on octant normal
 					
 					indexOctant = this.getOctantIndexFromPosition( octantX, octantY, octantZ );
-					indexOctantInverse = this.getOctantIndexFromPosition( -octantX, -octantY, -octantZ );
+					indexOctantInverse = this.getOctantIndexFromPosition( - octantX, - octantY, - octantZ );
 					
 					// properties
 					
@@ -1453,7 +1461,7 @@
 					// parent offset is difference between radius + overlap of parent and child
 					
 					radiusOffset = ( radiusParent + overlapParent ) - ( radius + overlap );
-					offset.set( indexOctant & 1 ? radiusOffset : -radiusOffset, indexOctant & 2 ? radiusOffset : -radiusOffset, indexOctant & 4 ? radiusOffset : -radiusOffset );
+					offset.set( indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset );
 					position = new THREE.Vector3().addVectors( this.position, offset );
 					
 					// parent
@@ -1735,7 +1743,7 @@
 					
 				}
 				
-				objectData.indexOctant = -indexOctant - this.tree.INDEX_OUTSIDE_OFFSET;
+				objectData.indexOctant = - indexOctant - this.tree.INDEX_OUTSIDE_OFFSET;
 				
 				return objectData.indexOctant;
 				
@@ -1743,13 +1751,13 @@
 			
 			// return octant index from delta xyz
 			
-			if ( deltaX - radiusObj > -overlap ) {
+			if ( deltaX - radiusObj > - overlap ) {
 				
 				// x right
 				
 				indexOctant = indexOctant | 1;
 				
-			} else if ( !( deltaX + radiusObj < overlap ) ) {
+			} else if ( ! ( deltaX + radiusObj < overlap ) ) {
 				
 				// x left
 				
@@ -1758,13 +1766,13 @@
 				
 			}
 			
-			if ( deltaY - radiusObj > -overlap ) {
+			if ( deltaY - radiusObj > - overlap ) {
 				
 				// y right
 				
 				indexOctant = indexOctant | 2;
 				
-			} else if ( !( deltaY + radiusObj < overlap ) ) {
+			} else if ( ! ( deltaY + radiusObj < overlap ) ) {
 				
 				// y left
 				
@@ -1774,13 +1782,13 @@
 			}
 			
 			
-			if ( deltaZ - radiusObj > -overlap ) {
+			if ( deltaZ - radiusObj > - overlap ) {
 				
 				// z right
 				
 				indexOctant = indexOctant | 4;
 				
-			} else if ( !( deltaZ + radiusObj < overlap ) ) {
+			} else if ( ! ( deltaZ + radiusObj < overlap ) ) {
 				
 				// z left
 				
@@ -1870,21 +1878,33 @@
 				pz = position.z;
 			
 			if ( px < this.left ) {
+
 				distance -= Math.pow( px - this.left, 2 );
+
 			} else if ( px > this.right ) {
+
 				distance -= Math.pow( px - this.right, 2 );
+
 			}
 			
 			if ( py < this.bottom ) {
+
 				distance -= Math.pow( py - this.bottom, 2 );
+
 			} else if ( py > this.top ) {
+
 				distance -= Math.pow( py - this.top, 2 );
+
 			}
 			
 			if ( pz < this.back ) {
+
 				distance -= Math.pow( pz - this.back, 2 );
+
 			} else if ( pz > this.front ) {
+
 				distance -= Math.pow( pz - this.front, 2 );
+
 			}
 			
 			return distance >= 0;
@@ -1905,20 +1925,23 @@
 				t4 = ( this.top - origin.y ) * directionPct.y,
 				t5 = ( this.back - origin.z ) * directionPct.z,
 				t6 = ( this.front - origin.z ) * directionPct.z,
-				tmax = Math.min( Math.min( Math.max( t1, t2), Math.max( t3, t4) ), Math.max( t5, t6) ),
+				tmax = Math.min( Math.min( Math.max( t1, t2 ), Math.max( t3, t4 ) ), Math.max( t5, t6 ) ),
 				tmin;
 
 			// ray would intersect in reverse direction, i.e. this is behind ray
-			if (tmax < 0)
-			{
+			if ( tmax < 0 ) {
+
 				return false;
+
 			}
 			
-			tmin = Math.max( Math.max( Math.min( t1, t2), Math.min( t3, t4)), Math.min( t5, t6));
+			tmin = Math.max( Math.max( Math.min( t1, t2 ), Math.min( t3, t4 ) ), Math.min( t5, t6 ) );
 			
 			// if tmin > tmax or tmin > ray distance, ray doesn't intersect AABB
 			if ( tmin > tmax || tmin > distance ) {
+
 				return false;
+
 			}
 			
 			return true;
@@ -1942,7 +1965,7 @@
 				
 			} else {
 
-				depth = !depth || this.depth > depth ? this.depth : depth;
+				depth = ! depth || this.depth > depth ? this.depth : depth;
 
 			}
 
@@ -2111,4 +2134,4 @@
 		
 	};
 
-}( THREE ) );
+}( THREE ) );

+ 15 - 3
examples/js/PRNG.js

@@ -4,8 +4,20 @@
 var PRNG = function () {
 
 	this.seed = 1;
-	this.next = function() { return (this.gen() / 2147483647); };
-	this.nextRange = function(min, max)	{ return min + ((max - min) * this.next()) };
-	this.gen = function() { return this.seed = (this.seed * 16807) % 2147483647; };
+	this.next = function() {
+
+		return ( this.gen() / 2147483647 );
+
+	};
+	this.nextRange = function( min, max )	{
+
+		return min + ( ( max - min ) * this.next() )
+
+	};
+	this.gen = function() {
+
+		return this.seed = ( this.seed * 16807 ) % 2147483647;
+
+	};
 
 };

+ 72 - 57
examples/js/ParametricGeometries.js

@@ -8,37 +8,46 @@
 
 THREE.ParametricGeometries = {
 
-	klein: function (v, u) {
+	klein: function ( v, u ) {
+
 		u *= Math.PI;
 		v *= 2 * Math.PI;
 
 		u = u * 2;
 		var x, y, z;
-		if (u < Math.PI) {
-			x = 3 * Math.cos(u) * (1 + Math.sin(u)) + (2 * (1 - Math.cos(u) / 2)) * Math.cos(u) * Math.cos(v);
-			z = -8 * Math.sin(u) - 2 * (1 - Math.cos(u) / 2) * Math.sin(u) * Math.cos(v);
+		if ( u < Math.PI ) {
+
+			x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( u ) * Math.cos( v );
+			z = - 8 * Math.sin( u ) - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( u ) * Math.cos( v );
+
 		} else {
-			x = 3 * Math.cos(u) * (1 + Math.sin(u)) + (2 * (1 - Math.cos(u) / 2)) * Math.cos(v + Math.PI);
-			z = -8 * Math.sin(u);
+
+			x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( v + Math.PI );
+			z = - 8 * Math.sin( u );
+
 		}
 
-		y = -2 * (1 - Math.cos(u) / 2) * Math.sin(v);
+		y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
+
+		return new THREE.Vector3( x, y, z );
 
-		return new THREE.Vector3(x, y, z);
 	},
 
-	plane: function (width, height) {
+	plane: function ( width, height ) {
+
+		return function( u, v ) {
 
-		return function(u, v) {
 			var x = u * width;
 			var y = 0;
 			var z = v * height;
 
-			return new THREE.Vector3(x, y, z);
+			return new THREE.Vector3( x, y, z );
+
 		};
+
 	},
 
-	mobius: function(u, t) {
+	mobius: function( u, t ) {
 
 		// flat mobius strip
 		// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
@@ -48,14 +57,14 @@ THREE.ParametricGeometries = {
 		var x, y, z;
 
 		var a = 2;
-		x = Math.cos(v) * (a + u * Math.cos(v / 2));
-		y = Math.sin(v) * (a + u * Math.cos(v / 2));
-		z = u * Math.sin(v / 2);
-		return new THREE.Vector3(x, y, z);
+		x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
+		y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
+		z = u * Math.sin( v / 2 );
+		return new THREE.Vector3( x, y, z );
 
 	},
 
-	mobius3d: function(u, t) {
+	mobius3d: function( u, t ) {
 
 		// volumetric mobius strip
 		u *= Math.PI;
@@ -65,11 +74,12 @@ THREE.ParametricGeometries = {
 		var phi = u / 2;
 		var major = 2.25, a = 0.125, b = 0.65;
 		var x, y, z;
-		x = a * Math.cos(t) * Math.cos(phi) - b * Math.sin(t) * Math.sin(phi);
-		z = a * Math.cos(t) * Math.sin(phi) + b * Math.sin(t) * Math.cos(phi);
-		y = (major + x) * Math.sin(u);
-		x = (major + x) * Math.cos(u);
-		return new THREE.Vector3(x, y, z);
+		x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
+		z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
+		y = ( major + x ) * Math.sin( u );
+		x = ( major + x ) * Math.cos( u );
+		return new THREE.Vector3( x, y, z );
+
 	}
 
 };
@@ -81,14 +91,14 @@ THREE.ParametricGeometries = {
  *
  *********************************************/
 
-THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segmentsRadius, closed, debug) {
+THREE.ParametricGeometries.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, debug ) {
 
 	this.path = path;
 	this.segments = segments || 64;
 	this.radius = radius || 1;
 	this.segmentsRadius = segmentsRadius || 8;
 	this.closed = closed || false;
-	if (debug) this.debug = new THREE.Object3D();
+	if ( debug ) this.debug = new THREE.Object3D();
 
 
 	var scope = this,
@@ -102,50 +112,52 @@ THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segme
 		cx, cy, pos, pos2 = new THREE.Vector3(),
 		i, j, ip, jp, a, b, c, d, uva, uvb, uvc, uvd;
 
-	var frames = new THREE.TubeGeometry.FrenetFrames(path, segments, closed),
+	var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
 		tangents = frames.tangents,
 		normals = frames.normals,
 		binormals = frames.binormals;
 
-		// proxy internals
+	// proxy internals
 	this.tangents = tangents;
 	this.normals = normals;
 	this.binormals = binormals;
 
 
 
-	var ParametricTube = function(u, v) {
+	var ParametricTube = function( u, v ) {
+
 		v *= 2 * Math.PI;
 
-		i = u * (numpoints - 1);
-		i = Math.floor(i);
+		i = u * ( numpoints - 1 );
+		i = Math.floor( i );
 
-		pos = path.getPointAt(u);
+		pos = path.getPointAt( u );
 
-		tangent = tangents[i];
-		normal = normals[i];
-		binormal = binormals[i];
+		tangent = tangents[ i ];
+		normal = normals[ i ];
+		binormal = binormals[ i ];
 
-		if (scope.debug) {
+		if ( scope.debug ) {
 
-			scope.debug.add(new THREE.ArrowHelper(tangent, pos, radius, 0x0000ff));
-			scope.debug.add(new THREE.ArrowHelper(normal, pos, radius, 0xff0000));
-			scope.debug.add(new THREE.ArrowHelper(binormal, pos, radius, 0x00ff00));
+			scope.debug.add( new THREE.ArrowHelper( tangent, pos, radius, 0x0000ff ) );
+			scope.debug.add( new THREE.ArrowHelper( normal, pos, radius, 0xff0000 ) );
+			scope.debug.add( new THREE.ArrowHelper( binormal, pos, radius, 0x00ff00 ) );
 
 		}
 
-		cx = -scope.radius * Math.cos(v); // TODO: Hack: Negating it so it faces outside.
-		cy = scope.radius * Math.sin(v);
+		cx = - scope.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
+		cy = scope.radius * Math.sin( v );
 
-		pos2.copy(pos);
+		pos2.copy( pos );
 		pos2.x += cx * normal.x + cy * binormal.x;
 		pos2.y += cx * normal.y + cy * binormal.y;
 		pos2.z += cx * normal.z + cy * binormal.z;
 
 		return pos2.clone();
+
 	};
 
-	THREE.ParametricGeometry.call(this, ParametricTube, segments, segmentsRadius);
+	THREE.ParametricGeometry.call( this, ParametricTube, segments, segmentsRadius );
 
 };
 
@@ -176,17 +188,17 @@ THREE.ParametricGeometries.TorusKnotGeometry = function ( radius, tube, segments
 		function() {
 		},
 
-		function(t) {
+		function( t ) {
 
 			t *= Math.PI * 2;
 
 			var r = 0.5;
 
-			var tx = (1 + r * Math.cos(q * t)) * Math.cos(p * t),
-				ty = (1 + r * Math.cos(q * t)) * Math.sin(p * t),
-				tz = r * Math.sin(q * t);
+			var tx = ( 1 + r * Math.cos( q * t ) ) * Math.cos( p * t ),
+				ty = ( 1 + r * Math.cos( q * t ) ) * Math.sin( p * t ),
+				tz = r * Math.sin( q * t );
 
-			return new THREE.Vector3(tx, ty * heightScale, tz).multiplyScalar(radius);
+			return new THREE.Vector3( tx, ty * heightScale, tz ).multiplyScalar( radius );
 
 		}
 
@@ -209,21 +221,23 @@ THREE.ParametricGeometries.TorusKnotGeometry.prototype.constructor = THREE.Param
   * Parametric Replacement for SphereGeometry
   *
   *********************************************/
-THREE.ParametricGeometries.SphereGeometry = function(size, u, v) {
+THREE.ParametricGeometries.SphereGeometry = function( size, u, v ) {
+
+	function sphere( u, v ) {
 
-	function sphere(u, v) {
 		u *= Math.PI;
 		v *= 2 * Math.PI;
 
-		var x = size * Math.sin(u) * Math.cos(v);
-		var y = size * Math.sin(u) * Math.sin(v);
-		var z = size * Math.cos(u);
+		var x = size * Math.sin( u ) * Math.cos( v );
+		var y = size * Math.sin( u ) * Math.sin( v );
+		var z = size * Math.cos( u );
+
 
+		return new THREE.Vector3( x, y, z );
 
-		return new THREE.Vector3(x, y, z);
 	}
 
-	THREE.ParametricGeometry.call(this, sphere, u, v, !true);
+	THREE.ParametricGeometry.call( this, sphere, u, v, ! true );
 
 };
 
@@ -237,18 +251,19 @@ THREE.ParametricGeometries.SphereGeometry.prototype.constructor = THREE.Parametr
   *
   *********************************************/
 
-THREE.ParametricGeometries.PlaneGeometry = function(width, depth, segmentsWidth, segmentsDepth) {
+THREE.ParametricGeometries.PlaneGeometry = function( width, depth, segmentsWidth, segmentsDepth ) {
 
-	function plane(u, v) {
+	function plane( u, v ) {
 
 		var x = u * width;
 		var y = 0;
 		var z = v * depth;
 
-		return new THREE.Vector3(x, y, z);
+		return new THREE.Vector3( x, y, z );
+
 	}
 
-	THREE.ParametricGeometry.call(this, plane, segmentsWidth, segmentsDepth);
+	THREE.ParametricGeometry.call( this, plane, segmentsWidth, segmentsDepth );
 
 };
 

+ 29 - 29
examples/js/ShaderDeferred.js

@@ -23,7 +23,7 @@ THREE.DeferredShaderChunk = {
 
 		"}"
 
-	].join("\n"),
+	].join( "\n" ),
 
 	computeVertexPositionVS: [
 
@@ -41,13 +41,13 @@ THREE.DeferredShaderChunk = {
 		"vertexPositionVS.xyz /= vertexPositionVS.w;",
 		"vertexPositionVS.w = 1.0;"
 
-	].join("\n"),
+	].join( "\n" ),
 
 	computeNormal: [
 
 		"vec3 normal = normalDepth.xyz * 2.0 - 1.0;"
 
-	].join("\n"),
+	].join( "\n" ),
 
 	unpackColorMap: [
 
@@ -59,7 +59,7 @@ THREE.DeferredShaderChunk = {
 		"float wrapAround = sign( colorMap.z );",
 		"float additiveSpecular = sign( colorMap.y );"
 
-	].join("\n"),
+	].join( "\n" ),
 
 	computeDiffuse: [
 
@@ -85,7 +85,7 @@ THREE.DeferredShaderChunk = {
 
 		"}"
 
-	].join("\n"),
+	].join( "\n" ),
 
 	computeSpecular: [
 
@@ -103,14 +103,14 @@ THREE.DeferredShaderChunk = {
 		"vec3 schlick = specularColor + vec3( 1.0 - specularColor ) * pow( 1.0 - dot( lightVector, halfVector ), 5.0 );",
 		"vec3 specular = schlick * max( pow( dotNormalHalf, shininess ), 0.0 ) * diffuse * specularNormalization;"
 
-	].join("\n"),
+	].join( "\n" ),
 
 	combine: [
 
 		"vec3 light = lightIntensity * lightColor;",
 		"gl_FragColor = vec4( light * ( albedo * diffuse + specular ), attenuation );"
 
-	].join("\n")
+	].join( "\n" )
 
 };
 
@@ -305,7 +305,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -346,7 +346,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -391,7 +391,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -434,7 +434,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -528,7 +528,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -542,7 +542,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -556,7 +556,7 @@ THREE.ShaderDeferred = {
 			viewWidth: 		{ type: "f", value: 800 },
 			viewHeight: 	{ type: "f", value: 600 },
 
-			lightPositionVS:{ type: "v3", value: new THREE.Vector3( 0, 0, 0 ) },
+			lightPositionVS: { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) },
 			lightColor: 	{ type: "c", value: new THREE.Color( 0x000000 ) },
 			lightIntensity: { type: "f", value: 1.0 },
 			lightRadius: 	{ type: "f", value: 1.0 }
@@ -614,7 +614,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -627,7 +627,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -641,8 +641,8 @@ THREE.ShaderDeferred = {
 			viewWidth: 		{ type: "f", value: 800 },
 			viewHeight: 	{ type: "f", value: 600 },
 
-			lightPositionVS :{ type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
-			lightDirectionVS:{ type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
+			lightPositionVS : { type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
+			lightDirectionVS: { type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
 			lightColor: 	{ type: "c", value: new THREE.Color( 0x000000 ) },
 			lightIntensity: { type: "f", value: 1.0 },
 			lightDistance: 	{ type: "f", value: 1.0 },
@@ -718,7 +718,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -730,7 +730,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -788,7 +788,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -800,7 +800,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -886,7 +886,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -898,7 +898,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -913,7 +913,7 @@ THREE.ShaderDeferred = {
 			viewHeight: 	{ type: "f", value: 600 },
 
 			lightPositionVS: { type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
-			lightNormalVS: 	 { type: "v3", value: new THREE.Vector3( 0, -1, 0 ) },
+			lightNormalVS: 	 { type: "v3", value: new THREE.Vector3( 0, - 1, 0 ) },
 			lightRightVS:  	 { type: "v3", value: new THREE.Vector3( 1, 0, 0 ) },
 			lightUpVS:  	 { type: "v3", value: new THREE.Vector3( 1, 0, 0 ) },
 
@@ -1041,7 +1041,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -1053,7 +1053,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -1087,7 +1087,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader : [
 
@@ -1099,7 +1099,7 @@ THREE.ShaderDeferred = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	}
 

+ 6 - 6
examples/js/ShaderGodRays.js

@@ -71,7 +71,7 @@ THREE.ShaderGodRays = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		fragmentShader: [
 
@@ -157,7 +157,7 @@ THREE.ShaderGodRays = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -203,7 +203,7 @@ THREE.ShaderGodRays = {
 
 			"}"
 
-			].join("\n"),
+			].join( "\n" ),
 
 		fragmentShader: [
 
@@ -226,7 +226,7 @@ THREE.ShaderGodRays = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -273,7 +273,7 @@ THREE.ShaderGodRays = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		fragmentShader: [
 
@@ -301,7 +301,7 @@ THREE.ShaderGodRays = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	}
 

+ 34 - 34
examples/js/ShaderSkin.js

@@ -30,27 +30,27 @@ THREE.ShaderSkin = {
 
 			{
 
-			"enableBump"	: { type: "i", value: 0 },
-			"enableSpecular": { type: "i", value: 0 },
+				"enableBump"	: { type: "i", value: 0 },
+				"enableSpecular": { type: "i", value: 0 },
 
-			"tDiffuse"	: { type: "t", value: null },
-			"tBeckmann"	: { type: "t", value: null },
+				"tDiffuse"	: { type: "t", value: null },
+				"tBeckmann"	: { type: "t", value: null },
 
-			"diffuse":  { type: "c", value: new THREE.Color( 0xeeeeee ) },
-			"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
-			"opacity": 	  { type: "f", value: 1 },
+				"diffuse":  { type: "c", value: new THREE.Color( 0xeeeeee ) },
+				"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
+				"opacity": 	  { type: "f", value: 1 },
 
-			"uRoughness": 	  		{ type: "f", value: 0.15 },
-			"uSpecularBrightness": 	{ type: "f", value: 0.75 },
+				"uRoughness": 	  		{ type: "f", value: 0.15 },
+				"uSpecularBrightness": 	{ type: "f", value: 0.75 },
 
-			"bumpMap"	: { type: "t", value: null },
-			"bumpScale" : { type: "f", value: 1 },
+				"bumpMap"	: { type: "t", value: null },
+				"bumpScale" : { type: "f", value: 1 },
 
-			"specularMap" : { type: "t", value: null },
+				"specularMap" : { type: "t", value: null },
 
-			"offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
+				"offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
 
-			"uWrapRGB":	{ type: "v3", value: new THREE.Vector3( 0.75, 0.375, 0.1875 ) }
+				"uWrapRGB":	{ type: "v3", value: new THREE.Vector3( 0.75, 0.375, 0.1875 ) }
 
 			}
 
@@ -279,7 +279,7 @@ THREE.ShaderSkin = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader: [
 
@@ -338,26 +338,26 @@ THREE.ShaderSkin = {
 
 			{
 
-			"passID": { type: "i", value: 0 },
+				"passID": { type: "i", value: 0 },
 
-			"tDiffuse"	: { type: "t", value: null },
-			"tNormal"	: { type: "t", value: null },
+				"tDiffuse"	: { type: "t", value: null },
+				"tNormal"	: { type: "t", value: null },
 
-			"tBlur1"	: { type: "t", value: null },
-			"tBlur2"	: { type: "t", value: null },
-			"tBlur3"	: { type: "t", value: null },
-			"tBlur4"	: { type: "t", value: null },
+				"tBlur1"	: { type: "t", value: null },
+				"tBlur2"	: { type: "t", value: null },
+				"tBlur3"	: { type: "t", value: null },
+				"tBlur4"	: { type: "t", value: null },
 
-			"tBeckmann"	: { type: "t", value: null },
+				"tBeckmann"	: { type: "t", value: null },
 
-			"uNormalScale": { type: "f", value: 1.0 },
+				"uNormalScale": { type: "f", value: 1.0 },
 
-			"diffuse":  { type: "c", value: new THREE.Color( 0xeeeeee ) },
-			"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
-			"opacity": 	  { type: "f", value: 1 },
+				"diffuse":  { type: "c", value: new THREE.Color( 0xeeeeee ) },
+				"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
+				"opacity": 	  { type: "f", value: 1 },
 
-			"uRoughness": 	  		{ type: "f", value: 0.15 },
-			"uSpecularBrightness": 	{ type: "f", value: 0.75 }
+				"uRoughness": 	  		{ type: "f", value: 0.15 },
+				"uSpecularBrightness": 	{ type: "f", value: 0.75 }
 
 			}
 
@@ -570,7 +570,7 @@ THREE.ShaderSkin = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader: [
 
@@ -659,7 +659,7 @@ THREE.ShaderSkin = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShaderUV: [
 
@@ -735,7 +735,7 @@ THREE.ShaderSkin = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	},
 
@@ -762,7 +762,7 @@ THREE.ShaderSkin = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		fragmentShader: [
 
@@ -794,7 +794,7 @@ THREE.ShaderSkin = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	}
 

+ 22 - 22
examples/js/ShaderTerrain.js

@@ -23,32 +23,32 @@ THREE.ShaderTerrain = {
 
 			{
 
-			"enableDiffuse1"  : { type: "i", value: 0 },
-			"enableDiffuse2"  : { type: "i", value: 0 },
-			"enableSpecular"  : { type: "i", value: 0 },
-			"enableReflection": { type: "i", value: 0 },
+				"enableDiffuse1"  : { type: "i", value: 0 },
+				"enableDiffuse2"  : { type: "i", value: 0 },
+				"enableSpecular"  : { type: "i", value: 0 },
+				"enableReflection": { type: "i", value: 0 },
 
-			"tDiffuse1"	   : { type: "t", value: null },
-			"tDiffuse2"	   : { type: "t", value: null },
-			"tDetail"	   : { type: "t", value: null },
-			"tNormal"	   : { type: "t", value: null },
-			"tSpecular"	   : { type: "t", value: null },
-			"tDisplacement": { type: "t", value: null },
+				"tDiffuse1"	   : { type: "t", value: null },
+				"tDiffuse2"	   : { type: "t", value: null },
+				"tDetail"	   : { type: "t", value: null },
+				"tNormal"	   : { type: "t", value: null },
+				"tSpecular"	   : { type: "t", value: null },
+				"tDisplacement": { type: "t", value: null },
 
-			"uNormalScale": { type: "f", value: 1.0 },
+				"uNormalScale": { type: "f", value: 1.0 },
 
-			"uDisplacementBias": { type: "f", value: 0.0 },
-			"uDisplacementScale": { type: "f", value: 1.0 },
+				"uDisplacementBias": { type: "f", value: 0.0 },
+				"uDisplacementScale": { type: "f", value: 1.0 },
 
-			"diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
-			"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
-			"shininess": { type: "f", value: 30 },
-			"opacity": { type: "f", value: 1 },
+				"diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
+				"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
+				"shininess": { type: "f", value: 30 },
+				"opacity": { type: "f", value: 1 },
 
-			"uRepeatBase"    : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
-			"uRepeatOverlay" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
+				"uRepeatBase"    : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
+				"uRepeatOverlay" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
 
-			"uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) }
+				"uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) }
 
 			}
 
@@ -263,7 +263,7 @@ THREE.ShaderTerrain = {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		vertexShader: [
 
@@ -336,7 +336,7 @@ THREE.ShaderTerrain = {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	}
 

+ 177 - 177
examples/js/ShaderToon.js

@@ -12,320 +12,320 @@
 
 THREE.ShaderToon = {
 
-'toon1' : {
+	'toon1' : {
 
-	uniforms: {
+		uniforms: {
 
-		"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
-		"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
+			"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
+			"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
 
-		"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
+			"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
 
-		"uBaseColor":  { type: "c", value: new THREE.Color( 0xffffff ) }
+			"uBaseColor":  { type: "c", value: new THREE.Color( 0xffffff ) }
 
-	},
+		},
 
-	vertexShader: [
+		vertexShader: [
 
-		"varying vec3 vNormal;",
-		"varying vec3 vRefract;",
+			"varying vec3 vNormal;",
+			"varying vec3 vRefract;",
 
-		"void main() {",
+			"void main() {",
 
-			"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
-			"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
-			"vec3 worldNormal = normalize ( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
+				"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
+				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
+				"vec3 worldNormal = normalize ( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
 
-			"vNormal = normalize( normalMatrix * normal );",
+				"vNormal = normalize( normalMatrix * normal );",
 
-			"vec3 I = worldPosition.xyz - cameraPosition;",
-			"vRefract = refract( normalize( I ), worldNormal, 1.02 );",
+				"vec3 I = worldPosition.xyz - cameraPosition;",
+				"vRefract = refract( normalize( I ), worldNormal, 1.02 );",
 
-			"gl_Position = projectionMatrix * mvPosition;",
+				"gl_Position = projectionMatrix * mvPosition;",
 
-		"}"
+			"}"
 
-	].join("\n"),
+		].join( "\n" ),
 
-	fragmentShader: [
+		fragmentShader: [
 
-		"uniform vec3 uBaseColor;",
+			"uniform vec3 uBaseColor;",
 
-		"uniform vec3 uDirLightPos;",
-		"uniform vec3 uDirLightColor;",
+			"uniform vec3 uDirLightPos;",
+			"uniform vec3 uDirLightColor;",
 
-		"uniform vec3 uAmbientLightColor;",
+			"uniform vec3 uAmbientLightColor;",
 
-		"varying vec3 vNormal;",
+			"varying vec3 vNormal;",
 
-		"varying vec3 vRefract;",
+			"varying vec3 vRefract;",
 
-		"void main() {",
+			"void main() {",
 
-			"float directionalLightWeighting = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);",
-			"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
+				"float directionalLightWeighting = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);",
+				"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
 
-			"float intensity = smoothstep( - 0.5, 1.0, pow( length(lightWeighting), 20.0 ) );",
-			"intensity += length(lightWeighting) * 0.2;",
+				"float intensity = smoothstep( - 0.5, 1.0, pow( length(lightWeighting), 20.0 ) );",
+				"intensity += length(lightWeighting) * 0.2;",
 
-			"float cameraWeighting = dot( normalize( vNormal ), vRefract );",
-			"intensity += pow( 1.0 - length( cameraWeighting ), 6.0 );",
-			"intensity = intensity * 0.2 + 0.3;",
+				"float cameraWeighting = dot( normalize( vNormal ), vRefract );",
+				"intensity += pow( 1.0 - length( cameraWeighting ), 6.0 );",
+				"intensity = intensity * 0.2 + 0.3;",
 
-			"if ( intensity < 0.50 ) {",
+				"if ( intensity < 0.50 ) {",
 
-				"gl_FragColor = vec4( 2.0 * intensity * uBaseColor, 1.0 );",
+					"gl_FragColor = vec4( 2.0 * intensity * uBaseColor, 1.0 );",
 
-			"} else {",
+				"} else {",
 
-				"gl_FragColor = vec4( 1.0 - 2.0 * ( 1.0 - intensity ) * ( 1.0 - uBaseColor ), 1.0 );",
+					"gl_FragColor = vec4( 1.0 - 2.0 * ( 1.0 - intensity ) * ( 1.0 - uBaseColor ), 1.0 );",
 
-			"}",
+				"}",
 
-		"}"
+			"}"
 
-	].join("\n")
+		].join( "\n" )
 
-},
+	},
 
-'toon2' : {
+	'toon2' : {
 
-	uniforms: {
+		uniforms: {
 
-		"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
-		"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
+			"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
+			"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
 
-		"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
+			"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
 
-		"uBaseColor":  { type: "c", value: new THREE.Color( 0xeeeeee ) },
-		"uLineColor1": { type: "c", value: new THREE.Color( 0x808080 ) },
-		"uLineColor2": { type: "c", value: new THREE.Color( 0x000000 ) },
-		"uLineColor3": { type: "c", value: new THREE.Color( 0x000000 ) },
-		"uLineColor4": { type: "c", value: new THREE.Color( 0x000000 ) }
+			"uBaseColor":  { type: "c", value: new THREE.Color( 0xeeeeee ) },
+			"uLineColor1": { type: "c", value: new THREE.Color( 0x808080 ) },
+			"uLineColor2": { type: "c", value: new THREE.Color( 0x000000 ) },
+			"uLineColor3": { type: "c", value: new THREE.Color( 0x000000 ) },
+			"uLineColor4": { type: "c", value: new THREE.Color( 0x000000 ) }
 
-	},
+		},
 
-	vertexShader: [
+		vertexShader: [
 
-		"varying vec3 vNormal;",
+			"varying vec3 vNormal;",
 
-		"void main() {",
+			"void main() {",
 
-			"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
-			"vNormal = normalize( normalMatrix * normal );",
+				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
+				"vNormal = normalize( normalMatrix * normal );",
 
-		"}"
+			"}"
 
-	].join("\n"),
+		].join( "\n" ),
 
-	fragmentShader: [
+		fragmentShader: [
 
-		"uniform vec3 uBaseColor;",
-		"uniform vec3 uLineColor1;",
-		"uniform vec3 uLineColor2;",
-		"uniform vec3 uLineColor3;",
-		"uniform vec3 uLineColor4;",
+			"uniform vec3 uBaseColor;",
+			"uniform vec3 uLineColor1;",
+			"uniform vec3 uLineColor2;",
+			"uniform vec3 uLineColor3;",
+			"uniform vec3 uLineColor4;",
 
-		"uniform vec3 uDirLightPos;",
-		"uniform vec3 uDirLightColor;",
+			"uniform vec3 uDirLightPos;",
+			"uniform vec3 uDirLightColor;",
 
-		"uniform vec3 uAmbientLightColor;",
+			"uniform vec3 uAmbientLightColor;",
 
-		"varying vec3 vNormal;",
+			"varying vec3 vNormal;",
 
-		"void main() {",
+			"void main() {",
 
-			"float camera = max( dot( normalize( vNormal ), vec3( 0.0, 0.0, 1.0 ) ), 0.4);",
-			"float light = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);",
+				"float camera = max( dot( normalize( vNormal ), vec3( 0.0, 0.0, 1.0 ) ), 0.4);",
+				"float light = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);",
 
-			"gl_FragColor = vec4( uBaseColor, 1.0 );",
+				"gl_FragColor = vec4( uBaseColor, 1.0 );",
 
-			"if ( length(uAmbientLightColor + uDirLightColor * light) < 1.00 ) {",
+				"if ( length(uAmbientLightColor + uDirLightColor * light) < 1.00 ) {",
 
-				"gl_FragColor *= vec4( uLineColor1, 1.0 );",
+					"gl_FragColor *= vec4( uLineColor1, 1.0 );",
 
-			"}",
+				"}",
+
+				"if ( length(uAmbientLightColor + uDirLightColor * camera) < 0.50 ) {",
 
-			"if ( length(uAmbientLightColor + uDirLightColor * camera) < 0.50 ) {",
+					"gl_FragColor *= vec4( uLineColor2, 1.0 );",
 
-				"gl_FragColor *= vec4( uLineColor2, 1.0 );",
+				"}",
 
-			"}",
+			"}"
 
-		"}"
+		].join( "\n" )
 
-	].join("\n")
+	},
 
-},
+	'hatching' : {
 
-'hatching' : {
+		uniforms: {
 
-	uniforms: {
+			"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
+			"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
 
-		"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
-		"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
+			"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
 
-		"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
+			"uBaseColor":  { type: "c", value: new THREE.Color( 0xffffff ) },
+			"uLineColor1": { type: "c", value: new THREE.Color( 0x000000 ) },
+			"uLineColor2": { type: "c", value: new THREE.Color( 0x000000 ) },
+			"uLineColor3": { type: "c", value: new THREE.Color( 0x000000 ) },
+			"uLineColor4": { type: "c", value: new THREE.Color( 0x000000 ) }
 
-		"uBaseColor":  { type: "c", value: new THREE.Color( 0xffffff ) },
-		"uLineColor1": { type: "c", value: new THREE.Color( 0x000000 ) },
-		"uLineColor2": { type: "c", value: new THREE.Color( 0x000000 ) },
-		"uLineColor3": { type: "c", value: new THREE.Color( 0x000000 ) },
-		"uLineColor4": { type: "c", value: new THREE.Color( 0x000000 ) }
+		},
 
-	},
+		vertexShader: [
 
-	vertexShader: [
+			"varying vec3 vNormal;",
 
-		"varying vec3 vNormal;",
+			"void main() {",
 
-		"void main() {",
+				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
+				"vNormal = normalize( normalMatrix * normal );",
 
-			"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
-			"vNormal = normalize( normalMatrix * normal );",
+			"}"
 
-		"}"
+		].join( "\n" ),
 
-	].join("\n"),
+		fragmentShader: [
 
-	fragmentShader: [
+			"uniform vec3 uBaseColor;",
+			"uniform vec3 uLineColor1;",
+			"uniform vec3 uLineColor2;",
+			"uniform vec3 uLineColor3;",
+			"uniform vec3 uLineColor4;",
 
-		"uniform vec3 uBaseColor;",
-		"uniform vec3 uLineColor1;",
-		"uniform vec3 uLineColor2;",
-		"uniform vec3 uLineColor3;",
-		"uniform vec3 uLineColor4;",
+			"uniform vec3 uDirLightPos;",
+			"uniform vec3 uDirLightColor;",
 
-		"uniform vec3 uDirLightPos;",
-		"uniform vec3 uDirLightColor;",
+			"uniform vec3 uAmbientLightColor;",
 
-		"uniform vec3 uAmbientLightColor;",
+			"varying vec3 vNormal;",
 
-		"varying vec3 vNormal;",
+			"void main() {",
 
-		"void main() {",
+				"float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);",
+				"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
 
-			"float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);",
-			"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
+				"gl_FragColor = vec4( uBaseColor, 1.0 );",
 
-			"gl_FragColor = vec4( uBaseColor, 1.0 );",
+				"if ( length(lightWeighting) < 1.00 ) {",
 
-			"if ( length(lightWeighting) < 1.00 ) {",
+					"if ( mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) {",
 
-				"if ( mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) {",
+						"gl_FragColor = vec4( uLineColor1, 1.0 );",
 
-					"gl_FragColor = vec4( uLineColor1, 1.0 );",
+					"}",
 
 				"}",
 
-			"}",
+				"if ( length(lightWeighting) < 0.75 ) {",
 
-			"if ( length(lightWeighting) < 0.75 ) {",
+					"if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) {",
 
-				"if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) {",
-
-					"gl_FragColor = vec4( uLineColor2, 1.0 );",
+						"gl_FragColor = vec4( uLineColor2, 1.0 );",
 
+					"}",
 				"}",
-			"}",
 
-			"if ( length(lightWeighting) < 0.50 ) {",
+				"if ( length(lightWeighting) < 0.50 ) {",
 
-				"if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
+					"if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
 
-					"gl_FragColor = vec4( uLineColor3, 1.0 );",
+						"gl_FragColor = vec4( uLineColor3, 1.0 );",
 
+					"}",
 				"}",
-			"}",
 
-			"if ( length(lightWeighting) < 0.3465 ) {",
+				"if ( length(lightWeighting) < 0.3465 ) {",
 
-				"if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
+					"if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
 
-					"gl_FragColor = vec4( uLineColor4, 1.0 );",
+						"gl_FragColor = vec4( uLineColor4, 1.0 );",
 
+					"}",
 				"}",
-			"}",
 
-		"}"
+			"}"
 
-	].join("\n")
+		].join( "\n" )
 
-},
+	},
 
-'dotted' : {
+	'dotted' : {
 
-	uniforms: {
+		uniforms: {
 
-		"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
-		"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
+			"uDirLightPos":	{ type: "v3", value: new THREE.Vector3() },
+			"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
 
-		"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
+			"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
 
-		"uBaseColor":  { type: "c", value: new THREE.Color( 0xffffff ) },
-		"uLineColor1": { type: "c", value: new THREE.Color( 0x000000 ) }
+			"uBaseColor":  { type: "c", value: new THREE.Color( 0xffffff ) },
+			"uLineColor1": { type: "c", value: new THREE.Color( 0x000000 ) }
 
-	},
+		},
+
+		vertexShader: [
 
-	vertexShader: [
+			"varying vec3 vNormal;",
 
-		"varying vec3 vNormal;",
+			"void main() {",
 
-		"void main() {",
+				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
+				"vNormal = normalize( normalMatrix * normal );",
 
-			"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
-			"vNormal = normalize( normalMatrix * normal );",
+			"}"
 
-		"}"
+		].join( "\n" ),
 
-	].join("\n"),
+		fragmentShader: [
 
-	fragmentShader: [
+			"uniform vec3 uBaseColor;",
+			"uniform vec3 uLineColor1;",
+			"uniform vec3 uLineColor2;",
+			"uniform vec3 uLineColor3;",
+			"uniform vec3 uLineColor4;",
 
-		"uniform vec3 uBaseColor;",
-		"uniform vec3 uLineColor1;",
-		"uniform vec3 uLineColor2;",
-		"uniform vec3 uLineColor3;",
-		"uniform vec3 uLineColor4;",
+			"uniform vec3 uDirLightPos;",
+			"uniform vec3 uDirLightColor;",
 
-		"uniform vec3 uDirLightPos;",
-		"uniform vec3 uDirLightColor;",
+			"uniform vec3 uAmbientLightColor;",
 
-		"uniform vec3 uAmbientLightColor;",
+			"varying vec3 vNormal;",
 
-		"varying vec3 vNormal;",
+			"void main() {",
 
-		"void main() {",
+				"float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);",
+				"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
 
-			"float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);",
-			"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
+				"gl_FragColor = vec4( uBaseColor, 1.0 );",
 
-			"gl_FragColor = vec4( uBaseColor, 1.0 );",
+				"if ( length(lightWeighting) < 1.00 ) {",
 
-			"if ( length(lightWeighting) < 1.00 ) {",
+					"if ( ( mod(gl_FragCoord.x, 4.001) + mod(gl_FragCoord.y, 4.0) ) > 6.00 ) {",
 
-				"if ( ( mod(gl_FragCoord.x, 4.001) + mod(gl_FragCoord.y, 4.0) ) > 6.00 ) {",
+						"gl_FragColor = vec4( uLineColor1, 1.0 );",
 
-					"gl_FragColor = vec4( uLineColor1, 1.0 );",
+					"}",
 
 				"}",
 
-			"}",
+				"if ( length(lightWeighting) < 0.50 ) {",
 
-			"if ( length(lightWeighting) < 0.50 ) {",
+					"if ( ( mod(gl_FragCoord.x + 2.0, 4.001) + mod(gl_FragCoord.y + 2.0, 4.0) ) > 6.00 ) {",
 
-				"if ( ( mod(gl_FragCoord.x + 2.0, 4.001) + mod(gl_FragCoord.y + 2.0, 4.0) ) > 6.00 ) {",
+						"gl_FragColor = vec4( uLineColor1, 1.0 );",
 
-					"gl_FragColor = vec4( uLineColor1, 1.0 );",
+					"}",
 
 				"}",
 
-			"}",
-
-		"}"
+			"}"
 
-	].join("\n")
+		].join( "\n" )
 
-}
+	}
 
 };

+ 28 - 14
examples/js/SimulationRenderer.js

@@ -10,7 +10,7 @@
  *
  */
 
-function SimulationRenderer(WIDTH, renderer) {
+function SimulationRenderer( WIDTH, renderer ) {
 
 	WIDTH = WIDTH || 4;
 	var camera = new THREE.Camera();
@@ -19,14 +19,18 @@ function SimulationRenderer(WIDTH, renderer) {
 	// Init RTT stuff
 	gl = renderer.getContext();
 
-	if ( !gl.getExtension( "OES_texture_float" )) {
+	if ( ! gl.getExtension( "OES_texture_float" ) ) {
+
 		alert( "No OES_texture_float support for float textures!" );
 		return;
+
 	}
 
-	if ( gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) == 0) {
+	if ( gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) == 0 ) {
+
 		alert( "No support for vertex shader textures!" );
 		return;
+
 	}
 
 	var scene = new THREE.Scene();
@@ -77,7 +81,7 @@ function SimulationRenderer(WIDTH, renderer) {
 			predator: { type: "v3", value: new THREE.Vector3() }
 		},
 		defines: {
-			WIDTH: WIDTH.toFixed(2)
+			WIDTH: WIDTH.toFixed( 2 )
 		},
 		vertexShader: document.getElementById( 'vertexShader' ).textContent,
 		fragmentShader: document.getElementById( 'fragmentShaderVelocity' ).textContent
@@ -92,6 +96,7 @@ function SimulationRenderer(WIDTH, renderer) {
 	var rtPosition1, rtPosition2, rtVelocity1, rtVelocity2;
 
 	function init() {
+
 		var dtPosition = generatePositionTexture();
 		var dtVelocity = generateVelocityTexture();
 
@@ -100,19 +105,21 @@ function SimulationRenderer(WIDTH, renderer) {
 		rtVelocity1 = getRenderTarget( THREE.RGBFormat );
 		rtVelocity2 = rtVelocity1.clone();
 
-		simulator.renderTexture(dtPosition, rtPosition1);
-		simulator.renderTexture(rtPosition1, rtPosition2);
+		simulator.renderTexture( dtPosition, rtPosition1 );
+		simulator.renderTexture( rtPosition1, rtPosition2 );
 
-		simulator.renderTexture(dtVelocity, rtVelocity1);
-		simulator.renderTexture(rtVelocity1, rtVelocity2);
+		simulator.renderTexture( dtVelocity, rtVelocity1 );
+		simulator.renderTexture( rtVelocity1, rtVelocity2 );
 
 		simulator.velocityUniforms.testing.value = 10;
+
 	}
 
 	this.init = init;
 
 	function getRenderTarget( type ) {
-		var renderTarget = new THREE.WebGLRenderTarget(WIDTH, WIDTH, {
+
+		var renderTarget = new THREE.WebGLRenderTarget( WIDTH, WIDTH, {
 			wrapS: THREE.RepeatWrapping,
 			wrapT: THREE.RepeatWrapping,
 			minFilter: THREE.NearestFilter,
@@ -120,20 +127,24 @@ function SimulationRenderer(WIDTH, renderer) {
 			format: type,
 			type: THREE.FloatType,
 			stencilBuffer: false
-		});
+		} );
 
 		return renderTarget;
+
 	}
 
 	// Takes a texture, and render out as another texture
 	this.renderTexture = function ( input, output ) {
+
 		mesh.material = passThruShader;
 		uniforms.texture.value = input;
 		renderer.render( scene, camera, output );
+
 	};
 
 
-	this.renderPosition = function(position, velocity, output, delta) {
+	this.renderPosition = function( position, velocity, output, delta ) {
+
 		mesh.material = positionShader;
 		positionShader.uniforms.texturePosition.value = position;
 		positionShader.uniforms.textureVelocity.value = velocity;
@@ -141,9 +152,11 @@ function SimulationRenderer(WIDTH, renderer) {
 		positionShader.uniforms.delta.value = delta;
 		renderer.render( scene, camera, output );
 		this.currentPosition = output;
+
 	};
 
-	this.renderVelocity = function(position, velocity, output, delta) {
+	this.renderVelocity = function( position, velocity, output, delta ) {
+
 		mesh.material = velocityShader;
 		velocityShader.uniforms.texturePosition.value = position;
 		velocityShader.uniforms.textureVelocity.value = velocity;
@@ -151,11 +164,12 @@ function SimulationRenderer(WIDTH, renderer) {
 		velocityShader.uniforms.delta.value = delta;
 		renderer.render( scene, camera, output );
 		this.currentVelocity = output;
+
 	};
 
 	this.simulate = function( delta ) {
 
-		if (flipflop) {
+		if ( flipflop ) {
 
 			simulator.renderVelocity( rtPosition1, rtVelocity1, rtVelocity2, delta );
 			simulator.renderPosition( rtPosition1, rtVelocity2, rtPosition2, delta );
@@ -167,7 +181,7 @@ function SimulationRenderer(WIDTH, renderer) {
 
 		}
 
-		flipflop = !flipflop;
+		flipflop = ! flipflop;
 
 	};
 

+ 8 - 8
examples/js/SkyShader.js

@@ -14,15 +14,15 @@
  * Three.js integration by zz85 http://twitter.com/blurspline
 */
 
-THREE.ShaderLib['sky'] = {
+THREE.ShaderLib[ 'sky' ] = {
 
 	uniforms: {
 
-		luminance:	 { type: "f", value:1 },
-		turbidity:	 { type: "f", value:2 },
-		reileigh:	 { type: "f", value:1 },
-		mieCoefficient:	 { type: "f", value:0.005 },
-		mieDirectionalG: { type: "f", value:0.8 },
+		luminance:	 { type: "f", value: 1 },
+		turbidity:	 { type: "f", value: 2 },
+		reileigh:	 { type: "f", value: 1 },
+		mieCoefficient:	 { type: "f", value: 0.005 },
+		mieDirectionalG: { type: "f", value: 0.8 },
 		sunPosition: 	 { type: "v3", value: new THREE.Vector3() }
 
 	},
@@ -40,7 +40,7 @@ THREE.ShaderLib['sky'] = {
 
 		"}",
 
-	].join("\n"),
+	].join( "\n" ),
 
 	fragmentShader: [
 
@@ -235,7 +235,7 @@ THREE.ShaderLib['sky'] = {
 			"gl_FragColor.a = 1.0;",
 		"}",
 
-	].join("\n")
+	].join( "\n" )
 
 };
 

+ 355 - 209
examples/js/Sparks.js

@@ -17,9 +17,9 @@ var SPARKS = {};
 *   Creates and Manages Particles
 *********************************/
 
-SPARKS.Emitter = function (counter) {
+SPARKS.Emitter = function ( counter ) {
 
-	this._counter = counter ? counter : new SPARKS.SteadyCounter(10); // provides number of particles to produce
+	this._counter = counter ? counter : new SPARKS.SteadyCounter( 10 ); // provides number of particles to produce
 
 	this._particles = [];
 
@@ -31,6 +31,7 @@ SPARKS.Emitter = function (counter) {
 	this._handlers = [];
 
 	this.callbacks = {};
+
 };
 
 
@@ -44,165 +45,207 @@ SPARKS.Emitter.prototype = {
 
 	// run its built in timer / stepping
 	start: function() {
+
 		this._lastTime = Date.now();
-		this._timer = setTimeout(this.step, this._timerStep, this);
+		this._timer = setTimeout( this.step, this._timerStep, this );
 		this._isRunning = true;
+
 	},
 
 	stop: function() {
+
 		this._isRunning = false;
-		clearTimeout(this._timer);
+		clearTimeout( this._timer );
+
 	},
 
 	isRunning: function() {
+
 		return this._isRunning & true;
+
 	},
 
 	// Step gets called upon by the engine
 	// but attempts to call update() on a regular basics
 	// This method is also described in http://gameclosure.com/2011/04/11/deterministic-delta-tee-in-js-games/
-	step: function(emitter) {
+	step: function( emitter ) {
 
 		var time = Date.now();
 		var elapsed = time - emitter._lastTime;
 
-		if (!this._velocityVerlet) {
+		if ( ! this._velocityVerlet ) {
+
 			// if elapsed is way higher than time step, (usually after switching tabs, or excution cached in ff)
 			// we will drop cycles. perhaps set to a limit of 10 or something?
 			var maxBlock = emitter._TIMESTEP * 20;
 
-			if (elapsed >= maxBlock) {
+			if ( elapsed >= maxBlock ) {
+
 				//console.log('warning: sparks.js is fast fowarding engine, skipping steps', elapsed / emitter._TIMESTEP);
 				//emitter.update( (elapsed - maxBlock) / 1000);
 				elapsed = maxBlock;
+
 			}
 
-			while (elapsed >= emitter._TIMESTEP) {
-				emitter.update(emitter._TIMESTEP / 1000);
+			while ( elapsed >= emitter._TIMESTEP ) {
+
+				emitter.update( emitter._TIMESTEP / 1000 );
 				elapsed -= emitter._TIMESTEP;
+
 			}
 			emitter._lastTime = time - elapsed;
 
 		} else {
-			emitter.update(elapsed / 1000);
+
+			emitter.update( elapsed / 1000 );
 			emitter._lastTime = time;
+
 		}
 
 
 
-		if (emitter._isRunning)
-		setTimeout(emitter.step, emitter._timerStep, emitter);
+		if ( emitter._isRunning )
+		setTimeout( emitter.step, emitter._timerStep, emitter );
 
 	},
 
 
 	// Update particle engine in seconds, not milliseconds
-    update: function(time) {
+	update: function( time ) {
 
-	var i, j;
-	var len = this._counter.updateEmitter( this, time );
+		var i, j;
+		var len = this._counter.updateEmitter( this, time );
 
-        // Create particles
-	for ( i = 0; i < len; i ++ ) {
-		this.createParticle();
-	}
+		// Create particles
+		for ( i = 0; i < len; i ++ ) {
 
-        // Update activities
-	len = this._activities.length;
-	for ( i = 0; i < len; i ++ )
-        {
-		this._activities[i].update( this, time );
-	}
+			this.createParticle();
 
+		}
 
-	len = this._actions.length;
+		// Update activities
+		len = this._activities.length;
+		for ( i = 0; i < len; i ++ ) {
 
-	var particle;
-	var action;
-	var len2 = this._particles.length;
+			this._activities[ i ].update( this, time );
 
-	for ( j = 0; j < len; j ++ )
-        {
-		action = this._actions[j];
-		for ( i = 0; i < len2; ++ i )
-            {
-			particle = this._particles[i];
-			action.update( this, particle, time );
 		}
-	}
 
 
-        // remove dead particles
-	for ( i = len2; i --; )
-        {
-		particle = this._particles[i];
-		if ( particle.isDead )
-            {
-                //particle =
-			this._particles.splice( i, 1 );
-			this.dispatchEvent("dead", particle);
-			SPARKS.VectorPool.release(particle.position); //
-			SPARKS.VectorPool.release(particle.velocity);
+		len = this._actions.length;
+
+		var particle;
+		var action;
+		var len2 = this._particles.length;
+
+		for ( j = 0; j < len; j ++ ) {
+
+			action = this._actions[ j ];
+			for ( i = 0; i < len2; ++ i ) {
+
+				particle = this._particles[ i ];
+				action.update( this, particle, time );
+
+			}
 
-		} else {
-			this.dispatchEvent("updated", particle);
 		}
-	}
 
-	this.dispatchEvent("loopUpdated");
 
-    },
+		// remove dead particles
+		for ( i = len2; i --; ) {
 
-    createParticle: function() {
-	var particle = new SPARKS.Particle();
-        // In future, use a Particle Factory
-	var len = this._initializers.length, i;
+			particle = this._particles[ i ];
+			if ( particle.isDead ) {
 
-	for ( i = 0; i < len; i ++ ) {
-		this._initializers[i].initialize( this, particle );
-	}
+				//particle =
+				this._particles.splice( i, 1 );
+				this.dispatchEvent( "dead", particle );
+				SPARKS.VectorPool.release( particle.position ); //
+				SPARKS.VectorPool.release( particle.velocity );
 
-	this._particles.push( particle );
+			} else {
 
-	this.dispatchEvent("created", particle); // ParticleCreated
+				this.dispatchEvent( "updated", particle );
 
-	return particle;
-    },
+			}
 
-    addInitializer: function (initializer) {
-	this._initializers.push(initializer);
-    },
+		}
 
-    addAction: function (action) {
-	this._actions.push(action);
-    },
+		this.dispatchEvent( "loopUpdated" );
 
-    removeInitializer: function (initializer) {
-	var index = this._initializers.indexOf(initializer);
-	if (index > -1) {
-		this._initializers.splice( index, 1 );
-	}
-    },
+	},
 
-    removeAction: function (action) {
-	var index = this._actions.indexOf(action);
-	if (index > -1) {
-		this._actions.splice( index, 1 );
-	}
+	createParticle: function() {
+
+		var particle = new SPARKS.Particle();
+		// In future, use a Particle Factory
+		var len = this._initializers.length, i;
+
+		for ( i = 0; i < len; i ++ ) {
+
+			this._initializers[ i ].initialize( this, particle );
+
+		}
+
+		this._particles.push( particle );
+
+		this.dispatchEvent( "created", particle ); // ParticleCreated
+
+		return particle;
+
+	},
+
+	addInitializer: function ( initializer ) {
+
+		this._initializers.push( initializer );
+
+	},
+
+	addAction: function ( action ) {
+
+		this._actions.push( action );
+
+	},
+
+	removeInitializer: function ( initializer ) {
+
+		var index = this._initializers.indexOf( initializer );
+		if ( index > - 1 ) {
+
+			this._initializers.splice( index, 1 );
+
+		}
+
+	},
+
+	removeAction: function ( action ) {
+
+		var index = this._actions.indexOf( action );
+		if ( index > - 1 ) {
+
+			this._actions.splice( index, 1 );
+
+		}
 		//console.log('removeAction', index, this._actions);
-    },
 
-    addCallback: function(name, callback) {
-	this.callbacks[name] = callback;
-    },
+	},
+
+	addCallback: function( name, callback ) {
 
-    dispatchEvent: function(name, args) {
-	var callback = this.callbacks[name];
-	if (callback) {
-		callback(args);
-	}
+		this.callbacks[ name ] = callback;
 
-    }
+	},
+
+	dispatchEvent: function( name, args ) {
+
+		var callback = this.callbacks[ name ];
+		if ( callback ) {
+
+			callback( args );
+
+		}
+
+	}
 
 
 };
@@ -226,7 +269,8 @@ SPARKS.EVENT_LOOP_UPDATED = "loopUpdated";
  */
 
 // Number of particles per seconds
-SPARKS.SteadyCounter = function(rate) {
+SPARKS.SteadyCounter = function( rate ) {
+
 	this.rate = rate;
 
 	// we use a shortfall counter to make up for slow emitters
@@ -234,14 +278,15 @@ SPARKS.SteadyCounter = function(rate) {
 
 };
 
-SPARKS.SteadyCounter.prototype.updateEmitter = function(emitter, time) {
+SPARKS.SteadyCounter.prototype.updateEmitter = function( emitter, time ) {
 
 	var targetRelease = time * this.rate + this.leftover;
-	var actualRelease = Math.floor(targetRelease);
+	var actualRelease = Math.floor( targetRelease );
 
 	this.leftover = targetRelease - actualRelease;
 
 	return actualRelease;
+
 };
 
 
@@ -250,20 +295,27 @@ SPARKS.SteadyCounter.prototype.updateEmitter = function(emitter, time) {
  * on a single impluse or burst
  */
 
-SPARKS.ShotCounter = function(particles) {
+SPARKS.ShotCounter = function( particles ) {
+
 	this.particles = particles;
 	this.used = false;
+
 };
 
-SPARKS.ShotCounter.prototype.updateEmitter = function(emitter, time) {
+SPARKS.ShotCounter.prototype.updateEmitter = function( emitter, time ) {
+
+	if ( this.used ) {
 
-	if (this.used) {
 		return 0;
+
 	} else {
+
 		this.used = true;
+
 	}
 
 	return this.particles;
+
 };
 
 
@@ -274,38 +326,38 @@ SPARKS.ShotCounter.prototype.updateEmitter = function(emitter, time) {
 *********************************/
 SPARKS.Particle = function() {
 
-    /**
-     * The lifetime of the particle, in seconds.
-     */
+	/**
+	     * The lifetime of the particle, in seconds.
+	     */
 	this.lifetime = 0;
 
-    /**
-     * The age of the particle, in seconds.
-     */
+	/**
+	     * The age of the particle, in seconds.
+	     */
 	this.age = 0;
 
-    /**
-     * The energy of the particle.
-     */
+	/**
+	     * The energy of the particle.
+	     */
 	this.energy = 1;
 
-    /**
-     * Whether the particle is dead and should be removed from the stage.
-     */
+	/**
+	     * Whether the particle is dead and should be removed from the stage.
+	     */
 	this.isDead = false;
 
 	this.target = null; // tag
 
-    /**
-     * For 3D
-     */
-
-	this.position = SPARKS.VectorPool.get().set(0, 0, 0); //new THREE.Vector3( 0, 0, 0 );
-	this.velocity = SPARKS.VectorPool.get().set(0, 0, 0); //new THREE.Vector3( 0, 0, 0 );
-	this._oldvelocity = SPARKS.VectorPool.get().set(0, 0, 0);
-     // rotation vec3
-     // angVelocity vec3
-     // faceAxis vec3
+	/**
+	     * For 3D
+	     */
+	
+	this.position = SPARKS.VectorPool.get().set( 0, 0, 0 ); //new THREE.Vector3( 0, 0, 0 );
+	this.velocity = SPARKS.VectorPool.get().set( 0, 0, 0 ); //new THREE.Vector3( 0, 0, 0 );
+	this._oldvelocity = SPARKS.VectorPool.get().set( 0, 0, 0 );
+	// rotation vec3
+	// angVelocity vec3
+	// faceAxis vec3
 
 };
 
@@ -317,26 +369,33 @@ SPARKS.Particle = function() {
 *   update function
 *********************************/
 SPARKS.Action = function() {
+
 	this._priority = 0;
+
 };
 
 
-SPARKS.Age = function(easing) {
-	this._easing = (easing == null) ? TWEEN.Easing.Linear.None : easing;
+SPARKS.Age = function( easing ) {
+
+	this._easing = ( easing == null ) ? TWEEN.Easing.Linear.None : easing;
+
 };
 
-SPARKS.Age.prototype.update = function (emitter, particle, time) {
+SPARKS.Age.prototype.update = function ( emitter, particle, time ) {
+
 	particle.age += time;
-	if ( particle.age >= particle.lifetime )
-    {
+	if ( particle.age >= particle.lifetime ) {
+
 		particle.energy = 0;
 		particle.isDead = true;
+
+	} else {
+
+		var t = this._easing( particle.age / particle.lifetime );
+		particle.energy = - 1 * t + 1;
+
 	}
-    else
-	{
-		var t = this._easing(particle.age / particle.lifetime);
-		particle.energy = -1 * t + 1;
-	}
+
 };
 
 /*
@@ -358,39 +417,48 @@ SPARKS.Move = function() {
 
 };
 
-SPARKS.Move.prototype.update = function(emitter, particle, time) {
-    // attempt verlet velocity updating.
+SPARKS.Move.prototype.update = function( emitter, particle, time ) {
+
+	// attempt verlet velocity updating.
 	var p = particle.position;
 	var v = particle.velocity;
 	var old = particle._oldvelocity;
 
-	if (this._velocityVerlet) {
-		p.x += (v.x + old.x) * 0.5 * time;
-		p.y += (v.y + old.y) * 0.5 * time;
-		p.z += (v.z + old.z) * 0.5 * time;
+	if ( this._velocityVerlet ) {
+
+		p.x += ( v.x + old.x ) * 0.5 * time;
+		p.y += ( v.y + old.y ) * 0.5 * time;
+		p.z += ( v.z + old.z ) * 0.5 * time;
+
 	} else {
+
 		p.x += v.x * time;
 		p.y += v.y * time;
 		p.z += v.z * time;
+
 	}
 
-    //  OldVel = Vel;
-    // Vel = Vel + Accel * dt;
-    // Pos = Pos + (vel + Vel + Accel * dt) * 0.5 * dt;
+	//  OldVel = Vel;
+	// Vel = Vel + Accel * dt;
+	// Pos = Pos + (vel + Vel + Accel * dt) * 0.5 * dt;
 
 
 
 };
 
 /* Marks particles found in specified zone dead */
-SPARKS.DeathZone = function(zone) {
+SPARKS.DeathZone = function( zone ) {
+
 	this.zone = zone;
+
 };
 
-SPARKS.DeathZone.prototype.update = function(emitter, particle, time) {
+SPARKS.DeathZone.prototype.update = function( emitter, particle, time ) {
+
+	if ( this.zone.contains( particle.position ) ) {
 
-	if (this.zone.contains(particle.position)) {
 		particle.isDead = true;
+
 	}
 
 };
@@ -398,15 +466,19 @@ SPARKS.DeathZone.prototype.update = function(emitter, particle, time) {
 /*
  * SPARKS.ActionZone applies an action when particle is found in zone
  */
-SPARKS.ActionZone = function(action, zone) {
+SPARKS.ActionZone = function( action, zone ) {
+
 	this.action = action;
 	this.zone = zone;
+
 };
 
-SPARKS.ActionZone.prototype.update = function(emitter, particle, time) {
+SPARKS.ActionZone.prototype.update = function( emitter, particle, time ) {
+
+	if ( this.zone.contains( particle.position ) ) {
 
-	if (this.zone.contains(particle.position)) {
 		this.action.update( emitter, particle, time );
+
 	}
 
 };
@@ -414,23 +486,26 @@ SPARKS.ActionZone.prototype.update = function(emitter, particle, time) {
 /*
  * Accelerate action affects velocity in specified 3d direction
  */
-SPARKS.Accelerate = function(x,y,z) {
+SPARKS.Accelerate = function( x, y, z ) {
+
+	if ( x instanceof THREE.Vector3 ) {
 
-	if (x instanceof THREE.Vector3) {
 		this.acceleration = x;
 		return;
+
 	}
 
-	this.acceleration = new THREE.Vector3(x,y,z);
+	this.acceleration = new THREE.Vector3( x, y, z );
 
 };
 
-SPARKS.Accelerate.prototype.update = function(emitter, particle, time) {
+SPARKS.Accelerate.prototype.update = function( emitter, particle, time ) {
+
 	var acc = this.acceleration;
 
 	var v = particle.velocity;
 
-	particle._oldvelocity.set(v.x, v.y, v.z);
+	particle._oldvelocity.set( v.x, v.y, v.z );
 
 	v.x += acc.x * time;
 	v.y += acc.y * time;
@@ -441,25 +516,29 @@ SPARKS.Accelerate.prototype.update = function(emitter, particle, time) {
 /*
  * Accelerate Factor accelerate based on a factor of particle's velocity.
  */
-SPARKS.AccelerateFactor = function(factor) {
+SPARKS.AccelerateFactor = function( factor ) {
+
 	this.factor = factor;
+
 };
 
-SPARKS.AccelerateFactor.prototype.update = function(emitter, particle, time) {
+SPARKS.AccelerateFactor.prototype.update = function( emitter, particle, time ) {
+
 	var factor = this.factor;
 
 	var v = particle.velocity;
 	var len = v.length();
 	var adjFactor;
-	if (len > 0) {
+	if ( len > 0 ) {
 
 		adjFactor = factor * time / len;
 		adjFactor += 1;
 
-		v.multiplyScalar(adjFactor);
+		v.multiplyScalar( adjFactor );
 		// v.x *= adjFactor;
 		// 	    v.y *= adjFactor;
 		// 	    v.z *= adjFactor;
+
 	}
 
 };
@@ -468,13 +547,14 @@ SPARKS.AccelerateFactor.prototype.update = function(emitter, particle, time) {
 AccelerateNormal
  * AccelerateVelocity affects velocity based on its velocity direction
  */
-SPARKS.AccelerateVelocity = function(factor) {
+SPARKS.AccelerateVelocity = function( factor ) {
 
 	this.factor = factor;
 
 };
 
-SPARKS.AccelerateVelocity.prototype.update = function(emitter, particle, time) {
+SPARKS.AccelerateVelocity.prototype.update = function( emitter, particle, time ) {
+
 	var factor = this.factor;
 
 	var v = particle.velocity;
@@ -488,17 +568,22 @@ SPARKS.AccelerateVelocity.prototype.update = function(emitter, particle, time) {
 
 
 /* Set the max ammount of x,y,z drift movements in a second */
-SPARKS.RandomDrift = function(x,y,z) {
-	if (x instanceof THREE.Vector3) {
+SPARKS.RandomDrift = function( x, y, z ) {
+
+	if ( x instanceof THREE.Vector3 ) {
+
 		this.drift = x;
 		return;
+
 	}
 
-	this.drift = new THREE.Vector3(x,y,z);
+	this.drift = new THREE.Vector3( x, y, z );
+
 };
 
 
-SPARKS.RandomDrift.prototype.update = function(emitter, particle, time) {
+SPARKS.RandomDrift.prototype.update = function( emitter, particle, time ) {
+
 	var drift = this.drift;
 
 	var v = particle.velocity;
@@ -520,29 +605,40 @@ SPARKS.Zone = function() {
 
 // TODO, contains() for Zone
 
-SPARKS.PointZone = function(pos) {
+SPARKS.PointZone = function( pos ) {
+
 	this.pos = pos;
+
 };
 
 SPARKS.PointZone.prototype.getLocation = function() {
+
 	return this.pos;
+
 };
 
-SPARKS.PointZone = function(pos) {
+SPARKS.PointZone = function( pos ) {
+
 	this.pos = pos;
+
 };
 
 SPARKS.PointZone.prototype.getLocation = function() {
+
 	return this.pos;
+
 };
 
-SPARKS.LineZone = function(start, end) {
+SPARKS.LineZone = function( start, end ) {
+
 	this.start = start;
 	this.end = end;
 	this._length = end.clone().sub( start );
+
 };
 
 SPARKS.LineZone.prototype.getLocation = function() {
+
 	var len = this._length.clone();
 
 	len.multiplyScalar( Math.random() );
@@ -551,30 +647,35 @@ SPARKS.LineZone.prototype.getLocation = function() {
 };
 
 // Basically a RectangleZone
-SPARKS.ParallelogramZone = function(corner, side1, side2) {
+SPARKS.ParallelogramZone = function( corner, side1, side2 ) {
+
 	this.corner = corner;
 	this.side1 = side1;
 	this.side2 = side2;
+
 };
 
 SPARKS.ParallelogramZone.prototype.getLocation = function() {
 
 	var d1 = this.side1.clone().multiplyScalar( Math.random() );
 	var d2 = this.side2.clone().multiplyScalar( Math.random() );
-	d1.add(d2);
+	d1.add( d2 );
 	return d1.add( this.corner );
 
 };
 
-SPARKS.CubeZone = function(position, x, y, z) {
+SPARKS.CubeZone = function( position, x, y, z ) {
+
 	this.position = position;
 	this.x = x;
 	this.y = y;
 	this.z = z;
+
 };
 
 SPARKS.CubeZone.prototype.getLocation = function() {
-    //TODO use pool?
+
+	//TODO use pool?
 
 	var location = this.position.clone();
 	location.x += Math.random() * this.x;
@@ -586,7 +687,7 @@ SPARKS.CubeZone.prototype.getLocation = function() {
 };
 
 
-SPARKS.CubeZone.prototype.contains = function(position) {
+SPARKS.CubeZone.prototype.contains = function( position ) {
 
 	var startX = this.position.x;
 	var startY = this.position.y;
@@ -595,29 +696,37 @@ SPARKS.CubeZone.prototype.contains = function(position) {
 	var y = this.y; // depth
 	var z = this.z; // height
 
-	if (x < 0) {
+	if ( x < 0 ) {
+
 		startX += x;
-		x = Math.abs(x);
+		x = Math.abs( x );
+
 	}
 
-	if (y < 0) {
+	if ( y < 0 ) {
+
 		startY += y;
-		y = Math.abs(y);
+		y = Math.abs( y );
+
 	}
 
-	if (z < 0) {
+	if ( z < 0 ) {
+
 		startZ += z;
-		z = Math.abs(z);
+		z = Math.abs( z );
+
 	}
 
 	var diffX = position.x - startX;
 	var diffY = position.y - startY;
 	var diffZ = position.z - startZ;
 
-	if ( (diffX > 0) && (diffX < x) &&
-			(diffY > 0) && (diffY < y) &&
-			(diffZ > 0) && (diffZ < z) ) {
+	if ( ( diffX > 0 ) && ( diffX < x ) &&
+			( diffY > 0 ) && ( diffY < y ) &&
+			( diffZ > 0 ) && ( diffZ < z ) ) {
+
 		return true;
+
 	}
 
 	return false;
@@ -673,30 +782,34 @@ SPARKS.DiscZone.prototype.getLocation = function() {
 };
 */
 
-SPARKS.SphereCapZone = function(x, y, z, minr, maxr, angle) {
+SPARKS.SphereCapZone = function( x, y, z, minr, maxr, angle ) {
+
 	this.x = x;
 	this.y = y;
 	this.z = z;
 	this.minr = minr;
 	this.maxr = maxr;
 	this.angle = angle;
+
 };
 
 SPARKS.SphereCapZone.prototype.getLocation = function() {
+
 	var theta = Math.PI * 2  * SPARKS.Utils.random();
 	var r = SPARKS.Utils.random();
 
-    //new THREE.Vector3
-	var v =  SPARKS.VectorPool.get().set(r * Math.cos(theta), -1 / Math.tan(this.angle * SPARKS.Utils.DEGREE_TO_RADIAN), r * Math.sin(theta));
+	//new THREE.Vector3
+	var v =  SPARKS.VectorPool.get().set( r * Math.cos( theta ), - 1 / Math.tan( this.angle * SPARKS.Utils.DEGREE_TO_RADIAN ), r * Math.sin( theta ) );
 
-    //v.length = StardustMath.interpolate(0, _minRadius, 1, _maxRadius, Math.random());
+	//v.length = StardustMath.interpolate(0, _minRadius, 1, _maxRadius, Math.random());
 
-	var i = this.minr - ((this.minr - this.maxr) *  Math.random() );
-	v.multiplyScalar(i);
+	var i = this.minr - ( ( this.minr - this.maxr ) *  Math.random() );
+	v.multiplyScalar( i );
 
 	v.__markedForReleased = true;
 
 	return v;
+
 };
 
 
@@ -708,7 +821,8 @@ SPARKS.SphereCapZone.prototype.getLocation = function() {
 *********************************/
 
 // Specifies random life between max and min
-SPARKS.Lifetime = function(min, max) {
+SPARKS.Lifetime = function( min, max ) {
+
 	this._min = min;
 
 	this._max = max ? max : min;
@@ -716,44 +830,62 @@ SPARKS.Lifetime = function(min, max) {
 };
 
 SPARKS.Lifetime.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
+
 	particle.lifetime = this._min + SPARKS.Utils.random() * ( this._max - this._min );
+
 };
 
 
-SPARKS.Position = function(zone) {
+SPARKS.Position = function( zone ) {
+
 	this.zone = zone;
+
 };
 
 SPARKS.Position.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
+
 	var pos = this.zone.getLocation();
-	particle.position.set(pos.x, pos.y, pos.z);
+	particle.position.set( pos.x, pos.y, pos.z );
+
 };
 
-SPARKS.Velocity = function(zone) {
+SPARKS.Velocity = function( zone ) {
+
 	this.zone = zone;
+
 };
 
 SPARKS.Velocity.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
+
 	var pos = this.zone.getLocation();
-	particle.velocity.set(pos.x, pos.y, pos.z);
-	if (pos.__markedForReleased) {
+	particle.velocity.set( pos.x, pos.y, pos.z );
+	if ( pos.__markedForReleased ) {
+
 		//console.log("release");
-		SPARKS.VectorPool.release(pos);
+		SPARKS.VectorPool.release( pos );
 		pos.__markedForReleased = false;
+
 	}
+
 };
 
-SPARKS.Target = function(target, callback) {
+SPARKS.Target = function( target, callback ) {
+
 	this.target = target;
 	this.callback = callback;
+
 };
 
 SPARKS.Target.prototype.initialize = function( emitter, particle ) {
 
-	if (this.callback) {
+	if ( this.callback ) {
+
 		particle.target = this.callback();
+
 	} else {
+
 		particle.target = this.target;
+
 	}
 
 };
@@ -769,8 +901,11 @@ SPARKS.VectorPool = {
 
 	// Get a new Vector
 	get: function() {
-		if (this.__pools.length > 0) {
+
+		if ( this.__pools.length > 0 ) {
+
 			return this.__pools.pop();
+
 		}
 
 		return this._addToPool();
@@ -778,16 +913,21 @@ SPARKS.VectorPool = {
 	},
 
 	// Release a vector back into the pool
-	release: function(v) {
-		this.__pools.push(v);
+	release: function( v ) {
+
+		this.__pools.push( v );
+
 	},
 
 	// Create a bunch of vectors and add to the pool
 	_addToPool: function() {
+
 		//console.log("creating some pools");
 
-		for (var i = 0, size = 100; i < size; i ++) {
-			this.__pools.push(new THREE.Vector3());
+		for ( var i = 0, size = 100; i < size; i ++ ) {
+
+			this.__pools.push( new THREE.Vector3() );
+
 		}
 
 		return new THREE.Vector3();
@@ -806,30 +946,36 @@ SPARKS.VectorPool = {
 *   particles. Implements initialize( emitter:Emitter, particle:Particle )
 *********************************/
 SPARKS.Utils = {
-    random: function() {
-	return Math.random();
-    },
-    DEGREE_TO_RADIAN: Math.PI / 180,
+	random: function() {
+
+		return Math.random();
+
+	},
+	DEGREE_TO_RADIAN: Math.PI / 180,
 	TWOPI: Math.PI * 2,
 
-	getPerpendiculars: function(normal) {
+	getPerpendiculars: function( normal ) {
+
 		var p1 = this.getPerpendicular( normal );
 		var p2 = normal.cross( p1 );
 		p2.normalize();
 		return [ p1, p2 ];
+
 	},
 
-	getPerpendicular: function( v )
-	{
-		if ( v.x == 0 )
-		{
+	getPerpendicular: function( v ) {
+
+		if ( v.x == 0 ) {
+
 			return new THREE.Vector3D( 1, 0, 0 );
-		}
-		else
-		{
-			var temp = new THREE.Vector3( v.y, -v.x, 0 );
+
+		} else {
+
+			var temp = new THREE.Vector3( v.y, - v.x, 0 );
 			return temp.normalize();
+
 		}
+
 	}
 
 };

+ 18 - 10
examples/js/TypedArrayUtils.js

@@ -21,7 +21,7 @@ THREE.TypedArrayUtils = {};
 THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 
 	var stack = [];
-	var sp = -1;
+	var sp = - 1;
 	var left = 0;
 	var right = arr.length / eleSize - 1;
 	var tmp = 0.0, x = 0, y = 0;
@@ -56,7 +56,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 				
 				i = j - 1;
 				
-				while ( i >= left && arr[ i * eleSize + orderElement ] > swap[orderElement ] ) {
+				while ( i >= left && arr[ i * eleSize + orderElement ] > swap[ orderElement ] ) {
 
 					for ( x = 0; x < eleSize; x ++ ) {
 
@@ -76,7 +76,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 
 			}
 			
-			if ( sp == -1 ) break;
+			if ( sp == - 1 ) break;
 
 			right = stack[ sp -- ]; //?
 			left = stack[ sp -- ];
@@ -215,7 +215,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 		median = Math.floor( plength / 2 );
 		
 		node = new self.Node( getPointSet( points, median ), depth, parent, median + pos );
-		node.left = buildTree( points.subarray( 0, median * eleSize), depth + 1, node, pos );
+		node.left = buildTree( points.subarray( 0, median * eleSize ), depth + 1, node, pos );
 		node.right = buildTree( points.subarray( ( median + 1 ) * eleSize, points.length ), depth + 1, node, pos + median + 1 );
 
 		return node;
@@ -224,7 +224,11 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 
 	this.root = buildTree( points, 0, null, 0 );
 		
-	this.getMaxDepth = function () { return maxDepth; };
+	this.getMaxDepth = function () {
+
+		return maxDepth;
+
+	};
 	
 	this.nearest = function ( point, maxNodes, maxDistance ) {
 	
@@ -240,15 +244,19 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 
 		bestNodes = new THREE.TypedArrayUtils.Kdtree.BinaryHeap(
 
-			function ( e ) { return -e[ 1 ]; }
+			function ( e ) {
 
-		);
+				return - e[ 1 ];
+
+			}
+
+					);
 
 		function nearestSearch( node ) {
 
 			var bestChild,
 				dimension = node.depth % eleSize,
-				ownDistance = metric(point, node.obj),
+				ownDistance = metric( point, node.obj ),
 				linearDistance = 0,
 				otherChild,
 				i,
@@ -330,7 +338,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
 
 			// if there's still room or the current distance is nearer than the best distance
 
-			if ( bestNodes.size() < maxNodes || Math.abs(linearDistance) < bestNodes.peek()[ 1 ] ) {
+			if ( bestNodes.size() < maxNodes || Math.abs( linearDistance ) < bestNodes.peek()[ 1 ] ) {
 
 				if ( bestChild === node.left ) {
 
@@ -591,4 +599,4 @@ THREE.TypedArrayUtils.Kdtree.BinaryHeap.prototype = {
 
 	}
 
-};
+};

+ 17 - 1
examples/js/UCSCharacter.js

@@ -38,6 +38,7 @@ THREE.UCSCharacter = function() {
 		var loader = new THREE.JSONLoader();
 		console.log( config.baseUrl + config.character );
 		loader.load( config.baseUrl + config.character, function( geometry ) {
+
 			geometry.computeBoundingBox();
 			geometry.computeVertexNormals();
 
@@ -56,28 +57,40 @@ THREE.UCSCharacter = function() {
 			animation = new THREE.Animation( mesh, geometry.animation );
 			animation.play();
 			
-			scope.setSkin(0);
+			scope.setSkin( 0 );
 			
 			scope.checkLoadComplete();
+
 		} );
 
 	};
 	
 	this.setSkin = function( index ) {
+
 		if ( mesh && scope.materials ) {
+
 			mesh.material = scope.materials[ index ];
+
 		}
+
 	};
 	
 	this.updateMorphs = function( influences ) {
+
 		if ( mesh ) {
+
 			for ( var i = 0; i < scope.numMorphs; i ++ ) {
+
 				mesh.morphTargetInfluences[ i ] = influences[ scope.morphs[ i ] ] / 100;
+
 			}
+
 		}
+
 	};
 	
 	function loadTextures( baseUrl, textureUrls ) {
+
 		var mapping = THREE.UVMapping;
 		var textures = [];
 
@@ -89,9 +102,11 @@ THREE.UCSCharacter = function() {
 		}
 
 		return textures;
+
 	}
 
 	function createMaterials( skins ) {
+
 		var materials = [];
 		
 		for ( var i = 0; i < skins.length; i ++ ) {
@@ -107,6 +122,7 @@ THREE.UCSCharacter = function() {
 		}
 		
 		return materials;
+
 	}
 
 	this.checkLoadComplete = function () {

+ 36 - 26
examples/js/WaterShader.js

@@ -7,7 +7,7 @@
  * @author Jonas Wagner / http://29a.ch/ && http://29a.ch/slides/2012/webglwater/ : Water shader explanations in WebGL
  */
 
-THREE.ShaderLib['water'] = {
+THREE.ShaderLib[ 'water' ] = {
 
 	uniforms: { "normalSampler":	{ type: "t", value: null },
 				"mirrorSampler":	{ type: "t", value: null },
@@ -35,7 +35,7 @@ THREE.ShaderLib['water'] = {
 		'	mirrorCoord = textureMatrix * mirrorCoord;',
 		'	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
 		'}'
-	].join('\n'),
+	].join( '\n' ),
 
 	fragmentShader: [
 		'precision highp float;',
@@ -98,7 +98,7 @@ THREE.ShaderLib['water'] = {
 		'	vec3 albedo = mix( sunColor * diffuseLight * 0.3 + scatter, ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance );',
 		'	gl_FragColor = vec4( albedo, alpha );',
 		'}'
-	].join('\n')
+	].join( '\n' )
 
 };
 
@@ -108,7 +108,9 @@ THREE.Water = function ( renderer, camera, scene, options ) {
 	this.name = 'water_' + this.id;
 
 	function optionalParameter ( value, defaultValue ) {
+
 		return value !== undefined ? value : defaultValue;
+
 	}
 
 	options = options || {};
@@ -134,15 +136,16 @@ THREE.Water = function ( renderer, camera, scene, options ) {
 	this.mirrorWorldPosition = new THREE.Vector3();
 	this.cameraWorldPosition = new THREE.Vector3();
 	this.rotationMatrix = new THREE.Matrix4();
-	this.lookAtPosition = new THREE.Vector3( 0, 0, -1 );
+	this.lookAtPosition = new THREE.Vector3( 0, 0, - 1 );
 	this.clipPlane = new THREE.Vector4();
 	
 	if ( camera instanceof THREE.PerspectiveCamera )
 		this.camera = camera;
-	else 
-	{
+	else {
+
 		this.camera = new THREE.PerspectiveCamera();
-		console.log(this.name + ': camera is not a Perspective Camera!')
+		console.log( this.name + ': camera is not a Perspective Camera!' )
+
 	}
 
 	this.textureMatrix = new THREE.Matrix4();
@@ -174,16 +177,18 @@ THREE.Water = function ( renderer, camera, scene, options ) {
 	
 	this.material.uniforms.eye.value = this.eye;
 	
-	if ( !THREE.Math.isPowerOfTwo(width) || !THREE.Math.isPowerOfTwo(height) )
-	{
+	if ( ! THREE.Math.isPowerOfTwo( width ) || ! THREE.Math.isPowerOfTwo( height ) ) {
+
 		this.texture.generateMipmaps = false;
 		this.texture.minFilter = THREE.LinearFilter;
 		this.tempTexture.generateMipmaps = false;
 		this.tempTexture.minFilter = THREE.LinearFilter;
+
 	}
 
 	this.updateTextureMatrix();
 	this.render();
+
 };
 
 THREE.Water.prototype = Object.create( THREE.Mirror.prototype );
@@ -192,7 +197,11 @@ THREE.Water.prototype.constructor = THREE.Water;
 
 THREE.Water.prototype.updateTextureMatrix = function () {
 
-	function sign(x) { return x ? x < 0 ? -1 : 1 : 0; }
+	function sign( x ) {
+
+		return x ? x < 0 ? - 1 : 1 : 0;
+
+	}
 
 	this.updateMatrixWorld();
 	this.camera.updateMatrixWorld();
@@ -211,7 +220,7 @@ THREE.Water.prototype.updateTextureMatrix = function () {
 
 	this.rotationMatrix.extractRotation( this.camera.matrixWorld );
 
-	this.lookAtPosition.set(0, 0, -1);
+	this.lookAtPosition.set( 0, 0, - 1 );
 	this.lookAtPosition.applyMatrix4( this.rotationMatrix );
 	this.lookAtPosition.add( this.cameraWorldPosition );
 
@@ -219,7 +228,7 @@ THREE.Water.prototype.updateTextureMatrix = function () {
 	target.reflect( this.normal ).negate();
 	target.add( this.mirrorWorldPosition );
 
-	this.up.set(0, -1, 0);
+	this.up.set( 0, - 1, 0 );
 	this.up.applyMatrix4( this.rotationMatrix );
 	this.up.reflect( this.normal ).negate();
 
@@ -230,43 +239,44 @@ THREE.Water.prototype.updateTextureMatrix = function () {
 
 	this.mirrorCamera.updateProjectionMatrix();
 	this.mirrorCamera.updateMatrixWorld();
-	this.mirrorCamera.matrixWorldInverse.getInverse(this.mirrorCamera.matrixWorld);
+	this.mirrorCamera.matrixWorldInverse.getInverse( this.mirrorCamera.matrixWorld );
 
 	// Update the texture matrix
 	this.textureMatrix.set( 0.5, 0.0, 0.0, 0.5,
 							0.0, 0.5, 0.0, 0.5,
 							0.0, 0.0, 0.5, 0.5,
 							0.0, 0.0, 0.0, 1.0 );
-	this.textureMatrix.multiply(this.mirrorCamera.projectionMatrix);
-	this.textureMatrix.multiply(this.mirrorCamera.matrixWorldInverse);
+	this.textureMatrix.multiply( this.mirrorCamera.projectionMatrix );
+	this.textureMatrix.multiply( this.mirrorCamera.matrixWorldInverse );
 
 	// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
 	// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
 	this.mirrorPlane.setFromNormalAndCoplanarPoint( this.normal, this.mirrorWorldPosition );
-	this.mirrorPlane.applyMatrix4(this.mirrorCamera.matrixWorldInverse);
+	this.mirrorPlane.applyMatrix4( this.mirrorCamera.matrixWorldInverse );
 
-	this.clipPlane.set(this.mirrorPlane.normal.x, this.mirrorPlane.normal.y, this.mirrorPlane.normal.z, this.mirrorPlane.constant );
+	this.clipPlane.set( this.mirrorPlane.normal.x, this.mirrorPlane.normal.y, this.mirrorPlane.normal.z, this.mirrorPlane.constant );
 
 	var q = new THREE.Vector4();
 	var projectionMatrix = this.mirrorCamera.projectionMatrix;
 
-	q.x = (sign(this.clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
-	q.y = (sign(this.clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
-	q.z = -1.0;
-	q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
+	q.x = ( sign( this.clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
+	q.y = ( sign( this.clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
+	q.z = - 1.0;
+	q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ];
 
 	// Calculate the scaled plane vector
 	var c = new THREE.Vector4();
-	c = this.clipPlane.multiplyScalar( 2.0 / this.clipPlane.dot(q) );
+	c = this.clipPlane.multiplyScalar( 2.0 / this.clipPlane.dot( q ) );
 
 	// Replacing the third row of the projection matrix
-	projectionMatrix.elements[2] = c.x;
-	projectionMatrix.elements[6] = c.y;
-	projectionMatrix.elements[10] = c.z + 1.0 - this.clipBias;
-	projectionMatrix.elements[14] = c.w;
+	projectionMatrix.elements[ 2 ] = c.x;
+	projectionMatrix.elements[ 6 ] = c.y;
+	projectionMatrix.elements[ 10 ] = c.z + 1.0 - this.clipBias;
+	projectionMatrix.elements[ 14 ] = c.w;
 	
 	var worldCoordinates = new THREE.Vector3();
 	worldCoordinates.setFromMatrixPosition( this.camera.matrixWorld );
 	this.eye = worldCoordinates;
 	this.material.uniforms.eye.value = this.eye;
+
 };

+ 7 - 6
examples/js/cameras/CombinedCamera.js

@@ -15,10 +15,10 @@ THREE.CombinedCamera = function ( width, height, fov, near, far, orthoNear, orth
 
 	this.fov = fov;
 
-	this.left = -width / 2;
+	this.left = - width / 2;
 	this.right = width / 2;
 	this.top = height / 2;
-	this.bottom = -height / 2;
+	this.bottom = - height / 2;
 
 	// We could also handle the projectionMatrix internally, but just wanted to test nested camera objects
 
@@ -73,10 +73,10 @@ THREE.CombinedCamera.prototype.toOrthographic = function () {
 	halfHeight /= this.zoom;
 	halfWidth /= this.zoom;
 
-	this.cameraO.left = -halfWidth;
+	this.cameraO.left = - halfWidth;
 	this.cameraO.right = halfWidth;
 	this.cameraO.top = halfHeight;
-	this.cameraO.bottom = -halfHeight;
+	this.cameraO.bottom = - halfHeight;
 
 	// this.cameraO.left = -farHalfWidth;
 	// this.cameraO.right = farHalfWidth;
@@ -103,10 +103,10 @@ THREE.CombinedCamera.prototype.toOrthographic = function () {
 THREE.CombinedCamera.prototype.setSize = function( width, height ) {
 
 	this.cameraP.aspect = width / height;
-	this.left = -width / 2;
+	this.left = - width / 2;
 	this.right = width / 2;
 	this.top = height / 2;
-	this.bottom = -height / 2;
+	this.bottom = - height / 2;
 
 };
 
@@ -158,6 +158,7 @@ THREE.CombinedCamera.prototype.setLens = function ( focalLength, frameHeight ) {
 	this.setFov( fov );
 
 	return fov;
+
 };
 
 

+ 8 - 7
examples/js/controls/DragControls.js

@@ -25,7 +25,7 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
 	var me = this;
 	this.on = function( event, handler ) {
 		
-		if ( !_listeners[ event ] ) _listeners[ event ] = [];
+		if ( ! _listeners[ event ] ) _listeners[ event ] = [];
 
 		_listeners[ event ].push( handler );
 		return me;
@@ -35,9 +35,9 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
 	this.off = function( event, handler ) {
 		
 		var l = _listeners[ event ];
-		if ( !l ) return me;
+		if ( ! l ) return me;
 
-		if ( l.indexOf( handler ) > -1 ) {
+		if ( l.indexOf( handler ) > - 1 ) {
 			
 			l.splice( handler, 1 );
 		
@@ -50,9 +50,9 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
 	var notify = function( event, data, member ) {
 			
 		var l = _listeners[ event ];
-		if ( !l ) return;
+		if ( ! l ) return;
 
-		if ( !member ) {
+		if ( ! member ) {
 					
 			for ( var i = 0; i < l.length; i ++ ) {
 						
@@ -103,7 +103,7 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
 		event.preventDefault();
 
 		_mouse.x = ( event.clientX / _domElement.width ) * 2 - 1;
-		_mouse.y = -( event.clientY / _domElement.height ) * 2 + 1;
+		_mouse.y = - ( event.clientY / _domElement.height ) * 2 + 1;
 
 		_raycaster.setFromCamera( _mouse, _camera );
 		var ray = _raycaster.ray;
@@ -118,6 +118,7 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
 
 			var denom = normal.dot( ray.direction );
 			if ( denom == 0 ) {
+
 				// bail
 				console.log( 'no or infinite solutions' );
 				return;
@@ -188,7 +189,7 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
 		event.preventDefault();
 
 		_mouse.x = ( event.clientX / _domElement.width ) * 2 - 1;
-		_mouse.y = -( event.clientY / _domElement.height ) * 2 + 1;
+		_mouse.y = - ( event.clientY / _domElement.height ) * 2 + 1;
 
 		_raycaster.setFromCamera( _mouse, _camera );
 		var intersects = _raycaster.intersectObjects( _objects );

+ 18 - 8
examples/js/controls/EditorControls.js

@@ -19,7 +19,7 @@ THREE.EditorControls = function ( object, domElement ) {
 	var scope = this;
 	var vector = new THREE.Vector3();
 
-	var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2 };
+	var STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2 };
 	var state = STATE.NONE;
 
 	var center = this.center;
@@ -39,7 +39,7 @@ THREE.EditorControls = function ( object, domElement ) {
 		if ( frame && target.geometry ) {
 
 			scale = ( scale.x + scale.y + scale.z ) / 3;
-			center.add(target.geometry.boundingSphere.center.clone().multiplyScalar( scale ));
+			center.add( target.geometry.boundingSphere.center.clone().multiplyScalar( scale ) );
 			var radius = target.geometry.boundingSphere.radius * ( scale );
 			var pos = object.position.clone().sub( center ).normalize().multiplyScalar( radius * 2 );
 			object.position.copy( center ).add( pos );
@@ -185,11 +185,15 @@ THREE.EditorControls = function ( object, domElement ) {
 
 		var delta = 0;
 
-		if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
+		if ( event.wheelDelta ) {
+
+			// WebKit / Opera / Explorer 9
 
 			delta = - event.wheelDelta;
 
-		} else if ( event.detail ) { // Firefox
+		} else if ( event.detail ) {
+
+			// Firefox
 
 			delta = event.detail * 10;
 
@@ -199,7 +203,11 @@ THREE.EditorControls = function ( object, domElement ) {
 
 	}
 
-	domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
+	domElement.addEventListener( 'contextmenu', function ( event ) {
+
+		event.preventDefault();
+
+	}, false );
 	domElement.addEventListener( 'mousedown', onMouseDown, false );
 	domElement.addEventListener( 'mousewheel', onMouseWheel, false );
 	domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
@@ -250,7 +258,9 @@ THREE.EditorControls = function ( object, domElement ) {
 			var closest = touches[ 0 ];
 
 			for ( var i in touches ) {
-				if ( closest.distanceTo(touch) > touches[ i ].distanceTo(touch) ) closest = touches[ i ];
+
+				if ( closest.distanceTo( touch ) > touches[ i ].distanceTo( touch ) ) closest = touches[ i ];
+
 			}
 
 			return closest;
@@ -275,8 +285,8 @@ THREE.EditorControls = function ( object, domElement ) {
 
 				var offset0 = touches[ 0 ].clone().sub( getClosest( touches[ 0 ], prevTouches ) );
 				var offset1 = touches[ 1 ].clone().sub( getClosest( touches[ 1 ], prevTouches ) );
-				offset0.x = -offset0.x;
-				offset1.x = -offset1.x;
+				offset0.x = - offset0.x;
+				offset1.x = - offset1.x;
 
 				scope.pan( offset0.add( offset1 ).multiplyScalar( 0.5 ) );
 

+ 8 - 4
examples/js/controls/FirstPersonControls.js

@@ -52,7 +52,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
 
 	if ( this.domElement !== document ) {
 
-		this.domElement.setAttribute( 'tabindex', -1 );
+		this.domElement.setAttribute( 'tabindex', - 1 );
 
 	}
 
@@ -203,7 +203,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
 
 		var actualMoveSpeed = delta * this.movementSpeed;
 
-		if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
+		if ( this.moveForward || ( this.autoForward && ! this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
 		if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
 
 		if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
@@ -214,7 +214,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
 
 		var actualLookSpeed = delta * this.lookSpeed;
 
-		if ( !this.activeLook ) {
+		if ( ! this.activeLook ) {
 
 			actualLookSpeed = 0;
 
@@ -254,7 +254,11 @@ THREE.FirstPersonControls = function ( object, domElement ) {
 	};
 
 
-	this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
+	this.domElement.addEventListener( 'contextmenu', function ( event ) {
+
+		event.preventDefault();
+
+	}, false );
 
 	this.domElement.addEventListener( 'mousemove', bind( this, this.onMouseMove ), false );
 	this.domElement.addEventListener( 'mousedown', bind( this, this.onMouseDown ), false );

+ 14 - 10
examples/js/controls/FlyControls.js

@@ -7,7 +7,7 @@ THREE.FlyControls = function ( object, domElement ) {
 	this.object = object;
 
 	this.domElement = ( domElement !== undefined ) ? domElement : document;
-	if ( domElement ) this.domElement.setAttribute( 'tabindex', -1 );
+	if ( domElement ) this.domElement.setAttribute( 'tabindex', - 1 );
 
 	// API
 
@@ -141,7 +141,7 @@ THREE.FlyControls = function ( object, domElement ) {
 
 	this.mousemove = function( event ) {
 
-		if ( !this.dragToLook || this.mouseStatus > 0 ) {
+		if ( ! this.dragToLook || this.mouseStatus > 0 ) {
 
 			var container = this.getContainerDimensions();
 			var halfWidth  = container.size[ 0 ] / 2;
@@ -204,11 +204,11 @@ THREE.FlyControls = function ( object, domElement ) {
 
 	this.updateMovementVector = function() {
 
-		var forward = ( this.moveState.forward || ( this.autoForward && !this.moveState.back ) ) ? 1 : 0;
+		var forward = ( this.moveState.forward || ( this.autoForward && ! this.moveState.back ) ) ? 1 : 0;
 
-		this.moveVector.x = ( -this.moveState.left    + this.moveState.right );
-		this.moveVector.y = ( -this.moveState.down    + this.moveState.up );
-		this.moveVector.z = ( -forward + this.moveState.back );
+		this.moveVector.x = ( - this.moveState.left    + this.moveState.right );
+		this.moveVector.y = ( - this.moveState.down    + this.moveState.up );
+		this.moveVector.z = ( - forward + this.moveState.back );
 
 		//console.log( 'move:', [ this.moveVector.x, this.moveVector.y, this.moveVector.z ] );
 
@@ -216,9 +216,9 @@ THREE.FlyControls = function ( object, domElement ) {
 
 	this.updateRotationVector = function() {
 
-		this.rotationVector.x = ( -this.moveState.pitchDown + this.moveState.pitchUp );
-		this.rotationVector.y = ( -this.moveState.yawRight  + this.moveState.yawLeft );
-		this.rotationVector.z = ( -this.moveState.rollRight + this.moveState.rollLeft );
+		this.rotationVector.x = ( - this.moveState.pitchDown + this.moveState.pitchUp );
+		this.rotationVector.y = ( - this.moveState.yawRight  + this.moveState.yawLeft );
+		this.rotationVector.z = ( - this.moveState.rollRight + this.moveState.rollLeft );
 
 		//console.log( 'rotate:', [ this.rotationVector.x, this.rotationVector.y, this.rotationVector.z ] );
 
@@ -254,7 +254,11 @@ THREE.FlyControls = function ( object, domElement ) {
 
 	}
 
-	this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
+	this.domElement.addEventListener( 'contextmenu', function ( event ) {
+
+		event.preventDefault();
+
+	}, false );
 
 	this.domElement.addEventListener( 'mousemove', bind( this, this.mousemove ), false );
 	this.domElement.addEventListener( 'mousedown', bind( this, this.mousedown ), false );

+ 7 - 7
examples/js/controls/MouseControls.js

@@ -9,9 +9,9 @@ THREE.MouseControls = function ( object ) {
 	var scope = this;
 	var PI_2 = Math.PI / 2;
 	var mouseQuat = {
-    x: new THREE.Quaternion(),
-    y: new THREE.Quaternion()
-  };
+		x: new THREE.Quaternion(),
+		y: new THREE.Quaternion()
+	};
 	var object = object;
 	var xVector = new THREE.Vector3( 1, 0, 0 );
 	var yVector = new THREE.Vector3( 0, 1, 0 );
@@ -35,9 +35,9 @@ THREE.MouseControls = function ( object ) {
 	this.enabled = true;
 
 	this.orientation = {
-    x: 0,
-    y: 0,
-  };
+		x: 0,
+		y: 0,
+	};
 
 	this.update = function() {
 
@@ -45,7 +45,7 @@ THREE.MouseControls = function ( object ) {
 
 		mouseQuat.x.setFromAxisAngle( xVector, this.orientation.x );
 		mouseQuat.y.setFromAxisAngle( yVector, this.orientation.y );
-		object.quaternion.copy(mouseQuat.y).multiply(mouseQuat.x);
+		object.quaternion.copy( mouseQuat.y ).multiply( mouseQuat.x );
 		return;
 
 	};

+ 646 - 417
examples/js/controls/OrbitControls.js

@@ -7,700 +7,929 @@
  */
 /*global THREE, console */
 
-// This set of controls performs orbiting, dollying (zooming), and panning. It maintains
-// the "up" direction as +Y, unlike the TrackballControls. Touch on tablet and phones is
-// supported.
-//
-//    Orbit - left mouse / touch: one finger move
-//    Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
-//    Pan - right mouse, or arrow keys / touch: three finter swipe
+( function () {
 
-THREE.OrbitControls = function ( object, domElement ) {
+	function OrbitConstraint ( object ) {
 
-	this.object = object;
-	this.domElement = ( domElement !== undefined ) ? domElement : document;
+		this.object = object;
 
-	// API
+		// "target" sets the location of focus, where the object orbits around
+		// and where it pans with respect to.
+		this.target = new THREE.Vector3();
 
-	// Set to false to disable this control
-	this.enabled = true;
+		// Limits to how far you can dolly in and out ( PerspectiveCamera only )
+		this.minDistance = 0;
+		this.maxDistance = Infinity;
 
-	// "target" sets the location of focus, where the control orbits around
-	// and where it pans with respect to.
-	this.target = new THREE.Vector3();
+		// Limits to how far you can zoom in and out ( OrthographicCamera only )
+		this.minZoom = 0;
+		this.maxZoom = Infinity;
 
-	// center is old, deprecated; use "target" instead
-	this.center = this.target;
+		// How far you can orbit vertically, upper and lower limits.
+		// Range is 0 to Math.PI radians.
+		this.minPolarAngle = 0; // radians
+		this.maxPolarAngle = Math.PI; // radians
 
-	// This option actually enables dollying in and out; left as "zoom" for
-	// backwards compatibility
-	this.noZoom = false;
-	this.zoomSpeed = 1.0;
+		// How far you can orbit horizontally, upper and lower limits.
+		// If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
+		this.minAzimuthAngle = - Infinity; // radians
+		this.maxAzimuthAngle = Infinity; // radians
 
-	// Limits to how far you can dolly in and out ( PerspectiveCamera only )
-	this.minDistance = 0;
-	this.maxDistance = Infinity;
+		////////////
+		// internals
 
-	// Limits to how far you can zoom in and out ( OrthographicCamera only )
-	this.minZoom = 0;
-	this.maxZoom = Infinity;
+		var scope = this;
 
-	// Set to true to disable this control
-	this.noRotate = false;
-	this.rotateSpeed = 1.0;
+		var EPS = 0.000001;
 
-	// Set to true to disable this control
-	this.noPan = false;
-	this.keyPanSpeed = 7.0;	// pixels moved per arrow key push
+		// Current position in spherical coordinate system.
+		var theta;
+		var phi;
 
-	// Set to true to automatically rotate around the target
-	this.autoRotate = false;
-	this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
+		// Pending changes
+		var phiDelta = 0;
+		var thetaDelta = 0;
+		var scale = 1;
+		var panOffset = new THREE.Vector3();
+		var zoomChanged = false;
 
-	// How far you can orbit vertically, upper and lower limits.
-	// Range is 0 to Math.PI radians.
-	this.minPolarAngle = 0; // radians
-	this.maxPolarAngle = Math.PI; // radians
+		// API
 
-	// How far you can orbit horizontally, upper and lower limits.
-	// If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
-	this.minAzimuthAngle = - Infinity; // radians
-	this.maxAzimuthAngle = Infinity; // radians
+		this.getPolarAngle = function () {
 
-	// Set to true to disable use of the keys
-	this.noKeys = false;
+			return phi;
 
-	// The four arrow keys
-	this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
+		};
 
-	// Mouse buttons
-	this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
+		this.getAzimuthalAngle = function () {
 
-	////////////
-	// internals
+			return theta;
 
-	var scope = this;
+		};
 
-	var EPS = 0.000001;
+		this.rotateLeft = function ( angle ) {
 
-	var rotateStart = new THREE.Vector2();
-	var rotateEnd = new THREE.Vector2();
-	var rotateDelta = new THREE.Vector2();
+			thetaDelta -= angle;
 
-	var panStart = new THREE.Vector2();
-	var panEnd = new THREE.Vector2();
-	var panDelta = new THREE.Vector2();
-	var panOffset = new THREE.Vector3();
+		};
 
-	var offset = new THREE.Vector3();
+		this.rotateUp = function ( angle ) {
 
-	var dollyStart = new THREE.Vector2();
-	var dollyEnd = new THREE.Vector2();
-	var dollyDelta = new THREE.Vector2();
+			phiDelta -= angle;
 
-	var theta;
-	var phi;
-	var phiDelta = 0;
-	var thetaDelta = 0;
-	var scale = 1;
-	var pan = new THREE.Vector3();
+		};
 
-	var lastPosition = new THREE.Vector3();
-	var lastQuaternion = new THREE.Quaternion();
+		// pass in distance in world space to move left
+		this.panLeft = function() {
 
-	var STATE = { NONE : -1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
+			var v = new THREE.Vector3();
 
-	var state = STATE.NONE;
+			return function panLeft ( distance ) {
 
-	// for reset
+				var te = this.object.matrix.elements;
 
-	this.target0 = this.target.clone();
-	this.position0 = this.object.position.clone();
-	this.zoom0 = this.object.zoom;
+				// get X column of matrix
+				v.set( te[ 0 ], te[ 1 ], te[ 2 ] );
+				v.multiplyScalar( - distance );
 
-	// so camera.up is the orbit axis
+				panOffset.add( v );
 
-	var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
-	var quatInverse = quat.clone().inverse();
+			};
 
-	// events
+		}();
 
-	var changeEvent = { type: 'change' };
-	var startEvent = { type: 'start' };
-	var endEvent = { type: 'end' };
+		// pass in distance in world space to move up
+		this.panUp = function() {
 
-	this.rotateLeft = function ( angle ) {
+			var v = new THREE.Vector3();
 
-		if ( angle === undefined ) {
+			return function panUp ( distance ) {
 
-			angle = getAutoRotationAngle();
+				var te = this.object.matrix.elements;
 
-		}
+				// get Y column of matrix
+				v.set( te[ 4 ], te[ 5 ], te[ 6 ] );
+				v.multiplyScalar( distance );
 
-		thetaDelta -= angle;
+				panOffset.add( v );
 
-	};
+			};
 
-	this.rotateUp = function ( angle ) {
+		}();
 
-		if ( angle === undefined ) {
+		// pass in x,y of change desired in pixel space,
+		// right and down are positive
+		this.pan = function ( deltaX, deltaY, screenWidth, screenHeight ) {
 
-			angle = getAutoRotationAngle();
+			if ( scope.object instanceof THREE.PerspectiveCamera ) {
 
-		}
+				// perspective
+				var position = scope.object.position;
+				var offset = position.clone().sub( scope.target );
+				var targetDistance = offset.length();
 
-		phiDelta -= angle;
+				// half of the fov is center to top of screen
+				targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
 
-	};
+				// we actually don't use screenWidth, since perspective camera is fixed to screen height
+				scope.panLeft( 2 * deltaX * targetDistance / screenHeight );
+				scope.panUp( 2 * deltaY * targetDistance / screenHeight );
 
-	// pass in distance in world space to move left
-	this.panLeft = function ( distance ) {
+			} else if ( scope.object instanceof THREE.OrthographicCamera ) {
 
-		var te = this.object.matrix.elements;
+				// orthographic
+				scope.panLeft( deltaX * ( scope.object.right - scope.object.left ) / screenWidth );
+				scope.panUp( deltaY * ( scope.object.top - scope.object.bottom ) / screenHeight );
 
-		// get X column of matrix
-		panOffset.set( te[ 0 ], te[ 1 ], te[ 2 ] );
-		panOffset.multiplyScalar( - distance );
+			} else {
 
-		pan.add( panOffset );
+				// camera neither orthographic or perspective
+				console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
 
-	};
+			}
 
-	// pass in distance in world space to move up
-	this.panUp = function ( distance ) {
+		};
 
-		var te = this.object.matrix.elements;
+		this.dollyIn = function ( dollyScale ) {
 
-		// get Y column of matrix
-		panOffset.set( te[ 4 ], te[ 5 ], te[ 6 ] );
-		panOffset.multiplyScalar( distance );
+			if ( scope.object instanceof THREE.PerspectiveCamera ) {
 
-		pan.add( panOffset );
+				scale /= dollyScale;
 
-	};
+			} else if ( scope.object instanceof THREE.OrthographicCamera ) {
 
-	// pass in x,y of change desired in pixel space,
-	// right and down are positive
-	this.pan = function ( deltaX, deltaY ) {
+				scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom * dollyScale ) );
+				scope.object.updateProjectionMatrix();
+				zoomChanged = true;
 
-		var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
+			} else {
 
-		if ( scope.object instanceof THREE.PerspectiveCamera ) {
+				console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
 
-			// perspective
-			var position = scope.object.position;
-			var offset = position.clone().sub( scope.target );
-			var targetDistance = offset.length();
+			}
 
-			// half of the fov is center to top of screen
-			targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
+		};
 
-			// we actually don't use screenWidth, since perspective camera is fixed to screen height
-			scope.panLeft( 2 * deltaX * targetDistance / element.clientHeight );
-			scope.panUp( 2 * deltaY * targetDistance / element.clientHeight );
+		this.dollyOut = function ( dollyScale ) {
 
-		} else if ( scope.object instanceof THREE.OrthographicCamera ) {
+			if ( scope.object instanceof THREE.PerspectiveCamera ) {
 
-			// orthographic
-			scope.panLeft( deltaX * (scope.object.right - scope.object.left) / element.clientWidth );
-			scope.panUp( deltaY * (scope.object.top - scope.object.bottom) / element.clientHeight );
+				scale *= dollyScale;
 
-		} else {
+			} else if ( scope.object instanceof THREE.OrthographicCamera ) {
 
-			// camera neither orthographic or perspective
-			console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
+				scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / dollyScale ) );
+				scope.object.updateProjectionMatrix();
+				zoomChanged = true;
 
-		}
+			} else {
 
-	};
+				console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
 
-	this.dollyIn = function ( dollyScale ) {
+			}
 
-		if ( dollyScale === undefined ) {
+		};
 
-			dollyScale = getZoomScale();
+		this.update = function() {
 
-		}
+			var offset = new THREE.Vector3();
 
-		if ( scope.object instanceof THREE.PerspectiveCamera ) {
+			// so camera.up is the orbit axis
+			var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
+			var quatInverse = quat.clone().inverse();
 
-			scale /= dollyScale;
+			var lastPosition = new THREE.Vector3();
+			var lastQuaternion = new THREE.Quaternion();
 
-		} else if ( scope.object instanceof THREE.OrthographicCamera ) {
+			return function () {
 
-			scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom * dollyScale ) );
-			scope.object.updateProjectionMatrix();
-			scope.dispatchEvent( changeEvent );
+				var position = this.object.position;
 
-		} else {
+				offset.copy( position ).sub( this.target );
 
-			console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
+				// rotate offset to "y-axis-is-up" space
+				offset.applyQuaternion( quat );
 
-		}
+				// angle from z-axis around y-axis
 
-	};
+				theta = Math.atan2( offset.x, offset.z );
 
-	this.dollyOut = function ( dollyScale ) {
+				// angle from y-axis
 
-		if ( dollyScale === undefined ) {
+				phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
 
-			dollyScale = getZoomScale();
+				theta += thetaDelta;
+				phi += phiDelta;
 
-		}
+				// restrict theta to be between desired limits
+				theta = Math.max( this.minAzimuthAngle, Math.min( this.maxAzimuthAngle, theta ) );
 
-		if ( scope.object instanceof THREE.PerspectiveCamera ) {
+				// restrict phi to be between desired limits
+				phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
 
-			scale *= dollyScale;
+				// restrict phi to be betwee EPS and PI-EPS
+				phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
 
-		} else if ( scope.object instanceof THREE.OrthographicCamera ) {
+				var radius = offset.length() * scale;
 
-			scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / dollyScale ) );
-			scope.object.updateProjectionMatrix();
-			scope.dispatchEvent( changeEvent );
+				// restrict radius to be between desired limits
+				radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
 
-		} else {
+				// move target to panned location
+				this.target.add( panOffset );
 
-			console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
+				offset.x = radius * Math.sin( phi ) * Math.sin( theta );
+				offset.y = radius * Math.cos( phi );
+				offset.z = radius * Math.sin( phi ) * Math.cos( theta );
 
-		}
+				// rotate offset back to "camera-up-vector-is-up" space
+				offset.applyQuaternion( quatInverse );
 
-	};
+				position.copy( this.target ).add( offset );
 
-	this.update = function () {
+				this.object.lookAt( this.target );
 
-		var position = this.object.position;
+				thetaDelta = 0;
+				phiDelta = 0;
+				scale = 1;
+				panOffset.set( 0, 0, 0 );
 
-		offset.copy( position ).sub( this.target );
+				// update condition is:
+				// min(camera displacement, camera rotation in radians)^2 > EPS
+				// using small-angle approximation cos(x/2) = 1 - x^2 / 8
 
-		// rotate offset to "y-axis-is-up" space
-		offset.applyQuaternion( quat );
+				if ( zoomChanged ||
+					 lastPosition.distanceToSquared( this.object.position ) > EPS ||
+				    8 * ( 1 - lastQuaternion.dot( this.object.quaternion ) ) > EPS ) {
 
-		// angle from z-axis around y-axis
+					lastPosition.copy( this.object.position );
+					lastQuaternion.copy( this.object.quaternion );
+					zoomChanged = false;
 
-		theta = Math.atan2( offset.x, offset.z );
+					return true;
 
-		// angle from y-axis
+				}
 
-		phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
+				return false;
 
-		if ( this.autoRotate && state === STATE.NONE ) {
+			};
 
-			this.rotateLeft( getAutoRotationAngle() );
+		}();
 
-		}
+	};
 
-		theta += thetaDelta;
-		phi += phiDelta;
 
-		// restrict theta to be between desired limits
-		theta = Math.max( this.minAzimuthAngle, Math.min( this.maxAzimuthAngle, theta ) );
+	// This set of controls performs orbiting, dollying (zooming), and panning. It maintains
+	// the "up" direction as +Y, unlike the TrackballControls. Touch on tablet and phones is
+	// supported.
+	//
+	//    Orbit - left mouse / touch: one finger move
+	//    Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
+	//    Pan - right mouse, or arrow keys / touch: three finter swipe
 
-		// restrict phi to be between desired limits
-		phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
+	THREE.OrbitControls = function ( object, domElement ) {
 
-		// restrict phi to be betwee EPS and PI-EPS
-		phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
+		var constraint = new OrbitConstraint( object );
 
-		var radius = offset.length() * scale;
+		this.domElement = ( domElement !== undefined ) ? domElement : document;
 
-		// restrict radius to be between desired limits
-		radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
+		// API
 
-		// move target to panned location
-		this.target.add( pan );
+		Object.defineProperty( this, 'constraint', {
 
-		offset.x = radius * Math.sin( phi ) * Math.sin( theta );
-		offset.y = radius * Math.cos( phi );
-		offset.z = radius * Math.sin( phi ) * Math.cos( theta );
+			get: function() {
 
-		// rotate offset back to "camera-up-vector-is-up" space
-		offset.applyQuaternion( quatInverse );
+				return constraint;
 
-		position.copy( this.target ).add( offset );
+			}
 
-		this.object.lookAt( this.target );
+		} );
 
-		thetaDelta = 0;
-		phiDelta = 0;
-		scale = 1;
-		pan.set( 0, 0, 0 );
+		this.getPolarAngle = function () {
 
-		// update condition is:
-		// min(camera displacement, camera rotation in radians)^2 > EPS
-		// using small-angle approximation cos(x/2) = 1 - x^2 / 8
+			return constraint.phi;
 
-		if ( lastPosition.distanceToSquared( this.object.position ) > EPS
-		    || 8 * (1 - lastQuaternion.dot(this.object.quaternion)) > EPS ) {
+		};
 
-			this.dispatchEvent( changeEvent );
+		this.getAzimuthalAngle = function () {
 
-			lastPosition.copy( this.object.position );
-			lastQuaternion.copy (this.object.quaternion );
+			return constraint.theta;
 
-		}
+		};
 
-	};
+		// Set to false to disable this control
+		this.enabled = true;
 
+		// center is old, deprecated; use "target" instead
+		this.center = this.target;
 
-	this.reset = function () {
+		// This option actually enables dollying in and out; left as "zoom" for
+		// backwards compatibility
+		this.noZoom = false;
+		this.zoomSpeed = 1.0;
 
-		state = STATE.NONE;
+		// Set to true to disable this control
+		this.noRotate = false;
+		this.rotateSpeed = 1.0;
 
-		this.target.copy( this.target0 );
-		this.object.position.copy( this.position0 );
-		this.object.zoom = this.zoom0;
+		// Set to true to disable this control
+		this.noPan = false;
+		this.keyPanSpeed = 7.0;	// pixels moved per arrow key push
 
-		this.object.updateProjectionMatrix();
-		this.dispatchEvent( changeEvent );
+		// Set to true to automatically rotate around the target
+		this.autoRotate = false;
+		this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
 
-		this.update();
+		// Set to true to disable use of the keys
+		this.noKeys = false;
 
-	};
+		// The four arrow keys
+		this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
 
-	this.getPolarAngle = function () {
+		// Mouse buttons
+		this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
 
-		return phi;
+		////////////
+		// internals
 
-	};
+		var scope = this;
 
-	this.getAzimuthalAngle = function () {
+		var rotateStart = new THREE.Vector2();
+		var rotateEnd = new THREE.Vector2();
+		var rotateDelta = new THREE.Vector2();
 
-		return theta
+		var panStart = new THREE.Vector2();
+		var panEnd = new THREE.Vector2();
+		var panDelta = new THREE.Vector2();
 
-	};
+		var dollyStart = new THREE.Vector2();
+		var dollyEnd = new THREE.Vector2();
+		var dollyDelta = new THREE.Vector2();
+
+		var STATE = { NONE : - 1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
+
+		var state = STATE.NONE;
+
+		// for reset
+
+		this.target0 = this.target.clone();
+		this.position0 = this.object.position.clone();
+		this.zoom0 = this.object.zoom;
+
+		// events
 
-	function getAutoRotationAngle() {
+		var changeEvent = { type: 'change' };
+		var startEvent = { type: 'start' };
+		var endEvent = { type: 'end' };
 
-		return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
+		// pass in x,y of change desired in pixel space,
+		// right and down are positive
+		function pan( deltaX, deltaY ) {
 
-	}
+			var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
 
-	function getZoomScale() {
+			constraint.pan( deltaX, deltaY, element.clientWidth, element.clientHeight );
 
-		return Math.pow( 0.95, scope.zoomSpeed );
+		}
+
+		this.update = function() {
+
+			if ( this.autoRotate && state === STATE.NONE ) {
+
+				constraint.rotateLeft( getAutoRotationAngle() );
+
+			}
 
-	}
+			if ( constraint.update() === true ) {
 
-	function onMouseDown( event ) {
+				this.dispatchEvent( changeEvent );
 
-		if ( scope.enabled === false ) return;
-		event.preventDefault();
+			}
 
-		if ( event.button === scope.mouseButtons.ORBIT ) {
-			if ( scope.noRotate === true ) return;
+		};
 
-			state = STATE.ROTATE;
+		this.reset = function () {
 
-			rotateStart.set( event.clientX, event.clientY );
+			state = STATE.NONE;
 
-		} else if ( event.button === scope.mouseButtons.ZOOM ) {
-			if ( scope.noZoom === true ) return;
+			this.target.copy( this.target0 );
+			this.object.position.copy( this.position0 );
+			this.object.zoom = this.zoom0;
 
-			state = STATE.DOLLY;
+			this.object.updateProjectionMatrix();
+			this.dispatchEvent( changeEvent );
 
-			dollyStart.set( event.clientX, event.clientY );
+			this.update();
 
-		} else if ( event.button === scope.mouseButtons.PAN ) {
-			if ( scope.noPan === true ) return;
+		};
 
-			state = STATE.PAN;
+		function getAutoRotationAngle() {
 
-			panStart.set( event.clientX, event.clientY );
+			return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
 
 		}
 
-		if ( state !== STATE.NONE ) {
-			document.addEventListener( 'mousemove', onMouseMove, false );
-			document.addEventListener( 'mouseup', onMouseUp, false );
-			scope.dispatchEvent( startEvent );
+		function getZoomScale() {
+
+			return Math.pow( 0.95, scope.zoomSpeed );
+
 		}
 
-	}
+		function onMouseDown( event ) {
 
-	function onMouseMove( event ) {
+			if ( scope.enabled === false ) return;
 
-		if ( scope.enabled === false ) return;
+			event.preventDefault();
 
-		event.preventDefault();
+			if ( event.button === scope.mouseButtons.ORBIT ) {
 
-		var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
+				if ( scope.noRotate === true ) return;
 
-		if ( state === STATE.ROTATE ) {
+				state = STATE.ROTATE;
 
-			if ( scope.noRotate === true ) return;
+				rotateStart.set( event.clientX, event.clientY );
 
-			rotateEnd.set( event.clientX, event.clientY );
-			rotateDelta.subVectors( rotateEnd, rotateStart );
+			} else if ( event.button === scope.mouseButtons.ZOOM ) {
 
-			// rotating across whole screen goes 360 degrees around
-			scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
+				if ( scope.noZoom === true ) return;
 
-			// rotating up and down along whole screen attempts to go 360, but limited to 180
-			scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
+				state = STATE.DOLLY;
 
-			rotateStart.copy( rotateEnd );
+				dollyStart.set( event.clientX, event.clientY );
 
-		} else if ( state === STATE.DOLLY ) {
+			} else if ( event.button === scope.mouseButtons.PAN ) {
 
-			if ( scope.noZoom === true ) return;
+				if ( scope.noPan === true ) return;
 
-			dollyEnd.set( event.clientX, event.clientY );
-			dollyDelta.subVectors( dollyEnd, dollyStart );
+				state = STATE.PAN;
 
-			if ( dollyDelta.y > 0 ) {
+				panStart.set( event.clientX, event.clientY );
 
-				scope.dollyIn();
+			}
 
-			} else if ( dollyDelta.y < 0 ) {
+			if ( state !== STATE.NONE ) {
 
-				scope.dollyOut();
+				document.addEventListener( 'mousemove', onMouseMove, false );
+				document.addEventListener( 'mouseup', onMouseUp, false );
+				scope.dispatchEvent( startEvent );
 
 			}
 
-			dollyStart.copy( dollyEnd );
+		}
+
+		function onMouseMove( event ) {
 
-		} else if ( state === STATE.PAN ) {
+			if ( scope.enabled === false ) return;
 
-			if ( scope.noPan === true ) return;
+			event.preventDefault();
 
-			panEnd.set( event.clientX, event.clientY );
-			panDelta.subVectors( panEnd, panStart );
+			var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
 
-			scope.pan( panDelta.x, panDelta.y );
+			if ( state === STATE.ROTATE ) {
 
-			panStart.copy( panEnd );
+				if ( scope.noRotate === true ) return;
+
+				rotateEnd.set( event.clientX, event.clientY );
+				rotateDelta.subVectors( rotateEnd, rotateStart );
+
+				// rotating across whole screen goes 360 degrees around
+				constraint.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
+
+				// rotating up and down along whole screen attempts to go 360, but limited to 180
+				constraint.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
+
+				rotateStart.copy( rotateEnd );
+
+			} else if ( state === STATE.DOLLY ) {
+
+				if ( scope.noZoom === true ) return;
+
+				dollyEnd.set( event.clientX, event.clientY );
+				dollyDelta.subVectors( dollyEnd, dollyStart );
+
+				if ( dollyDelta.y > 0 ) {
+
+					contraint.dollyIn( getZoomScale() );
+
+				} else if ( dollyDelta.y < 0 ) {
+
+					contraint.dollyOut( getZoomScale() );
+
+				}
+
+				dollyStart.copy( dollyEnd );
+
+			} else if ( state === STATE.PAN ) {
+
+				if ( scope.noPan === true ) return;
+
+				panEnd.set( event.clientX, event.clientY );
+				panDelta.subVectors( panEnd, panStart );
+
+				pan( panDelta.x, panDelta.y );
+
+				panStart.copy( panEnd );
+
+			}
+
+			if ( state !== STATE.NONE ) scope.update();
 
 		}
 
-		if ( state !== STATE.NONE ) scope.update();
+		function onMouseUp( /* event */ ) {
 
-	}
+			if ( scope.enabled === false ) return;
 
-	function onMouseUp( /* event */ ) {
+			document.removeEventListener( 'mousemove', onMouseMove, false );
+			document.removeEventListener( 'mouseup', onMouseUp, false );
+			scope.dispatchEvent( endEvent );
+			state = STATE.NONE;
 
-		if ( scope.enabled === false ) return;
+		}
+
+		function onMouseWheel( event ) {
+
+			if ( scope.enabled === false || scope.noZoom === true || state !== STATE.NONE ) return;
 
-		document.removeEventListener( 'mousemove', onMouseMove, false );
-		document.removeEventListener( 'mouseup', onMouseUp, false );
-		scope.dispatchEvent( endEvent );
-		state = STATE.NONE;
+			event.preventDefault();
+			event.stopPropagation();
 
-	}
+			var delta = 0;
 
-	function onMouseWheel( event ) {
+			if ( event.wheelDelta !== undefined ) {
 
-		if ( scope.enabled === false || scope.noZoom === true || state !== STATE.NONE ) return;
+				// WebKit / Opera / Explorer 9
 
-		event.preventDefault();
-		event.stopPropagation();
+				delta = event.wheelDelta;
 
-		var delta = 0;
+			} else if ( event.detail !== undefined ) {
 
-		if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
+				// Firefox
+
+				delta = - event.detail;
+
+			}
 
-			delta = event.wheelDelta;
+			if ( delta > 0 ) {
 
-		} else if ( event.detail !== undefined ) { // Firefox
+				constraint.dollyOut( getZoomScale() );
 
-			delta = - event.detail;
+			} else if ( delta < 0 ) {
+
+				constraint.dollyIn( getZoomScale() );
+
+			}
+
+			scope.update();
+			scope.dispatchEvent( startEvent );
+			scope.dispatchEvent( endEvent );
 
 		}
 
-		if ( delta > 0 ) {
+		function onKeyDown( event ) {
+
+			if ( scope.enabled === false || scope.noKeys === true || scope.noPan === true ) return;
 
-			scope.dollyOut();
+			switch ( event.keyCode ) {
 
-		} else if ( delta < 0 ) {
+				case scope.keys.UP:
+					pan( 0, scope.keyPanSpeed );
+					scope.update();
+					break;
 
-			scope.dollyIn();
+				case scope.keys.BOTTOM:
+					pan( 0, - scope.keyPanSpeed );
+					scope.update();
+					break;
+
+				case scope.keys.LEFT:
+					pan( scope.keyPanSpeed, 0 );
+					scope.update();
+					break;
+
+				case scope.keys.RIGHT:
+					pan( - scope.keyPanSpeed, 0 );
+					scope.update();
+					break;
+
+			}
 
 		}
 
-		scope.update();
-		scope.dispatchEvent( startEvent );
-		scope.dispatchEvent( endEvent );
+		function touchstart( event ) {
+
+			if ( scope.enabled === false ) return;
+
+			switch ( event.touches.length ) {
 
-	}
+				case 1:	// one-fingered touch: rotate
 
-	function onKeyDown( event ) {
+					if ( scope.noRotate === true ) return;
 
-		if ( scope.enabled === false || scope.noKeys === true || scope.noPan === true ) return;
+					state = STATE.TOUCH_ROTATE;
 
-		switch ( event.keyCode ) {
+					rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
+					break;
 
-			case scope.keys.UP:
-				scope.pan( 0, scope.keyPanSpeed );
-				scope.update();
-				break;
+				case 2:	// two-fingered touch: dolly
 
-			case scope.keys.BOTTOM:
-				scope.pan( 0, - scope.keyPanSpeed );
-				scope.update();
-				break;
+					if ( scope.noZoom === true ) return;
 
-			case scope.keys.LEFT:
-				scope.pan( scope.keyPanSpeed, 0 );
-				scope.update();
-				break;
+					state = STATE.TOUCH_DOLLY;
 
-			case scope.keys.RIGHT:
-				scope.pan( - scope.keyPanSpeed, 0 );
-				scope.update();
-				break;
+					var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
+					var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
+					var distance = Math.sqrt( dx * dx + dy * dy );
+					dollyStart.set( 0, distance );
+					break;
+
+				case 3: // three-fingered touch: pan
+
+					if ( scope.noPan === true ) return;
+
+					state = STATE.TOUCH_PAN;
+
+					panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
+					break;
+
+				default:
+
+					state = STATE.NONE;
+
+			}
+
+			if ( state !== STATE.NONE ) scope.dispatchEvent( startEvent );
 
 		}
 
-	}
+		function touchmove( event ) {
 
-	function touchstart( event ) {
+			if ( scope.enabled === false ) return;
 
-		if ( scope.enabled === false ) return;
+			event.preventDefault();
+			event.stopPropagation();
 
-		switch ( event.touches.length ) {
+			var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
 
-			case 1:	// one-fingered touch: rotate
+			switch ( event.touches.length ) {
 
-				if ( scope.noRotate === true ) return;
+				case 1: // one-fingered touch: rotate
 
-				state = STATE.TOUCH_ROTATE;
+					if ( scope.noRotate === true ) return;
+					if ( state !== STATE.TOUCH_ROTATE ) return;
 
-				rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
-				break;
+					rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
+					rotateDelta.subVectors( rotateEnd, rotateStart );
 
-			case 2:	// two-fingered touch: dolly
+					// rotating across whole screen goes 360 degrees around
+					constraint.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
+					// rotating up and down along whole screen attempts to go 360, but limited to 180
+					constraint.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
 
-				if ( scope.noZoom === true ) return;
+					rotateStart.copy( rotateEnd );
 
-				state = STATE.TOUCH_DOLLY;
+					scope.update();
+					break;
 
-				var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
-				var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
-				var distance = Math.sqrt( dx * dx + dy * dy );
-				dollyStart.set( 0, distance );
-				break;
+				case 2: // two-fingered touch: dolly
 
-			case 3: // three-fingered touch: pan
+					if ( scope.noZoom === true ) return;
+					if ( state !== STATE.TOUCH_DOLLY ) return;
 
-				if ( scope.noPan === true ) return;
+					var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
+					var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
+					var distance = Math.sqrt( dx * dx + dy * dy );
+
+					dollyEnd.set( 0, distance );
+					dollyDelta.subVectors( dollyEnd, dollyStart );
+
+					if ( dollyDelta.y > 0 ) {
+
+						constraint.dollyOut( getZoomScale() );
+
+					} else if ( dollyDelta.y < 0 ) {
+
+						constraint.dollyIn( getZoomScale() );
+
+					}
+
+					dollyStart.copy( dollyEnd );
+
+					scope.update();
+					break;
+
+				case 3: // three-fingered touch: pan
+
+					if ( scope.noPan === true ) return;
+					if ( state !== STATE.TOUCH_PAN ) return;
+
+					panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
+					panDelta.subVectors( panEnd, panStart );
+
+					pan( panDelta.x, panDelta.y );
+
+					panStart.copy( panEnd );
+
+					scope.update();
+					break;
 
-				state = STATE.TOUCH_PAN;
+				default:
 
-				panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
-				break;
+					state = STATE.NONE;
 
-			default:
+			}
+
+		}
+
+		function touchend( /* event */ ) {
 
-				state = STATE.NONE;
+			if ( scope.enabled === false ) return;
+
+			scope.dispatchEvent( endEvent );
+			state = STATE.NONE;
 
 		}
 
-		if ( state !== STATE.NONE ) scope.dispatchEvent( startEvent );
+		this.domElement.addEventListener( 'contextmenu', function ( event ) {
 
-	}
+			event.preventDefault();
 
-	function touchmove( event ) {
+		}, false );
+		this.domElement.addEventListener( 'mousedown', onMouseDown, false );
+		this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
+		this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
 
-		if ( scope.enabled === false ) return;
+		this.domElement.addEventListener( 'touchstart', touchstart, false );
+		this.domElement.addEventListener( 'touchend', touchend, false );
+		this.domElement.addEventListener( 'touchmove', touchmove, false );
 
-		event.preventDefault();
-		event.stopPropagation();
+		window.addEventListener( 'keydown', onKeyDown, false );
 
-		var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
+		// force an update at start
+		this.update();
 
-		switch ( event.touches.length ) {
+	};
 
-			case 1: // one-fingered touch: rotate
+	THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
+	THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
 
-				if ( scope.noRotate === true ) return;
-				if ( state !== STATE.TOUCH_ROTATE ) return;
+	Object.defineProperties( THREE.OrbitControls.prototype, {
 
-				rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
-				rotateDelta.subVectors( rotateEnd, rotateStart );
+		object: {
 
-				// rotating across whole screen goes 360 degrees around
-				scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
-				// rotating up and down along whole screen attempts to go 360, but limited to 180
-				scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
+			get: function () {
 
-				rotateStart.copy( rotateEnd );
+				return this.constraint.object;
 
-				scope.update();
-				break;
+			}
 
-			case 2: // two-fingered touch: dolly
+		},
 
-				if ( scope.noZoom === true ) return;
-				if ( state !== STATE.TOUCH_DOLLY ) return;
+		target: {
 
-				var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
-				var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
-				var distance = Math.sqrt( dx * dx + dy * dy );
+			get: function () {
 
-				dollyEnd.set( 0, distance );
-				dollyDelta.subVectors( dollyEnd, dollyStart );
+				return this.constraint.target;
 
-				if ( dollyDelta.y > 0 ) {
+			},
 
-					scope.dollyOut();
+			set: function ( value ) {
 
-				} else if ( dollyDelta.y < 0 ) {
+				console.warn( 'THREE.OrbitControls: target is now immutable. Use target.set() instead.' );
+				this.constraint.target.copy( value );
 
-					scope.dollyIn();
+			}
 
-				}
+		},
 
-				dollyStart.copy( dollyEnd );
+		minDistance : {
 
-				scope.update();
-				break;
+			get: function () {
 
-			case 3: // three-fingered touch: pan
+				return this.constraint.minDistance;
 
-				if ( scope.noPan === true ) return;
-				if ( state !== STATE.TOUCH_PAN ) return;
+			},
 
-				panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
-				panDelta.subVectors( panEnd, panStart );
+			set: function ( value ) {
 
-				scope.pan( panDelta.x, panDelta.y );
+				this.constraint.minDistance = value;
 
-				panStart.copy( panEnd );
+			}
 
-				scope.update();
-				break;
+		},
 
-			default:
+		maxDistance : {
 
-				state = STATE.NONE;
+			get: function () {
 
-		}
+				return this.constraint.maxDistance;
 
-	}
+			},
 
-	function touchend( /* event */ ) {
+			set: function ( value ) {
 
-		if ( scope.enabled === false ) return;
+				this.constraint.maxDistance = value;
 
-		scope.dispatchEvent( endEvent );
-		state = STATE.NONE;
+			}
 
-	}
+		},
 
-	this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
-	this.domElement.addEventListener( 'mousedown', onMouseDown, false );
-	this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
-	this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
+		minZoom : {
 
-	this.domElement.addEventListener( 'touchstart', touchstart, false );
-	this.domElement.addEventListener( 'touchend', touchend, false );
-	this.domElement.addEventListener( 'touchmove', touchmove, false );
+			get: function () {
 
-	window.addEventListener( 'keydown', onKeyDown, false );
+				return this.constraint.minZoom;
 
-	// force an update at start
-	this.update();
+			},
+
+			set: function ( value ) {
+
+				this.constraint.minZoom = value;
+
+			}
+
+		},
+
+		maxZoom : {
+
+			get: function () {
+
+				return this.constraint.maxZoom;
+
+			},
+
+			set: function ( value ) {
+
+				this.constraint.maxZoom = value;
+
+			}
+
+		},
+
+		minPolarAngle : {
+
+			get: function () {
+
+				return this.constraint.minPolarAngle;
+
+			},
+
+			set: function ( value ) {
+
+				this.constraint.minPolarAngle = value;
+
+			}
+
+		},
+
+		maxPolarAngle : {
+
+			get: function () {
+
+				return this.constraint.maxPolarAngle;
+
+			},
+
+			set: function ( value ) {
+
+				this.constraint.maxPolarAngle = value;
+
+			}
+
+		},
+
+		minAzimuthAngle : {
+
+			get: function () {
+
+				return this.constraint.minAzimuthAngle;
+
+			},
+
+			set: function ( value ) {
+
+				this.constraint.minAzimuthAngle = value;
+
+			}
+
+		},
+
+		maxAzimuthAngle : {
+
+			get: function () {
+
+				return this.constraint.maxAzimuthAngle;
+
+			},
+
+			set: function ( value ) {
+
+				this.constraint.maxAzimuthAngle = value;
+
+			}
+
+		}
 
-};
+	} );
 
-THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
-THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
+}() );

+ 33 - 23
examples/js/controls/OrthographicTrackballControls.js

@@ -8,7 +8,7 @@
 THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 	var _this = this;
-	var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
+	var STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
 
 	this.object = object;
 	this.domElement = ( domElement !== undefined ) ? domElement : document;
@@ -186,7 +186,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 	}() );
 
-	this.rotateCamera = (function() {
+	this.rotateCamera = ( function() {
 
 		var axis = new THREE.Vector3(),
 			quaternion = new THREE.Quaternion();
@@ -202,7 +202,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 				angle *= _this.rotateSpeed;
 
-				quaternion.setFromAxisAngle( axis, -angle );
+				quaternion.setFromAxisAngle( axis, - angle );
 
 				_eye.applyQuaternion( quaternion );
 				_this.object.up.applyQuaternion( quaternion );
@@ -223,9 +223,10 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 				_changed = true;
 
 			}
+
 		}
 
-	}());
+	}() );
 
 	this.zoomCamera = function () {
 
@@ -264,7 +265,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 	};
 
-	this.panCamera = (function() {
+	this.panCamera = ( function() {
 
 		var mouseChange = new THREE.Vector2(),
 			objectUp = new THREE.Vector3(),
@@ -301,21 +302,22 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 				_changed = true;
 
 			}
+
 		}
 
-	}());
+	}() );
 
 	this.update = function () {
 
 		_eye.subVectors( _this.object.position, _this.target );
 
-		if ( !_this.noRotate ) {
+		if ( ! _this.noRotate ) {
 
 			_this.rotateCamera();
 
 		}
 
-		if ( !_this.noZoom ) {
+		if ( ! _this.noZoom ) {
 
 			_this.zoomCamera();
 
@@ -327,7 +329,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 		}
 
-		if ( !_this.noPan ) {
+		if ( ! _this.noPan ) {
 
 			_this.panCamera();
 
@@ -385,15 +387,15 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 			return;
 
-		} else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && !_this.noRotate ) {
+		} else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && ! _this.noRotate ) {
 
 			_state = STATE.ROTATE;
 
-		} else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && !_this.noZoom ) {
+		} else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && ! _this.noZoom ) {
 
 			_state = STATE.ZOOM;
 
-		} else if ( event.keyCode === _this.keys[ STATE.PAN ] && !_this.noPan ) {
+		} else if ( event.keyCode === _this.keys[ STATE.PAN ] && ! _this.noPan ) {
 
 			_state = STATE.PAN;
 
@@ -424,20 +426,20 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 		}
 
-		if ( _state === STATE.ROTATE && !_this.noRotate ) {
+		if ( _state === STATE.ROTATE && ! _this.noRotate ) {
 
 			_rotateStart.copy( getMouseProjectionOnBall( event.pageX, event.pageY ) );
 			_rotateEnd.copy( _rotateStart );
 
-		} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
+		} else if ( _state === STATE.ZOOM && ! _this.noZoom ) {
 
 			_zoomStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
-			_zoomEnd.copy(_zoomStart);
+			_zoomEnd.copy( _zoomStart );
 
-		} else if ( _state === STATE.PAN && !_this.noPan ) {
+		} else if ( _state === STATE.PAN && ! _this.noPan ) {
 
 			_panStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
-			_panEnd.copy(_panStart)
+			_panEnd.copy( _panStart )
 
 		}
 
@@ -455,15 +457,15 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 		event.preventDefault();
 		event.stopPropagation();
 
-		if ( _state === STATE.ROTATE && !_this.noRotate ) {
+		if ( _state === STATE.ROTATE && ! _this.noRotate ) {
 
 			_rotateEnd.copy( getMouseProjectionOnBall( event.pageX, event.pageY ) );
 
-		} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
+		} else if ( _state === STATE.ZOOM && ! _this.noZoom ) {
 
 			_zoomEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
 
-		} else if ( _state === STATE.PAN && !_this.noPan ) {
+		} else if ( _state === STATE.PAN && ! _this.noPan ) {
 
 			_panEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
 
@@ -495,11 +497,15 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 		var delta = 0;
 
-		if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
+		if ( event.wheelDelta ) {
+
+			// WebKit / Opera / Explorer 9
 
 			delta = event.wheelDelta / 40;
 
-		} else if ( event.detail ) { // Firefox
+		} else if ( event.detail ) {
+
+			// Firefox
 
 			delta = - event.detail / 3;
 
@@ -600,7 +606,11 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
 
 	}
 
-	this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
+	this.domElement.addEventListener( 'contextmenu', function ( event ) {
+
+		event.preventDefault();
+
+	}, false );
 
 	this.domElement.addEventListener( 'mousedown', mousedown, false );
 

+ 1 - 1
examples/js/controls/PointerLockControls.js

@@ -45,7 +45,7 @@ THREE.PointerLockControls = function ( camera ) {
 
 		// assumes the camera itself is not rotated
 
-		var direction = new THREE.Vector3( 0, 0, -1 );
+		var direction = new THREE.Vector3( 0, 0, - 1 );
 		var rotation = new THREE.Euler( 0, 0, 0, "YXZ" );
 
 		return function( v ) {

+ 39 - 29
examples/js/controls/TrackballControls.js

@@ -8,7 +8,7 @@
 THREE.TrackballControls = function ( object, domElement ) {
 
 	var _this = this;
-	var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
+	var STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
 
 	this.object = object;
 	this.domElement = ( domElement !== undefined ) ? domElement : document;
@@ -140,11 +140,12 @@ THREE.TrackballControls = function ( object, domElement ) {
 			);
 
 			return vector;
+
 		};
 
 	}() );
 
-	this.rotateCamera = (function() {
+	this.rotateCamera = ( function() {
 
 		var axis = new THREE.Vector3(),
 			quaternion = new THREE.Quaternion(),
@@ -183,7 +184,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 				_lastAxis.copy( axis );
 				_lastAngle = angle;
 
-			} else if ( !_this.staticMoving && _lastAngle ) {
+			} else if ( ! _this.staticMoving && _lastAngle ) {
 
 				_lastAngle *= Math.sqrt( 1.0 - _this.dynamicDampingFactor );
 				_eye.copy( _this.object.position ).sub( _this.target );
@@ -197,7 +198,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		};
 
-	}());
+	}() );
 
 
 	this.zoomCamera = function () {
@@ -234,7 +235,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 	};
 
-	this.panCamera = (function() {
+	this.panCamera = ( function() {
 
 		var mouseChange = new THREE.Vector2(),
 			objectUp = new THREE.Vector3(),
@@ -265,13 +266,14 @@ THREE.TrackballControls = function ( object, domElement ) {
 				}
 
 			}
+
 		};
 
-	}());
+	}() );
 
 	this.checkDistances = function () {
 
-		if ( !_this.noZoom || !_this.noPan ) {
+		if ( ! _this.noZoom || ! _this.noPan ) {
 
 			if ( _eye.lengthSq() > _this.maxDistance * _this.maxDistance ) {
 
@@ -295,19 +297,19 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		_eye.subVectors( _this.object.position, _this.target );
 
-		if ( !_this.noRotate ) {
+		if ( ! _this.noRotate ) {
 
 			_this.rotateCamera();
 
 		}
 
-		if ( !_this.noZoom ) {
+		if ( ! _this.noZoom ) {
 
 			_this.zoomCamera();
 
 		}
 
-		if ( !_this.noPan ) {
+		if ( ! _this.noPan ) {
 
 			_this.panCamera();
 
@@ -362,15 +364,15 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 			return;
 
-		} else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && !_this.noRotate ) {
+		} else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && ! _this.noRotate ) {
 
 			_state = STATE.ROTATE;
 
-		} else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && !_this.noZoom ) {
+		} else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && ! _this.noZoom ) {
 
 			_state = STATE.ZOOM;
 
-		} else if ( event.keyCode === _this.keys[ STATE.PAN ] && !_this.noPan ) {
+		} else if ( event.keyCode === _this.keys[ STATE.PAN ] && ! _this.noPan ) {
 
 			_state = STATE.PAN;
 
@@ -401,20 +403,20 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		}
 
-		if ( _state === STATE.ROTATE && !_this.noRotate ) {
+		if ( _state === STATE.ROTATE && ! _this.noRotate ) {
 
 			_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
-			_movePrev.copy(_moveCurr);
+			_movePrev.copy( _moveCurr );
 
-		} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
+		} else if ( _state === STATE.ZOOM && ! _this.noZoom ) {
 
 			_zoomStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
-			_zoomEnd.copy(_zoomStart);
+			_zoomEnd.copy( _zoomStart );
 
-		} else if ( _state === STATE.PAN && !_this.noPan ) {
+		} else if ( _state === STATE.PAN && ! _this.noPan ) {
 
 			_panStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
-			_panEnd.copy(_panStart);
+			_panEnd.copy( _panStart );
 
 		}
 
@@ -432,16 +434,16 @@ THREE.TrackballControls = function ( object, domElement ) {
 		event.preventDefault();
 		event.stopPropagation();
 
-		if ( _state === STATE.ROTATE && !_this.noRotate ) {
+		if ( _state === STATE.ROTATE && ! _this.noRotate ) {
 
-			_movePrev.copy(_moveCurr);
+			_movePrev.copy( _moveCurr );
 			_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
 
-		} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
+		} else if ( _state === STATE.ZOOM && ! _this.noZoom ) {
 
 			_zoomEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
 
-		} else if ( _state === STATE.PAN && !_this.noPan ) {
+		} else if ( _state === STATE.PAN && ! _this.noPan ) {
 
 			_panEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
 
@@ -473,11 +475,15 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		var delta = 0;
 
-		if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
+		if ( event.wheelDelta ) {
+
+			// WebKit / Opera / Explorer 9
 
 			delta = event.wheelDelta / 40;
 
-		} else if ( event.detail ) { // Firefox
+		} else if ( event.detail ) {
+
+			// Firefox
 
 			delta = - event.detail / 3;
 
@@ -498,7 +504,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 			case 1:
 				_state = STATE.TOUCH_ROTATE;
 				_moveCurr.copy( getMouseOnCircle( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
-				_movePrev.copy(_moveCurr);
+				_movePrev.copy( _moveCurr );
 				break;
 
 			case 2:
@@ -532,7 +538,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 		switch ( event.touches.length ) {
 
 			case 1:
-				_movePrev.copy(_moveCurr);
+				_movePrev.copy( _moveCurr );
 				_moveCurr.copy( getMouseOnCircle(  event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
 				break;
 
@@ -560,7 +566,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 		switch ( event.touches.length ) {
 
 			case 1:
-				_movePrev.copy(_moveCurr);
+				_movePrev.copy( _moveCurr );
 				_moveCurr.copy( getMouseOnCircle(  event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
 				break;
 
@@ -580,7 +586,11 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 	}
 
-	this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
+	this.domElement.addEventListener( 'contextmenu', function ( event ) {
+
+		event.preventDefault();
+
+	}, false );
 
 	this.domElement.addEventListener( 'mousedown', mousedown, false );
 

+ 87 - 79
examples/js/controls/TransformControls.js

@@ -3,7 +3,7 @@
  */
  /*jshint sub:true*/
 
-(function () {
+( function () {
 
 	'use strict';
 
@@ -95,9 +95,9 @@
 			this.pickers = new THREE.Object3D();
 			this.planes = new THREE.Object3D();
 
-			this.add(this.handles);
-			this.add(this.pickers);
-			this.add(this.planes);
+			this.add( this.handles );
+			this.add( this.pickers );
+			this.add( this.planes );
 
 			//// PLANES
 
@@ -111,15 +111,17 @@
 				"XYZE": new THREE.Mesh( planeGeometry, planeMaterial )
 			};
 
-			this.activePlane = planes["XYZE"];
+			this.activePlane = planes[ "XYZE" ];
 
-			planes["YZ"].rotation.set( 0, Math.PI / 2, 0 );
-			planes["XZ"].rotation.set( -Math.PI / 2, 0, 0 );
+			planes[ "YZ" ].rotation.set( 0, Math.PI / 2, 0 );
+			planes[ "XZ" ].rotation.set( - Math.PI / 2, 0, 0 );
+
+			for ( var i in planes ) {
+
+				planes[ i ].name = i;
+				this.planes.add( planes[ i ] );
+				this.planes[ i ] = planes[ i ];
 
-			for (var i in planes) {
-				planes[i].name = i;
-				this.planes.add(planes[i]);
-				this.planes[i] = planes[i];
 			}
 
 			//// HANDLES AND PICKERS
@@ -128,16 +130,16 @@
 
 				for ( var name in gizmoMap ) {
 
-					for ( i = gizmoMap[name].length; i --;) {
+					for ( i = gizmoMap[ name ].length; i --; ) {
 
-						var object = gizmoMap[name][i][0];
-						var position = gizmoMap[name][i][1];
-						var rotation = gizmoMap[name][i][2];
+						var object = gizmoMap[ name ][ i ][ 0 ];
+						var position = gizmoMap[ name ][ i ][ 1 ];
+						var rotation = gizmoMap[ name ][ i ][ 2 ];
 
 						object.name = name;
 
-						if ( position ) object.position.set( position[0], position[1], position[2] );
-						if ( rotation ) object.rotation.set( rotation[0], rotation[1], rotation[2] );
+						if ( position ) object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
+						if ( rotation ) object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
 
 						parent.add( object );
 
@@ -147,14 +149,14 @@
 
 			};
 
-			setupGizmos(this.handleGizmos, this.handles);
-			setupGizmos(this.pickerGizmos, this.pickers);
+			setupGizmos( this.handleGizmos, this.handles );
+			setupGizmos( this.pickerGizmos, this.pickers );
 
 			// reset Transformations
 
-			this.traverse(function ( child ) {
+			this.traverse( function ( child ) {
 
-				if (child instanceof THREE.Mesh) {
+				if ( child instanceof THREE.Mesh ) {
 
 					child.updateMatrix();
 
@@ -168,7 +170,7 @@
 
 				}
 
-			});
+			} );
 
 		};
 
@@ -205,13 +207,13 @@
 		var vec2 = new THREE.Vector3( 0, 1, 0 );
 		var lookAtMatrix = new THREE.Matrix4();
 
-		this.traverse( function(child) {
+		this.traverse( function( child ) {
 
-			if ( child.name.search("E") !== -1 ) {
+			if ( child.name.search( "E" ) !== - 1 ) {
 
 				child.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( eye, vec1, vec2 ) );
 
-			} else if ( child.name.search("X") !== -1 || child.name.search("Y") !== -1 || child.name.search("Z") !== -1 ) {
+			} else if ( child.name.search( "X" ) !== - 1 || child.name.search( "Y" ) !== - 1 || child.name.search( "Z" ) !== - 1 ) {
 
 				child.quaternion.setFromEuler( rotation );
 
@@ -244,7 +246,7 @@
 		this.handleGizmos = {
 
 			X: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
+				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ],
 				[ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
 			],
 
@@ -271,7 +273,7 @@
 			],
 
 			XZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.15, 0, 0.15 ], [ -Math.PI / 2, 0, 0 ] ]
+				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ] ]
 			]
 
 		};
@@ -279,7 +281,7 @@
 		this.pickerGizmos = {
 
 			X: [
-				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ]
+				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
 			],
 
 			Y: [
@@ -303,7 +305,7 @@
 			],
 
 			XZ: [
-				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), pickerMaterial ), [ 0.2, 0, 0.2 ], [ -Math.PI / 2, 0, 0 ] ]
+				[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), pickerMaterial ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ] ]
 			]
 
 		};
@@ -317,7 +319,7 @@
 
 				this.activePlane = this.planes[ "XY" ];
 
-				if ( Math.abs(eye.y) > Math.abs(eye.z) ) this.activePlane = this.planes[ "XZ" ];
+				if ( Math.abs( eye.y ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "XZ" ];
 
 			}
 
@@ -325,7 +327,7 @@
 
 				this.activePlane = this.planes[ "XY" ];
 
-				if ( Math.abs(eye.x) > Math.abs(eye.z) ) this.activePlane = this.planes[ "YZ" ];
+				if ( Math.abs( eye.x ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "YZ" ];
 
 			}
 
@@ -333,7 +335,7 @@
 
 				this.activePlane = this.planes[ "XZ" ];
 
-				if ( Math.abs(eye.x) > Math.abs(eye.y) ) this.activePlane = this.planes[ "YZ" ];
+				if ( Math.abs( eye.x ) > Math.abs( eye.y ) ) this.activePlane = this.planes[ "YZ" ];
 
 			}
 
@@ -380,23 +382,23 @@
 		this.handleGizmos = {
 
 			X: [
-				[ new THREE.Line( new CircleGeometry(1,'x',0.5), new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
+				[ new THREE.Line( new CircleGeometry( 1, 'x', 0.5 ), new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
 			],
 
 			Y: [
-				[ new THREE.Line( new CircleGeometry(1,'y',0.5), new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
+				[ new THREE.Line( new CircleGeometry( 1, 'y', 0.5 ), new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
 			],
 
 			Z: [
-				[ new THREE.Line( new CircleGeometry(1,'z',0.5), new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
+				[ new THREE.Line( new CircleGeometry( 1, 'z', 0.5 ), new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
 			],
 
 			E: [
-				[ new THREE.Line( new CircleGeometry(1.25,'z',1), new GizmoLineMaterial( { color: 0xcccc00 } ) ) ]
+				[ new THREE.Line( new CircleGeometry( 1.25, 'z', 1 ), new GizmoLineMaterial( { color: 0xcccc00 } ) ) ]
 			],
 
 			XYZE: [
-				[ new THREE.Line( new CircleGeometry(1,'z',1), new GizmoLineMaterial( { color: 0x787878 } ) ) ]
+				[ new THREE.Line( new CircleGeometry( 1, 'z', 1 ), new GizmoLineMaterial( { color: 0x787878 } ) ) ]
 			]
 
 		};
@@ -404,7 +406,7 @@
 		this.pickerGizmos = {
 
 			X: [
-				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, -Math.PI / 2, -Math.PI / 2 ] ]
+				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ] ]
 			],
 
 			Y: [
@@ -412,7 +414,7 @@
 			],
 
 			Z: [
-				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ]
+				[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
 			],
 
 			E: [
@@ -443,8 +445,8 @@
 
 			var group = {
 
-				handles: this["handles"],
-				pickers: this["pickers"],
+				handles: this[ "handles" ],
+				pickers: this[ "pickers" ],
 
 			};
 
@@ -459,19 +461,19 @@
 			var quaternionZ = new THREE.Quaternion();
 			var eye = eye2.clone();
 
-			worldRotation.copy( this.planes["XY"].rotation );
+			worldRotation.copy( this.planes[ "XY" ].rotation );
 			tempQuaternion.setFromEuler( worldRotation );
 
 			tempMatrix.makeRotationFromQuaternion( tempQuaternion ).getInverse( tempMatrix );
 			eye.applyMatrix4( tempMatrix );
 
-			this.traverse(function(child) {
+			this.traverse( function( child ) {
 
 				tempQuaternion.setFromEuler( worldRotation );
 
 				if ( child.name === "X" ) {
 
-					quaternionX.setFromAxisAngle( unitX, Math.atan2( -eye.y, eye.z ) );
+					quaternionX.setFromAxisAngle( unitX, Math.atan2( - eye.y, eye.z ) );
 					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
 					child.quaternion.copy( tempQuaternion );
 
@@ -493,7 +495,7 @@
 
 				}
 
-			});
+			} );
 
 		};
 
@@ -527,7 +529,7 @@
 		this.handleGizmos = {
 
 			X: [
-				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ],
+				[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ],
 				[ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
 			],
 
@@ -550,7 +552,7 @@
 		this.pickerGizmos = {
 
 			X: [
-				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI / 2 ] ]
+				[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
 			],
 
 			Y: [
@@ -573,18 +575,24 @@
 			eye.applyMatrix4( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
 
 			if ( axis === "X" ) {
+
 				this.activePlane = this.planes[ "XY" ];
-				if ( Math.abs(eye.y) > Math.abs(eye.z) ) this.activePlane = this.planes[ "XZ" ];
+				if ( Math.abs( eye.y ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "XZ" ];
+
 			}
 
 			if ( axis === "Y" ) {
+
 				this.activePlane = this.planes[ "XY" ];
-				if ( Math.abs(eye.x) > Math.abs(eye.z) ) this.activePlane = this.planes[ "YZ" ];
+				if ( Math.abs( eye.x ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "YZ" ];
+
 			}
 
 			if ( axis === "Z" ) {
+
 				this.activePlane = this.planes[ "XZ" ];
-				if ( Math.abs(eye.x) > Math.abs(eye.y) ) this.activePlane = this.planes[ "YZ" ];
+				if ( Math.abs( eye.x ) > Math.abs( eye.y ) ) this.activePlane = this.planes[ "YZ" ];
+
 			}
 
 			if ( axis === "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
@@ -626,9 +634,9 @@
 			"scale": new THREE.TransformGizmoScale()
 		};
 
-		for (var type in _gizmo) {
+		for ( var type in _gizmo ) {
 
-			var gizmoObj = _gizmo[type];
+			var gizmoObj = _gizmo[ type ];
 
 			gizmoObj.visible = ( type === _mode );
 			this.add( gizmoObj );
@@ -735,7 +743,7 @@
 
 			if ( _mode === "scale" ) scope.space = "local";
 
-			for (var type in _gizmo) _gizmo[type].visible = ( type === _mode );
+			for ( var type in _gizmo ) _gizmo[ type ].visible = ( type === _mode );
 
 			this.update();
 			scope.dispatchEvent( changeEvent );
@@ -784,15 +792,15 @@
 
 			if ( scope.space === "local" ) {
 
-				_gizmo[_mode].update( worldRotation, eye );
+				_gizmo[ _mode ].update( worldRotation, eye );
 
 			} else if ( scope.space === "world" ) {
 
-				_gizmo[_mode].update( new THREE.Euler(), eye );
+				_gizmo[ _mode ].update( new THREE.Euler(), eye );
 
 			}
 
-			_gizmo[_mode].highlight( scope.axis );
+			_gizmo[ _mode ].highlight( scope.axis );
 
 		};
 
@@ -802,7 +810,7 @@
 
 			var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
 
-			var intersect = intersectObjects( pointer, _gizmo[_mode].pickers.children );
+			var intersect = intersectObjects( pointer, _gizmo[ _mode ].pickers.children );
 
 			var axis = null;
 
@@ -832,7 +840,7 @@
 
 			if ( pointer.button === 0 || pointer.button === undefined ) {
 
-				var intersect = intersectObjects( pointer, _gizmo[_mode].pickers.children );
+				var intersect = intersectObjects( pointer, _gizmo[ _mode ].pickers.children );
 
 				if ( intersect ) {
 
@@ -847,9 +855,9 @@
 
 					eye.copy( camPosition ).sub( worldPosition ).normalize();
 
-					_gizmo[_mode].setActivePlane( scope.axis, eye );
+					_gizmo[ _mode ].setActivePlane( scope.axis, eye );
 
-					var planeIntersect = intersectObjects( pointer, [ _gizmo[_mode].activePlane ] );
+					var planeIntersect = intersectObjects( pointer, [ _gizmo[ _mode ].activePlane ] );
 
 					if ( planeIntersect ) {
 
@@ -878,9 +886,9 @@
 
 			if ( scope.object === undefined || scope.axis === null || _dragging === false ) return;
 
-			var pointer = event.changedTouches ? event.changedTouches[0] : event;
+			var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
 
-			var planeIntersect = intersectObjects( pointer, [ _gizmo[_mode].activePlane ] );
+			var planeIntersect = intersectObjects( pointer, [ _gizmo[ _mode ].activePlane ] );
 
 			if ( planeIntersect === false ) return;
 
@@ -892,15 +900,15 @@
 			if ( _mode === "translate" ) {
 
 				point.sub( offset );
-				point.multiply(parentScale);
+				point.multiply( parentScale );
 
 				if ( scope.space === "local" ) {
 
 					point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
 
-					if ( scope.axis.search("X") === -1 ) point.x = 0;
-					if ( scope.axis.search("Y") === -1 ) point.y = 0;
-					if ( scope.axis.search("Z") === -1 ) point.z = 0;
+					if ( scope.axis.search( "X" ) === - 1 ) point.x = 0;
+					if ( scope.axis.search( "Y" ) === - 1 ) point.y = 0;
+					if ( scope.axis.search( "Z" ) === - 1 ) point.z = 0;
 
 					point.applyMatrix4( oldRotationMatrix );
 
@@ -909,11 +917,11 @@
 
 				}
 
-				if ( scope.space === "world" || scope.axis.search("XYZ") !== -1 ) {
+				if ( scope.space === "world" || scope.axis.search( "XYZ" ) !== - 1 ) {
 
-					if ( scope.axis.search("X") === -1 ) point.x = 0;
-					if ( scope.axis.search("Y") === -1 ) point.y = 0;
-					if ( scope.axis.search("Z") === -1 ) point.z = 0;
+					if ( scope.axis.search( "X" ) === - 1 ) point.x = 0;
+					if ( scope.axis.search( "Y" ) === - 1 ) point.y = 0;
+					if ( scope.axis.search( "Z" ) === - 1 ) point.z = 0;
 
 					point.applyMatrix4( tempMatrix.getInverse( parentRotationMatrix ) );
 
@@ -924,20 +932,20 @@
 
 				if ( scope.snap !== null ) {
 
-					if ( scope.axis.search("X") !== -1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.snap ) * scope.snap;
-					if ( scope.axis.search("Y") !== -1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.snap ) * scope.snap;
-					if ( scope.axis.search("Z") !== -1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.snap ) * scope.snap;
+					if ( scope.axis.search( "X" ) !== - 1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.snap ) * scope.snap;
+					if ( scope.axis.search( "Y" ) !== - 1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.snap ) * scope.snap;
+					if ( scope.axis.search( "Z" ) !== - 1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.snap ) * scope.snap;
 
 				}
 
 			} else if ( _mode === "scale" ) {
 
 				point.sub( offset );
-				point.multiply(parentScale);
+				point.multiply( parentScale );
 
 				if ( scope.space === "local" ) {
 
-					if ( scope.axis === "XYZ") {
+					if ( scope.axis === "XYZ" ) {
 
 						scale = 1 + ( ( point.y ) / 50 );
 
@@ -984,10 +992,10 @@
 
 				} else if ( scope.axis === "XYZE" ) {
 
-					quaternionE.setFromEuler( point.clone().cross(tempVector).normalize() ); // rotation axis
+					quaternionE.setFromEuler( point.clone().cross( tempVector ).normalize() ); // rotation axis
 
 					tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
-					quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo(tempVector) );
+					quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo( tempVector ) );
 					quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
 
 					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
@@ -1069,7 +1077,7 @@
 			ray.setFromCamera( pointerVector, camera );
 
 			var intersections = ray.intersectObjects( objects, true );
-			return intersections[0] ? intersections[0] : false;
+			return intersections[ 0 ] ? intersections[ 0 ] : false;
 
 		}
 
@@ -1078,4 +1086,4 @@
 	THREE.TransformControls.prototype = Object.create( THREE.Object3D.prototype );
 	THREE.TransformControls.prototype.constructor = THREE.TransformControls;
 
-}());
+}() );

+ 2 - 2
examples/js/controls/VRControls.js

@@ -15,7 +15,7 @@ THREE.VRControls = function ( object, onError ) {
 
 		var oculusDevices = devices.filter( function ( device ) {
 
-			return device.deviceName.toLowerCase().indexOf('oculus') !== -1;
+			return device.deviceName.toLowerCase().indexOf( 'oculus' ) !== - 1;
 
 		} );
 
@@ -23,7 +23,7 @@ THREE.VRControls = function ( object, onError ) {
 
 			return devices.filter( function ( device ) {
 
-				return device.deviceName.toLowerCase().indexOf('cardboard') === -1;
+				return device.deviceName.toLowerCase().indexOf( 'cardboard' ) === - 1;
 
 			} );
 

+ 14 - 14
examples/js/crossfade/gui.js

@@ -12,28 +12,28 @@ function initGUI() {
 	
 	var gui = new dat.GUI();
 
-	gui.add(transitionParams, "useTexture").onChange(function(value) {
+	gui.add( transitionParams, "useTexture" ).onChange( function( value ) {
 		
-		transition.useTexture(value);
+		transition.useTexture( value );
 		
-	});
+	} );
 	
-	gui.add(transitionParams, 'loopTexture');
+	gui.add( transitionParams, 'loopTexture' );
 	
-	gui.add(transitionParams, 'texture', { Perlin: 0, Squares: 1, Cells: 2, Distort: 3, Gradient: 4, Radial: 5 } ).onChange(function(value) {
+	gui.add( transitionParams, 'texture', { Perlin: 0, Squares: 1, Cells: 2, Distort: 3, Gradient: 4, Radial: 5 } ).onChange( function( value ) {
 		
-		transition.setTexture(value);
+		transition.setTexture( value );
 		
-	}).listen();
+	} ).listen();
 		
-	gui.add(transitionParams, "textureThreshold", 0, 1, 0.01).onChange(function(value) {
+	gui.add( transitionParams, "textureThreshold", 0, 1, 0.01 ).onChange( function( value ) {
 		
-		transition.setTextureThreshold(value);
+		transition.setTextureThreshold( value );
 		
-	});
+	} );
 
-	gui.add(transitionParams, "animateTransition");
-	gui.add(transitionParams, "transition", 0, 1, 0.01).listen();
-	gui.add(transitionParams, "transitionSpeed", 0.5, 5, 0.01);
+	gui.add( transitionParams, "animateTransition" );
+	gui.add( transitionParams, "transition", 0, 1, 0.01 ).listen();
+	gui.add( transitionParams, "transitionSpeed", 0.5, 5, 0.01 );
 	
-}
+}

+ 10 - 8
examples/js/crossfade/scenes.js

@@ -1,4 +1,4 @@
-function generateGeometry(objectType, numObjects) {
+function generateGeometry( objectType, numObjects ) {
 
 	var geometry = new THREE.Geometry();
 
@@ -38,18 +38,19 @@ function generateGeometry(objectType, numObjects) {
 
 		scale.x = Math.random() * 200 + 100;
 
-		if ( objectType == "cube" )
-		{
+		if ( objectType == "cube" ) {
+
 			geom = new THREE.BoxGeometry( 1, 1, 1 );
 			scale.y = Math.random() * 200 + 100;
 			scale.z = Math.random() * 200 + 100;
 			color.setRGB( 0, 0, Math.random() + 0.1 );
-		}
-		else if ( objectType == "sphere" )
-		{
+
+		} else if ( objectType == "sphere" ) {
+
 			geom = new THREE.IcosahedronGeometry( 1, 1 );
 			scale.y = scale.z = scale.x;
 			color.setRGB( Math.random() + 0.1, 0, 0 );
+
 		}
 
 		// give the geom's vertices a random color, to be displayed
@@ -85,7 +86,7 @@ function Scene ( type, numObjects, cameraZ, fov, rotationSpeed, clearColor ) {
 	this.scene.add( light );
 
 	this.rotationSpeed = rotationSpeed;
-	defaultMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors	} );
+	defaultMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors	} );
 	this.mesh = new THREE.Mesh( generateGeometry( type, numObjects ), defaultMaterial );
 	this.scene.add( this.mesh );
 
@@ -100,10 +101,11 @@ function Scene ( type, numObjects, cameraZ, fov, rotationSpeed, clearColor ) {
 
 		renderer.setClearColor( this.clearColor );
 
-		if (rtt)
+		if ( rtt )
 			renderer.render( this.scene, this.camera, this.fbo, true );
 		else
 			renderer.render( this.scene, this.camera );
 
 	};
+
 }

+ 28 - 26
examples/js/crossfade/transition.js

@@ -2,13 +2,13 @@ function Transition ( sceneA, sceneB ) {
 
 	this.scene = new THREE.Scene();
 	
-	this.cameraOrtho = new THREE.OrthographicCamera(window.innerWidth / -2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / -2, -10, 10);
+	this.cameraOrtho = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, - 10, 10 );
 
 	this.textures = [];
-	for (var i = 0; i < 6; i ++)
-		this.textures[i] = new THREE.ImageUtils.loadTexture('textures/transition/transition' + (i + 1) + '.png');
+	for ( var i = 0; i < 6; i ++ )
+		this.textures[ i ] = new THREE.ImageUtils.loadTexture( 'textures/transition/transition' + ( i + 1 ) + '.png' );
 				
-	this.quadmaterial = new THREE.ShaderMaterial({
+	this.quadmaterial = new THREE.ShaderMaterial( {
 
 		uniforms: {
 
@@ -34,7 +34,7 @@ function Transition ( sceneA, sceneB ) {
 			},
 			tMixTexture: {
 				type: "t",
-				value: this.textures[0]
+				value: this.textures[ 0 ]
 			}
 		},
 		vertexShader: [
@@ -48,7 +48,7 @@ function Transition ( sceneA, sceneB ) {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 		fragmentShader: [
 
 			"uniform float mixRatio;",
@@ -81,14 +81,14 @@ function Transition ( sceneA, sceneB ) {
 			"}",
 		"}"
 
-		].join("\n")
+		].join( "\n" )
 
-	});
+	} );
 
-	quadgeometry = new THREE.PlaneBufferGeometry(window.innerWidth, window.innerHeight);
+	quadgeometry = new THREE.PlaneBufferGeometry( window.innerWidth, window.innerHeight );
 	
-	this.quad = new THREE.Mesh(quadgeometry, this.quadmaterial);
-	this.scene.add(this.quad);
+	this.quad = new THREE.Mesh( quadgeometry, this.quadmaterial );
+	this.scene.add( this.quad );
 
 	// Link both scenes and their FBOs
 	this.sceneA = sceneA;
@@ -113,29 +113,30 @@ function Transition ( sceneA, sceneB ) {
 	
 	this.setTexture = function ( i ) {
 		
-		this.quadmaterial.uniforms.tMixTexture.value = this.textures[i];
+		this.quadmaterial.uniforms.tMixTexture.value = this.textures[ i ];
 		
 	};
 	
 	this.render = function( delta ) {
 		
 		// Transition animation
-		if (transitionParams.animateTransition)
-		{
-			var t = (1 + Math.sin(transitionParams.transitionSpeed * clock.getElapsedTime() / Math.PI)) / 2;
-			transitionParams.transition = THREE.Math.smoothstep(t, 0.3, 0.7);
+		if ( transitionParams.animateTransition ) {
+
+			var t = ( 1 + Math.sin( transitionParams.transitionSpeed * clock.getElapsedTime() / Math.PI ) ) / 2;
+			transitionParams.transition = THREE.Math.smoothstep( t, 0.3, 0.7 );
 			
 			// Change the current alpha texture after each transition
-			if (transitionParams.loopTexture && (transitionParams.transition == 0 || transitionParams.transition == 1))
-			{
-				if (this.needChange)
-				{
-					transitionParams.texture = (transitionParams.texture + 1)%this.textures.length;
-					this.quadmaterial.uniforms.tMixTexture.value = this.textures[transitionParams.texture];
+			if ( transitionParams.loopTexture && ( transitionParams.transition == 0 || transitionParams.transition == 1 ) ) {
+
+				if ( this.needChange ) {
+
+					transitionParams.texture = ( transitionParams.texture + 1 ) % this.textures.length;
+					this.quadmaterial.uniforms.tMixTexture.value = this.textures[ transitionParams.texture ];
 					this.needChange = false;
+
 				}
-			}	
-			else
+
+			} else
 				this.needChange = true;
 				
 		}
@@ -143,11 +144,11 @@ function Transition ( sceneA, sceneB ) {
 		this.quadmaterial.uniforms.mixRatio.value = transitionParams.transition;
 
 		// Prevent render both scenes when it's not necessary
-		if (transitionParams.transition == 0) {
+		if ( transitionParams.transition == 0 ) {
 			
 			this.sceneB.render( delta, false );
 		
-		} else if (transitionParams.transition == 1) {
+		} else if ( transitionParams.transition == 1 ) {
 		
 			this.sceneA.render( delta, false );
 			
@@ -162,4 +163,5 @@ function Transition ( sceneA, sceneB ) {
 		}
 
 	}
+
 }

+ 20 - 12
examples/js/curves/NURBSCurve.js

@@ -13,14 +13,17 @@
  *	NURBS curve
  **************************************************************/
 
-THREE.NURBSCurve = function ( degree, knots /* array of reals */, controlPoints /* array of Vector(2|3|4) */) {
+THREE.NURBSCurve = function ( degree, knots /* array of reals */, controlPoints /* array of Vector(2|3|4) */ ) {
 
 	this.degree = degree;
 	this.knots = knots;
 	this.controlPoints = [];
-	for (var i = 0; i < controlPoints.length; ++ i) { // ensure Vector4 for control points
-		var point = controlPoints[i];
-		this.controlPoints[i] = new THREE.Vector4(point.x, point.y, point.z, point.w);
+	for ( var i = 0; i < controlPoints.length; ++ i ) {
+
+		// ensure Vector4 for control points
+		var point = controlPoints[ i ];
+		this.controlPoints[ i ] = new THREE.Vector4( point.x, point.y, point.z, point.w );
+
 	}
 
 };
@@ -32,26 +35,31 @@ THREE.NURBSCurve.prototype.constructor = THREE.NURBSCurve;
 
 THREE.NURBSCurve.prototype.getPoint = function ( t ) {
 
-	var u = this.knots[0] + t * (this.knots[this.knots.length - 1] - this.knots[0]); // linear mapping t->u
+	var u = this.knots[ 0 ] + t * ( this.knots[ this.knots.length - 1 ] - this.knots[ 0 ] ); // linear mapping t->u
 
 	// following results in (wx, wy, wz, w) homogeneous point
-	var hpoint = THREE.NURBSUtils.calcBSplinePoint(this.degree, this.knots, this.controlPoints, u);
+	var hpoint = THREE.NURBSUtils.calcBSplinePoint( this.degree, this.knots, this.controlPoints, u );
+
+	if ( hpoint.w != 1.0 ) {
+
+		// project to 3D space: (wx, wy, wz, w) -> (x, y, z, 1)
+		hpoint.divideScalar( hpoint.w );
 
-	if (hpoint.w != 1.0) { // project to 3D space: (wx, wy, wz, w) -> (x, y, z, 1)
-		hpoint.divideScalar(hpoint.w);
 	}
 
-	return new THREE.Vector3(hpoint.x, hpoint.y, hpoint.z);
+	return new THREE.Vector3( hpoint.x, hpoint.y, hpoint.z );
+
 };
 
 
 THREE.NURBSCurve.prototype.getTangent = function ( t ) {
 
-	var u = this.knots[0] + t * (this.knots[this.knots.length - 1] - this.knots[0]);
-	var ders = THREE.NURBSUtils.calcNURBSDerivatives(this.degree, this.knots, this.controlPoints, u, 1);
-	var tangent = ders[1].clone();
+	var u = this.knots[ 0 ] + t * ( this.knots[ this.knots.length - 1 ] - this.knots[ 0 ] );
+	var ders = THREE.NURBSUtils.calcNURBSDerivatives( this.degree, this.knots, this.controlPoints, u, 1 );
+	var tangent = ders[ 1 ].clone();
 	tangent.normalize();
 
 	return tangent;
+
 };
 

+ 15 - 9
examples/js/curves/NURBSSurface.js

@@ -11,7 +11,7 @@
  *	NURBS surface
  **************************************************************/
 
-THREE.NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */) {
+THREE.NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */ ) {
 
 	this.degree1 = degree1;
 	this.degree2 = degree2;
@@ -23,13 +23,18 @@ THREE.NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of re
 	var len2 = knots2.length - degree2 - 1;
 
 	// ensure Vector4 for control points
-	for (var i = 0; i < len1; ++ i) {
-		this.controlPoints[i] = [];
-		for (var j = 0; j < len2; ++ j) {
-			var point = controlPoints[i][j];
-			this.controlPoints[i][j] = new THREE.Vector4(point.x, point.y, point.z, point.w);
+	for ( var i = 0; i < len1; ++ i ) {
+
+		this.controlPoints[ i ] = [];
+		for ( var j = 0; j < len2; ++ j ) {
+
+			var point = controlPoints[ i ][ j ];
+			this.controlPoints[ i ][ j ] = new THREE.Vector4( point.x, point.y, point.z, point.w );
+
 		}
+
 	}
+
 };
 
 
@@ -39,10 +44,11 @@ THREE.NURBSSurface.prototype = {
 
 	getPoint: function ( t1, t2 ) {
 
-		var u = this.knots1[0] + t1 * (this.knots1[this.knots1.length - 1] - this.knots1[0]); // linear mapping t1->u
-		var v = this.knots2[0] + t2 * (this.knots2[this.knots2.length - 1] - this.knots2[0]); // linear mapping t2->u
+		var u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u
+		var v = this.knots2[ 0 ] + t2 * ( this.knots2[ this.knots2.length - 1 ] - this.knots2[ 0 ] ); // linear mapping t2->u
+
+		return THREE.NURBSUtils.calcSurfacePoint( this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v );
 
-		return THREE.NURBSUtils.calcSurfacePoint(this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v);
 	}
 };
 

+ 190 - 112
examples/js/curves/NURBSUtils.js

@@ -23,32 +23,43 @@ THREE.NURBSUtils = {
 	returns the span
 	*/
 	findSpan: function( p,  u,  U ) {
+
 		var n = U.length - p - 1;
 
-		if (u >= U[n]) {
+		if ( u >= U[ n ] ) {
+
 			return n - 1;
+
 		}
 
-		if (u <= U[p]) {
+		if ( u <= U[ p ] ) {
+
 			return p;
+
 		}
 
 		var low = p;
 		var high = n;
-		var mid = Math.floor((low + high) / 2);
+		var mid = Math.floor( ( low + high ) / 2 );
 
-		while (u < U[mid] || u >= U[mid + 1]) {
+		while ( u < U[ mid ] || u >= U[ mid + 1 ] ) {
 		  
-			if (u < U[mid]) {
+			if ( u < U[ mid ] ) {
+
 				high = mid;
+
 			} else {
+
 				low = mid;
+
 			}
 
-			mid = Math.floor((low + high) / 2);
+			mid = Math.floor( ( low + high ) / 2 );
+
 		}
 
 		return mid;
+
 	},
     
 		
@@ -63,31 +74,35 @@ THREE.NURBSUtils = {
 	returns array[p+1] with basis functions values.
 	*/
 	calcBasisFunctions: function( span, u, p, U ) {
+
 		var N = [];
 		var left = [];
 		var right = [];
-		N[0] = 1.0;
+		N[ 0 ] = 1.0;
 
-		for (var j = 1; j <= p; ++ j) {
+		for ( var j = 1; j <= p; ++ j ) {
 	   
-			left[j] = u - U[span + 1 - j];
-			right[j] = U[span + j] - u;
+			left[ j ] = u - U[ span + 1 - j ];
+			right[ j ] = U[ span + j ] - u;
 
 			var saved = 0.0;
 
-			for (var r = 0; r < j; ++ r) {
+			for ( var r = 0; r < j; ++ r ) {
 
-				var rv = right[r + 1];
-				var lv = left[j - r];
-				var temp = N[r] / (rv + lv);
-				N[r] = saved + rv * temp;
+				var rv = right[ r + 1 ];
+				var lv = left[ j - r ];
+				var temp = N[ r ] / ( rv + lv );
+				N[ r ] = saved + rv * temp;
 				saved = lv * temp;
+
 			 }
 
-			 N[j] = saved;
+			 N[ j ] = saved;
+
 		 }
 
 		 return N;
+
 	},
 
 
@@ -102,21 +117,25 @@ THREE.NURBSUtils = {
 	returns point for given u
 	*/
 	calcBSplinePoint: function( p, U, P, u ) {
-		var span = this.findSpan(p, u, U);
-		var N = this.calcBasisFunctions(span, u, p, U);
-		var C = new THREE.Vector4(0, 0, 0, 0);
 
-		for (var j = 0; j <= p; ++ j) {
-			var point = P[span - p + j];
-			var Nj = N[j];
+		var span = this.findSpan( p, u, U );
+		var N = this.calcBasisFunctions( span, u, p, U );
+		var C = new THREE.Vector4( 0, 0, 0, 0 );
+
+		for ( var j = 0; j <= p; ++ j ) {
+
+			var point = P[ span - p + j ];
+			var Nj = N[ j ];
 			var wNj = point.w * Nj;
 			C.x += point.x * wNj;
 			C.y += point.y * wNj;
 			C.z += point.z * wNj;
 			C.w += point.w * Nj;
+
 		}
 
 		return C;
+
 	},
 
 
@@ -134,142 +153,175 @@ THREE.NURBSUtils = {
 	calcBasisFunctionDerivatives: function( span,  u,  p,  n,  U ) {
 
 		var zeroArr = [];
-		for (var i = 0; i <= p; ++ i)
-			zeroArr[i] = 0.0;
+		for ( var i = 0; i <= p; ++ i )
+			zeroArr[ i ] = 0.0;
 
 		var ders = [];
-		for (var i = 0; i <= n; ++ i)
-			ders[i] = zeroArr.slice(0);
+		for ( var i = 0; i <= n; ++ i )
+			ders[ i ] = zeroArr.slice( 0 );
 
 		var ndu = [];
-		for (var i = 0; i <= p; ++ i)
-			ndu[i] = zeroArr.slice(0);
+		for ( var i = 0; i <= p; ++ i )
+			ndu[ i ] = zeroArr.slice( 0 );
 
-		ndu[0][0] = 1.0;
+		ndu[ 0 ][ 0 ] = 1.0;
 
-		var left = zeroArr.slice(0);
-		var right = zeroArr.slice(0);
+		var left = zeroArr.slice( 0 );
+		var right = zeroArr.slice( 0 );
 
-		for (var j = 1; j <= p; ++ j) {
-			left[j] = u - U[span + 1 - j];
-			right[j] = U[span + j] - u;
+		for ( var j = 1; j <= p; ++ j ) {
+
+			left[ j ] = u - U[ span + 1 - j ];
+			right[ j ] = U[ span + j ] - u;
 
 			var saved = 0.0;
 
-			for (var r = 0; r < j; ++ r) {
-				var rv = right[r + 1];
-				var lv = left[j - r];
-				ndu[j][r] = rv + lv;
+			for ( var r = 0; r < j; ++ r ) {
+
+				var rv = right[ r + 1 ];
+				var lv = left[ j - r ];
+				ndu[ j ][ r ] = rv + lv;
 
-				var temp = ndu[r][j - 1] / ndu[j][r];
-				ndu[r][j] = saved + rv * temp;
+				var temp = ndu[ r ][ j - 1 ] / ndu[ j ][ r ];
+				ndu[ r ][ j ] = saved + rv * temp;
 				saved = lv * temp;
+
 			}
 
-			ndu[j][j] = saved;
+			ndu[ j ][ j ] = saved;
+
 		}
 
-		for (var j = 0; j <= p; ++ j) {
-			ders[0][j] = ndu[j][p];
+		for ( var j = 0; j <= p; ++ j ) {
+
+			ders[ 0 ][ j ] = ndu[ j ][ p ];
+
 		}
 
-		for (var r = 0; r <= p; ++ r) {
+		for ( var r = 0; r <= p; ++ r ) {
+
 			var s1 = 0;
 			var s2 = 1;
 
 			var a = [];
-			for (var i = 0; i <= p; ++ i) {
-				a[i] = zeroArr.slice(0);
+			for ( var i = 0; i <= p; ++ i ) {
+
+				a[ i ] = zeroArr.slice( 0 );
+
 			}
-			a[0][0] = 1.0;
+			a[ 0 ][ 0 ] = 1.0;
+
+			for ( var k = 1; k <= n; ++ k ) {
 
-			for (var k = 1; k <= n; ++ k) {
 				var d = 0.0;
 				var rk = r - k;
 				var pk = p - k;
 
-				if (r >= k) {
-					a[s2][0] = a[s1][0] / ndu[pk + 1][rk];
-					d = a[s2][0] * ndu[rk][pk];
+				if ( r >= k ) {
+
+					a[ s2 ][ 0 ] = a[ s1 ][ 0 ] / ndu[ pk + 1 ][ rk ];
+					d = a[ s2 ][ 0 ] * ndu[ rk ][ pk ];
+
 				}
 
-				var j1 = (rk >= -1) ? 1 : -rk;
-				var j2 = (r - 1 <= pk) ? k - 1 :  p - r;
+				var j1 = ( rk >= - 1 ) ? 1 : - rk;
+				var j2 = ( r - 1 <= pk ) ? k - 1 :  p - r;
+
+				for ( var j = j1; j <= j2; ++ j ) {
+
+					a[ s2 ][ j ] = ( a[ s1 ][ j ] - a[ s1 ][ j - 1 ] ) / ndu[ pk + 1 ][ rk + j ];
+					d += a[ s2 ][ j ] * ndu[ rk + j ][ pk ];
 
-				for (var j = j1; j <= j2; ++ j) {
-					a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][rk + j];
-					d += a[s2][j] * ndu[rk + j][pk];
 				}
 
-				if (r <= pk) {
-					a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r];
-					d += a[s2][k] * ndu[r][pk];
+				if ( r <= pk ) {
+
+					a[ s2 ][ k ] = - a[ s1 ][ k - 1 ] / ndu[ pk + 1 ][ r ];
+					d += a[ s2 ][ k ] * ndu[ r ][ pk ];
+
 				}
 
-				ders[k][r] = d;
+				ders[ k ][ r ] = d;
 
 				var j = s1;
 				s1 = s2;
 				s2 = j;
+
 			}
+
 		}
 
 		var r = p;
 
-		for (var k = 1; k <= n; ++ k) {
-			for (var j = 0; j <= p; ++ j) {
-				ders[k][j] *= r;
+		for ( var k = 1; k <= n; ++ k ) {
+
+			for ( var j = 0; j <= p; ++ j ) {
+
+				ders[ k ][ j ] *= r;
+
 			}
 			r *= p - k;
+
 		}
 
 		return ders;
+
 	},
 
 
- 	/*
-	Calculate derivatives of a B-Spline. See The NURBS Book, page 93, algorithm A3.2.
+	/*
+		Calculate derivatives of a B-Spline. See The NURBS Book, page 93, algorithm A3.2.
 
-	p  : degree
-	U  : knot vector
-	P  : control points
-	u  : Parametric points
-	nd : number of derivatives
+		p  : degree
+		U  : knot vector
+		P  : control points
+		u  : Parametric points
+		nd : number of derivatives
 
-	returns array[d+1] with derivatives
-	*/
+		returns array[d+1] with derivatives
+		*/
 	calcBSplineDerivatives: function( p,  U,  P,  u,  nd ) {
+
 		var du = nd < p ? nd : p;
 		var CK = [];
-		var span = this.findSpan(p, u, U);
-		var nders = this.calcBasisFunctionDerivatives(span, u, p, du, U);
+		var span = this.findSpan( p, u, U );
+		var nders = this.calcBasisFunctionDerivatives( span, u, p, du, U );
 		var Pw = [];
 
-		for (var i = 0; i < P.length; ++ i) {
-			var point = P[i].clone();
+		for ( var i = 0; i < P.length; ++ i ) {
+
+			var point = P[ i ].clone();
 			var w = point.w;
 
 			point.x *= w;
 			point.y *= w;
 			point.z *= w;
 
-			Pw[i] = point;
+			Pw[ i ] = point;
+
 		}
-		for (var k = 0; k <= du; ++ k) {
-			var point = Pw[span - p].clone().multiplyScalar(nders[k][0]);
+		for ( var k = 0; k <= du; ++ k ) {
+
+			var point = Pw[ span - p ].clone().multiplyScalar( nders[ k ][ 0 ] );
+
+			for ( var j = 1; j <= p; ++ j ) {
+
+				point.add( Pw[ span - p + j ].clone().multiplyScalar( nders[ k ][ j ] ) );
 
-			for (var j = 1; j <= p; ++ j) {
-				point.add(Pw[span - p + j].clone().multiplyScalar(nders[k][j]));
 			}
 
-			CK[k] = point;
+			CK[ k ] = point;
+
 		}
 
-		for (var k = du + 1; k <= nd + 1; ++ k) {
-			CK[k] = new THREE.Vector4(0, 0, 0);
+		for ( var k = du + 1; k <= nd + 1; ++ k ) {
+
+			CK[ k ] = new THREE.Vector4( 0, 0, 0 );
+
 		}
 
 		return CK;
+
 	},
 
 
@@ -279,23 +331,31 @@ THREE.NURBSUtils = {
 	returns k!/(i!(k-i)!)
 	*/
 	calcKoverI: function( k, i ) {
+
 		var nom = 1;
 
-		for (var j = 2; j <= k; ++ j) {
+		for ( var j = 2; j <= k; ++ j ) {
+
 			nom *= j;
+
 		}
 
 		var denom = 1;
 
-		for (var j = 2; j <= i; ++ j) {
+		for ( var j = 2; j <= i; ++ j ) {
+
 			denom *= j;
+
 		}
 
-		for (var j = 2; j <= k - i; ++ j) {
+		for ( var j = 2; j <= k - i; ++ j ) {
+
 			denom *= j;
+
 		}
 
 		return nom / denom;
+
 	},
 
 
@@ -307,29 +367,37 @@ THREE.NURBSUtils = {
 	returns array with derivatives for rational curve.
 	*/
 	calcRationalCurveDerivatives: function ( Pders ) {
+
 		var nd = Pders.length;
 		var Aders = [];
 		var wders = [];
 
-		for (var i = 0; i < nd; ++ i) {
-			var point = Pders[i];
-			Aders[i] = new THREE.Vector3(point.x, point.y, point.z);
-			wders[i] = point.w;
+		for ( var i = 0; i < nd; ++ i ) {
+
+			var point = Pders[ i ];
+			Aders[ i ] = new THREE.Vector3( point.x, point.y, point.z );
+			wders[ i ] = point.w;
+
 		}
 
 		var CK = [];
 
-		for (var k = 0; k < nd; ++ k) {
-			var v = Aders[k].clone();
+		for ( var k = 0; k < nd; ++ k ) {
+
+			var v = Aders[ k ].clone();
+
+			for ( var i = 1; i <= k; ++ i ) {
+
+				v.sub( CK[ k - i ].clone().multiplyScalar( this.calcKoverI( k, i ) * wders[ i ] ) );
 
-			for (var i = 1; i <= k; ++ i) {
-				v.sub(CK[k - i].clone().multiplyScalar(this.calcKoverI(k, i) * wders[i]));
 			}
 
-			CK[k] = v.divideScalar(wders[0]);
+			CK[ k ] = v.divideScalar( wders[ 0 ] );
+
 		}
 
 		return CK;
+
 	},
 
 
@@ -345,8 +413,10 @@ THREE.NURBSUtils = {
 	returns array with derivatives.
 	*/
 	calcNURBSDerivatives: function( p,  U,  P,  u,  nd ) {
-		var Pders = this.calcBSplineDerivatives(p, U, P, u, nd);
-		return this.calcRationalCurveDerivatives(Pders);
+
+		var Pders = this.calcBSplineDerivatives( p, U, P, u, nd );
+		return this.calcRationalCurveDerivatives( Pders );
+
 	},
 
 
@@ -361,31 +431,39 @@ THREE.NURBSUtils = {
 	returns point for given (u, v)
 	*/
 	calcSurfacePoint: function( p, q, U, V, P, u, v ) {
-		var uspan = this.findSpan(p, u, U);
-		var vspan = this.findSpan(q, v, V);
-		var Nu = this.calcBasisFunctions(uspan, u, p, U);
-		var Nv = this.calcBasisFunctions(vspan, v, q, V);
+
+		var uspan = this.findSpan( p, u, U );
+		var vspan = this.findSpan( q, v, V );
+		var Nu = this.calcBasisFunctions( uspan, u, p, U );
+		var Nv = this.calcBasisFunctions( vspan, v, q, V );
 		var temp = [];
 
-		for (var l = 0; l <= q; ++ l) {
-			temp[l] = new THREE.Vector4(0, 0, 0, 0);
-			for (var k = 0; k <= p; ++ k) {
-				var point = P[uspan - p + k][vspan - q + l].clone();
+		for ( var l = 0; l <= q; ++ l ) {
+
+			temp[ l ] = new THREE.Vector4( 0, 0, 0, 0 );
+			for ( var k = 0; k <= p; ++ k ) {
+
+				var point = P[ uspan - p + k ][ vspan - q + l ].clone();
 				var w = point.w;
 				point.x *= w;
 				point.y *= w;
 				point.z *= w;
-				temp[l].add(point.multiplyScalar(Nu[k]));
+				temp[ l ].add( point.multiplyScalar( Nu[ k ] ) );
+
 			}
+
 		}
 
-		var Sw = new THREE.Vector4(0, 0, 0, 0);
-		for (var l = 0; l <= q; ++ l) {
-			Sw.add(temp[l].multiplyScalar(Nv[l]));
+		var Sw = new THREE.Vector4( 0, 0, 0, 0 );
+		for ( var l = 0; l <= q; ++ l ) {
+
+			Sw.add( temp[ l ].multiplyScalar( Nv[ l ] ) );
+
 		}
 
-		Sw.divideScalar(Sw.w);
-		return new THREE.Vector3(Sw.x, Sw.y, Sw.z);
+		Sw.divideScalar( Sw.w );
+		return new THREE.Vector3( Sw.x, Sw.y, Sw.z );
+
 	}
 
 };

+ 13 - 11
examples/js/effects/AnaglyphEffect.js

@@ -17,7 +17,7 @@ THREE.AnaglyphEffect = function ( renderer, width, height ) {
 	var _cameraR = new THREE.PerspectiveCamera();
 	_cameraR.matrixAutoUpdate = false;
 
-	var _camera = new THREE.OrthographicCamera( -1, 1, 1, - 1, 0, 1 );
+	var _camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 
 	var _scene = new THREE.Scene();
 
@@ -49,7 +49,7 @@ THREE.AnaglyphEffect = function ( renderer, width, height ) {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		fragmentShader: [
 
@@ -71,7 +71,7 @@ THREE.AnaglyphEffect = function ( renderer, width, height ) {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	} );
 
@@ -124,26 +124,26 @@ THREE.AnaglyphEffect = function ( renderer, width, height ) {
 
 			// translate xOffset
 
-			eyeRight.elements[12] = eyeSep;
-			eyeLeft.elements[12] = -eyeSep;
+			eyeRight.elements[ 12 ] = eyeSep;
+			eyeLeft.elements[ 12 ] = - eyeSep;
 
 			// for left eye
 
-			xmin = -ymax * _aspect + eyeSepOnProjection;
+			xmin = - ymax * _aspect + eyeSepOnProjection;
 			xmax = ymax * _aspect + eyeSepOnProjection;
 
-			projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin );
-			projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin );
+			projectionMatrix.elements[ 0 ] = 2 * _near / ( xmax - xmin );
+			projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
 
 			_cameraL.projectionMatrix.copy( projectionMatrix );
 
 			// for right eye
 
-			xmin = -ymax * _aspect - eyeSepOnProjection;
+			xmin = - ymax * _aspect - eyeSepOnProjection;
 			xmax = ymax * _aspect - eyeSepOnProjection;
 
-			projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin );
-			projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin );
+			projectionMatrix.elements[ 0 ] = 2 * _near / ( xmax - xmin );
+			projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
 
 			_cameraR.projectionMatrix.copy( projectionMatrix );
 
@@ -168,8 +168,10 @@ THREE.AnaglyphEffect = function ( renderer, width, height ) {
 	};
 
 	this.dispose = function() {
+
 		if ( _renderTargetL ) _renderTargetL.dispose();
 		if ( _renderTargetR ) _renderTargetR.dispose();
+
 	}
 
 };

+ 68 - 51
examples/js/effects/AsciiEffect.js

@@ -17,25 +17,25 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 	// darker bolder character set from https://github.com/saw/Canvas-ASCII-Art/
 	// ' .\'`^",:;Il!i~+_-?][}{1)(|/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$'.split('');
 
-	if ( !options ) options = {};
+	if ( ! options ) options = {};
 
 	// Some ASCII settings
 
-	var bResolution = !options['resolution'] ? 0.15 : options['resolution']; // Higher for more details
-	var iScale = !options['scale'] ? 1 : options['scale'];
-	var bColor = !options['color'] ? false : options['color']; // nice but slows down rendering!
-	var bAlpha = !options['alpha'] ? false : options['alpha']; // Transparency
-	var bBlock = !options['block'] ? false : options['block']; // blocked characters. like good O dos
-	var bInvert = !options['invert'] ? false : options['invert']; // black is white, white is black
+	var bResolution = ! options[ 'resolution' ] ? 0.15 : options[ 'resolution' ]; // Higher for more details
+	var iScale = ! options[ 'scale' ] ? 1 : options[ 'scale' ];
+	var bColor = ! options[ 'color' ] ? false : options[ 'color' ]; // nice but slows down rendering!
+	var bAlpha = ! options[ 'alpha' ] ? false : options[ 'alpha' ]; // Transparency
+	var bBlock = ! options[ 'block' ] ? false : options[ 'block' ]; // blocked characters. like good O dos
+	var bInvert = ! options[ 'invert' ] ? false : options[ 'invert' ]; // black is white, white is black
 
 	var strResolution = 'low';
 
 	var width, height;
 
-	var domElement = document.createElement('div');
+	var domElement = document.createElement( 'div' );
 	domElement.style.cursor = 'default';
 
-	var oAscii = document.createElement("table");
+	var oAscii = document.createElement( "table" );
 	domElement.appendChild( oAscii );
 
 	var iWidth, iHeight;
@@ -86,8 +86,8 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 		if ( oImg.style.backgroundColor ) {
 
-			oAscii.rows[0].cells[0].style.backgroundColor = oImg.style.backgroundColor;
-			oAscii.rows[0].cells[0].style.color = oImg.style.color;
+			oAscii.rows[ 0 ].cells[ 0 ].style.backgroundColor = oImg.style.backgroundColor;
+			oAscii.rows[ 0 ].cells[ 0 ].style.color = oImg.style.color;
 
 		}
 
@@ -96,8 +96,8 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 		var oStyle = oAscii.style;
 		oStyle.display = "inline";
-		oStyle.width = Math.round(iWidth / fResolution * iScale) + "px";
-		oStyle.height = Math.round(iHeight / fResolution * iScale) + "px";
+		oStyle.width = Math.round( iWidth / fResolution * iScale ) + "px";
+		oStyle.height = Math.round( iHeight / fResolution * iScale ) + "px";
 		oStyle.whiteSpace = "pre";
 		oStyle.margin = "0px";
 		oStyle.padding = "0px";
@@ -107,28 +107,33 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 		oStyle.lineHeight = fLineHeight + "px";
 		oStyle.textAlign = "left";
 		oStyle.textDecoration = "none";
+
 	}
 
 
-	var aDefaultCharList = (" .,:;i1tfLCG08@").split("");
-	var aDefaultColorCharList = (" CGO08@").split("");
+	var aDefaultCharList = ( " .,:;i1tfLCG08@" ).split( "" );
+	var aDefaultColorCharList = ( " CGO08@" ).split( "" );
 	var strFont = "courier new, monospace";
 
 	var oCanvasImg = renderer.domElement;
 
-	var oCanvas = document.createElement("canvas");
-	if (!oCanvas.getContext) {
+	var oCanvas = document.createElement( "canvas" );
+	if ( ! oCanvas.getContext ) {
+
 		return;
+
 	}
 
-	var oCtx = oCanvas.getContext("2d");
-	if (!oCtx.getImageData) {
+	var oCtx = oCanvas.getContext( "2d" );
+	if ( ! oCtx.getImageData ) {
+
 		return;
+
 	}
 
-	var aCharList = (bColor ? aDefaultColorCharList : aDefaultCharList);
+	var aCharList = ( bColor ? aDefaultColorCharList : aDefaultCharList );
 
-	if (charSet) aCharList = charSet;
+	if ( charSet ) aCharList = charSet;
 
 	var fResolution = 0.5;
 
@@ -144,8 +149,8 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 	// Setup dom
 
-	var fFontSize = (2 / fResolution) * iScale;
-	var fLineHeight = (2 / fResolution) * iScale;
+	var fFontSize = ( 2 / fResolution ) * iScale;
+	var fLineHeight = ( 2 / fResolution ) * iScale;
 
 	// adjust letter-spacing for all combinations of scale and resolution to get it to fit the image width.
 
@@ -153,36 +158,36 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 	if ( strResolution == "low" ) {
 
-		switch (iScale) {
-			case 1 : fLetterSpacing = -1; break;
+		switch ( iScale ) {
+			case 1 : fLetterSpacing = - 1; break;
 			case 2 :
-			case 3 : fLetterSpacing = -2.1; break;
-			case 4 : fLetterSpacing = -3.1; break;
-			case 5 : fLetterSpacing = -4.15; break;
+			case 3 : fLetterSpacing = - 2.1; break;
+			case 4 : fLetterSpacing = - 3.1; break;
+			case 5 : fLetterSpacing = - 4.15; break;
 		}
 
 	}
 
 	if ( strResolution == "medium" ) {
 
-		switch (iScale) {
+		switch ( iScale ) {
 			case 1 : fLetterSpacing = 0; break;
-			case 2 : fLetterSpacing = -1; break;
-			case 3 : fLetterSpacing = -1.04; break;
+			case 2 : fLetterSpacing = - 1; break;
+			case 3 : fLetterSpacing = - 1.04; break;
 			case 4 :
-			case 5 : fLetterSpacing = -2.1; break;
+			case 5 : fLetterSpacing = - 2.1; break;
 		}
 
 	}
 
 	if ( strResolution == "high" ) {
 
-		switch (iScale) {
+		switch ( iScale ) {
 			case 1 :
 			case 2 : fLetterSpacing = 0; break;
 			case 3 :
 			case 4 :
-			case 5 : fLetterSpacing = -1; break;
+			case 5 : fLetterSpacing = - 1; break;
 		}
 
 	}
@@ -197,61 +202,72 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 
 		oCtx.clearRect( 0, 0, iWidth, iHeight );
 		oCtx.drawImage( oCanvasImg, 0, 0, iWidth, iHeight );
-		var oImgData = oCtx.getImageData(0, 0, iWidth, iHeight).data;
+		var oImgData = oCtx.getImageData( 0, 0, iWidth, iHeight ).data;
 
 		// Coloring loop starts now
 		var strChars = "";
 
 		// console.time('rendering');
 
-		for (var y = 0; y < iHeight; y+=2) {
-			for (var x = 0; x < iWidth; x ++) {
-				var iOffset = (y * iWidth + x) * 4;
+		for ( var y = 0; y < iHeight; y += 2 ) {
 
-				var iRed = oImgData[iOffset];
-				var iGreen = oImgData[iOffset + 1];
-				var iBlue = oImgData[iOffset + 2];
-				var iAlpha = oImgData[iOffset + 3];
+			for ( var x = 0; x < iWidth; x ++ ) {
+
+				var iOffset = ( y * iWidth + x ) * 4;
+
+				var iRed = oImgData[ iOffset ];
+				var iGreen = oImgData[ iOffset + 1 ];
+				var iBlue = oImgData[ iOffset + 2 ];
+				var iAlpha = oImgData[ iOffset + 3 ];
 				var iCharIdx;
 
 				var fBrightness;
 
-				fBrightness = (0.3 * iRed + 0.59 * iGreen + 0.11 * iBlue) / 255;
+				fBrightness = ( 0.3 * iRed + 0.59 * iGreen + 0.11 * iBlue ) / 255;
 				// fBrightness = (0.3*iRed + 0.5*iGreen + 0.3*iBlue) / 255;
 
-				if (iAlpha == 0) {
+				if ( iAlpha == 0 ) {
+
 					// should calculate alpha instead, but quick hack :)
 					//fBrightness *= (iAlpha / 255);
 					fBrightness = 1;
 
 				}
 
-				iCharIdx = Math.floor((1 - fBrightness) * (aCharList.length - 1));
+				iCharIdx = Math.floor( ( 1 - fBrightness ) * ( aCharList.length - 1 ) );
+
+				if ( bInvert ) {
 
-				if (bInvert) {
 					iCharIdx = aCharList.length - iCharIdx - 1;
+
 				}
 
 				// good for debugging
 				//fBrightness = Math.floor(fBrightness * 10);
 				//strThisChar = fBrightness;
 
-				var strThisChar = aCharList[iCharIdx];
+				var strThisChar = aCharList[ iCharIdx ];
 
-				if (strThisChar === undefined || strThisChar == " ")
+				if ( strThisChar === undefined || strThisChar == " " )
 					strThisChar = "&nbsp;";
 
-				if (bColor) {
+				if ( bColor ) {
+
 					strChars += "<span style='"
 						+ "color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");"
-						+ (bBlock ? "background-color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");" : "")
-						+ (bAlpha ? "opacity:" + (iAlpha / 255) + ";" : "")
+						+ ( bBlock ? "background-color:rgb(" + iRed + "," + iGreen + "," + iBlue + ");" : "" )
+						+ ( bAlpha ? "opacity:" + ( iAlpha / 255 ) + ";" : "" )
 						+ "'>" + strThisChar + "</span>";
+
 				} else {
+
 					strChars += strThisChar;
+
 				}
+
 			}
 			strChars += "<br/>";
+
 		}
 
 		oAscii.innerHTML = "<tr><td>" + strChars + "</td></tr>";
@@ -259,6 +275,7 @@ THREE.AsciiEffect = function ( renderer, charSet, options ) {
 		// console.timeEnd('rendering');
 
 		// return oAscii;
+
 	}
 
 	// end modified asciifyImage block

+ 10 - 10
examples/js/effects/ParallaxBarrierEffect.js

@@ -48,7 +48,7 @@ THREE.ParallaxBarrierEffect = function ( renderer ) {
 
 			"}"
 
-		].join("\n"),
+		].join( "\n" ),
 
 		fragmentShader: [
 
@@ -72,7 +72,7 @@ THREE.ParallaxBarrierEffect = function ( renderer ) {
 
 			"}"
 
-		].join("\n")
+		].join( "\n" )
 
 	} );
 
@@ -123,26 +123,26 @@ THREE.ParallaxBarrierEffect = function ( renderer ) {
 
 			// translate xOffset
 
-			eyeRight.elements[12] = eyeSep;
-			eyeLeft.elements[12] = -eyeSep;
+			eyeRight.elements[ 12 ] = eyeSep;
+			eyeLeft.elements[ 12 ] = - eyeSep;
 
 			// for left eye
 
-			xmin = -ymax * _aspect + eyeSepOnProjection;
+			xmin = - ymax * _aspect + eyeSepOnProjection;
 			xmax = ymax * _aspect + eyeSepOnProjection;
 
-			projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin );
-			projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin );
+			projectionMatrix.elements[ 0 ] = 2 * _near / ( xmax - xmin );
+			projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
 
 			_cameraL.projectionMatrix.copy( projectionMatrix );
 
 			// for right eye
 
-			xmin = -ymax * _aspect - eyeSepOnProjection;
+			xmin = - ymax * _aspect - eyeSepOnProjection;
 			xmax = ymax * _aspect - eyeSepOnProjection;
 
-			projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin );
-			projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin );
+			projectionMatrix.elements[ 0 ] = 2 * _near / ( xmax - xmin );
+			projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
 
 			_cameraR.projectionMatrix.copy( projectionMatrix );
 

+ 11 - 3
examples/js/effects/StereoEffect.js

@@ -19,20 +19,28 @@ THREE.StereoEffect = function ( renderer ) {
 	Object.defineProperties( this, {
 		separation: {
 			get: function () {
+
 				return scope.eyeSeparation;
+
 			},
 			set: function ( value ) {
+
 				console.warn( 'THREE.StereoEffect: .separation is now .eyeSeparation.' );
 				scope.eyeSeparation = value;
+
 			}
 		},
 		targetDistance: {
 			get: function () {
+
 				return scope.focalLength;
+
 			},
 			set: function ( value ) {
+
 				console.warn( 'THREE.StereoEffect: .targetDistance is now .focalLength.' );
 				scope.focalLength = value;
+
 			}
 		}
 	} );
@@ -83,7 +91,7 @@ THREE.StereoEffect = function ( renderer ) {
 		_halfFocalWidth = _halfFocalHeight * 0.5 * camera.aspect;
 
 		_top = _halfFocalHeight * _ndfl;
-		_bottom = -_top;
+		_bottom = - _top;
 		_innerFactor = ( _halfFocalWidth + this.eyeSeparation / 2.0 ) / ( _halfFocalWidth * 2.0 );
 		_outerFactor = 1.0 - _innerFactor;
 
@@ -93,7 +101,7 @@ THREE.StereoEffect = function ( renderer ) {
 		// left
 
 		_cameraL.projectionMatrix.makeFrustum(
-			-_outer,
+			- _outer,
 			_inner,
 			_bottom,
 			_top,
@@ -108,7 +116,7 @@ THREE.StereoEffect = function ( renderer ) {
 		// right
 
 		_cameraR.projectionMatrix.makeFrustum(
-			-_inner,
+			- _inner,
 			_outer,
 			_bottom,
 			_top,

+ 23 - 22
examples/js/effects/VREffect.js

@@ -172,10 +172,10 @@ THREE.VREffect = function ( renderer, onError ) {
 
 	function fovToNDCScaleOffset( fov ) {
 
-		var pxscale = 2.0 / (fov.leftTan + fov.rightTan);
-		var pxoffset = (fov.leftTan - fov.rightTan) * pxscale * 0.5;
-		var pyscale = 2.0 / (fov.upTan + fov.downTan);
-		var pyoffset = (fov.upTan - fov.downTan) * pyscale * 0.5;
+		var pxscale = 2.0 / ( fov.leftTan + fov.rightTan );
+		var pxoffset = ( fov.leftTan - fov.rightTan ) * pxscale * 0.5;
+		var pyscale = 2.0 / ( fov.upTan + fov.downTan );
+		var pyoffset = ( fov.upTan - fov.downTan ) * pyscale * 0.5;
 		return { scale: [ pxscale, pyscale ], offset: [ pxoffset, pyoffset ] };
 
 	}
@@ -186,44 +186,45 @@ THREE.VREffect = function ( renderer, onError ) {
 		zNear = zNear === undefined ? 0.01 : zNear;
 		zFar = zFar === undefined ? 10000.0 : zFar;
 
-		var handednessScale = rightHanded ? -1.0 : 1.0;
+		var handednessScale = rightHanded ? - 1.0 : 1.0;
 
 		// start with an identity matrix
 		var mobj = new THREE.Matrix4();
 		var m = mobj.elements;
 
 		// and with scale/offset info for normalized device coords
-		var scaleAndOffset = fovToNDCScaleOffset(fov);
+		var scaleAndOffset = fovToNDCScaleOffset( fov );
 
 		// X result, map clip edges to [-w,+w]
-		m[0 * 4 + 0] = scaleAndOffset.scale[0];
-		m[0 * 4 + 1] = 0.0;
-		m[0 * 4 + 2] = scaleAndOffset.offset[0] * handednessScale;
-		m[0 * 4 + 3] = 0.0;
+		m[ 0 * 4 + 0 ] = scaleAndOffset.scale[ 0 ];
+		m[ 0 * 4 + 1 ] = 0.0;
+		m[ 0 * 4 + 2 ] = scaleAndOffset.offset[ 0 ] * handednessScale;
+		m[ 0 * 4 + 3 ] = 0.0;
 
 		// Y result, map clip edges to [-w,+w]
 		// Y offset is negated because this proj matrix transforms from world coords with Y=up,
 		// but the NDC scaling has Y=down (thanks D3D?)
-		m[1 * 4 + 0] = 0.0;
-		m[1 * 4 + 1] = scaleAndOffset.scale[1];
-		m[1 * 4 + 2] = -scaleAndOffset.offset[1] * handednessScale;
-		m[1 * 4 + 3] = 0.0;
+		m[ 1 * 4 + 0 ] = 0.0;
+		m[ 1 * 4 + 1 ] = scaleAndOffset.scale[ 1 ];
+		m[ 1 * 4 + 2 ] = - scaleAndOffset.offset[ 1 ] * handednessScale;
+		m[ 1 * 4 + 3 ] = 0.0;
 
 		// Z result (up to the app)
-		m[2 * 4 + 0] = 0.0;
-		m[2 * 4 + 1] = 0.0;
-		m[2 * 4 + 2] = zFar / (zNear - zFar) * -handednessScale;
-		m[2 * 4 + 3] = (zFar * zNear) / (zNear - zFar);
+		m[ 2 * 4 + 0 ] = 0.0;
+		m[ 2 * 4 + 1 ] = 0.0;
+		m[ 2 * 4 + 2 ] = zFar / ( zNear - zFar ) * - handednessScale;
+		m[ 2 * 4 + 3 ] = ( zFar * zNear ) / ( zNear - zFar );
 
 		// W result (= Z in)
-		m[3 * 4 + 0] = 0.0;
-		m[3 * 4 + 1] = 0.0;
-		m[3 * 4 + 2] = handednessScale;
-		m[3 * 4 + 3] = 0.0;
+		m[ 3 * 4 + 0 ] = 0.0;
+		m[ 3 * 4 + 1 ] = 0.0;
+		m[ 3 * 4 + 2 ] = handednessScale;
+		m[ 3 * 4 + 3 ] = 0.0;
 
 		mobj.transpose();
 
 		return mobj;
+
 	}
 
 	function fovToProjection( fov, rightHanded, zNear, zFar ) {

+ 16 - 14
examples/js/exporters/STLBinaryExporter.js

@@ -19,20 +19,22 @@ THREE.STLBinaryExporter.prototype = {
 
 			var triangles = 0;
 			scene.traverse( function ( object ) {
-				if ( !(object instanceof THREE.Mesh) ) return;
+
+				if ( ! ( object instanceof THREE.Mesh ) ) return;
 				triangles += object.geometry.faces.length;
-			});
+
+			} );
 
 			var offset = 80; // skip header
 			var bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4;
-			var arrayBuffer = new ArrayBuffer(bufferLength);
-			var output = new DataView(arrayBuffer);
-			output.setUint32(offset, triangles, true); offset += 4;
+			var arrayBuffer = new ArrayBuffer( bufferLength );
+			var output = new DataView( arrayBuffer );
+			output.setUint32( offset, triangles, true ); offset += 4;
 
 			scene.traverse( function ( object ) {
 
-				if ( !(object instanceof THREE.Mesh) ) return;
-				if ( !(object.geometry instanceof THREE.Geometry )) return;
+				if ( ! ( object instanceof THREE.Mesh ) ) return;
+				if ( ! ( object.geometry instanceof THREE.Geometry ) ) return;
 
 				var geometry = object.geometry;
 				var matrixWorld = object.matrixWorld;
@@ -48,9 +50,9 @@ THREE.STLBinaryExporter.prototype = {
 
 					vector.copy( face.normal ).applyMatrix3( normalMatrixWorld ).normalize();
 
-					output.setFloat32(offset, vector.x, true); offset += 4; // normal
-					output.setFloat32(offset, vector.y, true); offset += 4;
-					output.setFloat32(offset, vector.z, true); offset += 4;
+					output.setFloat32( offset, vector.x, true ); offset += 4; // normal
+					output.setFloat32( offset, vector.y, true ); offset += 4;
+					output.setFloat32( offset, vector.z, true ); offset += 4;
 
 					var indices = [ face.a, face.b, face.c ];
 
@@ -58,13 +60,13 @@ THREE.STLBinaryExporter.prototype = {
 
 						vector.copy( vertices[ indices[ j ] ] ).applyMatrix4( matrixWorld );
 
-						output.setFloat32(offset, vector.x, true); offset += 4; // vertices
-						output.setFloat32(offset, vector.y, true); offset += 4;
-						output.setFloat32(offset, vector.z, true); offset += 4;
+						output.setFloat32( offset, vector.x, true ); offset += 4; // vertices
+						output.setFloat32( offset, vector.y, true ); offset += 4;
+						output.setFloat32( offset, vector.z, true ); offset += 4;
 
 					}
 
-					output.setUint16(offset, 0, true); offset += 2; // attribute byte count
+					output.setUint16( offset, 0, true ); offset += 2; // attribute byte count
 
 				}
 

+ 6 - 2
examples/js/geometries/ConvexGeometry.js

@@ -80,11 +80,14 @@ THREE.ConvexGeometry = function( vertices ) {
 				faces[ f ] = faces[ faces.length - 1 ];
 				faces.pop();
 
-			} else { // not visible
+			} else {
+
+				// not visible
 
 				f ++;
 
 			}
+
 		}
 
 		// construct the new faces formed by the edges of the hole and the vertex
@@ -97,6 +100,7 @@ THREE.ConvexGeometry = function( vertices ) {
 			] );
 
 		}
+
 	}
 
 	/**
@@ -208,7 +212,7 @@ THREE.ConvexGeometry = function( vertices ) {
 		this.faceVertexUvs[ 0 ].push( [
 			vertexUv( this.vertices[ face.a ] ),
 			vertexUv( this.vertices[ face.b ] ),
-			vertexUv( this.vertices[ face.c ])
+			vertexUv( this.vertices[ face.c ] )
 		] );
 
 	}

+ 32 - 6
examples/js/geometries/DecalGeometry.js

@@ -79,20 +79,26 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 
 			switch ( total ) {
 				case 0: {
+
 					outVertices.push( inVertices[ j ] );
 					outVertices.push( inVertices[ j + 1 ] );
 					outVertices.push( inVertices[ j + 2 ] );
 					break;
+
 				}
 				case 1: {
+
 					var nV1, nV2, nV3;
 					if ( v1Out ) {
+
 						nV1 = inVertices[ j + 1 ]; 
 						nV2 = inVertices[ j + 2 ];
 						nV3 = clip( inVertices[ j ], nV1, plane );
 						nV4 = clip( inVertices[ j ], nV2, plane );
+
 					}
 					if ( v2Out ) { 
+
 						nV1 = inVertices[ j ]; 
 						nV2 = inVertices[ j + 2 ];
 						nV3 = clip( inVertices[ j + 1 ], nV1, plane );
@@ -106,12 +112,15 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 						outVertices.push( nV3.clone() );
 						outVertices.push( nV4 );
 						break;
+
 					}
 					if ( v3Out ) { 
+
 						nV1 = inVertices[ j ]; 
 						nV2 = inVertices[ j + 1 ];
 						nV3 = clip( inVertices[ j + 2 ], nV1, plane );
 						nV4 = clip( inVertices[ j + 2 ], nV2, plane );
+
 					}
 
 					outVertices.push( nV1.clone() );
@@ -123,38 +132,49 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 					outVertices.push( nV2.clone() );
 
 					break;
+
 				}
 				case 2: {
+
 					var nV1, nV2, nV3;
-					if ( !v1Out ) { 
+					if ( ! v1Out ) { 
+
 						nV1 = inVertices[ j ].clone();
 						nV2 = clip( nV1, inVertices[ j + 1 ], plane );
 						nV3 = clip( nV1, inVertices[ j + 2 ], plane ); 
 						outVertices.push( nV1 );
 						outVertices.push( nV2 );
 						outVertices.push( nV3 );
+
 					}
-					if ( !v2Out ) { 
+					if ( ! v2Out ) { 
+
 						nV1 = inVertices[ j + 1 ].clone();
 						nV2 = clip( nV1, inVertices[ j + 2 ], plane );
 						nV3 = clip( nV1, inVertices[ j ], plane );
 						outVertices.push( nV1 );
 						outVertices.push( nV2 );
 						outVertices.push( nV3 );
+
 					}
-					if ( !v3Out ) {
+					if ( ! v3Out ) {
+
 						nV1 = inVertices[ j + 2 ].clone();
 						nV2 = clip( nV1, inVertices[ j ], plane );
 						nV3 = clip( nV1, inVertices[ j + 1 ], plane );
 						outVertices.push( nV1 );
 						outVertices.push( nV2 );
 						outVertices.push( nV3 );
+
 					}
 
 					break;
+
 				}
 				case 3: {
+
 					break;
+
 				}
 			}
 
@@ -187,16 +207,22 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
 			this.pushVertex( vertices, f[ this.faceIndices[ 2 ] ], f.vertexNormals[ 2 ] );
 
 			if ( check.x ) {
+
 				vertices = this.clipFace( vertices, new THREE.Vector3( 1, 0, 0 ) );
-				vertices = this.clipFace( vertices, new THREE.Vector3( -1, 0, 0 ) );
+				vertices = this.clipFace( vertices, new THREE.Vector3( - 1, 0, 0 ) );
+
 			}
 			if ( check.y ) {
+
 				vertices = this.clipFace( vertices, new THREE.Vector3( 0, 1, 0 ) );
-				vertices = this.clipFace( vertices, new THREE.Vector3( 0, -1, 0 ) );
+				vertices = this.clipFace( vertices, new THREE.Vector3( 0, - 1, 0 ) );
+
 			}
 			if ( check.z ) {
+
 				vertices = this.clipFace( vertices, new THREE.Vector3( 0, 0, 1 ) );
-				vertices = this.clipFace( vertices, new THREE.Vector3( 0, 0, -1 ) );
+				vertices = this.clipFace( vertices, new THREE.Vector3( 0, 0, - 1 ) );
+
 			}
 
 			for ( var j = 0; j < vertices.length; j ++ ) {

+ 7 - 3
examples/js/geometries/hilbert2D.js

@@ -15,9 +15,10 @@
  * @param v2         Corner index +X, +Z.
  * @param v3         Corner index +X, -Z.
  */
-function hilbert2D (center, size, iterations, v0, v1, v2, v3) {
+function hilbert2D ( center, size, iterations, v0, v1, v2, v3 ) {
+
 	// Default Vars
-	var center     = undefined !== center ? center : new THREE.Vector3(0, 0, 0),
+	var center     = undefined !== center ? center : new THREE.Vector3( 0, 0, 0 ),
 		size       = undefined !== size ? size : 10,
 		half       = size / 2,
 		iterations = undefined !== iterations ? iterations : 1,
@@ -42,7 +43,8 @@ function hilbert2D (center, size, iterations, v0, v1, v2, v3) {
 	];
 
 	// Recurse iterations
-	if (0 <= -- iterations) {
+	if ( 0 <= -- iterations ) {
+
 		var tmp = [];
 
 		Array.prototype.push.apply( tmp, hilbert2D ( vec[ 0 ], half, iterations, v0, v3, v2, v1 ) );
@@ -52,8 +54,10 @@ function hilbert2D (center, size, iterations, v0, v1, v2, v3) {
 
 		// Return recursive call
 		return tmp;
+
 	}
 
 	// Return complete Hilbert Curve.
 	return vec;
+
 }

+ 6 - 2
examples/js/geometries/hilbert3D.js

@@ -24,9 +24,10 @@
  * @param v6         Corner index +X, +Y, +Z.
  * @param v7         Corner index +X, +Y, -Z.
  */
-function hilbert3D(center, size, iterations, v0, v1, v2, v3, v4, v5, v6, v7) {
+function hilbert3D( center, size, iterations, v0, v1, v2, v3, v4, v5, v6, v7 ) {
+
 	// Default Vars
-	var center     = undefined !== center ? center : new THREE.Vector3(0, 0, 0),
+	var center     = undefined !== center ? center : new THREE.Vector3( 0, 0, 0 ),
 		size       = undefined !== size ? size : 10,
 		half       = size / 2,
 		iterations = undefined !== iterations ? iterations : 1,
@@ -64,6 +65,7 @@ function hilbert3D(center, size, iterations, v0, v1, v2, v3, v4, v5, v6, v7) {
 
 	// Recurse iterations
 	if ( -- iterations >= 0 ) {
+
 		var tmp = [];
 
 		Array.prototype.push.apply( tmp, hilbert3D ( vec[ 0 ], half, iterations, v0, v3, v4, v7, v6, v5, v2, v1 ) );
@@ -77,8 +79,10 @@ function hilbert3D(center, size, iterations, v0, v1, v2, v3, v4, v5, v6, v7) {
 
 		// Return recursive call
 		return tmp;
+
 	}
 
 	// Return complete Hilbert Curve.
 	return vec;
+
 }

Разница между файлами не показана из-за своего большого размера
+ 294 - 172
examples/js/loaders/AWDLoader.js


+ 171 - 85
examples/js/loaders/AssimpJSONLoader.js

@@ -14,6 +14,7 @@
 THREE.AssimpJSONLoader = function ( manager ) {
 
 	this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
+
 };
 
 THREE.AssimpJSONLoader.prototype = {
@@ -29,109 +30,142 @@ THREE.AssimpJSONLoader.prototype = {
 		var loader = new THREE.XHRLoader( this.manager );
 		loader.setCrossOrigin( this.crossOrigin );
 		loader.load( url, function ( text ) {
+
 			var json = JSON.parse( text ), scene, metadata;
 
 			// Check __metadata__ meta header if present
 			// This header is used to disambiguate between
 			// different JSON-based file formats.
 			metadata = json.__metadata__;
-			if ( typeof metadata !== 'undefined' )
-			{
+			if ( typeof metadata !== 'undefined' ) {
+
 				// Check if assimp2json at all
 				if ( metadata.format !== 'assimp2json' ) {
-					onError('Not an assimp2json scene');
+
+					onError( 'Not an assimp2json scene' );
 					return;
+
 				}
 				// Check major format version
 				else if ( metadata.version < 100 && metadata.version >= 200 ) {
-					onError('Unsupported assimp2json file format version');
+
+					onError( 'Unsupported assimp2json file format version' );
 					return;
+
 				}
+
 			}
 
 			scene = scope.parse( json );
 			onLoad( scene );
+
 		}, onProgress, onError );
+
 	},
 
 	setCrossOrigin: function ( value ) {
+
 		this.crossOrigin = value;
+
 	},
 
 	setTexturePath: function ( value ) {
+
 		this.texturePath = value;
+
 	},
 
-	extractUrlBase: function ( url ) { // from three/src/loaders/Loader.js
+	extractUrlBase: function ( url ) {
+
+		// from three/src/loaders/Loader.js
 		var parts = url.split( '/' );
 		parts.pop();
 		return ( parts.length < 1 ? '.' : parts.join( '/' ) ) + '/';
+
 	},
 
 	parse: function ( json ) {
+
 		var meshes = this.parseList ( json.meshes, this.parseMesh );
 		var materials = this.parseList ( json.materials, this.parseMaterial );
 		return this.parseObject( json, json.rootnode, meshes, materials );
+
 	},
 
-	parseList : function(json, handler) {
-		var meshes = new Array(json.length);
-		for (var i = 0; i < json.length; ++ i) {
-			meshes[i] = handler.call(this, json[i]);
+	parseList : function( json, handler ) {
+
+		var meshes = new Array( json.length );
+		for ( var i = 0; i < json.length; ++ i ) {
+
+			meshes[ i ] = handler.call( this, json[ i ] );
+
 		}
 		return meshes;
+
 	},
 
-	parseMesh : function(json) {
+	parseMesh : function( json ) {
+
 		var vertex, geometry, i, e, in_data, src;
 
 
 		geometry = new THREE.Geometry();
 
 		// read vertex positions
-		for (in_data = json.vertices, i = 0, e = in_data.length; i < e; ) {
+		for ( in_data = json.vertices, i = 0, e = in_data.length; i < e; ) {
+
 			geometry.vertices.push( new THREE.Vector3( in_data[ i ++ ], in_data[ i ++ ], in_data[ i ++ ] ) );
+
 		}
 
 		// read faces
 		var cnt = 0;
-		for (in_data = json.faces, i = 0, e = in_data.length; i < e; ++ i) {
-			src = in_data[i];
-			face = new THREE.Face3(src[0],src[1],src[2]);
-			geometry.faces.push(face);
+		for ( in_data = json.faces, i = 0, e = in_data.length; i < e; ++ i ) {
+
+			src = in_data[ i ];
+			face = new THREE.Face3( src[ 0 ], src[ 1 ], src[ 2 ] );
+			geometry.faces.push( face );
+
 		}
 
 		// read texture coordinates - three.js attaches them to its faces
 		json.texturecoords = json.texturecoords || [];
-		for (i = 0, e = json.texturecoords.length; i < e; ++ i) {
+		for ( i = 0, e = json.texturecoords.length; i < e; ++ i ) {
+
+			function convertTextureCoords( in_uv, out_faces, out_vertex_uvs ) {
 
-			function convertTextureCoords(in_uv, out_faces, out_vertex_uvs) {
 				var i, e, face, a, b, c;
 
-				for (i = 0, e = out_faces.length; i < e; ++ i) {
-					face = out_faces[i];
+				for ( i = 0, e = out_faces.length; i < e; ++ i ) {
+
+					face = out_faces[ i ];
 					a = face.a * 2;
 					b = face.b * 2;
 					c = face.c * 2;
-					out_vertex_uvs.push([
+					out_vertex_uvs.push( [
 						new THREE.Vector2( in_uv[ a ], in_uv[ a + 1 ] ),
 						new THREE.Vector2( in_uv[ b ], in_uv[ b + 1 ] ),
 						new THREE.Vector2( in_uv[ c ], in_uv[ c + 1 ] )
-					]);
+					] );
+
 				}
+
 			}
 
-			convertTextureCoords(json.texturecoords[i], geometry.faces, geometry.faceVertexUvs[i]);
+			convertTextureCoords( json.texturecoords[ i ], geometry.faces, geometry.faceVertexUvs[ i ] );
+
 		}
 
 		// read normals - three.js also attaches them to its faces
-		if (json.normals) {
+		if ( json.normals ) {
+
+			function convertNormals( in_nor, out_faces ) {
 
-			function convertNormals(in_nor, out_faces) {
 				var i, e, face, a, b, c;
 
-				for (i = 0, e = out_faces.length; i < e; ++ i) {
-					face = out_faces[i];
+				for ( i = 0, e = out_faces.length; i < e; ++ i ) {
+
+					face = out_faces[ i ];
 					a = face.a * 3;
 					b = face.b * 3;
 					c = face.c * 3;
@@ -140,27 +174,34 @@ THREE.AssimpJSONLoader.prototype = {
 						new THREE.Vector3( in_nor[ b ], in_nor[ b + 1 ], in_nor[ b + 2 ] ),
 						new THREE.Vector3( in_nor[ c ], in_nor[ c + 1 ], in_nor[ c + 2 ] )
 					];
+
 				}
+
 			}
 
-			convertNormals(json.normals, geometry.faces);
+			convertNormals( json.normals, geometry.faces );
+
 		}
 
 		// read vertex colors - three.js also attaches them to its faces
-		if (json.colors && json.colors[0]) {
+		if ( json.colors && json.colors[ 0 ] ) {
+
+			function convertColors( in_color, out_faces ) {
 
-			function convertColors(in_color, out_faces) {
 				var i, e, face, a, b, c;
 
-				function makeColor(start) {
+				function makeColor( start ) {
+
 					var col = new THREE.Color( );
-					col.setRGB( arr[0], arr[1], arr[2] );
+					col.setRGB( arr[ 0 ], arr[ 1 ], arr[ 2 ] );
 					// TODO: what about alpha?
 					return col;
+
 				}
 
-				for (i = 0, e = out_faces.length; i < e; ++ i) {
-					face = out_faces[i];
+				for ( i = 0, e = out_faces.length; i < e; ++ i ) {
+
+					face = out_faces[ i ];
 					a = face.a * 4;
 					b = face.b * 4;
 					c = face.c * 4;
@@ -169,10 +210,13 @@ THREE.AssimpJSONLoader.prototype = {
 						makeColor( b ),
 						makeColor( c )
 					];
+
 				}
+
 			}
 
-			convertColors(json.colors[0], geometry.faces);
+			convertColors( json.colors[ 0 ], geometry.faces );
+
 		}
 
 
@@ -183,9 +227,11 @@ THREE.AssimpJSONLoader.prototype = {
 
 		// TODO: tangents
 		return geometry;
+
 	},
 
-	parseMaterial : function(json) {
+	parseMaterial : function( json ) {
+
 		var mat = null,
 		scope = this, i, prop, has_textures = [],
 
@@ -193,120 +239,160 @@ THREE.AssimpJSONLoader.prototype = {
 			shading : THREE.SmoothShading
 		};
 
-		function toColor(value_arr) {
+		function toColor( value_arr ) {
+
 			var col = new THREE.Color();
-			col.setRGB(value_arr[0], value_arr[1], value_arr[2]);
+			col.setRGB( value_arr[ 0 ], value_arr[ 1 ], value_arr[ 2 ] );
 			return col;
+
 		}
 
 		function defaultTexture() {
+
 			var im = new Image();
 			im.width = 1;
 			im.height = 1;
-			return new THREE.Texture(im);
+			return new THREE.Texture( im );
+
 		}
 
-		for (var i in json.properties) {
-			prop = json.properties[i];
+		for ( var i in json.properties ) {
+
+			prop = json.properties[ i ];
+
+			if ( prop.key === '$tex.file' ) {
 
-			if (prop.key === '$tex.file') {
 				// prop.semantic gives the type of the texture
 				// 1: diffuse
 				// 2: specular mao
 				// 5: height map (bumps)
 				// 6: normal map
 				// more values (i.e. emissive, environment) are known by assimp and may be relevant
-				if (prop.semantic === 1 || prop.semantic === 5 || prop.semantic === 6 || prop.semantic === 2) {
-					(function(semantic) {
-						var loader = new THREE.TextureLoader(scope.manager),
+				if ( prop.semantic === 1 || prop.semantic === 5 || prop.semantic === 6 || prop.semantic === 2 ) {
+
+					( function( semantic ) {
+
+						var loader = new THREE.TextureLoader( scope.manager ),
 						keyname;
 
-						if (semantic === 1) {
+						if ( semantic === 1 ) {
+
 							keyname = 'map';
-						}
-						else if (semantic === 5) {
+
+						} else if ( semantic === 5 ) {
+
 							keyname = 'bumpMap';
-						}
-						else if (semantic === 6) {
+
+						} else if ( semantic === 6 ) {
+
 							keyname = 'normalMap';
-						}
-						else if (semantic === 2) {
+
+						} else if ( semantic === 2 ) {
+
 							keyname = 'specularMap';
+
 						}
 
-						has_textures.push(keyname);
+						has_textures.push( keyname );
 
-						loader.setCrossOrigin(this.crossOrigin);
+						loader.setCrossOrigin( this.crossOrigin );
 						var material_url = scope.texturePath + '/' + prop.value;
-						material_url = material_url.replace(/\\/g, '/');
-						loader.load(material_url, function(tex) {
-							if (tex) {
+						material_url = material_url.replace( /\\/g, '/' );
+						loader.load( material_url, function( tex ) {
+
+							if ( tex ) {
+
 								// TODO: read texture settings from assimp.
 								// Wrapping is the default, though.
 								tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
 
-								mat[keyname] = tex;
+								mat[ keyname ] = tex;
 								mat.needsUpdate = true;
+
 							}
-						});
-					})(prop.semantic);
+
+						} );
+
+					} )( prop.semantic );
+
 				}
-			}
-			else if (prop.key === '?mat.name') {
+
+			} else if ( prop.key === '?mat.name' ) {
+
 				init_props.name = prop.value;
-			}
-			else if (prop.key === '$clr.diffuse') {
-				init_props.color = toColor(prop.value);
-			}
-			else if (prop.key === '$clr.specular') {
-				init_props.specular = toColor(prop.value);
-			}
-			else if (prop.key === '$clr.emissive') {
-				init_props.emissive = toColor(prop.value);
-			}
-			else if (prop.key === '$mat.shadingm') {
+
+			} else if ( prop.key === '$clr.diffuse' ) {
+
+				init_props.color = toColor( prop.value );
+
+			} else if ( prop.key === '$clr.specular' ) {
+
+				init_props.specular = toColor( prop.value );
+
+			} else if ( prop.key === '$clr.emissive' ) {
+
+				init_props.emissive = toColor( prop.value );
+
+			} else if ( prop.key === '$mat.shadingm' ) {
+
 				// aiShadingMode_Flat
-				if (prop.value === 1) {
+				if ( prop.value === 1 ) {
+
 					init_props.shading = THREE.FlatShading;
+
 				}
-			}
-			else if (prop.key === '$mat.shininess') {
+
+			} else if ( prop.key === '$mat.shininess' ) {
+
 				init_props.shininess = prop.value;
+
 			}
+
 		}
 
 		// note: three.js does not like it when a texture is added after the geometry
 		// has been rendered once, see http://stackoverflow.com/questions/16531759/.
 		// for this reason we fill all slots upfront with default textures
-		if (has_textures.length) {
-			for (i = has_textures.length - 1; i >= 0; -- i) {
-				init_props[has_textures[i]] = defaultTexture();
+		if ( has_textures.length ) {
+
+			for ( i = has_textures.length - 1; i >= 0; -- i ) {
+
+				init_props[ has_textures[ i ]] = defaultTexture();
+
 			}
+
 		}
 
 		mat = new THREE.MeshPhongMaterial( init_props );
 		return mat;
+
 	},
 
-	parseObject : function(json, node, meshes, materials) {
+	parseObject : function( json, node, meshes, materials ) {
+
 		var obj = new THREE.Object3D()
 		,	i
 		,	idx
 		;
 
 		obj.name = node.name || "";
-		obj.matrix = new THREE.Matrix4().fromArray(node.transformation).transpose();
+		obj.matrix = new THREE.Matrix4().fromArray( node.transformation ).transpose();
 		obj.matrix.decompose( obj.position, obj.quaternion, obj.scale );
 
-		for (i = 0; node.meshes && i < node.meshes.length; ++ i) {
-			idx = node.meshes[i];
-			obj.add(new THREE.Mesh( meshes[idx], materials[json.meshes[idx].materialindex] ));
+		for ( i = 0; node.meshes && i < node.meshes.length; ++ i ) {
+
+			idx = node.meshes[ i ];
+			obj.add( new THREE.Mesh( meshes[ idx ], materials[ json.meshes[ idx ].materialindex ] ) );
+
 		}
 
-		for (i = 0; node.children && i < node.children.length; ++ i) {
-			obj.add(this.parseObject(json, node.children[i], meshes, materials));
+		for ( i = 0; node.children && i < node.children.length; ++ i ) {
+
+			obj.add( this.parseObject( json, node.children[ i ], meshes, materials ) );
+
 		}
 
 		return obj;
+
 	},
 };

+ 115 - 115
examples/js/loaders/BinaryLoader.js

@@ -50,7 +50,7 @@ THREE.BinaryLoader.prototype = {
 
 				scope.parse( bufData, onLoad, texturePath, json.materials );
 
-			}, onProgress, onError);
+			}, onProgress, onError );
 
 		}, onProgress, onError );
 
@@ -95,12 +95,12 @@ THREE.BinaryLoader.prototype = {
 			md = parseMetaData( data, currentOffset );
 
 			currentOffset += md.header_bytes;
-	/*
-			md.vertex_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
-			md.material_index_bytes = Uint16Array.BYTES_PER_ELEMENT;
-			md.normal_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
-			md.uv_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
-	*/
+			/*
+					md.vertex_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
+					md.material_index_bytes = Uint16Array.BYTES_PER_ELEMENT;
+					md.normal_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
+					md.uv_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
+			*/
 			// buffers sizes
 
 			tri_size =  md.vertex_index_bytes * 3 + md.material_index_bytes;
@@ -133,7 +133,7 @@ THREE.BinaryLoader.prototype = {
 			start_quad_flat     = start_tri_smooth_uv + len_tri_smooth_uv  + handlePadding( md.ntri_smooth_uv * 2 );
 			start_quad_smooth   = start_quad_flat     + len_quad_flat	   + handlePadding( md.nquad_flat * 2 );
 			start_quad_flat_uv  = start_quad_smooth   + len_quad_smooth    + handlePadding( md.nquad_smooth * 2 );
-			start_quad_smooth_uv= start_quad_flat_uv  + len_quad_flat_uv   + handlePadding( md.nquad_flat_uv * 2 );
+			start_quad_smooth_uv = start_quad_flat_uv  + len_quad_flat_uv   + handlePadding( md.nquad_flat_uv * 2 );
 
 			// have to first process faces with uvs
 			// so that face and uv indices match
@@ -164,75 +164,75 @@ THREE.BinaryLoader.prototype = {
 
 				var metaData = {
 
-					'signature'               :parseString( data, offset,  12 ),
-					'header_bytes'            :parseUChar8( data, offset + 12 ),
+					'signature'               : parseString( data, offset,  12 ),
+					'header_bytes'            : parseUChar8( data, offset + 12 ),
 
-					'vertex_coordinate_bytes' :parseUChar8( data, offset + 13 ),
-					'normal_coordinate_bytes' :parseUChar8( data, offset + 14 ),
-					'uv_coordinate_bytes'     :parseUChar8( data, offset + 15 ),
+					'vertex_coordinate_bytes' : parseUChar8( data, offset + 13 ),
+					'normal_coordinate_bytes' : parseUChar8( data, offset + 14 ),
+					'uv_coordinate_bytes'     : parseUChar8( data, offset + 15 ),
 
-					'vertex_index_bytes'      :parseUChar8( data, offset + 16 ),
-					'normal_index_bytes'      :parseUChar8( data, offset + 17 ),
-					'uv_index_bytes'          :parseUChar8( data, offset + 18 ),
-					'material_index_bytes'    :parseUChar8( data, offset + 19 ),
+					'vertex_index_bytes'      : parseUChar8( data, offset + 16 ),
+					'normal_index_bytes'      : parseUChar8( data, offset + 17 ),
+					'uv_index_bytes'          : parseUChar8( data, offset + 18 ),
+					'material_index_bytes'    : parseUChar8( data, offset + 19 ),
 
-					'nvertices'    :parseUInt32( data, offset + 20 ),
-					'nnormals'     :parseUInt32( data, offset + 20 + 4*1 ),
-					'nuvs'         :parseUInt32( data, offset + 20 + 4*2 ),
+					'nvertices'    : parseUInt32( data, offset + 20 ),
+					'nnormals'     : parseUInt32( data, offset + 20 + 4 * 1 ),
+					'nuvs'         : parseUInt32( data, offset + 20 + 4 * 2 ),
 
-					'ntri_flat'      :parseUInt32( data, offset + 20 + 4*3 ),
-					'ntri_smooth'    :parseUInt32( data, offset + 20 + 4*4 ),
-					'ntri_flat_uv'   :parseUInt32( data, offset + 20 + 4*5 ),
-					'ntri_smooth_uv' :parseUInt32( data, offset + 20 + 4*6 ),
+					'ntri_flat'      : parseUInt32( data, offset + 20 + 4 * 3 ),
+					'ntri_smooth'    : parseUInt32( data, offset + 20 + 4 * 4 ),
+					'ntri_flat_uv'   : parseUInt32( data, offset + 20 + 4 * 5 ),
+					'ntri_smooth_uv' : parseUInt32( data, offset + 20 + 4 * 6 ),
 
-					'nquad_flat'      :parseUInt32( data, offset + 20 + 4*7 ),
-					'nquad_smooth'    :parseUInt32( data, offset + 20 + 4*8 ),
-					'nquad_flat_uv'   :parseUInt32( data, offset + 20 + 4*9 ),
-					'nquad_smooth_uv' :parseUInt32( data, offset + 20 + 4*10 )
+					'nquad_flat'      : parseUInt32( data, offset + 20 + 4 * 7 ),
+					'nquad_smooth'    : parseUInt32( data, offset + 20 + 4 * 8 ),
+					'nquad_flat_uv'   : parseUInt32( data, offset + 20 + 4 * 9 ),
+					'nquad_smooth_uv' : parseUInt32( data, offset + 20 + 4 * 10 )
 
 				};
-	/*
-				console.log( "signature: " + metaData.signature );
-
-				console.log( "header_bytes: " + metaData.header_bytes );
-				console.log( "vertex_coordinate_bytes: " + metaData.vertex_coordinate_bytes );
-				console.log( "normal_coordinate_bytes: " + metaData.normal_coordinate_bytes );
-				console.log( "uv_coordinate_bytes: " + metaData.uv_coordinate_bytes );
-
-				console.log( "vertex_index_bytes: " + metaData.vertex_index_bytes );
-				console.log( "normal_index_bytes: " + metaData.normal_index_bytes );
-				console.log( "uv_index_bytes: " + metaData.uv_index_bytes );
-				console.log( "material_index_bytes: " + metaData.material_index_bytes );
-
-				console.log( "nvertices: " + metaData.nvertices );
-				console.log( "nnormals: " + metaData.nnormals );
-				console.log( "nuvs: " + metaData.nuvs );
-
-				console.log( "ntri_flat: " + metaData.ntri_flat );
-				console.log( "ntri_smooth: " + metaData.ntri_smooth );
-				console.log( "ntri_flat_uv: " + metaData.ntri_flat_uv );
-				console.log( "ntri_smooth_uv: " + metaData.ntri_smooth_uv );
-
-				console.log( "nquad_flat: " + metaData.nquad_flat );
-				console.log( "nquad_smooth: " + metaData.nquad_smooth );
-				console.log( "nquad_flat_uv: " + metaData.nquad_flat_uv );
-				console.log( "nquad_smooth_uv: " + metaData.nquad_smooth_uv );
-
-				var total = metaData.header_bytes
-						  + metaData.nvertices * metaData.vertex_coordinate_bytes * 3
-						  + metaData.nnormals * metaData.normal_coordinate_bytes * 3
-						  + metaData.nuvs * metaData.uv_coordinate_bytes * 2
-						  + metaData.ntri_flat * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes )
-						  + metaData.ntri_smooth * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.normal_index_bytes*3 )
-						  + metaData.ntri_flat_uv * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.uv_index_bytes*3 )
-						  + metaData.ntri_smooth_uv * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.normal_index_bytes*3 + metaData.uv_index_bytes*3 )
-						  + metaData.nquad_flat * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes )
-						  + metaData.nquad_smooth * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.normal_index_bytes*4 )
-						  + metaData.nquad_flat_uv * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.uv_index_bytes*4 )
-						  + metaData.nquad_smooth_uv * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.normal_index_bytes*4 + metaData.uv_index_bytes*4 );
-				console.log( "total bytes: " + total );
-	*/
-
+				/*
+							console.log( "signature: " + metaData.signature );
+
+							console.log( "header_bytes: " + metaData.header_bytes );
+							console.log( "vertex_coordinate_bytes: " + metaData.vertex_coordinate_bytes );
+							console.log( "normal_coordinate_bytes: " + metaData.normal_coordinate_bytes );
+							console.log( "uv_coordinate_bytes: " + metaData.uv_coordinate_bytes );
+
+							console.log( "vertex_index_bytes: " + metaData.vertex_index_bytes );
+							console.log( "normal_index_bytes: " + metaData.normal_index_bytes );
+							console.log( "uv_index_bytes: " + metaData.uv_index_bytes );
+							console.log( "material_index_bytes: " + metaData.material_index_bytes );
+
+							console.log( "nvertices: " + metaData.nvertices );
+							console.log( "nnormals: " + metaData.nnormals );
+							console.log( "nuvs: " + metaData.nuvs );
+
+							console.log( "ntri_flat: " + metaData.ntri_flat );
+							console.log( "ntri_smooth: " + metaData.ntri_smooth );
+							console.log( "ntri_flat_uv: " + metaData.ntri_flat_uv );
+							console.log( "ntri_smooth_uv: " + metaData.ntri_smooth_uv );
+
+							console.log( "nquad_flat: " + metaData.nquad_flat );
+							console.log( "nquad_smooth: " + metaData.nquad_smooth );
+							console.log( "nquad_flat_uv: " + metaData.nquad_flat_uv );
+							console.log( "nquad_smooth_uv: " + metaData.nquad_smooth_uv );
+
+							var total = metaData.header_bytes
+									  + metaData.nvertices * metaData.vertex_coordinate_bytes * 3
+									  + metaData.nnormals * metaData.normal_coordinate_bytes * 3
+									  + metaData.nuvs * metaData.uv_coordinate_bytes * 2
+									  + metaData.ntri_flat * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes )
+									  + metaData.ntri_smooth * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.normal_index_bytes*3 )
+									  + metaData.ntri_flat_uv * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.uv_index_bytes*3 )
+									  + metaData.ntri_smooth_uv * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.normal_index_bytes*3 + metaData.uv_index_bytes*3 )
+									  + metaData.nquad_flat * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes )
+									  + metaData.nquad_smooth * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.normal_index_bytes*4 )
+									  + metaData.nquad_flat_uv * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.uv_index_bytes*4 )
+									  + metaData.nquad_smooth_uv * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.normal_index_bytes*4 + metaData.uv_index_bytes*4 );
+							console.log( "total bytes: " + total );
+				*/
+				
 				return metaData;
 
 			}
@@ -277,7 +277,7 @@ THREE.BinaryLoader.prototype = {
 
 				var i, x, y, z;
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					x = coordArray[ i * 3 ];
 					y = coordArray[ i * 3 + 1 ];
@@ -301,13 +301,13 @@ THREE.BinaryLoader.prototype = {
 
 					var i, x, y, z;
 
-					for( i = 0; i < nElements; i ++ ) {
+					for ( i = 0; i < nElements; i ++ ) {
 
 						x = normalArray[ i * 3 ];
 						y = normalArray[ i * 3 + 1 ];
 						z = normalArray[ i * 3 + 2 ];
 
-						normals.push( x/127, y/127, z/127 );
+						normals.push( x / 127, y / 127, z / 127 );
 
 					}
 
@@ -327,7 +327,7 @@ THREE.BinaryLoader.prototype = {
 
 					var i, u, v;
 
-					for( i = 0; i < nElements; i ++ ) {
+					for ( i = 0; i < nElements; i ++ ) {
 
 						u = uvArray[ i * 2 ];
 						v = uvArray[ i * 2 + 1 ];
@@ -348,20 +348,20 @@ THREE.BinaryLoader.prototype = {
 
 				var uvIndexBuffer = new Uint32Array( data, offset, 3 * nElements );
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					uva = uvIndexBuffer[ i * 3 ];
 					uvb = uvIndexBuffer[ i * 3 + 1 ];
 					uvc = uvIndexBuffer[ i * 3 + 2 ];
 
-					u1 = uvs[ uva*2 ];
-					v1 = uvs[ uva*2 + 1 ];
+					u1 = uvs[ uva * 2 ];
+					v1 = uvs[ uva * 2 + 1 ];
 
-					u2 = uvs[ uvb*2 ];
-					v2 = uvs[ uvb*2 + 1 ];
+					u2 = uvs[ uvb * 2 ];
+					v2 = uvs[ uvb * 2 + 1 ];
 
-					u3 = uvs[ uvc*2 ];
-					v3 = uvs[ uvc*2 + 1 ];
+					u3 = uvs[ uvc * 2 ];
+					v3 = uvs[ uvc * 2 + 1 ];
 
 					scope.faceVertexUvs[ 0 ].push( [
 						new THREE.Vector2( u1, v1 ),
@@ -379,24 +379,24 @@ THREE.BinaryLoader.prototype = {
 
 				var uvIndexBuffer = new Uint32Array( data, offset, 4 * nElements );
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					uva = uvIndexBuffer[ i * 4 ];
 					uvb = uvIndexBuffer[ i * 4 + 1 ];
 					uvc = uvIndexBuffer[ i * 4 + 2 ];
 					uvd = uvIndexBuffer[ i * 4 + 3 ];
 
-					u1 = uvs[ uva*2 ];
-					v1 = uvs[ uva*2 + 1 ];
+					u1 = uvs[ uva * 2 ];
+					v1 = uvs[ uva * 2 + 1 ];
 
-					u2 = uvs[ uvb*2 ];
-					v2 = uvs[ uvb*2 + 1 ];
+					u2 = uvs[ uvb * 2 ];
+					v2 = uvs[ uvb * 2 + 1 ];
 
-					u3 = uvs[ uvc*2 ];
-					v3 = uvs[ uvc*2 + 1 ];
+					u3 = uvs[ uvc * 2 ];
+					v3 = uvs[ uvc * 2 + 1 ];
 
-					u4 = uvs[ uvd*2 ];
-					v4 = uvs[ uvd*2 + 1 ];
+					u4 = uvs[ uvd * 2 ];
+					v4 = uvs[ uvd * 2 + 1 ];
 
 					scope.faceVertexUvs[ 0 ].push( [
 						new THREE.Vector2( u1, v1 ),
@@ -421,7 +421,7 @@ THREE.BinaryLoader.prototype = {
 				var vertexIndexBuffer = new Uint32Array( data, offsetVertices, 3 * nElements );
 				var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					a = vertexIndexBuffer[ i * 3 ];
 					b = vertexIndexBuffer[ i * 3 + 1 ];
@@ -442,7 +442,7 @@ THREE.BinaryLoader.prototype = {
 				var vertexIndexBuffer = new Uint32Array( data, offsetVertices, 4 * nElements );
 				var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					a = vertexIndexBuffer[ i * 4 ];
 					b = vertexIndexBuffer[ i * 4 + 1 ];
@@ -467,7 +467,7 @@ THREE.BinaryLoader.prototype = {
 				var normalIndexBuffer = new Uint32Array( data, offsetNormals, 3 * nElements );
 				var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					a = vertexIndexBuffer[ i * 3 ];
 					b = vertexIndexBuffer[ i * 3 + 1 ];
@@ -479,17 +479,17 @@ THREE.BinaryLoader.prototype = {
 
 					m = materialIndexBuffer[ i ];
 
-					var nax = normals[ na*3     ],
-						nay = normals[ na*3 + 1 ],
-						naz = normals[ na*3 + 2 ],
+					var nax = normals[ na * 3 ],
+						nay = normals[ na * 3 + 1 ],
+						naz = normals[ na * 3 + 2 ],
 
-						nbx = normals[ nb*3     ],
-						nby = normals[ nb*3 + 1 ],
-						nbz = normals[ nb*3 + 2 ],
+						nbx = normals[ nb * 3 ],
+						nby = normals[ nb * 3 + 1 ],
+						nbz = normals[ nb * 3 + 2 ],
 
-						ncx = normals[ nc*3     ],
-						ncy = normals[ nc*3 + 1 ],
-						ncz = normals[ nc*3 + 2 ];
+						ncx = normals[ nc * 3 ],
+						ncy = normals[ nc * 3 + 1 ],
+						ncz = normals[ nc * 3 + 2 ];
 
 					scope.faces.push( new THREE.Face3( a, b, c, [
 						new THREE.Vector3( nax, nay, naz ),
@@ -510,7 +510,7 @@ THREE.BinaryLoader.prototype = {
 				var normalIndexBuffer = new Uint32Array( data, offsetNormals, 4 * nElements );
 				var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
 
-				for( i = 0; i < nElements; i ++ ) {
+				for ( i = 0; i < nElements; i ++ ) {
 
 					a = vertexIndexBuffer[ i * 4 ];
 					b = vertexIndexBuffer[ i * 4 + 1 ];
@@ -524,21 +524,21 @@ THREE.BinaryLoader.prototype = {
 
 					m = materialIndexBuffer[ i ];
 
-					var nax = normals[ na*3     ],
-						nay = normals[ na*3 + 1 ],
-						naz = normals[ na*3 + 2 ],
+					var nax = normals[ na * 3 ],
+						nay = normals[ na * 3 + 1 ],
+						naz = normals[ na * 3 + 2 ],
 
-						nbx = normals[ nb*3     ],
-						nby = normals[ nb*3 + 1 ],
-						nbz = normals[ nb*3 + 2 ],
+						nbx = normals[ nb * 3 ],
+						nby = normals[ nb * 3 + 1 ],
+						nbz = normals[ nb * 3 + 2 ],
 
-						ncx = normals[ nc*3     ],
-						ncy = normals[ nc*3 + 1 ],
-						ncz = normals[ nc*3 + 2 ],
+						ncx = normals[ nc * 3 ],
+						ncy = normals[ nc * 3 + 1 ],
+						ncz = normals[ nc * 3 + 2 ],
 
-						ndx = normals[ nd*3     ],
-						ndy = normals[ nd*3 + 1 ],
-						ndz = normals[ nd*3 + 2 ];
+						ndx = normals[ nd * 3 ],
+						ndy = normals[ nd * 3 + 1 ],
+						ndz = normals[ nd * 3 + 2 ];
 
 					scope.faces.push( new THREE.Face3( a, b, d, [
 						new THREE.Vector3( nax, nay, naz ),

Разница между файлами не показана из-за своего большого размера
+ 183 - 150
examples/js/loaders/ColladaLoader.js


+ 40 - 23
examples/js/loaders/DDSLoader.js

@@ -3,7 +3,9 @@
  */
 
 THREE.DDSLoader = function () {
+
 	this._parser = THREE.DDSLoader.parse;
+
 };
 
 THREE.DDSLoader.prototype = Object.create( THREE.CompressedTextureLoader.prototype );
@@ -52,10 +54,10 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
 
 	function fourCCToInt32( value ) {
 
-		return value.charCodeAt(0) +
-			(value.charCodeAt(1) << 8) +
-			(value.charCodeAt(2) << 16) +
-			(value.charCodeAt(3) << 24);
+		return value.charCodeAt( 0 ) +
+			( value.charCodeAt( 1 ) << 8 ) +
+			( value.charCodeAt( 2 ) << 16 ) +
+			( value.charCodeAt( 3 ) << 24 );
 
 	}
 
@@ -63,36 +65,43 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
 
 		return String.fromCharCode(
 			value & 0xff,
-			(value >> 8) & 0xff,
-			(value >> 16) & 0xff,
-			(value >> 24) & 0xff
+			( value >> 8 ) & 0xff,
+			( value >> 16 ) & 0xff,
+			( value >> 24 ) & 0xff
 		);
+
 	}
 
 	function loadARGBMip( buffer, dataOffset, width, height ) {
+
 		var dataLength = width * height * 4;
 		var srcBuffer = new Uint8Array( buffer, dataOffset, dataLength );
 		var byteArray = new Uint8Array( dataLength );
 		var dst = 0;
 		var src = 0;
 		for ( var y = 0; y < height; y ++ ) {
+
 			for ( var x = 0; x < width; x ++ ) {
-				var b = srcBuffer[src]; src ++;
-				var g = srcBuffer[src]; src ++;
-				var r = srcBuffer[src]; src ++;
-				var a = srcBuffer[src]; src ++;
-				byteArray[dst] = r; dst ++;	//r
-				byteArray[dst] = g; dst ++;	//g
-				byteArray[dst] = b; dst ++;	//b
-				byteArray[dst] = a; dst ++;	//a
+
+				var b = srcBuffer[ src ]; src ++;
+				var g = srcBuffer[ src ]; src ++;
+				var r = srcBuffer[ src ]; src ++;
+				var a = srcBuffer[ src ]; src ++;
+				byteArray[ dst ] = r; dst ++;	//r
+				byteArray[ dst ] = g; dst ++;	//g
+				byteArray[ dst ] = b; dst ++;	//b
+				byteArray[ dst ] = a; dst ++;	//a
+
 			}
+
 		}
 		return byteArray;
+
 	}
 
-	var FOURCC_DXT1 = fourCCToInt32("DXT1");
-	var FOURCC_DXT3 = fourCCToInt32("DXT3");
-	var FOURCC_DXT5 = fourCCToInt32("DXT5");
+	var FOURCC_DXT1 = fourCCToInt32( "DXT1" );
+	var FOURCC_DXT3 = fourCCToInt32( "DXT3" );
+	var FOURCC_DXT5 = fourCCToInt32( "DXT5" );
 
 	var headerLengthInt = 31; // The header length in 32 bit ints
 
@@ -166,17 +175,21 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
 
 		default:
 
-			if ( header[off_RGBBitCount] == 32 
-				&& header[off_RBitMask]&0xff0000
-				&& header[off_GBitMask]&0xff00 
-				&& header[off_BBitMask]&0xff
-				&& header[off_ABitMask]&0xff000000  ) {
+			if ( header[ off_RGBBitCount ] == 32 
+				&& header[ off_RBitMask ] & 0xff0000
+				&& header[ off_GBitMask ] & 0xff00 
+				&& header[ off_BBitMask ] & 0xff
+				&& header[ off_ABitMask ] & 0xff000000  ) {
+
 				isRGBAUncompressed = true;
 				blockBytes = 64;
 				dds.format = THREE.RGBAFormat;
+
 			} else {
+
 				console.error( 'THREE.DDSLoader.parse: Unsupported FourCC code ', int32ToFourCC( fourCC ) );
 				return dds;
+
 			}
 	}
 
@@ -209,11 +222,15 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
 		for ( var i = 0; i < dds.mipmapCount; i ++ ) {
 
 			if ( isRGBAUncompressed ) {
+
 				var byteArray = loadARGBMip( buffer, dataOffset, width, height );
 				var dataLength = byteArray.length;
+
 			} else {
+
 				var dataLength = Math.max( 4, width ) / 4 * Math.max( 4, height ) / 4 * blockBytes;
 				var byteArray = new Uint8Array( buffer, dataOffset, dataLength );
+
 			}
 			
 			var mipmap = { "data": byteArray, "width": width, "height": height };

+ 7 - 6
examples/js/loaders/MTLLoader.js

@@ -90,7 +90,7 @@ THREE.MTLLoader.prototype = {
 				if ( key === "ka" || key === "kd" || key === "ks" ) {
 
 					var ss = value.split( delimiter_pattern, 3 );
-					info[ key ] = [ parseFloat( ss[0] ), parseFloat( ss[1] ), parseFloat( ss[2] ) ];
+					info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ];
 
 				} else {
 
@@ -170,7 +170,7 @@ THREE.MTLLoader.MaterialCreator.prototype = {
 
 	convert: function( materialsInfo ) {
 
-		if ( !this.options ) return materialsInfo;
+		if ( ! this.options ) return materialsInfo;
 
 		var converted = {};
 
@@ -213,6 +213,7 @@ THREE.MTLLoader.MaterialCreator.prototype = {
 								save = false;
 
 							}
+
 						}
 
 						break;
@@ -350,7 +351,7 @@ THREE.MTLLoader.MaterialCreator.prototype = {
 					// The specular exponent (defines the focus of the specular highlight)
 					// A high exponent results in a tight, concentrated highlight. Ns values normally range from 0 to 1000.
 
-					params['shininess'] = value;
+					params[ 'shininess' ] = value;
 
 					break;
 
@@ -362,8 +363,8 @@ THREE.MTLLoader.MaterialCreator.prototype = {
 
 					if ( value < 1 ) {
 
-						params['transparent'] = true;
-						params['opacity'] = value;
+						params[ 'transparent' ] = true;
+						params[ 'opacity' ] = value;
 
 					}
 
@@ -444,7 +445,7 @@ THREE.MTLLoader.ensurePowerOfTwo_ = function ( image ) {
 		canvas.width = THREE.MTLLoader.nextHighestPowerOfTwo_( image.width );
 		canvas.height = THREE.MTLLoader.nextHighestPowerOfTwo_( image.height );
 
-		var ctx = canvas.getContext("2d");
+		var ctx = canvas.getContext( "2d" );
 		ctx.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
 		return canvas;
 

+ 4 - 0
examples/js/loaders/OBJLoader.js

@@ -352,11 +352,15 @@ THREE.OBJLoader.prototype = {
 			buffergeometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( geometry.vertices ), 3 ) );
 
 			if ( geometry.normals.length > 0 ) {
+
 				buffergeometry.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( geometry.normals ), 3 ) );
+
 			}
 
 			if ( geometry.uvs.length > 0 ) {
+
 				buffergeometry.addAttribute( 'uv', new THREE.BufferAttribute( new Float32Array( geometry.uvs ), 2 ) );
+
 			}
 
 			material = new THREE.MeshLambertMaterial();

+ 18 - 16
examples/js/loaders/OBJMTLLoader.js

@@ -138,17 +138,17 @@ THREE.OBJMTLLoader.prototype = {
 			if ( normals_inds === undefined ) {
 
 				geometry.faces.push( face3(
-					parseInt( a ) - (face_offset + 1),
-					parseInt( b ) - (face_offset + 1),
-					parseInt( c ) - (face_offset + 1)
+					parseInt( a ) - ( face_offset + 1 ),
+					parseInt( b ) - ( face_offset + 1 ),
+					parseInt( c ) - ( face_offset + 1 )
 				) );
 
 			} else {
 
 				geometry.faces.push( face3(
-					parseInt( a ) - (face_offset + 1),
-					parseInt( b ) - (face_offset + 1),
-					parseInt( c ) - (face_offset + 1),
+					parseInt( a ) - ( face_offset + 1 ),
+					parseInt( b ) - ( face_offset + 1 ),
+					parseInt( c ) - ( face_offset + 1 ),
 					[
 						normals[ parseInt( normals_inds[ 0 ] ) - 1 ].clone(),
 						normals[ parseInt( normals_inds[ 1 ] ) - 1 ].clone(),
@@ -170,31 +170,33 @@ THREE.OBJMTLLoader.prototype = {
 
 		}
 
-		function handle_face_line(faces, uvs, normals_inds) {
+		function handle_face_line( faces, uvs, normals_inds ) {
 
 			if ( faces[ 3 ] === undefined ) {
 
 				add_face( faces[ 0 ], faces[ 1 ], faces[ 2 ], normals_inds );
 
-				if (!(uvs === undefined) && uvs.length > 0) {
+				if ( ! ( uvs === undefined ) && uvs.length > 0 ) {
+
 					add_uvs( uvs[ 0 ], uvs[ 1 ], uvs[ 2 ] );
+
 				}
 
 			} else {
 
-				if (!(normals_inds === undefined) && normals_inds.length > 0) {
+				if ( ! ( normals_inds === undefined ) && normals_inds.length > 0 ) {
 
-					add_face( faces[ 0 ], faces[ 1 ], faces[ 3 ], [ normals_inds[ 0 ], normals_inds[ 1 ], normals_inds[ 3 ] ]);
-					add_face( faces[ 1 ], faces[ 2 ], faces[ 3 ], [ normals_inds[ 1 ], normals_inds[ 2 ], normals_inds[ 3 ] ]);
+					add_face( faces[ 0 ], faces[ 1 ], faces[ 3 ], [ normals_inds[ 0 ], normals_inds[ 1 ], normals_inds[ 3 ] ] );
+					add_face( faces[ 1 ], faces[ 2 ], faces[ 3 ], [ normals_inds[ 1 ], normals_inds[ 2 ], normals_inds[ 3 ] ] );
 
 				} else {
 
-					add_face( faces[ 0 ], faces[ 1 ], faces[ 3 ]);
-					add_face( faces[ 1 ], faces[ 2 ], faces[ 3 ]);
+					add_face( faces[ 0 ], faces[ 1 ], faces[ 3 ] );
+					add_face( faces[ 1 ], faces[ 2 ], faces[ 3 ] );
 
 				}
 
-				if (!(uvs === undefined) && uvs.length > 0) {
+				if ( ! ( uvs === undefined ) && uvs.length > 0 ) {
 
 					add_uvs( uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] );
 					add_uvs( uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] );
@@ -282,7 +284,7 @@ THREE.OBJMTLLoader.prototype = {
 
 				// ["f 1 2 3", "1", "2", "3", undefined]
 
-				handle_face_line([ result[ 1 ], result[ 2 ], result[ 3 ], result[ 4 ] ]);
+				handle_face_line( [ result[ 1 ], result[ 2 ], result[ 3 ], result[ 4 ] ] );
 
 			} else if ( ( result = face_pattern2.exec( line ) ) !== null ) {
 
@@ -361,7 +363,7 @@ THREE.OBJMTLLoader.prototype = {
 		}
 
 		//Add last object
-		meshN(undefined, undefined);
+		meshN( undefined, undefined );
 
 		return group;
 

Разница между файлами не показана из-за своего большого размера
+ 2 - 2
examples/js/loaders/PDBLoader.js


+ 61 - 47
examples/js/loaders/PLYLoader.js

@@ -66,12 +66,14 @@ THREE.PLYLoader.prototype = {
 
 	},
 
-	bin2str: function (buf) {
+	bin2str: function ( buf ) {
 
-		var array_buffer = new Uint8Array(buf);
+		var array_buffer = new Uint8Array( buf );
 		var str = '';
-		for (var i = 0; i < buf.byteLength; i ++) {
-			str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
+		for ( var i = 0; i < buf.byteLength; i ++ ) {
+
+			str += String.fromCharCode( array_buffer[ i ] ); // implicitly assumes little-endian
+
 		}
 
 		return str;
@@ -109,8 +111,10 @@ THREE.PLYLoader.prototype = {
 		var headerLength = 0;
 		var result = patternHeader.exec( data );
 		if ( result !== null ) {
+
 			headerText = result [ 1 ];
 			headerLength = result[ 0 ].length;
+
 		}
 
 		var header = {
@@ -155,37 +159,41 @@ THREE.PLYLoader.prototype = {
 
 			var line = lines[ i ];
 			line = line.trim();
-			if ( line === "" ) { continue; }
+			if ( line === "" ) {
+
+				continue;
+
+			}
 			lineValues = line.split( /\s+/ );
 			lineType = lineValues.shift();
-			line = lineValues.join(" ");
+			line = lineValues.join( " " );
 
 			switch ( lineType ) {
 
 			case "format":
 
-				header.format = lineValues[0];
-				header.version = lineValues[1];
+				header.format = lineValues[ 0 ];
+				header.version = lineValues[ 1 ];
 
 				break;
 
 			case "comment":
 
-				header.comments.push(line);
+				header.comments.push( line );
 
 				break;
 
 			case "element":
 
-				if ( !(currentElement === undefined) ) {
+				if ( ! ( currentElement === undefined ) ) {
 
-					header.elements.push(currentElement);
+					header.elements.push( currentElement );
 
 				}
 
 				currentElement = Object();
-				currentElement.name = lineValues[0];
-				currentElement.count = parseInt( lineValues[1] );
+				currentElement.name = lineValues[ 0 ];
+				currentElement.count = parseInt( lineValues[ 1 ] );
 				currentElement.properties = [];
 
 				break;
@@ -199,15 +207,15 @@ THREE.PLYLoader.prototype = {
 
 			default:
 
-				console.log("unhandled", lineType, lineValues);
+				console.log( "unhandled", lineType, lineValues );
 
 			}
 
 		}
 
-		if ( !(currentElement === undefined) ) {
+		if ( ! ( currentElement === undefined ) ) {
 
-			header.elements.push(currentElement);
+			header.elements.push( currentElement );
 
 		}
 
@@ -240,22 +248,22 @@ THREE.PLYLoader.prototype = {
 
 		for ( var i = 0; i < properties.length; i ++ ) {
 
-			if ( properties[i].type === "list" ) {
+			if ( properties[ i ].type === "list" ) {
 
 				var list = [];
-				var n = this.parseASCIINumber( values.shift(), properties[i].countType );
+				var n = this.parseASCIINumber( values.shift(), properties[ i ].countType );
 
 				for ( var j = 0; j < n; j ++ ) {
 
-					list.push( this.parseASCIINumber( values.shift(), properties[i].itemType ) );
+					list.push( this.parseASCIINumber( values.shift(), properties[ i ].itemType ) );
 
 				}
 
-				element[ properties[i].name ] = list;
+				element[ properties[ i ].name ] = list;
 
 			} else {
 
-				element[ properties[i].name ] = this.parseASCIINumber( values.shift(), properties[i].type );
+				element[ properties[ i ].name ] = this.parseASCIINumber( values.shift(), properties[ i ].type );
 
 			}
 
@@ -278,7 +286,9 @@ THREE.PLYLoader.prototype = {
 		var patternBody = /end_header\s([\s\S]*)$/;
 		var body = "";
 		if ( ( result = patternBody.exec( data ) ) !== null ) {
+
 			body = result [ 1 ];
+
 		}
 
 		var lines = body.split( '\n' );
@@ -290,18 +300,22 @@ THREE.PLYLoader.prototype = {
 
 			var line = lines[ i ];
 			line = line.trim();
-			if ( line === "" ) { continue; }
+			if ( line === "" ) {
+
+				continue;
 
-			if ( currentElementCount >= header.elements[currentElement].count ) {
+			}
+
+			if ( currentElementCount >= header.elements[ currentElement ].count ) {
 
 				currentElement ++;
 				currentElementCount = 0;
 
 			}
 
-			var element = this.parseASCIIElement( header.elements[currentElement].properties, line );
+			var element = this.parseASCIIElement( header.elements[ currentElement ].properties, line );
 
-			this.handleElement( geometry, header.elements[currentElement].name, element );
+			this.handleElement( geometry, header.elements[ currentElement ].name, element );
 
 			currentElementCount ++;
 
@@ -317,10 +331,10 @@ THREE.PLYLoader.prototype = {
 
 			for ( var i = 0; i < geometry.faces.length; i ++ ) {
 
-				geometry.faces[i].vertexColors = [
-					geometry.colors[geometry.faces[i].a],
-					geometry.colors[geometry.faces[i].b],
-					geometry.colors[geometry.faces[i].c]
+				geometry.faces[ i ].vertexColors = [
+					geometry.colors[ geometry.faces[ i ].a ],
+					geometry.colors[ geometry.faces[ i ].b ],
+					geometry.colors[ geometry.faces[ i ].c ]
 				];
 
 			}
@@ -408,29 +422,29 @@ THREE.PLYLoader.prototype = {
 
 		for ( var i = 0; i < properties.length; i ++ ) {
 
-			if ( properties[i].type === "list" ) {
+			if ( properties[ i ].type === "list" ) {
 
 				var list = [];
 
-				result = this.binaryRead( dataview, at + read, properties[i].countType, little_endian );
-				var n = result[0];
-				read += result[1];
+				result = this.binaryRead( dataview, at + read, properties[ i ].countType, little_endian );
+				var n = result[ 0 ];
+				read += result[ 1 ];
 
 				for ( var j = 0; j < n; j ++ ) {
 
-					result = this.binaryRead( dataview, at + read, properties[i].itemType, little_endian );
-					list.push( result[0] );
-					read += result[1];
+					result = this.binaryRead( dataview, at + read, properties[ i ].itemType, little_endian );
+					list.push( result[ 0 ] );
+					read += result[ 1 ];
 
 				}
 
-				element[ properties[i].name ] = list;
+				element[ properties[ i ].name ] = list;
 
 			} else {
 
-				result = this.binaryRead( dataview, at + read, properties[i].type, little_endian );
-				element[ properties[i].name ] = result[0];
-				read += result[1];
+				result = this.binaryRead( dataview, at + read, properties[ i ].type, little_endian );
+				element[ properties[ i ].name ] = result[ 0 ];
+				read += result[ 1 ];
 
 			}
 
@@ -445,19 +459,19 @@ THREE.PLYLoader.prototype = {
 		var geometry = new THREE.Geometry();
 
 		var header = this.parseHeader( this.bin2str( data ) );
-		var little_endian = (header.format === "binary_little_endian");
+		var little_endian = ( header.format === "binary_little_endian" );
 		var body = new DataView( data, header.headerLength );
 		var result, loc = 0;
 
 		for ( var currentElement = 0; currentElement < header.elements.length; currentElement ++ ) {
 
-			for ( var currentElementCount = 0; currentElementCount < header.elements[currentElement].count; currentElementCount ++ ) {
+			for ( var currentElementCount = 0; currentElementCount < header.elements[ currentElement ].count; currentElementCount ++ ) {
 
-				result = this.binaryReadElement( body, loc, header.elements[currentElement].properties, little_endian );
-				loc += result[1];
-				var element = result[0];
+				result = this.binaryReadElement( body, loc, header.elements[ currentElement ].properties, little_endian );
+				loc += result[ 1 ];
+				var element = result[ 0 ];
 
-				this.handleElement( geometry, header.elements[currentElement].name, element );
+				this.handleElement( geometry, header.elements[ currentElement ].name, element );
 
 			}
 
@@ -467,4 +481,4 @@ THREE.PLYLoader.prototype = {
 
 	}
 
-};
+};

+ 54 - 39
examples/js/loaders/PVRLoader.js

@@ -13,6 +13,7 @@ THREE.PVRLoader = function ( manager ) {
 	this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
 
 	this._parser = THREE.PVRLoader.parse;
+
 };
 
 THREE.PVRLoader.prototype = Object.create( THREE.CompressedTextureLoader.prototype );
@@ -20,6 +21,7 @@ THREE.PVRLoader.prototype.constructor = THREE.PVRLoader;
 
 
 THREE.PVRLoader.parse = function ( buffer, loadMipmaps ) {
+
 	var headerLengthInt = 13;
 	var header = new Uint32Array( buffer, 0, headerLengthInt );
 
@@ -30,15 +32,20 @@ THREE.PVRLoader.parse = function ( buffer, loadMipmaps ) {
 	};
 
 	// PVR v3
-	if ( header[0] === 0x03525650 ) {
+	if ( header[ 0 ] === 0x03525650 ) {
+
 		return THREE.PVRLoader._parseV3( pvrDatas );
+
 	} 
 	// PVR v2
-	else if ( header[11] === 0x21525650) {
+	else if ( header[ 11 ] === 0x21525650 ) {
+
 		return THREE.PVRLoader._parseV2( pvrDatas );
 
 	} else {
+
 		throw new Error( "[THREE.PVRLoader] Unknown PVR format" );
+
 	}
 
 };
@@ -49,13 +56,13 @@ THREE.PVRLoader._parseV3 = function ( pvrDatas ) {
 	var bpp, format;
 	
 
-	var metaLen 	  = header[12],
-		pixelFormat   =  header[2],
-		height        =  header[6],
-		width         =  header[7],
-		numSurfs      =  header[9],
-		numFaces      =  header[10],
-		numMipmaps    =  header[11];
+	var metaLen 	  = header[ 12 ],
+		pixelFormat   =  header[ 2 ],
+		height        =  header[ 6 ],
+		width         =  header[ 7 ],
+		numSurfs      =  header[ 9 ],
+		numFaces      =  header[ 10 ],
+		numMipmaps    =  header[ 11 ];
 
 	switch ( pixelFormat ) {
 		case 0 : // PVRTC 2bpp RGB
@@ -75,7 +82,7 @@ THREE.PVRLoader._parseV3 = function ( pvrDatas ) {
 			format = THREE.RGBA_PVRTC_4BPPV1_Format;
 			break;
 		default :
-			throw new Error( "pvrtc - unsupported PVR format " + pixelFormat);
+			throw new Error( "pvrtc - unsupported PVR format " + pixelFormat );
 	}
 
 	pvrDatas.dataPtr 	 = 52 + metaLen;
@@ -86,28 +93,29 @@ THREE.PVRLoader._parseV3 = function ( pvrDatas ) {
 	pvrDatas.numSurfaces = numFaces;
 	pvrDatas.numMipmaps  = numMipmaps;
 
-	pvrDatas.isCubemap 	= (numFaces === 6);
+	pvrDatas.isCubemap 	= ( numFaces === 6 );
 
 	return THREE.PVRLoader._extract( pvrDatas );
+
 };
 
 THREE.PVRLoader._parseV2 = function ( pvrDatas ) {
 
 	var header = pvrDatas.header;
 
-	var headerLength  =  header[0],
-		height        =  header[1],
-		width         =  header[2],
-		numMipmaps    =  header[3],
-		flags         =  header[4],
-		dataLength    =  header[5],
-		bpp           =  header[6],
-		bitmaskRed    =  header[7],
-		bitmaskGreen  =  header[8],
-		bitmaskBlue   =  header[9],
-		bitmaskAlpha  =  header[10],
-		pvrTag        =  header[11],
-		numSurfs      =  header[12];
+	var headerLength  =  header[ 0 ],
+		height        =  header[ 1 ],
+		width         =  header[ 2 ],
+		numMipmaps    =  header[ 3 ],
+		flags         =  header[ 4 ],
+		dataLength    =  header[ 5 ],
+		bpp           =  header[ 6 ],
+		bitmaskRed    =  header[ 7 ],
+		bitmaskGreen  =  header[ 8 ],
+		bitmaskBlue   =  header[ 9 ],
+		bitmaskAlpha  =  header[ 10 ],
+		pvrTag        =  header[ 11 ],
+		numSurfs      =  header[ 12 ];
 
 
 	var TYPE_MASK = 0xff;
@@ -121,16 +129,18 @@ THREE.PVRLoader._parseV2 = function ( pvrDatas ) {
 	var bpp, format;
 	var _hasAlpha = bitmaskAlpha > 0;
 
-	if (formatFlags === PVRTC_4 ) {
+	if ( formatFlags === PVRTC_4 ) {
+
 		format = _hasAlpha ? THREE.RGBA_PVRTC_4BPPV1_Format : THREE.RGB_PVRTC_4BPPV1_Format;
 		bpp = 4;
-	}
-	else if ( formatFlags === PVRTC_2) {
+
+	} else if ( formatFlags === PVRTC_2 ) {
+
 		format = _hasAlpha ? THREE.RGBA_PVRTC_2BPPV1_Format : THREE.RGB_PVRTC_2BPPV1_Format;
 		bpp = 2;
-	}
-	else
-		throw new Error( "pvrtc - unknown format " + formatFlags);
+
+	} else
+		throw new Error( "pvrtc - unknown format " + formatFlags );
 	
 
 
@@ -142,9 +152,9 @@ THREE.PVRLoader._parseV2 = function ( pvrDatas ) {
 	pvrDatas.numSurfaces = numSurfs;
 	pvrDatas.numMipmaps  = numMipmaps + 1;
 
-  	// guess cubemap type seems tricky in v2
-  	// it juste a pvr containing 6 surface (no explicit cubemap type)
-	pvrDatas.isCubemap 	= (numSurfs === 6);
+	// guess cubemap type seems tricky in v2
+	// it juste a pvr containing 6 surface (no explicit cubemap type)
+	pvrDatas.isCubemap 	= ( numSurfs === 6 );
 
 	return THREE.PVRLoader._extract( pvrDatas );
 
@@ -198,20 +208,24 @@ THREE.PVRLoader._extract = function ( pvrDatas ) {
 
 
 	if ( bpp === 2 ) {
+
 		blockWidth = 8;
 		blockHeight = 4;
+
 	} else {
+
 		blockWidth = 4;
 		blockHeight = 4;
+
 	}
 
-	blockSize = (blockWidth * blockHeight) * bpp / 8;
+	blockSize = ( blockWidth * blockHeight ) * bpp / 8;
 
 	pvr.mipmaps.length = pvrDatas.numMipmaps * numSurfs;
 
 	var mipLevel = 0;
 
-	while (mipLevel < pvrDatas.numMipmaps) {
+	while ( mipLevel < pvrDatas.numMipmaps ) {
 
 		var sWidth = pvrDatas.width >> mipLevel,
 		sHeight = pvrDatas.height >> mipLevel;
@@ -220,9 +234,9 @@ THREE.PVRLoader._extract = function ( pvrDatas ) {
 		heightBlocks = sHeight / blockHeight;
 
 		// Clamp to minimum number of blocks
-		if (widthBlocks < 2)
+		if ( widthBlocks < 2 )
 			widthBlocks = 2;
-		if (heightBlocks < 2)
+		if ( heightBlocks < 2 )
 			heightBlocks = 2;
 
 		dataSize = widthBlocks * heightBlocks * blockSize;
@@ -238,7 +252,7 @@ THREE.PVRLoader._extract = function ( pvrDatas ) {
 				height: sHeight 
 			};
 
-			pvr.mipmaps[ surfIndex * pvrDatas.numMipmaps + mipLevel] = mipmap;
+			pvr.mipmaps[ surfIndex * pvrDatas.numMipmaps + mipLevel ] = mipmap;
 
 			dataOffset += dataSize;
 
@@ -251,4 +265,5 @@ THREE.PVRLoader._extract = function ( pvrDatas ) {
 
 
 	return pvr;
-};
+
+};

+ 111 - 65
examples/js/loaders/RGBELoader.js

@@ -20,25 +20,27 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 	var
 		/* return codes for rgbe routines */
 		RGBE_RETURN_SUCCESS =  0,
-		RGBE_RETURN_FAILURE = -1,
+		RGBE_RETURN_FAILURE = - 1,
 
 		/* default error routine.  change this to change error handling */
 		rgbe_read_error     = 1,
 		rgbe_write_error    = 2,
 		rgbe_format_error   = 3,
 		rgbe_memory_error   = 4,
-		rgbe_error = function(rgbe_error_code, msg) {
-			switch (rgbe_error_code) {
-				case rgbe_read_error: console.error("THREE.RGBELoader Read Error: " + (msg||''));
+		rgbe_error = function( rgbe_error_code, msg ) {
+
+			switch ( rgbe_error_code ) {
+				case rgbe_read_error: console.error( "THREE.RGBELoader Read Error: " + ( msg || '' ) );
 					break;
-				case rgbe_write_error: console.error("THREE.RGBELoader Write Error: " + (msg||''));
+				case rgbe_write_error: console.error( "THREE.RGBELoader Write Error: " + ( msg || '' ) );
 					break;
-				case rgbe_format_error:  console.error("THREE.RGBELoader Bad File Format: " + (msg||''));
+				case rgbe_format_error:  console.error( "THREE.RGBELoader Bad File Format: " + ( msg || '' ) );
 					break;
 				default:
-				case rgbe_memory_error:  console.error("THREE.RGBELoader: Error: " + (msg||''));
+				case rgbe_memory_error:  console.error( "THREE.RGBELoader: Error: " + ( msg || '' ) );
 			}
 			return RGBE_RETURN_FAILURE;
+
 		},
 
 		/* offsets to red, green, and blue components in a data (float) pixel */
@@ -57,20 +59,21 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 		NEWLINE = "\n",
 
 		fgets = function( buffer, lineLimit, consume ) {
-			lineLimit = !lineLimit ? 1024 : lineLimit;
+
+			lineLimit = ! lineLimit ? 1024 : lineLimit;
 			var p = buffer.pos,
-				i = -1, len = 0, s = '', chunkSize = 128,
-				chunk = String.fromCharCode.apply(null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) )
+				i = - 1, len = 0, s = '', chunkSize = 128,
+				chunk = String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) )
 			;
-			while ( (0 > (i = chunk.indexOf( NEWLINE ))) && (len < lineLimit) && (p < buffer.byteLength) ) {
+			while ( ( 0 > ( i = chunk.indexOf( NEWLINE ) ) ) && ( len < lineLimit ) && ( p < buffer.byteLength ) ) {
 
 				s += chunk; len += chunk.length;
 				p += chunkSize;
-				chunk += String.fromCharCode.apply(null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) );
+				chunk += String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) );
 
 			}
 
-			if ( -1 < i ) {
+			if ( - 1 < i ) {
 
 				/*for (i=l-1; i>=0; i--) {
 					byteCode = m.charCodeAt(i);
@@ -79,14 +82,16 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 					if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate
 				}*/
 				if ( false !== consume ) buffer.pos += len + i + 1;
-				return s + chunk.slice(0, i);
+				return s + chunk.slice( 0, i );
 
 			}
 			return false;
+
 		},
 
 		/* minimal header reading.  modify if you want to parse more information */
 		RGBE_ReadHeader = function( buffer ) {
+
 			var line, match,
 
 				// regexes to parse header info fields
@@ -99,38 +104,42 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 				// RGBE format header struct
 				header = {
 
-				  valid: 0,                         /* indicate which fields are valid */
+					valid: 0,                         /* indicate which fields are valid */
 
-				  string: '',                       /* the actual header string */
+					string: '',                       /* the actual header string */
 
-				  comments: '',                     /* comments found in header */
+					comments: '',                     /* comments found in header */
 
-				  programtype: 'RGBE',              /* listed at beginning of file to identify it
+					programtype: 'RGBE',              /* listed at beginning of file to identify it
 													* after "#?".  defaults to "RGBE" */
+														
+					format: '',                       /* RGBE format, default 32-bit_rle_rgbe */
 
-				  format: '',                       /* RGBE format, default 32-bit_rle_rgbe */
-
-				  gamma: 1.0,                       /* image has already been gamma corrected with
+					gamma: 1.0,                       /* image has already been gamma corrected with
 													* given gamma.  defaults to 1.0 (no correction) */
-
-				  exposure: 1.0,                    /* a value of 1.0 in an image corresponds to
+														
+					exposure: 1.0,                    /* a value of 1.0 in an image corresponds to
 													* <exposure> watts/steradian/m^2.
 													* defaults to 1.0 */
-
-				  width: 0, height: 0               /* image dimensions, width/height */
+														
+					width: 0, height: 0               /* image dimensions, width/height */
 
 				}
 			;
 
-			if ( buffer.pos >= buffer.byteLength || !( line = fgets( buffer ) ) ) {
+			if ( buffer.pos >= buffer.byteLength || ! ( line = fgets( buffer ) ) ) {
+
 				return rgbe_error( rgbe_read_error, "no header found" );
+
 			}
 			/* if you want to require the magic token then uncomment the next line */
-			if ( !(match = line.match(magic_token_re)) ) {
+			if ( ! ( match = line.match( magic_token_re ) ) ) {
+
 				return rgbe_error( rgbe_format_error, "bad initial token" );
+
 			}
 			header.valid |= RGBE_VALID_PROGRAMTYPE;
-			header.programtype = match[1];
+			header.programtype = match[ 1 ];
 			header.string += line + "\n";
 
 			while ( true ) {
@@ -139,41 +148,58 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 				if ( false === line ) break;
 				header.string += line + "\n";
 
-				if ( '#' === line.charAt(0) ) {
+				if ( '#' === line.charAt( 0 ) ) {
+
 					header.comments += line + "\n";
 					continue; // comment line
+
 				}
 
-				if ( match = line.match(gamma_re) ) {
-					header.gamma = parseFloat(match[1], 10);
+				if ( match = line.match( gamma_re ) ) {
+
+					header.gamma = parseFloat( match[ 1 ], 10 );
+
 				}
-				if ( match = line.match(exposure_re) ) {
-					header.exposure = parseFloat(match[1], 10);
+				if ( match = line.match( exposure_re ) ) {
+
+					header.exposure = parseFloat( match[ 1 ], 10 );
+
 				}
-				if ( match = line.match(format_re) ) {
+				if ( match = line.match( format_re ) ) {
+
 					header.valid |= RGBE_VALID_FORMAT;
-					header.format = match[1];//'32-bit_rle_rgbe';
+					header.format = match[ 1 ];//'32-bit_rle_rgbe';
+
 				}
-				if ( match = line.match(dimensions_re) ) {
+				if ( match = line.match( dimensions_re ) ) {
+
 					header.valid |= RGBE_VALID_DIMENSIONS;
-					header.height = parseInt(match[1], 10);
-					header.width = parseInt(match[2], 10);
+					header.height = parseInt( match[ 1 ], 10 );
+					header.width = parseInt( match[ 2 ], 10 );
+
 				}
 
-				if ( (header.valid&RGBE_VALID_FORMAT) && (header.valid&RGBE_VALID_DIMENSIONS) ) break;
+				if ( ( header.valid & RGBE_VALID_FORMAT ) && ( header.valid & RGBE_VALID_DIMENSIONS ) ) break;
+
 			}
 
-			if ( !(header.valid&RGBE_VALID_FORMAT) ) {
+			if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) {
+
 				return rgbe_error( rgbe_format_error, "missing format specifier" );
+
 			}
-			if ( !(header.valid&RGBE_VALID_DIMENSIONS) ) {
+			if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) {
+
 				return rgbe_error( rgbe_format_error, "missing image size specifier" );
+
 			}
 
 			return header;
+
 		},
 
 		RGBE_ReadPixels_RLE = function( buffer, w, h ) {
+
 			var data_rgba, offset, pos, count, byteValue,
 				scanline_buffer, ptr, ptr_end, i, l, off, isEncodedRun,
 				scanline_width = w, num_scanlines = h, rgbeStart
@@ -181,22 +207,28 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 
 			if (
 				// run length encoding is not allowed so read flat
-				((scanline_width < 8) || (scanline_width > 0x7fff)) ||
+				( ( scanline_width < 8 ) || ( scanline_width > 0x7fff ) ) ||
 				// this file is not run length encoded
-				((2 !== buffer[0]) || (2 !== buffer[1]) || (buffer[2] & 0x80))
+				( ( 2 !== buffer[ 0 ] ) || ( 2 !== buffer[ 1 ] ) || ( buffer[ 2 ] & 0x80 ) )
 			) {
+
 				// return the flat buffer
 				return new Uint8Array( buffer );
+
 			}
 
-			if ( scanline_width !== ((buffer[2]<<8) | buffer[3]) ) {
-				return rgbe_error(rgbe_format_error, "wrong scanline width");
+			if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) {
+
+				return rgbe_error( rgbe_format_error, "wrong scanline width" );
+
 			}
 
 			data_rgba = new Uint8Array( 4 * w * h );
 
-			if ( !data_rgba || !data_rgba.length ) {
-				return rgbe_error(rgbe_memory_error, "unable to allocate buffer space");
+			if ( ! data_rgba || ! data_rgba.length ) {
+
+				return rgbe_error( rgbe_memory_error, "unable to allocate buffer space" );
+
 			}
 
 			offset = 0; pos = 0; ptr_end = 4 * scanline_width;
@@ -204,7 +236,7 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 			scanline_buffer = new Uint8Array( ptr_end );
 
 			// read in each successive scanline
-			while ( (num_scanlines > 0) && (pos < buffer.byteLength) ) {
+			while ( ( num_scanlines > 0 ) && ( pos < buffer.byteLength ) ) {
 
 				if ( pos + 4 > buffer.byteLength ) {
 
@@ -212,67 +244,77 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 
 				}
 
-				rgbeStart[0] = buffer[pos ++];
-				rgbeStart[1] = buffer[pos ++];
-				rgbeStart[2] = buffer[pos ++];
-				rgbeStart[3] = buffer[pos ++];
+				rgbeStart[ 0 ] = buffer[ pos ++ ];
+				rgbeStart[ 1 ] = buffer[ pos ++ ];
+				rgbeStart[ 2 ] = buffer[ pos ++ ];
+				rgbeStart[ 3 ] = buffer[ pos ++ ];
 
-				if ( (2 != rgbeStart[0]) || (2 != rgbeStart[1]) || (((rgbeStart[2]<<8) | rgbeStart[3]) != scanline_width) ) {
+				if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) {
 
-					return rgbe_error(rgbe_format_error, "bad rgbe scanline format");
+					return rgbe_error( rgbe_format_error, "bad rgbe scanline format" );
 
 				}
 
 				// read each of the four channels for the scanline into the buffer
 				// first red, then green, then blue, then exponent
 				ptr = 0;
-				while ( (ptr < ptr_end) && (pos < buffer.byteLength) ) {
+				while ( ( ptr < ptr_end ) && ( pos < buffer.byteLength ) ) {
 
 					count = buffer[ pos ++ ];
 					isEncodedRun = count > 128;
 					if ( isEncodedRun ) count -= 128;
 
-					if ( (0 === count) || (ptr + count > ptr_end) ) {
+					if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) {
 
-						return rgbe_error(rgbe_format_error, "bad scanline data");
+						return rgbe_error( rgbe_format_error, "bad scanline data" );
 
 					}
 
 					if ( isEncodedRun ) {
+
 						// a (encoded) run of the same value
 						byteValue = buffer[ pos ++ ];
-						for (i = 0; i < count; i ++) {
+						for ( i = 0; i < count; i ++ ) {
+
 							scanline_buffer[ ptr ++ ] = byteValue;
+
 						}
 						//ptr += count;
 
 					} else {
+
 						// a literal-run
-						scanline_buffer.set( buffer.subarray(pos, pos + count), ptr );
+						scanline_buffer.set( buffer.subarray( pos, pos + count ), ptr );
 						ptr += count; pos += count;
+
 					}
+
 				}
 
 
 				// now convert data from buffer into rgba
 				// first red, then green, then blue, then exponent (alpha)
 				l = scanline_width; //scanline_buffer.byteLength;
-				for (i = 0; i < l; i ++) {
+				for ( i = 0; i < l; i ++ ) {
+
 					off = 0;
-					data_rgba[offset] = scanline_buffer[i + off];
+					data_rgba[ offset ] = scanline_buffer[ i + off ];
 					off += scanline_width; //1;
-					data_rgba[offset + 1] = scanline_buffer[i + off];
+					data_rgba[ offset + 1 ] = scanline_buffer[ i + off ];
 					off += scanline_width; //1;
-					data_rgba[offset + 2] = scanline_buffer[i + off];
+					data_rgba[ offset + 2 ] = scanline_buffer[ i + off ];
 					off += scanline_width; //1;
-					data_rgba[offset + 3] = scanline_buffer[i + off];
+					data_rgba[ offset + 3 ] = scanline_buffer[ i + off ];
 					offset += 4;
+
 				}
 
 				num_scanlines --;
+
 			}
 
 			return data_rgba;
+
 		}
 	;
 
@@ -285,9 +327,10 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 
 		var w = rgbe_header_info.width,
 			h = rgbe_header_info.height
-			,image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray(byteArray.pos), w, h )
+			, image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h )
 		;
 		if ( RGBE_RETURN_FAILURE !== image_rgba_data ) {
+
 			return {
 				width: w, height: h,
 				data: image_rgba_data,
@@ -297,7 +340,10 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
 				format: THREE.RGBEFormat, // handled as THREE.RGBAFormat in shaders
 				type: THREE.UnsignedByteType
 			};
+
 		}
+
 	}
 	return null;
+
 };

+ 147 - 88
examples/js/loaders/STLLoader.js

@@ -64,9 +64,9 @@ THREE.STLLoader.prototype = {
 
 			var expect, face_size, n_faces, reader;
 			reader = new DataView( binData );
-			face_size = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
-			n_faces = reader.getUint32(80, true);
-			expect = 80 + (32 / 8) + (n_faces * face_size);
+			face_size = ( 32 / 8 * 3 ) + ( ( 32 / 8 * 3 ) * 3 ) + ( 16 / 8 );
+			n_faces = reader.getUint32( 80, true );
+			expect = 80 + ( 32 / 8 ) + ( n_faces * face_size );
 
 			if ( expect === reader.byteLength ) {
 
@@ -79,7 +79,7 @@ THREE.STLLoader.prototype = {
 			var fileLength = reader.byteLength;
 			for ( var index = 0; index < fileLength; index ++ ) {
 
-				if ( reader.getUint8(index, false) > 127 ) {
+				if ( reader.getUint8( index, false ) > 127 ) {
 
 					return true;
 
@@ -112,18 +112,20 @@ THREE.STLLoader.prototype = {
 
 		for ( var index = 0; index < 80 - 10; index ++ ) {
 
-			if ((reader.getUint32(index, false) == 0x434F4C4F /*COLO*/) &&
-				(reader.getUint8(index + 4) == 0x52 /*'R'*/) &&
-				(reader.getUint8(index + 5) == 0x3D /*'='*/)) {
+			if ( ( reader.getUint32( index, false ) == 0x434F4C4F /*COLO*/ ) &&
+				( reader.getUint8( index + 4 ) == 0x52 /*'R'*/ ) &&
+				( reader.getUint8( index + 5 ) == 0x3D /*'='*/ ) ) {
 
 				hasColors = true;
-				colors = new Float32Array( faces * 3 * 3);
+				colors = new Float32Array( faces * 3 * 3 );
+
+				defaultR = reader.getUint8( index + 6 ) / 255;
+				defaultG = reader.getUint8( index + 7 ) / 255;
+				defaultB = reader.getUint8( index + 8 ) / 255;
+				alpha = reader.getUint8( index + 9 ) / 255;
 
-				defaultR = reader.getUint8(index + 6) / 255;
-				defaultG = reader.getUint8(index + 7) / 255;
-				defaultB = reader.getUint8(index + 8) / 255;
-				alpha = reader.getUint8(index + 9) / 255;
 			}
+
 		}
 
 		var dataOffset = 84;
@@ -139,43 +141,50 @@ THREE.STLLoader.prototype = {
 		for ( var face = 0; face < faces; face ++ ) {
 
 			var start = dataOffset + face * faceLength;
-			var normalX = reader.getFloat32(start, true);
-			var normalY = reader.getFloat32(start + 4, true);
-			var normalZ = reader.getFloat32(start + 8, true);
+			var normalX = reader.getFloat32( start, true );
+			var normalY = reader.getFloat32( start + 4, true );
+			var normalZ = reader.getFloat32( start + 8, true );
+
+			if ( hasColors ) {
+
+				var packedColor = reader.getUint16( start + 48, true );
 
-			if (hasColors) {
+				if ( ( packedColor & 0x8000 ) === 0 ) {
 
-				var packedColor = reader.getUint16(start + 48, true);
+					// facet has its own unique color
 
-				if ((packedColor & 0x8000) === 0) { // facet has its own unique color
+					r = ( packedColor & 0x1F ) / 31;
+					g = ( ( packedColor >> 5 ) & 0x1F ) / 31;
+					b = ( ( packedColor >> 10 ) & 0x1F ) / 31;
 
-					r = (packedColor & 0x1F) / 31;
-					g = ((packedColor >> 5) & 0x1F) / 31;
-					b = ((packedColor >> 10) & 0x1F) / 31;
 				} else {
 
 					r = defaultR;
 					g = defaultG;
 					b = defaultB;
+
 				}
+
 			}
 
 			for ( var i = 1; i <= 3; i ++ ) {
 
 				var vertexstart = start + i * 12;
 
-				vertices[ offset     ] = reader.getFloat32( vertexstart, true );
+				vertices[ offset ] = reader.getFloat32( vertexstart, true );
 				vertices[ offset + 1 ] = reader.getFloat32( vertexstart + 4, true );
 				vertices[ offset + 2 ] = reader.getFloat32( vertexstart + 8, true );
 
-				normals[ offset     ] = normalX;
+				normals[ offset ] = normalX;
 				normals[ offset + 1 ] = normalY;
 				normals[ offset + 2 ] = normalZ;
 
-				if (hasColors) {
-					colors[ offset     ] = r;
+				if ( hasColors ) {
+
+					colors[ offset ] = r;
 					colors[ offset + 1 ] = g;
 					colors[ offset + 2 ] = b;
+
 				}
 
 				offset += 3;
@@ -187,10 +196,12 @@ THREE.STLLoader.prototype = {
 		geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
 		geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
 
-		if (hasColors) {
+		if ( hasColors ) {
+
 			geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
 			geometry.hasColors = true;
 			geometry.alpha = alpha;
+
 		}
 
 		return geometry;
@@ -205,7 +216,7 @@ THREE.STLLoader.prototype = {
 
 		while ( ( result = patternFace.exec( data ) ) !== null ) {
 
-			text = result[0];
+			text = result[ 0 ];
 			patternNormal = /normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
 
 			while ( ( result = patternNormal.exec( text ) ) !== null ) {
@@ -237,38 +248,50 @@ THREE.STLLoader.prototype = {
 
 	ensureString: function ( buf ) {
 
-		if (typeof buf !== "string") {
-			var array_buffer = new Uint8Array(buf);
+		if ( typeof buf !== "string" ) {
+
+			var array_buffer = new Uint8Array( buf );
 			var str = '';
-			for (var i = 0; i < buf.byteLength; i ++) {
-				str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
+			for ( var i = 0; i < buf.byteLength; i ++ ) {
+
+				str += String.fromCharCode( array_buffer[ i ] ); // implicitly assumes little-endian
+
 			}
 			return str;
+
 		} else {
+
 			return buf;
+
 		}
 
 	},
 
 	ensureBinary: function ( buf ) {
 
-		if (typeof buf === "string") {
-			var array_buffer = new Uint8Array(buf.length);
-			for (var i = 0; i < buf.length; i ++) {
-				array_buffer[i] = buf.charCodeAt(i) & 0xff; // implicitly assumes little-endian
+		if ( typeof buf === "string" ) {
+
+			var array_buffer = new Uint8Array( buf.length );
+			for ( var i = 0; i < buf.length; i ++ ) {
+
+				array_buffer[ i ] = buf.charCodeAt( i ) & 0xff; // implicitly assumes little-endian
+
 			}
 			return array_buffer.buffer || array_buffer;
+
 		} else {
+
 			return buf;
+
 		}
 
 	}
 
 };
 
-if ( typeof DataView === 'undefined') {
+if ( typeof DataView === 'undefined' ) {
 
-	DataView = function(buffer, byteOffset, byteLength) {
+	DataView = function( buffer, byteOffset, byteLength ) {
 
 		this.buffer = buffer;
 		this.byteOffset = byteOffset || 0;
@@ -279,30 +302,34 @@ if ( typeof DataView === 'undefined') {
 
 	DataView.prototype = {
 
-		_getCharCodes:function(buffer,start,length) {
+		_getCharCodes: function( buffer, start, length ) {
+
 			start = start || 0;
 			length = length || buffer.length;
 			var end = start + length;
 			var codes = [];
-			for (var i = start; i < end; i ++) {
-				codes.push(buffer.charCodeAt(i) & 0xff);
+			for ( var i = start; i < end; i ++ ) {
+
+				codes.push( buffer.charCodeAt( i ) & 0xff );
+
 			}
 			return codes;
+
 		},
 
-		_getBytes: function (length, byteOffset, littleEndian) {
+		_getBytes: function ( length, byteOffset, littleEndian ) {
 
 			var result;
 
 			// Handle the lack of endianness
-			if (littleEndian === undefined) {
+			if ( littleEndian === undefined ) {
 
 				littleEndian = this._littleEndian;
 
 			}
 
 			// Handle the lack of byteOffset
-			if (byteOffset === undefined) {
+			if ( byteOffset === undefined ) {
 
 				byteOffset = this.byteOffset;
 
@@ -312,44 +339,45 @@ if ( typeof DataView === 'undefined') {
 
 			}
 
-			if (length === undefined) {
+			if ( length === undefined ) {
 
 				length = this.byteLength - byteOffset;
 
 			}
 
 			// Error Checking
-			if (typeof byteOffset !== 'number') {
+			if ( typeof byteOffset !== 'number' ) {
 
-				throw new TypeError('DataView byteOffset is not a number');
+				throw new TypeError( 'DataView byteOffset is not a number' );
 
 			}
 
-			if (length < 0 || byteOffset + length > this.byteLength) {
+			if ( length < 0 || byteOffset + length > this.byteLength ) {
 
-				throw new Error('DataView length or (byteOffset+length) value is out of bounds');
+				throw new Error( 'DataView length or (byteOffset+length) value is out of bounds' );
 
 			}
 
-			if (this.isString) {
+			if ( this.isString ) {
 
-				result = this._getCharCodes(this.buffer, byteOffset, byteOffset + length);
+				result = this._getCharCodes( this.buffer, byteOffset, byteOffset + length );
 
 			} else {
 
-				result = this.buffer.slice(byteOffset, byteOffset + length);
+				result = this.buffer.slice( byteOffset, byteOffset + length );
 
 			}
 
-			if (!littleEndian && length > 1) {
+			if ( ! littleEndian && length > 1 ) {
 
 				if ( Array.isArray( result ) === false ) {
 
-					result = Array.prototype.slice.call(result);
+					result = Array.prototype.slice.call( result );
 
 				}
 
 				result.reverse();
+
 			}
 
 			return result;
@@ -358,80 +386,111 @@ if ( typeof DataView === 'undefined') {
 
 		// Compatibility functions on a String Buffer
 
-		getFloat64: function (byteOffset, littleEndian) {
+		getFloat64: function ( byteOffset, littleEndian ) {
 
-			var b = this._getBytes(8, byteOffset, littleEndian),
+			var b = this._getBytes( 8, byteOffset, littleEndian ),
 
-				sign = 1 - (2 * (b[7] >> 7)),
-				exponent = ((((b[7] << 1) & 0xff) << 3) | (b[6] >> 4)) - ((1 << 10) - 1),
+				sign = 1 - ( 2 * ( b[ 7 ] >> 7 ) ),
+				exponent = ( ( ( ( b[ 7 ] << 1 ) & 0xff ) << 3 ) | ( b[ 6 ] >> 4 ) ) - ( ( 1 << 10 ) - 1 ),
 
 			// Binary operators such as | and << operate on 32 bit values, using + and Math.pow(2) instead
-				mantissa = ((b[6] & 0x0f) * Math.pow(2, 48)) + (b[5] * Math.pow(2, 40)) + (b[4] * Math.pow(2, 32)) +
-							(b[3] * Math.pow(2, 24)) + (b[2] * Math.pow(2, 16)) + (b[1] * Math.pow(2, 8)) + b[0];
+				mantissa = ( ( b[ 6 ] & 0x0f ) * Math.pow( 2, 48 ) ) + ( b[ 5 ] * Math.pow( 2, 40 ) ) + ( b[ 4 ] * Math.pow( 2, 32 ) ) +
+							( b[ 3 ] * Math.pow( 2, 24 ) ) + ( b[ 2 ] * Math.pow( 2, 16 ) ) + ( b[ 1 ] * Math.pow( 2, 8 ) ) + b[ 0 ];
+
+			if ( exponent === 1024 ) {
+
+				if ( mantissa !== 0 ) {
 
-			if (exponent === 1024) {
-				if (mantissa !== 0) {
 					return NaN;
+
 				} else {
+
 					return sign * Infinity;
+
 				}
+
 			}
 
-			if (exponent === -1023) { // Denormalized
-				return sign * mantissa * Math.pow(2, -1022 - 52);
+			if ( exponent === - 1023 ) {
+
+				// Denormalized
+				return sign * mantissa * Math.pow( 2, - 1022 - 52 );
+
 			}
 
-			return sign * (1 + mantissa * Math.pow(2, -52)) * Math.pow(2, exponent);
+			return sign * ( 1 + mantissa * Math.pow( 2, - 52 ) ) * Math.pow( 2, exponent );
 
 		},
 
-		getFloat32: function (byteOffset, littleEndian) {
+		getFloat32: function ( byteOffset, littleEndian ) {
 
-			var b = this._getBytes(4, byteOffset, littleEndian),
+			var b = this._getBytes( 4, byteOffset, littleEndian ),
 
-				sign = 1 - (2 * (b[3] >> 7)),
-				exponent = (((b[3] << 1) & 0xff) | (b[2] >> 7)) - 127,
-				mantissa = ((b[2] & 0x7f) << 16) | (b[1] << 8) | b[0];
+				sign = 1 - ( 2 * ( b[ 3 ] >> 7 ) ),
+				exponent = ( ( ( b[ 3 ] << 1 ) & 0xff ) | ( b[ 2 ] >> 7 ) ) - 127,
+				mantissa = ( ( b[ 2 ] & 0x7f ) << 16 ) | ( b[ 1 ] << 8 ) | b[ 0 ];
+
+			if ( exponent === 128 ) {
+
+				if ( mantissa !== 0 ) {
 
-			if (exponent === 128) {
-				if (mantissa !== 0) {
 					return NaN;
+
 				} else {
+
 					return sign * Infinity;
+
 				}
+
 			}
 
-			if (exponent === -127) { // Denormalized
-				return sign * mantissa * Math.pow(2, -126 - 23);
+			if ( exponent === - 127 ) {
+
+				// Denormalized
+				return sign * mantissa * Math.pow( 2, - 126 - 23 );
+
 			}
 
-			return sign * (1 + mantissa * Math.pow(2, -23)) * Math.pow(2, exponent);
+			return sign * ( 1 + mantissa * Math.pow( 2, - 23 ) ) * Math.pow( 2, exponent );
+
 		},
 
-		getInt32: function (byteOffset, littleEndian) {
-			var b = this._getBytes(4, byteOffset, littleEndian);
-			return (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0];
+		getInt32: function ( byteOffset, littleEndian ) {
+
+			var b = this._getBytes( 4, byteOffset, littleEndian );
+			return ( b[ 3 ] << 24 ) | ( b[ 2 ] << 16 ) | ( b[ 1 ] << 8 ) | b[ 0 ];
+
 		},
 
-		getUint32: function (byteOffset, littleEndian) {
-			return this.getInt32(byteOffset, littleEndian) >>> 0;
+		getUint32: function ( byteOffset, littleEndian ) {
+
+			return this.getInt32( byteOffset, littleEndian ) >>> 0;
+
 		},
 
-		getInt16: function (byteOffset, littleEndian) {
-			return (this.getUint16(byteOffset, littleEndian) << 16) >> 16;
+		getInt16: function ( byteOffset, littleEndian ) {
+
+			return ( this.getUint16( byteOffset, littleEndian ) << 16 ) >> 16;
+
 		},
 
-		getUint16: function (byteOffset, littleEndian) {
-			var b = this._getBytes(2, byteOffset, littleEndian);
-			return (b[1] << 8) | b[0];
+		getUint16: function ( byteOffset, littleEndian ) {
+
+			var b = this._getBytes( 2, byteOffset, littleEndian );
+			return ( b[ 1 ] << 8 ) | b[ 0 ];
+
 		},
 
-		getInt8: function (byteOffset) {
-			return (this.getUint8(byteOffset) << 24) >> 24;
+		getInt8: function ( byteOffset ) {
+
+			return ( this.getUint8( byteOffset ) << 24 ) >> 24;
+
 		},
 
-		getUint8: function (byteOffset) {
-			return this._getBytes(1, byteOffset)[0];
+		getUint8: function ( byteOffset ) {
+
+			return this._getBytes( 1, byteOffset )[ 0 ];
+
 		}
 
 	 };

+ 129 - 77
examples/js/loaders/TGALoader.js

@@ -62,8 +62,10 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
 			// Check indexed type
 			case TGA_TYPE_INDEXED:
 			case TGA_TYPE_RLE_INDEXED:
-				if ( header.colormap_length > 256 || header.colormap_size !== 24 || header.colormap_type !== 1) {
-					console.error('THREE.TGALoader.parse.tgaCheckHeader: Invalid type colormap data for indexed type');
+				if ( header.colormap_length > 256 || header.colormap_size !== 24 || header.colormap_type !== 1 ) {
+
+					console.error( 'THREE.TGALoader.parse.tgaCheckHeader: Invalid type colormap data for indexed type' );
+
 				}
 				break;
 
@@ -72,32 +74,38 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
 			case TGA_TYPE_GREY:
 			case TGA_TYPE_RLE_RGB:
 			case TGA_TYPE_RLE_GREY:
-				if (header.colormap_type) {
-					console.error('THREE.TGALoader.parse.tgaCheckHeader: Invalid type colormap data for colormap type');
+				if ( header.colormap_type ) {
+
+					console.error( 'THREE.TGALoader.parse.tgaCheckHeader: Invalid type colormap data for colormap type' );
+
 				}
 				break;
 
 			// What the need of a file without data ?
 			case TGA_TYPE_NO_DATA:
-				console.error('THREE.TGALoader.parse.tgaCheckHeader: No data');
+				console.error( 'THREE.TGALoader.parse.tgaCheckHeader: No data' );
 
 			// Invalid type ?
 			default:
-				console.error('THREE.TGALoader.parse.tgaCheckHeader: Invalid type " ' + header.image_type + '"');
+				console.error( 'THREE.TGALoader.parse.tgaCheckHeader: Invalid type " ' + header.image_type + '"' );
 
 		}
 
 		// Check image width and height
 		if ( header.width <= 0 || header.height <= 0 ) {
+
 			console.error( 'THREE.TGALoader.parse.tgaCheckHeader: Invalid image size' );
+
 		}
 
 		// Check image pixel size
-		if (header.pixel_size !== 8  &&
+		if ( header.pixel_size !== 8  &&
 			header.pixel_size !== 16 &&
 			header.pixel_size !== 24 &&
-			header.pixel_size !== 32) {
-			console.error('THREE.TGALoader.parse.tgaCheckHeader: Invalid pixel size "' + header.pixel_size + '"');
+			header.pixel_size !== 32 ) {
+
+			console.error( 'THREE.TGALoader.parse.tgaCheckHeader: Invalid pixel size "' + header.pixel_size + '"' );
+
 		}
 
 	}
@@ -106,7 +114,9 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
 	tgaCheckHeader( header );
 
 	if ( header.id_length + offset > buffer.length ) {
-		console.error('THREE.TGALoader.parse: No data');
+
+		console.error( 'THREE.TGALoader.parse: No data' );
+
 	}
 
 	// Skip the needn't data
@@ -159,126 +169,160 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
 
 		 // Read palettes
 		 if ( use_pal ) {
+
 			 palettes = data.subarray( offset, offset += header.colormap_length * ( header.colormap_size >> 3 ) );
+
 		 }
 
 		 // Read RLE
 		 if ( use_rle ) {
-			 pixel_data = new Uint8Array(pixel_total);
+
+			 pixel_data = new Uint8Array( pixel_total );
 
 			var c, count, i;
 			var shift = 0;
-			var pixels = new Uint8Array(pixel_size);
+			var pixels = new Uint8Array( pixel_size );
 
-			while (shift < pixel_total) {
-				c     = data[offset ++];
-				count = (c & 0x7f) + 1;
+			while ( shift < pixel_total ) {
+
+				c     = data[ offset ++ ];
+				count = ( c & 0x7f ) + 1;
 
 				// RLE pixels.
-				if (c & 0x80) {
+				if ( c & 0x80 ) {
+
 					// Bind pixel tmp array
-					for (i = 0; i < pixel_size; ++ i) {
-						pixels[i] = data[offset ++];
+					for ( i = 0; i < pixel_size; ++ i ) {
+
+						pixels[ i ] = data[ offset ++ ];
+
 					}
 
 					// Copy pixel array
-					for (i = 0; i < count; ++ i) {
-						pixel_data.set(pixels, shift + i * pixel_size);
+					for ( i = 0; i < count; ++ i ) {
+
+						pixel_data.set( pixels, shift + i * pixel_size );
+
 					}
 
 					shift += pixel_size * count;
 
 				} else {
+
 					// Raw pixels.
 					count *= pixel_size;
-					for (i = 0; i < count; ++ i) {
-						pixel_data[shift + i] = data[offset ++];
+					for ( i = 0; i < count; ++ i ) {
+
+						pixel_data[ shift + i ] = data[ offset ++ ];
+
 					}
 					shift += count;
+
 				}
+
 			}
+
 		 } else {
+
 			// RAW Pixels
 			pixel_data = data.subarray(
-				 offset, offset += (use_pal ? header.width * header.height : pixel_total)
+				 offset, offset += ( use_pal ? header.width * header.height : pixel_total )
 			);
+
 		 }
 
 		 return {
 			pixel_data: pixel_data,
 			palettes: palettes
 		 };
+
 	}
 
-	function tgaGetImageData8bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image, palettes) {
+	function tgaGetImageData8bits( imageData, y_start, y_step, y_end, x_start, x_step, x_end, image, palettes ) {
 
 		var colormap = palettes;
 		var color, i = 0, x, y;
 		var width = header.width;
 
-		for (y = y_start; y !== y_end; y += y_step) {
-			for (x = x_start; x !== x_end; x += x_step, i ++) {
-				color = image[i];
-				imageData[(x + width * y) * 4 + 3] = 255;
-				imageData[(x + width * y) * 4 + 2] = colormap[(color * 3) + 0];
-				imageData[(x + width * y) * 4 + 1] = colormap[(color * 3) + 1];
-				imageData[(x + width * y) * 4 + 0] = colormap[(color * 3) + 2];
+		for ( y = y_start; y !== y_end; y += y_step ) {
+
+			for ( x = x_start; x !== x_end; x += x_step, i ++ ) {
+
+				color = image[ i ];
+				imageData[ ( x + width * y ) * 4 + 3 ] = 255;
+				imageData[ ( x + width * y ) * 4 + 2 ] = colormap[ ( color * 3 ) + 0 ];
+				imageData[ ( x + width * y ) * 4 + 1 ] = colormap[ ( color * 3 ) + 1 ];
+				imageData[ ( x + width * y ) * 4 + 0 ] = colormap[ ( color * 3 ) + 2 ];
+
 			}
+
 		}
 
 		return imageData;
 
 	}
 
-	function tgaGetImageData16bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
+	function tgaGetImageData16bits( imageData, y_start, y_step, y_end, x_start, x_step, x_end, image ) {
 
 		var color, i = 0, x, y;
 		var width = header.width;
 
-		for (y = y_start; y !== y_end; y += y_step) {
-			for (x = x_start; x !== x_end; x += x_step, i += 2) {
-				color = image[i + 0] + (image[i + 1] << 8); // Inversed ?
-				imageData[(x + width * y) * 4 + 0] = (color & 0x7C00) >> 7;
-				imageData[(x + width * y) * 4 + 1] = (color & 0x03E0) >> 2;
-				imageData[(x + width * y) * 4 + 2] = (color & 0x001F) >> 3;
-				imageData[(x + width * y) * 4 + 3] = (color & 0x8000) ? 0 : 255;
+		for ( y = y_start; y !== y_end; y += y_step ) {
+
+			for ( x = x_start; x !== x_end; x += x_step, i += 2 ) {
+
+				color = image[ i + 0 ] + ( image[ i + 1 ] << 8 ); // Inversed ?
+				imageData[ ( x + width * y ) * 4 + 0 ] = ( color & 0x7C00 ) >> 7;
+				imageData[ ( x + width * y ) * 4 + 1 ] = ( color & 0x03E0 ) >> 2;
+				imageData[ ( x + width * y ) * 4 + 2 ] = ( color & 0x001F ) >> 3;
+				imageData[ ( x + width * y ) * 4 + 3 ] = ( color & 0x8000 ) ? 0 : 255;
+
 			}
+
 		}
 
 		return imageData;
 
 	}
 
-	function tgaGetImageData24bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
+	function tgaGetImageData24bits( imageData, y_start, y_step, y_end, x_start, x_step, x_end, image ) {
 
 		var i = 0, x, y;
 		var width = header.width;
 
-		for (y = y_start; y !== y_end; y += y_step) {
-			for (x = x_start; x !== x_end; x += x_step, i += 3) {
-				imageData[(x + width * y) * 4 + 3] = 255;
-				imageData[(x + width * y) * 4 + 2] = image[i + 0];
-				imageData[(x + width * y) * 4 + 1] = image[i + 1];
-				imageData[(x + width * y) * 4 + 0] = image[i + 2];
+		for ( y = y_start; y !== y_end; y += y_step ) {
+
+			for ( x = x_start; x !== x_end; x += x_step, i += 3 ) {
+
+				imageData[ ( x + width * y ) * 4 + 3 ] = 255;
+				imageData[ ( x + width * y ) * 4 + 2 ] = image[ i + 0 ];
+				imageData[ ( x + width * y ) * 4 + 1 ] = image[ i + 1 ];
+				imageData[ ( x + width * y ) * 4 + 0 ] = image[ i + 2 ];
+
 			}
+
 		}
 
 		return imageData;
 
 	}
 
-	function tgaGetImageData32bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
+	function tgaGetImageData32bits( imageData, y_start, y_step, y_end, x_start, x_step, x_end, image ) {
 
 		var i = 0, x, y;
 		var width = header.width;
 
-		for (y = y_start; y !== y_end; y += y_step) {
-			for (x = x_start; x !== x_end; x += x_step, i += 4) {
-				imageData[(x + width * y) * 4 + 2] = image[i + 0];
-				imageData[(x + width * y) * 4 + 1] = image[i + 1];
-				imageData[(x + width * y) * 4 + 0] = image[i + 2];
-				imageData[(x + width * y) * 4 + 3] = image[i + 3];
+		for ( y = y_start; y !== y_end; y += y_step ) {
+
+			for ( x = x_start; x !== x_end; x += x_step, i += 4 ) {
+
+				imageData[ ( x + width * y ) * 4 + 2 ] = image[ i + 0 ];
+				imageData[ ( x + width * y ) * 4 + 1 ] = image[ i + 1 ];
+				imageData[ ( x + width * y ) * 4 + 0 ] = image[ i + 2 ];
+				imageData[ ( x + width * y ) * 4 + 3 ] = image[ i + 3 ];
+
 			}
+
 		}
 
 		return imageData;
@@ -290,32 +334,40 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
 		var color, i = 0, x, y;
 		var width = header.width;
 
-		for (y = y_start; y !== y_end; y += y_step) {
-			for (x = x_start; x !== x_end; x += x_step, i ++) {
-				color = image[i];
-				imageData[(x + width * y) * 4 + 0] = color;
-				imageData[(x + width * y) * 4 + 1] = color;
-				imageData[(x + width * y) * 4 + 2] = color;
-				imageData[(x + width * y) * 4 + 3] = 255;
+		for ( y = y_start; y !== y_end; y += y_step ) {
+
+			for ( x = x_start; x !== x_end; x += x_step, i ++ ) {
+
+				color = image[ i ];
+				imageData[ ( x + width * y ) * 4 + 0 ] = color;
+				imageData[ ( x + width * y ) * 4 + 1 ] = color;
+				imageData[ ( x + width * y ) * 4 + 2 ] = color;
+				imageData[ ( x + width * y ) * 4 + 3 ] = 255;
+
 			}
+
 		}
 
 		return imageData;
 
 	}
 
-	function tgaGetImageDataGrey16bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
+	function tgaGetImageDataGrey16bits( imageData, y_start, y_step, y_end, x_start, x_step, x_end, image ) {
 
 		var i = 0, x, y;
 		var width = header.width;
 
-		for (y = y_start; y !== y_end; y += y_step) {
-			for (x = x_start; x !== x_end; x += x_step, i += 2) {
-				imageData[(x + width * y) * 4 + 0] = image[i + 0];
-				imageData[(x + width * y) * 4 + 1] = image[i + 0];
-				imageData[(x + width * y) * 4 + 2] = image[i + 0];
-				imageData[(x + width * y) * 4 + 3] = image[i + 1];
+		for ( y = y_start; y !== y_end; y += y_step ) {
+
+			for ( x = x_start; x !== x_end; x += x_step, i += 2 ) {
+
+				imageData[ ( x + width * y ) * 4 + 0 ] = image[ i + 0 ];
+				imageData[ ( x + width * y ) * 4 + 1 ] = image[ i + 0 ];
+				imageData[ ( x + width * y ) * 4 + 2 ] = image[ i + 0 ];
+				imageData[ ( x + width * y ) * 4 + 3 ] = image[ i + 1 ];
+
 			}
+
 		}
 
 		return imageData;
@@ -330,9 +382,9 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
 			y_step,
 			x_end,
 			y_end,
-			data = new Uint8Array(width * height * 4);
+			data = new Uint8Array( width * height * 4 );
 
-		switch ( (header.flags & TGA_ORIGIN_MASK) >> TGA_ORIGIN_SHIFT ) {
+		switch ( ( header.flags & TGA_ORIGIN_MASK ) >> TGA_ORIGIN_SHIFT ) {
 			default:
 			case TGA_ORIGIN_UL:
 				x_start = 0;
@@ -348,14 +400,14 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
 				x_step = 1;
 				x_end = width;
 				y_start = height - 1;
-				y_step = -1;
-				y_end = -1;
+				y_step = - 1;
+				y_end = - 1;
 				break;
 
 			case TGA_ORIGIN_UR:
 				x_start = width - 1;
-				x_step = -1;
-				x_end = -1;
+				x_step = - 1;
+				x_end = - 1;
 				y_start = 0;
 				y_step = 1;
 				y_end = height;
@@ -363,11 +415,11 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
 
 			case TGA_ORIGIN_BR:
 				x_start = width - 1;
-				x_step = -1;
-				x_end = -1;
+				x_step = - 1;
+				x_end = - 1;
 				y_start = height - 1;
-				y_step = -1;
-				y_end = -1;
+				y_step = - 1;
+				y_end = - 1;
 				break;
 
 		}

+ 155 - 85
examples/js/loaders/VRMLLoader.js

@@ -69,7 +69,8 @@ THREE.VRMLLoader.prototype = {
 			* @param float t
 			* @returns {Color}
 			*/
-			var interpolateColors = function(a, b, t) {
+			var interpolateColors = function( a, b, t ) {
+
 				var deltaR = a.r - b.r;
 				var deltaG = a.g - b.g;
 				var deltaB = a.b - b.b;
@@ -81,6 +82,7 @@ THREE.VRMLLoader.prototype = {
 				c.b = a.b - t * deltaB;
 
 				return c;
+
 			};
 
 			/**
@@ -105,11 +107,11 @@ THREE.VRMLLoader.prototype = {
 			 * @param colors
 			 * @param boolean directionIsDown Whether to work bottom up or top down.
 			 */
-			var paintFaces = function (geometry, radius, angles, colors, directionIsDown) {
+			var paintFaces = function ( geometry, radius, angles, colors, directionIsDown ) {
 
 				var f, n, p, vertexIndex, color;
 
-				var direction = directionIsDown ? 1 : -1;
+				var direction = directionIsDown ? 1 : - 1;
 
 				var faceIndices = [ 'a', 'b', 'c', 'd' ];
 
@@ -120,9 +122,9 @@ THREE.VRMLLoader.prototype = {
 					var vec = { };
 
 					// push the vector at which the color changes
-					vec.y = direction * ( Math.cos( angles[k] ) * radius);
+					vec.y = direction * ( Math.cos( angles[ k ] ) * radius );
 
-					vec.x = direction * ( Math.sin( angles[k] ) * radius);
+					vec.x = direction * ( Math.sin( angles[ k ] ) * radius );
 
 					coord.push( vec );
 
@@ -148,7 +150,7 @@ THREE.VRMLLoader.prototype = {
 							if ( index === 0 ) {
 
 								A.x = 0;
-								A.y = directionIsDown ? radius : -1 * radius;
+								A.y = directionIsDown ? radius : - 1 * radius;
 
 							} else {
 
@@ -158,13 +160,14 @@ THREE.VRMLLoader.prototype = {
 							}
 
 							// B is current point (angle)
-							B = coord[index];
+							B = coord[ index ];
 
 							if ( undefined !== B ) {
+
 								// p has to be between the points A and B which we interpolate
 								applyColor = directionIsDown ? p.y <= A.y && p.y > B.y : p.y >= A.y && p.y < B.y;
 
-								if (applyColor) {
+								if ( applyColor ) {
 
 									bColor = colors[ index + 1 ];
 
@@ -177,21 +180,25 @@ THREE.VRMLLoader.prototype = {
 									color = interpolateColors( aColor, bColor, t );
 
 									f.vertexColors[ j ] = color;
+
 								}
 
 							} else if ( undefined === f.vertexColors[ j ] ) {
+
 								colorIndex = directionIsDown ? colors.length - 1 : 0;
 								f.vertexColors[ j ] = colors[ colorIndex ];
 
 							}
+
 						}
 
 					}
 
 				}
+
 			};
 
-			var parseProperty = function (node, line) {
+			var parseProperty = function ( node, line ) {
 
 				var parts = [], part, property = {}, fieldName;
 
@@ -203,15 +210,17 @@ THREE.VRMLLoader.prototype = {
 
 				var point, index, angles, colors;
 
-				while (null != ( part = regex.exec(line) ) ) {
-					parts.push(part[0]);
+				while ( null != ( part = regex.exec( line ) ) ) {
+
+					parts.push( part[ 0 ] );
+
 				}
 
-				fieldName = parts[0];
+				fieldName = parts[ 0 ];
 
 
 				// trigger several recorders
-				switch (fieldName) {
+				switch ( fieldName ) {
 					case 'skyAngle':
 					case 'groundAngle':
 						this.recordingFieldname = fieldName;
@@ -236,56 +245,72 @@ THREE.VRMLLoader.prototype = {
 						break;
 				}
 
-				if (this.isRecordingFaces) {
+				if ( this.isRecordingFaces ) {
 
 					// the parts hold the indexes as strings
-					if (parts.length > 0) {
+					if ( parts.length > 0 ) {
+
 						index = [];
 
-						for (var ind = 0; ind < parts.length; ind ++) {
+						for ( var ind = 0; ind < parts.length; ind ++ ) {
 
 							// the part should either be positive integer or -1
-							if (!/(-?\d+)/.test( parts[ind]) ) {
+							if ( ! /(-?\d+)/.test( parts[ ind ] ) ) {
+
 								continue;
+
 							}
 
 							// end of current face
-							if (parts[ind] === "-1") {
-								if (index.length > 0) {
-									this.indexes.push(index);
+							if ( parts[ ind ] === "-1" ) {
+
+								if ( index.length > 0 ) {
+
+									this.indexes.push( index );
+
 								}
 
 								// start new one
 								index = [];
+
 							} else {
-								index.push(parseInt( parts[ind]) );
+
+								index.push( parseInt( parts[ ind ] ) );
+
 							}
+
 						}
 
 					}
 
 					// end
-					if (/]/.exec(line)) {
+					if ( /]/.exec( line ) ) {
+
 						this.isRecordingFaces = false;
 						node.coordIndex = this.indexes;
+
 					}
 
-				} else if (this.isRecordingPoints) {
+				} else if ( this.isRecordingPoints ) {
+
+					while ( null !== ( parts = float3_pattern.exec( line ) ) ) {
 
-					while ( null !== ( parts = float3_pattern.exec(line) ) ) {
 						point = {
-							x: parseFloat(parts[1]),
-							y: parseFloat(parts[2]),
-							z: parseFloat(parts[3])
+							x: parseFloat( parts[ 1 ] ),
+							y: parseFloat( parts[ 2 ] ),
+							z: parseFloat( parts[ 3 ] )
 						};
 
-						this.points.push(point);
+						this.points.push( point );
+
 					}
 
 					// end
-					if ( /]/.exec(line) ) {
+					if ( /]/.exec( line ) ) {
+
 						this.isRecordingPoints = false;
 						node.points = this.points;
+
 					}
 
 				} else if ( this.isRecordingAngles ) {
@@ -296,59 +321,68 @@ THREE.VRMLLoader.prototype = {
 						for ( var ind = 0; ind < parts.length; ind ++ ) {
 
 							// the part should be a float
-							if ( ! float_pattern.test( parts[ind] ) ) {
+							if ( ! float_pattern.test( parts[ ind ] ) ) {
+
 								continue;
+
 							}
 
-							this.angles.push( parseFloat( parts[ind] ) );
+							this.angles.push( parseFloat( parts[ ind ] ) );
+
 						}
 
 					}
 
 					// end
-					if ( /]/.exec(line) ) {
+					if ( /]/.exec( line ) ) {
+
 						this.isRecordingAngles = false;
-						node[this.recordingFieldname] = this.angles;
+						node[ this.recordingFieldname ] = this.angles;
+
 					}
 
-				} else if (this.isRecordingColors) {
+				} else if ( this.isRecordingColors ) {
 
-					while ( null !== ( parts = float3_pattern.exec(line) ) ) {
+					while ( null !== ( parts = float3_pattern.exec( line ) ) ) {
 
 						color = {
-							r: parseFloat(parts[1]),
-							g: parseFloat(parts[2]),
-							b: parseFloat(parts[3])
+							r: parseFloat( parts[ 1 ] ),
+							g: parseFloat( parts[ 2 ] ),
+							b: parseFloat( parts[ 3 ] )
 						};
 
-						this.colors.push(color);
+						this.colors.push( color );
 
 					}
 
 					// end
-					if (/]/.exec(line)) {
+					if ( /]/.exec( line ) ) {
+
 						this.isRecordingColors = false;
-						node[this.recordingFieldname] = this.colors;
+						node[ this.recordingFieldname ] = this.colors;
+
 					}
 
-				} else if ( parts[parts.length - 1] !== 'NULL' && fieldName !== 'children') {
+				} else if ( parts[ parts.length - 1 ] !== 'NULL' && fieldName !== 'children' ) {
 
-					switch (fieldName) {
+					switch ( fieldName ) {
 
 						case 'diffuseColor':
 						case 'emissiveColor':
 						case 'specularColor':
 						case 'color':
 
-							if (parts.length != 4) {
-								console.warn('Invalid color format detected for ' + fieldName );
+							if ( parts.length != 4 ) {
+
+								console.warn( 'Invalid color format detected for ' + fieldName );
 								break;
+
 							}
 
 							property = {
-								r: parseFloat(parts[1]),
-								g: parseFloat(parts[2]),
-								b: parseFloat(parts[3])
+								r: parseFloat( parts[ 1 ] ),
+								g: parseFloat( parts[ 2 ] ),
+								b: parseFloat( parts[ 3 ] )
 							};
 
 							break;
@@ -356,15 +390,17 @@ THREE.VRMLLoader.prototype = {
 						case 'translation':
 						case 'scale':
 						case 'size':
-							if (parts.length != 4) {
-								console.warn('Invalid vector format detected for ' + fieldName);
+							if ( parts.length != 4 ) {
+
+								console.warn( 'Invalid vector format detected for ' + fieldName );
 								break;
+
 							}
 
 							property = {
-								x: parseFloat(parts[1]),
-								y: parseFloat(parts[2]),
-								z: parseFloat(parts[3])
+								x: parseFloat( parts[ 1 ] ),
+								y: parseFloat( parts[ 2 ] ),
+								z: parseFloat( parts[ 3 ] )
 							};
 
 							break;
@@ -376,26 +412,30 @@ THREE.VRMLLoader.prototype = {
 						case 'transparency':
 						case 'shininess':
 						case 'ambientIntensity':
-							if (parts.length != 2) {
-								console.warn('Invalid single float value specification detected for ' + fieldName);
+							if ( parts.length != 2 ) {
+
+								console.warn( 'Invalid single float value specification detected for ' + fieldName );
 								break;
+
 							}
 
-							property = parseFloat(parts[1]);
+							property = parseFloat( parts[ 1 ] );
 
 							break;
 
 						case 'rotation':
-							if (parts.length != 5) {
-								console.warn('Invalid quaternion format detected for ' + fieldName);
+							if ( parts.length != 5 ) {
+
+								console.warn( 'Invalid quaternion format detected for ' + fieldName );
 								break;
+
 							}
 
 							property = {
-								x: parseFloat(parts[1]),
-								y: parseFloat(parts[2]),
-								z: parseFloat(parts[3]),
-								w: parseFloat(parts[4])
+								x: parseFloat( parts[ 1 ] ),
+								y: parseFloat( parts[ 2 ] ),
+								z: parseFloat( parts[ 3 ] ),
+								w: parseFloat( parts[ 4 ] )
 							};
 
 							break;
@@ -404,20 +444,24 @@ THREE.VRMLLoader.prototype = {
 						case 'solid':
 						case 'colorPerVertex':
 						case 'convex':
-							if (parts.length != 2) {
-								console.warn('Invalid format detected for ' + fieldName);
+							if ( parts.length != 2 ) {
+
+								console.warn( 'Invalid format detected for ' + fieldName );
 								break;
+
 							}
 
-							property = parts[1] === 'TRUE' ? true : false;
+							property = parts[ 1 ] === 'TRUE' ? true : false;
 
 							break;
 					}
 
-					node[fieldName] = property;
+					node[ fieldName ] = property;
+
 				}
 
 				return property;
+
 			};
 
 			var getTree = function ( lines ) {
@@ -435,41 +479,49 @@ THREE.VRMLLoader.prototype = {
 
 					// omit whitespace only lines
 					if ( null !== ( result = /^\s+?$/g.exec( line ) ) ) {
+
 						continue;
+
 					}
 
 					line = line.trim();
 
 					// skip empty lines
-					if (line === '') {
+					if ( line === '' ) {
+
 						continue;
+
 					}
 
 					if ( /#/.exec( line ) ) {
 
-						var parts = line.split('#');
+						var parts = line.split( '#' );
 
 						// discard everything after the #, it is a comment
-						line = parts[0];
+						line = parts[ 0 ];
 
 						// well, let's also keep the comment
-						comment = parts[1];
+						comment = parts[ 1 ];
+
 					}
 
-					if ( matches = /([^\s]*){1}\s?{/.exec( line ) ) { // first subpattern should match the Node name
+					if ( matches = /([^\s]*){1}\s?{/.exec( line ) ) {
+
+						// first subpattern should match the Node name
 
-						var block = { 'nodeType' : matches[1], 'string': line, 'parent': current, 'children': [],'comment' : comment };
+						var block = { 'nodeType' : matches[ 1 ], 'string': line, 'parent': current, 'children': [], 'comment' : comment };
 						current.children.push( block );
 						current = block;
 
 						if ( /}/.exec( line ) ) {
+
 							// example: geometry Box { size 1 1 1 } # all on the same line
 							specification = /{(.*)}/.exec( line )[ 1 ];
 
 							// todo: remove once new parsing is complete?
 							block.children.push( specification );
 
-							parseProperty(current, specification);
+							parseProperty( current, specification );
 
 							current = current.parent;
 
@@ -481,7 +533,7 @@ THREE.VRMLLoader.prototype = {
 
 					} else if ( line !== '' ) {
 
-						parseProperty(current, line);
+						parseProperty( current, line );
 						// todo: remove once new parsing is complete? we still do not parse geometry and appearance the new way
 						current.children.push( line );
 
@@ -490,6 +542,7 @@ THREE.VRMLLoader.prototype = {
 				}
 
 				return tree;
+
 			};
 
 			var parseNode = function ( data, parent ) {
@@ -502,8 +555,10 @@ THREE.VRMLLoader.prototype = {
 
 						var defineKey = /USE\s+?(\w+)/.exec( data )[ 1 ];
 
-						if (undefined == defines[defineKey]) {
-							console.warn(defineKey + ' is not defined.');
+						if ( undefined == defines[ defineKey ] ) {
+
+							console.warn( defineKey + ' is not defined.' );
+
 						} else {
 
 							if ( /appearance/.exec( data ) && defineKey ) {
@@ -515,12 +570,14 @@ THREE.VRMLLoader.prototype = {
 								parent.geometry = defines[ defineKey ].clone();
 
 								// the solid property is not cloned with clone(), is only needed for VRML loading, so we need to transfer it
-								if (undefined !== defines[ defineKey ].solid && defines[ defineKey ].solid === false) {
+								if ( undefined !== defines[ defineKey ].solid && defines[ defineKey ].solid === false ) {
+
 									parent.geometry.solid = false;
 									parent.material.side = THREE.DoubleSide;
+
 								}
 
-							} else if (defineKey) {
+							} else if ( defineKey ) {
 
 								var object = defines[ defineKey ].clone();
 								parent.add( object );
@@ -542,15 +599,17 @@ THREE.VRMLLoader.prototype = {
 					object = new THREE.Object3D();
 
 					if ( /DEF/.exec( data.string ) ) {
+
 						object.name = /DEF\s+(\w+)/.exec( data.string )[ 1 ];
 						defines[ object.name ] = object;
+
 					}
 
-					if ( undefined !== data['translation'] ) {
+					if ( undefined !== data[ 'translation' ] ) {
 
 						var t = data.translation;
 
-						object.position.set(t.x, t.y, t.z);
+						object.position.set( t.x, t.y, t.z );
 
 					}
 
@@ -581,6 +640,7 @@ THREE.VRMLLoader.prototype = {
 						object.name = /DEF (\w+)/.exec( data.string )[ 1 ];
 
 						defines[ object.name ] = object;
+
 					}
 
 					parent.add( object );
@@ -667,10 +727,13 @@ THREE.VRMLLoader.prototype = {
 									vec = new THREE.Vector3( point.x, point.y, point.z );
 
 									geometry.vertices.push( vec );
+
 								}
 
 								break;
+
 							}
+
 						}
 
 						var skip = 0;
@@ -678,7 +741,7 @@ THREE.VRMLLoader.prototype = {
 						// read this: http://math.hws.edu/eck/cs424/notes2013/16_Threejs_Advanced.html
 						for ( var i = 0, j = data.coordIndex.length; i < j; i ++ ) {
 
-							indexes = data.coordIndex[i];
+							indexes = data.coordIndex[ i ];
 
 							// vrml support multipoint indexed face sets (more then 3 vertices). You must calculate the composing triangles here
 							skip = 0;
@@ -689,9 +752,9 @@ THREE.VRMLLoader.prototype = {
 							while ( indexes.length >= 3 && skip < ( indexes.length - 2 ) ) {
 
 								var face = new THREE.Face3(
-									indexes[0],
-									indexes[skip + 1],
-									indexes[skip + 2],
+									indexes[ 0 ],
+									indexes[ skip + 1 ],
+									indexes[ skip + 2 ],
 									null // normal, will be added later
 									// todo: pass in the color, if a color index is present
 								);
@@ -706,7 +769,9 @@ THREE.VRMLLoader.prototype = {
 						}
 
 						if ( false === data.solid ) {
+
 							parent.material.side = THREE.DoubleSide;
+
 						}
 
 						// we need to store it on the geometry for use with defines
@@ -718,11 +783,14 @@ THREE.VRMLLoader.prototype = {
 
 						// see if it's a define
 						if ( /DEF/.exec( data.string ) ) {
+
 							geometry.name = /DEF (\w+)/.exec( data.string )[ 1 ];
 							defines[ geometry.name ] = geometry;
+
 						}
 
 						parent.geometry = geometry;
+
 					}
 
 					return;
@@ -734,6 +802,7 @@ THREE.VRMLLoader.prototype = {
 						var child = data.children[ i ];
 
 						if ( 'Material' === child.nodeType ) {
+
 							var material = new THREE.MeshPhongMaterial();
 
 							if ( undefined !== child.diffuseColor ) {
@@ -783,6 +852,7 @@ THREE.VRMLLoader.prototype = {
 
 							// material found, stop looping
 							break;
+
 						}
 
 					}
@@ -825,4 +895,4 @@ THREE.VRMLLoader.prototype = {
 
 	}
 
-};
+};

+ 7 - 7
examples/js/loaders/deprecated/SceneLoader.js

@@ -308,10 +308,10 @@ THREE.SceneLoader.prototype = {
 
 								object.matrixAutoUpdate = false;
 								object.matrix.set(
-									mat[0],  mat[1],  mat[2],  mat[3],
-									mat[4],  mat[5],  mat[6],  mat[7],
-									mat[8],  mat[9],  mat[10], mat[11],
-									mat[12], mat[13], mat[14], mat[15]
+									mat[ 0 ],  mat[ 1 ],  mat[ 2 ],  mat[ 3 ],
+									mat[ 4 ],  mat[ 5 ],  mat[ 6 ],  mat[ 7 ],
+									mat[ 8 ],  mat[ 9 ],  mat[ 10 ], mat[ 11 ],
+									mat[ 12 ], mat[ 13 ], mat[ 14 ], mat[ 15 ]
 								);
 
 							} else {
@@ -385,7 +385,7 @@ THREE.SceneLoader.prototype = {
 								break;
 
 							case 'AreaLight':
-								light = new THREE.AreaLight(color, intensity);
+								light = new THREE.AreaLight( color, intensity );
 								light.position.fromArray( position );
 								light.width = objJSON.size;
 								light.height = objJSON.size_y;
@@ -763,7 +763,7 @@ THREE.SceneLoader.prototype = {
 			}
 
 			color = fogJSON.color;
-			fog.color.setRGB( color[0], color[1], color[2] );
+			fog.color.setRGB( color[ 0 ], color[ 1 ], color[ 2 ] );
 
 			result.fogs[ fogID ] = fog;
 
@@ -805,7 +805,7 @@ THREE.SceneLoader.prototype = {
 
 				}
 
-			});
+			} );
 
 		}
 

+ 53 - 4
examples/js/loaders/sea3d/SEA3D.js

@@ -2280,8 +2280,6 @@ SEA3D.Morph = function(name, data, sea) {
 	var useVertex = (this.attrib & 2) != 0;
 	var useNormal = (this.attrib & 4) != 0;
 	
-	var len = this.numVertex * 3;
-	
 	var nodeCount = data.readUShort();
 	
 	this.node = [];
@@ -2295,7 +2293,7 @@ SEA3D.Morph = function(name, data, sea) {
 			var verts = [];
 			
 			j = 0;
-			while(j < len)
+			while(j < this.length)
 				verts[j++] = data.readFloat();
 		}
 		
@@ -2303,7 +2301,7 @@ SEA3D.Morph = function(name, data, sea) {
 			var norms = [];
 			
 			j = 0;
-			while(j < len)
+			while(j < this.length)
 				norms[j++] = data.readFloat();
 		}
 		
@@ -2313,6 +2311,56 @@ SEA3D.Morph = function(name, data, sea) {
 
 SEA3D.Morph.prototype.type = "mph";
 
+//
+//	Vertex Animation
+//
+
+SEA3D.VertexAnimation = function(name, data, sea) {
+	this.name = name;
+	this.data = data;
+	this.sea = sea;
+	
+	SEA3D.AnimationBase.read(this);
+	
+	var flags = data.readUByte();
+	
+	this.isBigMesh = (flags & 1) != 0;	
+	
+	data.readVInt = this.isBigMesh ? data.readUInt : data.readUShort;
+
+	this.numVertex = data.readVInt();
+	this.length = this.numVertex * 3;
+	
+	var useVertex = (flags & 2) != 0;
+	var useNormal = (flags & 4) != 0;
+	
+	this.frame = [];
+
+	var i, j;
+	
+	for(i = 0; i < this.numFrames; i++) {
+		if (useVertex) {				
+			var verts = [];
+			
+			j = 0;
+			while(j < this.length)
+				verts[j++] = data.readFloat();
+		}
+		
+		if (useNormal) {
+			var norms = [];
+			
+			j = 0;
+			while(j < this.length)
+				norms[j++] = data.readFloat();
+		}
+		
+		this.frame[i] = {vertex:verts, normal:norms}
+	}	
+}
+
+SEA3D.VertexAnimation.prototype.type = "vtxa";
+
 //
 //	Camera
 //
@@ -2942,6 +2990,7 @@ SEA3D.File = function(data) {
 	this.addClass(SEA3D.JointObject);
 	this.addClass(SEA3D.Camera);
 	this.addClass(SEA3D.Morph);
+	this.addClass(SEA3D.VertexAnimation);
 	this.addClass(SEA3D.CubeMap);
 	this.addClass(SEA3D.Animation);	
 	this.addClass(SEA3D.Dummy);

+ 201 - 125
examples/js/loaders/sea3d/SEA3DLoader.js

@@ -25,12 +25,12 @@ THREE.ShaderLib.replaceCode = function(src, target, replace) {
 THREE.ShaderLib['phong'].fragmentShader_StandardMaterial = 
 	THREE.ShaderLib.replaceCode( THREE.ShaderLib['phong'].fragmentShader, [
 		//	Target
-		'outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + ambientLightColor ) * specular + totalSpecularLight + emissive;', // METAL
-		'outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + ambientLightColor ) + totalSpecularLight + emissive;'	
+		'outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;', // METAL
+		'outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;'	
 	], [
 		//	Replace To
-		'outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + ambientLightColor + emissive ) * specular + totalSpecularLight;', // METAL
-		'outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + ambientLightColor + emissive ) + totalSpecularLight;'	
+		'outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight + totalEmissiveLight ) * specular + totalSpecularLight;', // METAL
+		'outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight + totalEmissiveLight ) + totalSpecularLight;'	
 	] );
 
 //
@@ -47,7 +47,7 @@ THREE.MeshPhongMaterial.prototype.clone = function() {
 }
 
 THREE.MeshPhongMaterial.prototype.__defineSetter__("__webglShader", function(val){
-	if (this.emissiveToAmbientColor) val.fragmentShader = THREE.ShaderLib['phong'].fragmentShader_StandardMaterial;
+	if (this.emissiveToAmbientColor) val.fragmentShader = THREE.ShaderLib['phong'].fragmentShader_StandardMaterial;	
 	this.__webglShader__ = val;
 });
 THREE.MeshPhongMaterial.prototype.__defineGetter__("__webglShader", function(){
@@ -188,6 +188,16 @@ THREE.SkinnedMesh.prototype.setAnimations = function(animations) {
 	}
 }
 
+THREE.SkinnedMesh.prototype.boneByName = function(name) {
+	var bones = this.bones;
+	
+	for(var i = 0, bl = bones.length; i < bl; i++) {
+		if (name == bones[i].name) {
+			return bones[i];
+		}
+	}
+}
+
 THREE.SkinnedMesh.prototype.DISPOSE = THREE.SkinnedMesh.prototype.dispose;
 THREE.SkinnedMesh.prototype.dispose = function () {	
 	this.stop();
@@ -367,22 +377,6 @@ THREE.Sound3D.update = function( camera ) {
 	}
 }
 
-//
-//	Bone Extension (Joint Object)
-//
-
-THREE.Bone.fromName = function(mesh, name) {
-	var bones = mesh.bones;
-	
-	for(var i = 0, bl = bones.length; i < bl; i++)
-	{
-		if (name == bones[i].name)
-		{
-			return bones[i];
-		}
-	}
-}
-
 //
 //	SEA3D
 //
@@ -626,6 +620,7 @@ THREE.SEA3D.prototype.updateTransform = function(obj3d, sea) {
 THREE.SEA3D.prototype.updateAnimationSet = function(obj3d) {
 	var buf = THREE.SEA3D.BUFFER2;
 	var anmSet = obj3d.animation.animationSet;
+	var relative = obj3d.animation.relative;
 		
 	if (anmSet.flip)
 		return;
@@ -637,19 +632,19 @@ THREE.SEA3D.prototype.updateAnimationSet = function(obj3d) {
 		var t_anm = [], j;		
 				
 		for (j = 0; j < dataList.length; j++) {
-			var data = dataList[i];	
-			var raw = dataList[i].data;	
+			var data = dataList[j];	
+			var raw = dataList[j].data;	
 			var kind = data.kind;
 			var numFrames = raw.length / data.blockLength;			
 			
 			switch(kind) {
 				case SEA3D.Animation.POSITION:
-				case SEA3D.Animation.ROTATION:
+				case SEA3D.Animation.ROTATION:				
 					t_anm.push( {
 						kind : kind,
 						numFrames : numFrames,
 						raw : raw						
-					} );
+					} );					
 					break;
 			}
 		}
@@ -657,16 +652,23 @@ THREE.SEA3D.prototype.updateAnimationSet = function(obj3d) {
 		if (t_anm.length > 0) {	
 			
 			var numFrames = t_anm[0].numFrames,
-				ct = THREE.SEA3D.CONTAINER;
-			
-			ct.position.set(0, 0, 0);
-			ct.rotation.set(0, 0, 0);
-			ct.scale.set(1, 1, 1);
-						
-			obj3d.add( ct );
+				ct = THREE.SEA3D.CONTAINER,			
+				tar = relative ? obj3d : obj3d.parent;
+
+			if (obj3d.animation.relative) {				
+				ct.position.set(0, 0, 0);
+				ct.rotation.set(0, 0, 0);
+				ct.scale.set(1, 1, 1);
+			} else {
+				ct.position.copy(obj3d.position);
+				ct.rotation.copy(obj3d.rotation);
+				ct.scale.copy(obj3d.scale);
+			}
+
+			tar.add( ct );
 			
-			for (var f = 0, t, c; f < numFrames; f++) {									
-				
+			for (var f = 0, t, c; f < numFrames; f++) {
+								
 				for (t = 0; t < t_anm.length; t++) {				
 					
 					var raw = t_anm[t].raw,
@@ -681,8 +683,8 @@ THREE.SEA3D.prototype.updateAnimationSet = function(obj3d) {
 								raw[c    ], 
 								raw[c + 1], 
 								raw[c + 2]
-							);			
-													
+							);		
+
 							break;
 							
 						case SEA3D.Animation.ROTATION:
@@ -695,10 +697,10 @@ THREE.SEA3D.prototype.updateAnimationSet = function(obj3d) {
 								raw[c + 2],
 								raw[c + 3]
 							);
-
+							
 							break;
-					}					
-				}	
+					}
+				}
 				
 				this.updateMatrix( ct );
 				
@@ -711,28 +713,28 @@ THREE.SEA3D.prototype.updateAnimationSet = function(obj3d) {
 						case SEA3D.Animation.POSITION:
 							
 							c = f * 3;														
-																					
+
 							raw[c    ] = ct.position.x;
 							raw[c + 1] = ct.position.y;
 							raw[c + 2] = ct.position.z;																									
-						
+					
 							break;
 							
 						case SEA3D.Animation.ROTATION:
 							
 							c = f * 4;
 
-							raw[c    ] = ct.quaternion.x;
-							raw[c + 1] = ct.quaternion.y;
-							raw[c + 2] = ct.quaternion.z;
-							raw[c + 3] = ct.quaternion.w;
-							
+							raw[c    ] = ct.quaternion.x;	
+							raw[c + 1] = ct.quaternion.y;	
+							raw[c + 2] = ct.quaternion.z;	
+							raw[c + 3] = ct.quaternion.w;	
+
 							break;
 					}					
 				}
 			}
 
-			obj3d.remove( ct );			
+			tar.remove( ct );			
 		}
 	}
 	
@@ -831,10 +833,10 @@ THREE.SEA3D.prototype.applyDefaultAnimation = function(sea, ANIMATOR_CLASS) {
 		
 				if (this.config.flip)
 					this.updateAnimationSet(obj);
-		
+
 				if (this.config.autoPlay) 
 					obj.animation.play( obj.animation.getStateNameByIndex(0) );
-				
+
 				return obj.animation;
 				break;
 		}
@@ -918,7 +920,7 @@ THREE.SEA3D.Object3DAnimator.prototype.updateAnimationFrame = function(frame, ki
 				break;
 				
 			case SEA3D.Animation.ROTATION:		
-				var v = frame.toVector();				
+				var v = frame.toVector();	
 				this.object3d.quaternion.set(v.x, v.y, v.z, v.w);
 				break;	
 				
@@ -987,14 +989,10 @@ THREE.SEA3D.LightAnimator.prototype.$updateAnimationFrame = THREE.SEA3D.Object3D
 //
 
 THREE.SEA3D.prototype.readGeometrySwitch = function(sea) {
-	if (sea.numVertex < 0xFFFE && !sea.joint && (!sea.uv || sea.uv.length === 1) && sea.indexes.length === 1)
-	{
-		this.readGeometryBuffer(sea);
-	}
+	if (sea.indexes.length === 1)	
+		this.readGeometryBuffer(sea);	
 	else
-	{
-		this.readGeometry(sea);
-	}
+		this.readGeometry(sea);	
 }
 
 THREE.SEA3D.prototype.readGeometryBuffer = function(sea) {
@@ -1002,60 +1000,37 @@ THREE.SEA3D.prototype.readGeometryBuffer = function(sea) {
 		count = index.length,
 		geo = new THREE.BufferGeometry();
 	
-	var indices, position, normals, uv, colors;
-			
-	geo.attributes = {
-		
-		index : {
-			itemSize: 1,
-			array: indices = new Uint16Array( count )
-		},
-		
-		position : {
-			itemSize: 3,
-			array: position = new Float32Array( count * 3 )
-		},
-			
-		uv : {
-			itemSize: 2,
-			array: uv = new Float32Array( count * 2 )
-		}
-	}
+	var indices, position, normals, tangents, uv, uv2, colors, skinIndex, skinWeight;
+	
+	indices = new Uint16Array( count );
+	position = new Float32Array( count * 3 );
 	
 	var a, b, c,
 		v = sea.vertex,
 		n = sea.normal,
 		t = sea.tangent,
-		u = sea.uv ? sea.uv[0] : undefined;
-	var vc = sea.color ? sea.color[0] : undefined;
-	
-	if (n)
-	{
-		geo.attributes.normal = {
-			itemSize: 3,
-			array: normals = new Float32Array( count * 3 )
-		}
-	}
-	
-	if (t)
-	{
-		geo.attributes.tangent = {
-			itemSize: 3,
-			array: normals = new Float32Array( count * 3 )
-		}
-	}
-	
-	if (vc)
-	{
-		geo.attributes.color = {
-			itemSize: 3,
-			array: colors = new Float32Array( count * 3 )
-		}
+		u = sea.uv ? sea.uv[0] : undefined,
+		u2 = sea.uv && sea.uv.length > 1 ? sea.uv[1] : undefined,
+		vc = sea.color ? sea.color[0] : undefined,
+		sI = sea.joint,
+		sW = sea.weight;
+	
+	if (n) normals = new Float32Array( count * 3 );	
+	if (t) tangents = new Float32Array( count * 3 );	
+	if (u) uv = new Float32Array( count * 2 );		
+	if (u2) uv2 = new Float32Array( count * 2 );	
+	if (vc) colors = new Float32Array( count * 3 );	
+	if (sI) {
+		skinIndex = new Float32Array( count * 4 );	
+		skinWeight = new Float32Array( count * 4 );	
+		
+		var jointPerVertex = Math.min( sea.jointPerVertex, 4 );
+		var compJointPerVertex = sea.jointPerVertex.length > 4;
 	}
 	
 	var flip = this.config.flip ? -1 : 1;
 	
-	for (var f = 0, vt = 0, vu=0; f < count; f+=3, vt+=9, vu+=6) {
+	for (var f = 0, vt = 0, vu=0, jt=0; f < count; f+=3, vt+=9, vu+=6, jt+=12) {
 	
 		// index
 	
@@ -1098,17 +1073,20 @@ THREE.SEA3D.prototype.readGeometryBuffer = function(sea) {
 		
 		if (t)
 		{
-			tangent[ vt     ] = t[ a     ];
-			tangent[ vt + 1 ] = t[ a + 1 ];
-			tangent[ vt + 2 ] = t[ a + 2 ] * flip;
+			tangents[ vt     ] = t[ a     ];
+			tangents[ vt + 1 ] = t[ a + 1 ];
+			tangents[ vt + 2 ] = t[ a + 2 ] * flip;
+			tangents[ vt + 3 ] = handleVertex(tangents, vt);
 			
-			tangent[ vt + 3 ] = t[ b     ];
-			tangent[ vt + 4 ] = t[ b + 1 ];
-			tangent[ vt + 5 ] = t[ b + 2 ] * flip;
+			tangents[ vt + 4 ] = t[ b     ];
+			tangents[ vt + 5 ] = t[ b + 1 ];
+			tangents[ vt + 6 ] = t[ b + 2 ] * flip;
+			tangents[ vt + 7 ] = handleVertex(tangents + 5, vt);
 			
-			tangent[ vt + 6 ] = t[ c     ];
-			tangent[ vt + 7 ] = t[ c + 1 ];
-			tangent[ vt + 8 ] = t[ c + 2 ] * flip;
+			tangents[ vt + 8 ] = t[ c     ];
+			tangents[ vt + 9 ] = t[ c + 1 ];
+			tangents[ vt + 10 ] = t[ c + 2 ] * flip;
+			tangents[ vt + 11 ] = handleVertex(tangents + 8, vt);
 		}
 		
 		// uv		
@@ -1140,6 +1118,24 @@ THREE.SEA3D.prototype.readGeometryBuffer = function(sea) {
 			uv[ vu + 5 ] = 1;
 		}
 		
+		// uv2
+		
+		if (u2)
+		{
+			a = index[ f     ] * 2;
+			b = index[ f + 2 ] * 2;
+			c = index[ f + 1 ] * 2;
+			
+			uv2[ vu     ] = u2[ a     ];
+			uv2[ vu + 1 ] = u2[ a + 1 ];
+		
+			uv2[ vu + 2 ] = u2[ b     ];
+			uv2[ vu + 3 ] = u2[ b + 1 ];
+			
+			uv2[ vu + 4 ] = u2[ c     ];
+			uv2[ vu + 5 ] = u2[ c + 1 ];
+		}
+		
 		// colors
 		
 		if (vc)
@@ -1161,24 +1157,65 @@ THREE.SEA3D.prototype.readGeometryBuffer = function(sea) {
 			colors[ vt + 8 ] = vc[ c + 2 ];
 		}
 		
+		// skin
+		
+		if (sI)
+		{
+			var i = 0, totalA = 0, totalB = 0, totalC = 0;
+			
+			a = index[ f     ] * sea.jointPerVertex;
+			b = index[ f + 2 ] * sea.jointPerVertex;
+			c = index[ f + 1 ] * sea.jointPerVertex;
+			
+			i = 0;
+			while ( i < jointPerVertex )
+			{
+				skinIndex[ jt + i ] = sI[ a + i ];				
+				totalA += skinWeight[ jt + i ] = sW[ a + i ];	
+				
+				skinIndex[ jt + i + 4 ] = sI[ b + i ];				
+				totalB += skinWeight[ jt + i + 4 ] = sW[ b + i ];	
+				
+				skinIndex[ jt + i + 8 ] = sI[ c + i ];				
+				totalC += skinWeight[ jt + i + 8 ] = sW[ c + i ];	
+				
+				++i;
+			}
+			
+			skinWeight[ jt ] += 1 - totalA;
+			skinWeight[ jt + 4 ] += 1 - totalB;
+			skinWeight[ jt + 8 ] += 1 - totalC;
+		}
+		
 		// indices
 		
 		indices[ f     ] = f;
 		indices[ f + 1 ] = f + 1;
 		indices[ f + 2 ] = f + 2;
-	}	
-		
-	if (sea.numVertex >= 0xFFFE) {
-		console.warn( "SEA3D: Big Mesh is not compatible with geometry buffer." );
-		//geo.computeOffsets();
-	}	
+	}
+	
+	geo.addAttribute( 'position', new THREE.BufferAttribute( position, 3 ) );
+	geo.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
+	
+	if (normals) geo.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
+	if (tangents) geo.addAttribute( 'tangent', new THREE.BufferAttribute( tangents, 4 ) );
+	if (uv) geo.addAttribute( 'uv', new THREE.BufferAttribute( uv, 2 ) );
+	if (uv2) geo.addAttribute( 'uv2', new THREE.BufferAttribute( uv2, 2 ) );		
+	if (colors) geo.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
+	if (skinIndex) {
+		geo.addAttribute( 'skinIndex', new THREE.Float32Attribute( skinIndex, 4 ) );		
+		geo.addAttribute( 'skinWeight', new THREE.Float32Attribute( skinWeight, 4 ) );		
+	}
+	
+	if (sea.numVertex >= 0xFFFE)	
+		geo.computeOffsets();	
 	
 	if (!n)	
 		geo.computeVertexNormals();	
 	
 	if (this.config.tangent && !sea.tangent)
 		geo.computeTangents();
-		
+	
 	if (this.config.bounding)
 	{
 		geo.computeBoundingBox();
@@ -1445,8 +1482,8 @@ THREE.SEA3D.prototype.readMesh2D = function(sea) {
 
 THREE.SEA3D.prototype.readMesh = function(sea) {
 	var geo = sea.geometry.tag,
-		mesh, mat, skeleton, skeletonAnimation, morpher;
-		
+		mesh, mat, skeleton, skeletonAnimation, morpher, vtxAnm;
+	
 	for(var i = 0, count = sea.modifiers ? sea.modifiers.length : 0; i < count; i++) {
 		var mod = sea.modifiers[i];
 		
@@ -1458,7 +1495,7 @@ THREE.SEA3D.prototype.readMesh = function(sea) {
 				break;
 		
 			case SEA3D.Morph.prototype.type:
-				morpher = mod;
+				morpher = mod;				
 				break;
 		}
 	}
@@ -1472,6 +1509,10 @@ THREE.SEA3D.prototype.readMesh = function(sea) {
 				skeletonAnimation = anm.tag;
 				geo.animations = this.getSkeletonAnimation( skeletonAnimation, skeleton );	
 				break;
+				
+			case SEA3D.VertexAnimation.prototype.type:
+				vtxAnm = anm.tag;								
+				break;
 		}
 	}
 	
@@ -1509,6 +1550,9 @@ THREE.SEA3D.prototype.readMesh = function(sea) {
 		}
 	} else {
 		mesh = new THREE.Mesh( geo, mat );
+		
+		if (vtxAnm)
+			geo.morphTargets = this.getVertexAnimation( vtxAnm );
 	}
 	
 	mesh.name = sea.name;
@@ -1519,10 +1563,10 @@ THREE.SEA3D.prototype.readMesh = function(sea) {
 	this.meshes = this.meshes || [];
 	this.meshes.push( this.objects["m3d/" + sea.name] = sea.tag = mesh );
 	
-	this.addSceneObject( sea );
-	this.updateTransform(mesh, sea);
+	this.addSceneObject( sea );		
+	this.updateTransform(mesh, sea);		
 	
-	this.applyDefaultAnimation( sea, THREE.SEA3D.Object3DAnimator );		
+	this.applyDefaultAnimation( sea, THREE.SEA3D.Object3DAnimator );
 }
 
 //
@@ -1869,7 +1913,11 @@ THREE.SEA3D.prototype.readMaterial = function(sea) {
 THREE.SEA3D.prototype.readPointLight = function(sea) {	
 	var light = new THREE.PointLight( sea.color, sea.multiplier * this.config.multiplier );
 	light.name = sea.name;
-			
+	
+	if (sea.attenuation) {
+		light.distance = sea.attenuation.end;
+	}
+	
 	if (sea.shadow)		
 		this.setShadowMap(light, sea.shadow.opacity);		
 	
@@ -2151,6 +2199,34 @@ THREE.SEA3D.prototype.getMorpher = function(sea, geo) {
 	return morphs;
 }
 
+//
+//	Vertex Animation
+//
+
+THREE.SEA3D.prototype.getVertexAnimation = function(sea) {	
+	var vtxAnms = [],
+		flip = this.config.flip ? -1 : 1;
+	
+	for(var i = 0; i < sea.frame.length; i++) {
+		var frame = sea.frame[i],
+			vertex = [];
+		
+		var j = 0, k = 0;
+		while(j < frame.vertex.length)
+			vertex[k++] = new THREE.Vector3(
+				frame.vertex[j++], 
+				frame.vertex[j++], 
+				frame.vertex[j++] * flip
+			);
+		
+		vtxAnms[i] = {
+			vertices:vertex			
+		}
+	}
+	
+	return vtxAnms;
+}
+
 //
 //	Events
 //

+ 3 - 2
examples/js/math/ColorConverter.js

@@ -29,6 +29,7 @@ THREE.ColorConverter = {
 			s: 2 * hsl.s / ( hsl.l + hsl.s ),
 			v: hsl.l + hsl.s
 		};
+
 	},
 
 	// where c, m, y, k is between 0 and 1
@@ -48,7 +49,7 @@ THREE.ColorConverter = {
 		var r = color.r;
 		var g = color.g;
 		var b = color.b;
-		var k = 1 - Math.max(r, g, b);
+		var k = 1 - Math.max( r, g, b );
 		var c = ( 1 - r - k ) / ( 1 - k );
 		var m = ( 1 - g - k ) / ( 1 - k );
 		var y = ( 1 - b - k ) / ( 1 - k );
@@ -60,4 +61,4 @@ THREE.ColorConverter = {
 	}
 
 
-};
+};

+ 60 - 28
examples/js/math/Lut.js

@@ -26,7 +26,7 @@ THREE.Lut = function ( colormap, numberofcolors ) {
 
 				color = minColor.lerp( maxColor, ( i - min ) / ( max - min ) );
 
-				this.lut.push(color);
+				this.lut.push( color );
 
 			}
 
@@ -130,7 +130,11 @@ THREE.Lut.prototype = {
 
 	setLegendOn: function ( parameters ) {
 
-		if ( parameters === undefined ) { parameters = {}; }
+		if ( parameters === undefined ) {
+
+			parameters = {};
+
+		}
 
 		this.legend = {};
 
@@ -165,7 +169,7 @@ THREE.Lut.prototype = {
 
 		var step = 1.0 / this.n;
 
-		for ( var i = 1; i >= 0; i-=step ) {
+		for ( var i = 1; i >= 0; i -= step ) {
 
 			for ( var j = this.map.length - 1; j >= 0; j -- ) {
 
@@ -174,16 +178,16 @@ THREE.Lut.prototype = {
 					var min = this.map[ j - 1 ][ 0 ];
 					var max = this.map[ j ][ 0 ];
 					var color = new THREE.Color( 0xffffff );
-					var minColor = new THREE.Color( 0xffffff ).setHex( this.map[ j - 1][ 1 ] );
+					var minColor = new THREE.Color( 0xffffff ).setHex( this.map[ j - 1 ][ 1 ] );
 					var maxColor = new THREE.Color( 0xffffff ).setHex( this.map[ j ][ 1 ] );
 					color = minColor.lerp( maxColor, ( i - min ) / ( max - min ) );
 
-					data[ k * 4     ] = Math.round( color.r * 255 );
+					data[ k * 4 ] = Math.round( color.r * 255 );
 					data[ k * 4 + 1 ] = Math.round( color.g * 255 );
 					data[ k * 4 + 2 ] = Math.round( color.b * 255 );
 					data[ k * 4 + 3 ] = 255;
 
-					k+=1;
+					k += 1;
 
 				}
 
@@ -199,7 +203,7 @@ THREE.Lut.prototype = {
 
 		this.legend.mesh = new THREE.Mesh( this.legend.legendGeometry, this.legend.legendMaterial );
 
-		if ( this.legend.layout == 'horizontal') {
+		if ( this.legend.layout == 'horizontal' ) {
 
 			this.legend.mesh.rotation.z = - 90 * ( Math.PI / 180 );
 
@@ -221,11 +225,23 @@ THREE.Lut.prototype = {
 
 	setLegendLayout: function ( layout ) {
 
-		if ( ! this.legend ) { return false; }
+		if ( ! this.legend ) {
 
-		if ( this.legend.layout == layout ) { return false; }
+			return false;
 
-		if ( layout != 'horizontal' && layout != 'vertical' ) { return false; }
+		}
+
+		if ( this.legend.layout == layout ) {
+
+			return false;
+
+		}
+
+		if ( layout != 'horizontal' && layout != 'vertical' ) {
+
+			return false;
+
+		}
 
 		this.layout = layout;
 
@@ -237,7 +253,7 @@ THREE.Lut.prototype = {
 
 		if ( layout == 'vertical' ) {
 
-			this.legend.mesh.rotation.z = -90 * ( Math.PI / 180 );
+			this.legend.mesh.rotation.z = - 90 * ( Math.PI / 180 );
 
 		}
 
@@ -255,11 +271,23 @@ THREE.Lut.prototype = {
 
 	setLegendLabels: function ( parameters, callback ) {
 
-		if ( ! this.legend ) { return false; }
+		if ( ! this.legend ) {
+
+			return false;
+
+		}
 
-		if ( typeof parameters === 'function') { callback = parameters; }
+		if ( typeof parameters === 'function' ) {
 
-		if ( parameters === undefined ) { parameters = {}; }
+			callback = parameters;
+
+		}
+
+		if ( parameters === undefined ) {
+
+			parameters = {};
+
+		}
 
 		this.legend.labels = {};
 
@@ -348,17 +376,13 @@ THREE.Lut.prototype = {
 
 					value = callback ( value );
 
-				}
-
-				else {
+				} else {
 
 					if ( this.legend.labels.notation == 'scientific' ) {
 
 						value = value.toExponential( this.legend.labels.decimal );
 
-					}
-
-					else {
+					} else {
 
 						value = value.toFixed( this.legend.labels.decimal );
 
@@ -408,13 +432,21 @@ THREE.Lut.prototype = {
 
 					if ( this.legend.labels.ticks > 5 ) {
 
-						if ( i % 2 === 0 ) { var offset = 1.7; }
+						if ( i % 2 === 0 ) {
 
-						else { var offset = 2.1; }
+							var offset = 1.7;
 
-					}
+						} else {
+
+							var offset = 2.1;
 
-					else { var offset = 1.7; }
+						}
+
+					} else {
+
+						var offset = 1.7;
+
+					}
 
 					spriteTick.position.set( position, this.legend.position.y - this.legend.dimensions.width * offset, this.legend.position.z );
 
@@ -463,9 +495,9 @@ THREE.Lut.prototype = {
 
 THREE.ColorMapKeywords = {
 
-  "rainbow":    [ [ 0.0, '0x0000FF' ], [ 0.2, '0x00FFFF' ], [ 0.5, '0x00FF00' ], [ 0.8, '0xFFFF00' ],  [ 1.0, '0xFF0000' ] ],
-  "cooltowarm": [ [ 0.0, '0x3C4EC2' ], [ 0.2, '0x9BBCFF' ], [ 0.5, '0xDCDCDC' ], [ 0.8, '0xF6A385' ],  [ 1.0, '0xB40426' ] ],
-  "blackbody" : [ [ 0.0, '0x000000' ], [ 0.2, '0x780000' ], [ 0.5, '0xE63200' ], [ 0.8, '0xFFFF00' ],  [ 1.0, '0xFFFFFF' ] ],
-  "grayscale" : [ [ 0.0, '0x000000' ], [ 0.2, '0x404040' ], [ 0.5, '0x7F7F80' ], [ 0.8, '0xBFBFBF' ],  [ 1.0, '0xFFFFFF' ] ]
+	"rainbow":    [ [ 0.0, '0x0000FF' ], [ 0.2, '0x00FFFF' ], [ 0.5, '0x00FF00' ], [ 0.8, '0xFFFF00' ],  [ 1.0, '0xFF0000' ] ],
+	"cooltowarm": [ [ 0.0, '0x3C4EC2' ], [ 0.2, '0x9BBCFF' ], [ 0.5, '0xDCDCDC' ], [ 0.8, '0xF6A385' ],  [ 1.0, '0xB40426' ] ],
+	"blackbody" : [ [ 0.0, '0x000000' ], [ 0.2, '0x780000' ], [ 0.5, '0xE63200' ], [ 0.8, '0xFFFF00' ],  [ 1.0, '0xFFFFFF' ] ],
+	"grayscale" : [ [ 0.0, '0x000000' ], [ 0.2, '0x404040' ], [ 0.5, '0x7F7F80' ], [ 0.8, '0xBFBFBF' ],  [ 1.0, '0xFFFFFF' ] ]
 
 };

+ 19 - 12
examples/js/modifiers/SubdivisionModifier.js

@@ -17,7 +17,7 @@
 
 THREE.SubdivisionModifier = function ( subdivisions ) {
 
-	this.subdivisions = (subdivisions === undefined ) ? 1 : subdivisions;
+	this.subdivisions = ( subdivisions === undefined ) ? 1 : subdivisions;
 
 };
 
@@ -27,7 +27,9 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 	var repeats = this.subdivisions;
 
 	while ( repeats -- > 0 ) {
+
 		this.smooth( geometry );
+
 	}
 
 	delete geometry.__tmpVertices;
@@ -37,10 +39,10 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 
 };
 
-(function() {
+( function() {
 
 	// Some constants
-	var WARNINGS = !true; // Set to true for development
+	var WARNINGS = ! true; // Set to true for development
 	var ABC = [ 'a', 'b', 'c' ];
 	
 
@@ -102,10 +104,13 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 		var i, il, face, edge;
 
 		for ( i = 0, il = vertices.length; i < il; i ++ ) {
+
 			metaVertices[ i ] = { edges: [] };
+
 		}
 		
 		for ( i = 0, il = faces.length; i < il; i ++ ) {
+
 			face = faces[ i ];
 
 			processEdge( face.a, face.b, vertices, edges, face, metaVertices );
@@ -113,6 +118,7 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 			processEdge( face.c, face.a, vertices, edges, face, metaVertices );
 
 		}
+
 	}
 
 	function newFace( newFaces, a, b, c ) {
@@ -150,7 +156,7 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 		metaVertices = new Array( oldVertices.length );
 		sourceEdges = {}; // Edge => { oldVertex1, oldVertex2, faces[]  }
 
-		generateLookups(oldVertices, oldFaces, metaVertices, sourceEdges);
+		generateLookups( oldVertices, oldFaces, metaVertices, sourceEdges );
 
 
 		/******************************************************
@@ -184,7 +190,7 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 
 				if ( connectedFaces != 1 ) {
 					
-					if (WARNINGS) console.warn('Subdivision Modifier: Number of connected faces != 2, is: ', connectedFaces, currentEdge);
+					if ( WARNINGS ) console.warn( 'Subdivision Modifier: Number of connected faces != 2, is: ', connectedFaces, currentEdge );
 			
 				}
 
@@ -200,8 +206,8 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 				
 				for ( k = 0; k < 3; k ++ ) {
 
-					other = oldVertices[ face[ ABC[k] ] ];
-					if (other !== currentEdge.a && other !== currentEdge.b ) break;
+					other = oldVertices[ face[ ABC[ k ] ] ];
+					if ( other !== currentEdge.a && other !== currentEdge.b ) break;
 
 				}
 
@@ -213,9 +219,10 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 			newEdge.add( tmp );
 
 			currentEdge.newEdge = newEdgeVertices.length;
-			newEdgeVertices.push(newEdge);
+			newEdgeVertices.push( newEdge );
 
 			// console.log(currentEdge, newEdge);
+
 		}
 
 		/******************************************************
@@ -261,7 +268,7 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 
 				if ( n == 2 ) {
 
-					if (WARNINGS) console.warn('2 connecting edges', connectingEdges);
+					if ( WARNINGS ) console.warn( '2 connecting edges', connectingEdges );
 					sourceVertexWeight = 3 / 4;
 					connectingVertexWeight = 1 / 8;
 
@@ -270,11 +277,11 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 
 				} else if ( n == 1 ) {
 
-					if (WARNINGS) console.warn('only 1 connecting edge');
+					if ( WARNINGS ) console.warn( 'only 1 connecting edge' );
 
 				} else if ( n == 0 ) {
 
-					if (WARNINGS) console.warn('0 connecting edges');
+					if ( WARNINGS ) console.warn( '0 connecting edges' );
 			
 				}
 			
@@ -340,4 +347,4 @@ THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
 	};
 
 
-})();
+} )();

+ 5 - 5
examples/js/objects/ShadowMesh.js

@@ -38,29 +38,29 @@ THREE.ShadowMesh.prototype.update = function () {
 		var dot = plane.normal.x * lightPosition4D.x +
 			  plane.normal.y * lightPosition4D.y +
 			  plane.normal.z * lightPosition4D.z +
-			  -plane.constant * lightPosition4D.w;
+			  - plane.constant * lightPosition4D.w;
 
 		var sme = shadowMatrix.elements;
 
 		sme[ 0 ]  = dot - lightPosition4D.x * plane.normal.x;
 		sme[ 4 ]  = - lightPosition4D.x * plane.normal.y;
 		sme[ 8 ]  = - lightPosition4D.x * plane.normal.z;
-		sme[ 12 ] = - lightPosition4D.x * -plane.constant;
+		sme[ 12 ] = - lightPosition4D.x * - plane.constant;
 
 		sme[ 1 ]  = - lightPosition4D.y * plane.normal.x;
 		sme[ 5 ]  = dot - lightPosition4D.y * plane.normal.y;
 		sme[ 9 ]  = - lightPosition4D.y * plane.normal.z;
-		sme[ 13 ] = - lightPosition4D.y * -plane.constant;
+		sme[ 13 ] = - lightPosition4D.y * - plane.constant;
 
 		sme[ 2 ]  = - lightPosition4D.z * plane.normal.x;
 		sme[ 6 ]  = - lightPosition4D.z * plane.normal.y;
 		sme[ 10 ] = dot - lightPosition4D.z * plane.normal.z;
-		sme[ 14 ] = - lightPosition4D.z * -plane.constant;
+		sme[ 14 ] = - lightPosition4D.z * - plane.constant;
 
 		sme[ 3 ]  = - lightPosition4D.w * plane.normal.x;
 		sme[ 7 ]  = - lightPosition4D.w * plane.normal.y;
 		sme[ 11 ] = - lightPosition4D.w * plane.normal.z;
-		sme[ 15 ] = dot - lightPosition4D.w * -plane.constant;
+		sme[ 15 ] = dot - lightPosition4D.w * - plane.constant;
 
 		this.matrix.multiplyMatrices( shadowMatrix, this.meshMatrix );
 

+ 62 - 11
examples/js/postprocessing/AdaptiveToneMappingPass.js

@@ -11,7 +11,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
 
 	this.resolution = ( resolution !== undefined ) ? resolution : 256;
 	this.needsInit = true;
-	this.adaptive = adaptive !== undefined ? !!adaptive : true;
+	this.adaptive = adaptive !== undefined ? !! adaptive : true;
 
 	this.luminanceRT = null;
 	this.previousLuminanceRT = null;
@@ -47,7 +47,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
 
 	this.adaptLuminanceShader = {
 		defines: {
-			"MIP_LEVEL_1X1" : ( Math.log( this.resolution ) / Math.log( 2.0 ) ).toFixed(1),
+			"MIP_LEVEL_1X1" : ( Math.log( this.resolution ) / Math.log( 2.0 ) ).toFixed( 1 ),
 		},
 		uniforms: {
 			"lastLum": { type: "t", value: null },
@@ -64,7 +64,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
 				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 
 			"}"
-		].join('\n'),
+		].join( '\n' ),
 		fragmentShader: [
 			"varying vec2 vUv;",
 
@@ -90,7 +90,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
 				// "fAdaptedLum = sqrt(fAdaptedLum);",
 				"gl_FragColor = vec4( vec3( fAdaptedLum ), 1.0 );",
 			"}",
-		].join('\n')
+		].join( '\n' )
 	};
 
 	this.materialAdaptiveLum = new THREE.ShaderMaterial( {
@@ -117,7 +117,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
 	this.needsSwap = true;
 	this.clear = false;
 
-	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene  = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
@@ -130,14 +130,17 @@ THREE.AdaptiveToneMappingPass.prototype = {
 	render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
 
 		if ( this.needsInit ) {
+
 			this.reset( renderer );
 			this.luminanceRT.type = readBuffer.type;
 			this.previousLuminanceRT.type = readBuffer.type;
 			this.currentLuminanceRT.type = readBuffer.type;
 			this.needsInit = false;
+
 		}
 
 		if ( this.adaptive ) {
+
 			//Render the luminance of the current scene into a render target with mipmapping enabled
 			this.quad.material = this.materialLuminance;
 			this.materialLuminance.uniforms.tDiffuse.value = readBuffer;
@@ -155,6 +158,7 @@ THREE.AdaptiveToneMappingPass.prototype = {
 			this.quad.material = this.materialCopy;
 			this.copyUniforms.tDiffuse.value = this.luminanceRT;
 			renderer.render( this.scene, this.camera, this.previousLuminanceRT );
+
 		}
 
 		this.quad.material = this.materialToneMap;
@@ -164,15 +168,22 @@ THREE.AdaptiveToneMappingPass.prototype = {
 	},
 
 	reset: function( renderer ) {
+
 		// render targets
 		if ( this.luminanceRT ) {
+
 			this.luminanceRT.dispose();
+
 		}
 		if ( this.currentLuminanceRT ) {
+
 			this.currentLuminanceRT.dispose();
+
 		}
 		if ( this.previousLuminanceRT ) {
+
 			this.previousLuminanceRT.dispose();
+
 		}
 		var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat };
 
@@ -186,79 +197,119 @@ THREE.AdaptiveToneMappingPass.prototype = {
 		this.currentLuminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
 
 		if ( this.adaptive ) {
-			this.materialToneMap.defines["ADAPTED_LUMINANCE"] = "";
+
+			this.materialToneMap.defines[ "ADAPTED_LUMINANCE" ] = "";
 			this.materialToneMap.uniforms.luminanceMap.value = this.luminanceRT;
+
 		}
 		//Put something in the adaptive luminance texture so that the scene can render initially
-		this.quad.material = new THREE.MeshBasicMaterial( { color: 0x777777 });
+		this.quad.material = new THREE.MeshBasicMaterial( { color: 0x777777 } );
 		this.materialLuminance.needsUpdate = true;
 		this.materialAdaptiveLum.needsUpdate = true;
 		this.materialToneMap.needsUpdate = true;
 		// renderer.render( this.scene, this.camera, this.luminanceRT );
 		// renderer.render( this.scene, this.camera, this.previousLuminanceRT );
 		// renderer.render( this.scene, this.camera, this.currentLuminanceRT );
+
 	},
 
 	setAdaptive: function( adaptive ) {
+
 		if ( adaptive ) {
+
 			this.adaptive = true;
-			this.materialToneMap.defines["ADAPTED_LUMINANCE"] = "";
+			this.materialToneMap.defines[ "ADAPTED_LUMINANCE" ] = "";
 			this.materialToneMap.uniforms.luminanceMap.value = this.luminanceRT;
-		}
-		else {
+
+		} else {
+
 			this.adaptive = false;
-			delete this.materialToneMap.defines["ADAPTED_LUMINANCE"];
+			delete this.materialToneMap.defines[ "ADAPTED_LUMINANCE" ];
 			this.materialToneMap.uniforms.luminanceMap.value = undefined;
+
 		}
 		this.materialToneMap.needsUpdate = true;
+
 	},
 
 	setAdaptionRate: function( rate ) {
+
 		if ( rate ) {
+
 			this.materialAdaptiveLum.uniforms.tau.value = Math.abs( rate );
+
 		}
+
 	},
 
 	setMaxLuminance: function( maxLum ) {
+
 		if ( maxLum ) {
+
 			this.materialToneMap.uniforms.maxLuminance.value = maxLum;
+
 		}
+
 	},
 
 	setAverageLuminance: function( avgLum ) {
+
 		if ( avgLum ) {
+
 			this.materialToneMap.uniforms.averageLuminance.value = avgLum;
+
 		}
+
 	},
 
 	setMiddleGrey: function( middleGrey ) {
+
 		if ( middleGrey ) {
+
 			this.materialToneMap.uniforms.middleGrey.value = middleGrey;
+
 		}
+
 	},
 
 	dispose: function() {
+
 		if ( this.luminanceRT ) {
+
 			this.luminanceRT.dispose();
+
 		}
 		if ( this.previousLuminanceRT ) {
+
 			this.previousLuminanceRT.dispose();
+
 		}
 		if ( this.currentLuminanceRT ) {
+
 			this.currentLuminanceRT.dispose();
+
 		}
 		if ( this.materialLuminance ) {
+
 			this.materialLuminance.dispose();
+
 		}
 		if ( this.materialAdaptiveLum ) {
+
 			this.materialAdaptiveLum.dispose();
+
 		}
 		if ( this.materialCopy ) {
+
 			this.materialCopy.dispose();
+
 		}
 		if ( this.materialToneMap ) {
+
 			this.materialToneMap.dispose();
+
 		}
+
 	}
 
 };

+ 1 - 1
examples/js/postprocessing/BloomPass.js

@@ -66,7 +66,7 @@ THREE.BloomPass = function ( strength, kernelSize, sigma, resolution ) {
 	this.clear = false;
 
 
-	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene  = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );

+ 5 - 3
examples/js/postprocessing/BokehPass.js

@@ -33,7 +33,9 @@ THREE.BokehPass = function ( scene, camera, params ) {
 	// bokeh material
 
 	if ( THREE.BokehShader === undefined ) {
+
 		console.error( "THREE.BokehPass relies on THREE.BokehShader" );
+
 	}
 	
 	var bokehShader = THREE.BokehShader;
@@ -46,11 +48,11 @@ THREE.BokehPass = function ( scene, camera, params ) {
 	bokehUniforms[ "aperture" ].value = aperture;
 	bokehUniforms[ "maxblur" ].value = maxblur;
 
-	this.materialBokeh = new THREE.ShaderMaterial({
+	this.materialBokeh = new THREE.ShaderMaterial( {
 		uniforms: bokehUniforms,
 		vertexShader: bokehShader.vertexShader,
 		fragmentShader: bokehShader.fragmentShader
-	});
+	} );
 
 	this.uniforms = bokehUniforms;
 	this.enabled = true;
@@ -58,7 +60,7 @@ THREE.BokehPass = function ( scene, camera, params ) {
 	this.renderToScreen = false;
 	this.clear = false;
 
-	this.camera2 = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera2 = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene2  = new THREE.Scene();
 
 	this.quad2 = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );

+ 3 - 3
examples/js/postprocessing/DotScreenPass.js

@@ -12,8 +12,8 @@ THREE.DotScreenPass = function ( center, angle, scale ) {
 	this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
 
 	if ( center !== undefined ) this.uniforms[ "center" ].value.copy( center );
-	if ( angle !== undefined ) this.uniforms[ "angle"].value = angle;
-	if ( scale !== undefined ) this.uniforms[ "scale"].value = scale;
+	if ( angle !== undefined ) this.uniforms[ "angle" ].value = angle;
+	if ( scale !== undefined ) this.uniforms[ "scale" ].value = scale;
 
 	this.material = new THREE.ShaderMaterial( {
 
@@ -28,7 +28,7 @@ THREE.DotScreenPass = function ( center, angle, scale ) {
 	this.needsSwap = true;
 
 
-	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene  = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );

+ 1 - 1
examples/js/postprocessing/EffectComposer.js

@@ -68,7 +68,7 @@ THREE.EffectComposer.prototype = {
 
 			pass = this.passes[ i ];
 
-			if ( !pass.enabled ) continue;
+			if ( ! pass.enabled ) continue;
 
 			pass.render( this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive );
 

+ 1 - 1
examples/js/postprocessing/FilmPass.js

@@ -29,7 +29,7 @@ THREE.FilmPass = function ( noiseIntensity, scanlinesIntensity, scanlinesCount,
 	this.needsSwap = true;
 
 
-	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene  = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );

+ 49 - 43
examples/js/postprocessing/GlitchPass.js

@@ -9,26 +9,26 @@ THREE.GlitchPass = function ( dt_size ) {
 	var shader = THREE.DigitalGlitch;
 	this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
 
-	if (dt_size == undefined) dt_size = 64;
+	if ( dt_size == undefined ) dt_size = 64;
 	
 	
-	this.uniforms[ "tDisp"].value = this.generateHeightmap(dt_size);
+	this.uniforms[ "tDisp" ].value = this.generateHeightmap( dt_size );
 	
 
-	this.material = new THREE.ShaderMaterial({
+	this.material = new THREE.ShaderMaterial( {
 		uniforms: this.uniforms,
 		vertexShader: shader.vertexShader,
 		fragmentShader: shader.fragmentShader
-	});
+	} );
 
-	console.log(this.material);
+	console.log( this.material );
 	
 	this.enabled = true;
 	this.renderToScreen = false;
 	this.needsSwap = true;
 
 
-	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene  = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
@@ -42,73 +42,79 @@ THREE.GlitchPass = function ( dt_size ) {
 
 THREE.GlitchPass.prototype = {
 
-	render: function ( renderer, writeBuffer, readBuffer, delta ) 
-	{
+	render: function ( renderer, writeBuffer, readBuffer, delta ) {
+
 		this.uniforms[ "tDiffuse" ].value = readBuffer;
 		this.uniforms[ 'seed' ].value = Math.random();//default seeding
 		this.uniforms[ 'byp' ].value = 0;
 		
-		if (this.curF % this.randX == 0 || this.goWild == true)
-		{
+		if ( this.curF % this.randX == 0 || this.goWild == true ) {
+
 			this.uniforms[ 'amount' ].value = Math.random() / 30;
-			this.uniforms[ 'angle' ].value = THREE.Math.randFloat(-Math.PI, Math.PI);
-			this.uniforms[ 'seed_x' ].value = THREE.Math.randFloat(-1, 1);
-			this.uniforms[ 'seed_y' ].value = THREE.Math.randFloat(-1, 1);
-			this.uniforms[ 'distortion_x' ].value = THREE.Math.randFloat(0, 1);
-			this.uniforms[ 'distortion_y' ].value = THREE.Math.randFloat(0, 1);
+			this.uniforms[ 'angle' ].value = THREE.Math.randFloat( - Math.PI, Math.PI );
+			this.uniforms[ 'seed_x' ].value = THREE.Math.randFloat( - 1, 1 );
+			this.uniforms[ 'seed_y' ].value = THREE.Math.randFloat( - 1, 1 );
+			this.uniforms[ 'distortion_x' ].value = THREE.Math.randFloat( 0, 1 );
+			this.uniforms[ 'distortion_y' ].value = THREE.Math.randFloat( 0, 1 );
 			this.curF = 0;
 			this.generateTrigger();
-		}
-		else if (this.curF % this.randX < this.randX / 5)
-		{
+
+		} else if ( this.curF % this.randX < this.randX / 5 ) {
+
 			this.uniforms[ 'amount' ].value = Math.random() / 90;
-			this.uniforms[ 'angle' ].value = THREE.Math.randFloat(-Math.PI, Math.PI);
-			this.uniforms[ 'distortion_x' ].value = THREE.Math.randFloat(0, 1);
-			this.uniforms[ 'distortion_y' ].value = THREE.Math.randFloat(0, 1);
-			this.uniforms[ 'seed_x' ].value = THREE.Math.randFloat(-0.3, 0.3);
-			this.uniforms[ 'seed_y' ].value = THREE.Math.randFloat(-0.3, 0.3);
-		}
-		else if (this.goWild == false)
-		{
+			this.uniforms[ 'angle' ].value = THREE.Math.randFloat( - Math.PI, Math.PI );
+			this.uniforms[ 'distortion_x' ].value = THREE.Math.randFloat( 0, 1 );
+			this.uniforms[ 'distortion_y' ].value = THREE.Math.randFloat( 0, 1 );
+			this.uniforms[ 'seed_x' ].value = THREE.Math.randFloat( - 0.3, 0.3 );
+			this.uniforms[ 'seed_y' ].value = THREE.Math.randFloat( - 0.3, 0.3 );
+
+		} else if ( this.goWild == false ) {
+
 			this.uniforms[ 'byp' ].value = 1;
+
 		}
 		this.curF ++;
 		
 		this.quad.material = this.material;
-		if ( this.renderToScreen ) 
-		{
+		if ( this.renderToScreen ) {
+
 			renderer.render( this.scene, this.camera );
-		} 
-		else 
-		{
+
+		} else {
+
 			renderer.render( this.scene, this.camera, writeBuffer, false );
+
 		}
+
 	},
-	generateTrigger:function()
-	{
-		this.randX = THREE.Math.randInt(120, 240);
+	generateTrigger: function() {
+
+		this.randX = THREE.Math.randInt( 120, 240 );
+
 	},
-	generateHeightmap:function(dt_size)
-	{
+	generateHeightmap: function( dt_size ) {
+
 		var data_arr = new Float32Array( dt_size * dt_size * 3 );
-		console.log(dt_size);
+		console.log( dt_size );
 		var length = dt_size * dt_size;
 		
-		for ( var i = 0; i < length; i ++) 
-		{
-			var val = THREE.Math.randFloat(0, 1);
+		for ( var i = 0; i < length; i ++ ) {
+
+			var val = THREE.Math.randFloat( 0, 1 );
 			data_arr[ i * 3 + 0 ] = val;
 			data_arr[ i * 3 + 1 ] = val;
 			data_arr[ i * 3 + 2 ] = val;
+
 		}
 		
 		var texture = new THREE.DataTexture( data_arr, dt_size, dt_size, THREE.RGBFormat, THREE.FloatType );
-		console.log(texture);
-		console.log(dt_size);
+		console.log( texture );
+		console.log( dt_size );
 		texture.minFilter = THREE.NearestFilter;
 		texture.magFilter = THREE.NearestFilter;
 		texture.needsUpdate = true;
 		texture.flipY = false;
 		return texture;
+
 	}
-};
+};

+ 1 - 1
examples/js/postprocessing/SavePass.js

@@ -35,7 +35,7 @@ THREE.SavePass = function ( renderTarget ) {
 	this.clear = false;
 
 
-	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene  = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );

+ 2 - 2
examples/js/postprocessing/ShaderPass.js

@@ -10,7 +10,7 @@ THREE.ShaderPass = function ( shader, textureID ) {
 
 	this.material = new THREE.ShaderMaterial( {
 
-        	defines: shader.defines || {},
+		defines: shader.defines || {},
 		uniforms: this.uniforms,
 		vertexShader: shader.vertexShader,
 		fragmentShader: shader.fragmentShader
@@ -24,7 +24,7 @@ THREE.ShaderPass = function ( shader, textureID ) {
 	this.clear = false;
 
 
-	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene  = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );

+ 1 - 1
examples/js/postprocessing/TexturePass.js

@@ -26,7 +26,7 @@ THREE.TexturePass = function ( texture, opacity ) {
 	this.needsSwap = false;
 
 
-	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
+	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
 	this.scene  = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );

+ 74 - 68
examples/js/renderers/CanvasRenderer.js

@@ -22,8 +22,7 @@ THREE.SpriteCanvasMaterial.prototype.clone = function () {
 
 	var material = new THREE.SpriteCanvasMaterial();
 
-	THREE.Material.prototype.clone.call( this, material );
-
+	material.copy( this );
 	material.color.copy( this.color );
 	material.program = this.program;
 
@@ -145,7 +144,19 @@ THREE.CanvasRenderer = function ( parameters ) {
 	this.supportsVertexTextures = function () {};
 	this.setFaceCulling = function () {};
 
-	//
+	// API
+
+	this.getContext = function () {
+
+		return _context;
+
+	};
+
+	this.getContextAttributes = function () {
+
+		return _context.getContextAttributes();
+
+	};
 
 	this.getPixelRatio = function () {
 
@@ -177,7 +188,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 		}
 
-		_clipBox.min.set( -_canvasWidthHalf, -_canvasHeightHalf );
+		_clipBox.min.set( - _canvasWidthHalf, - _canvasHeightHalf );
 		_clipBox.max.set(   _canvasWidthHalf,   _canvasHeightHalf );
 
 		_clearBox.min.set( - _canvasWidthHalf, - _canvasHeightHalf );
@@ -507,53 +518,42 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 			var texture = material.map;
 
-			if ( texture !== null && texture.image !== undefined ) {
-
-				if ( texture.hasEventListener( 'update', onTextureUpdate ) === false ) {
-
-					if ( texture.image.width > 0 ) {
-
-						textureToPattern( texture );
-
-					}
-
-					texture.addEventListener( 'update', onTextureUpdate );
-
-				}
+			if ( texture !== null ) {
 
 				var pattern = _patterns[ texture.id ];
 
-				if ( pattern !== undefined ) {
+				if ( pattern === undefined || pattern.version !== texture.version ) {
 
-					setFillStyle( pattern );
+					pattern = textureToPattern( texture );
+					_patterns[ texture.id ] = pattern;
 
-				} else {
+				}
 
-					setFillStyle( 'rgba( 0, 0, 0, 1 )' );
+				if ( pattern.canvas !== undefined ) {
 
-				}
+					setFillStyle( pattern.canvas );
 
-				//
+					var bitmap = texture.image;
 
-				var bitmap = texture.image;
+					var ox = bitmap.width * texture.offset.x;
+					var oy = bitmap.height * texture.offset.y;
 
-				var ox = bitmap.width * texture.offset.x;
-				var oy = bitmap.height * texture.offset.y;
+					var sx = bitmap.width * texture.repeat.x;
+					var sy = bitmap.height * texture.repeat.y;
 
-				var sx = bitmap.width * texture.repeat.x;
-				var sy = bitmap.height * texture.repeat.y;
+					var cx = scaleX / sx;
+					var cy = scaleY / sy;
 
-				var cx = scaleX / sx;
-				var cy = scaleY / sy;
+					_context.save();
+					_context.translate( v1.x, v1.y );
+					if ( material.rotation !== 0 ) _context.rotate( material.rotation );
+					_context.translate( - scaleX / 2, - scaleY / 2 );
+					_context.scale( cx, cy );
+					_context.translate( - ox, - oy );
+					_context.fillRect( ox, oy, sx, sy );
+					_context.restore();
 
-				_context.save();
-				_context.translate( v1.x, v1.y );
-				if ( material.rotation !== 0 ) _context.rotate( material.rotation );
-				_context.translate( - scaleX / 2, - scaleY / 2 );
-				_context.scale( cx, cy );
-				_context.translate( - ox, - oy );
-				_context.fillRect( ox, oy, sx, sy );
-				_context.restore();
+				}
 
 			} else {
 
@@ -822,18 +822,18 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 	}
 
-	function onTextureUpdate ( event ) {
-
-		textureToPattern( event.target );
-
-	}
-
 	function textureToPattern( texture ) {
 
-		if ( texture instanceof THREE.CompressedTexture ) return;
+		if ( texture.version === 0 ||
+			texture instanceof THREE.CompressedTexture ||
+			texture instanceof THREE.DataTexture ) {
 
-		var repeatX = texture.wrapS === THREE.RepeatWrapping;
-		var repeatY = texture.wrapT === THREE.RepeatWrapping;
+			return {
+					canvas: undefined,
+					version: texture.version
+				}
+
+		}
 
 		var image = texture.image;
 
@@ -845,45 +845,51 @@ THREE.CanvasRenderer = function ( parameters ) {
 		context.setTransform( 1, 0, 0, - 1, 0, image.height );
 		context.drawImage( image, 0, 0 );
 
-		_patterns[ texture.id ] = _context.createPattern(
-			canvas, repeatX === true && repeatY === true
-				 ? 'repeat'
-				 : repeatX === true && repeatY === false
-					 ? 'repeat-x'
-					 : repeatX === false && repeatY === true
-						 ? 'repeat-y'
-						 : 'no-repeat'
-		);
+		var repeatX = texture.wrapS === THREE.RepeatWrapping;
+		var repeatY = texture.wrapT === THREE.RepeatWrapping;
 
-	}
+		var repeat = 'no-repeat';
 
-	function patternPath( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, texture ) {
+		if ( repeatX === true && repeatY === true ) {
 
-		if ( texture instanceof THREE.DataTexture ) return;
+			repeat = 'repeat';
 
-		if ( texture.hasEventListener( 'update', onTextureUpdate ) === false ) {
+		} else if ( repeatX === true ) {
 
-			if ( texture.image !== undefined && texture.image.width > 0 ) {
+			repeat = 'repeat-x';
 
-				textureToPattern( texture );
+		} else if ( repeatY === true ) {
 
-			}
+			repeat = 'repeat-y';
 
-			texture.addEventListener( 'update', onTextureUpdate );
+		}
 
+		return {
+			canvas: _context.createPattern( canvas, repeat ),
+			version: texture.version
 		}
 
+	}
+
+	function patternPath( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, texture ) {
+
 		var pattern = _patterns[ texture.id ];
 
-		if ( pattern !== undefined ) {
+		if ( pattern === undefined || pattern.version !== texture.version ) {
+
+			pattern = textureToPattern( texture );
+			_patterns[ texture.id ] = pattern;
+
+		}
+
+		if ( pattern.canvas !== undefined ) {
 
-			setFillStyle( pattern );
+			setFillStyle( pattern.canvas );
 
 		} else {
 
-			setFillStyle( 'rgba(0,0,0,1)' );
+			setFillStyle( 'rgba( 0, 0, 0, 1)' );
 			_context.fill();
-
 			return;
 
 		}

+ 4 - 2
examples/js/renderers/Projector.js

@@ -517,7 +517,7 @@ THREE.Projector = function () {
 						var face = faces[ f ];
 
 						material = isFaceMaterial === true
-							 ? objectMaterials.materials[ face.materialIndex ]
+							 ? objectMaterials.materials[ 0 ] // objectMaterials.materials[ face.materialIndex ]
 							 : object.material;
 
 						if ( material === undefined ) continue;
@@ -533,8 +533,10 @@ THREE.Projector = function () {
 						var visible = renderList.checkBackfaceCulling( v1, v2, v3 );
 
 						if ( side !== THREE.DoubleSide ) {
+
 							if ( side === THREE.FrontSide && visible === false ) continue;
 							if ( side === THREE.BackSide && visible === true ) continue;
+
 						}
 
 						_face = getNextFaceInPool();
@@ -825,7 +827,7 @@ THREE.Projector = function () {
 
 	function painterSort( a, b ) {
 
-		if ( a.renderOrder !== b.renderOrder) {
+		if ( a.renderOrder !== b.renderOrder ) {
 
 			return a.renderOrder - b.renderOrder;
 

+ 1 - 1
examples/js/renderers/RaytracingRenderer.js

@@ -543,4 +543,4 @@ THREE.RaytracingRenderer = function ( parameters ) {
 
 };
 
-THREE.EventDispatcher.prototype.apply(THREE.RaytracingRenderer.prototype);
+THREE.EventDispatcher.prototype.apply( THREE.RaytracingRenderer.prototype );

+ 6 - 6
examples/js/renderers/SVGRenderer.js

@@ -20,7 +20,7 @@ THREE.SVGRenderer = function () {
 	var _this = this,
 	_renderData, _elements, _lights,
 	_projector = new THREE.Projector(),
-	_svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
+	_svg = document.createElementNS( 'http://www.w3.org/2000/svg', 'svg' ),
 	_svgWidth, _svgHeight, _svgWidthHalf, _svgHeightHalf,
 
 	_v1, _v2, _v3, _v4,
@@ -68,7 +68,7 @@ THREE.SVGRenderer = function () {
 
 	this.setQuality = function( quality ) {
 
-		switch (quality) {
+		switch ( quality ) {
 
 			case "high": _quality = 1; break;
 			case "low": _quality = 0; break;
@@ -181,9 +181,9 @@ THREE.SVGRenderer = function () {
 
 				_v1 = element.v1; _v2 = element.v2; _v3 = element.v3;
 
-				if ( _v1.positionScreen.z < -1 || _v1.positionScreen.z > 1 ) continue;
-				if ( _v2.positionScreen.z < -1 || _v2.positionScreen.z > 1 ) continue;
-				if ( _v3.positionScreen.z < -1 || _v3.positionScreen.z > 1 ) continue;
+				if ( _v1.positionScreen.z < - 1 || _v1.positionScreen.z > 1 ) continue;
+				if ( _v2.positionScreen.z < - 1 || _v2.positionScreen.z > 1 ) continue;
+				if ( _v3.positionScreen.z < - 1 || _v3.positionScreen.z > 1 ) continue;
 
 				_v1.positionScreen.x *= _svgWidthHalf; _v1.positionScreen.y *= - _svgHeightHalf;
 				_v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= - _svgHeightHalf;
@@ -385,7 +385,7 @@ THREE.SVGRenderer = function () {
 
 		} else if ( material instanceof THREE.MeshDepthMaterial ) {
 
-			_w = 1 - ( material.__2near / (material.__farPlusNear - element.z * material.__farMinusNear) );
+			_w = 1 - ( material.__2near / ( material.__farPlusNear - element.z * material.__farMinusNear ) );
 			_color.setRGB( _w, _w, _w );
 
 		} else if ( material instanceof THREE.MeshNormalMaterial ) {

+ 234 - 127
examples/js/renderers/SoftwareRenderer.js

@@ -32,14 +32,14 @@ THREE.SoftwareRenderer = function ( parameters ) {
 	var imagedata, data, zbuffer;
 	var numBlocks, blockMaxZ, blockFlags;
 
-	var BLOCK_ISCLEAR = (1 << 0);
-	var BLOCK_NEEDCLEAR = (1 << 1);
+	var BLOCK_ISCLEAR = ( 1 << 0 );
+	var BLOCK_NEEDCLEAR = ( 1 << 1 );
 
 	var subpixelBits = 4;
-	var subpixelBias = (1 << subpixelBits) - 1;
+	var subpixelBias = ( 1 << subpixelBits ) - 1;
 	var blockShift = 3;
 	var blockSize = 1 << blockShift;
-	var maxZVal = (1 << 24); // Note: You want to size this so you don't get overflows.
+	var maxZVal = ( 1 << 24 ); // Note: You want to size this so you don't get overflows.
 
 	var rectx1 = Infinity, recty1 = Infinity;
 	var rectx2 = 0, recty2 = 0;
@@ -70,6 +70,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 		clearColor.set( color );
 		cleanColorBuffer();
+
 	};
 
 	this.setPixelRatio = function () {};
@@ -84,7 +85,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
 		var fixScale = 1 << subpixelBits;
 
 		viewportXScale =  fixScale * canvasWidth  / 2;
-		viewportYScale = -fixScale * canvasHeight / 2;
+		viewportYScale = - fixScale * canvasHeight / 2;
 		viewportZScale =             maxZVal      / 2;
 
 		viewportXOffs  =  fixScale * canvasWidth  / 2 + 0.5;
@@ -134,7 +135,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
 		for ( var i = 0; i < numBlocks; i ++ ) {
 
 			blockMaxZ[ i ] = maxZVal;
-			blockFlags[ i ] = (blockFlags[ i ] & BLOCK_ISCLEAR) ? BLOCK_ISCLEAR : BLOCK_NEEDCLEAR;
+			blockFlags[ i ] = ( blockFlags[ i ] & BLOCK_ISCLEAR ) ? BLOCK_ISCLEAR : BLOCK_NEEDCLEAR;
 
 		}
 
@@ -155,7 +156,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 			if ( element instanceof THREE.RenderableFace ) {
 
-				if ( !element.uvs ) {
+				if ( ! element.uvs ) {
 
 					drawTriangle(
 						element.v1.positionScreen,
@@ -164,15 +165,17 @@ THREE.SoftwareRenderer = function ( parameters ) {
 						null, null, null,
 						shader, element, material
 					);
+
 				} else {
 
 					drawTriangle(
 						element.v1.positionScreen,
 						element.v2.positionScreen,
 						element.v3.positionScreen,
-						element.uvs[0], element.uvs[1], element.uvs[2],
+						element.uvs[ 0 ], element.uvs[ 1 ], element.uvs[ 2 ],
 						shader, element, material
 					);
+
 				}
 
 
@@ -289,53 +292,64 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 		var size = canvasWidth * canvasHeight * 4;
 
-		for ( var i = 0; i < size; i+=4 ) {
+		for ( var i = 0; i < size; i += 4 ) {
 
 			data[ i ] = clearColor.r * 255 | 0;
 			data[ i + 1 ] = clearColor.g * 255 | 0;
 			data[ i + 2 ] = clearColor.b * 255 | 0;
 			data[ i + 3 ] = 255;
+
 		}
 
 		context.fillStyle = clearColor.getStyle();
 		context.fillRect( 0, 0, canvasWidth, canvasHeight );
+
 	}
 
 	function getPalette( material, bSimulateSpecular ) {
+
 		var i = 0, j = 0;
 		var diffuseR = material.color.r * 255;
 		var diffuseG = material.color.g * 255;
 		var diffuseB = material.color.b * 255;
-		var palette = new Uint8Array(256 * 3);
+		var palette = new Uint8Array( 256 * 3 );
 
 		if ( bSimulateSpecular ) {
 
-			while (i < 204) {
-				palette[j ++] = Math.min( i * diffuseR / 204, 255 );
-				palette[j ++] = Math.min( i * diffuseG / 204, 255 );
-				palette[j ++] = Math.min( i * diffuseB / 204, 255 );
+			while ( i < 204 ) {
+
+				palette[ j ++ ] = Math.min( i * diffuseR / 204, 255 );
+				palette[ j ++ ] = Math.min( i * diffuseG / 204, 255 );
+				palette[ j ++ ] = Math.min( i * diffuseB / 204, 255 );
 				++ i;
+
 			}
 
-			while (i < 256) { // plus specular highlight
-				palette[j ++] = Math.min( diffuseR + (i - 204) * (255 - diffuseR) / 82, 255 );
-				palette[j ++] = Math.min( diffuseG + (i - 204) * (255 - diffuseG) / 82, 255 );
-				palette[j ++] = Math.min( diffuseB + (i - 204) * (255 - diffuseB) / 82, 255 );
+			while ( i < 256 ) {
+
+				// plus specular highlight
+				palette[ j ++ ] = Math.min( diffuseR + ( i - 204 ) * ( 255 - diffuseR ) / 82, 255 );
+				palette[ j ++ ] = Math.min( diffuseG + ( i - 204 ) * ( 255 - diffuseG ) / 82, 255 );
+				palette[ j ++ ] = Math.min( diffuseB + ( i - 204 ) * ( 255 - diffuseB ) / 82, 255 );
 				++ i;
+
 			}
 
 		} else {
 
-			while (i < 256) {
-				palette[j ++] = Math.min( i * diffuseR / 255, 255 );
-				palette[j ++] = Math.min( i * diffuseG / 255, 255 );
-				palette[j ++] = Math.min( i * diffuseB / 255, 255 );
+			while ( i < 256 ) {
+
+				palette[ j ++ ] = Math.min( i * diffuseR / 255, 255 );
+				palette[ j ++ ] = Math.min( i * diffuseG / 255, 255 );
+				palette[ j ++ ] = Math.min( i * diffuseB / 255, 255 );
 				++ i;
+
 			}
 
 		}
 
 		return palette;
+
 	}
 
 	function basicMaterialShader( buffer, depthBuf, offset, depth, u, v, n, face, material ) {
@@ -344,35 +358,41 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 		var texture = textures[ material.map.id ];
 
-		if ( !texture.data )
+		if ( ! texture.data )
 			return;
 
 		var tdim = texture.width;
 		var isTransparent = material.transparent;
 		var tbound = tdim - 1;
 		var tdata = texture.data;
-		var tIndex = (((v * tdim) & tbound) * tdim + ((u * tdim) & tbound)) * 4;
+		var tIndex = ( ( ( v * tdim ) & tbound ) * tdim + ( ( u * tdim ) & tbound ) ) * 4;
+
+		if ( ! isTransparent ) {
 
-		if ( !isTransparent ) {
-			buffer[ colorOffset ] = tdata[tIndex];
-			buffer[ colorOffset + 1 ] = tdata[tIndex + 1];
-			buffer[ colorOffset + 2 ] = tdata[tIndex + 2];
+			buffer[ colorOffset ] = tdata[ tIndex ];
+			buffer[ colorOffset + 1 ] = tdata[ tIndex + 1 ];
+			buffer[ colorOffset + 2 ] = tdata[ tIndex + 2 ];
 			buffer[ colorOffset + 3 ] = material.opacity * 255;
 			depthBuf[ offset ] = depth;
-		}
-		else {
-			var opaci = tdata[tIndex + 3] * material.opacity;
-			var texel = (tdata[tIndex] << 16) + (tdata[tIndex + 1] << 8) + tdata[tIndex + 2];
-			if (opaci < 250) {
-				var backColor = (buffer[colorOffset] << 16) + (buffer[colorOffset + 1] << 8) + buffer[colorOffset + 2];
-				texel = texel * opaci + backColor * (1 - opaci);
+
+		} else {
+
+			var opaci = tdata[ tIndex + 3 ] * material.opacity;
+			var texel = ( tdata[ tIndex ] << 16 ) + ( tdata[ tIndex + 1 ] << 8 ) + tdata[ tIndex + 2 ];
+			if ( opaci < 250 ) {
+
+				var backColor = ( buffer[ colorOffset ] << 16 ) + ( buffer[ colorOffset + 1 ] << 8 ) + buffer[ colorOffset + 2 ];
+				texel = texel * opaci + backColor * ( 1 - opaci );
+
 			}
 
-			buffer[ colorOffset ] = (texel & 0xff0000) >> 16;
-			buffer[ colorOffset + 1 ] = (texel & 0xff00) >> 8;
+			buffer[ colorOffset ] = ( texel & 0xff0000 ) >> 16;
+			buffer[ colorOffset + 1 ] = ( texel & 0xff00 ) >> 8;
 			buffer[ colorOffset + 2 ] = texel & 0xff;
 			buffer[ colorOffset + 3 ] = material.opacity * 255;
+
 		}
+
 	}
 
 	function lightingMaterialShader( buffer, depthBuf, offset, depth, u, v, n, face, material ) {
@@ -381,37 +401,43 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 		var texture = textures[ material.map.id ];
 
-		if ( !texture.data )
+		if ( ! texture.data )
 			return;
 
 		var tdim = texture.width;
 		var isTransparent = material.transparent;
-		var cIndex = (n > 0 ? (~~n) : 0) * 3;
+		var cIndex = ( n > 0 ? ( ~~ n ) : 0 ) * 3;
 		var tbound = tdim - 1;
 		var tdata = texture.data;
-		var tIndex = (((v * tdim) & tbound) * tdim + ((u * tdim) & tbound)) * 4;
+		var tIndex = ( ( ( v * tdim ) & tbound ) * tdim + ( ( u * tdim ) & tbound ) ) * 4;
+
+		if ( ! isTransparent ) {
 
-		if ( !isTransparent ) {
-			buffer[ colorOffset ] = (material.palette[cIndex] * tdata[tIndex]) >> 8;
-			buffer[ colorOffset + 1 ] = (material.palette[cIndex + 1] * tdata[tIndex + 1]) >> 8;
-			buffer[ colorOffset + 2 ] = (material.palette[cIndex + 2] * tdata[tIndex + 2]) >> 8;
+			buffer[ colorOffset ] = ( material.palette[ cIndex ] * tdata[ tIndex ] ) >> 8;
+			buffer[ colorOffset + 1 ] = ( material.palette[ cIndex + 1 ] * tdata[ tIndex + 1 ] ) >> 8;
+			buffer[ colorOffset + 2 ] = ( material.palette[ cIndex + 2 ] * tdata[ tIndex + 2 ] ) >> 8;
 			buffer[ colorOffset + 3 ] = material.opacity * 255;
 			depthBuf[ offset ] = depth;
+
 		} else {
-			var opaci = tdata[tIndex + 3] * material.opacity;
-			var foreColor = ((material.palette[cIndex] * tdata[tIndex]) << 16)
-							+ ((material.palette[cIndex + 1] * tdata[tIndex + 1]) << 8 )
-							+ (material.palette[cIndex + 2] * tdata[tIndex + 2]);
 
-			if (opaci < 250) {
+			var opaci = tdata[ tIndex + 3 ] * material.opacity;
+			var foreColor = ( ( material.palette[ cIndex ] * tdata[ tIndex ] ) << 16 )
+							+ ( ( material.palette[ cIndex + 1 ] * tdata[ tIndex + 1 ] ) << 8 )
+							+ ( material.palette[ cIndex + 2 ] * tdata[ tIndex + 2 ] );
+
+			if ( opaci < 250 ) {
+
 				var backColor = buffer[ colorOffset ] << 24 + buffer[ colorOffset + 1 ] << 16 + buffer[ colorOffset + 2 ] << 8;
-				foreColor = foreColor * opaci + backColor * (1 - opaci);
+				foreColor = foreColor * opaci + backColor * ( 1 - opaci );
+
 			}
 
-			buffer[ colorOffset ] = (foreColor & 0xff0000) >> 16;
-			buffer[ colorOffset + 1 ] = (foreColor & 0xff00) >> 8;
-			buffer[ colorOffset + 2 ] = (foreColor & 0xff);
+			buffer[ colorOffset ] = ( foreColor & 0xff0000 ) >> 16;
+			buffer[ colorOffset + 1 ] = ( foreColor & 0xff00 ) >> 8;
+			buffer[ colorOffset + 2 ] = ( foreColor & 0xff );
 			buffer[ colorOffset + 3 ] = material.opacity * 255;
+
 		}
 
 	}
@@ -441,16 +467,23 @@ THREE.SoftwareRenderer = function ( parameters ) {
 				 material instanceof THREE.SpriteMaterial ) {
 
 				if ( material instanceof THREE.MeshLambertMaterial ) {
+
 					// Generate color palette
-					if ( !material.palette ) {
+					if ( ! material.palette ) {
+
 						material.palette = getPalette( material, false );
+
 					}
 
 				} else if ( material instanceof THREE.MeshPhongMaterial ) {
+
 					// Generate color palette
-					if ( !material.palette ) {
+					if ( ! material.palette ) {
+
 						material.palette = getPalette( material, true );
+
 					}
+
 				}
 
 				var string;
@@ -472,9 +505,11 @@ THREE.SoftwareRenderer = function ( parameters ) {
 						|| material instanceof THREE.SpriteMaterial ) {
 
 						shader = basicMaterialShader;
+
 					} else {
 
 						shader = lightingMaterialShader;
+
 					}
 
 
@@ -489,7 +524,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
 							'buffer[ colorOffset + 2 ] = face.color.b * 255;',
 							'buffer[ colorOffset + 3 ] = material.opacity * 255;',
 							'depthBuf[ offset ] = depth;'
-						].join('\n');
+						].join( '\n' );
 
 					} else {
 
@@ -500,11 +535,12 @@ THREE.SoftwareRenderer = function ( parameters ) {
 							'buffer[ colorOffset + 2 ] = material.color.b * 255;',
 							'buffer[ colorOffset + 3 ] = material.opacity * 255;',
 							'depthBuf[ offset ] = depth;'
-						].join('\n');
+						].join( '\n' );
 
 					}
 
 					shader = new Function( 'buffer, depthBuf, offset, depth, u, v, n, face, material', string );
+
 				}
 
 			} else {
@@ -516,7 +552,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
 					'buffer[ colorOffset + 2 ] = 0;',
 					'buffer[ colorOffset + 3 ] = 255;',
 					'depthBuf[ offset ] = depth;'
-				].join('\n');
+				].join( '\n' );
 
 				shader = new Function( 'buffer, depthBuf, offset, depth, u, v', string );
 
@@ -558,32 +594,33 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 		// TODO: Implement per-pixel z-clipping
 
-		if ( v1.z < -1 || v1.z > 1 || v2.z < -1 || v2.z > 1 || v3.z < -1 || v3.z > 1 ) return;
+		if ( v1.z < - 1 || v1.z > 1 || v2.z < - 1 || v2.z > 1 || v3.z < - 1 || v3.z > 1 ) return;
 
 		// https://gist.github.com/2486101
 		// explanation: http://pouet.net/topic.php?which=8760&page=1
 
 		// 28.4 fixed-point coordinates
 
-		var x1 = (v1.x * viewportXScale + viewportXOffs) | 0;
-		var x2 = (v2.x * viewportXScale + viewportXOffs) | 0;
-		var x3 = (v3.x * viewportXScale + viewportXOffs) | 0;
+		var x1 = ( v1.x * viewportXScale + viewportXOffs ) | 0;
+		var x2 = ( v2.x * viewportXScale + viewportXOffs ) | 0;
+		var x3 = ( v3.x * viewportXScale + viewportXOffs ) | 0;
 
-		var y1 = (v1.y * viewportYScale + viewportYOffs) | 0;
-		var y2 = (v2.y * viewportYScale + viewportYOffs) | 0;
-		var y3 = (v3.y * viewportYScale + viewportYOffs) | 0;
+		var y1 = ( v1.y * viewportYScale + viewportYOffs ) | 0;
+		var y2 = ( v2.y * viewportYScale + viewportYOffs ) | 0;
+		var y3 = ( v3.y * viewportYScale + viewportYOffs ) | 0;
 
 		// Z values (.28 fixed-point)
 
-		var z1 = (v1.z * viewportZScale + viewportZOffs) | 0;
-		var z2 = (v2.z * viewportZScale + viewportZOffs) | 0;
-		var z3 = (v3.z * viewportZScale + viewportZOffs) | 0;
+		var z1 = ( v1.z * viewportZScale + viewportZOffs ) | 0;
+		var z2 = ( v2.z * viewportZScale + viewportZOffs ) | 0;
+		var z3 = ( v3.z * viewportZScale + viewportZOffs ) | 0;
 
 		// UV values
 		var bHasUV = false;
 		var tu1, tv1, tu2, tv2, tu3, tv3;
 
 		if ( uv1 && uv2 && uv3 ) {
+
 			bHasUV = true;
 
 			tu1 = uv1.x;
@@ -592,6 +629,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
 			tv2 = 1 - uv2.y;
 			tu3 = uv3.x;
 			tv3 = 1 - uv3.y;
+
 		}
 
 		// Normal values
@@ -599,14 +637,16 @@ THREE.SoftwareRenderer = function ( parameters ) {
 		var n1, n2, n3, nz1, nz2, nz3;
 
 		if ( face.vertexNormalsModel ) {
+
 			bHasNormal = true;
 
-			n1 = face.vertexNormalsModel[0];
-			n2 = face.vertexNormalsModel[1];
-			n3 = face.vertexNormalsModel[2];
+			n1 = face.vertexNormalsModel[ 0 ];
+			n2 = face.vertexNormalsModel[ 1 ];
+			n3 = face.vertexNormalsModel[ 2 ];
 			nz1 = n1.z * 255;
 			nz2 = n2.z * 255;
 			nz3 = n3.z * 255;
+
 		}
 
 		// Deltas
@@ -633,17 +673,17 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 		// Start in corner of 8x8 block
 
-		minx &= ~(q - 1);
-		miny &= ~(q - 1);
+		minx &= ~ ( q - 1 );
+		miny &= ~ ( q - 1 );
 
 		// Constant part of half-edge functions
 
-		var minXfixscale = (minx << subpixelBits);
-		var minYfixscale = (miny << subpixelBits);
+		var minXfixscale = ( minx << subpixelBits );
+		var minYfixscale = ( miny << subpixelBits );
 
-		var c1 = dy12 * ((minXfixscale) - x1) + dx12 * ((minYfixscale) - y1);
-		var c2 = dy23 * ((minXfixscale) - x2) + dx23 * ((minYfixscale) - y2);
-		var c3 = dy31 * ((minXfixscale) - x3) + dx31 * ((minYfixscale) - y3);
+		var c1 = dy12 * ( ( minXfixscale ) - x1 ) + dx12 * ( ( minYfixscale ) - y1 );
+		var c2 = dy23 * ( ( minXfixscale ) - x2 ) + dx23 * ( ( minYfixscale ) - y2 );
+		var c3 = dy31 * ( ( minXfixscale ) - x3 ) + dx31 * ( ( minYfixscale ) - y3 );
 
 		// Correct for fill convention
 
@@ -653,61 +693,65 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 		// Note this doesn't kill subpixel precision, but only because we test for >=0 (not >0).
 		// It's a bit subtle. :)
-		c1 = (c1 - 1) >> subpixelBits;
-		c2 = (c2 - 1) >> subpixelBits;
-		c3 = (c3 - 1) >> subpixelBits;
+		c1 = ( c1 - 1 ) >> subpixelBits;
+		c2 = ( c2 - 1 ) >> subpixelBits;
+		c3 = ( c3 - 1 ) >> subpixelBits;
 
 		// Z interpolation setup
 
 		var dz12 = z1 - z2, dz31 = z3 - z1;
-		var invDet = 1.0 / (dx12 * dy31 - dx31 * dy12);
-		var dzdx = (invDet * (dz12 * dy31 - dz31 * dy12)); // dz per one subpixel step in x
-		var dzdy = (invDet * (dz12 * dx31 - dx12 * dz31)); // dz per one subpixel step in y
+		var invDet = 1.0 / ( dx12 * dy31 - dx31 * dy12 );
+		var dzdx = ( invDet * ( dz12 * dy31 - dz31 * dy12 ) ); // dz per one subpixel step in x
+		var dzdy = ( invDet * ( dz12 * dx31 - dx12 * dz31 ) ); // dz per one subpixel step in y
 
 		// Z at top/left corner of rast area
 
-		var cz = ( z1 + ((minXfixscale) - x1) * dzdx + ((minYfixscale) - y1) * dzdy ) | 0;
+		var cz = ( z1 + ( ( minXfixscale ) - x1 ) * dzdx + ( ( minYfixscale ) - y1 ) * dzdy ) | 0;
 
 		// Z pixel steps
 
-		var fixscale = (1 << subpixelBits);
-		dzdx = (dzdx * fixscale) | 0;
-		dzdy = (dzdy * fixscale) | 0;
+		var fixscale = ( 1 << subpixelBits );
+		dzdx = ( dzdx * fixscale ) | 0;
+		dzdy = ( dzdy * fixscale ) | 0;
 
 		var dtvdx, dtvdy, cbtu, cbtv;
 		if ( bHasUV ) {
+
 			// UV interpolation setup
 			var dtu12 = tu1 - tu2, dtu31 = tu3 - tu1;
-			var dtudx = (invDet * (dtu12 * dy31 - dtu31 * dy12)); // dtu per one subpixel step in x
-			var dtudy = (invDet * (dtu12 * dx31 - dx12 * dtu31)); // dtu per one subpixel step in y
+			var dtudx = ( invDet * ( dtu12 * dy31 - dtu31 * dy12 ) ); // dtu per one subpixel step in x
+			var dtudy = ( invDet * ( dtu12 * dx31 - dx12 * dtu31 ) ); // dtu per one subpixel step in y
 			var dtv12 = tv1 - tv2, dtv31 = tv3 - tv1;
-			dtvdx = (invDet * (dtv12 * dy31 - dtv31 * dy12)); // dtv per one subpixel step in x
-			dtvdy = (invDet * (dtv12 * dx31 - dx12 * dtv31)); // dtv per one subpixel step in y
+			dtvdx = ( invDet * ( dtv12 * dy31 - dtv31 * dy12 ) ); // dtv per one subpixel step in x
+			dtvdy = ( invDet * ( dtv12 * dx31 - dx12 * dtv31 ) ); // dtv per one subpixel step in y
 
 			// UV at top/left corner of rast area
-			cbtu = ( tu1 + (minXfixscale - x1) * dtudx + (minYfixscale - y1) * dtudy );
-			cbtv = ( tv1 + (minXfixscale - x1) * dtvdx + (minYfixscale - y1) * dtvdy );
+			cbtu = ( tu1 + ( minXfixscale - x1 ) * dtudx + ( minYfixscale - y1 ) * dtudy );
+			cbtv = ( tv1 + ( minXfixscale - x1 ) * dtvdx + ( minYfixscale - y1 ) * dtvdy );
 
 			// UV pixel steps
 			dtudx = dtudx * fixscale;
 			dtudy = dtudy * fixscale;
 			dtvdx = dtvdx * fixscale;
 			dtvdy = dtvdy * fixscale;
+
 		}
 
 		var dnxdx, dnzdy, cbnz;
 		if ( bHasNormal ) {
+
 			 // Normal interpolation setup
 			var dnz12 = nz1 - nz2, dnz31 = nz3 - nz1;
-			var dnzdx = (invDet * (dnz12 * dy31 - dnz31 * dy12)); // dnz per one subpixel step in x
-			var dnzdy = (invDet * (dnz12 * dx31 - dx12 * dnz31)); // dnz per one subpixel step in y
+			var dnzdx = ( invDet * ( dnz12 * dy31 - dnz31 * dy12 ) ); // dnz per one subpixel step in x
+			var dnzdy = ( invDet * ( dnz12 * dx31 - dx12 * dnz31 ) ); // dnz per one subpixel step in y
 
 			// Normal at top/left corner of rast area
-			cbnz = ( nz1 + (minXfixscale - x1) * dnzdx + (minYfixscale - y1) * dnzdy );
+			cbnz = ( nz1 + ( minXfixscale - x1 ) * dnzdx + ( minYfixscale - y1 ) * dnzdy );
 
 			// Normal pixel steps
-			dnzdx = (dnzdx * fixscale);
-			dnzdy = (dnzdy * fixscale);
+			dnzdx = ( dnzdx * fixscale );
+			dnzdy = ( dnzdy * fixscale );
+
 		}
 
 		// Set up min/max corners
@@ -716,24 +760,24 @@ THREE.SoftwareRenderer = function ( parameters ) {
 		var nmin2 = 0, nmax2 = 0;
 		var nmin3 = 0, nmax3 = 0;
 		var nminz = 0, nmaxz = 0;
-		if (dx12 >= 0) nmax1 -= qm1 * dx12; else nmin1 -= qm1 * dx12;
-		if (dy12 >= 0) nmax1 -= qm1 * dy12; else nmin1 -= qm1 * dy12;
-		if (dx23 >= 0) nmax2 -= qm1 * dx23; else nmin2 -= qm1 * dx23;
-		if (dy23 >= 0) nmax2 -= qm1 * dy23; else nmin2 -= qm1 * dy23;
-		if (dx31 >= 0) nmax3 -= qm1 * dx31; else nmin3 -= qm1 * dx31;
-		if (dy31 >= 0) nmax3 -= qm1 * dy31; else nmin3 -= qm1 * dy31;
-		if (dzdx >= 0) nmaxz += qm1 * dzdx; else nminz += qm1 * dzdx;
-		if (dzdy >= 0) nmaxz += qm1 * dzdy; else nminz += qm1 * dzdy;
+		if ( dx12 >= 0 ) nmax1 -= qm1 * dx12; else nmin1 -= qm1 * dx12;
+		if ( dy12 >= 0 ) nmax1 -= qm1 * dy12; else nmin1 -= qm1 * dy12;
+		if ( dx23 >= 0 ) nmax2 -= qm1 * dx23; else nmin2 -= qm1 * dx23;
+		if ( dy23 >= 0 ) nmax2 -= qm1 * dy23; else nmin2 -= qm1 * dy23;
+		if ( dx31 >= 0 ) nmax3 -= qm1 * dx31; else nmin3 -= qm1 * dx31;
+		if ( dy31 >= 0 ) nmax3 -= qm1 * dy31; else nmin3 -= qm1 * dy31;
+		if ( dzdx >= 0 ) nmaxz += qm1 * dzdx; else nminz += qm1 * dzdx;
+		if ( dzdy >= 0 ) nmaxz += qm1 * dzdy; else nminz += qm1 * dzdy;
 
 		// Loop through blocks
 		var linestep = canvasWidth - q;
-		var scale = 1.0 / (c1 + c2 + c3);
+		var scale = 1.0 / ( c1 + c2 + c3 );
 
 		var cb1 = c1;
 		var cb2 = c2;
 		var cb3 = c3;
 		var cbz = cz;
-		var qstep = -q;
+		var qstep = - q;
 		var e1x = qstep * dy12;
 		var e2x = qstep * dy23;
 		var e3x = qstep * dy31;
@@ -741,13 +785,17 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 		var etux, etvx;
 		if ( bHasUV ) {
+
 			etux = qstep * dtudx;
 			etvx = qstep * dtvdx;
+
 		}
 
 		var enzx;
 		if ( bHasNormal ) {
+
 			enzx = qstep * dnzdx;
+
 		}
 
 		var x0 = minx;
@@ -764,30 +812,38 @@ THREE.SoftwareRenderer = function ( parameters ) {
 				cbz += ezx;
 
 				if ( bHasUV ) {
+
 					cbtu += etux;
 					cbtv += etvx;
+
 				}
 
 				if ( bHasNormal ) {
+
 					cbnz += enzx;
+
 				}
 
 			}
 
 			// Okay, we're now in a block we know is outside. Reverse direction and go into main loop.
-			qstep = -qstep;
-			e1x = -e1x;
-			e2x = -e2x;
-			e3x = -e3x;
-			ezx = -ezx;
+			qstep = - qstep;
+			e1x = - e1x;
+			e2x = - e2x;
+			e3x = - e3x;
+			ezx = - ezx;
 
 			if ( bHasUV ) {
-				etux = -etux;
-				etvx = -etvx;
+
+				etux = - etux;
+				etvx = - etvx;
+
 			}
 
 			if ( bHasNormal ) {
-				enzx = -enzx;
+
+				enzx = - enzx;
+
 			}
 
 			while ( 1 ) {
@@ -800,21 +856,25 @@ THREE.SoftwareRenderer = function ( parameters ) {
 				cbz += ezx;
 
 				if ( bHasUV ) {
+
 					cbtu += etux;
 					cbtv += etvx;
+
 				}
 
 				if ( bHasNormal ) {
+
 					cbnz += enzx;
+
 				}
 
 				// We're done with this block line when at least one edge completely out
 				// If an edge function is too small and decreasing in the current traversal
 				// dir, we're done with this line.
-				if (x0 < minx || x0 >= maxx) break;
-				if (cb1 < nmax1) if (e1x < 0) break; else continue;
-				if (cb2 < nmax2) if (e2x < 0) break; else continue;
-				if (cb3 < nmax3) if (e3x < 0) break; else continue;
+				if ( x0 < minx || x0 >= maxx ) break;
+				if ( cb1 < nmax1 ) if ( e1x < 0 ) break; else continue;
+				if ( cb2 < nmax2 ) if ( e2x < 0 ) break; else continue;
+				if ( cb3 < nmax3 ) if ( e3x < 0 ) break; else continue;
 
 				// We can skip this block if it's already fully covered
 				var blockX = x0 >> blockShift;
@@ -827,8 +887,8 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 				// Need to do a deferred clear?
 				var bflags = blockFlags[ blockId ];
-				if ( bflags & BLOCK_NEEDCLEAR) clearBlock( blockX, blockY );
-				blockFlags[ blockId ] = bflags & ~( BLOCK_ISCLEAR | BLOCK_NEEDCLEAR );
+				if ( bflags & BLOCK_NEEDCLEAR ) clearBlock( blockX, blockY );
+				blockFlags[ blockId ] = bflags & ~ ( BLOCK_ISCLEAR | BLOCK_NEEDCLEAR );
 
 				// Offset at top-left corner
 				var offset = x0 + y0 * canvasWidth;
@@ -845,13 +905,17 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 					var cytu, cytv;
 					if ( bHasUV ) {
+
 						cytu = cbtu;
 						cytv = cbtv;
+
 					}
 
 					var cynz;
 					if ( bHasNormal ) {
+
 						cynz = cbnz;
+
 					}
 
 
@@ -864,13 +928,17 @@ THREE.SoftwareRenderer = function ( parameters ) {
 						var cxtu;
 						var cxtv;
 						if ( bHasUV ) {
+
 							cxtu = cytu;
 							cxtv = cytv;
+
 						}
 
 						var cxnz;
 						if ( bHasNormal ) {
+
 							cxnz = cynz;
+
 						}
 
 						for ( var ix = 0; ix < q; ix ++ ) {
@@ -878,7 +946,9 @@ THREE.SoftwareRenderer = function ( parameters ) {
 							var z = cxz;
 
 							if ( z < zbuffer[ offset ] ) {
+
 								shader( data, zbuffer, offset, z, cxtu, cxtv, cxnz, face, material );
+
 							}
 
 							cx1 += dy12;
@@ -886,12 +956,16 @@ THREE.SoftwareRenderer = function ( parameters ) {
 							cxz += dzdx;
 
 							if ( bHasUV ) {
+
 								cxtu += dtudx;
 								cxtv += dtvdx;
+
 							}
 
 							if ( bHasNormal ) {
+
 								cxnz += dnzdx;
+
 							}
 
 							offset ++;
@@ -903,19 +977,25 @@ THREE.SoftwareRenderer = function ( parameters ) {
 						cyz += dzdy;
 
 						if ( bHasUV ) {
+
 							cytu += dtudy;
 							cytv += dtvdy;
+
 						}
 
 						if ( bHasNormal ) {
+
 							cynz += dnzdy;
+
 						}
 
 						offset += linestep;
 
 					}
 
-				} else { // Partially covered block
+				} else {
+
+					// Partially covered block
 
 					var cy1 = cb1;
 					var cy2 = cb2;
@@ -924,13 +1004,17 @@ THREE.SoftwareRenderer = function ( parameters ) {
 
 					var cytu, cytv;
 					if ( bHasUV ) {
+
 						cytu = cbtu;
 						cytv = cbtv;
+
 					}
 
 					var cynz;
 					if ( bHasNormal ) {
+
 						cynz = cbnz;
+
 					}
 
 					for ( var iy = 0; iy < q; iy ++ ) {
@@ -943,13 +1027,17 @@ THREE.SoftwareRenderer = function ( parameters ) {
 						var cxtu;
 						var cxtv;
 						if ( bHasUV ) {
+
 							cxtu = cytu;
 							cxtv = cytv;
+
 						}
 
 						var cxnz;
 						if ( bHasNormal ) {
+
 							cxnz = cynz;
+
 						}
 
 						for ( var ix = 0; ix < q; ix ++ ) {
@@ -959,7 +1047,9 @@ THREE.SoftwareRenderer = function ( parameters ) {
 								var z = cxz;
 
 								if ( z < zbuffer[ offset ] ) {
+
 									shader( data, zbuffer, offset, z, cxtu, cxtv, cxnz, face, material );
+
 								}
 
 							}
@@ -970,12 +1060,16 @@ THREE.SoftwareRenderer = function ( parameters ) {
 							cxz += dzdx;
 
 							if ( bHasUV ) {
+
 								cxtu += dtudx;
 								cxtv += dtvdx;
+
 							}
 
 							if ( bHasNormal ) {
+
 								cxnz += dnzdx;
+
 							}
 
 							offset ++;
@@ -988,12 +1082,16 @@ THREE.SoftwareRenderer = function ( parameters ) {
 						cyz += dzdy;
 
 						if ( bHasUV ) {
+
 							cytu += dtudy;
 							cytv += dtvdy;
+
 						}
 
 						if ( bHasNormal ) {
+
 							cynz += dnzdy;
+
 						}
 
 						offset += linestep;
@@ -1011,12 +1109,16 @@ THREE.SoftwareRenderer = function ( parameters ) {
 			cbz += q * dzdy;
 
 			if ( bHasUV ) {
+
 				cbtu += q * dtudy;
 				cbtv += q * dtvdy;
+
 			}
 
 			if ( bHasNormal ) {
+
 				cbnz += q * dnzdy;
+
 			}
 
 		}
@@ -1067,6 +1169,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
 				}
 
 				block ++;
+
 			}
 
 		}
@@ -1081,7 +1184,7 @@ THREE.SoftwareRenderer.Texture = function() {
 
 	this.fromImage = function( image ) {
 
-		if ( !image || image.width <= 0 || image.height <= 0 )
+		if ( ! image || image.width <= 0 || image.height <= 0 )
 			return;
 
 		if ( canvas === undefined ) {
@@ -1093,12 +1196,14 @@ THREE.SoftwareRenderer.Texture = function() {
 		var size = image.width > image.height ? image.width : image.height;
 		size = THREE.Math.nextPowerOfTwo( size );
 
-		if ( canvas.width != size || canvas.height != size) {
+		if ( canvas.width != size || canvas.height != size ) {
+
 			canvas.width = size;
 			canvas.height = size;
+
 		}
 
-		var ctx = canvas.getContext('2d');
+		var ctx = canvas.getContext( '2d' );
 		ctx.clearRect( 0, 0, size, size );
 		ctx.drawImage( image, 0, 0, size, size );
 
@@ -1108,5 +1213,7 @@ THREE.SoftwareRenderer.Texture = function() {
 		this.width = size;
 		this.height = size;
 		this.srcUrl = image.src;
+
 	};
+
 };

Некоторые файлы не были показаны из-за большого количества измененных файлов