Browse Source

Synced with mrdoob's branch.

alteredq 14 years ago
parent
commit
06a977384d

File diff suppressed because it is too large
+ 90 - 90
build/Three.js


File diff suppressed because it is too large
+ 91 - 91
build/ThreeDebug.js


File diff suppressed because it is too large
+ 84 - 84
build/ThreeExtras.js


+ 0 - 1
examples/geometry_terrain_gl.html

@@ -37,7 +37,6 @@
 		<script type="text/javascript" src="js/ImprovedNoise.js"></script>
 		<script type="text/javascript" src="js/ImprovedNoise.js"></script>
 
 
 		<script type="text/javascript" src="../build/Three.js"></script>
 		<script type="text/javascript" src="../build/Three.js"></script>
-		<script type="text/javascript" src="../src/extras/GeometryUtils.js"></script>
 		<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
 		<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
 
 
 		<script type="text/javascript">
 		<script type="text/javascript">

+ 347 - 0
examples/geometry_terrain_gl2.html

@@ -0,0 +1,347 @@
+<!DOCTYPE HTML>
+<html lang="en">
+	<head>
+		<title>three.js - geometry - webgl terrain</title>
+		<meta charset="utf-8">
+		<style type="text/css">
+			body {
+				color: #61443e;
+				font-family:Monospace;
+				font-size:13px;
+				text-align:center;
+
+				background-color: #bfd1e5;
+				margin: 0px;
+				overflow: hidden;
+			}
+
+			#info {
+				position: absolute;
+				top: 0px; width: 100%;
+				padding: 5px;
+			}
+
+			a {
+
+				color: #a06851;
+			}
+
+		</style>
+	</head>
+	<body>
+
+		<div id="container"><br /><br /><br /><br /><br />Generating world...</div> 
+		<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl terrain demo<br />(left click: forward, right click: backward)</div> 
+
+		<script type="text/javascript" src="js/Stats.js"></script>
+		<script type="text/javascript" src="js/PRNG.js"></script>
+		<script type="text/javascript" src="js/SimplexNoise.js"></script>
+
+		<script type="text/javascript" src="../build/Three.js"></script>
+		<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
+
+		<script type="text/javascript">
+
+			var container, stats;
+
+			var camera, scene, renderer;
+
+			var mesh, texture;
+
+			var worldWidth = 256, worldDepth = 256,
+			worldHalfWidth = worldWidth / 2, worldHalfDepth = worldDepth / 2;
+
+			var mouseX = 0, mouseY = 0,
+			lat = 0, lon = 0, phy = 0, theta = 0;
+
+			var direction = new THREE.Vector3(),
+			moveForward = false, moveBackward = false;
+
+			var windowHalfX = window.innerWidth / 2;
+			var windowHalfY = window.innerHeight / 2;
+
+
+			init();
+			setInterval( loop, 1000 / 60 );
+
+
+			function init() {
+
+				container = document.getElementById( 'container' );
+
+				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 20000 );
+				camera.target.position.z = - 100;
+
+				scene = new THREE.Scene();
+
+				data = generateHeight( worldWidth, worldDepth );
+
+				camera.position.y = ( data[ worldHalfWidth + ( worldHalfDepth * worldWidth ) ] * 10 ) + 200;
+				camera.target.position.y = camera.position.y;
+
+				var geometry = new Plane( 10000, 10000, worldWidth - 1, worldDepth - 1 );
+
+				for ( var i = 0, l = geometry.vertices.length; i < l; i ++ ) {
+
+					geometry.vertices[ i ].position.z = data[ i ] * 10;
+
+				}
+
+				texture = new THREE.Texture( generateTexture( data, worldWidth, worldDepth ), new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping );
+
+				mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { map: texture } ) );
+				mesh.rotation.x = - 90 * Math.PI / 180;
+				scene.addObject( mesh );
+
+				renderer = new THREE.WebGLRenderer( { scene: scene } );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				container.innerHTML = "";
+
+				container.appendChild( renderer.domElement );
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				container.appendChild( stats.domElement );
+
+				document.addEventListener( 'mousedown', onDocumentMouseDown, false );
+				document.addEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
+
+			}
+
+			/*
+			function generateHeight( width, height ) {
+
+				var size = width * height, data = new Float32Array( size ),
+				perlin = new ImprovedNoise(), quality = 1, z = Math.random() * 100;
+
+				for ( var i = 0; i < size; i ++ ) {
+
+					data[ i ] = 0
+
+				}
+
+				for ( var j = 0; j < 4; j ++ ) {
+
+					for ( var i = 0; i < size; i ++ ) {
+
+						var x = i % width, y = ~~ ( i / width );
+						data[ i ] += Math.abs( perlin.noise( x / quality, y / quality, z ) * quality * 1.75 );
+
+
+					}
+
+					quality *= 5;
+
+				}
+
+				return data;
+
+			}
+			*/
+
+			function generateHeight( width, height ) {
+
+				var x, y, h, quality = 100, size = width * height, octaves = 10, offsetX = 100, offsetY = 100, data = [],
+				prng = new PRNG(), simplex1 = new SimplexNoise( prng ), simplex2 = new SimplexNoise( prng ), simplex3 = new SimplexNoise( prng );
+
+				simplex1.setSeed( Math.random() * 100 );
+				simplex2.setSeed( Math.random() * 100 );
+				simplex3.setSeed( Math.random() * 100 );
+
+				// Base Terrain
+
+				for ( var i = 0; i < size; i ++ ) {
+
+					x = ( ( i % width ) + offsetX ) / quality;
+					y = ( ~~ ( i / width ) + offsetY ) / quality;
+					h = 32 - ( Math.abs( simplex1.noise( x, y, 0 ) + simplex2.noise( x, y, 0 ) ) - simplex3.noise( x, y, 0 ) ) * 64;
+
+					data[ i ] = h;
+
+				}
+
+				// Blur
+
+				for ( var i = 0; i < size; i ++ ) {
+
+					x = i % width;
+
+					if ( x == 0 ) continue;
+					if ( x = width - 1 ); continue;
+
+					data[ i ] += ( data[ i - 1 ] + data[ i + 1 ] ) * 0.5;
+					data[ i ] *= 0.5;
+
+				}
+
+				for ( var i = width; i < size - width; i ++ ) {
+
+					data[ i ] += ( data[ i - width ] + data[ i + width ] ) * 0.5;
+					data[ i ] *= 0.5;
+
+				}
+
+				for ( var j = 4; j < 100; j *= 2 ) {
+
+					for ( var i = 0; i < size; i ++ ) {
+
+						x = ( ( i % width ) + offsetX ) / j,
+						y = ( ~~ ( i / width ) + offsetY ) / j;
+
+						data[ i ] -= Math.abs( simplex1.noise( x, y, 0 ) * simplex2.noise( x, y, 0 ) * simplex3.noise( x, y, 0 ) ) * j;
+
+					}
+
+				}
+
+				return data;
+
+			}
+
+			function generateTexture( data, width, height ) {
+
+				var canvas, canvasScaled, context, image, imageData,
+				level, diff, texel, vector3, sun, shade;
+
+				vector3 = new THREE.Vector3( 0, 0, 0 );
+
+				sun = new THREE.Vector3( 1, 1, 1 );
+				sun.normalize();
+
+				canvas = document.createElement( 'canvas' );
+				canvas.width = width;
+				canvas.height = height;
+
+				context = canvas.getContext( '2d' );
+				context.fillStyle = '#000';
+				context.fillRect( 0, 0, width, height );
+
+				image = context.getImageData( 0, 0, canvas.width, canvas.height );
+				imageData = image.data;
+
+				for ( var i = 0, j = 0, l = imageData.length; i < l; i += 4, j ++ ) {
+
+					texel = data[ j ];
+
+					/*
+					imageData[ i ] = texel;
+					imageData[ i + 1 ] = texel;
+					imageData[ i + 2 ] = texel;
+					continue;
+					*/
+
+					shade = 0;
+
+					for ( var k = 1; k < 16; k ++ ) {
+
+						vector3.x = data[ j - k ] - data[ j + k ];
+						vector3.y = 1;
+						vector3.z = data[ j - width * k ] - data[ j + width * k ];
+						vector3.normalize();
+
+						shade += vector3.dot( sun ) * ( 16 - k );
+
+					}
+
+					imageData[ i ] = ( 128 + shade ) + texel;
+					imageData[ i + 1 ] = ( 64 + shade ) + texel;
+					imageData[ i + 2 ] = ( 32 + shade ) + texel;
+
+				}
+
+				context.putImageData( image, 0, 0 );
+
+				// Scaled 4x
+
+				canvasScaled = document.createElement( 'canvas' );
+				canvasScaled.width = width * 4;
+				canvasScaled.height = height * 4;
+				canvasScaled.loaded = true;
+
+				context = canvasScaled.getContext( '2d' );
+				context.scale( 4, 4 );
+				context.drawImage( canvas, 0, 0 );
+
+				image = context.getImageData( 0, 0, canvasScaled.width, canvasScaled.height );
+				imageData = image.data;
+
+				for ( var i = 0, l = imageData.length; i < l; i += 4 ) {
+
+					var v = ~~ ( Math.random() * 5 );
+
+					imageData[ i ] += v;
+					imageData[ i + 1 ] += v;
+					imageData[ i + 2 ] += v;
+
+				}
+
+				context.putImageData( image, 0, 0 );
+
+				return canvasScaled;
+
+			}
+
+			function onDocumentMouseDown( event ) {
+
+				event.preventDefault();
+				event.stopPropagation();
+
+				switch ( event.button ) {
+
+					case 0: moveForward = true; break;
+					case 2: moveBackward = true; break;
+
+				}
+
+			}
+
+			function onDocumentMouseUp( event ) {
+
+				event.preventDefault();
+				event.stopPropagation();
+
+				switch ( event.button ) {
+
+					case 0: moveForward = false; break;
+					case 2: moveBackward = false; break;
+
+				}
+
+			}
+
+			function onDocumentMouseMove(event) {
+
+				mouseX = event.clientX - windowHalfX;
+				mouseY = event.clientY - windowHalfY;
+
+			}
+
+			function loop() {
+
+				if ( moveForward ) camera.translateZ( - 10 );
+				if ( moveBackward ) camera.translateZ( 10 );
+
+				lon += mouseX * 0.004;
+				lat -= mouseY * 0.004;
+
+				lat = Math.max( - 85, Math.min( 85, lat ) );
+				phi = ( 90 - lat ) * Math.PI / 180;
+				theta = lon * Math.PI / 180;
+
+				camera.target.position.x = 100 * Math.sin( phi ) * Math.cos( theta ) + camera.position.x;
+				camera.target.position.y = 100 * Math.cos( phi ) + camera.position.y;
+				camera.target.position.z = 100 * Math.sin( phi ) * Math.sin( theta ) + camera.position.z;
+
+				renderer.render(scene, camera);
+				stats.update();
+
+			}
+
+		</script>
+
+	</body>
+</html>

