2
0
Эх сурвалжийг харах

Merge branch 'dev' of https://github.com/mrdoob/three.js into dev

Zelimir Fedoran 12 жил өмнө
parent
commit
2b0fab2232
85 өөрчлөгдсөн 7555 нэмэгдсэн , 1479 устгасан
  1. 975 79
      build/three.js
  2. 154 134
      build/three.min.js
  3. 11 14
      docs/api/extras/core/Curve.html
  4. 2 2
      docs/api/extras/geometries/ExtrudeGeometry.html
  5. 1 1
      docs/api/extras/geometries/IcosahedronGeometry.html
  6. 1 1
      docs/api/extras/geometries/LatheGeometry.html
  7. 1 1
      docs/api/extras/geometries/OctahedronGeometry.html
  8. 1 1
      docs/api/extras/geometries/PlaneGeometry.html
  9. 1 1
      docs/api/extras/geometries/PolyhedronGeometry.html
  10. 1 1
      docs/api/extras/geometries/TetrahedronGeometry.html
  11. 1 1
      docs/api/extras/geometries/TextGeometry.html
  12. 1 1
      docs/api/extras/geometries/TorusGeometry.html
  13. 1 1
      docs/api/extras/geometries/TorusKnotGeometry.html
  14. 5 4
      docs/api/extras/modifiers/SubdivisionModifier.html
  15. 1 1
      docs/api/extras/objects/LensFlare.html
  16. 4 2
      docs/api/materials/ShaderMaterial.html
  17. 1 1
      docs/api/textures/DataTexture.html
  18. 1 1
      docs/api/textures/Texture.html
  19. 36 4
      docs/index.html
  20. 5 1
      editor/js/ui/Viewport.js
  21. 0 417
      examples/js/DeferredHelper.js
  22. 260 146
      examples/js/ShaderDeferred.js
  23. 12 12
      examples/js/UVsUtils.js
  24. 2 2
      examples/js/loaders/ColladaLoader.js
  25. 1 1
      examples/js/loaders/OBJLoader.js
  26. 1 1
      examples/js/loaders/OBJMTLLoader.js
  27. 4 4
      examples/js/loaders/UTF8Loader.js
  28. 3 3
      examples/js/loaders/ctm/CTMLoader.js
  29. 22 10
      examples/js/postprocessing/EffectComposer.js
  30. 5 5
      examples/js/renderers/CSS3DRenderer.js
  31. 1 1
      examples/js/renderers/DOMRenderer.js
  32. 574 0
      examples/js/renderers/WebGLDeferredRenderer.js
  33. 45 38
      examples/webgl_lights_deferred_morphs.html
  34. 80 39
      examples/webgl_lights_deferred_pointlights.html
  35. 3 6
      examples/webgl_marching_cubes.html
  36. 4 7
      examples/webgl_materials_cubemap_dynamic.html
  37. 2 2
      examples/webgl_materials_video.html
  38. 8 10
      examples/webgl_postprocessing.html
  39. 3 6
      examples/webgl_shading_physical.html
  40. 276 0
      src/core/Box2.js
  41. 301 0
      src/core/Box3.js
  42. 19 18
      src/core/Frustum.js
  43. 8 77
      src/core/Geometry.js
  44. 160 0
      src/core/Plane.js
  45. 140 0
      src/core/Sphere.js
  46. 2 41
      src/core/UV.js
  47. 89 0
      src/core/Vector2.js
  48. 91 2
      src/core/Vector3.js
  49. 157 1
      src/core/Vector4.js
  50. 12 18
      src/extras/GeometryUtils.js
  51. 10 22
      src/extras/core/Curve.js
  52. 2 2
      src/extras/geometries/CircleGeometry.js
  53. 1 1
      src/extras/geometries/ConvexGeometry.js
  54. 4 4
      src/extras/geometries/CubeGeometry.js
  55. 3 3
      src/extras/geometries/CylinderGeometry.js
  56. 11 11
      src/extras/geometries/ExtrudeGeometry.js
  57. 5 5
      src/extras/geometries/LatheGeometry.js
  58. 4 4
      src/extras/geometries/ParametricGeometry.js
  59. 4 4
      src/extras/geometries/PlaneGeometry.js
  60. 3 3
      src/extras/geometries/PolyhedronGeometry.js
  61. 1 1
      src/extras/geometries/SphereGeometry.js
  62. 1 1
      src/extras/geometries/TorusGeometry.js
  63. 4 4
      src/extras/geometries/TorusKnotGeometry.js
  64. 4 4
      src/extras/geometries/TubeGeometry.js
  65. 19 19
      src/extras/modifiers/SubdivisionModifier.js
  66. 7 7
      src/loaders/BinaryLoader.js
  67. 2 2
      src/loaders/JSONLoader.js
  68. 6 0
      src/loaders/Loader.js
  69. 257 240
      src/loaders/SceneLoader.js
  70. 2 2
      src/renderers/WebGLRenderTarget.js
  71. 14 14
      src/renderers/WebGLRenderer.js
  72. 4 7
      src/renderers/WebGLShaders.js
  73. 266 0
      test/core/Box2.js
  74. 262 0
      test/core/Box3.js
  75. 22 0
      test/core/Constants.js
  76. 96 0
      test/core/Plane.js
  77. 39 0
      test/core/Sphere.js
  78. 220 0
      test/core/Vector2.js
  79. 256 0
      test/core/Vector3.js
  80. 296 0
      test/core/Vector4.js
  81. 25 0
      test/index.html
  82. 235 0
      test/qunit/qunit-1.10.0.css
  83. 1977 0
      test/qunit/qunit-1.10.0.js
  84. 4 0
      utils/includes/common.json
  85. 0 0
      utils/servers/nodejs_server.sh

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 975 - 79
build/three.js


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 154 - 134
build/three.min.js


+ 11 - 14
docs/api/extras/core/Curve.html

@@ -9,7 +9,7 @@
 	<body>
 		<h1>[name]</h1>
 
-		<div class="desc">todo</div>
+		<div class="desc">An extensible curve object which contains methods for interpolation</div>
 
 
 		<h2>Constructor</h2>
@@ -25,37 +25,34 @@
 		<h2>Methods</h2>
 
 		<h3>.getPoint ( t )</h3>
-		<div>todo</div>
+		<div>Returns a vector for point t of the curve where t is between 0 and 1</div>
 
 		<h3>.getPointAt ( u )</h3>
-		<div>todo</div>
+		<div>Returns a vector for point at relative position in curve according to arc length</div>
 
 		<h3>.getPoints ( divisions )</h3>
-		<div>todo</div>
+		<div>Get sequence of points using getPoint( t ) </div>
 
 		<h3>.getSpacedPoints ( divisions )</h3>
-		<div>todo</div>
+		<div>Get sequence of equi-spaced points using getPointAt( u )</div>
 
 		<h3>.getLength ()</h3>
-		<div>todo</div>
+		<div>Get total curve arc length</div>
 
 		<h3>.getLengths ( divisions )</h3>
-		<div>todo</div>
+		<div>Get list of cumulative segment lengths</div>
 
 		<h3>.updateArcLengths ()</h3>
-		<div>todo</div>
+		<div>Update the cumlative segment distance cache</div>
 
 		<h3>.getUtoTmapping ( u, distance )</h3>
-		<div>todo</div>
-
-		<h3>.getNormalVector ( t )</h3>
-		<div>todo</div>
+		<div>Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equi distance</div>
 
 		<h3>.getTangent ( t )</h3>
-		<div>todo</div>
+		<div>Returns a unit vector tangent at t. If the subclassed curve do not implement its tangent derivation, 2 points a small delta apart will be used to find its gradient which seems to give a reasonable approximation</div>
 
 		<h3>.getTangentAt ( u )</h3>
-		<div>todo</div>
+		<div>Returns tangent at equidistance point u on the curve</div>
 
 
 		<h2>Source</h2>

+ 2 - 2
docs/api/extras/geometries/ExtrudeGeometry.html

@@ -9,12 +9,12 @@
 	<body>
 		<h1>[name]</h1>
 
-		<div class="desc">todo</div>
+		<div class="desc">Creates extruded geometry from a path shape</div>
 
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( shapes, options )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/IcosahedronGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( radius, detail )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/LatheGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( points, steps, angle )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/OctahedronGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( radius, detail )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/PlaneGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( width, height, widthSegments, heightSegments )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/PolyhedronGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( vertices, faces, radius, detail )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/TetrahedronGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( radius, detail )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/TextGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( text, parameters )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/TorusGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( radius, tube, radialSegments, tubularSegments, arc )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/extras/geometries/TorusKnotGeometry.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( radius, tube, radialSegments, tubularSegments, arc )</h3>
 
 
 		<h2>Properties</h2>

+ 5 - 4
docs/api/extras/modifiers/SubdivisionModifier.html

@@ -9,17 +9,18 @@
 	<body>
 		<h1>[name]</h1>
 
-		<div class="desc">todo</div>
+		<div class="desc">Applies Catmull-Clark Subdivision Surfaces for creating smooth geometry meshes</div>
 
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( subdivisions )</h3>
 
 
 		<h2>Properties</h2>
 
 		<h3>.subdivisions</h3>
+		<div>Number of time subdivision will be applied</div>
 
 		<h3>.useOldVertexColors</h3>
 
@@ -30,10 +31,10 @@
 		<h2>Methods</h2>
 
 		<h3>.modify ( geometry )</h3>
-		<div>todo</div>
+		<div>Modifies the geometry by running subdivision surfaces. This calls .smooth() internally</div>
 
 		<h3>.smooth ( oldGeometry )</h3>
-		<div>todo</div>
+		<div>Performs an iteration of Catmull-Clark Subdivision</div>
 
 
 

+ 1 - 1
docs/api/extras/objects/LensFlare.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( texture, size, distance, blending, color )</h3>
 
 
 		<h2>Properties</h2>

+ 4 - 2
docs/api/materials/ShaderMaterial.html

@@ -11,12 +11,14 @@
 
 		<h1>[name]</h1>
 
-		<div class="desc">todo</div>
+		<div class="desc">Material rendered with custom shaders</div>
 
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( parameters )
+
+</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/textures/DataTexture.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy )</h3>
 
 
 		<h2>Properties</h2>

+ 1 - 1
docs/api/textures/Texture.html

@@ -14,7 +14,7 @@
 
 		<h2>Constructor</h2>
 
-		<h3>[name]()</h3>
+		<h3>[name]( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy )</h3>
 
 
 		<h2>Properties</h2>

+ 36 - 4
docs/index.html

@@ -104,6 +104,9 @@
 
 			var html = '<h1><a href="http://threejs.org">three.js</a><span style="font-size: 50%; vertical-align: super;"> r' + REVISION + '</span></h1>';
 
+			var DELIMITER = '/';
+			var nameCategoryMap = {};
+
 			for ( var section in list ) {
 
 				html += '<h2>' + section + '</h2>';
@@ -122,6 +125,12 @@
 
 						html += '<li><a href="javascript:goTo(\'' + section + '\', \'' + category + '\', \'' + page[ 0 ] + '\')">' + page[ 0 ] + '</a></li>';
 
+						nameCategoryMap[page[0]] = {
+							section: section,
+							category: category,
+							name: page[0]
+						};
+
 					}
 
 					html += '</ul>';
@@ -134,13 +143,36 @@
 
 			panel.innerHTML += html;
 
+			function encodeUrl( path ) {
+
+				return path.replace(/\ \/\ /g, '.').replace(/\ /g, '_');
+
+			}
+
+			function decodeUrl( path ) {
+
+				return path.replace(/_/g, ' ').replace(/\./g, ' / ');
+
+			}
+
 			// Page loading
 
 			function goTo( section, category, name ) {
 
-				window.document.title = 'three.js - documentation - ' + section + ' - ' + name;
+				// Fully resolve links that only provide a name
+				if(arguments.length == 1) {
+					var location = nameCategoryMap[section];
+					section = location.section;
+					category = location.category;
+					name = location.name;
+				}
+
+				var title = 'three.js - documentation - ' + section + ' - ' + name;
+				var url = encodeUrl(section) + DELIMITER + encodeUrl( category ) + DELIMITER + encodeUrl(name);
+
+				window.location.hash = url;
+				window.document.title = title;
 
-				window.location.hash = section + '/' + category + '/' + name.replace(/\ /g, '-');
 
 				viewer.src = pages[ section ][ category ][ name ] + '.html';
 
@@ -148,8 +180,8 @@
 
 			function goToHash() {
 
-				var hash = window.location.hash.substring( 1 ).split('/');
-				goTo( hash[0], hash[1], hash[2].replace(/\-/g, ' ') );
+				var hash = window.location.hash.substring( 1 ).split(DELIMITER);
+				goTo( decodeUrl(hash[0]), decodeUrl(hash[1]), decodeUrl(hash[2]) );
 
 			}
 

+ 5 - 1
editor/js/ui/Viewport.js

@@ -714,7 +714,7 @@ var Viewport = function ( signals ) {
 		defaultScene.add( defaultCamera );
 
 		signals.sceneAdded.dispatch( defaultScene, defaultCamera, defaultBgColor );
-		signals.objectSelected.dispatch( defaultScene.properties.defaultSelection );
+		signals.objectSelected.dispatch( defaultCamera );
 
 	} );
 
@@ -872,6 +872,8 @@ var Viewport = function ( signals ) {
 
 		var scene = new THREE.Scene();
 
+		/*
+
 		// create lights
 
 		var light1 = new THREE.DirectionalLight( 0xffffff, 0.8 );
@@ -925,6 +927,8 @@ var Viewport = function ( signals ) {
 		scene.add( light4 );
 		scene.add( mesh );
 
+		*/
+
 		return scene;
 
 	}

+ 0 - 417
examples/js/DeferredHelper.js

@@ -1,417 +0,0 @@
-/**
- * @author alteredq / http://alteredqualia.com/
- * @author MPanknin / http://www.redplant.de/
- */
-
-THREE.DeferredHelper = function ( parameters ) {
-
-	var width = parameters.width;
-	var height = parameters.height;
-
-	var scene = parameters.scene;
-	var camera = parameters.camera;
-	var renderer = parameters.renderer;
-
-	// scene for light proxy geometry
-
-	var lightScene = new THREE.Scene();
-	lightNode = new THREE.Object3D();
-	lightScene.add( lightNode );
-
-	// scene for the coloured emitter spheres
-
-	var emitterScene = new THREE.Scene();
-	emitterNode = new THREE.Object3D();
-	emitterScene.add( emitterNode );
-
-	//
-
-	var black = new THREE.Color( 0x000000 );
-
-	var colorShader = THREE.ShaderDeferred[ "color" ];
-	var normalShader = THREE.ShaderDeferred[ "normals" ];
-	var bumpShader = THREE.ShaderDeferred[ "bump" ];
-	var clipDepthShader = THREE.ShaderDeferred[ "clipDepth" ];
-
-	//
-
-	var unlitShader = THREE.ShaderDeferred[ "unlit" ];
-	var lightShader = THREE.ShaderDeferred[ "light" ];
-	var compositeShader = THREE.ShaderDeferred[ "composite" ];
-
-	unlitShader.uniforms[ "viewWidth" ].value = width;
-	unlitShader.uniforms[ "viewHeight" ].value = height;
-
-	lightShader.uniforms[ "viewWidth" ].value = width;
-	lightShader.uniforms[ "viewHeight" ].value = height;
-
-	//
-
-	var compColor, compNormal, compDepth, compLightBuffer, compFinal, compEmitter, compositePass;
-
-	//
-
-	var defaultNormalMaterial = new THREE.ShaderMaterial( {
-
-		uniforms:       THREE.UniformsUtils.clone( normalShader.uniforms ),
-		vertexShader:   normalShader.vertexShader,
-		fragmentShader: normalShader.fragmentShader
-
-	} );
-
-	var defaultDepthMaterial = new THREE.ShaderMaterial( {
-
-		uniforms:       THREE.UniformsUtils.clone( clipDepthShader.uniforms ),
-		vertexShader:   clipDepthShader.vertexShader,
-		fragmentShader: clipDepthShader.fragmentShader
-
-	} );
-
-	//
-
-	var rtParamsFloatLinear = { minFilter: THREE.NearestFilter, magFilter: THREE.LinearFilter, stencilBuffer: false,
-								format: THREE.RGBAFormat, type: THREE.FloatType };
-
-	var rtParamsFloatNearest = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, stencilBuffer: false,
-								 format: THREE.RGBAFormat, type: THREE.FloatType };
-
-	var rtParamsUByte = { minFilter: THREE.NearestFilter, magFilter: THREE.LinearFilter, stencilBuffer: false,
-						  format: THREE.RGBFormat, type: THREE.UnsignedByteType };
-
-	//
-
-	this.addDeferredMaterials = function ( object ) {
-
-		object.traverse( function( node ) {
-
-			if ( !node.material ) return;
-
-			var originalMaterial = node.material;
-
-			// color material
-			// 	diffuse color
-			//	specular color
-			//	shininess
-			//	diffuse map
-			//	vertex colors
-			//	alphaTest
-			// 	morphs
-
-			var uniforms = THREE.UniformsUtils.clone( colorShader.uniforms );
-			var defines = { "USE_MAP": !! originalMaterial.map, "GAMMA_INPUT": true };
-
-			var material = new THREE.ShaderMaterial( {
-
-				fragmentShader: colorShader.fragmentShader,
-				vertexShader: 	colorShader.vertexShader,
-				uniforms: 		uniforms,
-				defines: 		defines,
-				shading:		originalMaterial.shading
-
-			} );
-
-			var diffuse = originalMaterial.color;
-			var specular = originalMaterial.specular !== undefined ? originalMaterial.specular : black;
-			var shininess = originalMaterial.shininess !== undefined ? originalMaterial.shininess : 1;
-
-			uniforms.diffuse.value.copy( diffuse );
-			uniforms.specular.value.copy( specular );
-			uniforms.shininess.value = shininess;
-
-			uniforms.map.value = originalMaterial.map;
-
-			material.vertexColors = originalMaterial.vertexColors;
-			material.morphTargets = originalMaterial.morphTargets;
-			material.morphNormals = originalMaterial.morphNormals;
-
-			material.alphaTest = originalMaterial.alphaTest;
-
-			if ( originalMaterial.bumpMap ) {
-
-				var offset = originalMaterial.bumpMap.offset;
-				var repeat = originalMaterial.bumpMap.repeat;
-
-				uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
-
-			}
-
-			node.properties.colorMaterial = material;
-
-			// normal material
-			//	vertex normals
-			//	morph normals
-			//	bump map
-			//	bump scale
-
-			if ( originalMaterial.bumpMap ) {
-
-				var uniforms = THREE.UniformsUtils.clone( bumpShader.uniforms );
-
-				var normalMaterial = new THREE.ShaderMaterial( {
-
-					uniforms: 		uniforms,
-					vertexShader: 	bumpShader.vertexShader,
-					fragmentShader: bumpShader.fragmentShader,
-					defines:		{ "USE_BUMPMAP": true }
-
-				} );
-
-				uniforms.bumpMap.value = originalMaterial.bumpMap;
-				uniforms.bumpScale.value = originalMaterial.bumpScale;
-
-				var offset = originalMaterial.bumpMap.offset;
-				var repeat = originalMaterial.bumpMap.repeat;
-
-				uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
-
-				node.properties.normalMaterial = normalMaterial;
-
-			} else if ( originalMaterial.morphTargets ) {
-
-				var normalMaterial = new THREE.ShaderMaterial( {
-
-					uniforms:       THREE.UniformsUtils.clone( normalShader.uniforms ),
-					vertexShader:   normalShader.vertexShader,
-					fragmentShader: normalShader.fragmentShader,
-					shading:		originalMaterial.shading
-
-				} );
-
-				normalMaterial.morphTargets = originalMaterial.morphTargets;
-				normalMaterial.morphNormals = originalMaterial.morphNormals;
-
-				node.properties.normalMaterial = normalMaterial;
-
-			} else {
-
-				node.properties.normalMaterial = defaultNormalMaterial;
-
-			}
-
-			// depth material
-
-			if ( originalMaterial.morphTargets ) {
-
-				var depthMaterial = new THREE.ShaderMaterial( {
-
-					uniforms:       THREE.UniformsUtils.clone( clipDepthShader.uniforms ),
-					vertexShader:   clipDepthShader.vertexShader,
-					fragmentShader: clipDepthShader.fragmentShader
-
-				} );
-
-				depthMaterial.morphTargets = originalMaterial.morphTargets;
-
-				node.properties.depthMaterial = depthMaterial;
-
-			} else {
-
-				node.properties.depthMaterial = defaultDepthMaterial;
-
-			}
-
-		} );
-
-	};
-
-	this.createRenderTargets = function ( ) {
-
-		// g-buffers
-
-		var rtColor   = new THREE.WebGLRenderTarget( width, height, rtParamsFloatNearest );
-		var rtNormal  = new THREE.WebGLRenderTarget( width, height, rtParamsFloatLinear );
-		var rtDepth   = new THREE.WebGLRenderTarget( width, height, rtParamsFloatLinear );
-		var rtLight   = new THREE.WebGLRenderTarget( width, height, rtParamsFloatLinear );
-		var rtEmitter = new THREE.WebGLRenderTarget( width, height, rtParamsUByte );
-		var rtFinal   = new THREE.WebGLRenderTarget( width, height, rtParamsUByte );
-
-		rtColor.generateMipmaps = false;
-		rtNormal.generateMipmaps = false;
-		rtDepth.generateMipmaps = false;
-		rtLight.generateMipmaps = false;
-		rtEmitter.generateMipmaps = false;
-		rtFinal.generateMipmaps = false;
-
-		// composers
-
-		var passColor = new THREE.RenderPass( scene, camera );
-		compColor = new THREE.EffectComposer( renderer, rtColor );
-		compColor.addPass( passColor );
-
-		var passNormal = new THREE.RenderPass( scene, camera );
-		compNormal = new THREE.EffectComposer( renderer, rtNormal );
-		compNormal.addPass( passNormal );
-
-		var passDepth = new THREE.RenderPass( scene, camera );
-		compDepth = new THREE.EffectComposer( renderer, rtDepth );
-		compDepth.addPass( passDepth );
-
-		var passEmitter = new THREE.RenderPass( emitterScene, camera );
-		compEmitter = new THREE.EffectComposer( renderer, rtEmitter );
-		compEmitter.addPass( passEmitter );
-
-		var passLight = new THREE.RenderPass( lightScene, camera );
-		compLightBuffer = new THREE.EffectComposer( renderer, rtLight );
-		compLightBuffer.addPass( passLight );
-
-		//
-
-		lightShader.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
-		lightShader.uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
-		lightShader.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
-		lightShader.uniforms[ 'samplerLightBuffer' ].value = rtLight;
-
-		compositeShader.uniforms[ 'samplerLightBuffer' ].value = compLightBuffer.renderTarget2;
-		compositeShader.uniforms[ 'samplerEmitter' ].value = compEmitter.renderTarget2;
-
-		// composite
-
-		var compositePass = new THREE.ShaderPass( compositeShader );
-		compositePass.needsSwap = true;
-
-		var effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
-		effectFXAA.uniforms[ 'resolution' ].value.set( 1 / width, 1 / height );
-
-		var effectColor = new THREE.ShaderPass( THREE.ColorCorrectionShader );
-		effectColor.renderToScreen = true;
-
-		effectColor.uniforms[ 'powRGB' ].value.set( 1, 1, 1 );
-		effectColor.uniforms[ 'mulRGB' ].value.set( 2, 2, 2 );
-
-		compFinal = new THREE.EffectComposer( renderer, rtFinal );
-		compFinal.addPass( compositePass );
-		compFinal.addPass( effectFXAA );
-		compFinal.addPass( effectColor );
-
-	};
-
-	this.addDeferredLights = function ( lights, additiveSpecular ) {
-
-		var geometryEmitter = new THREE.SphereGeometry( 0.7, 7, 7 );
-
-		for ( var i = 0, il = lights.length; i < il; i ++ ) {
-
-			var light = lights[ i ];
-
-			// setup material
-
-			var materialLight = new THREE.ShaderMaterial( {
-
-				uniforms:       THREE.UniformsUtils.clone( lightShader.uniforms ),
-				vertexShader:   lightShader.vertexShader,
-				fragmentShader: lightShader.fragmentShader,
-				defines:		{ "ADDITIVE_SPECULAR": additiveSpecular },
-
-				blending:		THREE.AdditiveBlending,
-				depthWrite:		false,
-				transparent:	true
-
-			} );
-
-			materialLight.uniforms[ "lightPos" ].value = light.position;
-			materialLight.uniforms[ "lightRadius" ].value = light.distance;
-			materialLight.uniforms[ "lightIntensity" ].value = light.intensity;
-			materialLight.uniforms[ "lightColor" ].value = light.color;
-
-			// setup proxy geometry for this light
-
-			var geometryLight = new THREE.SphereGeometry( light.distance, 16, 8 );
-			var meshLight = new THREE.Mesh( geometryLight, materialLight );
-			meshLight.position = light.position;
-			lightNode.add( meshLight );
-
-			// create emitter sphere
-
-			var matEmitter = new THREE.ShaderMaterial( {
-
-				uniforms:       THREE.UniformsUtils.clone( unlitShader.uniforms ),
-				vertexShader:   unlitShader.vertexShader,
-				fragmentShader: unlitShader.fragmentShader
-
-			} );
-
-			matEmitter.uniforms[ "samplerDepth" ].value = compDepth.renderTarget2;
-			matEmitter.uniforms[ "lightColor" ].value = light.color;
-
-			var meshEmitter = new THREE.Mesh( geometryEmitter, matEmitter );
-			meshEmitter.position = light.position;
-			emitterNode.add( meshEmitter );
-
-			// add emitter to light node
-
-			meshLight.properties.emitter = meshEmitter;
-
-		}
-
-	};
-
-	this.render = function () {
-
-		// -----------------------------
-		// g-buffer color
-		// -----------------------------
-
-		scene.traverse( function( node ) {
-
-			if ( node.material ) node.material = node.properties.colorMaterial;
-
-		} );
-
-		compColor.render();
-
-		// -----------------------------
-		// g-buffer depth
-		// -----------------------------
-
-		scene.traverse( function( node ) {
-
-			if ( node.material ) node.material = node.properties.depthMaterial;
-
-		} );
-
-		compDepth.render();
-
-		// -----------------------------
-		// g-buffer normals
-		// -----------------------------
-
-		scene.traverse( function( node ) {
-
-			if ( node.material ) node.material = node.properties.normalMaterial;
-
-		} );
-
-		compNormal.render();
-
-		// -----------------------------
-		// emitter pass
-		// -----------------------------
-
-		compEmitter.render();
-
-		// -----------------------------
-		// light pass
-		// -----------------------------
-
-		camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
-
-		for ( var i = 0, il = lightNode.children.length; i < il; i ++ ) {
-
-			var uniforms = lightNode.children[ i ].material.uniforms;
-
-			uniforms[ "matProjInverse" ].value = camera.projectionMatrixInverse;
-			uniforms[ "matView" ].value = camera.matrixWorldInverse;
-
-		}
-
-		compLightBuffer.render();
-
-		// -----------------------------
-		// composite pass
-		// -----------------------------
-
-		compFinal.render( 0.1 );
-
-	};
-
-};

+ 260 - 146
examples/js/ShaderDeferred.js

@@ -17,8 +17,11 @@ THREE.ShaderDeferred = {
 			THREE.UniformsLib[ "shadowmap" ],
 
 			{
-				"specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
-				"shininess": { type: "f", value: 30 }
+				"emissive" :  { type: "c", value: new THREE.Color( 0x000000 ) },
+				"specular" :  { type: "c", value: new THREE.Color( 0x111111 ) },
+				"shininess":  { type: "f", value: 30 },
+				"wrapAround": 		{ type: "f", value: 1 },
+				"additiveSpecular": { type: "f", value: 1 }
 			}
 
 		] ),
