Browse Source

Merge branch 'mrdoob-dev' into test-suite

Conflicts:
	src/core/Box3.js
Ben Houston 12 years ago
parent
commit
44478c4fdc

File diff suppressed because it is too large
+ 259 - 242
build/three.js


File diff suppressed because it is too large
+ 258 - 256
build/three.min.js


+ 399 - 227
examples/js/DeferredHelper.js

@@ -7,22 +7,12 @@ THREE.DeferredHelper = function ( parameters ) {
 
 
 	var width = parameters.width;
 	var width = parameters.width;
 	var height = parameters.height;
 	var height = parameters.height;
+	var scale = parameters.scale;
 
 
-	var scene = parameters.scene;
-	var camera = parameters.camera;
 	var renderer = parameters.renderer;
 	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 additiveSpecular = parameters.additiveSpecular;
+	var multiply = parameters.multiply;
 
 
 	//
 	//
 
 
@@ -35,19 +25,23 @@ THREE.DeferredHelper = function ( parameters ) {
 
 
 	//
 	//
 
 
-	var unlitShader = THREE.ShaderDeferred[ "unlit" ];
-	var lightShader = THREE.ShaderDeferred[ "light" ];
+	var emissiveLightShader = THREE.ShaderDeferred[ "emissiveLight" ];
+	var pointLightShader = THREE.ShaderDeferred[ "pointLight" ];
+	var directionalLightShader = THREE.ShaderDeferred[ "directionalLight" ];
+
 	var compositeShader = THREE.ShaderDeferred[ "composite" ];
 	var compositeShader = THREE.ShaderDeferred[ "composite" ];
 
 
-	unlitShader.uniforms[ "viewWidth" ].value = width;
-	unlitShader.uniforms[ "viewHeight" ].value = height;
+	//
+
+	var compColor, compNormal, compDepth, compLight, compFinal;
+	var passColor, passNormal, passDepth, passLightFullscreen, passLightProxy, compositePass;
 
 
-	lightShader.uniforms[ "viewWidth" ].value = width;
-	lightShader.uniforms[ "viewHeight" ].value = height;
+	var effectFXAA;
 
 
 	//
 	//
 
 
-	var compColor, compNormal, compDepth, compLightBuffer, compFinal, compEmitter, compositePass;
+	var lightSceneFullscreen, lightSceneProxy;
+	var lightMaterials = [];
 
 
 	//
 	//
 
 
@@ -69,349 +63,527 @@ THREE.DeferredHelper = function ( parameters ) {
 
 
 	//
 	//
 
 
-	var rtParamsFloatLinear = { minFilter: THREE.NearestFilter, magFilter: THREE.LinearFilter, stencilBuffer: false,
-								format: THREE.RGBAFormat, type: THREE.FloatType };
+	var initDeferredMaterials = function ( object ) {
 
 
-	var rtParamsFloatNearest = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, stencilBuffer: false,
-								 format: THREE.RGBAFormat, type: THREE.FloatType };
+		if ( object.material instanceof THREE.MeshFaceMaterial ) {
 
 
-	var rtParamsUByte = { minFilter: THREE.NearestFilter, magFilter: THREE.LinearFilter, stencilBuffer: false,
-						  format: THREE.RGBFormat, type: THREE.UnsignedByteType };
+			var colorMaterials = [];
+			var depthMaterials = [];
+			var normalMaterials = [];
 
 
-	//
+			var materials = object.material.materials;
+
+			for ( var i = 0, il = materials.length; i < il; i ++ ) {
+
+				var deferredMaterials = createDeferredMaterials( materials[ i ] );
 
 
-	this.addDeferredMaterials = function ( object ) {
+				colorMaterials.push( deferredMaterials.colorMaterial );
+				depthMaterials.push( deferredMaterials.depthMaterial );
+				normalMaterials.push( deferredMaterials.normalMaterial );
 
 
-		object.traverse( function( node ) {
+			}
+
+			object.properties.colorMaterial = new THREE.MeshFaceMaterial( colorMaterials );
+			object.properties.depthMaterial = new THREE.MeshFaceMaterial( depthMaterials );
+			object.properties.normalMaterial = new THREE.MeshFaceMaterial( normalMaterials );
 
 
-			if ( !node.material ) return;
+		} else {
 
 
-			var originalMaterial = node.material;
+			var deferredMaterials = createDeferredMaterials( object.material );
 
 
-			// color material
-			// 	diffuse color
-			//	specular color
-			//	shininess
-			//	diffuse map
-			//	vertex colors
-			//	alphaTest
-			// 	morphs
+			object.properties.colorMaterial = deferredMaterials.colorMaterial;
+			object.properties.depthMaterial = deferredMaterials.depthMaterial;
+			object.properties.normalMaterial = deferredMaterials.normalMaterial;
 
 
-			var uniforms = THREE.UniformsUtils.clone( colorShader.uniforms );
-			var defines = { "USE_MAP": !! originalMaterial.map, "GAMMA_INPUT": true };
+		}
+
+	};
+
+
+	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
+
+		} );
 
 
-			var material = new THREE.ShaderMaterial( {
+		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;
+
+		uniforms.emissive.value.copy( emissive );
+		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 );
+
+		}
+
+		deferredMaterials.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( {
 
 
-				fragmentShader: colorShader.fragmentShader,
-				vertexShader: 	colorShader.vertexShader,
 				uniforms: 		uniforms,
 				uniforms: 		uniforms,
-				defines: 		defines,
-				shading:		originalMaterial.shading
+				vertexShader: 	bumpShader.vertexShader,
+				fragmentShader: bumpShader.fragmentShader,
+				defines:		{ "USE_BUMPMAP": true }
 
 
 			} );
 			} );
 
 
-			var diffuse = originalMaterial.color;
-			var specular = originalMaterial.specular !== undefined ? originalMaterial.specular : black;
-			var shininess = originalMaterial.shininess !== undefined ? originalMaterial.shininess : 1;
+			uniforms.bumpMap.value = originalMaterial.bumpMap;
+			uniforms.bumpScale.value = originalMaterial.bumpScale;
 
 
-			uniforms.diffuse.value.copy( diffuse );
-			uniforms.specular.value.copy( specular );
-			uniforms.shininess.value = shininess;
+			var offset = originalMaterial.bumpMap.offset;
+			var repeat = originalMaterial.bumpMap.repeat;
 
 
-			uniforms.map.value = originalMaterial.map;
+			uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
 
 
-			material.vertexColors = originalMaterial.vertexColors;
-			material.morphTargets = originalMaterial.morphTargets;
-			material.morphNormals = originalMaterial.morphNormals;
+			deferredMaterials.normalMaterial = normalMaterial;
 
 
-			material.alphaTest = originalMaterial.alphaTest;
+		} else if ( originalMaterial.morphTargets ) {
 
 
-			if ( originalMaterial.bumpMap ) {
+			var normalMaterial = new THREE.ShaderMaterial( {
 
 
-				var offset = originalMaterial.bumpMap.offset;
-				var repeat = originalMaterial.bumpMap.repeat;
+				uniforms:       THREE.UniformsUtils.clone( normalShader.uniforms ),
+				vertexShader:   normalShader.vertexShader,
+				fragmentShader: normalShader.fragmentShader,
+				shading:		originalMaterial.shading
 
 
-				uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
+			} );
 
 
-			}
+			normalMaterial.morphTargets = originalMaterial.morphTargets;
+			normalMaterial.morphNormals = originalMaterial.morphNormals;
 
 
-			node.properties.colorMaterial = material;
+			deferredMaterials.normalMaterial = normalMaterial;
 
 
-			// normal material
-			//	vertex normals
-			//	morph normals
-			//	bump map
-			//	bump scale
+		} else {
 
 
-			if ( originalMaterial.bumpMap ) {
+			deferredMaterials.normalMaterial = defaultNormalMaterial;
 
 
-				var uniforms = THREE.UniformsUtils.clone( bumpShader.uniforms );
+		}
 
 
-				var normalMaterial = new THREE.ShaderMaterial( {
+		// depth material
 
 
-					uniforms: 		uniforms,
-					vertexShader: 	bumpShader.vertexShader,
-					fragmentShader: bumpShader.fragmentShader,
-					defines:		{ "USE_BUMPMAP": true }
+		if ( originalMaterial.morphTargets ) {
 
 
-				} );
+			var depthMaterial = new THREE.ShaderMaterial( {
 
 
-				uniforms.bumpMap.value = originalMaterial.bumpMap;
-				uniforms.bumpScale.value = originalMaterial.bumpScale;
+				uniforms:       THREE.UniformsUtils.clone( clipDepthShader.uniforms ),
+				vertexShader:   clipDepthShader.vertexShader,
+				fragmentShader: clipDepthShader.fragmentShader
 
 
-				var offset = originalMaterial.bumpMap.offset;
-				var repeat = originalMaterial.bumpMap.repeat;
+			} );
 
 
-				uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
+			depthMaterial.morphTargets = originalMaterial.morphTargets;
 
 
-				node.properties.normalMaterial = normalMaterial;
+			deferredMaterials.depthMaterial = depthMaterial;
 
 
-			} else if ( originalMaterial.morphTargets ) {
+		} else {
 
 
-				var normalMaterial = new THREE.ShaderMaterial( {
+			deferredMaterials.depthMaterial = defaultDepthMaterial;
 
 
-					uniforms:       THREE.UniformsUtils.clone( normalShader.uniforms ),
-					vertexShader:   normalShader.vertexShader,
-					fragmentShader: normalShader.fragmentShader,
-					shading:		originalMaterial.shading
+		}
 
 
-				} );
+		return deferredMaterials;
 
 
-				normalMaterial.morphTargets = originalMaterial.morphTargets;
-				normalMaterial.morphNormals = originalMaterial.morphNormals;
+	};
 
 
-				node.properties.normalMaterial = normalMaterial;
+	var createDeferredPointLight = function ( light ) {
 
 
-			} else {
+		// setup light material
 
 
-				node.properties.normalMaterial = defaultNormalMaterial;
+		var materialLight = new THREE.ShaderMaterial( {
 
 
-			}
+			uniforms:       THREE.UniformsUtils.clone( pointLightShader.uniforms ),
+			vertexShader:   pointLightShader.vertexShader,
+			fragmentShader: pointLightShader.fragmentShader,
+			defines:		{ "ADDITIVE_SPECULAR": additiveSpecular },
 
 
-			// depth material
+			blending:		THREE.AdditiveBlending,
+			depthWrite:		false,
+			transparent:	true
 
 
-			if ( originalMaterial.morphTargets ) {
+		} );
 
 
-				var depthMaterial = new THREE.ShaderMaterial( {
+		materialLight.uniforms[ "lightPos" ].value = light.position;
+		materialLight.uniforms[ "lightRadius" ].value = light.distance;
+		materialLight.uniforms[ "lightIntensity" ].value = light.intensity;
+		materialLight.uniforms[ "lightColor" ].value = light.color;
 
 
-					uniforms:       THREE.UniformsUtils.clone( clipDepthShader.uniforms ),
-					vertexShader:   clipDepthShader.vertexShader,
-					fragmentShader: clipDepthShader.fragmentShader
+		materialLight.uniforms[ "viewWidth" ].value = width;
+		materialLight.uniforms[ "viewHeight" ].value = height;
 
 
-				} );
+		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
+		materialLight.uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
+		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
 
 
-				depthMaterial.morphTargets = originalMaterial.morphTargets;
+		// create light proxy mesh
 
 
-				node.properties.depthMaterial = depthMaterial;
+		var geometryLight = new THREE.SphereGeometry( light.distance, 16, 8 );
+		var meshLight = new THREE.Mesh( geometryLight, materialLight );
+		meshLight.position = light.position;
 
 
-			} else {
+		// keep reference for size reset
 
 
-				node.properties.depthMaterial = defaultDepthMaterial;
+		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,
+			defines:		{ "ADDITIVE_SPECULAR": additiveSpecular },
+
+			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 = width;
+		materialLight.uniforms[ "viewHeight" ].value = height;
+
+		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
+		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
+		materialLight.uniforms[ 'samplerNormals' ].value = compNormal.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;
+
 	};
 	};
 
 