+ 11 - 0
examples/js/PRNG.js

@@ -0,0 +1,11 @@
+// Park-Miller-Carta Pseudo-Random Number Generator
+// https://github.com/pnitsch/BitmapData.js/blob/master/js/BitmapData.js
+
+var PRNG = function () {
+
+	this.seed = 1;
+	this.next = function() { return (this.gen() / 2147483647); };
+	this.nextRange = function(min, max)	{ return min + ((max - min) * this.next()) };
+	this.gen = function() { return this.seed = (this.seed * 16807) % 2147483647; };
+
+};

+ 92 - 0
examples/js/SimplexNoise.js

@@ -0,0 +1,92 @@
+// Ported from Stefan Gustavson's java implementation
+// http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
+// Sean McCullough [email protected]
+
+var SimplexNoise = function(gen) {
+	this.rand = gen;
+	this.grad3 = [
+		[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0], 
+		[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1], 
+		[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]
+	]; 
+	
+	this.simplex = [ 
+		[0,1,2,3],[0,1,3,2],[0,0,0,0],[0,2,3,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,3,0], 
+		[0,2,1,3],[0,0,0,0],[0,3,1,2],[0,3,2,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,3,2,0], 
+		[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0], 
+		[1,2,0,3],[0,0,0,0],[1,3,0,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,3,0,1],[2,3,1,0], 
+		[1,0,2,3],[1,0,3,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,3,1],[0,0,0,0],[2,1,3,0], 
+		[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0], 
+		[2,0,1,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,0,1,2],[3,0,2,1],[0,0,0,0],[3,1,2,0], 
+		[2,1,0,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,1,0,2],[0,0,0,0],[3,2,0,1],[3,2,1,0]
+	]; 
+};
+
+SimplexNoise.prototype.setSeed = function(seed) {
+	this.p = [];
+	this.rand.seed = seed;
+	
+	for (var i=0; i<256; i++) {
+		this.p[i] = Math.floor(this.rand.nextRange(0, 255));
+	}
+
+	this.perm = []; 
+	for(var i=0; i<512; i++) {
+		this.perm[i]=this.p[i & 255];
+	}
+}
+
+SimplexNoise.prototype.dot = function(g, x, y) {
+	return g[0]*x + g[1]*y;
+};
+
+SimplexNoise.prototype.noise = function(xin, yin) { 
+	var n0, n1, n2; 
+
+	var F2 = 0.5*(Math.sqrt(3.0)-1.0); 
+	var s = (xin+yin)*F2; 
+	var i = Math.floor(xin+s); 
+	var j = Math.floor(yin+s); 
+	var G2 = (3.0-Math.sqrt(3.0))/6.0; 
+	var t = (i+j)*G2; 
+	var X0 = i-t; 
+	var Y0 = j-t; 
+	var x0 = xin-X0; 
+	var y0 = yin-Y0; 
+
+	var i1, j1; 
+	if(x0>y0) {i1=1; j1=0;} 
+	else {i1=0; j1=1;}      
+
+	var x1 = x0 - i1 + G2; 
+	var y1 = y0 - j1 + G2; 
+	var x2 = x0 - 1.0 + 2.0 * G2;  
+	var y2 = y0 - 1.0 + 2.0 * G2; 
+
+	var ii = i & 255; 
+	var jj = j & 255; 
+	var gi0 = this.perm[ii+this.perm[jj]] % 12; 
+	var gi1 = this.perm[ii+i1+this.perm[jj+j1]] % 12; 
+	var gi2 = this.perm[ii+1+this.perm[jj+1]] % 12; 
+
+	var t0 = 0.5 - x0*x0-y0*y0; 
+	if(t0<0) n0 = 0.0; 
+	else { 
+		t0 *= t0; 
+		n0 = t0 * t0 * this.dot(this.grad3[gi0], x0, y0);  
+	} 
+	var t1 = 0.5 - x1*x1-y1*y1; 
+	if(t1<0) n1 = 0.0; 
+	else { 
+		t1 *= t1; 
+		n1 = t1 * t1 * this.dot(this.grad3[gi1], x1, y1); 
+	}
+	var t2 = 0.5 - x2*x2-y2*y2; 
+	if(t2<0) n2 = 0.0; 
+	else { 
+		t2 *= t2; 
+		n2 = t2 * t2 * this.dot(this.grad3[gi2], x2, y2); 
+	} 
+
+	return 70.0 * (n0 + n1 + n2); 
+};

+ 2 - 2
src/core/Color.js

@@ -7,7 +7,7 @@ THREE.Color = function ( hex ) {
 	this.autoUpdate = true;
 	this.autoUpdate = true;
 	this.setHex( hex );
 	this.setHex( hex );
 
 
-}
+};
 
 
 THREE.Color.prototype = {
 THREE.Color.prototype = {
 
 
@@ -65,7 +65,7 @@ THREE.Color.prototype = {
 
 
 	},
 	},
 
 
-	
+
 	toString: function () {
 	toString: function () {
 
 
 		return 'THREE.Color ( r: ' + this.r + ', g: ' + this.g + ', b: ' + this.b + ', hex: ' + this.hex + ' )';
 		return 'THREE.Color ( r: ' + this.r + ', g: ' + this.g + ', b: ' + this.b + ', hex: ' + this.hex + ' )';

+ 3 - 3
src/core/Geometry.js

@@ -113,7 +113,7 @@ THREE.Geometry.prototype = {
 
 
 	computeVertexNormals: function () {
 	computeVertexNormals: function () {
 
 
-		var v, vertices = [],
+		var v, vl, vertices = [],
 		f, fl, face;
 		f, fl, face;
 
 
 		for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
 		for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
@@ -179,7 +179,7 @@ THREE.Geometry.prototype = {
 
 
 		var f, fl, v, vl, face, uv, vA, vB, vC, uvA, uvB, uvC,
 		var f, fl, v, vl, face, uv, vA, vB, vC, uvA, uvB, uvC,
 			x1, x2, y1, y2, z1, z2,
 			x1, x2, y1, y2, z1, z2,
-			s1, s2, t1, t2, r, t, n,
+			s1, s2, t1, t2, r, t, test,
 			tan1 = [], tan2 = [],
 			tan1 = [], tan2 = [],
 			sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
 			sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
 			tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
 			tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
@@ -355,7 +355,7 @@ THREE.Geometry.prototype = {
 		// which could then use vertex color attributes instead of each being
 		// which could then use vertex color attributes instead of each being
 		// in its separate VBO
 		// in its separate VBO
 
 
-		var i, l, f, fl, face, material, vertices, mhash, ghash, hash_map = {};
+		var i, l, f, fl, face, material, materials, vertices, mhash, ghash, hash_map = {};
 
 
 		function materialHash( material ) {
 		function materialHash( material ) {
 
 

+ 1 - 1
src/core/Matrix3.js

@@ -18,4 +18,4 @@ THREE.Matrix3.prototype = {
 
 
 	}
 	}
 
 
-}
+};

+ 1 - 1
src/core/UV.js

@@ -24,4 +24,4 @@ THREE.UV.prototype = {
 
 
 	}
 	}
 
 
-}
+};

+ 1 - 1
src/core/Vertex.js

@@ -16,7 +16,7 @@ THREE.Vertex = function ( position, normal ) {
 
 
 	this.__visible = true;
 	this.__visible = true;
 
 
-}
+};
 
 
 THREE.Vertex.prototype = {
 THREE.Vertex.prototype = {
 
 

+ 3 - 3
src/extras/GeometryUtils.js

@@ -28,7 +28,7 @@ var GeometryUtils = {
 
 
 		}
 		}
 
 
-		for ( var i = 0, il = faces2.length; i < il; i ++ ) {
+		for ( i = 0, il = faces2.length; i < il; i ++ ) {
 
 
 			var face = faces2[ i ], faceCopy, normal,
 			var face = faces2[ i ], faceCopy, normal,
 			faceVertexNormals = face.vertexNormals;
 			faceVertexNormals = face.vertexNormals;
@@ -59,7 +59,7 @@ var GeometryUtils = {
 
 
 		}
 		}
 
 
-		for ( var i = 0, il = uvs2.length; i < il; i ++ ) {
+		for ( i = 0, il = uvs2.length; i < il; i ++ ) {
 
 
 			var uv = uvs2[ i ], uvCopy = [];
 			var uv = uvs2[ i ], uvCopy = [];
 
 
@@ -75,4 +75,4 @@ var GeometryUtils = {
 
 
 	}
 	}
 
 
-}
+};

+ 2 - 2
src/extras/ImageUtils.js

@@ -20,7 +20,7 @@ var ImageUtils = {
 
 
 			images[ i ] = new Image();
 			images[ i ] = new Image();
 			images[ i ].loaded = 0;
 			images[ i ].loaded = 0;
-			images[ i ].onload = function () { images.loadCount += 1; this.loaded = true; }
+			images[ i ].onload = function () { images.loadCount += 1; this.loaded = true; };
 			images[ i ].src = array[ i ];
 			images[ i ].src = array[ i ];
 
 
 		}
 		}
@@ -29,4 +29,4 @@ var ImageUtils = {
 
 
 	}
 	}
 
 
-}
+};