@@ -27,7 +30,10 @@ THREE.ShaderDeferred = {
 
 			"uniform vec3 diffuse;",
 			"uniform vec3 specular;",
+			"uniform vec3 emissive;",
 			"uniform float shininess;",
+			"uniform float wrapAround;",
+			"uniform float additiveSpecular;",
 
 			THREE.ShaderChunk[ "color_pars_fragment" ],
 			THREE.ShaderChunk[ "map_pars_fragment" ],
@@ -64,21 +70,33 @@ THREE.ShaderDeferred = {
 
 				THREE.ShaderChunk[ "fog_fragment" ],
 
+				//
+
+				"const float compressionScale = 0.999;",
+
 				// diffuse color
 
-				"gl_FragColor.x = vec3_to_float( 0.999 * gl_FragColor.xyz );",
+				"gl_FragColor.x = vec3_to_float( compressionScale * gl_FragColor.xyz );",
 
 				// specular color
 
-				"gl_FragColor.y = vec3_to_float( 0.999 * specular );",
+				"gl_FragColor.y = additiveSpecular * vec3_to_float( compressionScale * specular );",
 
 				// shininess
 
-				"gl_FragColor.z = shininess;",
+				"gl_FragColor.z = wrapAround * shininess;",
+
+				// emissive color
 
-				// free
+				"#ifdef USE_MAP",
 
-				"gl_FragColor.w = 0.0;",
+					"gl_FragColor.w = vec3_to_float( compressionScale * emissive * texelColor.xyz );",
+
+				"#else",
+
+					"gl_FragColor.w = vec3_to_float( compressionScale * emissive );",
+
+				"#endif",
 
 			"}"
 
@@ -123,60 +141,62 @@ THREE.ShaderDeferred = {
 
 	},
 
-	"clipDepth" : {
+	"normalDepth" : {
 
-		uniforms: { },
+		uniforms: {
 
-		fragmentShader : [
+			bumpMap: 	  { type: "t", value: null },
+			bumpScale:	  { type: "f", value: 1 },
+			offsetRepeat: { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
 
-			"varying vec4 clipPos;",
+		},
 
-			"void main() {",
+		fragmentShader : [
 
-				"gl_FragColor = vec4( clipPos.z / clipPos.w, 1.0, 1.0, 1.0 );",
+			"#ifdef USE_BUMPMAP",
 
-			"}"
+				"#extension GL_OES_standard_derivatives : enable\n",
 
-		].join("\n"),
+				"varying vec2 vUv;",
+				"varying vec3 vViewPosition;",
 
-		vertexShader : [
+				THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
 
-			"varying vec4 clipPos;",
+			"#endif",
 
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
+			"varying vec3 normalView;",
+			"varying vec4 clipPos;",
 
 			"void main() {",
 
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "default_vertex" ],
+				"vec3 normal = normalize( normalView );",
 
-				"clipPos = gl_Position;",
+				"#ifdef USE_BUMPMAP",
 
-			"}"
+					"normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );",
 
-		].join("\n")
+				"#endif",
 
-	},
+				"gl_FragColor.xyz = normal * 0.5 + 0.5;",
+				"gl_FragColor.w = clipPos.z / clipPos.w;",
 
-	"normals" : {
+			"}"
 
-		uniforms: { },
+		].join("\n"),
 
-		fragmentShader : [
+		vertexShader : [
 
 			"varying vec3 normalView;",
+			"varying vec4 clipPos;",
 
-			"void main() {",
-
-				"gl_FragColor = vec4( vec3( normalView * 0.5 + 0.5 ), 1.0 );",
+			"#ifdef USE_BUMPMAP",
 
-			"}"
+				"varying vec2 vUv;",
+				"varying vec3 vViewPosition;",
 
-		].join("\n"),
+				"uniform vec4 offsetRepeat;",
 
-		vertexShader : [
-
-			"varying vec3 normalView;",
+			"#endif",
 
 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
 
@@ -202,37 +222,40 @@ THREE.ShaderDeferred = {
 
 				"normalView = normalize( normalMatrix * objectNormal );",
 
+				"#ifdef USE_BUMPMAP",
+
+					"vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
+					"vViewPosition = -mvPosition.xyz;",
+
+				"#endif",
+
+				"clipPos = gl_Position;",
+
 			"}"
 
 		].join("\n")
 
 	},
 
-	"bump" : {
+	"composite" : {
 
 		uniforms: {
 
-			bumpMap: 	  { type: "t", value: null },
-			bumpScale:	  { type: "f", value: 1 },
-			offsetRepeat: { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
+			samplerLight: 	{ type: "t", value: null },
+			brightness:		{ type: "f", value: 1 }
 
 		},
 
 		fragmentShader : [
 
-			"#extension GL_OES_standard_derivatives : enable\n",
-
-			"varying vec3 normalView;",
-			"varying vec2 vUv;",
-			"varying vec3 vViewPosition;",
-
-			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
+			"varying vec2 texCoord;",
+			"uniform sampler2D samplerLight;",
+			"uniform float brightness;",
 
 			"void main() {",
 
-				"vec3 normal = normalize( normalView );",
-				"normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );",
-				"gl_FragColor = vec4( vec3( normal * 0.5 + 0.5 ), 1.0 );",
+				"vec3 color = texture2D( samplerLight, texCoord ).xyz;",
+				"gl_FragColor = vec4( brightness * sqrt( color ), 1.0 );",
 
 			"}"
 
@@ -240,19 +263,13 @@ THREE.ShaderDeferred = {
 
 		vertexShader : [
 
-			"varying vec3 normalView;",
-			"varying vec2 vUv;",
-			"varying vec3 vViewPosition;",
-
-			"uniform vec4 offsetRepeat;",
+			"varying vec2 texCoord;",
 
 			"void main() {",
 
-				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
-				"gl_Position = projectionMatrix * mvPosition;",
-				"normalView = normalize( normalMatrix * normal );",
-				"vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
-				"vViewPosition = -mvPosition.xyz;",
+				"vec4 pos = vec4( sign( position.xy ), 0.0, 1.0 );",
+				"texCoord = pos.xy * vec2( 0.5 ) + 0.5;",
+				"gl_Position = pos;",
 
 			"}"
 
@@ -260,83 +277,150 @@ THREE.ShaderDeferred = {
 
 	},
 
-	"unlit" : {
+	"pointLight" : {
 
 		uniforms: {
 
-			samplerDepth: { type: "t", value: null },
-			viewWidth:    { type: "f", value: 800 },
-			viewHeight:   { type: "f", value: 600 },
-			lightColor:   { type: "c", value: new THREE.Color( 0x000000 ) }
+			samplerNormalDepth: { type: "t", value: null },
+			samplerColor: 		{ type: "t", value: null },
+			matView: 		{ type: "m4", value: new THREE.Matrix4() },
+			matProjInverse: { type: "m4", value: new THREE.Matrix4() },
+			viewWidth: 		{ type: "f", value: 800 },
+			viewHeight: 	{ type: "f", value: 600 },
+			lightPos: 		{ 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 }
 
 		},
 
 		fragmentShader : [
 
+			"varying vec3 lightView;",
 			"varying vec4 clipPos;",
-			"uniform sampler2D samplerDepth;",
 
+			"uniform sampler2D samplerColor;",
+			"uniform sampler2D samplerNormalDepth;",
+
+			"uniform float lightRadius;",
+			"uniform float lightIntensity;",
 			"uniform float viewHeight;",
 			"uniform float viewWidth;",
 
 			"uniform vec3 lightColor;",
 
+			"uniform mat4 matProjInverse;",
+
+			"vec3 float_to_vec3( float data ) {",
+
+				"vec3 uncompressed;",
+				"uncompressed.x = fract( data );",
+				"float zInt = floor( data / 255.0 );",
+				"uncompressed.z = fract( zInt / 255.0 );",
+				"uncompressed.y = fract( floor( data - ( zInt * 255.0 ) ) / 255.0 );",
+				"return uncompressed;",
+
+			"}",
+
 			"void main() {",
 
 				"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
-				"float z = texture2D( samplerDepth, texCoord ).x;",
-				"vec4 color = vec4( lightColor, 1.0 );",
-				"float depth = clipPos.z / clipPos.w;",
-				"if( depth > z && z > 0.0 ) color.w = 0.0;",
-				"gl_FragColor = color;",
 
-			"}"
+				"vec4 normalDepth = texture2D( samplerNormalDepth, texCoord );",
 
-		].join("\n"),
+				"float z = normalDepth.w;",
+				"float lightZ = clipPos.z / clipPos.w;",
 
-		vertexShader : [
+				"if ( z == 0.0 || lightZ > z ) discard;",
 
-			"varying vec4 clipPos;",
+				"float x = texCoord.x * 2.0 - 1.0;",
+				"float y = texCoord.y * 2.0 - 1.0;",
 
-			"void main() {",
+				"vec4 projectedPos = vec4( x, y, z, 1.0 );",
 
-				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
-				"clipPos = gl_Position;",
+				"vec4 viewPos = matProjInverse * projectedPos;",
+				"viewPos.xyz /= viewPos.w;",
+				"viewPos.w = 1.0;",
 
-			"}"
+				"vec3 lightDir = lightView - viewPos.xyz;",
+				"float dist = length( lightDir );",
 
-		].join("\n")
+				"if ( dist > lightRadius ) discard;",
 
-	},
+				"lightDir = normalize( lightDir );",
 
-	"composite" : {
+				"float cutoff = 0.3;",
+				"float denom = dist/lightRadius + 1.0;",
+				"float attenuation = 1.0 / ( denom * denom );",
+				"attenuation = ( attenuation - cutoff ) / ( 1.0 - cutoff );",
+				"attenuation = max( attenuation, 0.0 );",
+				"attenuation *= attenuation;",
 
-		uniforms: {
+				// normal
 
-			samplerLightBuffer: { type: "t", value: null },
-			samplerEmitter: 	{ type: "t", value: null }
+				"vec3 normal = normalDepth.xyz * 2.0 - 1.0;",
 
-		},
+				// color
 
-		fragmentShader : [
+				"vec4 colorMap = texture2D( samplerColor, texCoord );",
 
-			"varying vec2 texCoord;",
-			"uniform sampler2D samplerLightBuffer;",
-			"uniform sampler2D samplerEmitter;",
-			"uniform vec3 lightPos;",
+				"vec3 albedo = float_to_vec3( abs( colorMap.x ) );",
+				"vec3 specularColor = float_to_vec3( abs( colorMap.y ) );",
+				"float shininess = abs( colorMap.z );",
+				"float wrapAround = sign( colorMap.z );",
 
-			"void main() {",
+				// light
+
+				"vec3 diffuse;",
+
+				"float diffuseFull = max( dot( normal, lightDir ), 0.0 );",
+
+				"if ( wrapAround < 0.0 ) {",
+
+					// wrap around lighting
+
+					"float diffuseHalf = max( 0.5 + 0.5 * dot( normal, lightDir ), 0.0 );",
+
+					"const vec3 wrapRGB = vec3( 0.6, 0.2, 0.2 );",
+					"diffuse = mix( vec3( diffuseFull ), vec3( diffuseHalf ), wrapRGB );",
+
+				"} else {",
+
+					// simple lighting
+
+					"diffuse = vec3( diffuseFull );",
+
+				"}",
+
+				// specular
+
+				"vec3 halfVector = normalize( lightDir - normalize( viewPos.xyz ) );",
+				"float dotNormalHalf = max( dot( normal, halfVector ), 0.0 );",
+
+				// simple specular
+
+				//"vec3 specular = specularIntensity * max( pow( dotNormalHalf, shininess ), 0.0 ) * diffuse;",
+
+				// physically based specular
+
+				"float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
+
+				"vec3 schlick = specularColor + vec3( 1.0 - specularColor ) * pow( 1.0 - dot( lightDir, halfVector ), 5.0 );",
+				"vec3 specular = schlick * max( pow( dotNormalHalf, shininess ), 0.0 ) * diffuse * specularNormalization;",
+
+				// combine
+
+				"vec3 light = lightIntensity * lightColor;",
 
-				"vec3 color = texture2D( samplerLightBuffer, texCoord ).xyz;",
-				"vec3 emitter = texture2D( samplerEmitter, texCoord ).xyz;",
+				"float additiveSpecular = sign( colorMap.y );",
 
-				"if ( emitter != vec3( 0.0 ) ) {",
+				"if ( additiveSpecular < 0.0 ) {",
 
-					"gl_FragColor = vec4( emitter, 1.0 );",
+					"gl_FragColor = vec4( albedo * light * diffuse, attenuation ) + vec4( light * specular, attenuation );",
 
 				"} else {",
 
-					"gl_FragColor = vec4( sqrt( color ), 1.0 );",
+					"gl_FragColor = vec4( albedo * light * ( diffuse + specular ), attenuation );",
 
 				"}",
 
@@ -346,13 +430,17 @@ THREE.ShaderDeferred = {
 
 		vertexShader : [
 
-			"varying vec2 texCoord;",
+			"varying vec3 lightView;",
+			"varying vec4 clipPos;",
+			"uniform vec3 lightPos;",
+			"uniform mat4 matView;",
 
-			"void main() {",
+			"void main() { ",
 
-				"vec4 pos = vec4( sign( position.xy ), 0.0, 1.0 );",
-				"texCoord = pos.xy * vec2( 0.5 ) + 0.5;",
-				"gl_Position = pos;",
+				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
+				"gl_Position = projectionMatrix * mvPosition;",
+				"lightView = vec3( matView * vec4( lightPos, 1.0 ) );",
+				"clipPos = gl_Position;",
 
 			"}"
 
@@ -360,22 +448,19 @@ THREE.ShaderDeferred = {
 
 	},
 
-	"light" : {
+	"directionalLight" : {
 
 		uniforms: {
 
-			samplerLightBuffer: { type: "t", value: null },
-			samplerNormals: { type: "t", value: null },
-			samplerDepth: 	{ type: "t", value: null },
-			samplerColor: 	{ type: "t", value: null },
+			samplerNormalDepth: { type: "t", value: null },
+			samplerColor: 		{ type: "t", value: null },
 			matView: 		{ type: "m4", value: new THREE.Matrix4() },
 			matProjInverse: { type: "m4", value: new THREE.Matrix4() },
 			viewWidth: 		{ type: "f", value: 800 },
 			viewHeight: 	{ type: "f", value: 600 },
-			lightPos: 		{ type: "v3", value: new THREE.Vector3( 0, 0, 0 ) },
+			lightDir: 		{ type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
 			lightColor: 	{ type: "c", value: new THREE.Color( 0x000000 ) },
-			lightIntensity: { type: "f", value: 1.0 },
-			lightRadius: 	{ type: "f", value: 1.0 }
+			lightIntensity: { type: "f", value: 1.0 }
 
 		},
 
@@ -385,9 +470,7 @@ THREE.ShaderDeferred = {
 			"varying vec4 clipPos;",
 
 			"uniform sampler2D samplerColor;",
-			"uniform sampler2D samplerDepth;",
-			"uniform sampler2D samplerNormals;",
-			"uniform sampler2D samplerLightBuffer;",
+			"uniform sampler2D samplerNormalDepth;",
 
 			"uniform float lightRadius;",
 			"uniform float lightIntensity;",
@@ -413,19 +496,10 @@ THREE.ShaderDeferred = {
 
 				"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
 
-				"float z = texture2D( samplerDepth, texCoord ).x;",
-				"float lightZ = clipPos.z / clipPos.w;",
-
-				/*
-				"if ( z == 0.0 ) {",
-
-					"gl_FragColor = vec4( vec3( 0.0 ), 1.0 );",
-					"return;",
-
-				"}",
-				*/
+				"vec4 normalDepth = texture2D( samplerNormalDepth, texCoord );",
+				"float z = normalDepth.w;",
 
-				"if ( z == 0.0 || lightZ > z ) discard;",
+				"if ( z == 0.0 ) discard;",
 
 				"float x = texCoord.x * 2.0 - 1.0;",
 				"float y = texCoord.y * 2.0 - 1.0;",
@@ -436,28 +510,15 @@ THREE.ShaderDeferred = {
 				"viewPos.xyz /= viewPos.w;",
 				"viewPos.w = 1.0;",
 
-				"vec3 lightDir = lightView - viewPos.xyz;",
-				"float dist = length( lightDir );",
-
-				"if ( dist > lightRadius ) discard;",
-
-				"lightDir = normalize( lightDir );",
-
-				"float cutoff = 0.3;",
-				"float denom = dist/lightRadius + 1.0;",
-				"float attenuation = 1.0 / ( denom * denom );",
-				"attenuation = ( attenuation - cutoff ) / ( 1.0 - cutoff );",
-				"attenuation = max( attenuation, 0.0 );",
-				"attenuation *= attenuation;",
+				"vec3 lightDir = normalize( lightView );",
 
 				// normal
 
-				"vec3 normal = texture2D( samplerNormals, texCoord ).xyz * 2.0 - 1.0;",
+				"vec3 normal = normalDepth.xyz * 2.0 - 1.0;",
 
 				// color
 
 				"vec4 colorMap = texture2D( samplerColor, texCoord );",
-
 				"vec3 albedo = float_to_vec3( abs( colorMap.x ) );",
 				"vec3 specularColor = float_to_vec3( abs( colorMap.y ) );",
 				"float shininess = colorMap.z;",
@@ -467,7 +528,7 @@ THREE.ShaderDeferred = {
 				"float diffuseFull = max( dot( normal, lightDir ), 0.0 );",
 				"float diffuseHalf = max( 0.5 + 0.5 * dot( normal, lightDir ), 0.0 );",
 
-				"const vec3 wrapRGB = vec3( 0.6, 0.2, 0.2 );",
+				"const vec3 wrapRGB = vec3( 0.2, 0.2, 0.2 );",
 				"vec3 diffuse = mix( vec3 ( diffuseFull ), vec3( diffuseHalf ), wrapRGB );",
 
 				// simple lighting
@@ -477,7 +538,7 @@ THREE.ShaderDeferred = {
 
 				// specular
 
-				"vec3 halfVector = normalize( lightDir - normalize( viewPos.xyz ) );",
+				"vec3 halfVector = normalize( lightDir + normalize( viewPos.xyz ) );",
 				"float dotNormalHalf = max( dot( normal, halfVector ), 0.0 );",
 
 				// simple specular
@@ -497,11 +558,11 @@ THREE.ShaderDeferred = {
 
 				"#ifdef ADDITIVE_SPECULAR",
 
-					"gl_FragColor = vec4( albedo * light * diffuse, attenuation ) + vec4( light * specular, attenuation );",
+					"gl_FragColor = vec4( albedo * light * diffuse, 1.0 ) + vec4( light * specular, 1.0 );",
 
 				"#else",
 
-					"gl_FragColor = vec4( albedo * light * ( diffuse + specular ), attenuation );",
+					"gl_FragColor = vec4( albedo * light * ( diffuse + specular ), 1.0 );",
 
 				"#endif",
 
@@ -513,21 +574,74 @@ THREE.ShaderDeferred = {
 
 			"varying vec3 lightView;",
 			"varying vec4 clipPos;",
-			"uniform vec3 lightPos;",
+			"uniform vec3 lightDir;",
 			"uniform mat4 matView;",
 
 			"void main() { ",
 
 				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
 				"gl_Position = projectionMatrix * mvPosition;",
-				"lightView = vec3( matView * vec4( lightPos, 1.0 ) );",
+				"lightView = vec3( matView * vec4( lightDir, 0.0 ) );",
 				"clipPos = gl_Position;",
 
 			"}"
 
 		].join("\n")
 
-	}
+	},
+
+	"emissiveLight" : {
+
+		uniforms: {
+
+			samplerColor: 	{ type: "t", value: null },
+			viewWidth: 		{ type: "f", value: 800 },
+			viewHeight: 	{ type: "f", value: 600 },
+
+		},
+
+		fragmentShader : [
+
+			"uniform sampler2D samplerColor;",
+
+			"uniform float viewHeight;",
+			"uniform float viewWidth;",
+
+			"vec3 float_to_vec3( float data ) {",
 
+				"vec3 uncompressed;",
+				"uncompressed.x = fract( data );",
+				"float zInt = floor( data / 255.0 );",
+				"uncompressed.z = fract( zInt / 255.0 );",
+				"uncompressed.y = fract( floor( data - ( zInt * 255.0 ) ) / 255.0 );",
+				"return uncompressed;",
+
+			"}",
+
+			"void main() {",
+
+				"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
+
+				"vec4 colorMap = texture2D( samplerColor, texCoord );",
+				"vec3 emissiveColor = float_to_vec3( abs( colorMap.w ) );",
+
+				"gl_FragColor = vec4( emissiveColor, 1.0 );",
+
+			"}"
+
+		].join("\n"),
+
+		vertexShader : [
+
+			"void main() { ",
+
+				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
+				"gl_Position = projectionMatrix * mvPosition;",
+
+			"}"
+
+		].join("\n")
+
+	}
 
 };

+ 12 - 12
examples/js/UVsUtils.js

@@ -39,10 +39,10 @@ THREE.UVsUtils.CylinderUVGenerator.prototype = {
         u1 *= this.uRepeat;
         u2 *= this.uRepeat;
         return [
-            new THREE.UV( u1, v1 ),
-            new THREE.UV( u2, v1 ),
-            new THREE.UV( u2, v2 ),
-            new THREE.UV( u1, v2 )
+            new THREE.Vector2( u1, v1 ),
+            new THREE.Vector2( u2, v1 ),
+            new THREE.Vector2( u2, v2 ),
+            new THREE.Vector2( u1, v2 )
         ];
     },
     
@@ -133,13 +133,13 @@ THREE.UVsDebug = function(geometry) {
         for (j = 0, jl = uv.length; j < jl; j++) {
             u = uv[j];
             
-            a.x += u.u;
-            a.y += u.v;
+            a.x += u.x;
+            a.y += u.y;
             
             if (j == 0) {
-                ctx.moveTo(u.u * width, u.v * height);
+                ctx.moveTo(u.x * width, u.y * height);
             } else {
-                ctx.lineTo(u.u * width, u.v * height);
+                ctx.lineTo(u.x * width, u.y * height);
             }
         }
         
@@ -160,10 +160,10 @@ THREE.UVsDebug = function(geometry) {
         // label uv edge orders
         for (j = 0, jl = uv.length; j < jl; j++) {
             u = uv[j];
-            b.set(u.u, u.v).subSelf(a).divideScalar(4);
+            b.set(u.x, u.y).subSelf(a).divideScalar(4);
             
-            b.x = u.u - b.x;
-            b.y = u.v - b.y;
+            b.x = u.x - b.x;
+            b.y = u.y - b.y;
             ctx.fillText(abc[j]
                 + ':' + faces[i][abc[j]], b.x * width, b.y * height);
         }
@@ -171,4 +171,4 @@ THREE.UVsDebug = function(geometry) {
     }
     
     return canvas;
-}
+}

+ 2 - 2
examples/js/loaders/ColladaLoader.js

@@ -2437,7 +2437,7 @@ THREE.ColladaLoader = function () {
 								ts = ts || { };
 								if ( ts[ input.set ] === undefined ) ts[ input.set ] = [];
 								// invert the V
-								ts[ input.set ].push( new THREE.UV( source.data[ idx32 ], source.data[ idx32 + 1 ] ) );
+								ts[ input.set ].push( new THREE.Vector2( source.data[ idx32 ], source.data[ idx32 + 1 ] ) );
 
 								break;
 
@@ -2498,7 +2498,7 @@ THREE.ColladaLoader = function () {
 							idx32 = vs[ ndx ] * numParams;
 							if ( ts[ input.set ] === undefined ) ts[ input.set ] = [ ];
 							// invert the V
-							ts[ input.set ].push( new THREE.UV( source.data[ idx32 ], 1.0 - source.data[ idx32 + 1 ] ) );
+							ts[ input.set ].push( new THREE.Vector2( source.data[ idx32 ], 1.0 - source.data[ idx32 + 1 ] ) );
 
 						}
 

+ 1 - 1
examples/js/loaders/OBJLoader.js

@@ -50,7 +50,7 @@ THREE.OBJLoader.prototype = {
 
 		function uv( u, v ) {
 
-			return new THREE.UV( u, v );
+			return new THREE.Vector2( u, v );
 
 		}
 

+ 1 - 1
examples/js/loaders/OBJMTLLoader.js

@@ -188,7 +188,7 @@ THREE.OBJMTLLoader.prototype = {
 
 		function uv( u, v ) {
 
-			return new THREE.UV( u, v );
+			return new THREE.Vector2( u, v );
 
 		}
 

+ 4 - 4
examples/js/loaders/UTF8Loader.js

@@ -265,9 +265,9 @@ THREE.UTF8Loader.GeometryCreator.prototype = {
     uv3: function ( where, u1, v1, u2, v2, u3, v3 ) {
 
         var uv = [];
-        uv.push( new THREE.UV( u1, v1 ) );
-        uv.push( new THREE.UV( u2, v2 ) );
-        uv.push( new THREE.UV( u3, v3 ) );
+        uv.push( new THREE.Vector2( u1, v1 ) );
+        uv.push( new THREE.Vector2( u2, v2 ) );
+        uv.push( new THREE.Vector2( u3, v3 ) );
         where.push( uv );
 
     }
@@ -957,4 +957,4 @@ function addListeners( dom, listeners ) {
         dom.addEventListener( key, listeners[ key ] );
 
     }
-}
+}

+ 3 - 3
examples/js/loaders/ctm/CTMLoader.js

@@ -621,9 +621,9 @@ THREE.CTMLoader.prototype.createModelClassic = function ( file, callback ) {
 	function uv3 ( where, u1, v1, u2, v2, u3, v3 ) {
 
 		var uv = [];
-		uv.push( new THREE.UV( u1, v1 ) );
-		uv.push( new THREE.UV( u2, v2 ) );
-		uv.push( new THREE.UV( u3, v3 ) );
+		uv.push( new THREE.Vector2( u1, v1 ) );
+		uv.push( new THREE.Vector2( u2, v2 ) );
+		uv.push( new THREE.Vector2( u3, v3 ) );
 		where.push( uv );
 
 	};

+ 22 - 10
examples/js/postprocessing/EffectComposer.js

@@ -6,19 +6,18 @@ THREE.EffectComposer = function ( renderer, renderTarget ) {
 
 	this.renderer = renderer;
 
-	this.renderTarget1 = renderTarget;
-
-	if ( this.renderTarget1 === undefined ) {
+	if ( renderTarget === undefined ) {
 
 		var width = window.innerWidth || 1;
 		var height = window.innerHeight || 1;
+		var parameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
 
-		this.renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
-		this.renderTarget1 = new THREE.WebGLRenderTarget( width, height, this.renderTargetParameters );
+		renderTarget = new THREE.WebGLRenderTarget( width, height, parameters );
 
 	}
 
-	this.renderTarget2 = this.renderTarget1.clone();
+	this.renderTarget1 = renderTarget;
+	this.renderTarget2 = renderTarget.clone();
 
 	this.writeBuffer = this.renderTarget1;
 	this.readBuffer = this.renderTarget2;
@@ -99,19 +98,32 @@ THREE.EffectComposer.prototype = {
 
 	reset: function ( renderTarget ) {
 
-		this.renderTarget1 = renderTarget;
+		if ( renderTarget === undefined ) {
 
-		if ( this.renderTarget1 === undefined ) {
+			renderTarget = this.renderTarget1.clone();
 
-			this.renderTarget1 = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, this.renderTargetParameters );
+			renderTarget.width = window.innerWidth;
+			renderTarget.height = window.innerHeight;
 
 		}
 
-		this.renderTarget2 = this.renderTarget1.clone();
+		this.renderTarget1 = renderTarget;
+		this.renderTarget2 = renderTarget.clone();
 
 		this.writeBuffer = this.renderTarget1;
 		this.readBuffer = this.renderTarget2;
 
+	},
+
+	setSize: function ( width, height ) {
+
+		var renderTarget = this.renderTarget1.clone();
+
+		renderTarget.width = width;
+		renderTarget.height = height;
+
+		this.reset( renderTarget );
+
 	}
 
 };

+ 5 - 5
examples/js/renderers/CSS3DRenderer.js

@@ -121,10 +121,10 @@ THREE.CSS3DRenderer = function () {
 			epsilon( elements[ 1 ] ) + ',' +
 			epsilon( elements[ 2 ] ) + ',' +
 			epsilon( elements[ 3 ] ) + ',' +
-			epsilon( elements[ 4 ] ) + ',' +
-			epsilon( elements[ 5 ] ) + ',' +
-			epsilon( elements[ 6 ] ) + ',' +
-			epsilon( elements[ 7 ] ) + ',' +
+			epsilon( - elements[ 4 ] ) + ',' +
+			epsilon( - elements[ 5 ] ) + ',' +
+			epsilon( - elements[ 6 ] ) + ',' +
+			epsilon( - elements[ 7 ] ) + ',' +
 			epsilon( elements[ 8 ] ) + ',' +
 			epsilon( elements[ 9 ] ) + ',' +
 			epsilon( elements[ 10 ] ) + ',' +
@@ -133,7 +133,7 @@ THREE.CSS3DRenderer = function () {
 			epsilon( elements[ 13 ] ) + ',' +
 			epsilon( elements[ 14 ] ) + ',' +
 			epsilon( elements[ 15 ] ) +
-		') scale3d(1,-1,1)';
+		')';
 
 	}
 

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

@@ -55,7 +55,7 @@ THREE.DOMRenderer = function () {
 
 			if ( element instanceof THREE.RenderableParticle && element.material instanceof THREE.ParticleDOMMaterial ) {
 
-				dom = element.material.domElement;
+				dom = element.material.element;
 
 				v1x = element.x * _widthHalf + _widthHalf - ( dom.offsetWidth >> 1 );
 				v1y = element.y * _heightHalf + _heightHalf - ( dom.offsetHeight >> 1 );

+ 574 - 0
examples/js/renderers/WebGLDeferredRenderer.js

@@ -0,0 +1,574 @@
+/**
+ * @author alteredq / http://alteredqualia.com/
+ * @author MPanknin / http://www.redplant.de/
+ */
+
+THREE.WebGLDeferredRenderer = function ( parameters ) {
+
+	var _this = this;
+
+	var width = parameters.width;
+	var height = parameters.height;
+	var scale = parameters.scale;
+
+	var scaledWidth = Math.floor( scale * width );
+	var scaledHeight = Math.floor( scale * height );
+
+	var brightness = parameters.brightness;
+
+	this.renderer = parameters.renderer;
+
+	if ( this.renderer === undefined ) {
+
+		this.renderer = new THREE.WebGLRenderer( { alpha: false } );
+		this.renderer.setSize( width, height );
+		this.renderer.setClearColorHex( 0x000000, 0 );
+
+		this.renderer.autoClear = false;
+
+	}
+
+	this.domElement = this.renderer.domElement;
+
+
+	//
+
+	var geometryLight = new THREE.SphereGeometry( 1, 16, 8 );
+
+	var black = new THREE.Color( 0x000000 );
+
+	var colorShader = THREE.ShaderDeferred[ "color" ];
+	var normalDepthShader = THREE.ShaderDeferred[ "normalDepth" ];
+
+	//
+
+	var emissiveLightShader = THREE.ShaderDeferred[ "emissiveLight" ];
+	var pointLightShader = THREE.ShaderDeferred[ "pointLight" ];
+	var directionalLightShader = THREE.ShaderDeferred[ "directionalLight" ];
+
+	var compositeShader = THREE.ShaderDeferred[ "composite" ];
+
+	//
+
+	var compColor, compNormal, compDepth, compLight, compFinal;
+	var passColor, passNormal, passDepth, passLightFullscreen, passLightProxy, compositePass;
+
+	var effectFXAA;
+
+	//
+
+	var lightSceneFullscreen, lightSceneProxy;
+	var lightMaterials = [];
+
+	//
+
+	var defaultNormalDepthMaterial = new THREE.ShaderMaterial( {
+
+		uniforms:       THREE.UniformsUtils.clone( normalDepthShader.uniforms ),
+		vertexShader:   normalDepthShader.vertexShader,
+		fragmentShader: normalDepthShader.fragmentShader
+
+	} );
+
+	//
+
+	var initDeferredMaterials = function ( object ) {
+
+		if ( object.material instanceof THREE.MeshFaceMaterial ) {
+
+			var colorMaterials = [];
+			var normalDepthMaterials = [];
+
+			var materials = object.material.materials;
+
+			for ( var i = 0, il = materials.length; i < il; i ++ ) {
+
+				var deferredMaterials = createDeferredMaterials( materials[ i ] );
+
+				colorMaterials.push( deferredMaterials.colorMaterial );
+				normalDepthMaterials.push( deferredMaterials.normalDepthMaterial );
+
+			}
+
+			object.properties.colorMaterial = new THREE.MeshFaceMaterial( colorMaterials );
+			object.properties.normalDepthMaterial = new THREE.MeshFaceMaterial( normalDepthMaterials );
+
+		} else {
+
+			var deferredMaterials = createDeferredMaterials( object.material );
+
+			object.properties.colorMaterial = deferredMaterials.colorMaterial;
+			object.properties.normalDepthMaterial = deferredMaterials.normalDepthMaterial;
+
+		}
+
+	};
+
+
+	var createDeferredMaterials = function ( originalMaterial ) {
+
+		var deferredMaterials = {};
+
+		// color material
+		// -----------------
+		// 	diffuse color
+		//	specular color
+		//	shininess
+		//	diffuse map
+		//	vertex colors
+		//	alphaTest
+		// 	morphs
+
+		var uniforms = THREE.UniformsUtils.clone( colorShader.uniforms );
+		var defines = { "USE_MAP": !! originalMaterial.map, "GAMMA_INPUT": true };
+
+		var material = new THREE.ShaderMaterial( {
+
+			fragmentShader: colorShader.fragmentShader,
+			vertexShader: 	colorShader.vertexShader,
+			uniforms: 		uniforms,
+			defines: 		defines,
+			shading:		originalMaterial.shading
+
+		} );
+
+		if ( originalMaterial instanceof THREE.MeshBasicMaterial ) {
+
+			var diffuse = black;
+			var emissive = originalMaterial.color;
+
+		} else {
+
+			var diffuse = originalMaterial.color;
+			var emissive = originalMaterial.emissive !== undefined ? originalMaterial.emissive : black;
+
+		}
+
+		var specular = originalMaterial.specular !== undefined ? originalMaterial.specular : black;
+		var shininess = originalMaterial.shininess !== undefined ? originalMaterial.shininess : 1;
+		var wrapAround = originalMaterial.wrapAround !== undefined ? ( originalMaterial.wrapAround ? -1 : 1 ) : 1;
+		var additiveSpecular = originalMaterial.metal !== undefined ? ( originalMaterial.metal ? 1 : -1 ) : -1;
+
+		uniforms.emissive.value.copy( emissive );
+		uniforms.diffuse.value.copy( diffuse );
+		uniforms.specular.value.copy( specular );
+		uniforms.shininess.value = shininess;
+		uniforms.wrapAround.value = wrapAround;
+		uniforms.additiveSpecular.value = additiveSpecular;
+
+		uniforms.map.value = originalMaterial.map;
+
+		material.vertexColors = originalMaterial.vertexColors;
+		material.morphTargets = originalMaterial.morphTargets;
+		material.morphNormals = originalMaterial.morphNormals;
+
+		material.alphaTest = originalMaterial.alphaTest;
+
+		if ( originalMaterial.bumpMap ) {
+
+			var offset = originalMaterial.bumpMap.offset;
+			var repeat = originalMaterial.bumpMap.repeat;
+
+			uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
+
+		}
+
+		deferredMaterials.colorMaterial = material;
+
+		// normal + depth material
+		// -----------------
+		//	vertex normals
+		//	morph normals
+		//	bump map
+		//	bump scale
+		//  clip depth
+
+		if ( originalMaterial.morphTargets || originalMaterial.bumpMap ) {
+
+			var uniforms = THREE.UniformsUtils.clone( normalDepthShader.uniforms );
+			var defines = { "USE_BUMPMAP": !!originalMaterial.bumpMap };
+
+			var normalDepthMaterial = new THREE.ShaderMaterial( {
+
+				uniforms:       uniforms,
+				vertexShader:   normalDepthShader.vertexShader,
+				fragmentShader: normalDepthShader.fragmentShader,
+				shading:		originalMaterial.shading,
+				defines:		defines,
+				blending:		THREE.NoBlending
+
+			} );
+
+			if ( originalMaterial.morphTargets ) {
+
+				normalDepthMaterial.morphTargets = originalMaterial.morphTargets;
+				normalDepthMaterial.morphNormals = originalMaterial.morphNormals;
+
+			}
+
+			if ( originalMaterial.bumpMap ) {
+
+				uniforms.bumpMap.value = originalMaterial.bumpMap;
+				uniforms.bumpScale.value = originalMaterial.bumpScale;
+
+				var offset = originalMaterial.bumpMap.offset;
+				var repeat = originalMaterial.bumpMap.repeat;
+
+				uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
+
+			}
+
+			deferredMaterials.normalDepthMaterial = normalDepthMaterial;
+
+		} else {
+
+			deferredMaterials.normalDepthMaterial = defaultNormalDepthMaterial;
+
+		}
+
+		return deferredMaterials;
+
+	};
+
+	var createDeferredPointLight = function ( light ) {
+
+		// setup light material
+
+		var materialLight = new THREE.ShaderMaterial( {
+
+			uniforms:       THREE.UniformsUtils.clone( pointLightShader.uniforms ),
+			vertexShader:   pointLightShader.vertexShader,
+			fragmentShader: pointLightShader.fragmentShader,
+
+			blending:		THREE.AdditiveBlending,
+			depthWrite:		false,
+			transparent:	true
+
+		} );
+
+		materialLight.uniforms[ "lightPos" ].value = light.position;
+		materialLight.uniforms[ "lightRadius" ].value = light.distance;
+		materialLight.uniforms[ "lightIntensity" ].value = light.intensity;
+		materialLight.uniforms[ "lightColor" ].value = light.color;
+
+		materialLight.uniforms[ "viewWidth" ].value = scaledWidth;
+		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
+
+		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
+		materialLight.uniforms[ 'samplerNormalDepth' ].value = compNormalDepth.renderTarget2;
+
+		// create light proxy mesh
+
+		var meshLight = new THREE.Mesh( geometryLight, materialLight );
+		meshLight.position = light.position;
+		meshLight.scale.multiplyScalar( light.distance );
+
+		// keep reference for size reset
+
+		lightMaterials.push( materialLight );
+
+		return meshLight;
+
+	};
+
+	var createDeferredDirectionalLight = function ( light ) {
+
+		// setup light material
+
+		var materialLight = new THREE.ShaderMaterial( {
+
+			uniforms:       THREE.UniformsUtils.clone( directionalLightShader.uniforms ),
+			vertexShader:   directionalLightShader.vertexShader,
+			fragmentShader: directionalLightShader.fragmentShader,
+
+			blending:		THREE.AdditiveBlending,
+			depthWrite:		false,
+			transparent:	true
+
+		} );
+
+		materialLight.uniforms[ "lightDir" ].value = light.position;
+		materialLight.uniforms[ "lightIntensity" ].value = light.intensity;
+		materialLight.uniforms[ "lightColor" ].value = light.color;
+
+		materialLight.uniforms[ "viewWidth" ].value = scaledWidth;
+		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
+
+		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
+		materialLight.uniforms[ 'samplerNormalDepth' ].value = compNormalDepth.renderTarget2;
+
+		// create light proxy mesh
+
+		var geometryLight = new THREE.PlaneGeometry( 2, 2 );
+		var meshLight = new THREE.Mesh( geometryLight, materialLight );
+
+		// keep reference for size reset
+
+		lightMaterials.push( materialLight );
+
+		return meshLight;
+
+	};
+
+	var createDeferredEmissiveLight = function () {
+
+		// setup light material
+
+		var materialLight = new THREE.ShaderMaterial( {
+
+			uniforms:       THREE.UniformsUtils.clone( emissiveLightShader.uniforms ),
+			vertexShader:   emissiveLightShader.vertexShader,
+			fragmentShader: emissiveLightShader.fragmentShader,
+			depthTest:		false,
+			depthWrite:		false,
+			blending:		THREE.NoBlending
+
+		} );
+
+
+		materialLight.uniforms[ "viewWidth" ].value = scaledWidth;
+		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
+
+		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
+
+		// create light proxy mesh
+
+		var geometryLight = new THREE.PlaneGeometry( 2, 2 );
+		var meshLight = new THREE.Mesh( geometryLight, materialLight );
+
+		// keep reference for size reset
+
+		lightMaterials.push( materialLight );
+
+		return meshLight;
+
+	};
+
+	var initDeferredProperties = function ( object ) {
+
+		if ( object.properties.deferredInitialized ) return;
+
+		if ( object.material ) initDeferredMaterials( object );
+
+		if ( object instanceof THREE.PointLight ) {
+
+			var meshLight = createDeferredPointLight( object );
+			lightSceneProxy.add( meshLight );
+
+		} else if ( object instanceof THREE.DirectionalLight ) {
+
+			var meshLight = createDeferredDirectionalLight( object );
+			lightSceneFullscreen.add( meshLight );
+
+		}
+
+		object.properties.deferredInitialized = true;
+
+	};
+
+	//
+
+	var setMaterialColor = function ( object ) {
+
+		if ( object.material ) object.material = object.properties.colorMaterial;
+
+	};
+
+	var setMaterialNormalDepth = function ( object ) {
+
+		if ( object.material ) object.material = object.properties.normalDepthMaterial;
+
+	};
+
+	//
+
+	this.setSize = function ( width, height ) {
+
+		this.renderer.setSize( width, height );
+
+		scaledWidth = Math.floor( scale * width );
+		scaledHeight = Math.floor( scale * height );
+
+		compColor.setSize( scaledWidth, scaledHeight );
+		compNormalDepth.setSize( scaledWidth, scaledHeight );
+		compLight.setSize( scaledWidth, scaledHeight );
+		compFinal.setSize( scaledWidth, scaledHeight );
+
+		for ( var i = 0, il = lightMaterials.length; i < il; i ++ ) {
+
+			var uniforms = lightMaterials[ i ].uniforms;
+
+			uniforms[ "viewWidth" ].value = scaledWidth;
+			uniforms[ "viewHeight" ].value = scaledHeight;
+
+			uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
+
+			if ( uniforms[ 'samplerNormalDepth' ] ) {
+
+				uniforms[ 'samplerNormalDepth' ].value = compNormalDepth.renderTarget2;
+
+			}
+
+		}
+
+		compositePass.uniforms[ 'samplerLight' ].value = compLight.renderTarget2;
+
+		effectFXAA.uniforms[ 'resolution' ].value.set( 1 / width, 1 / height );
+
+	};
+
+	//
+
+	this.render = function ( scene, camera ) {
+
+		// setup deferred properties
+
+		if ( ! scene.properties.lightSceneProxy ) {
+
+			scene.properties.lightSceneProxy = new THREE.Scene();
+			scene.properties.lightSceneFullscreen = new THREE.Scene();
+
+			var meshLight = createDeferredEmissiveLight();
+			scene.properties.lightSceneFullscreen.add( meshLight );
+
+		}
+
+		lightSceneProxy = scene.properties.lightSceneProxy;
+		lightSceneFullscreen = scene.properties.lightSceneFullscreen;
+
+		passColor.camera = camera;
+		passNormalDepth.camera = camera;
+		passLightProxy.camera = camera;
+		passLightFullscreen.camera = THREE.EffectComposer.camera;
+
+		passColor.scene = scene;
+		passNormalDepth.scene = scene;
+		passLightFullscreen.scene = lightSceneFullscreen;
+		passLightProxy.scene = lightSceneProxy;
+
+		scene.traverse( initDeferredProperties );
+
+		// update scene graph only once per frame
+
+		this.renderer.autoUpdateScene = false;
+		scene.updateMatrixWorld();
+
+		// g-buffer color
+
+		scene.traverse( setMaterialColor );
+		compColor.render();
+
+		// g-buffer normals + depth
+
+		scene.traverse( setMaterialNormalDepth );
+		compNormalDepth.render();
+
+		this.renderer.autoUpdateScene = true;
+
+		// light pass
+
+		camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
+
+		for ( var i = 0, il = lightSceneProxy.children.length; i < il; i ++ ) {
+
+			var uniforms = lightSceneProxy.children[ i ].material.uniforms;
+
+			uniforms[ "matProjInverse" ].value = camera.projectionMatrixInverse;
+			uniforms[ "matView" ].value = camera.matrixWorldInverse;
+
+		}
+
+		for ( var i = 0, il = lightSceneFullscreen.children.length; i < il; i ++ ) {
+
+			var uniforms = lightSceneFullscreen.children[ i ].material.uniforms;
+
+			if ( uniforms[ "matView" ] ) uniforms[ "matView" ].value = camera.matrixWorldInverse;
+
+		}
+
+		compLight.render();
+
+		// composite pass
+
+		compFinal.render( 0.1 );
+
+	};
+
+	var createRenderTargets = function ( ) {
+
+		var rtParamsFloatLinear = { minFilter: THREE.NearestFilter, magFilter: THREE.LinearFilter, stencilBuffer: false,
+									format: THREE.RGBAFormat, type: THREE.FloatType };
+
+		var rtParamsFloatNearest = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, stencilBuffer: false,
+									 format: THREE.RGBAFormat, type: THREE.FloatType };
+
+		var rtParamsUByte = { minFilter: THREE.NearestFilter, magFilter: THREE.LinearFilter, stencilBuffer: false,
+							  format: THREE.RGBFormat, type: THREE.UnsignedByteType };
+
+		// g-buffers
+
+		var rtColor   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatNearest );
+		var rtNormalDepth = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
+		var rtLight   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
+		var rtFinal   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsUByte );
+
+		rtColor.generateMipmaps = false;
+		rtNormalDepth.generateMipmaps = false;
+		rtLight.generateMipmaps = false;
+		rtFinal.generateMipmaps = false;
+
+		// color composer
+
+		passColor = new THREE.RenderPass();
+		passColor.clear = true;
+
+		compColor = new THREE.EffectComposer( _this.renderer, rtColor );
+		compColor.addPass( passColor );
+
+		// normal + depth composer
+
+		passNormalDepth = new THREE.RenderPass();
+		passNormalDepth.clear = true;
+
+		compNormalDepth = new THREE.EffectComposer( _this.renderer, rtNormalDepth );
+		compNormalDepth.addPass( passNormalDepth );
+
+		// light composer
+
+		passLightFullscreen = new THREE.RenderPass();
+		passLightFullscreen.clear = true;
+
+		passLightProxy = new THREE.RenderPass();
+		passLightProxy.clear = false;
+
+		compLight = new THREE.EffectComposer( _this.renderer, rtLight );
+		compLight.addPass( passLightFullscreen );
+		compLight.addPass( passLightProxy );
+
+		// final composer
+
+		compositePass = new THREE.ShaderPass( compositeShader );
+		compositePass.uniforms[ 'samplerLight' ].value = compLight.renderTarget2;
+		compositePass.uniforms[ 'brightness' ].value = brightness;
+		compositePass.material.blending = THREE.NoBlending;
+		compositePass.clear = true;
+
+		// FXAA
+
+		effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
+		effectFXAA.uniforms[ 'resolution' ].value.set( 1 / width, 1 / height );
+		effectFXAA.renderToScreen = true;
+
+		//
+
+		compFinal = new THREE.EffectComposer( _this.renderer, rtFinal );
+		compFinal.addPass( compositePass );
+		compFinal.addPass( effectFXAA );
+
+	};
+
+	// init
+
+	createRenderTargets();
+
+};

+ 45 - 38
examples/webgl_lights_deferred_morphs.html

@@ -51,12 +51,11 @@
 
 		<script src="js/Detector.js"></script>
 
+		<script src="js/renderers/WebGLDeferredRenderer.js"></script>
 		<script src="js/ShaderDeferred.js"></script>
-		<script src="js/DeferredHelper.js"></script>
 
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/FXAAShader.js"></script>
-		<script src="js/shaders/ColorCorrectionShader.js"></script>
 
 		<script src="js/postprocessing/EffectComposer.js"></script>
 		<script src="js/postprocessing/RenderPass.js"></script>
@@ -73,12 +72,8 @@
 			var WIDTH = window.innerWidth;
 			var HEIGHT = window.innerHeight - 2 * MARGIN;
 
-			var SCALED_WIDTH = Math.floor( SCALE * WIDTH );
-			var SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
-
 			var NEAR = 1.0, FAR = 350.0;
 			var VIEW_ANGLE = 45;
-			var ASPECT = WIDTH / HEIGHT;
 
 			// controls
 
@@ -116,9 +111,7 @@
 
 				// renderer
 
-				renderer = new THREE.WebGLRenderer( { alpha: false } );
-				renderer.setSize( WIDTH, HEIGHT );
-				renderer.setClearColorHex( 0x000000, 1 );
+				renderer = new THREE.WebGLDeferredRenderer( { width: WIDTH, height: HEIGHT, scale: SCALE, brightness: 2 } );
 
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.top = MARGIN + "px";
@@ -129,7 +122,7 @@
 
 				// camera
 
-				camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR );
+				camera = new THREE.PerspectiveCamera( VIEW_ANGLE, WIDTH / HEIGHT, NEAR, FAR );
 				camera.position.z = 150;
 
 				// scene
@@ -149,11 +142,6 @@
 
 				clock = new THREE.Clock();
 
-				// deferred helper
-
-				deferredHelper = new THREE.DeferredHelper( { renderer: renderer, scene: scene, camera: camera, width: SCALED_WIDTH, height: SCALED_HEIGHT } );
-				deferredHelper.createRenderTargets();
-
 				// add lights
 
 				initLights();
@@ -165,22 +153,11 @@
 				// events
 
 				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
+				window.addEventListener( 'resize', onWindowResize, false );
 
 			}
 
 
-			// -----------------------------
-
-			function addObject( object, y, scale ) {
-
-				deferredHelper.addDeferredMaterials( object );
-
-				object.position.y = y;
-				object.scale.set( scale, scale, scale );
-				scene.add( object );
-
-			}
-
 			// -----------------------------
 
 			function initLights() {
@@ -190,6 +167,7 @@
 				// front light
 
 				var light = new THREE.PointLight( 0xffffff, 1.5, 1.5 * distance );
+				scene.add( light );
 				lights.push( light );
 
 				// random lights
@@ -205,11 +183,26 @@
 					light.color.setRGB( c.x, c.y, c.z );
 					light.color.convertGammaToLinear();
 
+					scene.add( light );
 					lights.push( light );
 
 				}
 
-				deferredHelper.addDeferredLights( lights, true );
+				var geometry = new THREE.SphereGeometry( 0.7, 7, 7 );
+
+				for ( var i = 0; i < numLights; i ++ ) {
+
+					var light = lights[ i ];
+
+					var material = new THREE.MeshBasicMaterial();
+					material.color = light.color;
+
+					var emitter = new THREE.Mesh( geometry, material );
+					emitter.position = light.position;
+
+					scene.add( emitter );
+
+				}
 
 			}
 
@@ -222,28 +215,26 @@
 
 					geometry.computeMorphNormals();
 
-					var material = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x333333, shininess: 20, morphTargets: true, morphNormals: true, vertexColors: THREE.NoColors, shading: THREE.FlatShading } );
+					var material = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x333333, shininess: 20, wrapAround: true, morphTargets: true, morphNormals: true, vertexColors: THREE.NoColors, shading: THREE.FlatShading } );
 					var meshAnim = new THREE.MorphAnimMesh( geometry, material );
 
 					meshAnim.duration = 3000;
 					meshAnim.properties.delta = -13;
 
-					var s = 1;
-					meshAnim.scale.set( s, s, s );
-					meshAnim.position.x = 180;
-					meshAnim.position.z = -10;
+					meshAnim.scale.multiplyScalar( 50 );
+					meshAnim.position.set( 180, -48, -10 );
 					meshAnim.rotation.y = -Math.PI/2;
 
+					scene.add( meshAnim );
 					morphs.push( meshAnim );
 
-					addObject( meshAnim, -48, 50 );
-
 				} );
 
 				// add box
 
-				var object = generateBox();
-				addObject( object, 0, 8 );
+				var box = generateBox();
+				box.scale.multiplyScalar( 8 );
+				scene.add( box );
 
 			}
 
@@ -318,6 +309,21 @@
 
 			// -----------------------------
 
+			function onWindowResize( event ) {
+
+				windowHalfX = window.innerWidth / 2;
+				windowHalfY = window.innerHeight / 2;
+
+				WIDTH = window.innerWidth;
+				HEIGHT = window.innerHeight - 2 * MARGIN;
+
+				renderer.setSize( WIDTH, HEIGHT );
+
+				camera.aspect = WIDTH / HEIGHT;
+				camera.updateProjectionMatrix();
+
+			}
+
 			function onDocumentMouseMove( event ) {
 
 				mouseX = ( event.clientX - windowHalfX ) * 1;
@@ -391,8 +397,9 @@
 
 				camera.lookAt( target );
 
+				// render
 
-				deferredHelper.render();
+				renderer.render( scene, camera );
 
 			}
 

+ 80 - 39
examples/webgl_lights_deferred_pointlights.html

@@ -50,12 +50,11 @@
 		<script src="js/Detector.js"></script>
 		<script src="js/libs/stats.min.js"></script>
 
+		<script src="js/renderers/WebGLDeferredRenderer.js"></script>
 		<script src="js/ShaderDeferred.js"></script>
-		<script src="js/DeferredHelper.js"></script>
 
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/FXAAShader.js"></script>
-		<script src="js/shaders/ColorCorrectionShader.js"></script>
 
 		<script src="js/postprocessing/EffectComposer.js"></script>
 		<script src="js/postprocessing/RenderPass.js"></script>
@@ -77,12 +76,8 @@
 			var WIDTH = window.innerWidth;
 			var HEIGHT = window.innerHeight - 2 * MARGIN;
 
-			var SCALED_WIDTH = Math.floor( SCALE * WIDTH );
-			var SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
-
 			var NEAR = 1.0, FAR = 350.0;
 			var VIEW_ANGLE = 45;
-			var ASPECT = WIDTH / HEIGHT;
 
 			// controls
 
@@ -116,9 +111,7 @@
 
 				// renderer
 
-				renderer = new THREE.WebGLRenderer( { alpha: false } );
-				renderer.setSize( WIDTH, HEIGHT );
-				renderer.setClearColorHex( 0x000000, 1 );
+				renderer = new THREE.WebGLDeferredRenderer( { width: WIDTH, height: HEIGHT, scale: SCALE, brightness: 2 } );
 
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.top = MARGIN + "px";
@@ -129,7 +122,7 @@
 
 				// camera
 
-				camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR );
+				camera = new THREE.PerspectiveCamera( VIEW_ANGLE, WIDTH / HEIGHT, NEAR, FAR );
 				camera.position.z = 150;
 
 				// scene
@@ -149,11 +142,6 @@
 
 				clock = new THREE.Clock();
 
-				// deferred helper
-
-				deferredHelper = new THREE.DeferredHelper( { renderer: renderer, scene: scene, camera: camera, width: SCALED_WIDTH, height: SCALED_HEIGHT } );
-				deferredHelper.createRenderTargets();
-
 				// add lights
 
 				initLights();
@@ -165,19 +153,7 @@
 				// events
 
 				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
-
-			}
-
-			// -----------------------------
-
-			function addObject( object, y, scale ) {
-
-				deferredHelper.addDeferredMaterials( object );
-
-				object.position.y = y;
-				object.scale.set( scale, scale, scale );
-
-				scene.add( object );
+				window.addEventListener( 'resize', onWindowResize, false );
 
 			}
 
@@ -190,6 +166,7 @@
 				// front light
 
 				var light = new THREE.PointLight( 0xffffff, 1.5, 1.5 * distance );
+				scene.add( light );
 				lights.push( light );
 
 				// random lights
@@ -205,11 +182,26 @@
 					light.color.setRGB( c.x, c.y, c.z );
 					light.color.convertGammaToLinear();
 
+					scene.add( light );
 					lights.push( light );
 
 				}
 
-				deferredHelper.addDeferredLights( lights, false );
+				var geometry = new THREE.SphereGeometry( 0.7, 7, 7 );
+
+				for ( var i = 0; i < numLights; i ++ ) {
+
+					var light = lights[ i ];
+
+					var material = new THREE.MeshBasicMaterial();
+					material.color = light.color;
+
+					var emitter = new THREE.Mesh( geometry, material );
+					emitter.position = light.position;
+
+					scene.add( emitter );
+
+				}
 
 			}
 
@@ -223,20 +215,22 @@
 
 				loader.load( "models/utf8/ben_dds.js", function ( object ) {
 
-					addObject( object, -75, 150 );
-					animate();
+					object.scale.multiplyScalar( 150 );
+					object.position.y = -75;
+					scene.add( object );
 
 				}, { normalizeRGB: true } );
 
 				loader.load( "models/utf8/WaltHi.js", function ( object ) {
 
-					addObject( object, -35, 1 );
-					animate();
+					object.position.y = -35;
+					scene.add( object );
 
 				}, { normalizeRGB: true } );
 
 				*/
 
+
 				var loader = new THREE.JSONLoader();
 				loader.load( "obj/leeperrysmith/LeePerrySmith.js", function( geometry, materials ) {
 
@@ -248,17 +242,45 @@
 					mapHeight.anisotropy = 4;
 					mapHeight.format = THREE.RGBFormat;
 
-					var material = new THREE.MeshPhongMaterial( { map: mapColor, bumpMap: mapHeight, bumpScale: 2.5, shininess: 75, specular: 0x090909 } );
+					var material = new THREE.MeshPhongMaterial( { map: mapColor, bumpMap: mapHeight, bumpScale: 2.5, shininess: 75, specular: 0x090909, wrapAround: true, metal: true } );
 
 					var object = new THREE.Mesh( geometry, material );
-					addObject( object, 0, 8 );
+					object.scale.multiplyScalar( 8 );
+					scene.add( object );
+
+				} );
+
+
+				var loader = new THREE.BinaryLoader();
+				loader.load( "obj/female02/Female02_bin.js", function( geometry, materials ) {
+
+					for ( var i = 0; i < materials.length; i ++ ) materials[ i ].wrapAround = true;
+
+					var object = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
+					object.position.x = -50;
+					object.position.y = -48;
+					object.scale.multiplyScalar( 0.45 );
+					scene.add( object );
+
+				} );
+
+				loader.load( "obj/male02/Male02_bin.js", function( geometry, materials ) {
+
+					for ( var i = 0; i < materials.length; i ++ ) materials[ i ].wrapAround = true;
+
+					var object = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
+					object.position.x = 50;
+					object.position.y = -48;
+					object.scale.multiplyScalar( 0.45 );
+					scene.add( object );
 
 				} );
 
 				// create box
 
-				var object = generateBox();
-				addObject( object, 0, 8 );
+				var box = generateBox();
+				box.scale.multiplyScalar( 8 );
+				scene.add( box );
 
 			}
 
@@ -284,7 +306,7 @@
 
 				var matPlane  = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess:  50, bumpMap: mapHeight2, bumpScale: 0.5 } );
 				var matPlane2 = new THREE.MeshPhongMaterial( { color: 0x331919, specular: 0x111111, shininess:  50, bumpMap: mapHeight2, bumpScale: 1 } );
-				var matPlane3 = new THREE.MeshPhongMaterial( { color: 0x00aaff, specular: 0xffffff, shininess: 200, bumpMap: mapHeight3, bumpScale: 1.2 } );
+				var matPlane3 = new THREE.MeshPhongMaterial( { color: 0x00aaff, specular: 0xffffff, shininess: 200, bumpMap: mapHeight3, bumpScale: 1.2, wrapAround: true } );
 				var matPlane4 = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess:  50, bumpMap: mapHeight3, bumpScale: 1 } );
 
 				// bottom
@@ -334,6 +356,21 @@
 
 			// -----------------------------
 
+			function onWindowResize( event ) {
+
+				windowHalfX = window.innerWidth / 2;
+				windowHalfY = window.innerHeight / 2;
+
+				WIDTH = window.innerWidth;
+				HEIGHT = window.innerHeight - 2 * MARGIN;
+
+				renderer.setSize( WIDTH, HEIGHT );
+
+				camera.aspect = WIDTH / HEIGHT;
+				camera.updateProjectionMatrix();
+
+			}
+
 			function onDocumentMouseMove( event ) {
 
 				mouseX = ( event.clientX - windowHalfX ) * 1;
@@ -381,6 +418,8 @@
 
 				}
 
+				// update camera
+
 				var delta = clock.getDelta();
 
 				targetX = mouseX * .001;
@@ -393,7 +432,9 @@
 
 				camera.lookAt( target );
 
-				deferredHelper.render();
+				// render
+
+				renderer.render( scene, camera );
 
 			}
 

+ 3 - 6
examples/webgl_marching_cubes.html

@@ -185,7 +185,7 @@
 
 			renderer.autoClear = false;
 
-			renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
+			var renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
 			renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
 
 			effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
@@ -235,14 +235,11 @@
 			SCREEN_WIDTH = window.innerWidth;
 			SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 
-			renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
-
 			camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 			camera.updateProjectionMatrix();
 
-			renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
-
-			composer.reset( renderTarget );
+			renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
+			composer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
 
 			hblur.uniforms[ 'h' ].value = 4 / SCREEN_WIDTH;
 			vblur.uniforms[ 'v' ].value = 4 / SCREEN_HEIGHT;

+ 4 - 7
examples/webgl_materials_cubemap_dynamic.html

@@ -100,7 +100,7 @@
 			var container, stats;
 
 			var camera, cameraTarget, scene, renderer;
-			var renderTarget, renderTargetParameters;
+			var renderTarget;
 
 			var spotLight, ambientLight;
 
@@ -412,7 +412,7 @@
 
 				renderer.autoClear = false;
 
-				renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
+				var renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
 				renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
 
 				effectSave = new THREE.SavePass( new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters ) );
@@ -768,14 +768,11 @@
 				SCREEN_WIDTH = window.innerWidth;
 				SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 
-				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
-
 				camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 				camera.updateProjectionMatrix();
 
-				renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
-
-				composer.reset( renderTarget );
+				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
+				composer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
 
 				hblur.uniforms[ 'h' ].value = 10.75 / SCREEN_WIDTH;
 				vblur.uniforms[ 'v' ].value = 10.75 / SCREEN_HEIGHT;

+ 2 - 2
examples/webgl_materials_video.html

@@ -214,8 +214,8 @@
 
 					for ( j = 0; j < uv.length; j++ ) {
 
-						uv[j].u = ( uv[j].u + offsetx ) * unitx;
-						uv[j].v = ( uv[j].v + offsety ) * unity;
+						uv[j].x = ( uv[j].x + offsetx ) * unitx;
+						uv[j].y = ( uv[j].y + offsety ) * unity;
 
 					}
 

+ 8 - 10
examples/webgl_postprocessing.html

@@ -83,8 +83,6 @@
 
 			var materialColor, material2D, quadBG, quadMask, renderScene;
 
-			var rtParameters;
-
 			var delta = 0.01;
 
 			init();
@@ -207,7 +205,7 @@
 
 				//
 
-				rtParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: true };
+				var rtParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: true };
 
 				var rtWidth  = width / 2;
 				var rtHeight = height / 2;
@@ -294,8 +292,6 @@
 				halfWidth = window.innerWidth / 2;
 				halfHeight = window.innerHeight / 2;
 
-				renderer.setSize( window.innerWidth, window.innerHeight );
-
 				cameraPerspective.aspect = window.innerWidth / window.innerHeight;
 				cameraPerspective.updateProjectionMatrix();
 
@@ -306,12 +302,14 @@
 
 				cameraOrtho.updateProjectionMatrix();
 
-				composerScene.reset( new THREE.WebGLRenderTarget( halfWidth * 2, halfHeight * 2, rtParameters ) );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				composerScene.setSize( halfWidth * 2, halfHeight * 2 );
 
-				composer1.reset( new THREE.WebGLRenderTarget( halfWidth, halfHeight, rtParameters ) );
-				composer2.reset( new THREE.WebGLRenderTarget( halfWidth, halfHeight, rtParameters ) );
-				composer3.reset( new THREE.WebGLRenderTarget( halfWidth, halfHeight, rtParameters ) );
-				composer4.reset( new THREE.WebGLRenderTarget( halfWidth, halfHeight, rtParameters ) );
+				composer1.setSize( halfWidth, halfHeight );
+				composer2.setSize( halfWidth, halfHeight );
+				composer3.setSize( halfWidth, halfHeight );
+				composer4.setSize( halfWidth, halfHeight );
 
 				renderScene.uniforms[ "tDiffuse" ].value = composerScene.renderTarget2;
 

+ 3 - 6
examples/webgl_shading_physical.html

@@ -398,7 +398,7 @@
 
 				renderer.autoClear = false;
 
-				renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
+				var renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
 				renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
 
 				effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
@@ -497,14 +497,11 @@
 				SCREEN_WIDTH = window.innerWidth;
 				SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 
-				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
-
 				camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 				camera.updateProjectionMatrix();
 
-				renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
-
-				composer.reset( renderTarget );
+				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
+				composer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
 
 				hblur.uniforms[ 'h' ].value = 4 / SCREEN_WIDTH;
 				vblur.uniforms[ 'v' ].value = 4 / SCREEN_HEIGHT;

+ 276 - 0
src/core/Box2.js

@@ -0,0 +1,276 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+THREE.Box2 = function ( min, max ) {
+
+	if ( min === undefined && max === undefined ) {
+
+		this.min = new THREE.Vector2();
+		this.max = new THREE.Vector2();
+		this.makeEmpty();
+
+	} else {
+		this.min = min.clone();
+		if( max === undefined ) {
+			this.max = new THREE.Vector2().copy( this.min ); // This is done on purpose so you can make a box using a single point and then expand it.
+		}
+		else {
+			this.max = max.clone();
+		}
+	}
+
+};
+
+THREE.Box2.prototype = {
+
+	constructor: THREE.Box2,
+
+	set: function ( min, max ) {
+
+		this.min.copy( min );
+		this.max.copy( max );
+
+		return this;
+	},
+
+	setFromPoints: function ( points ) {
+
+		if ( points.length > 0 ) {
+
+			var p = points[ 0 ];
+
+			this.min.copy( p );
+			this.max.copy( p );
+
+			for ( var i = 1, il = points.length; i < il; i ++ ) {
+
+				p = points[ i ];
+
+				if ( p.x < this.min.x ) {
+
+					this.min.x = p.x;
+
+				} else if ( p.x > this.max.x ) {
+
+					this.max.x = p.x;
+
+				}
+
+				if ( p.y < this.min.y ) {
+
+					this.min.y = p.y;
+
+				} else if ( p.y > this.max.y ) {
+
+					this.max.y = p.y;
+
+				}
+
+			}
+
+		} else {
+
+			this.makeEmpty();
+
+		}
+
+		return this;
+
+	},
+
+	setFromCenterAndSize: function ( center, size ) {
+
+		var halfSize = THREE.Box2.__v1.copy( size ).multiplyScalar( 0.5 );
+		this.min.copy( center ).subSelf( halfSize );
+		this.max.copy( center ).addSelf( halfSize );
+
+		return this;
+
+	},
+
+	copy: function ( box ) {
+
+		this.min.copy( box.min );
+		this.max.copy( box.max );
+
+		return this;
+
+	},
+
+	makeEmpty: function () {
+
+		this.min.x = this.min.y = Infinity;
+		this.max.x = this.max.y = -Infinity;
+
+		return this;
+
+	},
+
+	empty: function () {
+
+		// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
+
+		return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
+
+	},
+
+	volume: function () {
+
+		return ( this.max.x - this.min.x ) * ( this.max.y - this.min.y );
+
+	},
+
+	center: function () {
+
+		return new THREE.Vector2().add( this.min, this.max ).multiplyScalar( 0.5 );
+
+	},
+
+	size: function () {
+
+		return new THREE.Vector2().sub( this.max, this.min );
+
+	},
+
+	expandByPoint: function ( point ) {
+
+		this.min.minSelf( point );
+		this.max.maxSelf( point );
+
+		return this;
+	},
+
+	expandByVector: function ( vector ) {
+
+		this.min.subSelf( vector );
+		this.max.addSelf( vector );
+
+		return this;
+	},
+
+	expandByScalar: function ( scalar ) {
+
+		this.min.addScalar( -scalar );
+		this.max.addScalar( scalar );
+
+		return this;
+	},
+
+	containsPoint: function ( point ) {
+
+		if ( ( this.min.x <= point.x ) && ( point.x <= this.max.x ) &&
+			 ( this.min.y <= point.y ) && ( point.y <= this.max.y ) ) {
+
+			return true;
+
+		}
+
+		return false;
+
+	},
+
+	containsBox: function ( box ) {
+
+		if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
+			 ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
+
+			return true;
+
+		}
+
+		return false;
+
+	},
+
+	getParameter: function ( point ) {
+
+		// This can potentially have a divide by zero if the box
+		// has a size dimension of 0.
+
+		return new THREE.Vector2(
+			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
+			( point.y - this.min.y ) / ( this.max.y - this.min.y )
+		);
+
+	},
+
+	isIntersection: function ( box ) {
+
+		// using 6 splitting planes to rule out intersections.
+
+		if ( ( box.max.x < this.min.x ) || ( box.min.x > this.max.x ) ||
+			 ( box.max.y < this.min.y ) || ( box.min.y > this.max.y ) ) {
+
+			return false;
+
+		}
+
+		return true;
+
+	},
+
+	clampPoint: function ( point ) {
+
+		return new THREE.Vector2().copy( point ).clampSelf( this.min, this.max );
+
+	},
+
+	distanceToPoint: function ( point ) {
+
+		var clampedPoint = THREE.Box2.__v1.copy( point ).clampSelf( this.min, this.max );
+		return clampedPoint.subSelf( point ).length();
+
+	},
+
+	intersect: function ( box ) {
+
+		this.min.maxSelf( box.min );
+		this.max.minSelf( box.max );
+
+		return this;
+
+	},
+
+	union: function ( box ) {
+
+		this.min.minSelf( box.min );
+		this.max.maxSelf( box.max );
+
+		return this;
+
+	},
+
+	translate: function ( offset ) {
+
+		this.min.addSelf( offset );
+		this.max.addSelf( offset );
+
+		return this;
+
+	},
+
+	scale: function ( factor ) {
+
+		var sizeDeltaHalf = this.size().multiplyScalar( ( factor - 1 )  * 0.5 );
+		this.expandByVector( sizeDeltaHalf );
+
+		return this;
+
+	},
+
+	equals: function ( box ) {
+
+		return box.min.equals( this.min ) && box.max.equals( this.max );
+
+	},
+
+	clone: function () {
+
+		return new THREE.Box2().copy( this );
+
+	}
+
+};
+
+THREE.Box2.__v1 = new THREE.Vector2();

+ 301 - 0
src/core/Box3.js

@@ -0,0 +1,301 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+THREE.Box3 = function ( min, max ) {
+
+	if ( min === undefined && max === undefined ) {
+
+		this.min = new THREE.Vector3();
+		this.max = new THREE.Vector3();
+		this.makeEmpty();
+
+	} else {
+
+		this.min = min.clone();
+
+		if( max === undefined ) {
+
+			this.max = new THREE.Vector3().copy( this.min ); // This is done on purpose so you can make a box using a single point and then expand it.
+
+		} else {
+
+			this.max = max.clone();
+
+		}
+
+	}
+
+};
+
+THREE.Box3.prototype = {
+
+	constructor: THREE.Box3,
+
+	set: function ( min, max ) {
+
+		this.min.copy( min );
+		this.max.copy( max );
+
+		return this;
+
+	},
+
+	setFromPoints: function ( points ) {
+
+		if ( points.length > 0 ) {
+
+			var p = points[ 0 ];
+
+			this.min.copy( p );
+			this.max.copy( p );
+
+			for ( var i = 1, il = points.length; i < il; i ++ ) {
+
+				p = points[ i ];
+
+				if ( p.x < this.min.x ) {
+
+					this.min.x = p.x;
+
+				} else if ( p.x > this.max.x ) {
+
+					this.max.x = p.x;
+
+				}
+
+				if ( p.y < this.min.y ) {
+
+					this.min.y = p.y;
+
+				} else if ( p.y > this.max.y ) {
+
+					this.max.y = p.y;
+
+				}
+
+				if ( p.z < this.min.z ) {
+
+					this.min.z = p.z;
+
+				} else if ( p.z > this.max.z ) {
+
+					this.max.z = p.z;
+
+				}
+
+			}
+
+		} else {
+
+			this.makeEmpty();
+
+		}
+
+		return this;
+
+	},
+
+	setFromCenterAndSize: function ( center, size ) {
+
+		var halfSize = THREE.Box3.__v1.copy( size ).multiplyScalar( 0.5 );
+
+		this.min.copy( center ).subSelf( halfSize );
+		this.max.copy( center ).addSelf( halfSize );
+
+		return this;
+
+	},
+
+	copy: function ( box ) {
+
+		this.min.copy( box.min );
+		this.max.copy( box.max );
+
+		return this;
+
+	},
+
+	makeEmpty: function () {
+
+		this.min.x = this.min.y = this.min.z = Infinity;
+		this.max.x = this.max.y = this.max.z = -Infinity;
+
+		return this;
+
+	},
+
+	empty: function () {
+
+		// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
+
+		return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
+
+	},
+
+	volume: function () {
+
+		return ( this.max.x - this.min.x ) * ( this.max.y - this.min.y ) * ( this.max.z - this.min.z );
+
+	},
+
+	center: function () {
+
+		return new THREE.Vector3().add( this.min, this.max ).multiplyScalar( 0.5 );
+
+	},
+
+	size: function () {
+
+		return new THREE.Vector3().sub( this.max, this.min );
+
+	},
+
+	expandByPoint: function ( point ) {
+
+		this.min.minSelf( point );
+		this.max.maxSelf( point );
+
+		return this;
+
+	},
+
+	expandByVector: function ( vector ) {
+
+		this.min.subSelf( vector );
+		this.max.addSelf( vector );
+
+		return this;
+
+	},
+
+	expandByScalar: function ( scalar ) {
+
+		this.min.addScalar( -scalar );
+		this.max.addScalar( scalar );
+
+		return this;
+
+	},
+
+	containsPoint: function ( point ) {
+
+		if ( ( this.min.x <= point.x ) && ( point.x <= this.max.x ) &&
+			 ( this.min.y <= point.y ) && ( point.y <= this.max.y ) &&
+			 ( this.min.z <= point.z ) && ( point.z <= this.max.z ) ) {
+
+			return true;
+
+		}
+
+		return false;
+
+	},
+
+	containsBox: function ( box ) {
+
+		if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
+			 ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
+			 ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
+
+			return true;
+
+		}
+
+		return false;
+
+	},
+
+	getParameter: function ( point ) {
+
+		// This can potentially have a divide by zero if the box
+		// has a size dimension of 0.
+
+		return new THREE.Vector3(
+			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
+			( point.y - this.min.y ) / ( this.max.y - this.min.y ),
+			( point.z - this.min.z ) / ( this.max.z - this.min.z )
+		);
+
+	},
+
+	isIntersection: function ( box ) {
+
+		// using 6 splitting planes to rule out intersections.
+
+		if ( ( box.max.x < this.min.x ) || ( box.min.x > this.max.x ) ||
+			 ( box.max.y < this.min.y ) || ( box.min.y > this.max.y ) ||
+			 ( box.max.z < this.min.z ) || ( box.min.z > this.max.z ) ) {
+
+			return false;
+
+		}
+
+		return true;
+
+	},
+
+	clampPoint: function ( point ) {
+
+		return new THREE.Vector3().copy( point ).clampSelf( this.min, this.max );
+
+	},
+
+	distanceToPoint: function ( point ) {
+
+		var clampedPoint = THREE.Box3.__v1.copy( point ).clampSelf( this.min, this.max );
+		return clampedPoint.subSelf( point ).length();
+
+	},
+
+	intersect: function ( box ) {
+
+		this.min.maxSelf( box.min );
+		this.max.minSelf( box.max );
+
+		return this;
+
+	},
+
+	union: function ( box ) {
+
+		this.min.minSelf( box.min );
+		this.max.maxSelf( box.max );
+
+		return this;
+
+	},
+
+	translate: function ( offset ) {
+
+		this.min.addSelf( offset );
+		this.max.addSelf( offset );
+
+		return this;
+
+	},
+
+	scale: function ( factor ) {
+
+		var sizeDeltaHalf = this.size().multiplyScalar( ( factor - 1 )  * 0.5 );
+		this.expandByVector( sizeDeltaHalf );
+
+		return this;
+
+	},
+
+	equals: function ( box ) {
+
+		return box.min.equals( this.min ) && box.max.equals( this.max );
+
+	},
+
+	clone: function () {
+
+		return new THREE.Box3().copy( this );
+
+	}
+
+};
+
+THREE.Box3.__v1 = new THREE.Vector3();

+ 19 - 18
src/core/Frustum.js

@@ -1,18 +1,19 @@
 /**
  * @author mrdoob / http://mrdoob.com/
  * @author alteredq / http://alteredqualia.com/
+ * @author bhouston / http://exocortex.com
  */
 
 THREE.Frustum = function ( ) {
 
 	this.planes = [
 
-		new THREE.Vector4(),
-		new THREE.Vector4(),
-		new THREE.Vector4(),
-		new THREE.Vector4(),
-		new THREE.Vector4(),
-		new THREE.Vector4()
+		new THREE.Plane(),
+		new THREE.Plane(),
+		new THREE.Plane(),
+		new THREE.Plane(),
+		new THREE.Plane(),
+		new THREE.Plane()
 
 	];
 
@@ -20,7 +21,6 @@ THREE.Frustum = function ( ) {
 
 THREE.Frustum.prototype.setFromMatrix = function ( m ) {
 
-	var plane;
 	var planes = this.planes;
 
 	var me = m.elements;
@@ -29,17 +29,16 @@ THREE.Frustum.prototype.setFromMatrix = function ( m ) {
 	var me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
 	var me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
 
-	planes[ 0 ].set( me3 - me0, me7 - me4, me11 - me8, me15 - me12 );
-	planes[ 1 ].set( me3 + me0, me7 + me4, me11 + me8, me15 + me12 );
-	planes[ 2 ].set( me3 + me1, me7 + me5, me11 + me9, me15 + me13 );
-	planes[ 3 ].set( me3 - me1, me7 - me5, me11 - me9, me15 - me13 );
-	planes[ 4 ].set( me3 - me2, me7 - me6, me11 - me10, me15 - me14 );
-	planes[ 5 ].set( me3 + me2, me7 + me6, me11 + me10, me15 + me14 );
+	planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 );
+	planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 );
+	planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 );
+	planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 );
+	planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 );
+	planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 );
 
 	for ( var i = 0; i < 6; i ++ ) {
 
-		plane = planes[ i ];
-		plane.divideScalar( Math.sqrt( plane.x * plane.x + plane.y * plane.y + plane.z * plane.z ) );
+		planes[ i ].normalize();
 
 	}
 