-	this.createRenderTargets = function ( ) {
+	var createDeferredEmissiveLight = function () {
 
 
-		// g-buffers
+		// setup light material
 
 
-		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 );
+		var materialLight = new THREE.ShaderMaterial( {
 
 
-		rtColor.generateMipmaps = false;
-		rtNormal.generateMipmaps = false;
-		rtDepth.generateMipmaps = false;
-		rtLight.generateMipmaps = false;
-		rtEmitter.generateMipmaps = false;
-		rtFinal.generateMipmaps = false;
+			uniforms:       THREE.UniformsUtils.clone( emissiveLightShader.uniforms ),
+			vertexShader:   emissiveLightShader.vertexShader,
+			fragmentShader: emissiveLightShader.fragmentShader,
+			depthTest:		false,
+			depthWrite:		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 );
+		materialLight.uniforms[ "viewWidth" ].value = width;
+		materialLight.uniforms[ "viewHeight" ].value = height;
 
 
-		var passDepth = new THREE.RenderPass( scene, camera );
-		compDepth = new THREE.EffectComposer( renderer, rtDepth );
-		compDepth.addPass( passDepth );
+		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
+		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
 
 
-		var passEmitter = new THREE.RenderPass( emitterScene, camera );
-		compEmitter = new THREE.EffectComposer( renderer, rtEmitter );
-		compEmitter.addPass( passEmitter );
+		// create light proxy mesh
 
 
-		var passLight = new THREE.RenderPass( lightScene, camera );
-		compLightBuffer = new THREE.EffectComposer( renderer, rtLight );
-		compLightBuffer.addPass( passLight );
+		var geometryLight = new THREE.PlaneGeometry( 2, 2 );
+		var meshLight = new THREE.Mesh( geometryLight, materialLight );
 
 
-		//
+		// keep reference for size reset
 
 
-		lightShader.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
-		lightShader.uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
-		lightShader.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
-		lightShader.uniforms[ 'samplerLightBuffer' ].value = rtLight;
+		lightMaterials.push( materialLight );
 
 
-		compositeShader.uniforms[ 'samplerLightBuffer' ].value = compLightBuffer.renderTarget2;
-		compositeShader.uniforms[ 'samplerEmitter' ].value = compEmitter.renderTarget2;
+		return meshLight;
 
 
-		// composite
+	};
 
 
-		var compositePass = new THREE.ShaderPass( compositeShader );
-		compositePass.needsSwap = true;
+	var initDeferredProperties = function ( object ) {
 
 
-		var effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
-		effectFXAA.uniforms[ 'resolution' ].value.set( 1 / width, 1 / height );
+		if ( object.properties.deferredInitialized ) return;
 
 
-		var effectColor = new THREE.ShaderPass( THREE.ColorCorrectionShader );
-		effectColor.renderToScreen = true;
+		if ( object.material ) initDeferredMaterials( object );
 
 
-		effectColor.uniforms[ 'powRGB' ].value.set( 1, 1, 1 );
-		effectColor.uniforms[ 'mulRGB' ].value.set( 2, 2, 2 );
+		if ( object instanceof THREE.PointLight ) {
 
 
-		compFinal = new THREE.EffectComposer( renderer, rtFinal );
-		compFinal.addPass( compositePass );
-		compFinal.addPass( effectFXAA );
-		compFinal.addPass( effectColor );
+			var meshLight = createDeferredPointLight( object );
+			lightSceneProxy.add( meshLight );
+
+		} else if ( object instanceof THREE.DirectionalLight ) {
+
+			var meshLight = createDeferredDirectionalLight( object );
+			lightSceneFullscreen.add( meshLight );
+
+		}
+
+		object.properties.deferredInitialized = true;
 
 
 	};
 	};
 
 
-	this.addDeferredLights = function ( lights, additiveSpecular ) {
+	//
 
 
-		var geometryEmitter = new THREE.SphereGeometry( 0.7, 7, 7 );
+	var setMaterialColor = function ( object ) {
 
 
-		for ( var i = 0, il = lights.length; i < il; i ++ ) {
+		if ( object.material ) object.material = object.properties.colorMaterial;
 
 
-			var light = lights[ i ];
+	};
 
 
-			// setup material
+	var setMaterialDepth = function ( object ) {
 
 
-			var materialLight = new THREE.ShaderMaterial( {
+		if ( object.material ) object.material = object.properties.depthMaterial;
 
 
-				uniforms:       THREE.UniformsUtils.clone( lightShader.uniforms ),
-				vertexShader:   lightShader.vertexShader,
-				fragmentShader: lightShader.fragmentShader,
-				defines:		{ "ADDITIVE_SPECULAR": additiveSpecular },
+	};
 
 
-				blending:		THREE.AdditiveBlending,
-				depthWrite:		false,
-				transparent:	true
+	var setMaterialNormal = function ( object ) {
 
 
-			} );
+		if ( object.material ) object.material = object.properties.normalMaterial;
 
 
-			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 );
+	this.setSize = function ( width, height ) {
 
 
-			// create emitter sphere
+		compColor.setSize( width, height );
+		compNormal.setSize( width, height );
+		compDepth.setSize( width, height );
+		compLight.setSize( width, height );
+		compFinal.setSize( width, height );
 
 
-			var matEmitter = new THREE.ShaderMaterial( {
+		for ( var i = 0, il = lightMaterials.length; i < il; i ++ ) {
 
 
-				uniforms:       THREE.UniformsUtils.clone( unlitShader.uniforms ),
-				vertexShader:   unlitShader.vertexShader,
-				fragmentShader: unlitShader.fragmentShader
+			var uniforms = lightMaterials[ i ].uniforms;
 
 
-			} );
+			uniforms[ "viewWidth" ].value = width;
+			uniforms[ "viewHeight" ].value = height;
 
 
-			matEmitter.uniforms[ "samplerDepth" ].value = compDepth.renderTarget2;
-			matEmitter.uniforms[ "lightColor" ].value = light.color;
+			uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
+			uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
 
 
-			var meshEmitter = new THREE.Mesh( geometryEmitter, matEmitter );
-			meshEmitter.position = light.position;
-			emitterNode.add( meshEmitter );
+			if ( uniforms[ 'samplerNormals' ] ) {
 
 
-			// add emitter to light node
+				uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
 
 
-			meshLight.properties.emitter = meshEmitter;
+			}
 
 
 		}
 		}
 
 
-	};
+		compositePass.uniforms[ 'samplerLight' ].value = compLight.renderTarget2;
 
 
-	this.render = function () {
+		effectFXAA.uniforms[ 'resolution' ].value.set( scale / width, scale / height );
 
 
-		// -----------------------------
-		// g-buffer color
-		// -----------------------------
+	};
 
 
-		scene.traverse( function( node ) {
+	//
 
 
-			if ( node.material ) node.material = node.properties.colorMaterial;
+	this.render = function ( scene, camera ) {
 
 
-		} );
+		// setup deferred properties
 
 
-		compColor.render();
+		if ( ! scene.properties.lightSceneProxy ) {
 
 
-		// -----------------------------
-		// g-buffer depth
-		// -----------------------------
+			scene.properties.lightSceneProxy = new THREE.Scene();
+			scene.properties.lightSceneFullscreen = new THREE.Scene();
 
 
-		scene.traverse( function( node ) {
+			var meshLight = createDeferredEmissiveLight();
+			scene.properties.lightSceneFullscreen.add( meshLight );
 
 
-			if ( node.material ) node.material = node.properties.depthMaterial;
+		}
 
 
-		} );
+		lightSceneProxy = scene.properties.lightSceneProxy;
+		lightSceneFullscreen = scene.properties.lightSceneFullscreen;
 
 
-		compDepth.render();
+		passColor.camera = camera;
+		passNormal.camera = camera;
+		passDepth.camera = camera;
+		passLightProxy.camera = camera;
+		passLightFullscreen.camera = THREE.EffectComposer.camera;
 
 
-		// -----------------------------
-		// g-buffer normals
-		// -----------------------------
+		passColor.scene = scene;
+		passNormal.scene = scene;
+		passDepth.scene = scene;
+		passLightFullscreen.scene = lightSceneFullscreen;
+		passLightProxy.scene = lightSceneProxy;
 
 
-		scene.traverse( function( node ) {
+		scene.traverse( initDeferredProperties );
 
 
-			if ( node.material ) node.material = node.properties.normalMaterial;
+		// g-buffer color
 
 
-		} );
+		scene.traverse( setMaterialColor );
+		compColor.render();
 
 
-		compNormal.render();
+		// g-buffer depth
+
+		scene.traverse( setMaterialDepth );
+		compDepth.render();
 
 
-		// -----------------------------
-		// emitter pass
-		// -----------------------------
+		// g-buffer normals
 
 
-		compEmitter.render();
+		scene.traverse( setMaterialNormal );
+		compNormal.render();
 
 
-		// -----------------------------
 		// light pass
 		// light pass
-		// -----------------------------
 
 
 		camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
 		camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
 
 
-		for ( var i = 0, il = lightNode.children.length; i < il; i ++ ) {
+		for ( var i = 0, il = lightSceneProxy.children.length; i < il; i ++ ) {
 
 
-			var uniforms = lightNode.children[ i ].material.uniforms;
+			var uniforms = lightSceneProxy.children[ i ].material.uniforms;
 
 
 			uniforms[ "matProjInverse" ].value = camera.projectionMatrixInverse;
 			uniforms[ "matProjInverse" ].value = camera.projectionMatrixInverse;
 			uniforms[ "matView" ].value = camera.matrixWorldInverse;
 			uniforms[ "matView" ].value = camera.matrixWorldInverse;
 
 
 		}
 		}
 
 
-		compLightBuffer.render();
+		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
 		// composite pass
-		// -----------------------------
 
 
 		compFinal.render( 0.1 );
 		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( 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 rtFinal   = new THREE.WebGLRenderTarget( width, height, rtParamsUByte );
+
+		rtColor.generateMipmaps = false;
+		rtNormal.generateMipmaps = false;
+		rtDepth.generateMipmaps = false;
+		rtLight.generateMipmaps = false;
+		rtFinal.generateMipmaps = false;
+
+		// composers
+
+		passColor = new THREE.RenderPass();
+		compColor = new THREE.EffectComposer( renderer, rtColor );
+		compColor.addPass( passColor );
+
+		passNormal = new THREE.RenderPass();
+		compNormal = new THREE.EffectComposer( renderer, rtNormal );
+		compNormal.addPass( passNormal );
+
+		passDepth = new THREE.RenderPass();
+		compDepth = new THREE.EffectComposer( renderer, rtDepth );
+		compDepth.addPass( passDepth );
+
+		passLightFullscreen = new THREE.RenderPass();
+		passLightProxy = new THREE.RenderPass();
+		passLightProxy.clear = false;
+
+		compLight = new THREE.EffectComposer( renderer, rtLight );
+		compLight.addPass( passLightFullscreen );
+		compLight.addPass( passLightProxy );
+
+		// composite
+
+		compositePass = new THREE.ShaderPass( compositeShader );
+		compositePass.uniforms[ 'samplerLight' ].value = compLight.renderTarget2;
+		compositePass.uniforms[ 'multiply' ].value = multiply;
+
+		// FXAA
+
+		effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
+		effectFXAA.uniforms[ 'resolution' ].value.set( scale / width, scale / height );
+		effectFXAA.renderToScreen = true;
+
+		//
+
+		compFinal = new THREE.EffectComposer( renderer, rtFinal );
+		compFinal.addPass( compositePass );
+		compFinal.addPass( effectFXAA );
+
+	};
+
+	// init
+
+	createRenderTargets();
+
 };
 };

+ 214 - 23
examples/js/ShaderDeferred.js

@@ -17,6 +17,7 @@ THREE.ShaderDeferred = {
 			THREE.UniformsLib[ "shadowmap" ],
 			THREE.UniformsLib[ "shadowmap" ],
 
 
 			{
 			{
+				"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
 				"specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
 				"specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
 				"shininess": { type: "f", value: 30 }
 				"shininess": { type: "f", value: 30 }
 			}
 			}
@@ -27,6 +28,7 @@ THREE.ShaderDeferred = {
 
 
 			"uniform vec3 diffuse;",
 			"uniform vec3 diffuse;",
 			"uniform vec3 specular;",
 			"uniform vec3 specular;",
+			"uniform vec3 emissive;",
 			"uniform float shininess;",
 			"uniform float shininess;",
 
 
 			THREE.ShaderChunk[ "color_pars_fragment" ],
 			THREE.ShaderChunk[ "color_pars_fragment" ],
@@ -76,9 +78,9 @@ THREE.ShaderDeferred = {
 
 
 				"gl_FragColor.z = shininess;",
 				"gl_FragColor.z = shininess;",
 
 
-				// free
+				// emissive color
 
 
-				"gl_FragColor.w = 0.0;",
+				"gl_FragColor.w = vec3_to_float( 0.999 * emissive );",
 
 
 			"}"
 			"}"
 
 
@@ -313,32 +315,21 @@ THREE.ShaderDeferred = {
 
 
 		uniforms: {
 		uniforms: {
 
 
-			samplerLightBuffer: { type: "t", value: null },
-			samplerEmitter: 	{ type: "t", value: null }
+			samplerLight: 	{ type: "t", value: null },
+			multiply:		{ type: "f", value: 1 }
 
 
 		},
 		},
 
 
 		fragmentShader : [
 		fragmentShader : [
 
 
 			"varying vec2 texCoord;",
 			"varying vec2 texCoord;",
-			"uniform sampler2D samplerLightBuffer;",
-			"uniform sampler2D samplerEmitter;",
-			"uniform vec3 lightPos;",
+			"uniform sampler2D samplerLight;",
+			"uniform float multiply;",
 
 
 			"void main() {",
 			"void main() {",
 
 
-				"vec3 color = texture2D( samplerLightBuffer, texCoord ).xyz;",
-				"vec3 emitter = texture2D( samplerEmitter, texCoord ).xyz;",
-
-				"if ( emitter != vec3( 0.0 ) ) {",
-
-					"gl_FragColor = vec4( emitter, 1.0 );",
-
-				"} else {",
-
-					"gl_FragColor = vec4( sqrt( color ), 1.0 );",
-
-				"}",
+				"vec3 color = texture2D( samplerLight, texCoord ).xyz;",
+				"gl_FragColor = vec4( multiply * sqrt( color ), 1.0 );",
 
 
 			"}"
 			"}"
 
 
@@ -360,11 +351,10 @@ THREE.ShaderDeferred = {
 
 
 	},
 	},
 
 
-	"light" : {
+	"pointLight" : {
 
 
 		uniforms: {
 		uniforms: {
 
 
-			samplerLightBuffer: { type: "t", value: null },
 			samplerNormals: { type: "t", value: null },
 			samplerNormals: { type: "t", value: null },
 			samplerDepth: 	{ type: "t", value: null },
 			samplerDepth: 	{ type: "t", value: null },
 			samplerColor: 	{ type: "t", value: null },
 			samplerColor: 	{ type: "t", value: null },
@@ -387,7 +377,6 @@ THREE.ShaderDeferred = {
 			"uniform sampler2D samplerColor;",
 			"uniform sampler2D samplerColor;",
 			"uniform sampler2D samplerDepth;",
 			"uniform sampler2D samplerDepth;",
 			"uniform sampler2D samplerNormals;",
 			"uniform sampler2D samplerNormals;",
-			"uniform sampler2D samplerLightBuffer;",
 
 
 			"uniform float lightRadius;",
 			"uniform float lightRadius;",
 			"uniform float lightIntensity;",
 			"uniform float lightIntensity;",
@@ -527,7 +516,209 @@ THREE.ShaderDeferred = {
 
 
 		].join("\n")
 		].join("\n")
 
 
-	}
+	},
+
+	"directionalLight" : {
+
+		uniforms: {
+
+			samplerNormals: { type: "t", value: null },
+			samplerDepth: 	{ 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 },
+			lightDir: 		{ type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
+			lightColor: 	{ type: "c", value: new THREE.Color( 0x000000 ) },
+			lightIntensity: { type: "f", value: 1.0 }
+
+		},
+
+		fragmentShader : [
+
+			"varying vec3 lightView;",
+			"varying vec4 clipPos;",
+
+			"uniform sampler2D samplerColor;",
+			"uniform sampler2D samplerDepth;",
+			"uniform sampler2D samplerNormals;",
+
+			"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;",
+
+				"if ( z == 0.0 ) discard;",
+
+				"float x = texCoord.x * 2.0 - 1.0;",
+				"float y = texCoord.y * 2.0 - 1.0;",
+
+				"vec4 projectedPos = vec4( x, y, z, 1.0 );",
+
+				"vec4 viewPos = matProjInverse * projectedPos;",
+				"viewPos.xyz /= viewPos.w;",
+				"viewPos.w = 1.0;",
+
+				"vec3 lightDir = normalize( lightView );",
+
+				// normal
+
+				"vec3 normal = texture2D( samplerNormals, texCoord ).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;",
+
+				// wrap around lighting
+
+				"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.2, 0.2, 0.2 );",
+				"vec3 diffuse = mix( vec3 ( diffuseFull ), vec3( diffuseHalf ), wrapRGB );",
+
+				// simple lighting
+
+				//"float diffuseFull = max( dot( normal, lightDir ), 0.0 );",
+				//"vec3 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;",
+
+				"#ifdef ADDITIVE_SPECULAR",
+
+					"gl_FragColor = vec4( albedo * light * diffuse, 1.0 ) + vec4( light * specular, 1.0 );",
+
+				"#else",
+
+					"gl_FragColor = vec4( albedo * light * ( diffuse + specular ), 1.0 );",
+
+				"#endif",
+
+			"}"
+
+		].join("\n"),
+
+		vertexShader : [
+
+			"varying vec3 lightView;",
+			"varying vec4 clipPos;",
+			"uniform vec3 lightDir;",
+			"uniform mat4 matView;",
+
+			"void main() { ",
+
+				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
+				"gl_Position = projectionMatrix * mvPosition;",
+				"lightView = vec3( matView * vec4( lightDir, 0.0 ) );",
+				"clipPos = gl_Position;",
+
+			"}"
+
+		].join("\n")
+
+	},
+
+	"emissiveLight" : {
+
+		uniforms: {
+
+			samplerDepth: 	{ type: "t", value: null },
+			samplerColor: 	{ type: "t", value: null },
+			viewWidth: 		{ type: "f", value: 800 },
+			viewHeight: 	{ type: "f", value: 600 },
+
+		},
+
+		fragmentShader : [
+
+			"uniform sampler2D samplerDepth;",
+			"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 );",
+
+				"float z = texture2D( samplerDepth, texCoord ).x;",
+
+				"if ( z == 0.0 ) discard;",
+
+				"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")
+
+	}
 
 
 };
 };

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

@@ -6,19 +6,18 @@ THREE.EffectComposer = function ( renderer, renderTarget ) {
 
 
 	this.renderer = renderer;
 	this.renderer = renderer;
 
 
-	this.renderTarget1 = renderTarget;
-
-	if ( this.renderTarget1 === undefined ) {
+	if ( renderTarget === undefined ) {
 
 
 		var width = window.innerWidth || 1;
 		var width = window.innerWidth || 1;
 		var height = window.innerHeight || 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.writeBuffer = this.renderTarget1;
 	this.readBuffer = this.renderTarget2;
 	this.readBuffer = this.renderTarget2;
@@ -99,19 +98,32 @@ THREE.EffectComposer.prototype = {
 
 
 	reset: function ( renderTarget ) {
 	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.writeBuffer = this.renderTarget1;
 		this.readBuffer = this.renderTarget2;
 		this.readBuffer = this.renderTarget2;
 
 
+	},
+
+	setSize: function ( width, height ) {
+
+		var renderTarget = this.renderTarget1.clone();
+
+		renderTarget.width = width;
+		renderTarget.height = height;
+
+		this.reset( renderTarget );
+
 	}
 	}
 
 
 };
 };

+ 48 - 28
examples/webgl_lights_deferred_morphs.html

@@ -56,7 +56,6 @@
 
 
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/FXAAShader.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/EffectComposer.js"></script>
 		<script src="js/postprocessing/RenderPass.js"></script>
 		<script src="js/postprocessing/RenderPass.js"></script>
@@ -78,7 +77,6 @@
 
 
 			var NEAR = 1.0, FAR = 350.0;
 			var NEAR = 1.0, FAR = 350.0;
 			var VIEW_ANGLE = 45;
 			var VIEW_ANGLE = 45;
-			var ASPECT = WIDTH / HEIGHT;
 
 
 			// controls
 			// controls
 
 
@@ -120,6 +118,8 @@
 				renderer.setSize( WIDTH, HEIGHT );
 				renderer.setSize( WIDTH, HEIGHT );
 				renderer.setClearColorHex( 0x000000, 1 );
 				renderer.setClearColorHex( 0x000000, 1 );
 
 
+				renderer.autoClear = false;
+
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.top = MARGIN + "px";
 				renderer.domElement.style.top = MARGIN + "px";
 				renderer.domElement.style.left = "0px";
 				renderer.domElement.style.left = "0px";
@@ -129,7 +129,7 @@
 
 
 				// camera
 				// camera
 
 
-				camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR );
+				camera = new THREE.PerspectiveCamera( VIEW_ANGLE, WIDTH / HEIGHT, NEAR, FAR );
 				camera.position.z = 150;
 				camera.position.z = 150;
 
 
 				// scene
 				// scene
@@ -151,8 +151,7 @@
 
 
 				// deferred helper
 				// deferred helper
 
 
-				deferredHelper = new THREE.DeferredHelper( { renderer: renderer, scene: scene, camera: camera, width: SCALED_WIDTH, height: SCALED_HEIGHT } );
-				deferredHelper.createRenderTargets();
+				deferredHelper = new THREE.DeferredHelper( { renderer: renderer, width: SCALED_WIDTH, height: SCALED_HEIGHT, scale: SCALE, multiply: 2, additiveSpecular: true } );
 
 
 				// add lights
 				// add lights
 
 
@@ -165,22 +164,11 @@
 				// events
 				// events
 
 
 				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
 				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() {
 			function initLights() {
@@ -190,6 +178,7 @@
 				// front light
 				// front light
 
 
 				var light = new THREE.PointLight( 0xffffff, 1.5, 1.5 * distance );
 				var light = new THREE.PointLight( 0xffffff, 1.5, 1.5 * distance );
+				scene.add( light );
 				lights.push( light );
 				lights.push( light );
 
 
 				// random lights
 				// random lights
@@ -205,11 +194,26 @@
 					light.color.setRGB( c.x, c.y, c.z );
 					light.color.setRGB( c.x, c.y, c.z );
 					light.color.convertGammaToLinear();
 					light.color.convertGammaToLinear();
 
 
+					scene.add( light );
 					lights.push( 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 );
+
+				}
 
 
 			}
 			}
 
 
@@ -228,22 +232,20 @@
 					meshAnim.duration = 3000;
 					meshAnim.duration = 3000;
 					meshAnim.properties.delta = -13;
 					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;
 					meshAnim.rotation.y = -Math.PI/2;
 
 
+					scene.add( meshAnim );
 					morphs.push( meshAnim );
 					morphs.push( meshAnim );
 
 
-					addObject( meshAnim, -48, 50 );
-
 				} );
 				} );
 
 
 				// add box
 				// add box
 
 
-				var object = generateBox();
-				addObject( object, 0, 8 );
+				var box = generateBox();
+				box.scale.multiplyScalar( 8 );
+				scene.add( box );
 
 
 			}
 			}
 
 
@@ -318,6 +320,25 @@
 
 
 			// -----------------------------
 			// -----------------------------
 
 
+			function onWindowResize( event ) {
+
+				windowHalfX = window.innerWidth / 2;
+				windowHalfY = window.innerHeight / 2;
+
+				WIDTH = window.innerWidth;
+				HEIGHT = window.innerHeight - 2 * MARGIN;
+
+				SCALED_WIDTH = Math.floor( SCALE * WIDTH );
+				SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
+
+				renderer.setSize( WIDTH, HEIGHT );
+				deferredHelper.setSize( SCALED_WIDTH, SCALED_HEIGHT );
+
+				camera.aspect = WIDTH / HEIGHT;
+				camera.updateProjectionMatrix();
+
+			}
+
 			function onDocumentMouseMove( event ) {
 			function onDocumentMouseMove( event ) {
 
 
 				mouseX = ( event.clientX - windowHalfX ) * 1;
 				mouseX = ( event.clientX - windowHalfX ) * 1;
@@ -391,8 +412,7 @@
 
 
 				camera.lookAt( target );
 				camera.lookAt( target );
 
 
-
-				deferredHelper.render();
+				deferredHelper.render( scene, camera );
 
 
 			}
 			}
 
 

+ 79 - 27
examples/webgl_lights_deferred_pointlights.html

@@ -55,7 +55,6 @@
 
 
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/CopyShader.js"></script>
 		<script src="js/shaders/FXAAShader.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/EffectComposer.js"></script>
 		<script src="js/postprocessing/RenderPass.js"></script>
 		<script src="js/postprocessing/RenderPass.js"></script>
@@ -82,7 +81,6 @@
 
 
 			var NEAR = 1.0, FAR = 350.0;
 			var NEAR = 1.0, FAR = 350.0;
 			var VIEW_ANGLE = 45;
 			var VIEW_ANGLE = 45;
-			var ASPECT = WIDTH / HEIGHT;
 
 
 			// controls
 			// controls
 
 
@@ -120,6 +118,8 @@
 				renderer.setSize( WIDTH, HEIGHT );
 				renderer.setSize( WIDTH, HEIGHT );
 				renderer.setClearColorHex( 0x000000, 1 );
 				renderer.setClearColorHex( 0x000000, 1 );
 
 
+				renderer.autoClear = false;
+
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.top = MARGIN + "px";
 				renderer.domElement.style.top = MARGIN + "px";
 				renderer.domElement.style.left = "0px";
 				renderer.domElement.style.left = "0px";
@@ -129,7 +129,7 @@
 
 
 				// camera
 				// camera
 
 
-				camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR );
+				camera = new THREE.PerspectiveCamera( VIEW_ANGLE, WIDTH / HEIGHT, NEAR, FAR );
 				camera.position.z = 150;
 				camera.position.z = 150;
 
 
 				// scene
 				// scene
@@ -151,8 +151,7 @@
 
 
 				// deferred helper
 				// deferred helper
 
 
-				deferredHelper = new THREE.DeferredHelper( { renderer: renderer, scene: scene, camera: camera, width: SCALED_WIDTH, height: SCALED_HEIGHT } );
-				deferredHelper.createRenderTargets();
+				deferredHelper = new THREE.DeferredHelper( { renderer: renderer, width: SCALED_WIDTH, height: SCALED_HEIGHT, scale: SCALE, additiveSpecular: false, multiply: 2 } );
 
 
 				// add lights
 				// add lights
 
 
@@ -165,19 +164,7 @@
 				// events
 				// events
 
 
 				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
 				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 +177,7 @@
 				// front light
 				// front light
 
 
 				var light = new THREE.PointLight( 0xffffff, 1.5, 1.5 * distance );
 				var light = new THREE.PointLight( 0xffffff, 1.5, 1.5 * distance );
+				scene.add( light );
 				lights.push( light );
 				lights.push( light );
 
 
 				// random lights
 				// random lights
@@ -205,11 +193,26 @@
 					light.color.setRGB( c.x, c.y, c.z );
 					light.color.setRGB( c.x, c.y, c.z );
 					light.color.convertGammaToLinear();
 					light.color.convertGammaToLinear();
 
 
+					scene.add( light );
 					lights.push( 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 +226,22 @@
 
 
 				loader.load( "models/utf8/ben_dds.js", function ( object ) {
 				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 } );
 				}, { normalizeRGB: true } );
 
 
 				loader.load( "models/utf8/WaltHi.js", function ( object ) {
 				loader.load( "models/utf8/WaltHi.js", function ( object ) {
 
 
-					addObject( object, -35, 1 );
-					animate();
+					object.position.y = -35;
+					scene.add( object );
 
 
 				}, { normalizeRGB: true } );
 				}, { normalizeRGB: true } );
 
 
 				*/
 				*/
 
 
+
 				var loader = new THREE.JSONLoader();
 				var loader = new THREE.JSONLoader();
 				loader.load( "obj/leeperrysmith/LeePerrySmith.js", function( geometry, materials ) {
 				loader.load( "obj/leeperrysmith/LeePerrySmith.js", function( geometry, materials ) {
 
 
@@ -251,14 +256,42 @@
 					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 } );
 
 
 					var object = new THREE.Mesh( geometry, material );
 					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 ) {
+
+					var material = new THREE.MeshPhongMaterial( { shininess: 175, specular: 0x999999 } );
+
+					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 ) {
+
+					var material = new THREE.MeshPhongMaterial( { shininess: 175, specular: 0x999999 } );
+
+					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
 				// create box
 
 
-				var object = generateBox();
-				addObject( object, 0, 8 );
+				var box = generateBox();
+				box.scale.multiplyScalar( 8 );
+				scene.add( box );
 
 
 			}
 			}
 
 
@@ -334,6 +367,25 @@
 
 
 			// -----------------------------
 			// -----------------------------
 
 
+			function onWindowResize( event ) {
+
+				windowHalfX = window.innerWidth / 2;
+				windowHalfY = window.innerHeight / 2;
+
+				WIDTH = window.innerWidth;
+				HEIGHT = window.innerHeight - 2 * MARGIN;
+
+				SCALED_WIDTH = Math.floor( SCALE * WIDTH );
+				SCALED_HEIGHT = Math.floor( SCALE * HEIGHT );
+
+				renderer.setSize( WIDTH, HEIGHT );
+				deferredHelper.setSize( SCALED_WIDTH, SCALED_HEIGHT );
+
+				camera.aspect = WIDTH / HEIGHT;
+				camera.updateProjectionMatrix();
+
+			}
+
 			function onDocumentMouseMove( event ) {
 			function onDocumentMouseMove( event ) {
 
 
 				mouseX = ( event.clientX - windowHalfX ) * 1;
 				mouseX = ( event.clientX - windowHalfX ) * 1;
@@ -393,7 +445,7 @@
 
 
 				camera.lookAt( target );
 				camera.lookAt( target );
 
 
-				deferredHelper.render();
+				deferredHelper.render( scene, camera );
 
 
 			}
 			}
 
 

+ 3 - 6
examples/webgl_marching_cubes.html

@@ -185,7 +185,7 @@
 
 
 			renderer.autoClear = false;
 			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 );
 			renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
 
 
 			effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
 			effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
@@ -235,14 +235,11 @@
 			SCREEN_WIDTH = window.innerWidth;
 			SCREEN_WIDTH = window.innerWidth;
 			SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 			SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 
 
-			renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
-
 			camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 			camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 			camera.updateProjectionMatrix();
 			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;
 			hblur.uniforms[ 'h' ].value = 4 / SCREEN_WIDTH;
 			vblur.uniforms[ 'v' ].value = 4 / SCREEN_HEIGHT;
 			vblur.uniforms[ 'v' ].value = 4 / SCREEN_HEIGHT;

+ 4 - 7
examples/webgl_materials_cubemap_dynamic.html

@@ -100,7 +100,7 @@
 			var container, stats;
 			var container, stats;
 
 
 			var camera, cameraTarget, scene, renderer;
 			var camera, cameraTarget, scene, renderer;
-			var renderTarget, renderTargetParameters;
+			var renderTarget;
 
 
 			var spotLight, ambientLight;
 			var spotLight, ambientLight;
 
 
@@ -412,7 +412,7 @@
 
 
 				renderer.autoClear = false;
 				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 );
 				renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
 
 
 				effectSave = new THREE.SavePass( 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_WIDTH = window.innerWidth;
 				SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 				SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 
 
-				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
-
 				camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 				camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 				camera.updateProjectionMatrix();
 				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;
 				hblur.uniforms[ 'h' ].value = 10.75 / SCREEN_WIDTH;
 				vblur.uniforms[ 'v' ].value = 10.75 / SCREEN_HEIGHT;
 				vblur.uniforms[ 'v' ].value = 10.75 / SCREEN_HEIGHT;

+ 8 - 10
examples/webgl_postprocessing.html

@@ -83,8 +83,6 @@
 
 
 			var materialColor, material2D, quadBG, quadMask, renderScene;
 			var materialColor, material2D, quadBG, quadMask, renderScene;
 
 
-			var rtParameters;
-
 			var delta = 0.01;
 			var delta = 0.01;
 
 
 			init();
 			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 rtWidth  = width / 2;
 				var rtHeight = height / 2;
 				var rtHeight = height / 2;
@@ -294,8 +292,6 @@
 				halfWidth = window.innerWidth / 2;
 				halfWidth = window.innerWidth / 2;
 				halfHeight = window.innerHeight / 2;
 				halfHeight = window.innerHeight / 2;
 
 
-				renderer.setSize( window.innerWidth, window.innerHeight );
-
 				cameraPerspective.aspect = window.innerWidth / window.innerHeight;
 				cameraPerspective.aspect = window.innerWidth / window.innerHeight;
 				cameraPerspective.updateProjectionMatrix();
 				cameraPerspective.updateProjectionMatrix();
 
 
@@ -306,12 +302,14 @@
 
 
 				cameraOrtho.updateProjectionMatrix();
 				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;
 				renderScene.uniforms[ "tDiffuse" ].value = composerScene.renderTarget2;
 
 

+ 3 - 6
examples/webgl_shading_physical.html

@@ -398,7 +398,7 @@
 
 
 				renderer.autoClear = false;
 				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 );
 				renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
 
 
 				effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
 				effectFXAA = new THREE.ShaderPass( THREE.FXAAShader );
@@ -497,14 +497,11 @@
 				SCREEN_WIDTH = window.innerWidth;
 				SCREEN_WIDTH = window.innerWidth;
 				SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 				SCREEN_HEIGHT = window.innerHeight - 2 * MARGIN;
 
 
-				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
-
 				camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 				camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
 				camera.updateProjectionMatrix();
 				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;
 				hblur.uniforms[ 'h' ].value = 4 / SCREEN_WIDTH;
 				vblur.uniforms[ 'v' ].value = 4 / SCREEN_HEIGHT;
 				vblur.uniforms[ 'v' ].value = 4 / SCREEN_HEIGHT;

+ 70 - 45
src/core/Box2.js

@@ -4,14 +4,13 @@
 
 
 THREE.Box2 = function ( min, max ) {
 THREE.Box2 = function ( min, max ) {
 
 
-	if( ! min && ! max ) {			
+	if ( min == undefined && max === undefined ) {
 		this.min = new THREE.Vector2();
 		this.min = new THREE.Vector2();
 		this.max = new THREE.Vector2();
 		this.max = new THREE.Vector2();
 		this.makeEmpty();
 		this.makeEmpty();
-	}
-	else {
+	} else {
 		this.min = min || new THREE.Vector2();
 		this.min = min || new THREE.Vector2();
-		this.max = 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.
+		this.max = 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.
 	}
 	}
 };
 };
 
 
@@ -29,36 +28,47 @@ THREE.Box2.prototype = {
 
 
 	setFromPoints: function ( points ) {
 	setFromPoints: function ( points ) {
 
 
-		if( points.length > 0 ) {
+		if ( points.length > 0 ) {
+
+			var p = points[ 0 ];
 
 
-			var p = points[0];
 			this.min.copy( p );
 			this.min.copy( p );
 			this.max.copy( p );
 			this.max.copy( p );
 
 
-			for( var i = 1, numPoints = points.length; i < numPoints; i ++ ) {
+			for ( var i = 1, il = points.length; i < il; i ++ ) {
 
 
-				p = points[ v ];
+				p = points[ i ];
 
 
 				if ( p.x < this.min.x ) {
 				if ( p.x < this.min.x ) {
+
 					this.min.x = p.x;
 					this.min.x = p.x;
-				}
-				else if ( p.x > this.max.x ) {
+
+				} else if ( p.x > this.max.x ) {
+
 					this.max.x = p.x;
 					this.max.x = p.x;
+
 				}
 				}
 
 
 				if ( p.y < this.min.y ) {
 				if ( p.y < this.min.y ) {
+
 					this.min.y = p.y;
 					this.min.y = p.y;
-				}
-				else if ( p.y > this.max.y ) {
+
+				} else if ( p.y > this.max.y ) {
+
 					this.max.y = p.y;
 					this.max.y = p.y;
+
 				}
 				}
+
 			}
 			}
-		}
-		else {
+
+		} else {
+
 			this.makeEmpty();
 			this.makeEmpty();
+
 		}
 		}
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	setFromCenterAndSize: function ( center, size ) {
 	setFromCenterAndSize: function ( center, size ) {
@@ -67,7 +77,8 @@ THREE.Box2.prototype = {
 		this.min.copy( center ).subSelf( halfSize );
 		this.min.copy( center ).subSelf( halfSize );
 		this.max.copy( center ).addSelf( halfSize );
 		this.max.copy( center ).addSelf( halfSize );
 
 
-		return box;	
+		return this;
+
 	},
 	},
 
 
 	copy: function ( box ) {
 	copy: function ( box ) {
@@ -76,6 +87,7 @@ THREE.Box2.prototype = {
 		this.max.copy( box.max );
 		this.max.copy( box.max );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	makeEmpty: function () {
 	makeEmpty: function () {
@@ -84,36 +96,37 @@ THREE.Box2.prototype = {
 		this.max.x = this.max.y = -Infinity;
 		this.max.x = this.max.y = -Infinity;
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	empty: function () {
 	empty: function () {
 
 
 		// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
 		// 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 );
+		return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
+
 	},
 	},
 
 
 	volume: function () {
 	volume: function () {
 
 
-		return 
-			( this.max.x - this.min.x ) *
-			( this.max.y - this.min.y );
+		return ( this.max.x - this.min.x ) * ( this.max.y - this.min.y );
+
 	},
 	},
 
 
 	center: function () {
 	center: function () {
 
 
 		return new THREE.Vector2().add( this.min, this.max ).multiplyScalar( 0.5 );
 		return new THREE.Vector2().add( this.min, this.max ).multiplyScalar( 0.5 );
+
 	},
 	},
 
 
 	size: function () {
 	size: function () {
 
 
 		return new THREE.Vector2().sub( this.max, this.min );
 		return new THREE.Vector2().sub( this.max, this.min );
+
 	},
 	},
 
 
 	expandByPoint: function ( point ) {
 	expandByPoint: function ( point ) {
 
 
-		this.min.minSelf( point );		
+		this.min.minSelf( point );
 		this.max.maxSelf( point );
 		this.max.maxSelf( point );
 
 
 		return this;
 		return this;
@@ -131,28 +144,34 @@ THREE.Box2.prototype = {
 
 
 		this.min.addScalar( -scalar );
 		this.min.addScalar( -scalar );
 		this.max.addScalar( scalar );
 		this.max.addScalar( scalar );
-		
+
 		return this;
 		return this;
 	},
 	},
 
 
 	containsPoint: function ( point ) {
 	containsPoint: function ( point ) {
-		if( 
-			( this.min.x <= point.x ) && ( point.x <= this.max.x ) &&
-			( this.min.y <= point.y ) && ( point.y <= this.max.y )
-			) {
+
+		if ( ( this.min.x <= point.x ) && ( point.x <= this.max.x ) &&
+			( this.min.y <= point.y ) && ( point.y <= this.max.y ) ) {
+
 			return true;
 			return true;
+
 		}
 		}
+
 		return false;
 		return false;
+
 	},
 	},
 
 
 	containsBox: function ( box ) {
 	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 )
-			) {
+
+		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 true;
+
 		}
 		}
+
 		return false;
 		return false;
+
 	},
 	},
 
 
 	getParameter: function ( point ) {
 	getParameter: function ( point ) {
@@ -161,36 +180,40 @@ THREE.Box2.prototype = {
 		return new THREE.Vector2(
 		return new THREE.Vector2(
 			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
 			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
 			( point.y - this.min.y ) / ( this.max.y - this.min.y )
 			( point.y - this.min.y ) / ( this.max.y - this.min.y )
-			);
+		);
+	},
+
+	isIntersection: function ( box ) {
+		// using 6 splitting planes to rule out intersections.
+		if ( ( this.max.x < box.min.x ) || ( box.min.x > this.max.x ) ||
+			( this.max.y < box.min.y ) || ( box.min.y > this.max.y ) ) {
+
+			return false;
+
+		}
+
+		return true;
 	},
 	},
 
 
 	clampPoint: function ( point ) {
 	clampPoint: function ( point ) {
 
 
 		return new THREE.Vector2().copy( point ).clampSelf( this.min, this.max );
 		return new THREE.Vector2().copy( point ).clampSelf( this.min, this.max );
+
 	},
 	},
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
 		return this.clampPoint( point ).subSelf( point ).length();
 		return this.clampPoint( point ).subSelf( point ).length();
-	},
 
 
-	isIntersection: function ( box ) {
-		// using 6 splitting planes to rule out intersections.
-		if( 
-			( this.max.x < box.min.x ) || ( box.min.x > this.max.x ) ||
-			( this.max.y < box.min.y ) || ( box.min.y > this.max.y )
-			) {
-			return false;
-		}
-		return true;
 	},
 	},
 
 
 	intersect: function ( box ) {
 	intersect: function ( box ) {
 
 
 		this.min.maxSelf( box.min );
 		this.min.maxSelf( box.min );
 		this.max.minSelf( box.max );
 		this.max.minSelf( box.max );
-		
+
 		return this;
 		return this;
+
 	},
 	},
 
 
 	union: function ( box ) {
 	union: function ( box ) {
@@ -199,6 +222,7 @@ THREE.Box2.prototype = {
 		this.max.maxSelf( box.max );
 		this.max.maxSelf( box.max );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	translate: function ( offset ) {
 	translate: function ( offset ) {
@@ -207,6 +231,7 @@ THREE.Box2.prototype = {
 		this.max.addSelf( offset );
 		this.max.addSelf( offset );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	scale: function ( factor ) {
 	scale: function ( factor ) {
@@ -215,6 +240,7 @@ THREE.Box2.prototype = {
 		this.expandByVector( sizeDeltaHalf );
 		this.expandByVector( sizeDeltaHalf );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	equals: function ( box ) {
 	equals: function ( box ) {
@@ -229,7 +255,6 @@ THREE.Box2.prototype = {
 
 
 	}
 	}
 
 
-	
 };
 };
 
 
-THREE.Box2.__v1 = new THREE.Vector2();
+THREE.Box2.__v1 = new THREE.Vector2();

+ 86 - 48
src/core/Box3.js

@@ -4,14 +4,15 @@
 
 
 THREE.Box3 = function ( min, max ) {
 THREE.Box3 = function ( min, max ) {
 
 
-	if( ! min && ! max ) {			
+	if( min == undefined && max === undefined ) {
+
 		this.min = new THREE.Vector3();
 		this.min = new THREE.Vector3();
 		this.max = new THREE.Vector3();
 		this.max = new THREE.Vector3();
 		this.makeEmpty();
 		this.makeEmpty();
 	}
 	}
 	else {
 	else {
 		this.min = min || new THREE.Vector3();
 		this.min = min || new THREE.Vector3();
-		this.max = 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.
+		this.max = 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.
 	}
 	}
 };
 };
 
 
@@ -25,44 +26,58 @@ THREE.Box3.prototype = {
 		this.max = max;
 		this.max = max;
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	setFromPoints: function ( points ) {
 	setFromPoints: function ( points ) {
 
 
-		if( points.length > 0 ) {
+		if ( points.length > 0 ) {
+
+			var p = points[ 0 ];
 
 
-			var p = points[0];
 			this.min.copy( p );
 			this.min.copy( p );
 			this.max.copy( p );
 			this.max.copy( p );
 
 
-			for( var i = 1, numPoints = points.length; i < numPoints; i ++ ) {
+			for ( var i = 1, il = points.length; i < il; i ++ ) {
 
 
-				p = points[ v ];
+				p = points[ i ];
 
 
 				if ( p.x < this.min.x ) {
 				if ( p.x < this.min.x ) {
+
 					this.min.x = p.x;
 					this.min.x = p.x;
-				}
-				else if ( p.x > this.max.x ) {
+
+				} else if ( p.x > this.max.x ) {
+
 					this.max.x = p.x;
 					this.max.x = p.x;
+
 				}
 				}
 
 
 				if ( p.y < this.min.y ) {
 				if ( p.y < this.min.y ) {
+
 					this.min.y = p.y;
 					this.min.y = p.y;
-				}
-				else if ( p.y > this.max.y ) {
+
+				} else if ( p.y > this.max.y ) {
+
 					this.max.y = p.y;
 					this.max.y = p.y;
+
 				}
 				}
 
 
 				if ( p.z < this.min.z ) {
 				if ( p.z < this.min.z ) {
+
 					this.min.z = p.z;
 					this.min.z = p.z;
-				}
-				else if ( p.z > this.max.z ) {
+
+				} else if ( p.z > this.max.z ) {
+
 					this.max.z = p.z;
 					this.max.z = p.z;
+
 				}
 				}
+
 			}
 			}
-		}
-		else {
+
+		} else {
+
 			this.makeEmpty();
 			this.makeEmpty();
+
 		}
 		}
 
 
 		return this;
 		return this;
@@ -71,10 +86,12 @@ THREE.Box3.prototype = {
 	setFromCenterAndSize: function ( center, size ) {
 	setFromCenterAndSize: function ( center, size ) {
 
 
 		var halfSize = THREE.Box3.__v1.copy( size ).multiplyScalar( 0.5 );
 		var halfSize = THREE.Box3.__v1.copy( size ).multiplyScalar( 0.5 );
+
 		this.min.copy( center ).subSelf( halfSize );
 		this.min.copy( center ).subSelf( halfSize );
 		this.max.copy( center ).addSelf( halfSize );
 		this.max.copy( center ).addSelf( halfSize );
 
 
-		return box;	
+		return this;
+
 	},
 	},
 
 
 	copy: function ( box ) {
 	copy: function ( box ) {
@@ -83,6 +100,7 @@ THREE.Box3.prototype = {
 		this.max.copy( box.max );
 		this.max.copy( box.max );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	makeEmpty: function () {
 	makeEmpty: function () {
@@ -91,41 +109,41 @@ THREE.Box3.prototype = {
 		this.max.x = this.max.y = this.max.z = -Infinity;
 		this.max.x = this.max.y = this.max.z = -Infinity;
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	empty: function () {
 	empty: function () {
 
 
 		// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
 		// 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 );
+		return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
+
 	},
 	},
 
 
 	volume: function () {
 	volume: function () {
 
 
-		return 
-			( this.max.x - this.min.x ) *
-			( this.max.y - this.min.y ) *
-			( this.max.z - this.min.z );
+		return ( this.max.x - this.min.x ) * ( this.max.y - this.min.y ) * ( this.max.z - this.min.z );
+
 	},
 	},
 
 
 	center: function () {
 	center: function () {
 
 
 		return new THREE.Vector3().add( this.min, this.max ).multiplyScalar( 0.5 );
 		return new THREE.Vector3().add( this.min, this.max ).multiplyScalar( 0.5 );
+
 	},
 	},
 
 
 	size: function () {
 	size: function () {
 
 
 		return new THREE.Vector3().sub( this.max, this.min );
 		return new THREE.Vector3().sub( this.max, this.min );
+
 	},
 	},
 
 
 	expandByPoint: function ( point ) {
 	expandByPoint: function ( point ) {
 
 
-		this.min.minSelf( point );		
+		this.min.minSelf( point );
 		this.max.maxSelf( point );
 		this.max.maxSelf( point );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	expandByVector: function ( vector ) {
 	expandByVector: function ( vector ) {
@@ -134,76 +152,93 @@ THREE.Box3.prototype = {
 		this.max.addSelf( vector );
 		this.max.addSelf( vector );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	expandByScalar: function ( scalar ) {
 	expandByScalar: function ( scalar ) {
 
 
 		this.min.addScalar( -scalar );
 		this.min.addScalar( -scalar );
 		this.max.addScalar( scalar );
 		this.max.addScalar( scalar );
-		
+
 		return this;
 		return this;
+
 	},
 	},
 
 
 	containsPoint: function ( point ) {
 	containsPoint: function ( point ) {
-		if( 
-			( this.min.x <= point.x ) && ( point.x <= this.max.x ) &&
+
+		if ( ( this.min.x <= point.x ) && ( point.x <= this.max.x ) &&
 			( this.min.y <= point.y ) && ( point.y <= this.max.y ) &&
 			( this.min.y <= point.y ) && ( point.y <= this.max.y ) &&
-			( this.min.z <= point.z ) && ( point.z <= this.max.z )
-			) {
+			( this.min.z <= point.z ) && ( point.z <= this.max.z ) ) {
+
 			return true;
 			return true;
+
 		}
 		}
+
 		return false;
 		return false;
+
 	},
 	},
 
 
 	containsBox: function ( box ) {
 	containsBox: function ( box ) {
-		if( 
-			( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
+
+		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.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
-			( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z )
-			) {
+			( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
+
 			return true;
 			return true;
+
 		}
 		}
+
 		return false;
 		return false;
+
 	},
 	},
 
 
 	getParameter: function ( point ) {
 	getParameter: function ( point ) {
+
 		// This can potentially have a divide by zero if the box
 		// This can potentially have a divide by zero if the box
 		// has a size dimension of 0.
 		// has a size dimension of 0.
 		return new THREE.Vector3(
 		return new THREE.Vector3(
 			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
 			( point.x - this.min.x ) / ( this.max.x - this.min.x ),
 			( point.y - this.min.y ) / ( this.max.y - this.min.y ),
 			( point.y - this.min.y ) / ( this.max.y - this.min.y ),
 			( point.z - this.min.z ) / ( this.max.z - this.min.z )
 			( point.z - this.min.z ) / ( this.max.z - this.min.z )
-			);
+		);
+
+	},
+
+	isIntersection: function ( box ) {
+
+		// using 6 splitting planes to rule out intersections.
+
+		if ( ( this.max.x < box.min.x ) || ( box.min.x > this.max.x ) ||
+			( this.max.y < box.min.y ) || ( box.min.y > this.max.y ) ||
+			( this.max.z < box.min.z ) || ( box.min.z > this.max.z ) ) {
+
+			return false;
+
+		}
+
+		return true;
+
 	},
 	},
 
 
 	clampPoint: function ( point ) {
 	clampPoint: function ( point ) {
 
 
 		return new THREE.Vector3().copy( point ).clampSelf( this.min, this.max );
 		return new THREE.Vector3().copy( point ).clampSelf( this.min, this.max );
+
 	},
 	},
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
 		return this.clampPoint( point ).subSelf( point ).length();
 		return this.clampPoint( point ).subSelf( point ).length();
-	},
 
 
-	isIntersection: function ( box ) {
-		// using 6 splitting planes to rule out intersections.
-		if( 
-			( this.max.x < box.min.x ) || ( box.min.x > this.max.x ) ||
-			( this.max.y < box.min.y ) || ( box.min.y > this.max.y ) ||
-			( this.max.z < box.min.z ) || ( box.min.z > this.max.z )
-			) {
-			return false;
-		}
-		return true;
 	},
 	},
 
 
 	intersect: function ( box ) {
 	intersect: function ( box ) {
 
 
 		this.min.maxSelf( box.min );
 		this.min.maxSelf( box.min );
 		this.max.minSelf( box.max );
 		this.max.minSelf( box.max );
-		
+
 		return this;
 		return this;
+
 	},
 	},
 
 
 	union: function ( box ) {
 	union: function ( box ) {
@@ -212,6 +247,7 @@ THREE.Box3.prototype = {
 		this.max.maxSelf( box.max );
 		this.max.maxSelf( box.max );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	translate: function ( offset ) {
 	translate: function ( offset ) {
@@ -220,6 +256,7 @@ THREE.Box3.prototype = {
 		this.max.addSelf( offset );
 		this.max.addSelf( offset );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	scale: function ( factor ) {
 	scale: function ( factor ) {
@@ -228,6 +265,7 @@ THREE.Box3.prototype = {
 		this.expandByVector( sizeDeltaHalf );
 		this.expandByVector( sizeDeltaHalf );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	equals: function ( box ) {
 	equals: function ( box ) {
@@ -241,7 +279,7 @@ THREE.Box3.prototype = {
 		return new THREE.Box3().copy( this );
 		return new THREE.Box3().copy( this );
 
 
 	}
 	}
-	
+
 };
 };
 
 
-THREE.Box3.__v1 = new THREE.Vector3();
+THREE.Box3.__v1 = new THREE.Vector3();

+ 19 - 10
src/core/Plane.js

@@ -44,8 +44,9 @@ THREE.Plane.prototype = {
 
 
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
 		this.setFromNormalAndCoplanarPoint( normal, a );
 		this.setFromNormalAndCoplanarPoint( normal, a );
-		
+
 		return this;
 		return this;
+
 	},
 	},
 
 
 	copy: function ( plane ) {
 	copy: function ( plane ) {
@@ -54,6 +55,7 @@ THREE.Plane.prototype = {
 		this.constant = plane.constant;
 		this.constant = plane.constant;
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	flip: function () {
 	flip: function () {
@@ -61,6 +63,7 @@ THREE.Plane.prototype = {
 		this.normal.negate();
 		this.normal.negate();
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	normalize: function () {
 	normalize: function () {
@@ -71,6 +74,7 @@ THREE.Plane.prototype = {
 		this.constant *= inverseNormalLength;
 		this.constant *= inverseNormalLength;
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
@@ -83,42 +87,47 @@ THREE.Plane.prototype = {
 		return this.distanceToPoint( sphere.center ) - sphere.radius;
 		return this.distanceToPoint( sphere.center ) - sphere.radius;
 	},
 	},
 
 
-	projectPoint: function ( point ) {		
-		
+	projectPoint: function ( point ) {
+
 		return this.orthoPoint( point ).subSelf( point ).negate();
 		return this.orthoPoint( point ).subSelf( point ).negate();
+
 	},
 	},
 
 
-	orthoPoint: function ( point ) {		
+	orthoPoint: function ( point ) {
 
 
 		var perpendicularMagnitude = this.distanceToPoint( point );
 		var perpendicularMagnitude = this.distanceToPoint( point );
 
 
 		return new THREE.Vector3().copy( this.normal ).multiplyScalar( perpendicularMagnitude );
 		return new THREE.Vector3().copy( this.normal ).multiplyScalar( perpendicularMagnitude );
+
 	},
 	},
 
 
-	intersectsLine: function ( startPoint, endPoint ) {	
+	intersectsLine: function ( startPoint, endPoint ) {
 
 
 		// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
 		// 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 startSign = this.distanceToPoint( startPoint );
 		var endSign = this.distanceToPoint( endPoint );
 		var endSign = this.distanceToPoint( endPoint );
 
 
 		return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
 		return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
+
 	},
 	},
 
 
-	coplanarPoint: function () {		
-		
+	coplanarPoint: function () {
+
 		return new THREE.Vector3().copy( this.normal ).multiplyScalar( - this.constant );
 		return new THREE.Vector3().copy( this.normal ).multiplyScalar( - this.constant );
+
 	},
 	},
 
 
 	translate: function ( offset ) {
 	translate: function ( offset ) {
 
 
-		this.constant =	- offset.dot( normal );
+		this.constant = - offset.dot( this.normal );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	equals: function ( plane ) {
 	equals: function ( plane ) {
 
 
-		return plane.normal.equals( this.normal ) && ( sphere.constant == this.constant );
+		return plane.normal.equals( this.normal ) && ( plane.constant == this.constant );
 
 
 	},
 	},
 
 
@@ -130,4 +139,4 @@ THREE.Plane.prototype = {
 };
 };
 
 
 THREE.Plane.__v1 = new THREE.Vector3();
 THREE.Plane.__v1 = new THREE.Vector3();
-THREE.Plane.__v2 = new THREE.Vector3();
+THREE.Plane.__v2 = new THREE.Vector3();

+ 21 - 6
src/core/Sphere.js

@@ -19,20 +19,25 @@ THREE.Sphere.prototype = {
 		this.radius = radius;
 		this.radius = radius;
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	setFromCenterAndPoints: function ( center, points ) {
 	setFromCenterAndPoints: function ( center, points ) {
 
 
 		var maxRadiusSq = 0;
 		var maxRadiusSq = 0;
-		for ( var i = 0, numPoints = points.length; i < numPoints; i ++ ) {			
-			var radiusSq = center.distanceToSquared( points[i] );
+
+		for ( var i = 0, il = points.length; i < il; i ++ ) {
+
+			var radiusSq = center.distanceToSquared( points[ i ] );
 			maxRadiusSq = Math.max( maxRadiusSq, radiusSq );
 			maxRadiusSq = Math.max( maxRadiusSq, radiusSq );
+
 		}
 		}
 
 
 		this.center = center;
 		this.center = center;
 		this.radius = Math.sqrt( maxRadiusSq );
 		this.radius = Math.sqrt( maxRadiusSq );
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	copy: function ( sphere ) {
 	copy: function ( sphere ) {
@@ -41,26 +46,31 @@ THREE.Sphere.prototype = {
 		this.radius = sphere.radius;
 		this.radius = sphere.radius;
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	empty: function () {
 	empty: function () {
 
 
 		return ( this.radius <= 0 );
 		return ( this.radius <= 0 );
+
 	},
 	},
 
 
 	volume: function () {
 	volume: function () {
 
 
 		return Math.PI * 4 / 3 * ( this.radius * this.radius * this.radius );
 		return Math.PI * 4 / 3 * ( this.radius * this.radius * this.radius );
+
 	},
 	},
 
 
 	containsPoint: function ( point ) {
 	containsPoint: function ( point ) {
 
 
 		return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
 		return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
+
 	},
 	},
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
 		return ( point.distanceTo( this.center ) - this.radius );
 		return ( point.distanceTo( this.center ) - this.radius );
+
 	},
 	},
 
 
 	clampPoint: function ( point ) {
 	clampPoint: function ( point ) {
@@ -69,13 +79,15 @@ THREE.Sphere.prototype = {
 
 
 		var result = new THREE.Vector3().copy( point );
 		var result = new THREE.Vector3().copy( point );
 
 
-		if( deltaLengthSq > ( this.radius * this.radius ) ) {
+		if ( deltaLengthSq > ( this.radius * this.radius ) ) {
 
 
-			result.subSelf( center ).normalize();
+			result.subSelf( this.center ).normalize();
 			result.multiplyScalar( this.radius ).addSelf( this.center );
 			result.multiplyScalar( this.radius ).addSelf( this.center );
+
 		}
 		}
 
 
 		return result;
 		return result;
+
 	},
 	},
 
 
 	bounds: function () {
 	bounds: function () {
@@ -84,20 +96,23 @@ THREE.Sphere.prototype = {
 		box.expandByScalar( this.radius );
 		box.expandByScalar( this.radius );
 
 
 		return box;
 		return box;
+
 	},
 	},
 
 
 	translate: function ( offset ) {
 	translate: function ( offset ) {
 
 
 		this.center.addSelf( this.offset );
 		this.center.addSelf( this.offset );
-		
+
 		return this;
 		return this;
+
 	},
 	},
 
 
 	scale: function ( factor ) {
 	scale: function ( factor ) {
 
 
 		this.radius *= factor;
 		this.radius *= factor;
-		
+
 		return this;
 		return this;
+
 	},
 	},
 
 
 	equals: function ( sphere ) {
 	equals: function ( sphere ) {

+ 9 - 15
src/extras/GeometryUtils.js

@@ -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 ) {
 	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();
 
 
 	},
 	},
 
 
@@ -1045,3 +1038,4 @@ THREE.GeometryUtils = {
 THREE.GeometryUtils.random = THREE.Math.random16;
 THREE.GeometryUtils.random = THREE.Math.random16;
 
 
 THREE.GeometryUtils.__v1 = new THREE.Vector3();
 THREE.GeometryUtils.__v1 = new THREE.Vector3();
+THREE.GeometryUtils.__v2 = new THREE.Vector3();

+ 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 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,
 		light, hex, intensity,
 		counter_models, counter_textures,
 		counter_models, counter_textures,
 		total_models, total_textures,
 		total_models, total_textures,
@@ -168,45 +166,52 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 	function handle_children( parent, children ) {
 	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,
 			// check by id if child has already been handled,
 			// if not, create new object
 			// 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;
 				var object = null;
 
 
 				// meshes
 				// 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 = {};
 					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
 					// OBJLoader
 
 
 					if ( loader.addEventListener ) {
 					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 {
 					} else {
 
 
@@ -214,21 +219,21 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 						if ( loader.options ) {
 						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
 						// UTF8Loader
 
 
 						} else {
 						} 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
 					// geometry already loaded
 
 
@@ -236,25 +241,25 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 						var needsTangents = false;
 						var needsTangents = false;
 
 
-						material = result.materials[ o.material ];
+						material = result.materials[ objJSON.material ];
 						needsTangents = material instanceof THREE.ShaderMaterial;
 						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
 						// turn off quaternions, for the moment
 
 
-						q = 0;
+						quat = 0;
 
 
 						// use materials from the model file
 						// use materials from the model file
 						// if there is no material specified in the object
 						// 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 ) {
 						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 );
 							object = new THREE.SkinnedMesh( geometry, material );
 
 
-						} else if ( o.morph ) {
+						} else if ( objJSON.morph ) {
 
 
 							object = new THREE.MorphAnimMesh( geometry, material );
 							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.matrixAutoUpdate = false;
 							object.matrix.set(
 							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 {
 						} 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;
 								object.useQuaternion = true;
 
 
 							} else {
 							} 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 );
 						parent.add( object );
 
 
-						result.objects[ dd ] = object;
+						result.objects[ objID ] = object;
 
 
 					}
 					}
 
 
 				// lights
 				// 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 = 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
 							// kill existing default target
 							// otherwise it gets added to scene when parent gets added
 							// 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 );
 						light = new THREE.AmbientLight( hex );
 
 
@@ -404,86 +409,86 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 					parent.add( light );
 					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
 				// 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 );
 					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
 				// pure Object3D
 
 
 				} else {
 				} 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
 					// turn off quaternions, for the moment
 
 
-					q = 0;
+					quat = 0;
 
 
 					object = new THREE.Object3D();
 					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;
 						object.useQuaternion = true;
 
 
 					} else {
 					} 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 );
 					parent.add( object );
 
 
-					result.objects[ dd ] = object;
-					result.empties[ dd ] = object;
+					result.objects[ objID ] = object;
+					result.empties[ objID ] = object;
 
 
 				}
 				}
 
 
 				if ( 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;
 							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] );
 		node.position.set( p[0], p[1], p[2] );
 
 
@@ -689,24 +694,26 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 	// fogs
 	// 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
 	// 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;
 			counter_models += 1;
 
 
@@ -732,11 +741,13 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 	// count how many hierarchies will be loaded asynchronously
 	// 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;
 			counter_models += 1;
 
 
@@ -748,59 +759,60 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 	total_models = counter_models;
 	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 = {};
 			var loaderParameters = {};
-			for ( var parType in g ) {
+
+			for ( var parType in geoJSON ) {
 
 
 				if ( parType !== "type" && parType !== "url" ) {
 				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 = "";
 				texture_path = "";
 
 
 			// pass metadata along to jsonLoader so it knows the format version
 			// 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 ) {
 			if ( modelJson ) {
 
 
 				var jsonLoader = this.geometryHandlerMap[ "ascii" ][ "loaderObject" ];
 				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
 	// 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();
 				scope.onLoadStart();
 
 
@@ -848,24 +862,24 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 	total_textures = counter_textures;
 	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 = [];
 			var url_array = [];
 
 
 			for( var i = 0; i < count; i ++ ) {
 			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 ) {
 			if ( isCompressed ) {
 
 
-				texture = THREE.ImageUtils.loadCompressedTextureCube( url_array, tt.mapping, generateTextureCallback( count ) );
+				texture = THREE.ImageUtils.loadCompressedTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
 
 
 			} else {
 			} else {
 
 
-				texture = THREE.ImageUtils.loadTextureCube( url_array, tt.mapping, generateTextureCallback( count ) );
+				texture = THREE.ImageUtils.loadTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
 
 
 			}
 			}
 
 
 		} else {
 		} 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 );
 			var textureCallback = generateTextureCallback( 1 );
 
 
 			if ( isCompressed ) {
 			if ( isCompressed ) {
 
 
-				texture = THREE.ImageUtils.loadCompressedTexture( fullUrl, tt.mapping, textureCallback );
+				texture = THREE.ImageUtils.loadCompressedTexture( fullUrl, textureJSON.mapping, textureCallback );
 
 
 			} else {
 			} 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
 			// handle wrap after repeat so that default repeat can be overriden
 
 
-			if ( tt.wrap ) {
+			if ( textureJSON.wrap ) {
 
 
 				var wrapMap = {
 				var wrapMap = {
 				"repeat" 	: THREE.RepeatWrapping,
 				"repeat" 	: THREE.RepeatWrapping,
 				"mirror"	: THREE.MirroredRepeatWrapping
 				"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
 	// 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 {
 				} 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
 				// 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 shader = THREE.ShaderUtils.lib[ "normal" ];
 			var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
 			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;
 				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[ "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;
 				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;
 				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[ "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;
 			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 {
 		} 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
 	// second pass through all materials to initialize MeshFaceMaterials
 	// that could be referring to other materials out of order
 	// 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 = [];
 			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 ] );
 				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 = 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;
 	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.wrapT = this.wrapT;
 
 
 	tmp.magFilter = this.magFilter;
 	tmp.magFilter = this.magFilter;
-	tmp.anisotropy = this.anisotropy;
-
 	tmp.minFilter = this.minFilter;
 	tmp.minFilter = this.minFilter;
 
 
+	tmp.anisotropy = this.anisotropy;
+
 	tmp.offset.copy( this.offset );
 	tmp.offset.copy( this.offset );
 	tmp.repeat.copy( this.repeat );
 	tmp.repeat.copy( this.repeat );
 
 

+ 6 - 6
src/renderers/WebGLRenderer.js

@@ -151,7 +151,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 	_projScreenMatrix = new THREE.Matrix4(),
 	_projScreenMatrix = new THREE.Matrix4(),
 	_projScreenMatrixPS = new THREE.Matrix4(),
 	_projScreenMatrixPS = new THREE.Matrix4(),
 
 
-	_vector3 = new THREE.Vector4(),
+	_vector3 = new THREE.Vector3(),
 
 
 	// light arrays cache
 	// 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 ++ ) {
 			for ( v = 0; v < vl; v ++ ) {
 
 
@@ -3798,7 +3798,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 				if ( influence > 0 ) {
 				if ( influence > 0 ) {
 
 
-					activeInfluenceIndices.push( [ i, influence ] );
+					activeInfluenceIndices.push( [ influence, i ] );
 
 
 				}
 				}
 
 
@@ -3825,7 +3825,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 				if ( activeInfluenceIndices[ m ] ) {
 				if ( activeInfluenceIndices[ m ] ) {
 
 
-					influenceIndex = activeInfluenceIndices[ m ][ 0 ];
+					influenceIndex = activeInfluenceIndices[ m ][ 1 ];
 
 
 					if ( attributes[ "morphTarget" + m ] >= 0 ) {
 					if ( attributes[ "morphTarget" + m ] >= 0 ) {
 
 
@@ -3896,7 +3896,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 	function numericalSort ( a, b ) {
 	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.bindRenderbuffer( _gl.RENDERBUFFER, null );
-			_gl.bindFramebuffer( _gl.FRAMEBUFFER, null);
+			_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
 
 
 		}
 		}
 
 

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


Some files were not shown because too many files changed in this diff