+ 19 - 19
src/extras/SceneUtils.js

@@ -1,7 +1,7 @@
 var SceneUtils = {
 var SceneUtils = {
-	
+
 	addMesh: function ( scene, geometry, scale, x, y, z, rx, ry, rz, material ) {
 	addMesh: function ( scene, geometry, scale, x, y, z, rx, ry, rz, material ) {
-		
+
 		var mesh = new THREE.Mesh( geometry, material );
 		var mesh = new THREE.Mesh( geometry, material );
 		mesh.scale.x = mesh.scale.y = mesh.scale.z = scale;
 		mesh.scale.x = mesh.scale.y = mesh.scale.z = scale;
 		mesh.position.x = x;
 		mesh.position.x = x;
@@ -13,30 +13,30 @@ var SceneUtils = {
 		scene.addObject( mesh );
 		scene.addObject( mesh );
 
 
 		return mesh;
 		return mesh;
-		
-	},	
+
+	},
 
 
 	addPanoramaCubeWebGL: function ( scene, size, textureCube ) {
 	addPanoramaCubeWebGL: function ( scene, size, textureCube ) {
-		
+
 		var shader = ShaderUtils.lib["cube"];
 		var shader = ShaderUtils.lib["cube"];
 		shader.uniforms["tCube"].texture = textureCube;
 		shader.uniforms["tCube"].texture = textureCube;
-		
-		var material = new THREE.MeshShaderMaterial( { fragment_shader: shader.fragment_shader, 
-													   vertex_shader: shader.vertex_shader, 
+
+		var material = new THREE.MeshShaderMaterial( { fragment_shader: shader.fragment_shader,
+													   vertex_shader: shader.vertex_shader,
 													   uniforms: shader.uniforms
 													   uniforms: shader.uniforms
 													} ),
 													} ),
-													
+
 			mesh = new THREE.Mesh( new Cube( size, size, size, 1, 1, null, true ), material );
 			mesh = new THREE.Mesh( new Cube( size, size, size, 1, 1, null, true ), material );
-		
+
 		scene.addObject( mesh );
 		scene.addObject( mesh );
-		
+
 		return mesh;
 		return mesh;
-		
+
 	},
 	},
 
 
 	addPanoramaCube: function( scene, size, images ) {
 	addPanoramaCube: function( scene, size, images ) {
-	
-		var materials = [];
+
+		var materials = [], mesh;
 		materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[0] ) } ) );
 		materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[0] ) } ) );
 		materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[1] ) } ) );
 		materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[1] ) } ) );
 		materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[2] ) } ) );
 		materials.push( new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[2] ) } ) );
@@ -46,14 +46,14 @@ var SceneUtils = {
 
 
 		mesh = new THREE.Mesh( new Cube( size, size, size, 1, 1, materials, true ), new THREE.MeshFaceMaterial() );
 		mesh = new THREE.Mesh( new Cube( size, size, size, 1, 1, materials, true ), new THREE.MeshFaceMaterial() );
 		scene.addObject( mesh );
 		scene.addObject( mesh );
-		
+
 		return mesh;
 		return mesh;
 
 
 	},
 	},
 
 
 	addPanoramaCubePlanes: function ( scene, size, images ) {
 	addPanoramaCubePlanes: function ( scene, size, images ) {
 
 
-		
+
 		var hsize = size/2, plane = new Plane( size, size ), pi2 = Math.PI/2, pi = Math.PI;
 		var hsize = size/2, plane = new Plane( size, size ), pi2 = Math.PI/2, pi = Math.PI;
 
 
 		SceneUtils.addMesh( scene, plane, 1,      0,     0,  -hsize,  0,      0,  0, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[5] ) } ) );
 		SceneUtils.addMesh( scene, plane, 1,      0,     0,  -hsize,  0,      0,  0, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[5] ) } ) );
@@ -61,7 +61,7 @@ var SceneUtils = {
 		SceneUtils.addMesh( scene, plane, 1,  hsize,     0,       0,  0,   -pi2,  0, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[1] ) } ) );
 		SceneUtils.addMesh( scene, plane, 1,  hsize,     0,       0,  0,   -pi2,  0, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[1] ) } ) );
 		SceneUtils.addMesh( scene, plane, 1,     0,  hsize,       0,  pi2,    0, pi, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[2] ) } ) );
 		SceneUtils.addMesh( scene, plane, 1,     0,  hsize,       0,  pi2,    0, pi, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[2] ) } ) );
 		SceneUtils.addMesh( scene, plane, 1,     0, -hsize,       0, -pi2,    0, pi, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[3] ) } ) );
 		SceneUtils.addMesh( scene, plane, 1,     0, -hsize,       0, -pi2,    0, pi, new THREE.MeshBasicMaterial( { map: new THREE.Texture( images[3] ) } ) );
-		
+
 	}
 	}
-	
-}
+
+};

+ 3 - 3
src/extras/primitives/Cube.js

@@ -64,7 +64,7 @@ var Cube = function ( width, height, depth, segments_width, segments_height, mat
 
 
 	function buildPlane( u, v, udir, vdir, width, height, depth, material ) {
 	function buildPlane( u, v, udir, vdir, width, height, depth, material ) {
 
 
-		var w,
+		var w, ix, iy,
 		gridX = segments_width || 1,
 		gridX = segments_width || 1,
 		gridY = segments_height || 1,
 		gridY = segments_height || 1,
 		gridX1 = gridX + 1,
 		gridX1 = gridX + 1,
@@ -160,7 +160,7 @@ var Cube = function ( width, height, depth, segments_width, segments_height, mat
 
 
 		}
 		}
 
 
-		for ( var i = 0, l = scope.faces.length; i < l; i ++ ) {
+		for ( i = 0, il = scope.faces.length; i < il; i ++ ) {
 
 
 			var face = scope.faces[ i ];
 			var face = scope.faces[ i ];
 
 
@@ -179,7 +179,7 @@ var Cube = function ( width, height, depth, segments_width, segments_height, mat
 	this.computeFaceNormals();
 	this.computeFaceNormals();
 	this.sortFacesByMaterial();
 	this.sortFacesByMaterial();
 
 
-}
+};
 
 
 Cube.prototype = new THREE.Geometry();
 Cube.prototype = new THREE.Geometry();
 Cube.prototype.constructor = Cube;
 Cube.prototype.constructor = Cube;

+ 1 - 1
src/extras/primitives/Cylinder.js

@@ -76,7 +76,7 @@ var Cylinder = function ( numSegs, topRad, botRad, height, topOffset, botOffset
 
 
 	}
 	}
 
 
-}
+};
 
 
 Cylinder.prototype = new THREE.Geometry();
 Cylinder.prototype = new THREE.Geometry();
 Cylinder.prototype.constructor = Cylinder;
 Cylinder.prototype.constructor = Cylinder;

+ 1 - 1
src/extras/primitives/Plane.js

@@ -56,7 +56,7 @@ var Plane = function ( width, height, segments_width, segments_height ) {
 	this.computeFaceNormals();
 	this.computeFaceNormals();
 	this.sortFacesByMaterial();
 	this.sortFacesByMaterial();
 
 
-}
+};
 
 
 Plane.prototype = new THREE.Geometry();
 Plane.prototype = new THREE.Geometry();
 Plane.prototype.constructor = Plane;
 Plane.prototype.constructor = Plane;

+ 1 - 1
src/extras/primitives/Sphere.js

@@ -110,7 +110,7 @@ var Sphere = function ( radius, segments_width, segments_height ) {
 
 
 	this.boundingSphere = { radius: radius };
 	this.boundingSphere = { radius: radius };
 
 
-}
+};
 
 
 Sphere.prototype = new THREE.Geometry();
 Sphere.prototype = new THREE.Geometry();
 Sphere.prototype.constructor = Sphere;
 Sphere.prototype.constructor = Sphere;

+ 18 - 18
src/materials/Uniforms.js

@@ -1,35 +1,35 @@
 var Uniforms = {
 var Uniforms = {
-	
+
 	clone: function( uniforms_src ) {
 	clone: function( uniforms_src ) {
-		
-		var u, p, parameter, uniforms_dst = {};
-		
+
+		var u, p, parameter, parameter_src, uniforms_dst = {};
+
 		for ( u in uniforms_src ) {
 		for ( u in uniforms_src ) {
-			
+
 			uniforms_dst[ u ] = {};
 			uniforms_dst[ u ] = {};
-			
+
 			for ( p in uniforms_src[ u ] ) {
 			for ( p in uniforms_src[ u ] ) {
-				
+
 				parameter_src = uniforms_src[ u ][ p ];
 				parameter_src = uniforms_src[ u ][ p ];
-				
+
 				if ( parameter_src instanceof THREE.Color ||
 				if ( parameter_src instanceof THREE.Color ||
 					 parameter_src instanceof THREE.Vector3 ||
 					 parameter_src instanceof THREE.Vector3 ||
 					 parameter_src instanceof THREE.Texture ) {
 					 parameter_src instanceof THREE.Texture ) {
-				
+
 					uniforms_dst[ u ][ p ] = parameter_src.clone();
 					uniforms_dst[ u ][ p ] = parameter_src.clone();
-					
+
 				} else {
 				} else {
-					
+
 					uniforms_dst[ u ][ p ] = parameter_src;
 					uniforms_dst[ u ][ p ] = parameter_src;
-					
+
 				}
 				}
-				
+
 			}
 			}
-			
+
 		}
 		}
-		
+
 		return uniforms_dst;
 		return uniforms_dst;
-		
+
 	}
 	}
-	
-}
+
+};

+ 3 - 3
src/materials/mappings/CubeReflectionMapping.js

@@ -1,9 +1,9 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
  */
  */
- 
+
 THREE.CubeReflectionMapping = function () {
 THREE.CubeReflectionMapping = function () {
 
 
-	
 
 
-}
+
+};

+ 3 - 3
src/materials/mappings/CubeRefractionMapping.js

@@ -1,9 +1,9 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
  */
  */
- 
+
 THREE.CubeRefractionMapping = function () {
 THREE.CubeRefractionMapping = function () {
 
 
-	
 
 
-}
+
+};

+ 3 - 3
src/materials/mappings/LatitudeReflectionMapping.js

@@ -1,9 +1,9 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
  */
  */
- 
+
 THREE.LatitudeReflectionMapping = function () {
 THREE.LatitudeReflectionMapping = function () {
 
 
-	
 
 
-}
+
+};

+ 3 - 3
src/materials/mappings/LatitudeRefractionMapping.js

@@ -1,9 +1,9 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
  */
  */
- 
+
 THREE.LatitudeRefractionMapping = function () {
 THREE.LatitudeRefractionMapping = function () {
 
 
-	
 
 
-}
+
+};

+ 3 - 3
src/materials/mappings/SphericalReflectionMapping.js

@@ -1,9 +1,9 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
  */
  */
- 
+
 THREE.SphericalReflectionMapping = function () {
 THREE.SphericalReflectionMapping = function () {
 
 
-	
 
 
-}
+
+};

+ 3 - 3
src/materials/mappings/SphericalRefractionMapping.js

@@ -1,9 +1,9 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
  */
  */
- 
+
 THREE.SphericalRefractionMapping = function () {
 THREE.SphericalRefractionMapping = function () {
 
 
-	
 
 
-}
+
+};

+ 3 - 3
src/materials/mappings/UVMapping.js

@@ -1,9 +1,9 @@
 /**
 /**
  * @author mr.doob / http://mrdoob.com/
  * @author mr.doob / http://mrdoob.com/
  */
  */
- 
+
 THREE.UVMapping = function () {
 THREE.UVMapping = function () {
 
 
-	
 
 
-}
+
+};

+ 45 - 45
src/renderers/WebGLRenderer.js

@@ -38,12 +38,12 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 	maxLightCount = allocateLights( parameters.scene, 4 ),
 	maxLightCount = allocateLights( parameters.scene, 4 ),
 	fog = parameters.scene ? parameters.scene.fog : null,
 	fog = parameters.scene ? parameters.scene.fog : null,
-	
+
 	antialias = parameters.antialias != undefined ? parameters.antialias : true,
 	antialias = parameters.antialias != undefined ? parameters.antialias : true,
-	
+
 	clearColor = parameters.clearColor ? new THREE.Color( parameters.clearColor ) : new THREE.Color( 0x000000 ),
 	clearColor = parameters.clearColor ? new THREE.Color( parameters.clearColor ) : new THREE.Color( 0x000000 ),
 	clearAlpha = parameters.clearAlpha ? parameters.clearAlpha : 0;
 	clearAlpha = parameters.clearAlpha ? parameters.clearAlpha : 0;
-	
+
 	this.domElement = _canvas;
 	this.domElement = _canvas;
 	this.autoClear = true;
 	this.autoClear = true;
 
 
@@ -63,12 +63,12 @@ THREE.WebGLRenderer = function ( parameters ) {
 	};
 	};
 
 
 	this.setClearColor = function( hex, alpha ) {
 	this.setClearColor = function( hex, alpha ) {
-		
+
 		var color = new THREE.Color( hex );
 		var color = new THREE.Color( hex );
 		_gl.clearColor( color.r, color.g, color.b, alpha );
 		_gl.clearColor( color.r, color.g, color.b, alpha );
-		
+
 	};
 	};
-	
+
 	this.clear = function () {
 	this.clear = function () {
 
 
 		_gl.clear( _gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT );
 		_gl.clear( _gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT );
@@ -122,7 +122,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 	this.createBuffers = function ( object, g ) {
 	this.createBuffers = function ( object, g ) {
 
 
-		var f, fl, fi, face, vertexNormals, normal, uv, v1, v2, v3, v4, t1, t2, t3, t4, m, ml, i,
+		var f, fl, fi, face, vertexNormals, faceNormal, normal, uv, v1, v2, v3, v4, t1, t2, t3, t4, m, ml, i,
 
 
 		faceArray = [],
 		faceArray = [],
 		lineArray = [],
 		lineArray = [],
@@ -321,7 +321,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		geometryChunk.__webGLLineCount = lineArray.length;
 		geometryChunk.__webGLLineCount = lineArray.length;
 
 
 	};
 	};
-	
+
 	function setMaterialShaders( material, shaders ) {
 	function setMaterialShaders( material, shaders ) {
 
 
 		material.fragment_shader = shaders.fragment_shader;
 		material.fragment_shader = shaders.fragment_shader;
@@ -340,30 +340,30 @@ THREE.WebGLRenderer = function ( parameters ) {
 		
 		
 		material.uniforms.opacity.value = material.opacity;
 		material.uniforms.opacity.value = material.opacity;
 		material.uniforms.map.texture = material.map;
 		material.uniforms.map.texture = material.map;
-		
+
 		material.uniforms.env_map.texture = material.env_map;
 		material.uniforms.env_map.texture = material.env_map;
 		material.uniforms.reflectivity.value = material.reflectivity;
 		material.uniforms.reflectivity.value = material.reflectivity;
 		material.uniforms.refraction_ratio.value = material.refraction_ratio;
 		material.uniforms.refraction_ratio.value = material.refraction_ratio;
 		material.uniforms.combine.value = material.combine;
 		material.uniforms.combine.value = material.combine;
 		material.uniforms.useRefract.value = material.env_map && material.env_map.mapping instanceof THREE.CubeRefractionMapping;
 		material.uniforms.useRefract.value = material.env_map && material.env_map.mapping instanceof THREE.CubeRefractionMapping;
-		
+
 		if ( fog ) {
 		if ( fog ) {
 
 
 			material.uniforms.fogColor.value.setHex( fog.color.hex );
 			material.uniforms.fogColor.value.setHex( fog.color.hex );
-			
+
 			if ( fog instanceof THREE.Fog ) {
 			if ( fog instanceof THREE.Fog ) {
-				
+
 				material.uniforms.fogNear.value = fog.near;
 				material.uniforms.fogNear.value = fog.near;
 				material.uniforms.fogFar.value = fog.far;
 				material.uniforms.fogFar.value = fog.far;
-				
+
 			} else if ( fog instanceof THREE.FogExp2 ) {
 			} else if ( fog instanceof THREE.FogExp2 ) {
-				
+
 				material.uniforms.fogDensity.value = fog.density;
 				material.uniforms.fogDensity.value = fog.density;
-				
+
 			}
 			}
 
 
 		}
 		}
-		
+
 	};
 	};
 	
 	
 	function refreshLights( material, lights ) {
 	function refreshLights( material, lights ) {
@@ -375,8 +375,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		material.uniforms.pointLightColor.value = lights.point.colors;
 		material.uniforms.pointLightColor.value = lights.point.colors;
 		material.uniforms.pointLightPosition.value = lights.point.positions;
 		material.uniforms.pointLightPosition.value = lights.point.positions;
 		
 		
-	}
-	
+	};
 	
 	
 	this.renderBuffer = function ( camera, lights, fog, material, geometryChunk ) {
 	this.renderBuffer = function ( camera, lights, fog, material, geometryChunk ) {
 
 
@@ -409,9 +408,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 					setMaterialShaders( material, THREE.ShaderLib[ 'normal' ] );
 					setMaterialShaders( material, THREE.ShaderLib[ 'normal' ] );
 
 
 				} else if ( material instanceof THREE.MeshBasicMaterial ) {
 				} else if ( material instanceof THREE.MeshBasicMaterial ) {
-					
+
 					setMaterialShaders( material, THREE.ShaderLib[ 'basic' ] );
 					setMaterialShaders( material, THREE.ShaderLib[ 'basic' ] );
-					
+
 					refreshUniforms( material, fog );
 					refreshUniforms( material, fog );
 					
 					
 				} else if ( material instanceof THREE.MeshLambertMaterial ) {
 				} else if ( material instanceof THREE.MeshLambertMaterial ) {
@@ -492,9 +491,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 			 material instanceof THREE.MeshLambertMaterial ) {
 			 material instanceof THREE.MeshLambertMaterial ) {
 			
 			
 			refreshUniforms( material, fog );
 			refreshUniforms( material, fog );
-		
+
 		}
 		}
-		
+
 		if ( material instanceof THREE.MeshShaderMaterial ||
 		if ( material instanceof THREE.MeshShaderMaterial ||
 		     material instanceof THREE.MeshDepthMaterial ||
 		     material instanceof THREE.MeshDepthMaterial ||
 			 material instanceof THREE.MeshNormalMaterial ||
 			 material instanceof THREE.MeshNormalMaterial ||
@@ -540,16 +539,16 @@ THREE.WebGLRenderer = function ( parameters ) {
 			if ( fog ) {
 			if ( fog ) {
 
 
 				_gl.uniform3f( program.uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
 				_gl.uniform3f( program.uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
-				
+
 				if ( fog instanceof THREE.Fog ) {
 				if ( fog instanceof THREE.Fog ) {
-				
+
 					_gl.uniform1f( program.uniforms.fogNear, fog.near );
 					_gl.uniform1f( program.uniforms.fogNear, fog.near );
 					_gl.uniform1f( program.uniforms.fogFar, fog.far );
 					_gl.uniform1f( program.uniforms.fogFar, fog.far );
-					
+
 				} else if ( fog instanceof THREE.FogExp2 ) {
 				} else if ( fog instanceof THREE.FogExp2 ) {
-					
+
 					_gl.uniform1f( program.uniforms.fogDensity, fog.density );
 					_gl.uniform1f( program.uniforms.fogDensity, fog.density );
-					
+
 				}
 				}
 
 
 			}
 			}
@@ -1154,7 +1153,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 				"}",
 				"}",
 
 
 				THREE.Snippets[ "fog_fragment" ],
 				THREE.Snippets[ "fog_fragment" ],
-				
+
 			"}" ];
 			"}" ];
 
 
 		return chunks.join("\n");
 		return chunks.join("\n");
@@ -1234,7 +1233,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 			parameters.fog ? "#define USE_FOG" : "",
 			parameters.fog ? "#define USE_FOG" : "",
 			parameters.fog instanceof THREE.FogExp2 ? "#define FOG_EXP2" : "",
 			parameters.fog instanceof THREE.FogExp2 ? "#define FOG_EXP2" : "",
-		
+
 			parameters.map ? "#define USE_MAP" : "",
 			parameters.map ? "#define USE_MAP" : "",
 			parameters.env_map ? "#define USE_ENVMAP" : "",
 			parameters.env_map ? "#define USE_ENVMAP" : "",
 
 
@@ -1548,7 +1547,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 	function bufferNeedsSmoothNormals( geometryChunk, object ) {
 	function bufferNeedsSmoothNormals( geometryChunk, object ) {
 
 
-		var m, ml, i, l, needsSmoothNormals = false;
+		var m, ml, i, l, meshMaterial, needsSmoothNormals = false;
 
 
 		for ( m = 0, ml = object.materials.length; m < ml; m++ ) {
 		for ( m = 0, ml = object.materials.length; m < ml; m++ ) {
 
 
@@ -1590,7 +1589,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		if ( scene ) {
 		if ( scene ) {
 
 
-			var l, ll, light, dirLights = pointLights = maxDirLights = maxPointLights = 0;
+			var l, ll, light, dirLights, pointLights, maxDirLights, maxPointLights;
+			dirLights = pointLights = maxDirLights = maxPointLights = 0;
 
 
 			for ( l = 0, ll = scene.lights.length; l < ll; l++ ) {
 			for ( l = 0, ll = scene.lights.length; l < ll; l++ ) {
 
 
@@ -1660,24 +1660,24 @@ THREE.Snippets = {
 	fog_pars_fragment: [
 	fog_pars_fragment: [
 
 
 	"#ifdef USE_FOG",
 	"#ifdef USE_FOG",
-	
+
 		"uniform vec3 fogColor;",
 		"uniform vec3 fogColor;",
-		
+
 		"#ifdef FOG_EXP2",
 		"#ifdef FOG_EXP2",
 			"uniform float fogDensity;",
 			"uniform float fogDensity;",
 		"#else",
 		"#else",
 			"uniform float fogNear;",
 			"uniform float fogNear;",
 			"uniform float fogFar;",
 			"uniform float fogFar;",
 		"#endif",
 		"#endif",
-		
+
 	"#endif"
 	"#endif"
-	
+
 	].join("\n"),
 	].join("\n"),
 
 
 	fog_fragment: [
 	fog_fragment: [
 
 
 	"#ifdef USE_FOG",
 	"#ifdef USE_FOG",
-	
+
 		"float depth = gl_FragCoord.z / gl_FragCoord.w;",
 		"float depth = gl_FragCoord.z / gl_FragCoord.w;",
 
 
 		"#ifdef FOG_EXP2",
 		"#ifdef FOG_EXP2",
@@ -1687,7 +1687,7 @@ THREE.Snippets = {
 		"#else",
 		"#else",
 			"float fogFactor = smoothstep( fogNear, fogFar, depth );",
 			"float fogFactor = smoothstep( fogNear, fogFar, depth );",
 		"#endif",
 		"#endif",
-		
+
 		"gl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );",
 		"gl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );",
 
 
 	"#endif"
 	"#endif"
@@ -1868,7 +1868,7 @@ THREE.Snippets = {
 	"}"
 	"}"
 
 
 	].join("\n")
 	].join("\n")
-	
+
 };
 };
 
 
 THREE.ShaderLib = {
 THREE.ShaderLib = {
@@ -1937,9 +1937,9 @@ THREE.ShaderLib = {
 		].join("\n")
 		].join("\n")
 
 
 	},
 	},
-	
+
 	'basic': {
 	'basic': {
-		
+
 		uniforms: { "color"   : { type: "c", value: new THREE.Color( 0xeeeeee ) },
 		uniforms: { "color"   : { type: "c", value: new THREE.Color( 0xeeeeee ) },
 					"opacity" : { type: "f", value: 1 },
 					"opacity" : { type: "f", value: 1 },
 					"map"     : { type: "t", value: 0, texture: null },
 					"map"     : { type: "t", value: 0, texture: null },
@@ -1953,9 +1953,9 @@ THREE.ShaderLib = {
 					"fogFar"	: { type: "f", value: 2000 },
 					"fogFar"	: { type: "f", value: 2000 },
 					"fogColor"	: { type: "c", value: new THREE.Color( 0xffffff ) }
 					"fogColor"	: { type: "c", value: new THREE.Color( 0xffffff ) }
 				},
 				},
-		
+
 		fragment_shader: [
 		fragment_shader: [
-			
+
 			"uniform vec3 color;",
 			"uniform vec3 color;",
 			"uniform float opacity;",
 			"uniform float opacity;",
 			
 			
@@ -1964,7 +1964,7 @@ THREE.ShaderLib = {
 			THREE.Snippets[ "fog_pars_fragment" ],
 			THREE.Snippets[ "fog_pars_fragment" ],
 				
 				
 			"void main() {",
 			"void main() {",
-					
+
 				"vec4 mColor = vec4( color, opacity );",
 				"vec4 mColor = vec4( color, opacity );",
 				"vec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );",
 				"vec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );",
 				"vec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );",
 				"vec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );",
@@ -2048,11 +2048,11 @@ THREE.ShaderLib = {
 				
 				
 				THREE.Snippets[ "envmap_fragment" ],
 				THREE.Snippets[ "envmap_fragment" ],
 				THREE.Snippets[ "fog_fragment" ],
 				THREE.Snippets[ "fog_fragment" ],
-				
+
 			"}"
 			"}"
 
 
 		].join("\n"),
 		].join("\n"),
-		
+
 		vertex_shader: [
 		vertex_shader: [
 		
 		
 			"varying vec3 vLightWeighting;",
 			"varying vec3 vLightWeighting;",

+ 10 - 10
src/renderers/WebGLRenderer2.js

@@ -14,6 +14,7 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 	_canvas = document.createElement( 'canvas' ),
 	_canvas = document.createElement( 'canvas' ),
 	_gl, _currentProgram,
 	_gl, _currentProgram,
 	_modelViewMatrix = new THREE.Matrix4(),
 	_modelViewMatrix = new THREE.Matrix4(),
+	_normalMatrix = new THREE.Matrix4(),
 	_viewMatrixArray = new Float32Array( 16 ),
 	_viewMatrixArray = new Float32Array( 16 ),
 	_modelViewMatrixArray = new Float32Array( 16 ),
 	_modelViewMatrixArray = new Float32Array( 16 ),
 	_projectionMatrixArray = new Float32Array( 16 ),
 	_projectionMatrixArray = new Float32Array( 16 ),
@@ -100,7 +101,7 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 
 
 		function renderObject( object ) {
 		function renderObject( object ) {
 
 
-			var geometry, material, m, nl,
+			var geometry, material, m, ml,
 			program, uniforms, attributes;
 			program, uniforms, attributes;
 
 
 			object.autoUpdateMatrix && object.updateMatrix();
 			object.autoUpdateMatrix && object.updateMatrix();
@@ -268,11 +269,11 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 
 
 			} else if ( object instanceof THREE.Line ) {
 			} else if ( object instanceof THREE.Line ) {
 
 
-				
+
 
 
 			} else if ( object instanceof THREE.Particle ) {
 			} else if ( object instanceof THREE.Particle ) {
 
 
-				
+
 
 
 			}
 			}
 
 
@@ -283,10 +284,9 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 		function buildBuffers( geometry ) {
 		function buildBuffers( geometry ) {
 
 
 			var itemCount = 0, vertexIndex, group,
 			var itemCount = 0, vertexIndex, group,
-			f, fl, face, v1, v2, v3, vertexNormals, normal, uv,
+			f, fl, face, v1, v2, v3, v4, vertexNormals, faceNormal, normal, uv,
 			vertexGroups = [], faceGroups = [], lineGroups = [], normalGroups = [], uvGroups = [],
 			vertexGroups = [], faceGroups = [], lineGroups = [], normalGroups = [], uvGroups = [],
-			vertices, faces, lines, normals, uvs,
-			buffers = {};
+			vertices, faces, lines, normals, uvs;
 
 
 			for ( f = 0, fl = geometry.faces.length; f < fl; f++ ) {
 			for ( f = 0, fl = geometry.faces.length; f < fl; f++ ) {
 
 
@@ -544,9 +544,9 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 
 
 				identifiers.push( 'mColor', 'mOpacity' );
 				identifiers.push( 'mColor', 'mOpacity' );
 
 
-				material.map ? identifiers.push( 'tMap' ) : null;
-				material.env_map ? identifiers.push( 'tSpherical' ) : null;
-				material.fog ? identifiers.push( 'fog', 'fogColor', 'fogNear', 'fogFar' ) : null;
+				if ( material.map ) identifiers.push( 'tMap' );
+				if ( material.env_map ) identifiers.push( 'tSpherical' );
+				if ( material.fog ) identifiers.push( 'fog', 'fogColor', 'fogNear', 'fogFar' );
 
 
 
 
 			} else if ( material instanceof THREE.MeshNormalMaterial ) {
 			} else if ( material instanceof THREE.MeshNormalMaterial ) {
@@ -622,7 +622,7 @@ THREE.WebGLRenderer2 = function ( antialias ) {
 
 
 		function compileProgram( vertex_shader, fragment_shader ) {
 		function compileProgram( vertex_shader, fragment_shader ) {
 
 
-			var program = _gl.createProgram(), shader
+			var program = _gl.createProgram(), shader, prefix_vertex, prefix_fragment;
 
 
 			prefix_vertex = [
 			prefix_vertex = [
 				maxVertexTextures() > 0 ? "#define VERTEX_TEXTURES" : "",
 				maxVertexTextures() > 0 ? "#define VERTEX_TEXTURES" : "",

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