@@ -47,15 +46,17 @@ THREE.Frustum.prototype.setFromMatrix = function ( m ) {
 
 THREE.Frustum.prototype.contains = function ( object ) {
 
-	var distance = 0.0;
 	var planes = this.planes;
+
 	var matrix = object.matrixWorld;
-	var me = matrix.elements;
+	var matrixPosition = matrix.getPosition();
 	var radius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis();
 
+	var distance = 0.0;
+
 	for ( var i = 0; i < 6; i ++ ) {
 
-		distance = planes[ i ].x * me[12] + planes[ i ].y * me[13] + planes[ i ].z * me[14] + planes[ i ].w;
+		distance = planes[ i ].distanceToPoint( matrixPosition );
 		if ( distance <= radius ) return false;
 
 	}

+ 8 - 77
src/core/Geometry.js

@@ -4,6 +4,7 @@
  * @author alteredq / http://alteredqualia.com/
  * @author mikael emtinger / http://gomo.se/
  * @author zz85 / http://www.lab4games.net/zz85/blog
+ * @author bhouston / http://exocortex.com
  */
 
 THREE.Geometry = function () {
@@ -479,10 +480,10 @@ THREE.Geometry.prototype = {
 			z1 = vB.z - vA.z;
 			z2 = vC.z - vA.z;
 
-			s1 = uvB.u - uvA.u;
-			s2 = uvC.u - uvA.u;
-			t1 = uvB.v - uvA.v;
-			t2 = uvC.v - uvA.v;
+			s1 = uvB.x - uvA.x;
+			s2 = uvC.x - uvA.x;
+			t1 = uvB.y - uvA.y;
+			t2 = uvC.y - uvA.y;
 
 			r = 1.0 / ( s1 * t2 - s2 * t1 );
 			sdir.set( ( t2 * x1 - t1 * x2 ) * r,
@@ -576,82 +577,12 @@ THREE.Geometry.prototype = {
 
 	computeBoundingBox: function () {
 
-		if ( ! this.boundingBox ) {
-
-			this.boundingBox = { min: new THREE.Vector3(), max: new THREE.Vector3() };
-
-		}
-
-		if ( this.vertices.length > 0 ) {
-
-			var position, firstPosition = this.vertices[ 0 ];
-
-			this.boundingBox.min.copy( firstPosition );
-			this.boundingBox.max.copy( firstPosition );
-
-			var min = this.boundingBox.min,
-				max = this.boundingBox.max;
-
-			for ( var v = 1, vl = this.vertices.length; v < vl; v ++ ) {
-
-				position = this.vertices[ v ];
-
-				if ( position.x < min.x ) {
-
-					min.x = position.x;
-
-				} else if ( position.x > max.x ) {
-
-					max.x = position.x;
-
-				}
-
-				if ( position.y < min.y ) {
-
-					min.y = position.y;
-
-				} else if ( position.y > max.y ) {
-
-					max.y = position.y;
-
-				}
-
-				if ( position.z < min.z ) {
-
-					min.z = position.z;
-
-				} else if ( position.z > max.z ) {
-
-					max.z = position.z;
-
-				}
-
-			}
-
-		} else {
-
-			this.boundingBox.min.set( 0, 0, 0 );
-			this.boundingBox.max.set( 0, 0, 0 );
-
-		}
-
+		this.boundingBox = new THREE.Box3().setFromPoints( this.vertices );
 	},
 
 	computeBoundingSphere: function () {
 
-		var maxRadiusSq = 0;
-
-		if ( this.boundingSphere === null ) this.boundingSphere = { radius: 0 };
-
-		for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
-
-			var radiusSq = this.vertices[ i ].lengthSq();
-			if ( radiusSq > maxRadiusSq ) maxRadiusSq = radiusSq;
-
-		}
-
-		this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
-
+		this.boundingSphere = new THREE.Sphere().setFromCenterAndPoints( new THREE.Vector3(), this.vertices );
 	},
 
 	/*
@@ -779,7 +710,7 @@ THREE.Geometry.prototype = {
 
 			for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
 
-				uvCopy.push( new THREE.UV( uv[ j ].u, uv[ j ].v ) );
+				uvCopy.push( new THREE.Vector2( uv[ j ].x, uv[ j ].y ) );
 
 			}
 

+ 160 - 0
src/core/Plane.js

@@ -0,0 +1,160 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+THREE.Plane = function ( normal, constant ) {
+
+	if ( normal === undefined && constant === undefined ) {
+
+		this.normal = new THREE.Vector3();
+		this.constant = 0;
+
+	} else {
+
+		this.normal = normal.clone();
+		this.constant = constant || 0;
+
+	}
+
+};
+
+THREE.Plane.prototype = {
+
+	constructor: THREE.Plane,
+
+	set: function ( normal, constant ) {
+
+		this.normal.copy( normal );
+		this.constant = constant;
+
+		return this;
+
+	},
+
+	setComponents: function ( x, y, z, w ) {
+
+		this.normal.set( x, y, z );
+		this.constant = w;
+
+		return this;
+
+	},
+
+	setFromNormalAndCoplanarPoint: function ( normal, point ) {
+
+		this.normal.copy( normal );
+		this.constant = - point.dot( normal );
+
+		return this;
+
+	},
+
+	setFromCoplanarPoints: function ( a, b, c ) {
+
+		var normal = THREE.Plane.__v1.sub( b, a ).cross(
+					 THREE.Plane.__v2.sub( c, a ) );
+
+		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
+
+		this.setFromNormalAndCoplanarPoint( normal, a );
+
+		return this;
+
+	},
+
+	copy: function ( plane ) {
+
+		this.normal.copy( plane.normal );
+		this.constant = plane.constant;
+
+		return this;
+
+	},
+
+	flip: function () {
+
+		this.normal.negate();
+
+		return this;
+
+	},
+
+	normalize: function () {
+
+		// Note: will lead to a divide by zero if the plane is invalid.
+
+		var inverseNormalLength = 1.0 / this.normal.length();
+		this.normal.multiplyScalar( inverseNormalLength );
+		this.constant *= inverseNormalLength;
+
+		return this;
+
+	},
+
+	distanceToPoint: function ( point ) {
+
+		return this.normal.dot( point ) + this.constant;
+
+	},
+
+	distanceToSphere: function ( sphere ) {
+
+		return this.distanceToPoint( sphere.center ) - sphere.radius;
+
+	},
+
+	projectPoint: function ( point ) {
+
+		return this.orthoPoint( point ).subSelf( point ).negate();
+
+	},
+
+	orthoPoint: function ( point ) {
+
+		var perpendicularMagnitude = this.distanceToPoint( point );
+
+		return new THREE.Vector3().copy( this.normal ).multiplyScalar( perpendicularMagnitude );
+
+	},
+
+	intersectsLine: function ( startPoint, endPoint ) {
+
+		// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
+
+		var startSign = this.distanceToPoint( startPoint );
+		var endSign = this.distanceToPoint( endPoint );
+
+		return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
+
+	},
+
+	coplanarPoint: function () {
+
+		return new THREE.Vector3().copy( this.normal ).multiplyScalar( - this.constant );
+
+	},
+
+	translate: function ( offset ) {
+
+		this.constant = - offset.dot( this.normal );
+
+		return this;
+
+	},
+
+	equals: function ( plane ) {
+
+		return plane.normal.equals( this.normal ) && ( plane.constant == this.constant );
+
+	},
+
+	clone: function () {
+
+		return new THREE.Plane().copy( this );
+
+	}
+
+};
+
+THREE.Plane.__v1 = new THREE.Vector3();
+THREE.Plane.__v2 = new THREE.Vector3();

+ 140 - 0
src/core/Sphere.js

@@ -0,0 +1,140 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+THREE.Sphere = function ( center, radius ) {
+
+
+	if ( center === undefined && radius === undefined ) {
+
+		this.center = new THREE.Vector3();
+		this.radius = 0;
+
+	} else {
+
+		this.center = center.clone();
+		this.radius = radius || 0;
+
+	}
+	
+};
+
+THREE.Sphere.prototype = {
+
+	constructor: THREE.Sphere,
+
+	set: function ( center, radius ) {
+
+		this.center.copy( center );
+		this.radius = radius;
+
+		return this;
+
+	},
+
+	setFromCenterAndPoints: function ( center, points ) {
+
+		var maxRadiusSq = 0;
+
+		for ( var i = 0, il = points.length; i < il; i ++ ) {
+
+			var radiusSq = center.distanceToSquared( points[ i ] );
+			maxRadiusSq = Math.max( maxRadiusSq, radiusSq );
+
+		}
+
+		this.center = center;
+		this.radius = Math.sqrt( maxRadiusSq );
+
+		return this;
+
+	},
+
+	copy: function ( sphere ) {
+
+		this.center.copy( sphere.center );
+		this.radius = sphere.radius;
+
+		return this;
+
+	},
+
+	empty: function () {
+
+		return ( this.radius <= 0 );
+
+	},
+
+	volume: function () {
+
+		return Math.PI * 4 / 3 * ( this.radius * this.radius * this.radius );
+
+	},
+
+	containsPoint: function ( point ) {
+
+		return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
+
+	},
+
+	distanceToPoint: function ( point ) {
+
+		return ( point.distanceTo( this.center ) - this.radius );
+
+	},
+
+	clampPoint: function ( point ) {
+
+		var deltaLengthSq = this.center.distanceToSquared( point );
+
+		var result = new THREE.Vector3().copy( point );
+
+		if ( deltaLengthSq > ( this.radius * this.radius ) ) {
+
+			result.subSelf( this.center ).normalize();
+			result.multiplyScalar( this.radius ).addSelf( this.center );
+
+		}
+
+		return result;
+
+	},
+
+	bounds: function () {
+
+		var box =  new THREE.Box3( this.center, this.center );
+		box.expandByScalar( this.radius );
+
+		return box;
+
+	},
+
+	translate: function ( offset ) {
+
+		this.center.addSelf( this.offset );
+
+		return this;
+
+	},
+
+	scale: function ( factor ) {
+
+		this.radius *= factor;
+
+		return this;
+
+	},
+
+	equals: function ( sphere ) {
+
+		return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
+
+	},
+
+	clone: function () {
+
+		return new THREE.Sphere3().copy( this );
+
+	}
+
+};

+ 2 - 41
src/core/UV.js

@@ -4,46 +4,7 @@
 
 THREE.UV = function ( u, v ) {
 
-	this.u = u || 0;
-	this.v = v || 0;
-
-};
-
-THREE.UV.prototype = {
-
-	constructor: THREE.UV,
-
-	set: function ( u, v ) {
-
-		this.u = u;
-		this.v = v;
-
-		return this;
-
-	},
-
-	copy: function ( uv ) {
-
-		this.u = uv.u;
-		this.v = uv.v;
-
-		return this;
-
-	},
-
-	lerpSelf: function ( uv, alpha ) {
-
-		this.u += ( uv.u - this.u ) * alpha;
-		this.v += ( uv.v - this.v ) * alpha;
-
-		return this;
-
-	},
-
-	clone: function () {
-
-		return new THREE.UV( this.u, this.v );
-
-	}
+	console.warn( 'THREE.UV has been DEPRECATED. Use THREE.Vector2 instead.')
+	return new THREE.Vector2( u, v );
 
 };

+ 89 - 0
src/core/Vector2.js

@@ -25,6 +25,22 @@ THREE.Vector2.prototype = {
 
 	},
 
+	setX: function ( x ) {
+
+		this.x = x;
+
+		return this;
+
+	},
+
+	setY: function ( y ) {
+
+		this.y = y;
+
+		return this;
+
+	},
+
 	copy: function ( v ) {
 
 		this.x = v.x;
@@ -34,6 +50,15 @@ THREE.Vector2.prototype = {
 
 	},
 
+	addScalar: function ( s ) {
+
+		this.x += s;
+		this.y += s;
+
+		return this;
+
+	},
+
 	add: function ( a, b ) {
 
 		this.x = a.x + b.x;
@@ -96,6 +121,70 @@ THREE.Vector2.prototype = {
 
 	},
 
+	minSelf: function ( v ) {
+
+		if ( this.x > v.x ) {
+
+			this.x = v.x;
+
+		}
+
+		if ( this.y > v.y ) {
+
+			this.y = v.y;
+
+		}
+
+		return this;
+
+	},
+
+	maxSelf: function ( v ) {
+
+		if ( this.x < v.x ) {
+
+			this.x = v.x;
+
+		}
+
+		if ( this.y < v.y ) {
+
+			this.y = v.y;
+
+		}
+
+		return this;
+
+	},
+
+	clampSelf: function ( min, max ) {
+
+		// This function assumes min < max, if this assumption isn't true it will not operate correctly
+
+		if ( this.x < min.x ) {
+
+			this.x = min.x;
+
+		} else if ( this.x > max.x ) {
+
+			this.x = max.x;
+
+		}
+
+		if ( this.y < min.y ) {
+
+			this.y = min.y;
+
+		} else if ( this.y > max.y ) {
+
+			this.y = max.y;
+
+		}
+
+		return this;
+
+	},
+
 	negate: function() {
 
 		return this.multiplyScalar( - 1 );

+ 91 - 2
src/core/Vector3.js

@@ -1,6 +1,6 @@
 /**
  * @author mrdoob / http://mrdoob.com/
- * @author kile / http://kile.stravaganza.org/
+ * @author *kile / http://kile.stravaganza.org/
  * @author philogb / http://blog.thejit.org/
  * @author mikael emtinger / http://gomo.se/
  * @author egraether / http://egraether.com/
@@ -174,6 +174,91 @@ THREE.Vector3.prototype = {
 
 	},
 
+	minSelf: function ( v ) {
+
+		if ( this.x > v.x ) {
+
+			this.x = v.x;
+
+		}
+
+		if ( this.y > v.y ) {
+
+			this.y = v.y;
+
+		}
+
+		if ( this.z > v.z ) {
+
+			this.z = v.z;
+
+		}
+
+		return this;
+
+	},
+
+	maxSelf: function ( v ) {
+
+		if ( this.x < v.x ) {
+
+			this.x = v.x;
+
+		}
+
+		if ( this.y < v.y ) {
+
+			this.y = v.y;
+
+		}
+
+		if ( this.z < v.z ) {
+
+			this.z = v.z;
+
+		}
+
+		return this;
+
+	},
+
+	clampSelf: function ( min, max ) {
+
+		// This function assumes min < max, if this assumption isn't true it will not operate correctly
+
+		if ( this.x < min.x ) {
+
+			this.x = min.x;
+
+		} else if ( this.x > max.x ) {
+
+			this.x = max.x;
+
+		}
+
+		if ( this.y < min.y ) {
+
+			this.y = min.y;
+
+		} else if ( this.y > max.y ) {
+
+			this.y = max.y;
+
+		}
+
+		if ( this.z < min.z ) {
+
+			this.z = min.z;
+
+		} else if ( this.z > max.z ) {
+
+			this.z = max.z;
+
+		}
+
+		return this;
+
+	},
 
 	negate: function() {
 
@@ -263,7 +348,11 @@ THREE.Vector3.prototype = {
 
 	distanceToSquared: function ( v ) {
 
-		return new THREE.Vector3().sub( this, v ).lengthSq();
+		var dx = this.x - v.x;
+		var dy = this.y - v.y;
+		var dz = this.z - v.z;
+
+		return dx * dx + dy * dy + dz * dz;
 
 	},
 

+ 157 - 1
src/core/Vector4.js

@@ -30,6 +30,38 @@ THREE.Vector4.prototype = {
 
 	},
 
+	setX: function ( x ) {
+
+		this.x = x;
+
+		return this;
+
+	},
+
+	setY: function ( y ) {
+
+		this.y = y;
+
+		return this;
+
+	},
+
+	setZ: function ( z ) {
+
+		this.z = z;
+
+		return this;
+
+	},
+
+	setW: function ( w ) {
+
+		this.w = w;
+
+		return this;
+
+	},
+
 	copy: function ( v ) {
 
 		this.x = v.x;
@@ -41,6 +73,17 @@ THREE.Vector4.prototype = {
 
 	},
 
+	addScalar: function ( s ) {
+
+		this.x += s;
+		this.y += s;
+		this.z += s;
+		this.w += s;
+
+		return this;
+
+	},
+
 	add: function ( a, b ) {
 
 		this.x = a.x + b.x;
@@ -118,6 +161,113 @@ THREE.Vector4.prototype = {
 
 	},
 
+	minSelf: function ( v ) {
+
+		if ( this.x > v.x ) {
+
+			this.x = v.x;
+
+		}
+
+		if ( this.y > v.y ) {
+
+			this.y = v.y;
+
+		}
+
+		if ( this.z > v.z ) {
+
+			this.z = v.z;
+
+		}
+
+		if ( this.w > v.w ) {
+
+			this.w = v.w;
+
+		}
+
+		return this;
+
+	},
+
+	maxSelf: function ( v ) {
+
+		if ( this.x < v.x ) {
+
+			this.x = v.x;
+
+		}
+
+		if ( this.y < v.y ) {
+
+			this.y = v.y;
+
+		}
+
+		if ( this.z < v.z ) {
+
+			this.z = v.z;
+
+		}
+
+		if ( this.w < v.w ) {
+
+			this.w = v.w;
+
+		}
+
+		return this;
+
+	},
+
+	clampSelf: function ( min, max ) {
+
+		// This function assumes min < max, if this assumption isn't true it will not operate correctly
+
+		if ( this.x < min.x ) {
+
+			this.x = min.x;
+
+		} else if ( this.x > max.x ) {
+
+			this.x = max.x;
+
+		}
+
+		if ( this.y < min.y ) {
+
+			this.y = min.y;
+
+		} else if ( this.y > max.y ) {
+
+			this.y = max.y;
+
+		}
+
+		if ( this.z < min.z ) {
+
+			this.z = min.z;
+
+		} else if ( this.z > max.z ) {
+
+			this.z = max.z;
+
+		}
+
+		if ( this.w < min.w ) {
+
+			this.w = min.w;
+
+		} else if ( this.w > max.w ) {
+
+			this.w = max.w;
+
+		}
+
+		return this;
+
+	},
 
 	negate: function() {
 
@@ -172,6 +322,12 @@ THREE.Vector4.prototype = {
 
 	},
 
+	equals: function ( v ) {
+
+		return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
+
+	},
+
 	clone: function () {
 
 		return new THREE.Vector4( this.x, this.y, this.z, this.w );
@@ -316,7 +472,7 @@ THREE.Vector4.prototype = {
 						 + ( m13 - m31 ) * ( m13 - m31 )
 						 + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
 
-		if ( Math.abs( s ) < 0.001 ) s = 1; 
+		if ( Math.abs( s ) < 0.001 ) s = 1;
 
 		// prevent divide by zero, should not happen if matrix is orthogonal and should be
 		// caught by singularity test above, but I've left it in just in case

+ 12 - 18
src/extras/GeometryUtils.js

@@ -102,7 +102,7 @@ THREE.GeometryUtils = {
 
 			for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
 
-				uvCopy.push( new THREE.UV( uv[ j ].u, uv[ j ].v ) );
+				uvCopy.push( new THREE.Vector2( uv[ j ].x, uv[ j ].y ) );
 
 			}
 
@@ -354,26 +354,19 @@ THREE.GeometryUtils = {
 
 	},
 
-	// Get triangle area (by Heron's formula)
-	// 	http://en.wikipedia.org/wiki/Heron%27s_formula
+	// Get triangle area (half of parallelogram)
+	//	http://mathworld.wolfram.com/TriangleArea.html
 
 	triangleArea: function ( vectorA, vectorB, vectorC ) {
 
-		var s, a, b, c,
-			tmp = THREE.GeometryUtils.__v1;
-
-		tmp.sub( vectorA, vectorB );
-		a = tmp.length();
-
-		tmp.sub( vectorA, vectorC );
-		b = tmp.length();
-
-		tmp.sub( vectorB, vectorC );
-		c = tmp.length();
+		var tmp1 = THREE.GeometryUtils.__v1,
+			tmp2 = THREE.GeometryUtils.__v2;
 
-		s = 0.5 * ( a + b + c );
+		tmp1.sub( vectorB, vectorA );
+		tmp2.sub( vectorC, vectorA );
+		tmp1.crossSelf( tmp2 );
 
-		return Math.sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) );
+		return 0.5 * tmp1.length();
 
 	},
 
@@ -412,8 +405,8 @@ THREE.GeometryUtils = {
 
 				// texture repeat
 
-				if( uvs[ j ].u !== 1.0 ) uvs[ j ].u = uvs[ j ].u - Math.floor( uvs[ j ].u );
-				if( uvs[ j ].v !== 1.0 ) uvs[ j ].v = uvs[ j ].v - Math.floor( uvs[ j ].v );
+				if( uvs[ j ].x !== 1.0 ) uvs[ j ].x = uvs[ j ].x - Math.floor( uvs[ j ].x );
+				if( uvs[ j ].y !== 1.0 ) uvs[ j ].y = uvs[ j ].y - Math.floor( uvs[ j ].y );
 
 			}
 
@@ -1045,3 +1038,4 @@ THREE.GeometryUtils = {
 THREE.GeometryUtils.random = THREE.Math.random16;
 
 THREE.GeometryUtils.__v1 = new THREE.Vector3();
+THREE.GeometryUtils.__v2 = new THREE.Vector3();

+ 10 - 22
src/extras/core/Curve.js

@@ -1,7 +1,7 @@
 /**
  * @author zz85 / http://www.lab4games.net/zz85/blog
  * Extensible curve object
- * 
+ *
  * Some common of Curve methods
  * .getPoint(t), getTangent(t)
  * .getPointAt(u), getTagentAt(u)
@@ -110,8 +110,8 @@ THREE.Curve.prototype.getLengths = function ( divisions ) {
 
 	if ( !divisions ) divisions = (this.__arcLengthDivisions) ? (this.__arcLengthDivisions): 200;
 
-	if ( this.cacheArcLengths 
-		&& ( this.cacheArcLengths.length == divisions + 1 ) 
+	if ( this.cacheArcLengths
+		&& ( this.cacheArcLengths.length == divisions + 1 )
 		&& !this.needsUpdate) {
 
 		//console.log( "cached", this.cacheArcLengths );
@@ -231,22 +231,10 @@ THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
 
 };
 
-
-// In 2D space, there are actually 2 normal vectors,
-// and in 3D space, infinte
-// TODO this should be depreciated.
-THREE.Curve.prototype.getNormalVector = function( t ) {
-
-	var vec = this.getTangent( t );
-
-	return new THREE.Vector2( -vec.y , vec.x );
-
-};
-
 // Returns a unit vector tangent at t
-// In case any sub curve does not implement its tangent / normal finding,
-// we get 2 points with a small delta and find a gradient of the 2 points
-// which seems to make a reasonable approximation
+// In case any sub curve does not implement its tangent derivation,
+// 2 points a small delta apart will be used to find its gradient
+// which seems to give a reasonable approximation
 
 THREE.Curve.prototype.getTangent = function( t ) {
 
@@ -261,7 +249,7 @@ THREE.Curve.prototype.getTangent = function( t ) {
 
 	var pt1 = this.getPoint( t1 );
 	var pt2 = this.getPoint( t2 );
-	
+
 	var vec = pt2.clone().subSelf(pt1);
 	return vec.normalize();
 
@@ -715,7 +703,7 @@ THREE.SplineCurve3 = THREE.Curve.create(
 // 	v.z = THREE.Curve.Utils.tangentSpline( t, pt0.z, pt1.z, pt2.z, pt3.z );
 
 // 	return v;
-		
+
 // }
 
 /**************************************************************
@@ -741,7 +729,7 @@ THREE.ClosedSplineCurve3 = THREE.Curve.create(
 
         intPoint = Math.floor( point );
         weight = point - intPoint;
-            
+
         intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
         c[ 0 ] = ( intPoint - 1 ) % points.length;
         c[ 1 ] = ( intPoint ) % points.length;
@@ -751,7 +739,7 @@ THREE.ClosedSplineCurve3 = THREE.Curve.create(
         v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
         v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
         v.z = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].z, points[ c[ 1 ] ].z, points[ c[ 2 ] ].z, points[ c[ 3 ] ].z, weight );
-        
+
         return v;
 
     }

+ 2 - 2
src/extras/geometries/CircleGeometry.js

@@ -13,7 +13,7 @@ THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
     segments = segments !== undefined ? Math.max( 3, segments ) : 8;
 
     var i, uvs = [],
-    center = new THREE.Vector3(), centerUV = new THREE.UV( 0.5, 0.5 );
+    center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
 
     this.vertices.push(center);
     uvs.push( centerUV );
@@ -26,7 +26,7 @@ THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
         vertex.y = radius * Math.sin( thetaStart + i / segments * thetaLength );
 
         this.vertices.push( vertex );
-        uvs.push( new THREE.UV( ( vertex.x / radius + 1 ) / 2, - ( vertex.y / radius + 1 ) / 2 + 1 ) );
+        uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, - ( vertex.y / radius + 1 ) / 2 + 1 ) );
 
     }
 

+ 1 - 1
src/extras/geometries/ConvexGeometry.js

@@ -162,7 +162,7 @@ THREE.ConvexGeometry = function( vertices ) {
 	function vertexUv( vertex ) {
 
 		var mag = vertex.length();
-		return new THREE.UV( vertex.x / mag, vertex.y / mag );
+		return new THREE.Vector2( vertex.x / mag, vertex.y / mag );
 
 	}
 

+ 4 - 4
src/extras/geometries/CubeGeometry.js

@@ -92,10 +92,10 @@ THREE.CubeGeometry = function ( width, height, depth, widthSegments, heightSegme
 
 				scope.faces.push( face );
 				scope.faceVertexUvs[ 0 ].push( [
-							new THREE.UV( ix / gridX, 1 - iy / gridY ),
-							new THREE.UV( ix / gridX, 1 - ( iy + 1 ) / gridY ),
-							new THREE.UV( ( ix + 1 ) / gridX, 1- ( iy + 1 ) / gridY ),
-							new THREE.UV( ( ix + 1 ) / gridX, 1 - iy / gridY )
+							new THREE.Vector2( ix / gridX, 1 - iy / gridY ),
+							new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY ),
+							new THREE.Vector2( ( ix + 1 ) / gridX, 1- ( iy + 1 ) / gridY ),
+							new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY )
 						] );
 
 			}

+ 3 - 3
src/extras/geometries/CylinderGeometry.js

@@ -36,7 +36,7 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radiusSegme
 			this.vertices.push( vertex );
 
 			verticesRow.push( this.vertices.length - 1 );
-			uvsRow.push( new THREE.UV( u, 1 - v ) );
+			uvsRow.push( new THREE.Vector2( u, 1 - v ) );
 
 		}
 
@@ -107,7 +107,7 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radiusSegme
 
 			var uv1 = uvs[ 0 ][ x ].clone();
 			var uv2 = uvs[ 0 ][ x + 1 ].clone();
-			var uv3 = new THREE.UV( uv2.u, 0 );
+			var uv3 = new THREE.Vector2( uv2.u, 0 );
 
 			this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
 			this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
@@ -134,7 +134,7 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radiusSegme
 
 			var uv1 = uvs[ y ][ x + 1 ].clone();
 			var uv2 = uvs[ y ][ x ].clone();
-			var uv3 = new THREE.UV( uv2.u, 1 );
+			var uv3 = new THREE.Vector2( uv2.u, 1 );
 
 			this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
 			this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );

+ 11 - 11
src/extras/geometries/ExtrudeGeometry.js

@@ -674,9 +674,9 @@ THREE.ExtrudeGeometry.WorldUVGenerator = {
 			cy = geometry.vertices[ indexC ].y;
 
 		return [
-			new THREE.UV( ax, ay ),
-			new THREE.UV( bx, by ),
-			new THREE.UV( cx, cy )
+			new THREE.Vector2( ax, ay ),
+			new THREE.Vector2( bx, by ),
+			new THREE.Vector2( cx, cy )
 		];
 
 	},
@@ -709,17 +709,17 @@ THREE.ExtrudeGeometry.WorldUVGenerator = {
 
 		if ( Math.abs( ay - by ) < 0.01 ) {
 			return [
-				new THREE.UV( ax, 1 - az ),
-				new THREE.UV( bx, 1 - bz ),
-				new THREE.UV( cx, 1 - cz ),
-				new THREE.UV( dx, 1 - dz )
+				new THREE.Vector2( ax, 1 - az ),
+				new THREE.Vector2( bx, 1 - bz ),
+				new THREE.Vector2( cx, 1 - cz ),
+				new THREE.Vector2( dx, 1 - dz )
 			];
 		} else {
 			return [
-				new THREE.UV( ay, 1 - az ),
-				new THREE.UV( by, 1 - bz ),
-				new THREE.UV( cy, 1 - cz ),
-				new THREE.UV( dy, 1 - dz )
+				new THREE.Vector2( ay, 1 - az ),
+				new THREE.Vector2( by, 1 - bz ),
+				new THREE.Vector2( cy, 1 - cz ),
+				new THREE.Vector2( dy, 1 - dz )
 			];
 		}
 	}

+ 5 - 5
src/extras/geometries/LatheGeometry.js

@@ -46,11 +46,11 @@ THREE.LatheGeometry = function ( points, steps, angle ) {
 
 			this.faceVertexUvs[ 0 ].push( [
 
-				new THREE.UV( 1 - i / _steps, k / kl ),
-				new THREE.UV( 1 - ( i + 1 ) / _steps, k / kl ),
-				new THREE.UV( 1 - ( i + 1 ) / _steps, ( k + 1 ) / kl ),
-				new THREE.UV( 1 - i / _steps, ( k + 1 ) / kl )
-				
+				new THREE.Vector2( 1 - i / _steps, k / kl ),
+				new THREE.Vector2( 1 - ( i + 1 ) / _steps, k / kl ),
+				new THREE.Vector2( 1 - ( i + 1 ) / _steps, ( k + 1 ) / kl ),
+				new THREE.Vector2( 1 - i / _steps, ( k + 1 ) / kl )
+
 			] );
 
 		}

+ 4 - 4
src/extras/geometries/ParametricGeometry.js

@@ -49,10 +49,10 @@ THREE.ParametricGeometry = function ( func, slices, stacks, useTris ) {
 			c = (i + 1) * sliceCount + j;
 			d = (i + 1) * sliceCount + j + 1;
 
-			uva = new THREE.UV( j / slices, i / stacks );
-			uvb = new THREE.UV( ( j + 1 ) / slices, i / stacks );
-			uvc = new THREE.UV( j / slices, ( i + 1 ) / stacks );
-			uvd = new THREE.UV( ( j + 1 ) / slices, ( i + 1 ) / stacks );
+			uva = new THREE.Vector2( j / slices, i / stacks );
+			uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
+			uvc = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
+			uvd = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
 
 			if ( useTris ) {
 

+ 4 - 4
src/extras/geometries/PlaneGeometry.js

@@ -56,10 +56,10 @@ THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments )
 
 			this.faces.push( face );
 			this.faceVertexUvs[ 0 ].push( [
-				new THREE.UV( ix / gridX, 1 - iz / gridZ ),
-				new THREE.UV( ix / gridX, 1 - ( iz + 1 ) / gridZ ),
-				new THREE.UV( ( ix + 1 ) / gridX, 1 - ( iz + 1 ) / gridZ ),
-				new THREE.UV( ( ix + 1 ) / gridX, 1 - iz / gridZ )
+				new THREE.Vector2( ix / gridX, 1 - iz / gridZ ),
+				new THREE.Vector2( ix / gridX, 1 - ( iz + 1 ) / gridZ ),
+				new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iz + 1 ) / gridZ ),
+				new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iz / gridZ )
 			] );
 
 		}

+ 3 - 3
src/extras/geometries/PolyhedronGeometry.js

@@ -48,7 +48,7 @@ THREE.PolyhedronGeometry = function ( vertices, faces, radius, detail ) {
 
 		var u = azimuth( vector ) / 2 / Math.PI + 0.5;
 		var v = inclination( vector ) / Math.PI + 0.5;
-		vertex.uv = new THREE.UV( u, 1 - v );
+		vertex.uv = new THREE.Vector2( u, 1 - v );
 
 		return vertex;
 
@@ -131,8 +131,8 @@ THREE.PolyhedronGeometry = function ( vertices, faces, radius, detail ) {
 
 	function correctUV( uv, vector, azimuth ) {
 
-		if ( ( azimuth < 0 ) && ( uv.u === 1 ) ) uv = new THREE.UV( uv.u - 1, uv.v );
-		if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.UV( azimuth / 2 / Math.PI + 0.5, uv.v );
+		if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
+		if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
 		return uv;
 
 	}

+ 1 - 1
src/extras/geometries/SphereGeometry.js

@@ -37,7 +37,7 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
 			this.vertices.push( vertex );
 
 			verticesRow.push( this.vertices.length - 1 );
-			uvsRow.push( new THREE.UV( u, 1 - v ) );
+			uvsRow.push( new THREE.Vector2( u, 1 - v ) );
 
 		}
 

+ 1 - 1
src/extras/geometries/TorusGeometry.js

@@ -35,7 +35,7 @@ THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments,
 
 			this.vertices.push( vertex );
 
-			uvs.push( new THREE.UV( i / this.tubularSegments, j / this.radialSegments ) );
+			uvs.push( new THREE.Vector2( i / this.tubularSegments, j / this.radialSegments ) );
 			normals.push( vertex.clone().subSelf( center ).normalize() );
 
 		}

+ 4 - 4
src/extras/geometries/TorusKnotGeometry.js

@@ -67,10 +67,10 @@ THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegmen
 			var c = this.grid[ ip ][ jp ];
 			var d = this.grid[ i ][ jp ];
 
-			var uva = new THREE.UV( i / this.radialSegments, j / this.tubularSegments );
-			var uvb = new THREE.UV( ( i + 1 ) / this.radialSegments, j / this.tubularSegments );
-			var uvc = new THREE.UV( ( i + 1 ) / this.radialSegments, ( j + 1 ) / this.tubularSegments );
-			var uvd = new THREE.UV( i / this.radialSegments, ( j + 1 ) / this.tubularSegments );
+			var uva = new THREE.Vector2( i / this.radialSegments, j / this.tubularSegments );
+			var uvb = new THREE.Vector2( ( i + 1 ) / this.radialSegments, j / this.tubularSegments );
+			var uvc = new THREE.Vector2( ( i + 1 ) / this.radialSegments, ( j + 1 ) / this.tubularSegments );
+			var uvd = new THREE.Vector2( i / this.radialSegments, ( j + 1 ) / this.tubularSegments );
 
 			this.faces.push( new THREE.Face4( a, b, c, d ) );
 			this.faceVertexUvs[ 0 ].push( [ uva,uvb,uvc, uvd ] );

+ 4 - 4
src/extras/geometries/TubeGeometry.js

@@ -115,10 +115,10 @@ THREE.TubeGeometry = function( path, segments, radius, radiusSegments, closed, d
 			c = this.grid[ ip ][ jp ];
 			d = this.grid[ i ][ jp ];
 
-			uva = new THREE.UV( i / this.segments, j / this.radiusSegments );
-			uvb = new THREE.UV( ( i + 1 ) / this.segments, j / this.radiusSegments );
-			uvc = new THREE.UV( ( i + 1 ) / this.segments, ( j + 1 ) / this.radiusSegments );
-			uvd = new THREE.UV( i / this.segments, ( j + 1 ) / this.radiusSegments );
+			uva = new THREE.Vector2( i / this.segments, j / this.radiusSegments );
+			uvb = new THREE.Vector2( ( i + 1 ) / this.segments, j / this.radiusSegments );
+			uvc = new THREE.Vector2( ( i + 1 ) / this.segments, ( j + 1 ) / this.radiusSegments );
+			uvd = new THREE.Vector2( i / this.segments, ( j + 1 ) / this.radiusSegments );
 
 			this.faces.push( new THREE.Face4( a, b, c, d ) );
 			this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvc, uvd ] );

+ 19 - 19
src/extras/modifiers/SubdivisionModifier.js

@@ -336,21 +336,21 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
 
 		// Prepare subdivided uv
 
-		avgUv = new THREE.UV();
+		avgUv = new THREE.Vector2();
 
 		if ( face instanceof THREE.Face3 ) {
 
-			avgUv.u = getUV( face.a, i ).u + getUV( face.b, i ).u + getUV( face.c, i ).u;
-			avgUv.v = getUV( face.a, i ).v + getUV( face.b, i ).v + getUV( face.c, i ).v;
-			avgUv.u /= 3;
-			avgUv.v /= 3;
+			avgUv.x = getUV( face.a, i ).x + getUV( face.b, i ).x + getUV( face.c, i ).x;
+			avgUv.y = getUV( face.a, i ).y + getUV( face.b, i ).y + getUV( face.c, i ).y;
+			avgUv.x /= 3;
+			avgUv.y /= 3;
 
 		} else if ( face instanceof THREE.Face4 ) {
 
-			avgUv.u = getUV( face.a, i ).u + getUV( face.b, i ).u + getUV( face.c, i ).u + getUV( face.d, i ).u;
-			avgUv.v = getUV( face.a, i ).v + getUV( face.b, i ).v + getUV( face.c, i ).v + getUV( face.d, i ).v;
-			avgUv.u /= 4;
-			avgUv.v /= 4;
+			avgUv.x = getUV( face.a, i ).x + getUV( face.b, i ).x + getUV( face.c, i ).x + getUV( face.d, i ).x;
+			avgUv.y = getUV( face.a, i ).y + getUV( face.b, i ).y + getUV( face.c, i ).y + getUV( face.d, i ).y;
+			avgUv.x /= 4;
+			avgUv.y /= 4;
 
 		}
 
@@ -482,23 +482,23 @@ THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
 
 		// Prepare subdivided uv
 
-		avgUv = new THREE.UV();
+		avgUv = new THREE.Vector2();
 
-		avgUv.u = getUV(edgeVertexA, faceIndexA).u + getUV(edgeVertexB, faceIndexA).u;
-		avgUv.v = getUV(edgeVertexA, faceIndexA).v + getUV(edgeVertexB, faceIndexA).v;
-		avgUv.u /= 2;
-		avgUv.v /= 2;
+		avgUv.x = getUV(edgeVertexA, faceIndexA).x + getUV(edgeVertexB, faceIndexA).x;
+		avgUv.y = getUV(edgeVertexA, faceIndexA).y + getUV(edgeVertexB, faceIndexA).y;
+		avgUv.x /= 2;
+		avgUv.y /= 2;
 
 		addUV(edgePoints[i], faceIndexA, avgUv);
 
 		if (edge.length>=2) {
 			assert(edge.length == 2, 'did we plan for more than 2 edges?');
-			avgUv = new THREE.UV();
+			avgUv = new THREE.Vector2();
 
-			avgUv.u = getUV(edgeVertexA, faceIndexB).u + getUV(edgeVertexB, faceIndexB).u;
-			avgUv.v = getUV(edgeVertexA, faceIndexB).v + getUV(edgeVertexB, faceIndexB).v;
-			avgUv.u /= 2;
-			avgUv.v /= 2;
+			avgUv.x = getUV(edgeVertexA, faceIndexB).x + getUV(edgeVertexB, faceIndexB).x;
+			avgUv.y = getUV(edgeVertexA, faceIndexB).y + getUV(edgeVertexB, faceIndexB).y;
+			avgUv.x /= 2;
+			avgUv.y /= 2;
 
 			addUV(edgePoints[i], faceIndexB, avgUv);
 		}

+ 7 - 7
src/loaders/BinaryLoader.js

@@ -738,9 +738,9 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 	function uv3 ( where, u1, v1, u2, v2, u3, v3 ) {
 
 		where.push( [
-			new THREE.UV( u1, v1 ),
-			new THREE.UV( u2, v2 ),
-			new THREE.UV( u3, v3 )
+			new THREE.Vector2( u1, v1 ),
+			new THREE.Vector2( u2, v2 ),
+			new THREE.Vector2( u3, v3 )
 		] );
 
 	};
@@ -748,10 +748,10 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 	function uv4 ( where, u1, v1, u2, v2, u3, v3, u4, v4 ) {
 
 		where.push( [
-			new THREE.UV( u1, v1 ),
-			new THREE.UV( u2, v2 ),
-			new THREE.UV( u3, v3 ),
-			new THREE.UV( u4, v4 )
+			new THREE.Vector2( u1, v1 ),
+			new THREE.Vector2( u2, v2 ),
+			new THREE.Vector2( u3, v3 ),
+			new THREE.Vector2( u4, v4 )
 		] );
 	};
 

+ 2 - 2
src/loaders/JSONLoader.js

@@ -230,7 +230,7 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
 					u = uvLayer[ uvIndex * 2 ];
 					v = uvLayer[ uvIndex * 2 + 1 ];
 
-					geometry.faceUvs[ i ][ fi ] = new THREE.UV( u, v );
+					geometry.faceUvs[ i ][ fi ] = new THREE.Vector2( u, v );
 
 				}
 
@@ -251,7 +251,7 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
 						u = uvLayer[ uvIndex * 2 ];
 						v = uvLayer[ uvIndex * 2 + 1 ];
 
-						uvs[ j ] = new THREE.UV( u, v );
+						uvs[ j ] = new THREE.Vector2( u, v );
 
 					}
 

+ 6 - 0
src/loaders/Loader.js

@@ -420,6 +420,12 @@ THREE.Loader.prototype = {
 			var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
 			var material = new THREE.ShaderMaterial( parameters );
 
+			if ( mpars.transparent ) {
+
+				material.transparent = true;
+
+			}
+
 		} else {
 
 			var material = new THREE[ mtype ]( mpars );

+ 257 - 240
src/loaders/SceneLoader.js

@@ -69,10 +69,8 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	var urlBase = THREE.Loader.prototype.extractUrlBase( url );
 
-	var dg, dm, dc, df, dt,
-		g, m, l, d, p, r, q, s, c, t, f, tt, pp, u,
-		geometry, material, camera, fog,
-		texture, images,
+	var geometry, material, camera, fog,
+		texture, images, color,
 		light, hex, intensity,
 		counter_models, counter_textures,
 		total_models, total_textures,
@@ -168,45 +166,52 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	function handle_children( parent, children ) {
 
-		for ( var dd in children ) {
+		var mat, dst, pos, rot, scl, quat;
+
+		for ( var objID in children ) {
 
 			// check by id if child has already been handled,
 			// if not, create new object
 
-			if ( result.objects[ dd ] === undefined ) {
+			if ( result.objects[ objID ] === undefined ) {
 
-				var o = children[ dd ];
+				var objJSON = children[ objID ];
 
 				var object = null;
 
 				// meshes
 
-				if ( o.type && ( o.type in scope.hierarchyHandlerMap ) && o.loading === undefined ) {
+				if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlerMap ) && objJSON.loading === undefined ) {
+
+					var reservedTypes = { "type": 1, "url": 1, "material": 1,
+										  "position": 1, "rotation": 1, "scale" : 1,
+										  "visible": 1, "children": 1, "properties": 1,
+										  "skin": 1, "morph": 1, "mirroredLoop": 1, "duration": 1 };
 
 					var loaderParameters = {};
 
-					for ( var parType in g ) {
+					for ( var parType in objJSON ) {
 
-						if ( parType !== "type" && parType !== "url" ) {
+						if ( ! ( parType in reservedTypes ) ) {
 
-							loaderParameters[ parType ] = g[ parType ];
+							loaderParameters[ parType ] = objJSON[ parType ];
 
 						}
 
 					}
 
-					material = result.materials[ o.material ];
+					material = result.materials[ objJSON.material ];
 
-					o.loading = true;
+					objJSON.loading = true;
 
-					var loader = scope.hierarchyHandlerMap[ o.type ][ "loaderObject" ];
+					var loader = scope.hierarchyHandlerMap[ objJSON.type ][ "loaderObject" ];
 
 					// OBJLoader
 
 					if ( loader.addEventListener ) {
 
-						loader.addEventListener( 'load', create_callback_hierachy( dd, parent, material, o ) );
-						loader.load( get_url( o.url, data.urlBaseType ) );
+						loader.addEventListener( 'load', create_callback_hierachy( objID, parent, material, objJSON ) );
+						loader.load( get_url( objJSON.url, data.urlBaseType ) );
 
 					} else {
 
@@ -214,21 +219,21 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 						if ( loader.options ) {
 
-							loader.load( get_url( o.url, data.urlBaseType ), create_callback_hierachy( dd, parent, material, o ) );
+							loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ) );
 
 						// UTF8Loader
 
 						} else {
 
-							loader.load( get_url( o.url, data.urlBaseType ), create_callback_hierachy( dd, parent, material, o ), loaderParameters );
+							loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ), loaderParameters );
 
 						}
 
 					}
 
-				} else if ( o.geometry !== undefined ) {
+				} else if ( objJSON.geometry !== undefined ) {
 
-					geometry = result.geometries[ o.geometry ];
+					geometry = result.geometries[ objJSON.geometry ];
 
 					// geometry already loaded
 
@@ -236,25 +241,25 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 						var needsTangents = false;
 
-						material = result.materials[ o.material ];
+						material = result.materials[ objJSON.material ];
 						needsTangents = material instanceof THREE.ShaderMaterial;
 
-						p = o.position;
-						r = o.rotation;
-						q = o.quaternion;
-						s = o.scale;
-						m = o.matrix;
+						pos = objJSON.position;
+						rot = objJSON.rotation;
+						scl = objJSON.scale;
+						mat = objJSON.matrix;
+						quat = objJSON.quaternion;
 
 						// turn off quaternions, for the moment
 
-						q = 0;
+						quat = 0;
 
 						// use materials from the model file
 						// if there is no material specified in the object
 
-						if ( ! o.material ) {
+						if ( ! objJSON.material ) {
 
-							material = new THREE.MeshFaceMaterial( result.face_materials[ o.geometry ] );
+							material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
 
 						}
 
@@ -264,7 +269,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 						if ( ( material instanceof THREE.MeshFaceMaterial ) && material.materials.length === 0 ) {
 
-							material = new THREE.MeshFaceMaterial( result.face_materials[ o.geometry ] );
+							material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
 
 						}
 
@@ -284,29 +289,29 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 						}
 
-						if ( o.skin ) {
+						if ( objJSON.skin ) {
 
 							object = new THREE.SkinnedMesh( geometry, material );
 
-						} else if ( o.morph ) {
+						} else if ( objJSON.morph ) {
 
 							object = new THREE.MorphAnimMesh( geometry, material );
 
-							if ( o.duration !== undefined ) {
+							if ( objJSON.duration !== undefined ) {
 
-								object.duration = o.duration;
+								object.duration = objJSON.duration;
 
 							}
 
-							if ( o.time !== undefined ) {
+							if ( objJSON.time !== undefined ) {
 
-								object.time = o.time;
+								object.time = objJSON.time;
 
 							}
 
-							if ( o.mirroredLoop !== undefined ) {
+							if ( objJSON.mirroredLoop !== undefined ) {
 
-								object.mirroredLoop = o.mirroredLoop;
+								object.mirroredLoop = objJSON.mirroredLoop;
 
 							}
 
@@ -322,64 +327,64 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 						}
 
-						object.name = dd;
+						object.name = objID;
 
-						if ( m ) {
+						if ( mat ) {
 
 							object.matrixAutoUpdate = false;
 							object.matrix.set(
-								m[0], m[1], m[2], m[3],
-								m[4], m[5], m[6], m[7],
-								m[8], m[9], m[10], m[11],
-								m[12], m[13], m[14], m[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 {
 
-							object.position.set( p[0], p[1], p[2] );
+							object.position.set( pos[0], pos[1], pos[2] );
 
-							if ( q ) {
+							if ( quat ) {
 
-								object.quaternion.set( q[0], q[1], q[2], q[3] );
+								object.quaternion.set( quat[0], quat[1], quat[2], quat[3] );
 								object.useQuaternion = true;
 
 							} else {
 
-								object.rotation.set( r[0], r[1], r[2] );
+								object.rotation.set( rot[0], rot[1], rot[2] );
 
 							}
 
-							object.scale.set( s[0], s[1], s[2] );
+							object.scale.set( scl[0], scl[1], scl[2] );
 
 						}
 
-						object.visible = o.visible;
-						object.castShadow = o.castShadow;
-						object.receiveShadow = o.receiveShadow;
+						object.visible = objJSON.visible;
+						object.castShadow = objJSON.castShadow;
+						object.receiveShadow = objJSON.receiveShadow;
 
 						parent.add( object );
 
-						result.objects[ dd ] = object;
+						result.objects[ objID ] = object;
 
 					}
 
 				// lights
 
-				} else if ( o.type === "DirectionalLight" || o.type === "PointLight" || o.type === "AmbientLight" ) {
+				} else if ( objJSON.type === "DirectionalLight" || objJSON.type === "PointLight" || objJSON.type === "AmbientLight" ) {
 
-					hex = ( o.color !== undefined ) ? o.color : 0xffffff;
-					intensity = ( o.intensity !== undefined ) ? o.intensity : 1;
+					hex = ( objJSON.color !== undefined ) ? objJSON.color : 0xffffff;
+					intensity = ( objJSON.intensity !== undefined ) ? objJSON.intensity : 1;
 
-					if ( o.type === "DirectionalLight" ) {
+					if ( objJSON.type === "DirectionalLight" ) {
 
-						p = o.direction;
+						pos = objJSON.direction;
 
 						light = new THREE.DirectionalLight( hex, intensity );
-						light.position.set( p[0], p[1], p[2] );
+						light.position.set( pos[0], pos[1], pos[2] );
 
-						if ( o.target ) {
+						if ( objJSON.target ) {
 
-							target_array.push( { "object": light, "targetName" : o.target } );
+							target_array.push( { "object": light, "targetName" : objJSON.target } );
 
 							// kill existing default target
 							// otherwise it gets added to scene when parent gets added
@@ -388,15 +393,15 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 						}
 
-					} else if ( o.type === "PointLight" ) {
+					} else if ( objJSON.type === "PointLight" ) {
 
-						p = o.position;
-						d = o.distance;
+						pos = objJSON.position;
+						dst = objJSON.distance;
 
-						light = new THREE.PointLight( hex, intensity, d );
-						light.position.set( p[0], p[1], p[2] );
+						light = new THREE.PointLight( hex, intensity, dst );
+						light.position.set( pos[0], pos[1], pos[2] );
 
-					} else if ( o.type === "AmbientLight" ) {
+					} else if ( objJSON.type === "AmbientLight" ) {
 
 						light = new THREE.AmbientLight( hex );
 
@@ -404,86 +409,86 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 					parent.add( light );
 
-					light.name = dd;
-					result.lights[ dd ] = light;
-					result.objects[ dd ] = light;
+					light.name = objID;
+					result.lights[ objID ] = light;
+					result.objects[ objID ] = light;
 
 				// cameras
 
-				} else if ( o.type === "PerspectiveCamera" || o.type === "OrthographicCamera" ) {
+				} else if ( objJSON.type === "PerspectiveCamera" || objJSON.type === "OrthographicCamera" ) {
 
-					if ( o.type === "PerspectiveCamera" ) {
+					if ( objJSON.type === "PerspectiveCamera" ) {
 
-						camera = new THREE.PerspectiveCamera( o.fov, o.aspect, o.near, o.far );
+						camera = new THREE.PerspectiveCamera( objJSON.fov, objJSON.aspect, objJSON.near, objJSON.far );
 
-					} else if ( o.type === "OrthographicCamera" ) {
+					} else if ( objJSON.type === "OrthographicCamera" ) {
 
-						camera = new THREE.OrthographicCamera( c.left, c.right, c.top, c.bottom, c.near, c.far );
+						camera = new THREE.OrthographicCamera( objJSON.left, objJSON.right, objJSON.top, objJSON.bottom, objJSON.near, objJSON.far );
 
 					}
 
-					p = o.position;
-					camera.position.set( p[0], p[1], p[2] );
+					pos = objJSON.position;
+					camera.position.set( pos[0], pos[1], pos[2] );
 					parent.add( camera );
 
-					camera.name = dd;
-					result.cameras[ dd ] = camera;
-					result.objects[ dd ] = camera;
+					camera.name = objID;
+					result.cameras[ objID ] = camera;
+					result.objects[ objID ] = camera;
 
 				// pure Object3D
 
 				} else {
 
-					p = o.position;
-					r = o.rotation;
-					q = o.quaternion;
-					s = o.scale;
+					pos = objJSON.position;
+					rot = objJSON.rotation;
+					scl = objJSON.scale;
+					quat = objJSON.quaternion;
 
 					// turn off quaternions, for the moment
 
-					q = 0;
+					quat = 0;
 
 					object = new THREE.Object3D();
-					object.name = dd;
-					object.position.set( p[0], p[1], p[2] );
+					object.name = objID;
+					object.position.set( pos[0], pos[1], pos[2] );
 
-					if ( q ) {
+					if ( quat ) {
 
-						object.quaternion.set( q[0], q[1], q[2], q[3] );
+						object.quaternion.set( quat[0], quat[1], quat[2], quat[3] );
 						object.useQuaternion = true;
 
 					} else {
 
-						object.rotation.set( r[0], r[1], r[2] );
+						object.rotation.set( rot[0], rot[1], rot[2] );
 
 					}
 
-					object.scale.set( s[0], s[1], s[2] );
-					object.visible = ( o.visible !== undefined ) ? o.visible : false;
+					object.scale.set( scl[0], scl[1], scl[2] );
+					object.visible = ( objJSON.visible !== undefined ) ? objJSON.visible : false;
 
 					parent.add( object );
 
-					result.objects[ dd ] = object;
-					result.empties[ dd ] = object;
+					result.objects[ objID ] = object;
+					result.empties[ objID ] = object;
 
 				}
 
 				if ( object ) {
 
-					if ( o.properties !== undefined )  {
+					if ( objJSON.properties !== undefined )  {
 
-						for ( var key in o.properties ) {
+						for ( var key in objJSON.properties ) {
 
-							var value = o.properties[ key ];
+							var value = objJSON.properties[ key ];
 							object.properties[ key ] = value;
 
 						}
 
 					}
 
-					if ( o.children !== undefined ) {
+					if ( objJSON.children !== undefined ) {
 
-						handle_children( object, o.children );
+						handle_children( object, objJSON.children );
 
 					}
 
@@ -503,12 +508,12 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	};
 
-	function handle_hierarchy( node, id, parent, material, o ) {
+	function handle_hierarchy( node, id, parent, material, obj ) {
 
-		var p = o.position;
-		var r = o.rotation;
-		var q = o.quaternion;
-		var s = o.scale;
+		var p = obj.position;
+		var r = obj.rotation;
+		var q = obj.quaternion;
+		var s = obj.scale;
 
 		node.position.set( p[0], p[1], p[2] );
 
@@ -689,24 +694,26 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	// fogs
 
-	for ( df in data.fogs ) {
+	var fogID, fogJSON;
 
-		f = data.fogs[ df ];
+	for ( fogID in data.fogs ) {
 
-		if ( f.type === "linear" ) {
+		fogJSON = data.fogs[ fogID ];
 
-			fog = new THREE.Fog( 0x000000, f.near, f.far );
+		if ( fogJSON.type === "linear" ) {
 
-		} else if ( f.type === "exp2" ) {
+			fog = new THREE.Fog( 0x000000, fogJSON.near, fogJSON.far );
 
-			fog = new THREE.FogExp2( 0x000000, f.density );
+		} else if ( fogJSON.type === "exp2" ) {
+
+			fog = new THREE.FogExp2( 0x000000, fogJSON.density );
 
 		}
 
-		c = f.color;
-		fog.color.setRGB( c[0], c[1], c[2] );
+		color = fogJSON.color;
+		fog.color.setRGB( color[0], color[1], color[2] );
 
-		result.fogs[ df ] = fog;
+		result.fogs[ fogID ] = fog;
 
 	}
 
@@ -716,11 +723,13 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	// count how many geometries will be loaded asynchronously
 
-	for ( dg in data.geometries ) {
+	var geoID, geoJSON;
+
+	for ( geoID in data.geometries ) {
 
-		g = data.geometries[ dg ];
+		geoJSON = data.geometries[ geoID ];
 
-		if ( g.type in this.geometryHandlerMap ) {
+		if ( geoJSON.type in this.geometryHandlerMap ) {
 
 			counter_models += 1;
 
@@ -732,11 +741,13 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	// count how many hierarchies will be loaded asynchronously
 
-	for ( var dd in data.objects ) {
+	var objID, objJSON;
 
-		var o = data.objects[ dd ];
+	for ( objID in data.objects ) {
 
-		if ( o.type && ( o.type in this.hierarchyHandlerMap ) ) {
+		objJSON = data.objects[ objID ];
+
+		if ( objJSON.type && ( objJSON.type in this.hierarchyHandlerMap ) ) {
 
 			counter_models += 1;
 
@@ -748,59 +759,60 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	total_models = counter_models;
 
-	for ( dg in data.geometries ) {
+	for ( geoID in data.geometries ) {
 
-		g = data.geometries[ dg ];
+		geoJSON = data.geometries[ geoID ];
 
-		if ( g.type === "cube" ) {
+		if ( geoJSON.type === "cube" ) {
 
-			geometry = new THREE.CubeGeometry( g.width, g.height, g.depth, g.widthSegments, g.heightSegments, g.depthSegments );
-			result.geometries[ dg ] = geometry;
+			geometry = new THREE.CubeGeometry( geoJSON.width, geoJSON.height, geoJSON.depth, geoJSON.widthSegments, geoJSON.heightSegments, geoJSON.depthSegments );
+			result.geometries[ geoID ] = geometry;
 
-		} else if ( g.type === "plane" ) {
+		} else if ( geoJSON.type === "plane" ) {
 
-			geometry = new THREE.PlaneGeometry( g.width, g.height, g.widthSegments, g.heightSegments );
-			result.geometries[ dg ] = geometry;
+			geometry = new THREE.PlaneGeometry( geoJSON.width, geoJSON.height, geoJSON.widthSegments, geoJSON.heightSegments );
+			result.geometries[ geoID ] = geometry;
 
-		} else if ( g.type === "sphere" ) {
+		} else if ( geoJSON.type === "sphere" ) {
 
-			geometry = new THREE.SphereGeometry( g.radius, g.widthSegments, g.heightSegments );
-			result.geometries[ dg ] = geometry;
+			geometry = new THREE.SphereGeometry( geoJSON.radius, geoJSON.widthSegments, geoJSON.heightSegments );
+			result.geometries[ geoID ] = geometry;
 
-		} else if ( g.type === "cylinder" ) {
+		} else if ( geoJSON.type === "cylinder" ) {
 
-			geometry = new THREE.CylinderGeometry( g.topRad, g.botRad, g.height, g.radSegs, g.heightSegs );
-			result.geometries[ dg ] = geometry;
+			geometry = new THREE.CylinderGeometry( geoJSON.topRad, geoJSON.botRad, geoJSON.height, geoJSON.radSegs, geoJSON.heightSegs );
+			result.geometries[ geoID ] = geometry;
 
-		} else if ( g.type === "torus" ) {
+		} else if ( geoJSON.type === "torus" ) {
 
-			geometry = new THREE.TorusGeometry( g.radius, g.tube, g.segmentsR, g.segmentsT );
-			result.geometries[ dg ] = geometry;
+			geometry = new THREE.TorusGeometry( geoJSON.radius, geoJSON.tube, geoJSON.segmentsR, geoJSON.segmentsT );
+			result.geometries[ geoID ] = geometry;
 
-		} else if ( g.type === "icosahedron" ) {
+		} else if ( geoJSON.type === "icosahedron" ) {
 
-			geometry = new THREE.IcosahedronGeometry( g.radius, g.subdivisions );
-			result.geometries[ dg ] = geometry;
+			geometry = new THREE.IcosahedronGeometry( geoJSON.radius, geoJSON.subdivisions );
+			result.geometries[ geoID ] = geometry;
 
-		} else if ( g.type in this.geometryHandlerMap ) {
+		} else if ( geoJSON.type in this.geometryHandlerMap ) {
 
 			var loaderParameters = {};
-			for ( var parType in g ) {
+
+			for ( var parType in geoJSON ) {
 
 				if ( parType !== "type" && parType !== "url" ) {
 
-					loaderParameters[ parType ] = g[ parType ];
+					loaderParameters[ parType ] = geoJSON[ parType ];
 
 				}
 
 			}
 
-			var loader = this.geometryHandlerMap[ g.type ][ "loaderObject" ];
-			loader.load( get_url( g.url, data.urlBaseType ), create_callback_geometry( dg ), loaderParameters );
+			var loader = this.geometryHandlerMap[ geoJSON.type ][ "loaderObject" ];
+			loader.load( get_url( geoJSON.url, data.urlBaseType ), create_callback_geometry( geoID ), loaderParameters );
 
-		} else if ( g.type === "embedded" ) {
+		} else if ( geoJSON.type === "embedded" ) {
 
-			var modelJson = data.embeds[ g.id ],
+			var modelJson = data.embeds[ geoJSON.id ],
 				texture_path = "";
 
 			// pass metadata along to jsonLoader so it knows the format version
@@ -810,7 +822,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 			if ( modelJson ) {
 
 				var jsonLoader = this.geometryHandlerMap[ "ascii" ][ "loaderObject" ];
-				jsonLoader.createModel( modelJson, create_callback_embed( dg ), texture_path );
+				jsonLoader.createModel( modelJson, create_callback_embed( geoID ), texture_path );
 
 			}
 
@@ -822,15 +834,17 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	// count how many textures will be loaded asynchronously
 
-	for ( dt in data.textures ) {
+	var textureID, textureJSON;
 
-		tt = data.textures[ dt ];
+	for ( textureID in data.textures ) {
 
-		if ( tt.url instanceof Array ) {
+		textureJSON = data.textures[ textureID ];
 
-			counter_textures += tt.url.length;
+		if ( textureJSON.url instanceof Array ) {
 
-			for( var n = 0; n < tt.url.length; n ++ ) {
+			counter_textures += textureJSON.url.length;
+
+			for( var n = 0; n < textureJSON.url.length; n ++ ) {
 
 				scope.onLoadStart();
 
@@ -848,24 +862,24 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	total_textures = counter_textures;
 
-	for ( dt in data.textures ) {
+	for ( textureID in data.textures ) {
 
-		tt = data.textures[ dt ];
+		textureJSON = data.textures[ textureID ];
 
-		if ( tt.mapping !== undefined && THREE[ tt.mapping ] !== undefined  ) {
+		if ( textureJSON.mapping !== undefined && THREE[ textureJSON.mapping ] !== undefined  ) {
 
-			tt.mapping = new THREE[ tt.mapping ]();
+			textureJSON.mapping = new THREE[ textureJSON.mapping ]();
 
 		}
 
-		if ( tt.url instanceof Array ) {
+		if ( textureJSON.url instanceof Array ) {
 
-			var count = tt.url.length;
+			var count = textureJSON.url.length;
 			var url_array = [];
 
 			for( var i = 0; i < count; i ++ ) {
 
-				url_array[ i ] = get_url( tt.url[ i ], data.urlBaseType );
+				url_array[ i ] = get_url( textureJSON.url[ i ], data.urlBaseType );
 
 			}
 
@@ -873,196 +887,199 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 			if ( isCompressed ) {
 
-				texture = THREE.ImageUtils.loadCompressedTextureCube( url_array, tt.mapping, generateTextureCallback( count ) );
+				texture = THREE.ImageUtils.loadCompressedTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
 
 			} else {
 
-				texture = THREE.ImageUtils.loadTextureCube( url_array, tt.mapping, generateTextureCallback( count ) );
+				texture = THREE.ImageUtils.loadTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
 
 			}
 
 		} else {
 
-			var isCompressed = tt.url.toLowerCase().endsWith( ".dds" );
-			var fullUrl = get_url( tt.url, data.urlBaseType );
+			var isCompressed = textureJSON.url.toLowerCase().endsWith( ".dds" );
+			var fullUrl = get_url( textureJSON.url, data.urlBaseType );
 			var textureCallback = generateTextureCallback( 1 );
 
 			if ( isCompressed ) {
 
-				texture = THREE.ImageUtils.loadCompressedTexture( fullUrl, tt.mapping, textureCallback );
+				texture = THREE.ImageUtils.loadCompressedTexture( fullUrl, textureJSON.mapping, textureCallback );
 
 			} else {
 
-				texture = THREE.ImageUtils.loadTexture( fullUrl, tt.mapping, textureCallback );
+				texture = THREE.ImageUtils.loadTexture( fullUrl, textureJSON.mapping, textureCallback );
 
 			}
 
-			if ( THREE[ tt.minFilter ] !== undefined )
-				texture.minFilter = THREE[ tt.minFilter ];
+			if ( THREE[ textureJSON.minFilter ] !== undefined )
+				texture.minFilter = THREE[ textureJSON.minFilter ];
 
-			if ( THREE[ tt.magFilter ] !== undefined )
-				texture.magFilter = THREE[ tt.magFilter ];
+			if ( THREE[ textureJSON.magFilter ] !== undefined )
+				texture.magFilter = THREE[ textureJSON.magFilter ];
 
-			if ( tt.anisotropy ) texture.anisotropy = tt.anisotropy;
+			if ( textureJSON.anisotropy ) texture.anisotropy = textureJSON.anisotropy;
 
-			if ( tt.repeat ) {
+			if ( textureJSON.repeat ) {
 
-				texture.repeat.set( tt.repeat[ 0 ], tt.repeat[ 1 ] );
+				texture.repeat.set( textureJSON.repeat[ 0 ], textureJSON.repeat[ 1 ] );
 
-				if ( tt.repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
-				if ( tt.repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
+				if ( textureJSON.repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
+				if ( textureJSON.repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
 
 			}
 
-			if ( tt.offset ) {
+			if ( textureJSON.offset ) {
 
-				texture.offset.set( tt.offset[ 0 ], tt.offset[ 1 ] );
+				texture.offset.set( textureJSON.offset[ 0 ], textureJSON.offset[ 1 ] );
 
 			}
 
 			// handle wrap after repeat so that default repeat can be overriden
 
-			if ( tt.wrap ) {
+			if ( textureJSON.wrap ) {
 
 				var wrapMap = {
 				"repeat" 	: THREE.RepeatWrapping,
 				"mirror"	: THREE.MirroredRepeatWrapping
 				}
 
-				if ( wrapMap[ tt.wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ tt.wrap[ 0 ] ];
-				if ( wrapMap[ tt.wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ tt.wrap[ 1 ] ];
+				if ( wrapMap[ textureJSON.wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ textureJSON.wrap[ 0 ] ];
+				if ( wrapMap[ textureJSON.wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ textureJSON.wrap[ 1 ] ];
 
 			}
 
 		}
 
-		result.textures[ dt ] = texture;
+		result.textures[ textureID ] = texture;
 
 	}
 
 	// materials
 
-	for ( dm in data.materials ) {
+	var matID, matJSON;
+	var parID;
+
+	for ( matID in data.materials ) {
 
-		m = data.materials[ dm ];
+		matJSON = data.materials[ matID ];
 
-		for ( pp in m.parameters ) {
+		for ( parID in matJSON.parameters ) {
 
-			if ( pp === "envMap" || pp === "map" || pp === "lightMap" || pp === "bumpMap" ) {
+			if ( parID === "envMap" || parID === "map" || parID === "lightMap" || parID === "bumpMap" ) {
 
-				m.parameters[ pp ] = result.textures[ m.parameters[ pp ] ];
+				matJSON.parameters[ parID ] = result.textures[ matJSON.parameters[ parID ] ];
 
-			} else if ( pp === "shading" ) {
+			} else if ( parID === "shading" ) {
 
-				m.parameters[ pp ] = ( m.parameters[ pp ] === "flat" ) ? THREE.FlatShading : THREE.SmoothShading;
+				matJSON.parameters[ parID ] = ( matJSON.parameters[ parID ] === "flat" ) ? THREE.FlatShading : THREE.SmoothShading;
 
-			} else if ( pp === "side" ) {
+			} else if ( parID === "side" ) {
 
-				if (  m.parameters[ pp ] == "double" ) {
+				if ( matJSON.parameters[ parID ] == "double" ) {
 
-					m.parameters[ pp ] = THREE.DoubleSide;
+					matJSON.parameters[ parID ] = THREE.DoubleSide;
 
-				} else if ( m.parameters[ pp ] == "back" ) {
+				} else if ( matJSON.parameters[ parID ] == "back" ) {
 
-					m.parameters[ pp ] = THREE.BackSide;
+					matJSON.parameters[ parID ] = THREE.BackSide;
 
 				} else {
 
-					m.parameters[ pp ] = THREE.FrontSide;
+					matJSON.parameters[ parID ] = THREE.FrontSide;
 
 				}
 
-			} else if ( pp === "blending" ) {
+			} else if ( parID === "blending" ) {
 
-				m.parameters[ pp ] = m.parameters[ pp ] in THREE ? THREE[ m.parameters[ pp ] ] : THREE.NormalBlending;
+				matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.NormalBlending;
 
-			} else if ( pp === "combine" ) {
+			} else if ( parID === "combine" ) {
 
-				m.parameters[ pp ] = ( m.parameters[ pp ] == "MixOperation" ) ? THREE.MixOperation : THREE.MultiplyOperation;
+				matJSON.parameters[ parID ] = ( matJSON.parameters[ parID ] == "MixOperation" ) ? THREE.MixOperation : THREE.MultiplyOperation;
 
-			} else if ( pp === "vertexColors" ) {
+			} else if ( parID === "vertexColors" ) {
 
-				if ( m.parameters[ pp ] == "face" ) {
+				if ( matJSON.parameters[ parID ] == "face" ) {
 
-					m.parameters[ pp ] = THREE.FaceColors;
+					matJSON.parameters[ parID ] = THREE.FaceColors;
 
 				// default to vertex colors if "vertexColors" is anything else face colors or 0 / null / false
 
-				} else if ( m.parameters[ pp ] )   {
+				} else if ( matJSON.parameters[ parID ] )   {
 
-					m.parameters[ pp ] = THREE.VertexColors;
+					matJSON.parameters[ parID ] = THREE.VertexColors;
 
 				}
 
-			} else if ( pp === "wrapRGB" ) {
+			} else if ( parID === "wrapRGB" ) {
 
-				var v3 = m.parameters[ pp ];
-				m.parameters[ pp ] = new THREE.Vector3( v3[ 0 ], v3[ 1 ], v3[ 2 ] );
+				var v3 = matJSON.parameters[ parID ];
+				matJSON.parameters[ parID ] = new THREE.Vector3( v3[ 0 ], v3[ 1 ], v3[ 2 ] );
 
 			}
 
 		}
 
-		if ( m.parameters.opacity !== undefined && m.parameters.opacity < 1.0 ) {
+		if ( matJSON.parameters.opacity !== undefined && matJSON.parameters.opacity < 1.0 ) {
 
-			m.parameters.transparent = true;
+			matJSON.parameters.transparent = true;
 
 		}
 
-		if ( m.parameters.normalMap ) {
+		if ( matJSON.parameters.normalMap ) {
 
 			var shader = THREE.ShaderUtils.lib[ "normal" ];
 			var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
 
-			var diffuse = m.parameters.color;
-			var specular = m.parameters.specular;
-			var ambient = m.parameters.ambient;
-			var shininess = m.parameters.shininess;
+			var diffuse = matJSON.parameters.color;
+			var specular = matJSON.parameters.specular;
+			var ambient = matJSON.parameters.ambient;
+			var shininess = matJSON.parameters.shininess;
 
-			uniforms[ "tNormal" ].value = result.textures[ m.parameters.normalMap ];
+			uniforms[ "tNormal" ].value = result.textures[ matJSON.parameters.normalMap ];
 
-			if ( m.parameters.normalScale ) {
+			if ( matJSON.parameters.normalScale ) {
 
-				uniforms[ "uNormalScale" ].value.set( m.parameters.normalScale[ 0 ], m.parameters.normalScale[ 1 ] );
+				uniforms[ "uNormalScale" ].value.set( matJSON.parameters.normalScale[ 0 ], matJSON.parameters.normalScale[ 1 ] );
 
 			}
 
-			if ( m.parameters.map ) {
+			if ( matJSON.parameters.map ) {
 
-				uniforms[ "tDiffuse" ].value = m.parameters.map;
+				uniforms[ "tDiffuse" ].value = matJSON.parameters.map;
 				uniforms[ "enableDiffuse" ].value = true;
 
 			}
 
-			if ( m.parameters.envMap ) {
+			if ( matJSON.parameters.envMap ) {
 
-				uniforms[ "tCube" ].value = m.parameters.envMap;
+				uniforms[ "tCube" ].value = matJSON.parameters.envMap;
 				uniforms[ "enableReflection" ].value = true;
-				uniforms[ "uReflectivity" ].value = m.parameters.reflectivity;
+				uniforms[ "uReflectivity" ].value = matJSON.parameters.reflectivity;
 
 			}
 
-			if ( m.parameters.lightMap ) {
+			if ( matJSON.parameters.lightMap ) {
 
-				uniforms[ "tAO" ].value = m.parameters.lightMap;
+				uniforms[ "tAO" ].value = matJSON.parameters.lightMap;
 				uniforms[ "enableAO" ].value = true;
 
 			}
 
-			if ( m.parameters.specularMap ) {
+			if ( matJSON.parameters.specularMap ) {
 
-				uniforms[ "tSpecular" ].value = result.textures[ m.parameters.specularMap ];
+				uniforms[ "tSpecular" ].value = result.textures[ matJSON.parameters.specularMap ];
 				uniforms[ "enableSpecular" ].value = true;
 
 			}
 
-			if ( m.parameters.displacementMap ) {
+			if ( matJSON.parameters.displacementMap ) {
 
-				uniforms[ "tDisplacement" ].value = result.textures[ m.parameters.displacementMap ];
+				uniforms[ "tDisplacement" ].value = result.textures[ matJSON.parameters.displacementMap ];
 				uniforms[ "enableDisplacement" ].value = true;
 
-				uniforms[ "uDisplacementBias" ].value = m.parameters.displacementBias;
-				uniforms[ "uDisplacementScale" ].value = m.parameters.displacementScale;
+				uniforms[ "uDisplacementBias" ].value = matJSON.parameters.displacementBias;
+				uniforms[ "uDisplacementScale" ].value = matJSON.parameters.displacementScale;
 
 			}
 
@@ -1072,9 +1089,9 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 			uniforms[ "uShininess" ].value = shininess;
 
-			if ( m.parameters.opacity ) {
+			if ( matJSON.parameters.opacity ) {
 
-				uniforms[ "uOpacity" ].value = m.parameters.opacity;
+				uniforms[ "uOpacity" ].value = matJSON.parameters.opacity;
 
 			}
 
@@ -1084,33 +1101,33 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 		} else {
 
-			material = new THREE[ m.type ]( m.parameters );
+			material = new THREE[ matJSON.type ]( matJSON.parameters );
 
 		}
 
-		result.materials[ dm ] = material;
+		result.materials[ matID ] = material;
 
 	}
 
 	// second pass through all materials to initialize MeshFaceMaterials
 	// that could be referring to other materials out of order
 
-	for ( dm in data.materials ) {
+	for ( matID in data.materials ) {
 
-		m = data.materials[ dm ];
+		matJSON = data.materials[ matID ];
 
-		if ( m.parameters.materials ) {
+		if ( matJSON.parameters.materials ) {
 
 			var materialArray = [];
 
-			for ( var i = 0; i < m.parameters.materials.length; i ++ ) {
+			for ( var i = 0; i < matJSON.parameters.materials.length; i ++ ) {
 
-				var label = m.parameters.materials[ i ];
+				var label = matJSON.parameters.materials[ i ];
 				materialArray.push( result.materials[ label ] );
 
 			}
 
-			result.materials[ dm ].materials = materialArray;
+			result.materials[ matID ].materials = materialArray;
 
 		}
 
@@ -1134,9 +1151,9 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	}
 
-	c = data.defaults.bgcolor;
+	color = data.defaults.bgcolor;
 	result.bgColor = new THREE.Color();
-	result.bgColor.setRGB( c[0], c[1], c[2] );
+	result.bgColor.setRGB( color[0], color[1], color[2] );
 
 	result.bgColorAlpha = data.defaults.bgalpha;
 

+ 2 - 2
src/renderers/WebGLRenderTarget.js

@@ -39,10 +39,10 @@ THREE.WebGLRenderTarget.prototype.clone = function() {
 	tmp.wrapT = this.wrapT;
 
 	tmp.magFilter = this.magFilter;
-	tmp.anisotropy = this.anisotropy;
-
 	tmp.minFilter = this.minFilter;
 
+	tmp.anisotropy = this.anisotropy;
+
 	tmp.offset.copy( this.offset );
 	tmp.repeat.copy( this.repeat );
 

+ 14 - 14
src/renderers/WebGLRenderer.js

@@ -151,7 +151,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 	_projScreenMatrix = new THREE.Matrix4(),
 	_projScreenMatrixPS = new THREE.Matrix4(),
 
-	_vector3 = new THREE.Vector4(),
+	_vector3 = new THREE.Vector3(),
 
 	// light arrays cache
 
@@ -1031,7 +1031,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			}
 
-			sortArray.sort( function( a, b ) { return b[ 0 ] - a[ 0 ]; } );
+			sortArray.sort( numericalSort );
 
 			for ( v = 0; v < vl; v ++ ) {
 
@@ -2361,8 +2361,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					uvi = uv[ i ];
 
-					uvArray[ offset_uv ]     = uvi.u;
-					uvArray[ offset_uv + 1 ] = uvi.v;
+					uvArray[ offset_uv ]     = uvi.x;
+					uvArray[ offset_uv + 1 ] = uvi.y;
 
 					offset_uv += 2;
 
@@ -2382,8 +2382,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					uvi = uv[ i ];
 
-					uvArray[ offset_uv ]     = uvi.u;
-					uvArray[ offset_uv + 1 ] = uvi.v;
+					uvArray[ offset_uv ]     = uvi.x;
+					uvArray[ offset_uv + 1 ] = uvi.y;
 
 					offset_uv += 2;
 
@@ -2414,8 +2414,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					uv2i = uv2[ i ];
 
-					uv2Array[ offset_uv2 ]     = uv2i.u;
-					uv2Array[ offset_uv2 + 1 ] = uv2i.v;
+					uv2Array[ offset_uv2 ]     = uv2i.x;
+					uv2Array[ offset_uv2 + 1 ] = uv2i.y;
 
 					offset_uv2 += 2;
 
@@ -2435,8 +2435,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 					uv2i = uv2[ i ];
 
-					uv2Array[ offset_uv2 ]     = uv2i.u;
-					uv2Array[ offset_uv2 + 1 ] = uv2i.v;
+					uv2Array[ offset_uv2 ]     = uv2i.x;
+					uv2Array[ offset_uv2 + 1 ] = uv2i.y;
 
 					offset_uv2 += 2;
 
@@ -3798,7 +3798,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( influence > 0 ) {
 
-					activeInfluenceIndices.push( [ i, influence ] );
+					activeInfluenceIndices.push( [ influence, i ] );
 
 				}
 
@@ -3825,7 +3825,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( activeInfluenceIndices[ m ] ) {
 
-					influenceIndex = activeInfluenceIndices[ m ][ 0 ];
+					influenceIndex = activeInfluenceIndices[ m ][ 1 ];
 
 					if ( attributes[ "morphTarget" + m ] >= 0 ) {
 
@@ -3896,7 +3896,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	function numericalSort ( a, b ) {
 
-		return b[ 1 ] - a[ 1 ];
+		return b[ 0 ] - a[ 0 ];
 
 	};
 
@@ -6928,7 +6928,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 			}
 
 			_gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
-			_gl.bindFramebuffer( _gl.FRAMEBUFFER, null);
+			_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
 
 		}
 

+ 4 - 7
src/renderers/WebGLShaders.js

@@ -268,19 +268,16 @@ THREE.ShaderChunk = {
 
 		"#ifdef USE_MAP",
 
+			"vec4 texelColor = texture2D( map, vUv );",
+
 			"#ifdef GAMMA_INPUT",
 
-				"vec4 texelColor = texture2D( map, vUv );",
 				"texelColor.xyz *= texelColor.xyz;",
 
-				"gl_FragColor = gl_FragColor * texelColor;",
-
-			"#else",
-
-				"gl_FragColor = gl_FragColor * texture2D( map, vUv );",
-
 			"#endif",
 
+			"gl_FragColor = gl_FragColor * texelColor;",
+
 		"#endif"
 
 	].join("\n"),

+ 266 - 0
test/core/Box2.js

@@ -0,0 +1,266 @@
+	/**
+ * @author bhouston / http://exocortex.com
+ */
+
+module( "Box2" );
+
+test( "constructor", function() {
+	var a = new THREE.Box2();
+	ok( a.min.equals( posInf2 ), "Passed!" );
+	ok( a.max.equals( negInf2 ), "Passed!" );
+
+	a = new THREE.Box2( zero2 );
+	ok( a.min.equals( zero2 ), "Passed!" );
+	ok( a.max.equals( zero2 ), "Passed!" );
+
+	a = new THREE.Box2( zero2, one2 );
+	ok( a.min.equals( zero2 ), "Passed!" );
+	ok( a.max.equals( one2 ), "Passed!" );
+});
+
+
+test( "copy", function() {
+	var a = new THREE.Box2( zero2, one2 );
+	var b = new THREE.Box2().copy( a );
+	ok( b.min.equals( zero2 ), "Passed!" );
+	ok( b.max.equals( one2 ), "Passed!" );
+
+	// ensure that it is a true copy
+	a.min = zero2;
+	a.max = one2;
+	ok( b.min.equals( zero2 ), "Passed!" );
+	ok( b.max.equals( one2 ), "Passed!" );
+});
+
+test( "set", function() {
+	var a = new THREE.Box2();
+
+	a.set( zero2, one2 )
+	ok( a.min.equals( zero2 ), "Passed!" );
+	ok( a.max.equals( one2 ), "Passed!" );
+});
+
+test( "empty/makeEmpty", function() {
+	var a = new THREE.Box2();
+
+	ok( a.empty(), "Passed!" );
+
+	var a = new THREE.Box2( zero2, one2 );
+	ok( ! a.empty(), "Passed!" );
+
+	a.makeEmpty();
+	ok( a.empty(), "Passed!" );
+});
+
+test( "volume", function() {
+	var a = new THREE.Box2( zero2, one2 );
+	ok( a.volume() == 1, "Passed!" );
+
+	a = new THREE.Box2( one2.clone().negate(), zero2 );
+	ok( a.volume() == 1, "Passed!" );
+});
+
+test( "center", function() {
+	var a = new THREE.Box2( zero2 );
+
+	ok( a.center().equals( zero2 ), "Passed!" );
+
+	a = new THREE.Box2( zero2, one2 );
+	var midpoint = one2.clone().multiplyScalar( 0.5 );
+	ok( a.center().equals( midpoint ), "Passed!" );
+});
+
+test( "size", function() {
+	var a = new THREE.Box2( zero2 );
+
+	ok( a.size().equals( zero2 ), "Passed!" );
+
+	a = new THREE.Box2( zero2, one2 );
+	ok( a.size().equals( one2 ), "Passed!" );
+});
+
+test( "expandByPoint", function() {
+	var a = new THREE.Box2( zero2 );
+
+	a.expandByPoint( zero2 );
+	ok( a.size().equals( zero2 ), "Passed!" );
+
+	a.expandByPoint( one2 );
+	ok( a.size().equals( one2 ), "Passed!" );
+
+	a.expandByPoint( one2.clone().negate() );
+	ok( a.size().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
+	ok( a.center().equals( zero2 ), "Passed!" );
+});
+
+test( "expandByVector", function() {
+	var a = new THREE.Box2( zero2 );
+
+	a.expandByVector( zero2 );
+	ok( a.size().equals( zero2 ), "Passed!" );
+
+	a.expandByVector( one2 );
+	ok( a.size().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
+	ok( a.center().equals( zero2 ), "Passed!" );
+});
+
+test( "expandByScalar", function() {
+	var a = new THREE.Box2( zero2 );
+
+	a.expandByScalar( 0 );
+	ok( a.size().equals( zero2 ), "Passed!" );
+
+	a.expandByScalar( 1 );
+	ok( a.size().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
+	ok( a.center().equals( zero2 ), "Passed!" );
+});
+
+test( "containsPoint", function() {
+	var a = new THREE.Box2( zero2 );
+
+	ok( a.containsPoint( zero2 ), "Passed!" );
+	ok( ! a.containsPoint( one2 ), "Passed!" );
+
+	a.expandByScalar( 1 );
+	ok( a.containsPoint( zero2 ), "Passed!" );
+	ok( a.containsPoint( one2 ), "Passed!" );
+	ok( a.containsPoint( one2.clone().negate() ), "Passed!" );
+});
+
+test( "containsBox", function() {
+	var a = new THREE.Box2( zero2 );
+	var b = new THREE.Box2( zero2, one2 );
+	var c = new THREE.Box2( one2.clone().negate(), one2 );
+
+	ok( a.containsBox( a ), "Passed!" );
+	ok( ! a.containsBox( b ), "Passed!" );
+	ok( ! a.containsBox( c ), "Passed!" );
+
+	ok( b.containsBox( a ), "Passed!" );
+	ok( c.containsBox( a ), "Passed!" );
+	ok( ! b.containsBox( c ), "Passed!" );
+});
+
+test( "getParameter", function() {
+	var a = new THREE.Box2( zero2, one2 );
+	var b = new THREE.Box2( one2.clone().negate(), one2 );
+
+	ok( a.getParameter( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
+	ok( a.getParameter( new THREE.Vector2( 1, 1 ) ).equals( new THREE.Vector2( 1, 1 ) ), "Passed!" );
+
+	ok( b.getParameter( new THREE.Vector2( -1, -1 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
+	ok( b.getParameter( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0.5, 0.5 ) ), "Passed!" );
+	ok( b.getParameter( new THREE.Vector2( 1, 1 ) ).equals( new THREE.Vector2( 1, 1 ) ), "Passed!" );
+});
+
+test( "clampPoint", function() {
+	var a = new THREE.Box2( zero2, zero2 );
+	var b = new THREE.Box2( one2.clone().negate(), one2 );
+
+	ok( a.clampPoint( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
+	ok( a.clampPoint( new THREE.Vector2( 1, 1 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
+	ok( a.clampPoint( new THREE.Vector2( -1, -1 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
+
+	ok( b.clampPoint( new THREE.Vector2( 2, 2 ) ).equals( new THREE.Vector2( 1, 1 ) ), "Passed!" );
+	ok( b.clampPoint( new THREE.Vector2( 1, 1 ) ).equals( new THREE.Vector2( 1, 1 ) ), "Passed!" );
+	ok( b.clampPoint( new THREE.Vector2( 0, 0 ) ).equals( new THREE.Vector2( 0, 0 ) ), "Passed!" );
+	ok( b.clampPoint( new THREE.Vector2( -1, -1 ) ).equals( new THREE.Vector2( -1, -1 ) ), "Passed!" );
+	ok( b.clampPoint( new THREE.Vector2( -2, -2 ) ).equals( new THREE.Vector2( -1, -1 ) ), "Passed!" );
+});
+
+test( "distanceToPoint", function() {
+	var a = new THREE.Box2( zero2, zero2 );
+	var b = new THREE.Box2( one2.clone().negate(), one2 );
+
+	ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
+	ok( a.distanceToPoint( new THREE.Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );
+	ok( a.distanceToPoint( new THREE.Vector2( -1, -1 ) ) == Math.sqrt( 2 ), "Passed!" );
+
+	ok( b.distanceToPoint( new THREE.Vector2( 2, 2 ) ) == Math.sqrt( 2 ), "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector2( 1, 1 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector2( -1, -1 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector2( -2, -2 ) ) == Math.sqrt( 2 ), "Passed!" );
+});
+
+test( "distanceToPoint", function() {
+	var a = new THREE.Box2( zero2, zero2 );
+	var b = new THREE.Box2( one2.clone().negate(), one2 );
+
+	ok( a.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
+	ok( a.distanceToPoint( new THREE.Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );
+	ok( a.distanceToPoint( new THREE.Vector2( -1, -1 ) ) == Math.sqrt( 2 ), "Passed!" );
+
+	ok( b.distanceToPoint( new THREE.Vector2( 2, 2 ) ) == Math.sqrt( 2 ), "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector2( 1, 1 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector2( 0, 0 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector2( -1, -1 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector2( -2, -2 ) ) == Math.sqrt( 2 ), "Passed!" );
+});
+
+test( "isIntersection", function() {
+	var a = new THREE.Box2( zero2 );
+	var b = new THREE.Box2( zero2, one2 );
+	var c = new THREE.Box2( one2.clone().negate(), one2 );
+
+	ok( a.isIntersection( a ), "Passed!" );
+	ok( a.isIntersection( b ), "Passed!" );
+	ok( a.isIntersection( c ), "Passed!" );
+
+	ok( b.isIntersection( a ), "Passed!" );
+	ok( c.isIntersection( a ), "Passed!" );
+	ok( b.isIntersection( c ), "Passed!" );
+
+	b.translate( new THREE.Vector2( 2, 2 ) );
+	ok( ! a.isIntersection( b ), "Passed!" );
+	ok( ! b.isIntersection( a ), "Passed!" );
+	ok( ! b.isIntersection( c ), "Passed!" );
+});
+
+test( "intersect", function() {
+	var a = new THREE.Box2( zero2 );
+	var b = new THREE.Box2( zero2, one2 );
+	var c = new THREE.Box2( one2.clone().negate(), one2 );
+
+	ok( a.clone().intersect( a ).equals( a ), "Passed!" );
+	ok( a.clone().intersect( b ).equals( a ), "Passed!" );
+	ok( b.clone().intersect( b ).equals( b ), "Passed!" );
+	ok( a.clone().intersect( c ).equals( a ), "Passed!" );
+	ok( b.clone().intersect( c ).equals( b ), "Passed!" );
+	ok( c.clone().intersect( c ).equals( c ), "Passed!" );
+});
+
+test( "union", function() {
+	var a = new THREE.Box2( zero2 );
+	var b = new THREE.Box2( zero2, one2 );
+	var c = new THREE.Box2( one2.clone().negate(), one2 );
+
+	ok( a.clone().union( a ).equals( a ), "Passed!" );
+	ok( a.clone().union( b ).equals( b ), "Passed!" );
+	ok( a.clone().union( c ).equals( c ), "Passed!" );
+	ok( b.clone().union( c ).equals( c ), "Passed!" );
+});
+
+test( "translate", function() {
+	var a = new THREE.Box2( zero2 );
+	var b = new THREE.Box2( zero2, one2 );
+	var c = new THREE.Box2( one2.clone().negate(), one2 );
+	var d = new THREE.Box2( one2.clone().negate(), zero2 );
+
+	ok( a.clone().translate( one2 ).equals( new THREE.Box2( one2, one2 ) ), "Passed!" );
+	ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" );
+	ok( d.clone().translate( one2 ).equals( b ), "Passed!" );
+	ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" );
+});
+
+test( "scale", function() {
+	var a = new THREE.Box2( zero2 );
+	var b = new THREE.Box2( zero2, one2 );
+	var c = new THREE.Box2( one2.clone().negate(), one2 );
+	var d = new THREE.Box2( one2.clone().negate(), zero2 );
+
+	ok( a.clone().scale( 0 ).equals( a ), "Passed!" );
+	ok( c.clone().scale( 0 ).equals( a ), "Passed!" );
+	ok( b.clone().scale( 3 ).equals( new THREE.Box2( new THREE.Vector2( -1, -1, -1 ), new THREE.Vector2( 2, 2, 2 ) ) ), "Passed!" );
+	ok( d.clone().scale( 3 ).equals( new THREE.Box2( new THREE.Vector2( 2, 2, 2 ).negate(), new THREE.Vector2( 1, 1, 1 ) ) ), "Passed!" );
+});

+ 262 - 0
test/core/Box3.js

@@ -0,0 +1,262 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+module( "Box3" );
+
+test( "constructor", function() {
+	var a = new THREE.Box3();
+	ok( a.min.equals( posInf3 ), "Passed!" );
+	ok( a.max.equals( negInf3 ), "Passed!" );
+
+	a = new THREE.Box3( zero3 );
+	ok( a.min.equals( zero3 ), "Passed!" );
+	ok( a.max.equals( zero3 ), "Passed!" );
+
+	a = new THREE.Box3( zero3, one3 );
+	ok( a.min.equals( zero3 ), "Passed!" );
+	ok( a.max.equals( one3 ), "Passed!" );
+});
+
+test( "copy", function() {
+	var a = new THREE.Box3( zero3, one3 );
+	var b = new THREE.Box3().copy( a );
+	ok( b.min.equals( zero3 ), "Passed!" );
+	ok( b.max.equals( one3 ), "Passed!" );
+
+	// ensure that it is a true copy
+	a.min = zero3;
+	a.max = one3;
+	ok( b.min.equals( zero3 ), "Passed!" );
+	ok( b.max.equals( one3 ), "Passed!" );
+});
+
+test( "set", function() {
+	var a = new THREE.Box3();
+
+	a.set( zero3, one3 )
+	ok( a.min.equals( zero3 ), "Passed!" );
+	ok( a.max.equals( one3 ), "Passed!" );
+});
+
+test( "empty/makeEmpty", function() {
+	var a = new THREE.Box3();
+
+	ok( a.empty(), "Passed!" );
+
+	var a = new THREE.Box3( zero3, one3 );
+	ok( ! a.empty(), "Passed!" );
+
+	a.makeEmpty();
+	ok( a.empty(), "Passed!" );
+});
+
+test( "volume", function() {
+	var a = new THREE.Box3( zero3, one3 );
+	ok( a.volume() == 1, "Passed!" );
+});
+
+test( "center", function() {
+	var a = new THREE.Box3( zero3 );
+
+	ok( a.center().equals( zero3 ), "Passed!" );
+
+	a = new THREE.Box3( zero3, one3 );
+	var midpoint = one3.clone().multiplyScalar( 0.5 );
+	ok( a.center().equals( midpoint ), "Passed!" );
+});
+
+test( "size", function() {
+	var a = new THREE.Box3( zero3 );
+
+	ok( a.size().equals( zero3 ), "Passed!" );
+
+	a = new THREE.Box3( zero3, one3 );
+	ok( a.size().equals( one3 ), "Passed!" );
+});
+
+test( "expandByPoint", function() {
+	var a = new THREE.Box3( zero3 );
+
+	a.expandByPoint( zero3 );
+	ok( a.size().equals( zero3 ), "Passed!" );
+
+	a.expandByPoint( one3 );
+	ok( a.size().equals( one3 ), "Passed!" );
+
+	a.expandByPoint( one3.clone().negate() );
+	ok( a.size().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
+	ok( a.center().equals( zero3 ), "Passed!" );
+});
+
+test( "expandByVector", function() {
+	var a = new THREE.Box3( zero3 );
+
+	a.expandByVector( zero3 );
+	ok( a.size().equals( zero3 ), "Passed!" );
+
+	a.expandByVector( one3 );
+	ok( a.size().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
+	ok( a.center().equals( zero3 ), "Passed!" );
+});
+
+test( "expandByScalar", function() {
+	var a = new THREE.Box3( zero3 );
+
+	a.expandByScalar( 0 );
+	ok( a.size().equals( zero3 ), "Passed!" );
+
+	a.expandByScalar( 1 );
+	ok( a.size().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
+	ok( a.center().equals( zero3 ), "Passed!" );
+});
+
+test( "containsPoint", function() {
+	var a = new THREE.Box3( zero3 );
+
+	ok( a.containsPoint( zero3 ), "Passed!" );
+	ok( ! a.containsPoint( one3 ), "Passed!" );
+
+	a.expandByScalar( 1 );
+	ok( a.containsPoint( zero3 ), "Passed!" );
+	ok( a.containsPoint( one3 ), "Passed!" );
+	ok( a.containsPoint( one3.clone().negate() ), "Passed!" );
+});
+
+test( "containsBox", function() {
+	var a = new THREE.Box3( zero3 );
+	var b = new THREE.Box3( zero3, one3 );
+	var c = new THREE.Box3( one3.clone().negate(), one3 );
+
+	ok( a.containsBox( a ), "Passed!" );
+	ok( ! a.containsBox( b ), "Passed!" );
+	ok( ! a.containsBox( c ), "Passed!" );
+
+	ok( b.containsBox( a ), "Passed!" );
+	ok( c.containsBox( a ), "Passed!" );
+	ok( ! b.containsBox( c ), "Passed!" );
+});
+
+test( "getParameter", function() {
+	var a = new THREE.Box3( zero3, one3 );
+	var b = new THREE.Box3( one3.clone().negate(), one3 );
+
+	ok( a.getParameter( new THREE.Vector3( 0, 0, 0 ) ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	ok( a.getParameter( new THREE.Vector3( 1, 1, 1 ) ).equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" );
+
+	ok( b.getParameter( new THREE.Vector3( -1, -1, -1 ) ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	ok( b.getParameter( new THREE.Vector3( 0, 0, 0 ) ).equals( new THREE.Vector3( 0.5, 0.5, 0.5 ) ), "Passed!" );
+	ok( b.getParameter( new THREE.Vector3( 1, 1, 1 ) ).equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" );
+});
+
+test( "clampPoint", function() {
+	var a = new THREE.Box3( zero3, zero3 );
+	var b = new THREE.Box3( one3.clone().negate(), one3 );
+
+	ok( a.clampPoint( new THREE.Vector3( 0, 0, 0 ) ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	ok( a.clampPoint( new THREE.Vector3( 1, 1, 1 ) ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	ok( a.clampPoint( new THREE.Vector3( -1, -1, -1 ) ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+
+	ok( b.clampPoint( new THREE.Vector3( 2, 2, 2 ) ).equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" );
+	ok( b.clampPoint( new THREE.Vector3( 1, 1, 1 ) ).equals( new THREE.Vector3( 1, 1, 1 ) ), "Passed!" );
+	ok( b.clampPoint( new THREE.Vector3( 0, 0, 0 ) ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
+	ok( b.clampPoint( new THREE.Vector3( -1, -1, -1 ) ).equals( new THREE.Vector3( -1, -1, -1 ) ), "Passed!" );
+	ok( b.clampPoint( new THREE.Vector3( -2, -2, -2 ) ).equals( new THREE.Vector3( -1, -1, -1 ) ), "Passed!" );
+});
+
+test( "distanceToPoint", function() {
+	var a = new THREE.Box3( zero3, zero3  );
+	var b = new THREE.Box3( one3.clone().negate(), one3 );
+
+	ok( a.distanceToPoint( new THREE.Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
+	ok( a.distanceToPoint( new THREE.Vector3( 1, 1, 1 ) ) == Math.sqrt( 3 ), "Passed!" );
+	ok( a.distanceToPoint( new THREE.Vector3( -1, -1, -1 ) ) == Math.sqrt( 3 ), "Passed!" );
+
+	ok( b.distanceToPoint( new THREE.Vector3( 2, 2, 2 ) ) == Math.sqrt( 3 ), "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector3( 1, 1, 1 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector3( -1, -1, -1 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector3( -2, -2, -2 ) ) == Math.sqrt( 3 ), "Passed!" );
+});
+
+test( "distanceToPoint", function() {
+	var a = new THREE.Box3( zero3, zero3  );
+	var b = new THREE.Box3( one3.clone().negate(), one3 );
+
+	ok( a.distanceToPoint( new THREE.Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
+	ok( a.distanceToPoint( new THREE.Vector3( 1, 1, 1 ) ) == Math.sqrt( 3 ), "Passed!" );
+	ok( a.distanceToPoint( new THREE.Vector3( -1, -1, -1 ) ) == Math.sqrt( 3 ), "Passed!" );
+
+	ok( b.distanceToPoint( new THREE.Vector3( 2, 2, 2 ) ) == Math.sqrt( 3 ), "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector3( 1, 1, 1 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector3( -1, -1, -1 ) ) == 0, "Passed!" );
+	ok( b.distanceToPoint( new THREE.Vector3( -2, -2, -2 ) ) == Math.sqrt( 3 ), "Passed!" );
+});
+
+test( "isIntersection", function() {
+	var a = new THREE.Box3( zero3 );
+	var b = new THREE.Box3( zero3, one3 );
+	var c = new THREE.Box3( one3.clone().negate(), one3 );
+
+	ok( a.isIntersection( a ), "Passed!" );
+	ok( a.isIntersection( b ), "Passed!" );
+	ok( a.isIntersection( c ), "Passed!" );
+
+	ok( b.isIntersection( a ), "Passed!" );
+	ok( c.isIntersection( a ), "Passed!" );
+	ok( b.isIntersection( c ), "Passed!" );
+
+	b.translate( new THREE.Vector3( 2, 2, 2 ) );
+	ok( ! a.isIntersection( b ), "Passed!" );
+	ok( ! b.isIntersection( a ), "Passed!" );
+	ok( ! b.isIntersection( c ), "Passed!" );
+});
+
+test( "intersect", function() {
+	var a = new THREE.Box3( zero3 );
+	var b = new THREE.Box3( zero3, one3 );
+	var c = new THREE.Box3( one3.clone().negate(), one3 );
+
+	ok( a.clone().intersect( a ).equals( a ), "Passed!" );
+	ok( a.clone().intersect( b ).equals( a ), "Passed!" );
+	ok( b.clone().intersect( b ).equals( b ), "Passed!" );
+	ok( a.clone().intersect( c ).equals( a ), "Passed!" );
+	ok( b.clone().intersect( c ).equals( b ), "Passed!" );
+	ok( c.clone().intersect( c ).equals( c ), "Passed!" );
+});
+
+test( "union", function() {
+	var a = new THREE.Box3( zero3 );
+	var b = new THREE.Box3( zero3, one3 );
+	var c = new THREE.Box3( one3.clone().negate(), one3 );
+
+	ok( a.clone().union( a ).equals( a ), "Passed!" );
+	ok( a.clone().union( b ).equals( b ), "Passed!" );
+	ok( a.clone().union( c ).equals( c ), "Passed!" );
+	ok( b.clone().union( c ).equals( c ), "Passed!" );
+});
+
+test( "translate", function() {
+	var a = new THREE.Box3( zero3 );
+	var b = new THREE.Box3( zero3, one3 );
+	var c = new THREE.Box3( one3.clone().negate(), one3 );
+	var d = new THREE.Box3( one3.clone().negate(), zero3 );
+
+	ok( a.clone().translate( one3 ).equals( new THREE.Box3( one3, one3 ) ), "Passed!" );
+	ok( a.clone().translate( one3 ).translate( one3.clone().negate() ).equals( a ), "Passed!" );
+	ok( d.clone().translate( one3 ).equals( b ), "Passed!" );
+	ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" );
+});
+
+test( "scale", function() {
+	var a = new THREE.Box3( zero3 );
+	var b = new THREE.Box3( zero3, one3 );
+	var c = new THREE.Box3( one3.clone().negate(), one3 );
+	var d = new THREE.Box3( one3.clone().negate(), zero3 );
+
+	ok( a.clone().scale( 0 ).equals( a ), "Passed!" );
+	ok( c.clone().scale( 0 ).equals( a ), "Passed!" );
+	ok( b.clone().scale( 3 ).equals( new THREE.Box3( new THREE.Vector3( -1, -1, -1 ), new THREE.Vector3( 2, 2, 2 ) ) ), "Passed!" );
+	ok( d.clone().scale( 3 ).equals( new THREE.Box3( new THREE.Vector3( 2, 2, 2 ).negate(), new THREE.Vector3( 1, 1, 1 ) ) ), "Passed!" );
+});

+ 22 - 0
test/core/Constants.js

@@ -0,0 +1,22 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+var x = 2;
+var y = 3;
+var z = 4;
+var w = 5;
+
+var negInf2 = new THREE.Vector2( -Infinity, -Infinity );
+var posInf2 = new THREE.Vector2( Infinity, Infinity );
+
+var zero2 = new THREE.Vector2();
+var one2 = new THREE.Vector2( 1, 1 );
+var two2 = new THREE.Vector2( 2, 2 );
+
+var negInf3 = new THREE.Vector3( -Infinity, -Infinity, -Infinity );
+var posInf3 = new THREE.Vector3( Infinity, Infinity, Infinity );
+
+var zero3 = new THREE.Vector3();
+var one3 = new THREE.Vector3( 1, 1, 1 );
+var two3 = new THREE.Vector3( 2, 2, 2 );

+ 96 - 0
test/core/Plane.js

@@ -0,0 +1,96 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+module( "Plane" );
+
+test( "constructor", function() {
+	var a = new THREE.Plane();
+	ok( a.normal.x == 0, "Passed!" );
+	ok( a.normal.y == 0, "Passed!" );
+	ok( a.normal.z == 0, "Passed!" );
+	ok( a.constant == 0, "Passed!" );
+
+	a = new THREE.Plane( one3, 0 );
+	ok( a.normal.x == 1, "Passed!" );
+	ok( a.normal.y == 1, "Passed!" );
+	ok( a.normal.z == 1, "Passed!" );
+	ok( a.constant == 0, "Passed!" );
+
+	a = new THREE.Plane( one3, 1 );
+	ok( a.normal.x == 1, "Passed!" );
+	ok( a.normal.y == 1, "Passed!" );
+	ok( a.normal.z == 1, "Passed!" );
+	ok( a.constant == 1, "Passed!" );
+});
+
+test( "copy", function() {
+	var a = new THREE.Plane( new THREE.Vector3( x, y, z ), w );
+	var b = new THREE.Plane().copy( a );
+	ok( b.normal.x == x, "Passed!" );
+	ok( b.normal.y == y, "Passed!" );
+	ok( b.normal.z == z, "Passed!" );
+	ok( b.constant == w, "Passed!" );
+
+	// ensure that it is a true copy
+	a.normal.x = 0;
+	a.normal.y = -1;
+	a.normal.z = -2;
+	a.constant = -3;
+	ok( b.normal.x == x, "Passed!" );
+	ok( b.normal.y == y, "Passed!" );
+	ok( b.normal.z == z, "Passed!" );
+	ok( b.constant == w, "Passed!" );
+});
+
+test( "set", function() {
+	var a = new THREE.Plane();
+	ok( a.normal.x == 0, "Passed!" );
+	ok( a.normal.y == 0, "Passed!" );
+	ok( a.normal.z == 0, "Passed!" );
+	ok( a.constant == 0, "Passed!" );
+
+	var b = a.clone().set( new THREE.Vector3( x, y, z ), w );
+	ok( b.normal.x == x, "Passed!" );
+	ok( b.normal.y == y, "Passed!" );
+	ok( b.normal.z == z, "Passed!" );
+	ok( b.constant == w, "Passed!" );
+});
+
+test( "setComponents", function() {
+	var a = new THREE.Plane();
+	ok( a.normal.x == 0, "Passed!" );
+	ok( a.normal.y == 0, "Passed!" );
+	ok( a.normal.z == 0, "Passed!" );
+	ok( a.constant == 0, "Passed!" );
+
+	var b = a.clone().setComponents( x, y, z , w );
+	ok( b.normal.x == x, "Passed!" );
+	ok( b.normal.y == y, "Passed!" );
+	ok( b.normal.z == z, "Passed!" );
+	ok( b.constant == w, "Passed!" );
+});
+
+test( "setFromNormalAndCoplanarPoint", function() {
+	var a = new THREE.Plane().setFromNormalAndCoplanarPoint( one3, zero3 );
+	
+	ok( a.normal.equals( one3 ), "Passed!" );
+	ok( a.constant == 0, "Passed!" );
+});
+
+test( "flip", function() {
+	var a = new THREE.Plane( one3, 0 );
+	
+	ok( a.normal.equals( one3 ), "Passed!" );
+	a.flip();
+	ok( a.normal.negate().equals( one3 ), "Passed!" );
+});
+
+test( "normalize", function() {
+	var a = new THREE.Plane( new THREE.Vector3( 2, 0, 0 ), 2 );
+	
+	a.normalize();
+	ok( a.normal.length() == 1, "Passed!" );
+	ok( a.normal.equals( new THREE.Vector3( 1, 0, 0 ) ), "Passed!" );
+	ok( a.constant == 1, "Passed!" );
+});

+ 39 - 0
test/core/Sphere.js

@@ -0,0 +1,39 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+module( "Sphere" );
+
+test( "constructor", function() {
+	var a = new THREE.Sphere();
+	ok( a.center.equals( zero3 ), "Passed!" );
+	ok( a.radius == 0, "Passed!" );
+
+	a = new THREE.Sphere( one3, 1 );
+	ok( a.center.equals( one3 ), "Passed!" );
+	ok( a.radius == 1, "Passed!" );
+});
+
+test( "copy", function() {
+	var a = new THREE.Sphere( one3, 1 );
+	var b = new THREE.Sphere().copy( a );
+
+	ok( b.center.equals( one3 ), "Passed!" );
+	ok( b.radius == 1, "Passed!" );
+
+	// ensure that it is a true copy
+	a.center = zero3;
+	a.radius = 0;
+	ok( b.center.equals( one3 ), "Passed!" );
+	ok( b.radius == 1, "Passed!" );
+});
+
+test( "set", function() {
+	var a = new THREE.Sphere();
+	ok( a.center.equals( zero3 ), "Passed!" );
+	ok( a.radius == 0, "Passed!" );
+
+	a.set( one3, 1 )
+	ok( a.center.equals( one3 ), "Passed!" );
+	ok( a.radius == 1, "Passed!" );
+});

+ 220 - 0
test/core/Vector2.js

@@ -0,0 +1,220 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+module( "Vector2" );
+
+test( "constructor", function() {
+	var a = new THREE.Vector2();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+
+	a = new THREE.Vector2( x, y );
+	ok( a.x === x, "Passed!" );
+	ok( a.y === y, "Passed!" );
+});
+
+test( "copy", function() {
+	var a = new THREE.Vector2( x, y );
+	var b = new THREE.Vector2().copy( a );
+	ok( b.x == x, "Passed!" );
+	ok( b.y == y, "Passed!" );
+
+	// ensure that it is a true copy
+	a.x = 0;
+	a.y = -1;
+	ok( b.x == x, "Passed!" );
+	ok( b.y == y, "Passed!" );
+});
+
+test( "set", function() {
+	var a = new THREE.Vector2();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+
+	a.set( x, y )
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+});
+
+test( "setX,setY", function() {
+	var a = new THREE.Vector2();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+
+	a.setX( x );
+	a.setY( y );
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+});
+
+test( "add", function() {
+	var a = new THREE.Vector2( x, y );
+	var b = new THREE.Vector2( -x, -y );
+
+	a.addSelf( b );
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+
+	var c = new THREE.Vector2().add( b, b );
+	ok( c.x == -2*x, "Passed!" );
+	ok( c.y == -2*y, "Passed!" );	
+});
+
+test( "sub", function() {
+	var a = new THREE.Vector2( x, y );
+	var b = new THREE.Vector2( -x, -y );
+
+	a.subSelf( b );
+	ok( a.x == 2*x, "Passed!" );
+	ok( a.y == 2*y, "Passed!" );
+
+	var c = new THREE.Vector2().sub( a, a );
+	ok( c.x == 0, "Passed!" );
+	ok( c.y == 0, "Passed!" );	
+});
+
+test( "multiply/divide", function() {
+	var a = new THREE.Vector2( x, y );
+	var b = new THREE.Vector2( -x, -y );
+
+	a.multiplyScalar( -2 );
+	ok( a.x == x*-2, "Passed!" );
+	ok( a.y == y*-2, "Passed!" );
+
+	b.multiplyScalar( -2 );
+	ok( b.x == 2*x, "Passed!" );
+	ok( b.y == 2*y, "Passed!" );	
+
+	a.divideScalar( -2 );
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+
+	b.divideScalar( -2 );
+	ok( b.x == -x, "Passed!" );
+	ok( b.y == -y, "Passed!" );	
+});
+
+
+test( "min/max/clamp", function() {
+	var a = new THREE.Vector2( x, y );
+	var b = new THREE.Vector2( -x, -y );
+	var c = new THREE.Vector2();
+
+	c.copy( a ).minSelf( b );
+	ok( c.x == -x, "Passed!" );
+	ok( c.y == -y, "Passed!" );
+
+	c.copy( a ).maxSelf( b );
+	ok( c.x == x, "Passed!" );
+	ok( c.y == y, "Passed!" );
+
+	c.set( -2*x, 2*y );
+	c.clampSelf( b, a );
+	ok( c.x == -x, "Passed!" );
+	ok( c.y == y, "Passed!" );	
+});
+
+test( "negate", function() {
+	var a = new THREE.Vector2( x, y );
+	
+	a.negate();
+	ok( a.x == -x, "Passed!" );
+	ok( a.y == -y, "Passed!" );
+});
+
+test( "dot", function() {
+	var a = new THREE.Vector2( x, y );
+	var b = new THREE.Vector2( -x, -y );
+	var c = new THREE.Vector2();
+	
+	var result = a.dot( b );
+	ok( result == (-x*x-y*y), "Passed!" );
+
+	result = a.dot( c );
+	ok( result == 0, "Passed!" );
+});
+
+test( "length/lengthSq", function() {
+	var a = new THREE.Vector2( x, 0 );
+	var b = new THREE.Vector2( 0, -y );
+	var c = new THREE.Vector2();
+	
+	ok( a.length() == x, "Passed!" );
+	ok( a.lengthSq() == x*x, "Passed!" );
+	ok( b.length() == y, "Passed!" );
+	ok( b.lengthSq() == y*y, "Passed!" );
+	ok( c.length() == 0, "Passed!" );
+	ok( c.lengthSq() == 0, "Passed!" );
+
+	a.set( x, y );
+	ok( a.length() == Math.sqrt( x*x + y*y ), "Passed!" );
+	ok( a.lengthSq() == ( x*x + y*y ), "Passed!" );
+});
+
+test( "normalize", function() {
+	var a = new THREE.Vector2( x, 0 );
+	var b = new THREE.Vector2( 0, -y );
+	var c = new THREE.Vector2();
+	
+	a.normalize();
+	ok( a.length() == 1, "Passed!" );
+	ok( a.x == 1, "Passed!" );
+
+	b.normalize();
+	ok( b.length() == 1, "Passed!" );
+	ok( b.y == -1, "Passed!" );
+});
+
+test( "distanceTo/distanceToSquared", function() {
+	var a = new THREE.Vector2( x, 0 );
+	var b = new THREE.Vector2( 0, -y );
+	var c = new THREE.Vector2();
+	
+	ok( a.distanceTo( c ) == x, "Passed!" );
+	ok( a.distanceToSquared( c ) == x*x, "Passed!" );
+
+	ok( b.distanceTo( c ) == y, "Passed!" );
+	ok( b.distanceToSquared( c ) == y*y, "Passed!" );
+});
+
+test( "setLength", function() {
+	var a = new THREE.Vector2( x, 0 );
+	
+	ok( a.length() == x, "Passed!" );
+	a.setLength( y );
+	ok( a.length() == y, "Passed!" );
+});
+
+test( "lerpSelf/clone", function() {
+	var a = new THREE.Vector2( x, 0 );
+	var b = new THREE.Vector2( 0, -y );
+	
+	ok( a.lerpSelf( a, 0 ).equals( a.lerpSelf( a, 0.5 ) ), "Passed!" );
+	ok( a.lerpSelf( a, 0 ).equals( a.lerpSelf( a, 1 ) ), "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 0 ).equals( a ), "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 0.5 ).x == x*0.5, "Passed!" );
+	ok( a.clone().lerpSelf( b, 0.5 ).y == -y*0.5, "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 1 ).equals( b ), "Passed!" );
+});
+
+test( "equals", function() {
+	var a = new THREE.Vector2( x, 0 );
+	var b = new THREE.Vector2( 0, -y );
+	
+	ok( a.x != b.x, "Passed!" );
+	ok( a.y != b.y, "Passed!" );
+
+	ok( ! a.equals( b ), "Passed!" );
+	ok( ! b.equals( a ), "Passed!" );
+
+	a.copy( b );
+	ok( a.x == b.x, "Passed!" );
+	ok( a.y == b.y, "Passed!" );
+
+	ok( a.equals( b ), "Passed!" );
+	ok( b.equals( a ), "Passed!" );
+});

+ 256 - 0
test/core/Vector3.js

@@ -0,0 +1,256 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+module( "Vector3" );
+
+test( "constructor", function() {
+	var a = new THREE.Vector3();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+	ok( a.z == 0, "Passed!" );
+
+	a = new THREE.Vector3( x, y, z );
+	ok( a.x === x, "Passed!" );
+	ok( a.y === y, "Passed!" );
+	ok( a.z === z, "Passed!" );
+});
+
+test( "copy", function() {
+	var a = new THREE.Vector3( x, y, z );
+	var b = new THREE.Vector3().copy( a );
+	ok( b.x == x, "Passed!" );
+	ok( b.y == y, "Passed!" );
+	ok( b.z == z, "Passed!" );
+
+	// ensure that it is a true copy
+	a.x = 0;
+	a.y = -1;
+	a.z = -2;
+	ok( b.x == x, "Passed!" );
+	ok( b.y == y, "Passed!" );
+	ok( b.z == z, "Passed!" );
+});
+
+test( "set", function() {
+	var a = new THREE.Vector3();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+	ok( a.z == 0, "Passed!" );
+
+	a.set( x, y, z )
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+	ok( a.z == z, "Passed!" );
+});
+
+test( "setX,setY,setZ", function() {
+	var a = new THREE.Vector3();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+	ok( a.z == 0, "Passed!" );
+
+	a.setX( x );
+	a.setY( y );
+	a.setZ( z );
+
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+	ok( a.z == z, "Passed!" );
+});
+
+test( "add", function() {
+	var a = new THREE.Vector3( x, y, z );
+	var b = new THREE.Vector3( -x, -y, -z );
+
+	a.addSelf( b );
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+	ok( a.z == 0, "Passed!" );
+
+	var c = new THREE.Vector3().add( b, b );
+	ok( c.x == -2*x, "Passed!" );
+	ok( c.y == -2*y, "Passed!" );	
+	ok( c.z == -2*z, "Passed!" );	
+});
+
+test( "sub", function() {
+	var a = new THREE.Vector3( x, y, z );
+	var b = new THREE.Vector3( -x, -y, -z );
+
+	a.subSelf( b );
+	ok( a.x == 2*x, "Passed!" );
+	ok( a.y == 2*y, "Passed!" );
+	ok( a.z == 2*z, "Passed!" );
+
+	var c = new THREE.Vector3().sub( a, a );
+	ok( c.x == 0, "Passed!" );
+	ok( c.y == 0, "Passed!" );	
+	ok( c.z == 0, "Passed!" );	
+});
+
+test( "multiply/divide", function() {
+	var a = new THREE.Vector3( x, y, z );
+	var b = new THREE.Vector3( -x, -y, -z );
+
+	a.multiplyScalar( -2 );
+	ok( a.x == x*-2, "Passed!" );
+	ok( a.y == y*-2, "Passed!" );
+	ok( a.z == z*-2, "Passed!" );
+
+	b.multiplyScalar( -2 );
+	ok( b.x == 2*x, "Passed!" );
+	ok( b.y == 2*y, "Passed!" );	
+	ok( b.z == 2*z, "Passed!" );	
+
+	a.divideScalar( -2 );
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+	ok( a.z == z, "Passed!" );
+
+	b.divideScalar( -2 );
+	ok( b.x == -x, "Passed!" );
+	ok( b.y == -y, "Passed!" );	
+	ok( b.z == -z, "Passed!" );	
+});
+
+test( "min/max/clamp", function() {
+	var a = new THREE.Vector3( x, y, z );
+	var b = new THREE.Vector3( -x, -y, -z );
+	var c = new THREE.Vector3();
+
+	c.copy( a ).minSelf( b );
+	ok( c.x == -x, "Passed!" );
+	ok( c.y == -y, "Passed!" );
+	ok( c.z == -z, "Passed!" );
+
+	c.copy( a ).maxSelf( b );
+	ok( c.x == x, "Passed!" );
+	ok( c.y == y, "Passed!" );
+	ok( c.z == z, "Passed!" );
+
+	c.set( -2*x, 2*y, -2*z );
+	c.clampSelf( b, a );
+	ok( c.x == -x, "Passed!" );
+	ok( c.y == y, "Passed!" );	
+	ok( c.z == -z, "Passed!" );	
+});
+
+test( "negate", function() {
+	var a = new THREE.Vector3( x, y, z );
+	
+	a.negate();
+	ok( a.x == -x, "Passed!" );
+	ok( a.y == -y, "Passed!" );
+	ok( a.z == -z, "Passed!" );
+});
+
+test( "dot", function() {
+	var a = new THREE.Vector3( x, y, z );
+	var b = new THREE.Vector3( -x, -y, -z );
+	var c = new THREE.Vector3();
+	
+	var result = a.dot( b );
+	ok( result == (-x*x-y*y-z*z), "Passed!" );
+
+	result = a.dot( c );
+	ok( result == 0, "Passed!" );
+});
+
+test( "length/lengthSq", function() {
+	var a = new THREE.Vector3( x, 0, 0 );
+	var b = new THREE.Vector3( 0, -y, 0 );
+	var c = new THREE.Vector3( 0, 0, z );
+	var d = new THREE.Vector3();
+	
+	ok( a.length() == x, "Passed!" );
+	ok( a.lengthSq() == x*x, "Passed!" );
+	ok( b.length() == y, "Passed!" );
+	ok( b.lengthSq() == y*y, "Passed!" );
+	ok( c.length() == z, "Passed!" );
+	ok( c.lengthSq() == z*z, "Passed!" );
+	ok( d.length() == 0, "Passed!" );
+	ok( d.lengthSq() == 0, "Passed!" );
+
+	a.set( x, y, z );
+	ok( a.length() == Math.sqrt( x*x + y*y + z*z ), "Passed!" );
+	ok( a.lengthSq() == ( x*x + y*y + z*z ), "Passed!" );
+});
+
+test( "normalize", function() {
+	var a = new THREE.Vector3( x, 0, 0 );
+	var b = new THREE.Vector3( 0, -y, 0 );
+	var c = new THREE.Vector3( 0, 0, z );
+	
+	a.normalize();
+	ok( a.length() == 1, "Passed!" );
+	ok( a.x == 1, "Passed!" );
+
+	b.normalize();
+	ok( b.length() == 1, "Passed!" );
+	ok( b.y == -1, "Passed!" );
+
+	c.normalize();
+	ok( c.length() == 1, "Passed!" );
+	ok( c.z == 1, "Passed!" );
+});
+
+test( "distanceTo/distanceToSquared", function() {
+	var a = new THREE.Vector3( x, 0, 0 );
+	var b = new THREE.Vector3( 0, -y, 0 );
+	var c = new THREE.Vector3( 0, 0, z );
+	var d = new THREE.Vector3();
+	
+	ok( a.distanceTo( d ) == x, "Passed!" );
+	ok( a.distanceToSquared( d ) == x*x, "Passed!" );
+
+	ok( b.distanceTo( d ) == y, "Passed!" );
+	ok( b.distanceToSquared( d ) == y*y, "Passed!" );
+
+	ok( c.distanceTo( d ) == z, "Passed!" );
+	ok( c.distanceToSquared( d ) == z*z, "Passed!" );
+});
+
+test( "setLength", function() {
+	var a = new THREE.Vector3( x, 0, 0 );
+	
+	ok( a.length() == x, "Passed!" );
+	a.setLength( y );
+	ok( a.length() == y, "Passed!" );
+});
+
+test( "lerpSelf/clone", function() {
+	var a = new THREE.Vector3( x, 0, z );
+	var b = new THREE.Vector3( 0, -y, 0 );
+	
+	ok( a.lerpSelf( a, 0 ).equals( a.lerpSelf( a, 0.5 ) ), "Passed!" );
+	ok( a.lerpSelf( a, 0 ).equals( a.lerpSelf( a, 1 ) ), "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 0 ).equals( a ), "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 0.5 ).x == x*0.5, "Passed!" );
+	ok( a.clone().lerpSelf( b, 0.5 ).y == -y*0.5, "Passed!" );
+	ok( a.clone().lerpSelf( b, 0.5 ).z == z*0.5, "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 1 ).equals( b ), "Passed!" );
+});
+
+test( "equals", function() {
+	var a = new THREE.Vector3( x, 0, z );
+	var b = new THREE.Vector3( 0, -y, 0 );
+	
+	ok( a.x != b.x, "Passed!" );
+	ok( a.y != b.y, "Passed!" );
+	ok( a.z != b.z, "Passed!" );
+
+	ok( ! a.equals( b ), "Passed!" );
+	ok( ! b.equals( a ), "Passed!" );
+
+	a.copy( b );
+	ok( a.x == b.x, "Passed!" );
+	ok( a.y == b.y, "Passed!" );
+	ok( a.z == b.z, "Passed!" );
+
+	ok( a.equals( b ), "Passed!" );
+	ok( b.equals( a ), "Passed!" );
+});

+ 296 - 0
test/core/Vector4.js

@@ -0,0 +1,296 @@
+/**
+ * @author bhouston / http://exocortex.com
+ */
+
+module( "Vector4" );
+
+test( "constructor", function() {
+	var a = new THREE.Vector4();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+	ok( a.z == 0, "Passed!" );
+	ok( a.w == 1, "Passed!" );
+
+	a = new THREE.Vector4( x, y, z, w );
+	ok( a.x === x, "Passed!" );
+	ok( a.y === y, "Passed!" );
+	ok( a.z === z, "Passed!" );
+	ok( a.w === w, "Passed!" );
+});
+
+test( "copy", function() {
+	var a = new THREE.Vector4( x, y, z, w );
+	var b = new THREE.Vector4().copy( a );
+	ok( b.x == x, "Passed!" );
+	ok( b.y == y, "Passed!" );
+	ok( b.z == z, "Passed!" );
+	ok( b.w == w, "Passed!" );
+
+	// ensure that it is a true copy
+	a.x = 0;
+	a.y = -1;
+	a.z = -2;
+	a.w = -3;
+	ok( b.x == x, "Passed!" );
+	ok( b.y == y, "Passed!" );
+	ok( b.z == z, "Passed!" );
+	ok( b.w == w, "Passed!" );
+});
+
+test( "set", function() {
+	var a = new THREE.Vector4();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+	ok( a.z == 0, "Passed!" );
+	ok( a.w == 1, "Passed!" );
+
+	a.set( x, y, z, w )
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+	ok( a.z == z, "Passed!" );
+	ok( a.w == w, "Passed!" );
+});
+
+test( "setX,setY,setZ,setW", function() {
+	var a = new THREE.Vector4();
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+	ok( a.z == 0, "Passed!" );
+	ok( a.w == 1, "Passed!" );
+
+	a.setX( x );
+	a.setY( y );
+	a.setZ( z );
+	a.setW( w );
+
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+	ok( a.z == z, "Passed!" );
+	ok( a.w == w, "Passed!" );
+});
+
+test( "add", function() {
+	var a = new THREE.Vector4( x, y, z, w );
+	var b = new THREE.Vector4( -x, -y, -z, -w );
+
+	a.addSelf( b );
+	ok( a.x == 0, "Passed!" );
+	ok( a.y == 0, "Passed!" );
+	ok( a.z == 0, "Passed!" );
+	ok( a.w == 0, "Passed!" );
+
+	var c = new THREE.Vector4().add( b, b );
+	ok( c.x == -2*x, "Passed!" );
+	ok( c.y == -2*y, "Passed!" );	
+	ok( c.z == -2*z, "Passed!" );	
+	ok( c.w == -2*w, "Passed!" );	
+});
+
+test( "sub", function() {
+	var a = new THREE.Vector4( x, y, z, w );
+	var b = new THREE.Vector4( -x, -y, -z, -w );
+
+	a.subSelf( b );
+	ok( a.x == 2*x, "Passed!" );
+	ok( a.y == 2*y, "Passed!" );
+	ok( a.z == 2*z, "Passed!" );
+	ok( a.w == 2*w, "Passed!" );
+
+	var c = new THREE.Vector4().sub( a, a );
+	ok( c.x == 0, "Passed!" );
+	ok( c.y == 0, "Passed!" );	
+	ok( c.z == 0, "Passed!" );	
+	ok( c.w == 0, "Passed!" );	
+});
+
+test( "multiply/divide", function() {
+	var a = new THREE.Vector4( x, y, z, w );
+	var b = new THREE.Vector4( -x, -y, -z, -w );
+
+	a.multiplyScalar( -2 );
+	ok( a.x == x*-2, "Passed!" );
+	ok( a.y == y*-2, "Passed!" );
+	ok( a.z == z*-2, "Passed!" );
+	ok( a.w == w*-2, "Passed!" );
+
+	b.multiplyScalar( -2 );
+	ok( b.x == 2*x, "Passed!" );
+	ok( b.y == 2*y, "Passed!" );	
+	ok( b.z == 2*z, "Passed!" );	
+	ok( b.w == 2*w, "Passed!" );	
+
+	a.divideScalar( -2 );
+	ok( a.x == x, "Passed!" );
+	ok( a.y == y, "Passed!" );
+	ok( a.z == z, "Passed!" );
+	ok( a.w == w, "Passed!" );
+
+	b.divideScalar( -2 );
+	ok( b.x == -x, "Passed!" );
+	ok( b.y == -y, "Passed!" );	
+	ok( b.z == -z, "Passed!" );	
+	ok( b.w == -w, "Passed!" );	
+});
+
+test( "min/max/clamp", function() {
+	var a = new THREE.Vector4( x, y, z, w );
+	var b = new THREE.Vector4( -x, -y, -z, -w );
+	var c = new THREE.Vector4();
+
+	c.copy( a ).minSelf( b );
+	ok( c.x == -x, "Passed!" );
+	ok( c.y == -y, "Passed!" );
+	ok( c.z == -z, "Passed!" );
+	ok( c.w == -w, "Passed!" );
+
+	c.copy( a ).maxSelf( b );
+	ok( c.x == x, "Passed!" );
+	ok( c.y == y, "Passed!" );
+	ok( c.z == z, "Passed!" );
+	ok( c.w == w, "Passed!" );
+
+	c.set( -2*x, 2*y, -2*z, 2*w );
+	c.clampSelf( b, a );
+	ok( c.x == -x, "Passed!" );
+	ok( c.y == y, "Passed!" );	
+	ok( c.z == -z, "Passed!" );	
+	ok( c.w == w, "Passed!" );	
+});
+
+test( "negate", function() {
+	var a = new THREE.Vector4( x, y, z, w );
+	
+	a.negate();
+	ok( a.x == -x, "Passed!" );
+	ok( a.y == -y, "Passed!" );
+	ok( a.z == -z, "Passed!" );
+	ok( a.w == -w, "Passed!" );
+});
+
+test( "dot", function() {
+	var a = new THREE.Vector4( x, y, z, w );
+	var b = new THREE.Vector4( -x, -y, -z, -w );
+	var c = new THREE.Vector4( 0, 0, 0, 0 );
+	
+	var result = a.dot( b );
+	ok( result == (-x*x-y*y-z*z-w*w), "Passed!" );
+
+	result = a.dot( c );
+	ok( result == 0, "Passed!" );
+});
+
+test( "length/lengthSq", function() {
+	var a = new THREE.Vector4( x, 0, 0, 0 );
+	var b = new THREE.Vector4( 0, -y, 0, 0 );
+	var c = new THREE.Vector4( 0, 0, z, 0 );
+	var d = new THREE.Vector4( 0, 0, 0, w );
+	var e = new THREE.Vector4( 0, 0, 0, 0 );
+	
+	ok( a.length() == x, "Passed!" );
+	ok( a.lengthSq() == x*x, "Passed!" );
+	ok( b.length() == y, "Passed!" );
+	ok( b.lengthSq() == y*y, "Passed!" );
+	ok( c.length() == z, "Passed!" );
+	ok( c.lengthSq() == z*z, "Passed!" );
+	ok( d.length() == w, "Passed!" );
+	ok( d.lengthSq() == w*w, "Passed!" );
+	ok( e.length() == 0, "Passed!" );
+	ok( e.lengthSq() == 0, "Passed!" );
+
+	a.set( x, y, z, w );
+	ok( a.length() == Math.sqrt( x*x + y*y + z*z + w*w ), "Passed!" );
+	ok( a.lengthSq() == ( x*x + y*y + z*z + w*w ), "Passed!" );
+});
+
+test( "normalize", function() {
+	var a = new THREE.Vector4( x, 0, 0, 0 );
+	var b = new THREE.Vector4( 0, -y, 0, 0 );
+	var c = new THREE.Vector4( 0, 0, z, 0 );
+	var d = new THREE.Vector4( 0, 0, 0, -w );
+	
+	a.normalize();
+	ok( a.length() == 1, "Passed!" );
+	ok( a.x == 1, "Passed!" );
+
+	b.normalize();
+	ok( b.length() == 1, "Passed!" );
+	ok( b.y == -1, "Passed!" );
+
+	c.normalize();
+	ok( c.length() == 1, "Passed!" );
+	ok( c.z == 1, "Passed!" );
+
+	d.normalize();
+	ok( d.length() == 1, "Passed!" );
+	ok( d.w == -1, "Passed!" );
+});
+
+/*
+test( "distanceTo/distanceToSquared", function() {
+	var a = new THREE.Vector4( x, 0, 0, 0 );
+	var b = new THREE.Vector4( 0, -y, 0, 0 );
+	var c = new THREE.Vector4( 0, 0, z, 0 );
+	var d = new THREE.Vector4( 0, 0, 0, -w );
+	var e = new THREE.Vector4();
+	
+	ok( a.distanceTo( e ) == x, "Passed!" );
+	ok( a.distanceToSquared( e ) == x*x, "Passed!" );
+
+	ok( b.distanceTo( e ) == y, "Passed!" );
+	ok( b.distanceToSquared( e ) == y*y, "Passed!" );
+
+	ok( c.distanceTo( e ) == z, "Passed!" );
+	ok( c.distanceToSquared( e ) == z*z, "Passed!" );
+
+	ok( d.distanceTo( e ) == w, "Passed!" );
+	ok( d.distanceToSquared( e ) == w*w, "Passed!" );
+});
+*/
+
+
+test( "setLength", function() {
+	var a = new THREE.Vector4( x, 0, 0, 0 );
+	
+	ok( a.length() == x, "Passed!" );
+	a.setLength( y );
+	ok( a.length() == y, "Passed!" );
+});
+
+test( "lerpSelf/clone", function() {
+	var a = new THREE.Vector4( x, 0, z, 0 );
+	var b = new THREE.Vector4( 0, -y, 0, -w );
+	
+	ok( a.lerpSelf( a, 0 ).equals( a.lerpSelf( a, 0.5 ) ), "Passed!" );
+	ok( a.lerpSelf( a, 0 ).equals( a.lerpSelf( a, 1 ) ), "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 0 ).equals( a ), "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 0.5 ).x == x*0.5, "Passed!" );
+	ok( a.clone().lerpSelf( b, 0.5 ).y == -y*0.5, "Passed!" );
+	ok( a.clone().lerpSelf( b, 0.5 ).z == z*0.5, "Passed!" );
+	ok( a.clone().lerpSelf( b, 0.5 ).w == -w*0.5, "Passed!" );
+
+	ok( a.clone().lerpSelf( b, 1 ).equals( b ), "Passed!" );
+});
+
+test( "equals", function() {
+	var a = new THREE.Vector4( x, 0, z, 0 );
+	var b = new THREE.Vector4( 0, -y, 0, -w );
+	
+	ok( a.x != b.x, "Passed!" );
+	ok( a.y != b.y, "Passed!" );
+	ok( a.z != b.z, "Passed!" );
+	ok( a.w != b.w, "Passed!" );
+
+	ok( ! a.equals( b ), "Passed!" );
+	ok( ! b.equals( a ), "Passed!" );
+
+	a.copy( b );
+	ok( a.x == b.x, "Passed!" );
+	ok( a.y == b.y, "Passed!" );
+	ok( a.z == b.z, "Passed!" );
+	ok( a.w == b.w, "Passed!" );
+
+	ok( a.equals( b ), "Passed!" );
+	ok( b.equals( a ), "Passed!" );
+});

+ 25 - 0
test/index.html

@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>ThreeJS Test Suite</title>
+  <link rel="stylesheet" href="qunit/qunit-1.10.0.css">
+</head>
+<body>
+  <div id="qunit"></div>
+  <script src="../build/three.js"></script>
+  <script src="qunit/qunit-1.10.0.js"></script>
+  <script src="core/Constants.js"></script>
+
+  <!-- add class-based unit tests below -->
+
+  <script src="core/Box2.js"></script>
+  <script src="core/Box3.js"></script>
+  <script src="core/Plane.js"></script>
+  <script src="core/Sphere.js"></script>
+  <script src="core/Vector2.js"></script>
+  <script src="core/Vector3.js"></script>
+  <script src="core/Vector4.js"></script>
+  
+</body>
+</html>

+ 235 - 0
test/qunit/qunit-1.10.0.css

@@ -0,0 +1,235 @@
+/**
+ * QUnit v1.10.0 - A JavaScript Unit Testing Framework
+ *
+ * http://qunitjs.com
+ *
+ * Copyright 2012 jQuery Foundation and other contributors
+ * Released under the MIT license.
+ * http://jquery.org/license
+ */
+
+/** Font Family and Sizes */
+
+#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
+	font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
+}
+
+#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
+#qunit-tests { font-size: smaller; }
+
+
+/** Resets */
+
+#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
+	margin: 0;
+	padding: 0;
+}
+
+
+/** Header */
+
+#qunit-header {
+	padding: 0.5em 0 0.5em 1em;
+
+	color: #8699a4;
+	background-color: #0d3349;
+
+	font-size: 1.5em;
+	line-height: 1em;
+	font-weight: normal;
+
+	border-radius: 5px 5px 0 0;
+	-moz-border-radius: 5px 5px 0 0;
+	-webkit-border-top-right-radius: 5px;
+	-webkit-border-top-left-radius: 5px;
+}
+
+#qunit-header a {
+	text-decoration: none;
+	color: #c2ccd1;
+}
+
+#qunit-header a:hover,
+#qunit-header a:focus {
+	color: #fff;
+}
+
+#qunit-testrunner-toolbar label {
+	display: inline-block;
+	padding: 0 .5em 0 .1em;
+}
+
+#qunit-banner {
+	height: 5px;
+}
+
+#qunit-testrunner-toolbar {
+	padding: 0.5em 0 0.5em 2em;
+	color: #5E740B;
+	background-color: #eee;
+	overflow: hidden;
+}
+
+#qunit-userAgent {
+	padding: 0.5em 0 0.5em 2.5em;
+	background-color: #2b81af;
+	color: #fff;
+	text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
+}
+
+#qunit-modulefilter-container {
+	float: right;
+}
+
+/** Tests: Pass/Fail */
+
+#qunit-tests {
+	list-style-position: inside;
+}
+
+#qunit-tests li {
+	padding: 0.4em 0.5em 0.4em 2.5em;
+	border-bottom: 1px solid #fff;
+	list-style-position: inside;
+}
+
+#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running  {
+	display: none;
+}
+
+#qunit-tests li strong {
+	cursor: pointer;
+}
+
+#qunit-tests li a {
+	padding: 0.5em;
+	color: #c2ccd1;
+	text-decoration: none;
+}
+#qunit-tests li a:hover,
+#qunit-tests li a:focus {
+	color: #000;
+}
+
+#qunit-tests ol {
+	margin-top: 0.5em;
+	padding: 0.5em;
+
+	background-color: #fff;
+
+	border-radius: 5px;
+	-moz-border-radius: 5px;
+	-webkit-border-radius: 5px;
+}
+
+#qunit-tests table {
+	border-collapse: collapse;
+	margin-top: .2em;
+}
+
+#qunit-tests th {
+	text-align: right;
+	vertical-align: top;
+	padding: 0 .5em 0 0;
+}
+
+#qunit-tests td {
+	vertical-align: top;
+}
+
+#qunit-tests pre {
+	margin: 0;
+	white-space: pre-wrap;
+	word-wrap: break-word;
+}
+
+#qunit-tests del {
+	background-color: #e0f2be;
+	color: #374e0c;
+	text-decoration: none;
+}
+
+#qunit-tests ins {
+	background-color: #ffcaca;
+	color: #500;
+	text-decoration: none;
+}
+
+/*** Test Counts */
+
+#qunit-tests b.counts                       { color: black; }
+#qunit-tests b.passed                       { color: #5E740B; }
+#qunit-tests b.failed                       { color: #710909; }
+
+#qunit-tests li li {
+	padding: 5px;
+	background-color: #fff;
+	border-bottom: none;
+	list-style-position: inside;
+}
+
+/*** Passing Styles */
+
+#qunit-tests li li.pass {
+	color: #3c510c;
+	background-color: #fff;
+	border-left: 10px solid #C6E746;
+}
+
+#qunit-tests .pass                          { color: #528CE0; background-color: #D2E0E6; }
+#qunit-tests .pass .test-name               { color: #366097; }
+
+#qunit-tests .pass .test-actual,
+#qunit-tests .pass .test-expected           { color: #999999; }
+
+#qunit-banner.qunit-pass                    { background-color: #C6E746; }
+
+/*** Failing Styles */
+
+#qunit-tests li li.fail {
+	color: #710909;
+	background-color: #fff;
+	border-left: 10px solid #EE5757;
+	white-space: pre;
+}
+
+#qunit-tests > li:last-child {
+	border-radius: 0 0 5px 5px;
+	-moz-border-radius: 0 0 5px 5px;
+	-webkit-border-bottom-right-radius: 5px;
+	-webkit-border-bottom-left-radius: 5px;
+}
+
+#qunit-tests .fail                          { color: #000000; background-color: #EE5757; }
+#qunit-tests .fail .test-name,
+#qunit-tests .fail .module-name             { color: #000000; }
+
+#qunit-tests .fail .test-actual             { color: #EE5757; }
+#qunit-tests .fail .test-expected           { color: green;   }
+
+#qunit-banner.qunit-fail                    { background-color: #EE5757; }
+
+
+/** Result */
+
+#qunit-testresult {
+	padding: 0.5em 0.5em 0.5em 2.5em;
+
+	color: #2b81af;
+	background-color: #D2E0E6;
+
+	border-bottom: 1px solid white;
+}
+#qunit-testresult .module-name {
+	font-weight: bold;
+}
+
+/** Fixture */
+
+#qunit-fixture {
+	position: absolute;
+	top: -10000px;
+	left: -10000px;
+	width: 1000px;
+	height: 1000px;
+}

+ 1977 - 0
test/qunit/qunit-1.10.0.js

@@ -0,0 +1,1977 @@
+/**
+ * QUnit v1.10.0 - A JavaScript Unit Testing Framework
+ *
+ * http://qunitjs.com
+ *
+ * Copyright 2012 jQuery Foundation and other contributors
+ * Released under the MIT license.
+ * http://jquery.org/license
+ */
+
+(function( window ) {
+
+var QUnit,
+	config,
+	onErrorFnPrev,
+	testId = 0,
+	fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""),
+	toString = Object.prototype.toString,
+	hasOwn = Object.prototype.hasOwnProperty,
+	// Keep a local reference to Date (GH-283)
+	Date = window.Date,
+	defined = {
+	setTimeout: typeof window.setTimeout !== "undefined",
+	sessionStorage: (function() {
+		var x = "qunit-test-string";
+		try {
+			sessionStorage.setItem( x, x );
+			sessionStorage.removeItem( x );
+			return true;
+		} catch( e ) {
+			return false;
+		}
+	}())
+};
+
+function Test( settings ) {
+	extend( this, settings );
+	this.assertions = [];
+	this.testNumber = ++Test.count;
+}
+
+Test.count = 0;
+
+Test.prototype = {
+	init: function() {
+		var a, b, li,
+        tests = id( "qunit-tests" );
+
+		if ( tests ) {
+			b = document.createElement( "strong" );
+			b.innerHTML = this.name;
+
+			// `a` initialized at top of scope
+			a = document.createElement( "a" );
+			a.innerHTML = "Rerun";
+			a.href = QUnit.url({ testNumber: this.testNumber });
+
+			li = document.createElement( "li" );
+			li.appendChild( b );
+			li.appendChild( a );
+			li.className = "running";
+			li.id = this.id = "qunit-test-output" + testId++;
+
+			tests.appendChild( li );
+		}
+	},
+	setup: function() {
+		if ( this.module !== config.previousModule ) {
+			if ( config.previousModule ) {
+				runLoggingCallbacks( "moduleDone", QUnit, {
+					name: config.previousModule,
+					failed: config.moduleStats.bad,
+					passed: config.moduleStats.all - config.moduleStats.bad,
+					total: config.moduleStats.all
+				});
+			}
+			config.previousModule = this.module;
+			config.moduleStats = { all: 0, bad: 0 };
+			runLoggingCallbacks( "moduleStart", QUnit, {
+				name: this.module
+			});
+		} else if ( config.autorun ) {
+			runLoggingCallbacks( "moduleStart", QUnit, {
+				name: this.module
+			});
+		}
+
+		config.current = this;
+
+		this.testEnvironment = extend({
+			setup: function() {},
+			teardown: function() {}
+		}, this.moduleTestEnvironment );
+
+		runLoggingCallbacks( "testStart", QUnit, {
+			name: this.testName,
+			module: this.module
+		});
+
+		// allow utility functions to access the current test environment
+		// TODO why??
+		QUnit.current_testEnvironment = this.testEnvironment;
+
+		if ( !config.pollution ) {
+			saveGlobal();
+		}
+		if ( config.notrycatch ) {
+			this.testEnvironment.setup.call( this.testEnvironment );
+			return;
+		}
+		try {
+			this.testEnvironment.setup.call( this.testEnvironment );
+		} catch( e ) {
+			QUnit.pushFailure( "Setup failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) );
+		}
+	},
+	run: function() {
+		config.current = this;
+
+		var running = id( "qunit-testresult" );
+
+		if ( running ) {
+			running.innerHTML = "Running: <br/>" + this.name;
+		}
+
+		if ( this.async ) {
+			QUnit.stop();
+		}
+
+		if ( config.notrycatch ) {
+			this.callback.call( this.testEnvironment, QUnit.assert );
+			return;
+		}
+
+		try {
+			this.callback.call( this.testEnvironment, QUnit.assert );
+		} catch( e ) {
+			QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + e.message, extractStacktrace( e, 0 ) );
+			// else next test will carry the responsibility
+			saveGlobal();
+
+			// Restart the tests if they're blocking
+			if ( config.blocking ) {
+				QUnit.start();
+			}
+		}
+	},
+	teardown: function() {
+		config.current = this;
+		if ( config.notrycatch ) {
+			this.testEnvironment.teardown.call( this.testEnvironment );
+			return;
+		} else {
+			try {
+				this.testEnvironment.teardown.call( this.testEnvironment );
+			} catch( e ) {
+				QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) );
+			}
+		}
+		checkPollution();
+	},
+	finish: function() {
+		config.current = this;
+		if ( config.requireExpects && this.expected == null ) {
+			QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack );
+		} else if ( this.expected != null && this.expected != this.assertions.length ) {
+			QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack );
+		} else if ( this.expected == null && !this.assertions.length ) {
+			QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack );
+		}
+
+		var assertion, a, b, i, li, ol,
+			test = this,
+			good = 0,
+			bad = 0,
+			tests = id( "qunit-tests" );
+
+		config.stats.all += this.assertions.length;
+		config.moduleStats.all += this.assertions.length;
+
+		if ( tests ) {
+			ol = document.createElement( "ol" );
+
+			for ( i = 0; i < this.assertions.length; i++ ) {
+				assertion = this.assertions[i];
+
+				li = document.createElement( "li" );
+				li.className = assertion.result ? "pass" : "fail";
+				li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" );
+				ol.appendChild( li );
+
+				if ( assertion.result ) {
+					good++;
+				} else {
+					bad++;
+					config.stats.bad++;
+					config.moduleStats.bad++;
+				}
+			}
+
+			// store result when possible
+			if ( QUnit.config.reorder && defined.sessionStorage ) {
+				if ( bad ) {
+					sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad );
+				} else {
+					sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName );
+				}
+			}
+
+			if ( bad === 0 ) {
+				ol.style.display = "none";
+			}
+
+			// `b` initialized at top of scope
+			b = document.createElement( "strong" );
+			b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
+
+			addEvent(b, "click", function() {
+				var next = b.nextSibling.nextSibling,
+					display = next.style.display;
+				next.style.display = display === "none" ? "block" : "none";
+			});
+
+			addEvent(b, "dblclick", function( e ) {
+				var target = e && e.target ? e.target : window.event.srcElement;
+				if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
+					target = target.parentNode;
+				}
+				if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
+					window.location = QUnit.url({ testNumber: test.testNumber });
+				}
+			});
+
+			// `li` initialized at top of scope
+			li = id( this.id );
+			li.className = bad ? "fail" : "pass";
+			li.removeChild( li.firstChild );
+			a = li.firstChild;
+			li.appendChild( b );
+			li.appendChild ( a );
+			li.appendChild( ol );
+
+		} else {
+			for ( i = 0; i < this.assertions.length; i++ ) {
+				if ( !this.assertions[i].result ) {
+					bad++;
+					config.stats.bad++;
+					config.moduleStats.bad++;
+				}
+			}
+		}
+
+		runLoggingCallbacks( "testDone", QUnit, {
+			name: this.testName,
+			module: this.module,
+			failed: bad,
+			passed: this.assertions.length - bad,
+			total: this.assertions.length
+		});
+
+		QUnit.reset();
+
+		config.current = undefined;
+	},
+
+	queue: function() {
+		var bad,
+			test = this;
+
+		synchronize(function() {
+			test.init();
+		});
+		function run() {
+			// each of these can by async
+			synchronize(function() {
+				test.setup();
+			});
+			synchronize(function() {
+				test.run();
+			});
+			synchronize(function() {
+				test.teardown();
+			});
+			synchronize(function() {
+				test.finish();
+			});
+		}
+
+		// `bad` initialized at top of scope
+		// defer when previous test run passed, if storage is available
+		bad = QUnit.config.reorder && defined.sessionStorage &&
+						+sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName );
+
+		if ( bad ) {
+			run();
+		} else {
+			synchronize( run, true );
+		}
+	}
+};
+
+// Root QUnit object.
+// `QUnit` initialized at top of scope
+QUnit = {
+
+	// call on start of module test to prepend name to all tests
+	module: function( name, testEnvironment ) {
+		config.currentModule = name;
+		config.currentModuleTestEnvironment = testEnvironment;
+		config.modules[name] = true;
+	},
+
+	asyncTest: function( testName, expected, callback ) {
+		if ( arguments.length === 2 ) {
+			callback = expected;
+			expected = null;
+		}
+
+		QUnit.test( testName, expected, callback, true );
+	},
+
+	test: function( testName, expected, callback, async ) {
+		var test,
+			name = "<span class='test-name'>" + escapeInnerText( testName ) + "</span>";
+
+		if ( arguments.length === 2 ) {
+			callback = expected;
+			expected = null;
+		}
+
+		if ( config.currentModule ) {
+			name = "<span class='module-name'>" + config.currentModule + "</span>: " + name;
+		}
+
+		test = new Test({
+			name: name,
+			testName: testName,
+			expected: expected,
+			async: async,
+			callback: callback,
+			module: config.currentModule,
+			moduleTestEnvironment: config.currentModuleTestEnvironment,
+			stack: sourceFromStacktrace( 2 )
+		});
+
+		if ( !validTest( test ) ) {
+			return;
+		}
+
+		test.queue();
+	},
+
+	// Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
+	expect: function( asserts ) {
+		if (arguments.length === 1) {
+			config.current.expected = asserts;
+		} else {
+			return config.current.expected;
+		}
+	},
+
+	start: function( count ) {
+		config.semaphore -= count || 1;
+		// don't start until equal number of stop-calls
+		if ( config.semaphore > 0 ) {
+			return;
+		}
+		// ignore if start is called more often then stop
+		if ( config.semaphore < 0 ) {
+			config.semaphore = 0;
+		}
+		// A slight delay, to avoid any current callbacks
+		if ( defined.setTimeout ) {
+			window.setTimeout(function() {
+				if ( config.semaphore > 0 ) {
+					return;
+				}
+				if ( config.timeout ) {
+					clearTimeout( config.timeout );
+				}
+
+				config.blocking = false;
+				process( true );
+			}, 13);
+		} else {
+			config.blocking = false;
+			process( true );
+		}
+	},
+
+	stop: function( count ) {
+		config.semaphore += count || 1;
+		config.blocking = true;
+
+		if ( config.testTimeout && defined.setTimeout ) {
+			clearTimeout( config.timeout );
+			config.timeout = window.setTimeout(function() {
+				QUnit.ok( false, "Test timed out" );
+				config.semaphore = 1;
+				QUnit.start();
+			}, config.testTimeout );
+		}
+	}
+};
+
+// Asssert helpers
+// All of these must call either QUnit.push() or manually do:
+// - runLoggingCallbacks( "log", .. );
+// - config.current.assertions.push({ .. });
+QUnit.assert = {
+	/**
+	 * Asserts rough true-ish result.
+	 * @name ok
+	 * @function
+	 * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
+	 */
+	ok: function( result, msg ) {
+		if ( !config.current ) {
+			throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) );
+		}
+		result = !!result;
+
+		var source,
+			details = {
+				module: config.current.module,
+				name: config.current.testName,
+				result: result,
+				message: msg
+			};
+
+		msg = escapeInnerText( msg || (result ? "okay" : "failed" ) );
+		msg = "<span class='test-message'>" + msg + "</span>";
+
+		if ( !result ) {
+			source = sourceFromStacktrace( 2 );
+			if ( source ) {
+				details.source = source;
+				msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr></table>";
+			}
+		}
+		runLoggingCallbacks( "log", QUnit, details );
+		config.current.assertions.push({
+			result: result,
+			message: msg
+		});
+	},
+
+	/**
+	 * Assert that the first two arguments are equal, with an optional message.
+	 * Prints out both actual and expected values.
+	 * @name equal
+	 * @function
+	 * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" );
+	 */
+	equal: function( actual, expected, message ) {
+		QUnit.push( expected == actual, actual, expected, message );
+	},
+
+	/**
+	 * @name notEqual
+	 * @function
+	 */
+	notEqual: function( actual, expected, message ) {
+		QUnit.push( expected != actual, actual, expected, message );
+	},
+
+	/**
+	 * @name deepEqual
+	 * @function
+	 */
+	deepEqual: function( actual, expected, message ) {
+		QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
+	},
+
+	/**
+	 * @name notDeepEqual
+	 * @function
+	 */
+	notDeepEqual: function( actual, expected, message ) {
+		QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message );
+	},
+
+	/**
+	 * @name strictEqual
+	 * @function
+	 */
+	strictEqual: function( actual, expected, message ) {
+		QUnit.push( expected === actual, actual, expected, message );
+	},
+
+	/**
+	 * @name notStrictEqual
+	 * @function
+	 */
+	notStrictEqual: function( actual, expected, message ) {
+		QUnit.push( expected !== actual, actual, expected, message );
+	},
+
+	throws: function( block, expected, message ) {
+		var actual,
+			ok = false;
+
+		// 'expected' is optional
+		if ( typeof expected === "string" ) {
+			message = expected;
+			expected = null;
+		}
+
+		config.current.ignoreGlobalErrors = true;
+		try {
+			block.call( config.current.testEnvironment );
+		} catch (e) {
+			actual = e;
+		}
+		config.current.ignoreGlobalErrors = false;
+
+		if ( actual ) {
+			// we don't want to validate thrown error
+			if ( !expected ) {
+				ok = true;
+			// expected is a regexp
+			} else if ( QUnit.objectType( expected ) === "regexp" ) {
+				ok = expected.test( actual );
+			// expected is a constructor
+			} else if ( actual instanceof expected ) {
+				ok = true;
+			// expected is a validation function which returns true is validation passed
+			} else if ( expected.call( {}, actual ) === true ) {
+				ok = true;
+			}
+
+			QUnit.push( ok, actual, null, message );
+		} else {
+			QUnit.pushFailure( message, null, 'No exception was thrown.' );
+		}
+	}
+};
+
+/**
+ * @deprecate since 1.8.0
+ * Kept assertion helpers in root for backwards compatibility
+ */
+extend( QUnit, QUnit.assert );
+
+/**
+ * @deprecated since 1.9.0
+ * Kept global "raises()" for backwards compatibility
+ */
+QUnit.raises = QUnit.assert.throws;
+
+/**
+ * @deprecated since 1.0.0, replaced with error pushes since 1.3.0
+ * Kept to avoid TypeErrors for undefined methods.
+ */
+QUnit.equals = function() {
+	QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" );
+};
+QUnit.same = function() {
+	QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" );
+};
+
+// We want access to the constructor's prototype
+(function() {
+	function F() {}
+	F.prototype = QUnit;
+	QUnit = new F();
+	// Make F QUnit's constructor so that we can add to the prototype later
+	QUnit.constructor = F;
+}());
+
+/**
+ * Config object: Maintain internal state
+ * Later exposed as QUnit.config
+ * `config` initialized at top of scope
+ */
+config = {
+	// The queue of tests to run
+	queue: [],
+
+	// block until document ready
+	blocking: true,
+
+	// when enabled, show only failing tests
+	// gets persisted through sessionStorage and can be changed in UI via checkbox
+	hidepassed: false,
+
+	// by default, run previously failed tests first
+	// very useful in combination with "Hide passed tests" checked
+	reorder: true,
+
+	// by default, modify document.title when suite is done
+	altertitle: true,
+
+	// when enabled, all tests must call expect()
+	requireExpects: false,
+
+	// add checkboxes that are persisted in the query-string
+	// when enabled, the id is set to `true` as a `QUnit.config` property
+	urlConfig: [
+		{
+			id: "noglobals",
+			label: "Check for Globals",
+			tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings."
+		},
+		{
+			id: "notrycatch",
+			label: "No try-catch",
+			tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings."
+		}
+	],
+
+	// Set of all modules.
+	modules: {},
+
+	// logging callback queues
+	begin: [],
+	done: [],
+	log: [],
+	testStart: [],
+	testDone: [],
+	moduleStart: [],
+	moduleDone: []
+};
+
+// Initialize more QUnit.config and QUnit.urlParams
+(function() {
+	var i,
+		location = window.location || { search: "", protocol: "file:" },
+		params = location.search.slice( 1 ).split( "&" ),
+		length = params.length,
+		urlParams = {},
+		current;
+
+	if ( params[ 0 ] ) {
+		for ( i = 0; i < length; i++ ) {
+			current = params[ i ].split( "=" );
+			current[ 0 ] = decodeURIComponent( current[ 0 ] );
+			// allow just a key to turn on a flag, e.g., test.html?noglobals
+			current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
+			urlParams[ current[ 0 ] ] = current[ 1 ];
+		}
+	}
+
+	QUnit.urlParams = urlParams;
+
+	// String search anywhere in moduleName+testName
+	config.filter = urlParams.filter;
+
+	// Exact match of the module name
+	config.module = urlParams.module;
+
+	config.testNumber = parseInt( urlParams.testNumber, 10 ) || null;
+
+	// Figure out if we're running the tests from a server or not
+	QUnit.isLocal = location.protocol === "file:";
+}());
+
+// Export global variables, unless an 'exports' object exists,
+// in that case we assume we're in CommonJS (dealt with on the bottom of the script)
+if ( typeof exports === "undefined" ) {
+	extend( window, QUnit );
+
+	// Expose QUnit object
+	window.QUnit = QUnit;
+}
+
+// Extend QUnit object,
+// these after set here because they should not be exposed as global functions
+extend( QUnit, {
+	config: config,
+
+	// Initialize the configuration options
+	init: function() {
+		extend( config, {
+			stats: { all: 0, bad: 0 },
+			moduleStats: { all: 0, bad: 0 },
+			started: +new Date(),
+			updateRate: 1000,
+			blocking: false,
+			autostart: true,
+			autorun: false,
+			filter: "",
+			queue: [],
+			semaphore: 0
+		});
+
+		var tests, banner, result,
+			qunit = id( "qunit" );
+
+		if ( qunit ) {
+			qunit.innerHTML =
+				"<h1 id='qunit-header'>" + escapeInnerText( document.title ) + "</h1>" +
+				"<h2 id='qunit-banner'></h2>" +
+				"<div id='qunit-testrunner-toolbar'></div>" +
+				"<h2 id='qunit-userAgent'></h2>" +
+				"<ol id='qunit-tests'></ol>";
+		}
+
+		tests = id( "qunit-tests" );
+		banner = id( "qunit-banner" );
+		result = id( "qunit-testresult" );
+
+		if ( tests ) {
+			tests.innerHTML = "";
+		}
+
+		if ( banner ) {
+			banner.className = "";
+		}
+
+		if ( result ) {
+			result.parentNode.removeChild( result );
+		}
+
+		if ( tests ) {
+			result = document.createElement( "p" );
+			result.id = "qunit-testresult";
+			result.className = "result";
+			tests.parentNode.insertBefore( result, tests );
+			result.innerHTML = "Running...<br/>&nbsp;";
+		}
+	},
+
+	// Resets the test setup. Useful for tests that modify the DOM.
+	reset: function() {
+		var fixture = id( "qunit-fixture" );
+		if ( fixture ) {
+			fixture.innerHTML = config.fixture;
+		}
+	},
+
+	// Trigger an event on an element.
+	// @example triggerEvent( document.body, "click" );
+	triggerEvent: function( elem, type, event ) {
+		if ( document.createEvent ) {
+			event = document.createEvent( "MouseEvents" );
+			event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
+				0, 0, 0, 0, 0, false, false, false, false, 0, null);
+
+			elem.dispatchEvent( event );
+		} else if ( elem.fireEvent ) {
+			elem.fireEvent( "on" + type );
+		}
+	},
+
+	// Safe object type checking
+	is: function( type, obj ) {
+		return QUnit.objectType( obj ) == type;
+	},
+
+	objectType: function( obj ) {
+		if ( typeof obj === "undefined" ) {
+				return "undefined";
+		// consider: typeof null === object
+		}
+		if ( obj === null ) {
+				return "null";
+		}
+
+		var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || "";
+
+		switch ( type ) {
+			case "Number":
+				if ( isNaN(obj) ) {
+					return "nan";
+				}
+				return "number";
+			case "String":
+			case "Boolean":
+			case "Array":
+			case "Date":
+			case "RegExp":
+			case "Function":
+				return type.toLowerCase();
+		}
+		if ( typeof obj === "object" ) {
+			return "object";
+		}
+		return undefined;
+	},
+
+	push: function( result, actual, expected, message ) {
+		if ( !config.current ) {
+			throw new Error( "assertion outside test context, was " + sourceFromStacktrace() );
+		}
+
+		var output, source,
+			details = {
+				module: config.current.module,
+				name: config.current.testName,
+				result: result,
+				message: message,
+				actual: actual,
+				expected: expected
+			};
+
+		message = escapeInnerText( message ) || ( result ? "okay" : "failed" );
+		message = "<span class='test-message'>" + message + "</span>";
+		output = message;
+
+		if ( !result ) {
+			expected = escapeInnerText( QUnit.jsDump.parse(expected) );
+			actual = escapeInnerText( QUnit.jsDump.parse(actual) );
+			output += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + expected + "</pre></td></tr>";
+
+			if ( actual != expected ) {
+				output += "<tr class='test-actual'><th>Result: </th><td><pre>" + actual + "</pre></td></tr>";
+				output += "<tr class='test-diff'><th>Diff: </th><td><pre>" + QUnit.diff( expected, actual ) + "</pre></td></tr>";
+			}
+
+			source = sourceFromStacktrace();
+
+			if ( source ) {
+				details.source = source;
+				output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr>";
+			}
+
+			output += "</table>";
+		}
+
+		runLoggingCallbacks( "log", QUnit, details );
+
+		config.current.assertions.push({
+			result: !!result,
+			message: output
+		});
+	},
+
+	pushFailure: function( message, source, actual ) {
+		if ( !config.current ) {
+			throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) );
+		}
+
+		var output,
+			details = {
+				module: config.current.module,
+				name: config.current.testName,
+				result: false,
+				message: message
+			};
+
+		message = escapeInnerText( message ) || "error";
+		message = "<span class='test-message'>" + message + "</span>";
+		output = message;
+
+		output += "<table>";
+
+		if ( actual ) {
+			output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeInnerText( actual ) + "</pre></td></tr>";
+		}
+
+		if ( source ) {
+			details.source = source;
+			output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr>";
+		}
+
+		output += "</table>";
+
+		runLoggingCallbacks( "log", QUnit, details );
+
+		config.current.assertions.push({
+			result: false,
+			message: output
+		});
+	},
+
+	url: function( params ) {
+		params = extend( extend( {}, QUnit.urlParams ), params );
+		var key,
+			querystring = "?";
+
+		for ( key in params ) {
+			if ( !hasOwn.call( params, key ) ) {
+				continue;
+			}
+			querystring += encodeURIComponent( key ) + "=" +
+				encodeURIComponent( params[ key ] ) + "&";
+		}
+		return window.location.pathname + querystring.slice( 0, -1 );
+	},
+
+	extend: extend,
+	id: id,
+	addEvent: addEvent
+	// load, equiv, jsDump, diff: Attached later
+});
+
+/**
+ * @deprecated: Created for backwards compatibility with test runner that set the hook function
+ * into QUnit.{hook}, instead of invoking it and passing the hook function.
+ * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here.
+ * Doing this allows us to tell if the following methods have been overwritten on the actual
+ * QUnit object.
+ */
+extend( QUnit.constructor.prototype, {
+
+	// Logging callbacks; all receive a single argument with the listed properties
+	// run test/logs.html for any related changes
+	begin: registerLoggingCallback( "begin" ),
+
+	// done: { failed, passed, total, runtime }
+	done: registerLoggingCallback( "done" ),
+
+	// log: { result, actual, expected, message }
+	log: registerLoggingCallback( "log" ),
+
+	// testStart: { name }
+	testStart: registerLoggingCallback( "testStart" ),
+
+	// testDone: { name, failed, passed, total }
+	testDone: registerLoggingCallback( "testDone" ),
+
+	// moduleStart: { name }
+	moduleStart: registerLoggingCallback( "moduleStart" ),
+
+	// moduleDone: { name, failed, passed, total }
+	moduleDone: registerLoggingCallback( "moduleDone" )
+});
+
+if ( typeof document === "undefined" || document.readyState === "complete" ) {
+	config.autorun = true;
+}
+
+QUnit.load = function() {
+	runLoggingCallbacks( "begin", QUnit, {} );
+
+	// Initialize the config, saving the execution queue
+	var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, urlConfigCheckboxes, moduleFilter,
+	    numModules = 0,
+	    moduleFilterHtml = "",
+		urlConfigHtml = "",
+		oldconfig = extend( {}, config );
+
+	QUnit.init();
+	extend(config, oldconfig);
+
+	config.blocking = false;
+
+	len = config.urlConfig.length;
+
+	for ( i = 0; i < len; i++ ) {
+		val = config.urlConfig[i];
+		if ( typeof val === "string" ) {
+			val = {
+				id: val,
+				label: val,
+				tooltip: "[no tooltip available]"
+			};
+		}
+		config[ val.id ] = QUnit.urlParams[ val.id ];
+		urlConfigHtml += "<input id='qunit-urlconfig-" + val.id + "' name='" + val.id + "' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) + " title='" + val.tooltip + "'><label for='qunit-urlconfig-" + val.id + "' title='" + val.tooltip + "'>" + val.label + "</label>";
+	}
+
+	moduleFilterHtml += "<label for='qunit-modulefilter'>Module: </label><select id='qunit-modulefilter' name='modulefilter'><option value='' " + ( config.module === undefined  ? "selected" : "" ) + ">< All Modules ></option>";
+	for ( i in config.modules ) {
+		if ( config.modules.hasOwnProperty( i ) ) {
+			numModules += 1;
+			moduleFilterHtml += "<option value='" + encodeURIComponent(i) + "' " + ( config.module === i ? "selected" : "" ) + ">" + i + "</option>";
+		}
+	}
+	moduleFilterHtml += "</select>";
+
+	// `userAgent` initialized at top of scope
+	userAgent = id( "qunit-userAgent" );
+	if ( userAgent ) {
+		userAgent.innerHTML = navigator.userAgent;
+	}
+
+	// `banner` initialized at top of scope
+	banner = id( "qunit-header" );
+	if ( banner ) {
+		banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined, module: undefined, testNumber: undefined }) + "'>" + banner.innerHTML + "</a> ";
+	}
+
+	// `toolbar` initialized at top of scope
+	toolbar = id( "qunit-testrunner-toolbar" );
+	if ( toolbar ) {
+		// `filter` initialized at top of scope
+		filter = document.createElement( "input" );
+		filter.type = "checkbox";
+		filter.id = "qunit-filter-pass";
+
+		addEvent( filter, "click", function() {
+			var tmp,
+				ol = document.getElementById( "qunit-tests" );
+
+			if ( filter.checked ) {
+				ol.className = ol.className + " hidepass";
+			} else {
+				tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
+				ol.className = tmp.replace( / hidepass /, " " );
+			}
+			if ( defined.sessionStorage ) {
+				if (filter.checked) {
+					sessionStorage.setItem( "qunit-filter-passed-tests", "true" );
+				} else {
+					sessionStorage.removeItem( "qunit-filter-passed-tests" );
+				}
+			}
+		});
+
+		if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) {
+			filter.checked = true;
+			// `ol` initialized at top of scope
+			ol = document.getElementById( "qunit-tests" );
+			ol.className = ol.className + " hidepass";
+		}
+		toolbar.appendChild( filter );
+
+		// `label` initialized at top of scope
+		label = document.createElement( "label" );
+		label.setAttribute( "for", "qunit-filter-pass" );
+		label.setAttribute( "title", "Only show tests and assertons that fail. Stored in sessionStorage." );
+		label.innerHTML = "Hide passed tests";
+		toolbar.appendChild( label );
+
+		urlConfigCheckboxes = document.createElement( 'span' );
+		urlConfigCheckboxes.innerHTML = urlConfigHtml;
+		addEvent( urlConfigCheckboxes, "change", function( event ) {
+			var params = {};
+			params[ event.target.name ] = event.target.checked ? true : undefined;
+			window.location = QUnit.url( params );
+		});
+		toolbar.appendChild( urlConfigCheckboxes );
+
+		if (numModules > 1) {
+			moduleFilter = document.createElement( 'span' );
+			moduleFilter.setAttribute( 'id', 'qunit-modulefilter-container' );
+			moduleFilter.innerHTML = moduleFilterHtml;
+			addEvent( moduleFilter, "change", function() {
+				var selectBox = moduleFilter.getElementsByTagName("select")[0],
+				    selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value);
+
+				window.location = QUnit.url( { module: ( selectedModule === "" ) ? undefined : selectedModule } );
+			});
+			toolbar.appendChild(moduleFilter);
+		}
+	}
+
+	// `main` initialized at top of scope
+	main = id( "qunit-fixture" );
+	if ( main ) {
+		config.fixture = main.innerHTML;
+	}
+
+	if ( config.autostart ) {
+		QUnit.start();
+	}
+};
+
+addEvent( window, "load", QUnit.load );
+
+// `onErrorFnPrev` initialized at top of scope
+// Preserve other handlers
+onErrorFnPrev = window.onerror;
+
+// Cover uncaught exceptions
+// Returning true will surpress the default browser handler,
+// returning false will let it run.
+window.onerror = function ( error, filePath, linerNr ) {
+	var ret = false;
+	if ( onErrorFnPrev ) {
+		ret = onErrorFnPrev( error, filePath, linerNr );
+	}
+
+	// Treat return value as window.onerror itself does,
+	// Only do our handling if not surpressed.
+	if ( ret !== true ) {
+		if ( QUnit.config.current ) {
+			if ( QUnit.config.current.ignoreGlobalErrors ) {
+				return true;
+			}
+			QUnit.pushFailure( error, filePath + ":" + linerNr );
+		} else {
+			QUnit.test( "global failure", extend( function() {
+				QUnit.pushFailure( error, filePath + ":" + linerNr );
+			}, { validTest: validTest } ) );
+		}
+		return false;
+	}
+
+	return ret;
+};
+
+function done() {
+	config.autorun = true;
+
+	// Log the last module results
+	if ( config.currentModule ) {
+		runLoggingCallbacks( "moduleDone", QUnit, {
+			name: config.currentModule,
+			failed: config.moduleStats.bad,
+			passed: config.moduleStats.all - config.moduleStats.bad,
+			total: config.moduleStats.all
+		});
+	}
+
+	var i, key,
+		banner = id( "qunit-banner" ),
+		tests = id( "qunit-tests" ),
+		runtime = +new Date() - config.started,
+		passed = config.stats.all - config.stats.bad,
+		html = [
+			"Tests completed in ",
+			runtime,
+			" milliseconds.<br/>",
+			"<span class='passed'>",
+			passed,
+			"</span> tests of <span class='total'>",
+			config.stats.all,
+			"</span> passed, <span class='failed'>",
+			config.stats.bad,
+			"</span> failed."
+		].join( "" );
+
+	if ( banner ) {
+		banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" );
+	}
+
+	if ( tests ) {
+		id( "qunit-testresult" ).innerHTML = html;
+	}
+
+	if ( config.altertitle && typeof document !== "undefined" && document.title ) {
+		// show ✖ for good, ✔ for bad suite result in title
+		// use escape sequences in case file gets loaded with non-utf-8-charset
+		document.title = [
+			( config.stats.bad ? "\u2716" : "\u2714" ),
+			document.title.replace( /^[\u2714\u2716] /i, "" )
+		].join( " " );
+	}
+
+	// clear own sessionStorage items if all tests passed
+	if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) {
+		// `key` & `i` initialized at top of scope
+		for ( i = 0; i < sessionStorage.length; i++ ) {
+			key = sessionStorage.key( i++ );
+			if ( key.indexOf( "qunit-test-" ) === 0 ) {
+				sessionStorage.removeItem( key );
+			}
+		}
+	}
+
+	// scroll back to top to show results
+	if ( window.scrollTo ) {
+		window.scrollTo(0, 0);
+	}
+
+	runLoggingCallbacks( "done", QUnit, {
+		failed: config.stats.bad,
+		passed: passed,
+		total: config.stats.all,
+		runtime: runtime
+	});
+}
+
+/** @return Boolean: true if this test should be ran */
+function validTest( test ) {
+	var include,
+		filter = config.filter && config.filter.toLowerCase(),
+		module = config.module && config.module.toLowerCase(),
+		fullName = (test.module + ": " + test.testName).toLowerCase();
+
+	// Internally-generated tests are always valid
+	if ( test.callback && test.callback.validTest === validTest ) {
+		delete test.callback.validTest;
+		return true;
+	}
+
+	if ( config.testNumber ) {
+		return test.testNumber === config.testNumber;
+	}
+
+	if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) {
+		return false;
+	}
+
+	if ( !filter ) {
+		return true;
+	}
+
+	include = filter.charAt( 0 ) !== "!";
+	if ( !include ) {
+		filter = filter.slice( 1 );
+	}
+
+	// If the filter matches, we need to honour include
+	if ( fullName.indexOf( filter ) !== -1 ) {
+		return include;
+	}
+
+	// Otherwise, do the opposite
+	return !include;
+}
+
+// so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions)
+// Later Safari and IE10 are supposed to support error.stack as well
+// See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack
+function extractStacktrace( e, offset ) {
+	offset = offset === undefined ? 3 : offset;
+
+	var stack, include, i, regex;
+
+	if ( e.stacktrace ) {
+		// Opera
+		return e.stacktrace.split( "\n" )[ offset + 3 ];
+	} else if ( e.stack ) {
+		// Firefox, Chrome
+		stack = e.stack.split( "\n" );
+		if (/^error$/i.test( stack[0] ) ) {
+			stack.shift();
+		}
+		if ( fileName ) {
+			include = [];
+			for ( i = offset; i < stack.length; i++ ) {
+				if ( stack[ i ].indexOf( fileName ) != -1 ) {
+					break;
+				}
+				include.push( stack[ i ] );
+			}
+			if ( include.length ) {
+				return include.join( "\n" );
+			}
+		}
+		return stack[ offset ];
+	} else if ( e.sourceURL ) {
+		// Safari, PhantomJS
+		// hopefully one day Safari provides actual stacktraces
+		// exclude useless self-reference for generated Error objects
+		if ( /qunit.js$/.test( e.sourceURL ) ) {
+			return;
+		}
+		// for actual exceptions, this is useful
+		return e.sourceURL + ":" + e.line;
+	}
+}
+function sourceFromStacktrace( offset ) {
+	try {
+		throw new Error();
+	} catch ( e ) {
+		return extractStacktrace( e, offset );
+	}
+}
+
+function escapeInnerText( s ) {
+	if ( !s ) {
+		return "";
+	}
+	s = s + "";
+	return s.replace( /[\&<>]/g, function( s ) {
+		switch( s ) {
+			case "&": return "&amp;";
+			case "<": return "&lt;";
+			case ">": return "&gt;";
+			default: return s;
+		}
+	});
+}
+
+function synchronize( callback, last ) {
+	config.queue.push( callback );
+
+	if ( config.autorun && !config.blocking ) {
+		process( last );
+	}
+}
+
+function process( last ) {
+	function next() {
+		process( last );
+	}
+	var start = new Date().getTime();
+	config.depth = config.depth ? config.depth + 1 : 1;
+
+	while ( config.queue.length && !config.blocking ) {
+		if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) {
+			config.queue.shift()();
+		} else {
+			window.setTimeout( next, 13 );
+			break;
+		}
+	}
+	config.depth--;
+	if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) {
+		done();
+	}
+}
+
+function saveGlobal() {
+	config.pollution = [];
+
+	if ( config.noglobals ) {
+		for ( var key in window ) {
+			// in Opera sometimes DOM element ids show up here, ignore them
+			if ( !hasOwn.call( window, key ) || /^qunit-test-output/.test( key ) ) {
+				continue;
+			}
+			config.pollution.push( key );
+		}
+	}
+}
+
+function checkPollution( name ) {
+	var newGlobals,
+		deletedGlobals,
+		old = config.pollution;
+
+	saveGlobal();
+
+	newGlobals = diff( config.pollution, old );
+	if ( newGlobals.length > 0 ) {
+		QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") );
+	}
+
+	deletedGlobals = diff( old, config.pollution );
+	if ( deletedGlobals.length > 0 ) {
+		QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") );
+	}
+}
+
+// returns a new Array with the elements that are in a but not in b
+function diff( a, b ) {
+	var i, j,
+		result = a.slice();
+
+	for ( i = 0; i < result.length; i++ ) {
+		for ( j = 0; j < b.length; j++ ) {
+			if ( result[i] === b[j] ) {
+				result.splice( i, 1 );
+				i--;
+				break;
+			}
+		}
+	}
+	return result;
+}
+
+function extend( a, b ) {
+	for ( var prop in b ) {
+		if ( b[ prop ] === undefined ) {
+			delete a[ prop ];
+
+		// Avoid "Member not found" error in IE8 caused by setting window.constructor
+		} else if ( prop !== "constructor" || a !== window ) {
+			a[ prop ] = b[ prop ];
+		}
+	}
+
+	return a;
+}
+
+function addEvent( elem, type, fn ) {
+	if ( elem.addEventListener ) {
+		elem.addEventListener( type, fn, false );
+	} else if ( elem.attachEvent ) {
+		elem.attachEvent( "on" + type, fn );
+	} else {
+		fn();
+	}
+}
+
+function id( name ) {
+	return !!( typeof document !== "undefined" && document && document.getElementById ) &&
+		document.getElementById( name );
+}
+
+function registerLoggingCallback( key ) {
+	return function( callback ) {
+		config[key].push( callback );
+	};
+}
+
+// Supports deprecated method of completely overwriting logging callbacks
+function runLoggingCallbacks( key, scope, args ) {
+	//debugger;
+	var i, callbacks;
+	if ( QUnit.hasOwnProperty( key ) ) {
+		QUnit[ key ].call(scope, args );
+	} else {
+		callbacks = config[ key ];
+		for ( i = 0; i < callbacks.length; i++ ) {
+			callbacks[ i ].call( scope, args );
+		}
+	}
+}
+
+// Test for equality any JavaScript type.
+// Author: Philippe Rathé <[email protected]>
+QUnit.equiv = (function() {
+
+	// Call the o related callback with the given arguments.
+	function bindCallbacks( o, callbacks, args ) {
+		var prop = QUnit.objectType( o );
+		if ( prop ) {
+			if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) {
+				return callbacks[ prop ].apply( callbacks, args );
+			} else {
+				return callbacks[ prop ]; // or undefined
+			}
+		}
+	}
+
+	// the real equiv function
+	var innerEquiv,
+		// stack to decide between skip/abort functions
+		callers = [],
+		// stack to avoiding loops from circular referencing
+		parents = [],
+
+		getProto = Object.getPrototypeOf || function ( obj ) {
+			return obj.__proto__;
+		},
+		callbacks = (function () {
+
+			// for string, boolean, number and null
+			function useStrictEquality( b, a ) {
+				if ( b instanceof a.constructor || a instanceof b.constructor ) {
+					// to catch short annotaion VS 'new' annotation of a
+					// declaration
+					// e.g. var i = 1;
+					// var j = new Number(1);
+					return a == b;
+				} else {
+					return a === b;
+				}
+			}
+
+			return {
+				"string": useStrictEquality,
+				"boolean": useStrictEquality,
+				"number": useStrictEquality,
+				"null": useStrictEquality,
+				"undefined": useStrictEquality,
+
+				"nan": function( b ) {
+					return isNaN( b );
+				},
+
+				"date": function( b, a ) {
+					return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf();
+				},
+
+				"regexp": function( b, a ) {
+					return QUnit.objectType( b ) === "regexp" &&
+						// the regex itself
+						a.source === b.source &&
+						// and its modifers
+						a.global === b.global &&
+						// (gmi) ...
+						a.ignoreCase === b.ignoreCase &&
+						a.multiline === b.multiline &&
+						a.sticky === b.sticky;
+				},
+
+				// - skip when the property is a method of an instance (OOP)
+				// - abort otherwise,
+				// initial === would have catch identical references anyway
+				"function": function() {
+					var caller = callers[callers.length - 1];
+					return caller !== Object && typeof caller !== "undefined";
+				},
+
+				"array": function( b, a ) {
+					var i, j, len, loop;
+
+					// b could be an object literal here
+					if ( QUnit.objectType( b ) !== "array" ) {
+						return false;
+					}
+
+					len = a.length;
+					if ( len !== b.length ) {
+						// safe and faster
+						return false;
+					}
+
+					// track reference to avoid circular references
+					parents.push( a );
+					for ( i = 0; i < len; i++ ) {
+						loop = false;
+						for ( j = 0; j < parents.length; j++ ) {
+							if ( parents[j] === a[i] ) {
+								loop = true;// dont rewalk array
+							}
+						}
+						if ( !loop && !innerEquiv(a[i], b[i]) ) {
+							parents.pop();
+							return false;
+						}
+					}
+					parents.pop();
+					return true;
+				},
+
+				"object": function( b, a ) {
+					var i, j, loop,
+						// Default to true
+						eq = true,
+						aProperties = [],
+						bProperties = [];
+
+					// comparing constructors is more strict than using
+					// instanceof
+					if ( a.constructor !== b.constructor ) {
+						// Allow objects with no prototype to be equivalent to
+						// objects with Object as their constructor.
+						if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) ||
+							( getProto(b) === null && getProto(a) === Object.prototype ) ) ) {
+								return false;
+						}
+					}
+
+					// stack constructor before traversing properties
+					callers.push( a.constructor );
+					// track reference to avoid circular references
+					parents.push( a );
+
+					for ( i in a ) { // be strict: don't ensures hasOwnProperty
+									// and go deep
+						loop = false;
+						for ( j = 0; j < parents.length; j++ ) {
+							if ( parents[j] === a[i] ) {
+								// don't go down the same path twice
+								loop = true;
+							}
+						}
+						aProperties.push(i); // collect a's properties
+
+						if (!loop && !innerEquiv( a[i], b[i] ) ) {
+							eq = false;
+							break;
+						}
+					}
+
+					callers.pop(); // unstack, we are done
+					parents.pop();
+
+					for ( i in b ) {
+						bProperties.push( i ); // collect b's properties
+					}
+
+					// Ensures identical properties name
+					return eq && innerEquiv( aProperties.sort(), bProperties.sort() );
+				}
+			};
+		}());
+
+	innerEquiv = function() { // can take multiple arguments
+		var args = [].slice.apply( arguments );
+		if ( args.length < 2 ) {
+			return true; // end transition
+		}
+
+		return (function( a, b ) {
+			if ( a === b ) {
+				return true; // catch the most you can
+			} else if ( a === null || b === null || typeof a === "undefined" ||
+					typeof b === "undefined" ||
+					QUnit.objectType(a) !== QUnit.objectType(b) ) {
+				return false; // don't lose time with error prone cases
+			} else {
+				return bindCallbacks(a, callbacks, [ b, a ]);
+			}
+
+			// apply transition with (1..n) arguments
+		}( args[0], args[1] ) && arguments.callee.apply( this, args.splice(1, args.length - 1 )) );
+	};
+
+	return innerEquiv;
+}());
+
+/**
+ * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com |
+ * http://flesler.blogspot.com Licensed under BSD
+ * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008
+ *
+ * @projectDescription Advanced and extensible data dumping for Javascript.
+ * @version 1.0.0
+ * @author Ariel Flesler
+ * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
+ */
+QUnit.jsDump = (function() {
+	function quote( str ) {
+		return '"' + str.toString().replace( /"/g, '\\"' ) + '"';
+	}
+	function literal( o ) {
+		return o + "";
+	}
+	function join( pre, arr, post ) {
+		var s = jsDump.separator(),
+			base = jsDump.indent(),
+			inner = jsDump.indent(1);
+		if ( arr.join ) {
+			arr = arr.join( "," + s + inner );
+		}
+		if ( !arr ) {
+			return pre + post;
+		}
+		return [ pre, inner + arr, base + post ].join(s);
+	}
+	function array( arr, stack ) {
+		var i = arr.length, ret = new Array(i);
+		this.up();
+		while ( i-- ) {
+			ret[i] = this.parse( arr[i] , undefined , stack);
+		}
+		this.down();
+		return join( "[", ret, "]" );
+	}
+
+	var reName = /^function (\w+)/,
+		jsDump = {
+			parse: function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance
+				stack = stack || [ ];
+				var inStack, res,
+					parser = this.parsers[ type || this.typeOf(obj) ];
+
+				type = typeof parser;
+				inStack = inArray( obj, stack );
+
+				if ( inStack != -1 ) {
+					return "recursion(" + (inStack - stack.length) + ")";
+				}
+				//else
+				if ( type == "function" )  {
+					stack.push( obj );
+					res = parser.call( this, obj, stack );
+					stack.pop();
+					return res;
+				}
+				// else
+				return ( type == "string" ) ? parser : this.parsers.error;
+			},
+			typeOf: function( obj ) {
+				var type;
+				if ( obj === null ) {
+					type = "null";
+				} else if ( typeof obj === "undefined" ) {
+					type = "undefined";
+				} else if ( QUnit.is( "regexp", obj) ) {
+					type = "regexp";
+				} else if ( QUnit.is( "date", obj) ) {
+					type = "date";
+				} else if ( QUnit.is( "function", obj) ) {
+					type = "function";
+				} else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) {
+					type = "window";
+				} else if ( obj.nodeType === 9 ) {
+					type = "document";
+				} else if ( obj.nodeType ) {
+					type = "node";
+				} else if (
+					// native arrays
+					toString.call( obj ) === "[object Array]" ||
+					// NodeList objects
+					( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
+				) {
+					type = "array";
+				} else {
+					type = typeof obj;
+				}
+				return type;
+			},
+			separator: function() {
+				return this.multiline ?	this.HTML ? "<br />" : "\n" : this.HTML ? "&nbsp;" : " ";
+			},
+			indent: function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
+				if ( !this.multiline ) {
+					return "";
+				}
+				var chr = this.indentChar;
+				if ( this.HTML ) {
+					chr = chr.replace( /\t/g, "   " ).replace( / /g, "&nbsp;" );
+				}
+				return new Array( this._depth_ + (extra||0) ).join(chr);
+			},
+			up: function( a ) {
+				this._depth_ += a || 1;
+			},
+			down: function( a ) {
+				this._depth_ -= a || 1;
+			},
+			setParser: function( name, parser ) {
+				this.parsers[name] = parser;
+			},
+			// The next 3 are exposed so you can use them
+			quote: quote,
+			literal: literal,
+			join: join,
+			//
+			_depth_: 1,
+			// This is the list of parsers, to modify them, use jsDump.setParser
+			parsers: {
+				window: "[Window]",
+				document: "[Document]",
+				error: "[ERROR]", //when no parser is found, shouldn"t happen
+				unknown: "[Unknown]",
+				"null": "null",
+				"undefined": "undefined",
+				"function": function( fn ) {
+					var ret = "function",
+						name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];//functions never have name in IE
+
+					if ( name ) {
+						ret += " " + name;
+					}
+					ret += "( ";
+
+					ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" );
+					return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" );
+				},
+				array: array,
+				nodelist: array,
+				"arguments": array,
+				object: function( map, stack ) {
+					var ret = [ ], keys, key, val, i;
+					QUnit.jsDump.up();
+					if ( Object.keys ) {
+						keys = Object.keys( map );
+					} else {
+						keys = [];
+						for ( key in map ) {
+							keys.push( key );
+						}
+					}
+					keys.sort();
+					for ( i = 0; i < keys.length; i++ ) {
+						key = keys[ i ];
+						val = map[ key ];
+						ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) );
+					}
+					QUnit.jsDump.down();
+					return join( "{", ret, "}" );
+				},
+				node: function( node ) {
+					var a, val,
+						open = QUnit.jsDump.HTML ? "&lt;" : "<",
+						close = QUnit.jsDump.HTML ? "&gt;" : ">",
+						tag = node.nodeName.toLowerCase(),
+						ret = open + tag;
+
+					for ( a in QUnit.jsDump.DOMAttrs ) {
+						val = node[ QUnit.jsDump.DOMAttrs[a] ];
+						if ( val ) {
+							ret += " " + a + "=" + QUnit.jsDump.parse( val, "attribute" );
+						}
+					}
+					return ret + close + open + "/" + tag + close;
+				},
+				functionArgs: function( fn ) {//function calls it internally, it's the arguments part of the function
+					var args,
+						l = fn.length;
+
+					if ( !l ) {
+						return "";
+					}
+
+					args = new Array(l);
+					while ( l-- ) {
+						args[l] = String.fromCharCode(97+l);//97 is 'a'
+					}
+					return " " + args.join( ", " ) + " ";
+				},
+				key: quote, //object calls it internally, the key part of an item in a map
+				functionCode: "[code]", //function calls it internally, it's the content of the function
+				attribute: quote, //node calls it internally, it's an html attribute value
+				string: quote,
+				date: quote,
+				regexp: literal, //regex
+				number: literal,
+				"boolean": literal
+			},
+			DOMAttrs: {
+				//attributes to dump from nodes, name=>realName
+				id: "id",
+				name: "name",
+				"class": "className"
+			},
+			HTML: false,//if true, entities are escaped ( <, >, \t, space and \n )
+			indentChar: "  ",//indentation unit
+			multiline: true //if true, items in a collection, are separated by a \n, else just a space.
+		};
+
+	return jsDump;
+}());
+
+// from Sizzle.js
+function getText( elems ) {
+	var i, elem,
+		ret = "";
+
+	for ( i = 0; elems[i]; i++ ) {
+		elem = elems[i];
+
+		// Get the text from text nodes and CDATA nodes
+		if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
+			ret += elem.nodeValue;
+
+		// Traverse everything else, except comment nodes
+		} else if ( elem.nodeType !== 8 ) {
+			ret += getText( elem.childNodes );
+		}
+	}
+
+	return ret;
+}
+
+// from jquery.js
+function inArray( elem, array ) {
+	if ( array.indexOf ) {
+		return array.indexOf( elem );
+	}
+
+	for ( var i = 0, length = array.length; i < length; i++ ) {
+		if ( array[ i ] === elem ) {
+			return i;
+		}
+	}
+
+	return -1;
+}
+
+/*
+ * Javascript Diff Algorithm
+ *  By John Resig (http://ejohn.org/)
+ *  Modified by Chu Alan "sprite"
+ *
+ * Released under the MIT license.
+ *
+ * More Info:
+ *  http://ejohn.org/projects/javascript-diff-algorithm/
+ *
+ * Usage: QUnit.diff(expected, actual)
+ *
+ * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the  quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over"
+ */
+QUnit.diff = (function() {
+	function diff( o, n ) {
+		var i,
+			ns = {},
+			os = {};
+
+		for ( i = 0; i < n.length; i++ ) {
+			if ( ns[ n[i] ] == null ) {
+				ns[ n[i] ] = {
+					rows: [],
+					o: null
+				};
+			}
+			ns[ n[i] ].rows.push( i );
+		}
+
+		for ( i = 0; i < o.length; i++ ) {
+			if ( os[ o[i] ] == null ) {
+				os[ o[i] ] = {
+					rows: [],
+					n: null
+				};
+			}
+			os[ o[i] ].rows.push( i );
+		}
+
+		for ( i in ns ) {
+			if ( !hasOwn.call( ns, i ) ) {
+				continue;
+			}
+			if ( ns[i].rows.length == 1 && typeof os[i] != "undefined" && os[i].rows.length == 1 ) {
+				n[ ns[i].rows[0] ] = {
+					text: n[ ns[i].rows[0] ],
+					row: os[i].rows[0]
+				};
+				o[ os[i].rows[0] ] = {
+					text: o[ os[i].rows[0] ],
+					row: ns[i].rows[0]
+				};
+			}
+		}
+
+		for ( i = 0; i < n.length - 1; i++ ) {
+			if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
+						n[ i + 1 ] == o[ n[i].row + 1 ] ) {
+
+				n[ i + 1 ] = {
+					text: n[ i + 1 ],
+					row: n[i].row + 1
+				};
+				o[ n[i].row + 1 ] = {
+					text: o[ n[i].row + 1 ],
+					row: i + 1
+				};
+			}
+		}
+
+		for ( i = n.length - 1; i > 0; i-- ) {
+			if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
+						n[ i - 1 ] == o[ n[i].row - 1 ]) {
+
+				n[ i - 1 ] = {
+					text: n[ i - 1 ],
+					row: n[i].row - 1
+				};
+				o[ n[i].row - 1 ] = {
+					text: o[ n[i].row - 1 ],
+					row: i - 1
+				};
+			}
+		}
+
+		return {
+			o: o,
+			n: n
+		};
+	}
+
+	return function( o, n ) {
+		o = o.replace( /\s+$/, "" );
+		n = n.replace( /\s+$/, "" );
+
+		var i, pre,
+			str = "",
+			out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ),
+			oSpace = o.match(/\s+/g),
+			nSpace = n.match(/\s+/g);
+
+		if ( oSpace == null ) {
+			oSpace = [ " " ];
+		}
+		else {
+			oSpace.push( " " );
+		}
+
+		if ( nSpace == null ) {
+			nSpace = [ " " ];
+		}
+		else {
+			nSpace.push( " " );
+		}
+
+		if ( out.n.length === 0 ) {
+			for ( i = 0; i < out.o.length; i++ ) {
+				str += "<del>" + out.o[i] + oSpace[i] + "</del>";
+			}
+		}
+		else {
+			if ( out.n[0].text == null ) {
+				for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) {
+					str += "<del>" + out.o[n] + oSpace[n] + "</del>";
+				}
+			}
+
+			for ( i = 0; i < out.n.length; i++ ) {
+				if (out.n[i].text == null) {
+					str += "<ins>" + out.n[i] + nSpace[i] + "</ins>";
+				}
+				else {
+					// `pre` initialized at top of scope
+					pre = "";
+
+					for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
+						pre += "<del>" + out.o[n] + oSpace[n] + "</del>";
+					}
+					str += " " + out.n[i].text + nSpace[i] + pre;
+				}
+			}
+		}
+
+		return str;
+	};
+}());
+
+// for CommonJS enviroments, export everything
+if ( typeof exports !== "undefined" ) {
+	extend(exports, QUnit);
+}
+
+// get at whatever the global object is, like window in browsers
+}( (function() {return this;}.call()) ));

+ 4 - 0
utils/includes/common.json

@@ -5,12 +5,16 @@
 	"../src/core/Vector2.js",
 	"../src/core/Vector3.js",
 	"../src/core/Vector4.js",
+	"../src/core/Box2.js",
+	"../src/core/Box3.js",
 	"../src/core/Matrix3.js",
 	"../src/core/Matrix4.js",
 	"../src/core/EventTarget.js",
 	"../src/core/Frustum.js",
+	"../src/core/Plane.js",
 	"../src/core/Ray.js",
 	"../src/core/Rectangle.js",
+	"../src/core/Sphere.js",
 	"../src/core/Math.js",
 	"../src/core/Object3D.js",
 	"../src/core/Projector.js",

+ 0 - 0
utils/servers/javascript_server.sh → utils/servers/nodejs_server.sh


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно