Browse Source

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

Conflicts:
	examples/js/loaders/VTKLoader.js
Valentin Demeusy 9 years ago
parent
commit
627f7ee4a6

File diff suppressed because it is too large
+ 312 - 308
build/three.js


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


+ 0 - 4
examples/js/Ocean.js

@@ -12,10 +12,6 @@
 
 
 	this.scene = new THREE.Scene();
 	this.scene = new THREE.Scene();
 
 
-	// Enable necessary extensions
-	this.renderer.context.getExtension( 'OES_texture_float' );
-	this.renderer.context.getExtension( 'OES_texture_float_linear' );
-
 	// Assign optional parameters as variables and object properties
 	// Assign optional parameters as variables and object properties
 	function optionalParameter( value, defaultValue ) {
 	function optionalParameter( value, defaultValue ) {
 
 

+ 25 - 19
examples/js/exporters/STLBinaryExporter.js

@@ -17,11 +17,29 @@ THREE.STLBinaryExporter.prototype = {
 
 
 		return function parse( scene ) {
 		return function parse( scene ) {
 
 
+			// We collect objects first, as we may need to convert from BufferGeometry to Geometry
+			var objects = [];
 			var triangles = 0;
 			var triangles = 0;
 			scene.traverse( function ( object ) {
 			scene.traverse( function ( object ) {
 
 
 				if ( ! ( object instanceof THREE.Mesh ) ) return;
 				if ( ! ( object instanceof THREE.Mesh ) ) return;
-				triangles += object.geometry.faces.length;
+
+				var geometry = object.geometry;
+				if ( geometry instanceof THREE.BufferGeometry ) {
+
+					geometry = new THREE.Geometry().fromBufferGeometry( geometry );
+
+				}
+
+				if ( ! ( geometry instanceof THREE.Geometry ) ) return;
+				triangles += geometry.faces.length;
+
+				objects.push( {
+
+					geometry: geometry,
+					matrix: object.matrixWorld
+
+				} );
 
 
 			} );
 			} );
 
 
@@ -31,25 +49,13 @@ THREE.STLBinaryExporter.prototype = {
 			var output = new DataView( arrayBuffer );
 			var output = new DataView( arrayBuffer );
 			output.setUint32( offset, triangles, true ); offset += 4;
 			output.setUint32( offset, triangles, true ); offset += 4;
 
 
-			scene.traverse( function ( object ) {
-
-				if ( ! ( object instanceof THREE.Mesh ) ) return;
-
-				var geometry = object.geometry;
-				if ( geometry instanceof THREE.BufferGeometry ) {
-                            
-					geometry = new THREE.Geometry().fromBufferGeometry( geometry );
-                            
-				}
-
-				if ( ! ( geometry instanceof THREE.Geometry ) ) return;
-
-				var matrixWorld = object.matrixWorld;
+			// Traversing our collected objects
+			objects.forEach( function ( object ) {
 
 
-				var vertices = geometry.vertices;
-				var faces = geometry.faces;
+				var vertices = object.geometry.vertices;
+				var faces = object.geometry.faces;
 
 
-				normalMatrixWorld.getNormalMatrix( matrixWorld );
+				normalMatrixWorld.getNormalMatrix( object.matrix );
 
 
 				for ( var i = 0, l = faces.length; i < l; i ++ ) {
 				for ( var i = 0, l = faces.length; i < l; i ++ ) {
 
 
@@ -65,7 +71,7 @@ THREE.STLBinaryExporter.prototype = {
 
 
 					for ( var j = 0; j < 3; j ++ ) {
 					for ( var j = 0; j < 3; j ++ ) {
 
 
-						vector.copy( vertices[ indices[ j ] ] ).applyMatrix4( matrixWorld );
+						vector.copy( vertices[ indices[ j ] ] ).applyMatrix4( object.matrix );
 
 
 						output.setFloat32( offset, vector.x, true ); offset += 4; // vertices
 						output.setFloat32( offset, vector.x, true ); offset += 4; // vertices
 						output.setFloat32( offset, vector.y, true ); offset += 4;
 						output.setFloat32( offset, vector.y, true ); offset += 4;

+ 99 - 6
examples/js/loaders/ColladaLoader2.js

@@ -420,7 +420,87 @@ THREE.ColladaLoader.prototype = {
 						break;
 						break;
 
 
 					case 'texture':
 					case 'texture':
-						data[ child.nodeName ] = child.getAttribute( 'texture' );
+						data[ child.nodeName ] = { id: child.getAttribute( 'texture' ), extra: parseEffectParameterTexture( child ) };
+						break;
+
+				}
+
+			}
+
+			return data;
+
+		}
+
+		function parseEffectParameterTexture( xml ) {
+
+			var data = {};
+
+			for ( var i = 0, l = xml.childNodes.length; i < l; i ++ ) {
+
+				var child = xml.childNodes[ i ];
+
+				if ( child.nodeType !== 1 ) continue;
+
+				switch ( child.nodeName ) {
+
+					case 'extra':
+						data = parseEffectParameterTextureExtra( child );
+						break;
+
+				}
+
+			}
+
+			return data;
+
+		}
+
+		function parseEffectParameterTextureExtra( xml ) {
+
+			var data = {};
+
+			for ( var i = 0, l = xml.childNodes.length; i < l; i ++ ) {
+
+				var child = xml.childNodes[ i ];
+
+				if ( child.nodeType !== 1 ) continue;
+
+				switch ( child.nodeName ) {
+
+					case 'technique':
+						data[ child.nodeName ] = parseEffectParameterTextureExtraTechnique( child );
+						break;
+
+				}
+
+			}
+
+			return data;
+
+		}
+
+		function parseEffectParameterTextureExtraTechnique( xml ) {
+
+			var data = {};
+
+			for ( var i = 0, l = xml.childNodes.length; i < l; i ++ ) {
+
+				var child = xml.childNodes[ i ];
+
+				if ( child.nodeType !== 1 ) continue;
+
+				switch ( child.nodeName ) {
+
+					case 'repeatU':
+					case 'repeatV':
+					case 'offsetU':
+					case 'offsetV':
+						data[ child.nodeName ] = parseFloat( child.textContent );
+						break;
+
+					case 'wrapU':
+					case 'wrapV':
+						data[ child.nodeName ] = parseInt( child.textContent );
 						break;
 						break;
 
 
 				}
 				}
@@ -497,24 +577,37 @@ THREE.ColladaLoader.prototype = {
 
 
 			material.name = data.name;
 			material.name = data.name;
 
 
-			function getTexture( sid ) {
+			function getTexture( textureObject ) {
 
 
-				var sampler = effect.profile.samplers[ sid ];
+				var sampler = effect.profile.samplers[ textureObject.id ];
 
 
 				if ( sampler !== undefined ) {
 				if ( sampler !== undefined ) {
 
 
 					var surface = effect.profile.surfaces[ sampler.source ];
 					var surface = effect.profile.surfaces[ sampler.source ];
 
 
 					var texture = new THREE.Texture( getImage( surface.init_from ) );
 					var texture = new THREE.Texture( getImage( surface.init_from ) );
-					texture.wrapS = THREE.RepeatWrapping;
-					texture.wrapT = THREE.RepeatWrapping;
+
+					var extra = textureObject.extra;
+
+					if ( extra !== undefined && extra.technique !== undefined ) {
+
+						var technique = extra.technique;
+
+						texture.wrapS = technique.wrapU ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
+						texture.wrapT = technique.wrapV ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
+
+						texture.offset.set( technique.offsetU, technique.offsetV );
+						texture.repeat.set( technique.repeatU, technique.repeatV );
+
+					}
+
 					texture.needsUpdate = true;
 					texture.needsUpdate = true;
 
 
 					return texture;
 					return texture;
 
 
 				}
 				}
 
 
-				console.error( 'ColladaLoder: Undefined sampler', sid );
+				console.error( 'ColladaLoder: Undefined sampler', textureObject.id );
 
 
 				return null;
 				return null;
 
 

+ 337 - 339
examples/js/loaders/VTKLoader.js

@@ -13,171 +13,148 @@ THREE.VTKLoader.prototype = {
 
 
 	constructor: THREE.VTKLoader,
 	constructor: THREE.VTKLoader,
 
 
-	load: function( url, onLoad, onProgress, onError ) {
+	load: function ( url, onLoad, onProgress, onError ) {
 
 
-		// Will we bump into trouble reading the whole file into memory?
 		var scope = this;
 		var scope = this;
+
 		var loader = new THREE.XHRLoader( scope.manager );
 		var loader = new THREE.XHRLoader( scope.manager );
 		loader.setResponseType( 'arraybuffer' );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function( text ) {
 		loader.load( url, function( text ) {
 
 
 			onLoad( scope.parse( text ) );
 			onLoad( scope.parse( text ) );
 
 
-		},
-
-					onProgress, onError );
+		}, onProgress, onError );
 
 
 	},
 	},
 
 
-	parse: function( data ) {
+	parse: function ( data ) {
 
 
-		//get the 5 first lines of the files to check if there is the key word binary
-		var meta = String.fromCharCode.apply( null, new Uint8Array( data, 0, 250 ) ).split( '\n' );
-		console.log( meta );
-		if ( meta[ 2 ].includes( 'ASCII' ) ) {
+		function parseASCII( data ) {
 
 
-			var stringFile = '';
-			var charArray = new Uint8Array( data );
-			for ( var i = 0; i < charArray.length; i ++ ) {
+			// connectivity of the triangles
+			var indices = [];
 
 
-				stringFile += String.fromCharCode( charArray[ i ] );
-
-			}
+			// triangles vertices
+			var positions = [];
 
 
-			return this.parseASCII( stringFile );
+			// red, green, blue colors in the range 0 to 1
+			var colors = [];
 
 
-		} else {
+			// normal vector, one per vertex
+			var normals = [];
 
 
-			return this.parseBinary( data );
+			var result;
 
 
-		}
+			// pattern for reading vertices, 3 floats or integers
+			var pat3Floats = /(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)/g;
 
 
-	},
+			// pattern for connectivity, an integer followed by any number of ints
+			// the first integer is the number of polygon nodes
+			var patConnectivity = /^(\d+)\s+([\s\d]*)/;
 
 
-	parseASCII: function( data ) {
+			// indicates start of vertex data section
+			var patPOINTS = /^POINTS /;
 
 
-		// connectivity of the triangles
-		var indices = [];
+			// indicates start of polygon connectivity section
+			var patPOLYGONS = /^POLYGONS /;
 
 
-		// triangles vertices
-		var positions = [];
+			// indicates start of triangle strips section
+			var patTRIANGLE_STRIPS = /^TRIANGLE_STRIPS /;
 
 
-		// red, green, blue colors in the range 0 to 1
-		var colors = [];
+			// POINT_DATA number_of_values
+			var patPOINT_DATA = /^POINT_DATA[ ]+(\d+)/;
 
 
-		// normal vector, one per vertex
-		var normals = [];
+			// CELL_DATA number_of_polys
+			var patCELL_DATA = /^CELL_DATA[ ]+(\d+)/;
 
 
-		var result;
+			// Start of color section
+			var patCOLOR_SCALARS = /^COLOR_SCALARS[ ]+(\w+)[ ]+3/;
 
 
-		// pattern for reading vertices, 3 floats or integers
-		var pat3Floats = /(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)/g;
+			// NORMALS Normals float
+			var patNORMALS = /^NORMALS[ ]+(\w+)[ ]+(\w+)/;
 
 
-		// pattern for connectivity, an integer followed by any number of ints
-		// the first integer is the number of polygon nodes
-		var patConnectivity = /^(\d+)\s+([\s\d]*)/;
+			var inPointsSection = false;
+			var inPolygonsSection = false;
+			var inTriangleStripSection = false;
+			var inPointDataSection = false;
+			var inCellDataSection = false;
+			var inColorSection = false;
+			var inNormalsSection = false;
 
 
-		// indicates start of vertex data section
-		var patPOINTS = /^POINTS /;
+			var lines = data.split( '\n' );
 
 
-		// indicates start of polygon connectivity section
-		var patPOLYGONS = /^POLYGONS /;
+			for ( var i in lines ) {
 
 
-		// indicates start of triangle strips section
-		var patTRIANGLE_STRIPS = /^TRIANGLE_STRIPS /;
+				var line = lines[ i ];
 
 
-		// POINT_DATA number_of_values
-		var patPOINT_DATA = /^POINT_DATA[ ]+(\d+)/;
+				if ( inPointsSection ) {
 
 
-		// CELL_DATA number_of_polys
-		var patCELL_DATA = /^CELL_DATA[ ]+(\d+)/;
-
-		// Start of color section
-		var patCOLOR_SCALARS = /^COLOR_SCALARS[ ]+(\w+)[ ]+3/;
-
-		// NORMALS Normals float
-		var patNORMALS = /^NORMALS[ ]+(\w+)[ ]+(\w+)/;
-
-		var inPointsSection = false;
-		var inPolygonsSection = false;
-		var inTriangleStripSection = false;
-		var inPointDataSection = false;
-		var inCellDataSection = false;
-		var inColorSection = false;
-		var inNormalsSection = false;
-
-		var lines = data.split( '\n' );
-
-		for ( var i in lines ) {
-
-			var line = lines[ i ];
-
-			if ( inPointsSection ) {
+					// get the vertices
+					while ( ( result = pat3Floats.exec( line ) ) !== null ) {
 
 
-				// get the vertices
-				while ( ( result = pat3Floats.exec( line ) ) !== null ) {
+						var x = parseFloat( result[ 1 ] );
+						var y = parseFloat( result[ 2 ] );
+						var z = parseFloat( result[ 3 ] );
+						positions.push( x, y, z );
 
 
-					var x = parseFloat( result[ 1 ] );
-					var y = parseFloat( result[ 2 ] );
-					var z = parseFloat( result[ 3 ] );
-					positions.push( x, y, z );
+					}
 
 
-				}
+				} else if ( inPolygonsSection ) {
 
 
-			} else if ( inPolygonsSection ) {
+					if ( ( result = patConnectivity.exec( line ) ) !== null ) {
 
 
-				if ( ( result = patConnectivity.exec( line ) ) !== null ) {
+						// numVertices i0 i1 i2 ...
+						var numVertices = parseInt( result[ 1 ] );
+						var inds = result[ 2 ].split( /\s+/ );
 
 
-					// numVertices i0 i1 i2 ...
-					var numVertices = parseInt( result[ 1 ] );
-					var inds = result[ 2 ].split( /\s+/ );
+						if ( numVertices >= 3 ) {
 
 
-					if ( numVertices >= 3 ) {
+							var i0 = parseInt( inds[ 0 ] );
+							var i1, i2;
+							var k = 1;
+							// split the polygon in numVertices - 2 triangles
+							for ( var j = 0; j < numVertices - 2; ++ j ) {
 
 
-						var i0 = parseInt( inds[ 0 ] );
-						var i1, i2;
-						var k = 1;
-						// split the polygon in numVertices - 2 triangles
-						for ( var j = 0; j < numVertices - 2; ++ j ) {
+								i1 = parseInt( inds[ k ] );
+								i2 = parseInt( inds[ k + 1 ] );
+								indices.push( i0, i1, i2 );
+								k ++;
 
 
-							i1 = parseInt( inds[ k ] );
-							i2 = parseInt( inds[ k + 1 ] );
-							indices.push( i0, i1, i2 );
-							k ++;
+							}
 
 
 						}
 						}
 
 
 					}
 					}
 
 
-				}
+				} else if ( inTriangleStripSection ) {
 
 
-			} else if ( inTriangleStripSection ) {
+					if ( ( result = patConnectivity.exec( line ) ) !== null ) {
 
 
-				if ( ( result = patConnectivity.exec( line ) ) !== null ) {
+						// numVertices i0 i1 i2 ...
+						var numVertices = parseInt( result[ 1 ] );
+						var inds = result[ 2 ].split( /\s+/ );
 
 
-					// numVertices i0 i1 i2 ...
-					var numVertices = parseInt( result[ 1 ] );
-					var inds = result[ 2 ].split( /\s+/ );
+						if ( numVertices >= 3 ) {
 
 
-					if ( numVertices >= 3 ) {
+							var i0, i1, i2;
+							// split the polygon in numVertices - 2 triangles
+							for ( var j = 0; j < numVertices - 2; j ++ ) {
 
 
-						var i0, i1, i2;
-						// split the polygon in numVertices - 2 triangles
-						for ( var j = 0; j < numVertices - 2; j ++ ) {
+								if ( j % 2 === 1 ) {
 
 
-							if ( j % 2 === 1 ) {
+									i0 = parseInt( inds[ j ] );
+									i1 = parseInt( inds[ j + 2 ] );
+									i2 = parseInt( inds[ j + 1 ] );
+									indices.push( i0, i1, i2 );
 
 
-								i0 = parseInt( inds[ j ] );
-								i1 = parseInt( inds[ j + 2 ] );
-								i2 = parseInt( inds[ j + 1 ] );
-								indices.push( i0, i1, i2 );
+								} else {
 
 
-							} else {
+									i0 = parseInt( inds[ j ] );
+									i1 = parseInt( inds[ j + 1 ] );
+									i2 = parseInt( inds[ j + 2 ] );
+									indices.push( i0, i1, i2 );
 
 
-								i0 = parseInt( inds[ j ] );
-								i1 = parseInt( inds[ j + 1 ] );
-								i2 = parseInt( inds[ j + 2 ] );
-								indices.push( i0, i1, i2 );
+								}
 
 
 							}
 							}
 
 
@@ -185,373 +162,394 @@ THREE.VTKLoader.prototype = {
 
 
 					}
 					}
 
 
-				}
+				} else if ( inPointDataSection || inCellDataSection ) {
 
 
-			} else if ( inPointDataSection || inCellDataSection ) {
+					if ( inColorSection ) {
 
 
-				if ( inColorSection ) {
+						// Get the colors
 
 
-					// Get the colors
+						while ( ( result = pat3Floats.exec( line ) ) !== null ) {
 
 
-					while ( ( result = pat3Floats.exec( line ) ) !== null ) {
+							var r = parseFloat( result[ 1 ] );
+							var g = parseFloat( result[ 2 ] );
+							var b = parseFloat( result[ 3 ] );
+							colors.push( r, g, b );
 
 
-						var r = parseFloat( result[ 1 ] );
-						var g = parseFloat( result[ 2 ] );
-						var b = parseFloat( result[ 3 ] );
-						colors.push( r, g, b );
+						}
 
 
-					}
+					} else if ( inNormalsSection ) {
 
 
-				} else if ( inNormalsSection ) {
+						// Get the normal vectors
 
 
-					// Get the normal vectors
+						while ( ( result = pat3Floats.exec( line ) ) !== null ) {
 
 
-					while ( ( result = pat3Floats.exec( line ) ) !== null ) {
+							var nx = parseFloat( result[ 1 ] );
+							var ny = parseFloat( result[ 2 ] );
+							var nz = parseFloat( result[ 3 ] );
+							normals.push( nx, ny, nz );
 
 
-						var nx = parseFloat( result[ 1 ] );
-						var ny = parseFloat( result[ 2 ] );
-						var nz = parseFloat( result[ 3 ] );
-						normals.push( nx, ny, nz );
+						}
 
 
 					}
 					}
 
 
 				}
 				}
 
 
-			}
+				if ( patPOLYGONS.exec( line ) !== null ) {
 
 
-			if ( patPOLYGONS.exec( line ) !== null ) {
+					inPolygonsSection = true;
+					inPointsSection = false;
+					inTriangleStripSection = false;
 
 
-				inPolygonsSection = true;
-				inPointsSection = false;
-				inTriangleStripSection = false;
+				} else if ( patPOINTS.exec( line ) !== null ) {
 
 
-			} else if ( patPOINTS.exec( line ) !== null ) {
+					inPolygonsSection = false;
+					inPointsSection = true;
+					inTriangleStripSection = false;
 
 
-				inPolygonsSection = false;
-				inPointsSection = true;
-				inTriangleStripSection = false;
+				} else if ( patTRIANGLE_STRIPS.exec( line ) !== null ) {
 
 
-			} else if ( patTRIANGLE_STRIPS.exec( line ) !== null ) {
+					inPolygonsSection = false;
+					inPointsSection = false;
+					inTriangleStripSection = true;
 
 
-				inPolygonsSection = false;
-				inPointsSection = false;
-				inTriangleStripSection = true;
+				} else if ( patPOINT_DATA.exec( line ) !== null ) {
 
 
-			} else if ( patPOINT_DATA.exec( line ) !== null ) {
+					inPointDataSection = true;
+					inPointsSection = false;
+					inPolygonsSection = false;
+					inTriangleStripSection = false;
 
 
-				inPointDataSection = true;
-				inPointsSection = false;
-				inPolygonsSection = false;
-				inTriangleStripSection = false;
+				} else if ( patCELL_DATA.exec( line ) !== null ) {
 
 
-			} else if ( patCELL_DATA.exec( line ) !== null ) {
+					inCellDataSection = true;
+					inPointsSection = false;
+					inPolygonsSection = false;
+					inTriangleStripSection = false;
 
 
-				inCellDataSection = true;
-				inPointsSection = false;
-				inPolygonsSection = false;
-				inTriangleStripSection = false;
+				} else if ( patCOLOR_SCALARS.exec( line ) !== null ) {
 
 
-			} else if ( patCOLOR_SCALARS.exec( line ) !== null ) {
+					inColorSection = true;
+					inNormalsSection = false;
+					inPointsSection = false;
+					inPolygonsSection = false;
+					inTriangleStripSection = false;
 
 
-				inColorSection = true;
-				inNormalsSection = false;
-				inPointsSection = false;
-				inPolygonsSection = false;
-				inTriangleStripSection = false;
+				} else if ( patNORMALS.exec( line ) !== null ) {
 
 
-			} else if ( patNORMALS.exec( line ) !== null ) {
+					inNormalsSection = true;
+					inColorSection = false;
+					inPointsSection = false;
+					inPolygonsSection = false;
+					inTriangleStripSection = false;
 
 
-				inNormalsSection = true;
-				inColorSection = false;
-				inPointsSection = false;
-				inPolygonsSection = false;
-				inTriangleStripSection = false;
+				}
 
 
 			}
 			}
 
 
-		}
+			var geometry;
+			var stagger = 'point';
 
 
-		var geometry;
-		var stagger = 'point';
+			if ( colors.length == indices.length ) {
 
 
-		if ( colors.length == indices.length ) {
+				stagger = 'cell';
 
 
-			stagger = 'cell';
+			}
 
 
-		}
+			if ( stagger == 'point' ) {
 
 
-		if ( stagger == 'point' ) {
+				// Nodal. Use BufferGeometry
+				geometry = new THREE.BufferGeometry();
+				geometry.setIndex( new THREE.BufferAttribute( new Uint32Array( indices ), 1 ) );
+				geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( positions ), 3 ) );
 
 
-			// Nodal. Use BufferGeometry
-			geometry = new THREE.BufferGeometry();
-			geometry.setIndex( new THREE.BufferAttribute( new Uint32Array( indices ), 1 ) );
-			geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( positions ), 3 ) );
+				if ( colors.length == positions.length ) {
 
 
-			if ( colors.length == positions.length ) {
+					geometry.addAttribute( 'color', new THREE.BufferAttribute( new Float32Array( colors ), 3 ) );
 
 
-				geometry.addAttribute( 'color', new THREE.BufferAttribute( new Float32Array( colors ), 3 ) );
+				}
 
 
-			}
+				if ( normals.length == positions.length ) {
 
 
-			if ( normals.length == positions.length ) {
+					geometry.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( normals ), 3 ) );
 
 
-				geometry.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( normals ), 3 ) );
+				}
 
 
-			}
+			} else {
 
 
-		} else {
+				// Cell centered colors. The only way to attach a solid color to each triangle
+				// is to use Geometry, which is less efficient than BufferGeometry
+				geometry = new THREE.Geometry();
 
 
-			// Cell centered colors. The only way to attach a solid color to each triangle
-			// is to use Geometry, which is less efficient than BufferGeometry
-			geometry = new THREE.Geometry();
+				var numTriangles = indices.length / 3;
+				var numPoints = positions.length / 3;
+				var va, vb, vc;
+				var face;
+				var ia, ib, ic;
+				var x, y, z;
+				var r, g, b;
 
 
-			var numTriangles = indices.length / 3;
-			var numPoints = positions.length / 3;
-			var va, vb, vc;
-			var face;
-			var ia, ib, ic;
-			var x, y, z;
-			var r, g, b;
+				for ( var j = 0; j < numPoints; ++ j ) {
 
 
-			for ( var j = 0; j < numPoints; ++ j ) {
+					x = positions[ 3 * j + 0 ];
+					y = positions[ 3 * j + 1 ];
+					z = positions[ 3 * j + 2 ];
+					geometry.vertices.push( new THREE.Vector3( x, y, z ) );
 
 
-				x = positions[ 3 * j + 0 ];
-				y = positions[ 3 * j + 1 ];
-				z = positions[ 3 * j + 2 ];
-				geometry.vertices.push( new THREE.Vector3( x, y, z ) );
+				}
 
 
-			}
+				for ( var i = 0; i < numTriangles; ++ i ) {
 
 
-			for ( var i = 0; i < numTriangles; ++ i ) {
+					ia = indices[ 3 * i + 0 ];
+					ib = indices[ 3 * i + 1 ];
+					ic = indices[ 3 * i + 2 ];
+					geometry.faces.push( new THREE.Face3( ia, ib, ic ) );
 
 
-				ia = indices[ 3 * i + 0 ];
-				ib = indices[ 3 * i + 1 ];
-				ic = indices[ 3 * i + 2 ];
-				geometry.faces.push( new THREE.Face3( ia, ib, ic ) );
+				}
 
 
-			}
+				if ( colors.length == numTriangles * 3 ) {
 
 
-			if ( colors.length == numTriangles * 3 ) {
+					for ( var i = 0; i < numTriangles; ++ i ) {
 
 
-				for ( var i = 0; i < numTriangles; ++ i ) {
+						face = geometry.faces[ i ];
+						r = colors[ 3 * i + 0 ];
+						g = colors[ 3 * i + 1 ];
+						b = colors[ 3 * i + 2 ];
+						face.color = new THREE.Color().setRGB( r, g, b );
 
 
-					face = geometry.faces[ i ];
-					r = colors[ 3 * i + 0 ];
-					g = colors[ 3 * i + 1 ];
-					b = colors[ 3 * i + 2 ];
-					face.color = new THREE.Color().setRGB( r, g, b );
+					}
 
 
 				}
 				}
 
 
 			}
 			}
 
 
+			return geometry;
+
 		}
 		}
 
 
-		return geometry;
+		function parseBinary( data ) {
 
 
-	},
+			var count, pointIndex, i, numberOfPoints, pt, s;
+			var buffer = new Uint8Array ( data );
+			var dataView = new DataView ( data );
 
 
-	parseBinary: function( data ) {
+			// Points and normals, by default, are empty
+			var points = [];
+			var normals = [];
+			var indices = [];
 
 
-		var count, pointIndex, i, numberOfPoints, pt, s;
-		var buffer = new Uint8Array ( data );
-		var dataView = new DataView ( data );
+			// Going to make a big array of strings
+			var vtk = [];
+			var index = 0;
 
 
-		// Points and normals, by default, are empty
-		var points = [];
-		var normals = [];
-		var indices = [];
+			function findString( buffer, start ) {
 
 
-		// Going to make a big array of strings
-		var vtk = [];
-		var index = 0;
+				var index = start;
+				var c = buffer[ index ];
+				var s = [];
+				while ( c != 10 ) {
 
 
-		var findString = function( buffer, start ) {
+					s.push ( String.fromCharCode ( c ) );
+					index ++;
+					c = buffer[ index ];
 
 
-			var index = start;
-			var c = buffer[ index ];
-			var s = [];
-			while ( c != 10 ) {
+				}
 
 
-				s.push ( String.fromCharCode ( c ) );
-				index ++;
-				c = buffer[ index ];
+				return { start: start,
+						end: index,
+						next: index + 1,
+						parsedString: s.join( '' ) };
 
 
 			}
 			}
 
 
-			return { start: start,
-					end: index,
-					next: index + 1,
-					parsedString: s.join( '' ) };
-
-		}
+			var state, line;
 
 
+			while ( true ) {
 
 
-		var state, line;
+				// Get a string
+				state = findString ( buffer, index );
+				line = state.parsedString;
 
 
-		while ( true ) {
+				if ( line.indexOf ( "POINTS" ) === 0 ) {
 
 
-			// Get a string
-			state = findString ( buffer, index );
-			line = state.parsedString;
-			if ( line.indexOf ( "POINTS" ) == 0 ) {
+					vtk.push ( line );
+					// Add the points
+					numberOfPoints = parseInt ( line.split( " " )[ 1 ], 10 );
 
 
-				vtk.push ( line );
-				// Add the points
-				numberOfPoints = parseInt ( line.split( " " )[ 1 ], 10 );
+					// Each point is 3 4-byte floats
+					count = numberOfPoints * 4 * 3;
 
 
-				// Each point is 3 4-byte floats
-				count = numberOfPoints * 4 * 3;
+					points = new Float32Array( numberOfPoints * 3 );
 
 
-				points = new Float32Array( numberOfPoints * 3 );
+					pointIndex = state.next;
+					for ( i = 0; i < numberOfPoints; i ++ ) {
 
 
-				pointIndex = state.next;
-				for ( i = 0; i < numberOfPoints; i ++ ) {
+						points[ 3 * i ] = dataView.getFloat32( pointIndex, false );
+						points[ 3 * i + 1 ] = dataView.getFloat32( pointIndex + 4, false );
+						points[ 3 * i + 2 ] = dataView.getFloat32( pointIndex + 8, false );
+						pointIndex = pointIndex + 12;
 
 
-					points[ 3 * i ] = dataView.getFloat32( pointIndex, false );
-					points[ 3 * i + 1 ] = dataView.getFloat32( pointIndex + 4, false );
-					points[ 3 * i + 2 ] = dataView.getFloat32( pointIndex + 8, false );
-					pointIndex = pointIndex + 12;
+					}
+					// increment our next pointer
+					state.next = state.next + count + 1;
 
 
-				}
-				// increment our next pointer
-				state.next = state.next + count + 1;
+				} else if ( line.indexOf ( "TRIANGLE_STRIPS" ) === 0 ) {
 
 
-			} else if ( line.indexOf ( "TRIANGLE_STRIPS" ) === 0 ) {
+					var numberOfStrips = parseInt ( line.split( " " )[ 1 ], 10 );
+					var size = parseInt ( line.split ( " " )[ 2 ], 10 );
+					// 4 byte integers
+					count = size * 4;
 
 
-				var numberOfStrips = parseInt ( line.split( " " )[ 1 ], 10 );
-				var size = parseInt ( line.split ( " " )[ 2 ], 10 );
-				// 4 byte integers
-				count = size * 4;
+					indices = new Uint32Array( 3 * size - 9 * numberOfStrips );
+					var indicesIndex = 0;
 
 
-				indices = new Uint32Array( 3 * size - 9 * numberOfStrips );
-				var indicesIndex = 0;
+					pointIndex = state.next;
+					for ( i = 0; i < numberOfStrips; i ++ ) {
 
 
-				pointIndex = state.next;
-				for ( i = 0; i < numberOfStrips; i ++ ) {
+						// For each strip, read the first value, then record that many more points
+						var indexCount = dataView.getInt32( pointIndex, false );
+						var strip = [];
+						pointIndex += 4;
+						for ( s = 0; s < indexCount; s ++ ) {
 
 
-					// For each strip, read the first value, then record that many more points
-					var indexCount = dataView.getInt32( pointIndex, false );
-					var strip = [];
-					pointIndex += 4;
-					for ( s = 0; s < indexCount; s ++ ) {
+							strip.push ( dataView.getInt32( pointIndex, false ) );
+							pointIndex += 4;
 
 
-						strip.push ( dataView.getInt32( pointIndex, false ) );
-						pointIndex += 4;
+						}
 
 
-					}
+						// retrieves the n-2 triangles from the triangle strip
+						for ( var j = 0; j < indexCount - 2; j ++ ) {
 
 
-					// retrieves the n-2 triangles from the triangle strip
-					for ( var j = 0; j < indexCount - 2; j ++ ) {
+							if ( j % 2 ) {
 
 
-						if ( j % 2 ) {
+								indices[ indicesIndex ++ ] = strip[ j ];
+								indices[ indicesIndex ++ ] = strip[ j + 2 ];
+								indices[ indicesIndex ++ ] = strip[ j + 1 ];
 
 
-							indices[ indicesIndex ++ ] = strip[ j ];
-							indices[ indicesIndex ++ ] = strip[ j + 2 ];
-							indices[ indicesIndex ++ ] = strip[ j + 1 ];
+							} else {
 
 
-						} else {
 
 
+								indices[ indicesIndex ++ ] = strip[ j ];
+								indices[ indicesIndex ++ ] = strip[ j + 1 ];
+								indices[ indicesIndex ++ ] = strip[ j + 2 ];
 
 
-							indices[ indicesIndex ++ ] = strip[ j ];
-							indices[ indicesIndex ++ ] = strip[ j + 1 ];
-							indices[ indicesIndex ++ ] = strip[ j + 2 ];
+							}
 
 
 						}
 						}
 
 
 					}
 					}
+					// increment our next pointer
+					state.next = state.next + count + 1;
 
 
-				}
-				// increment our next pointer
-				state.next = state.next + count + 1;
+				} else if ( line.indexOf ( "POLYGONS" ) === 0 ) {
 
 
-			} else if ( line.indexOf ( "POLYGONS" ) === 0 ) {
+					var numberOfStrips = parseInt ( line.split( " " )[ 1 ], 10 );
+					var size = parseInt ( line.split ( " " )[ 2 ], 10 );
+					// 4 byte integers
+					count = size * 4;
 
 
-				var numberOfStrips = parseInt ( line.split( " " )[ 1 ], 10 );
-				var size = parseInt ( line.split ( " " )[ 2 ], 10 );
-				// 4 byte integers
-				count = size * 4;
+					indices = new Uint32Array( 3 * size - 9 * numberOfStrips );
+					var indicesIndex = 0;
 
 
-				indices = new Uint32Array( 3 * size - 9 * numberOfStrips );
-				var indicesIndex = 0;
+					pointIndex = state.next;
+					for ( i = 0; i < numberOfStrips; i ++ ) {
 
 
-				pointIndex = state.next;
-				for ( i = 0; i < numberOfStrips; i ++ ) {
+						// For each strip, read the first value, then record that many more points
+						var indexCount = dataView.getInt32( pointIndex, false );
+						var strip = [];
+						pointIndex += 4;
+						for ( s = 0; s < indexCount; s ++ ) {
 
 
-					// For each strip, read the first value, then record that many more points
-					var indexCount = dataView.getInt32( pointIndex, false );
-					var strip = [];
-					pointIndex += 4;
-					for ( s = 0; s < indexCount; s ++ ) {
+							strip.push ( dataView.getInt32( pointIndex, false ) );
+							pointIndex += 4;
 
 
-						strip.push ( dataView.getInt32( pointIndex, false ) );
-						pointIndex += 4;
+						}
+						var i0 = strip[ 0 ];
+						// divide the polygon in n-2 triangle
+						for ( var j = 1; j < indexCount - 1; j ++ ) {
 
 
-					}
-					var i0 = strip[ 0 ]
-					// divide the polygon in n-2 triangle
-					for ( var j = 1; j < indexCount - 1; j ++ ) {
+							indices[ indicesIndex ++ ] = strip[ 0 ];
+							indices[ indicesIndex ++ ] = strip[ j ];
+							indices[ indicesIndex ++ ] = strip[ j + 1 ];
 
 
-						indices[ indicesIndex ++ ] = strip[ 0 ];
-						indices[ indicesIndex ++ ] = strip[ j ];
-						indices[ indicesIndex ++ ] = strip[ j + 1 ];
+						}
 
 
 					}
 					}
+					// increment our next pointer
+					state.next = state.next + count + 1;
 
 
-				}
-				// increment our next pointer
-				state.next = state.next + count + 1;
+				} else if ( line.indexOf ( "POINT_DATA" ) === 0 ) {
 
 
-			} else if ( line.indexOf ( "POINT_DATA" ) == 0 ) {
+					numberOfPoints = parseInt ( line.split( " " )[ 1 ], 10 );
 
 
-				numberOfPoints = parseInt ( line.split( " " )[ 1 ], 10 );
+					// Grab the next line
+					state = findString ( buffer, state.next );
 
 
-				// Grab the next line
-				state = findString ( buffer, state.next );
+					// Now grab the binary data
+					count = numberOfPoints * 4 * 3;
 
 
-				// Now grab the binary data
-				count = numberOfPoints * 4 * 3;
+					normals = new Float32Array( numberOfPoints * 3 );
+					pointIndex = state.next;
+					for ( i = 0; i < numberOfPoints; i ++ ) {
 
 
-				normals = new Float32Array( numberOfPoints * 3 );
-				pointIndex = state.next;
-				for ( i = 0; i < numberOfPoints; i ++ ) {
+						normals[ 3 * i ] = dataView.getFloat32( pointIndex, false );
+						normals[ 3 * i + 1 ] = dataView.getFloat32( pointIndex + 4, false );
+						normals[ 3 * i + 2 ] = dataView.getFloat32( pointIndex + 8, false );
+						pointIndex += 12;
 
 
-					normals[ 3 * i ] = dataView.getFloat32( pointIndex, false );
-					normals[ 3 * i + 1 ] = dataView.getFloat32( pointIndex + 4, false );
-					normals[ 3 * i + 2 ] = dataView.getFloat32( pointIndex + 8, false );
-					pointIndex += 12;
+					}
+
+					// Increment past our data
+					state.next = state.next + count;
 
 
 				}
 				}
 
 
-				// Increment past our data
-				state.next = state.next + count;
+				// Increment index
+				index = state.next;
+
+				if ( index >= buffer.byteLength ) {
+
+					break;
+
+				}
 
 
 			}
 			}
 
 
-			// Increment index
-			index = state.next;
-			if ( index >= buffer.byteLength ) {
+			var geometry = new THREE.BufferGeometry();
+			geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
+			geometry.addAttribute( 'position', new THREE.BufferAttribute( points, 3 ) );
 
 
-				break;
+			if ( normals.length == points.length ) {
+
+				geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
 
 
 			}
 			}
 
 
+			return geometry;
+
 		}
 		}
 
 
+		// get the 5 first lines of the files to check if there is the key word binary
+
+		var meta = String.fromCharCode.apply( null, new Uint8Array( data, 0, 250 ) ).split( '\n' );
+
+
+		if ( meta[ 2 ].includes( 'ASCII' ) ) {
 
 
-		var geometry = new THREE.BufferGeometry();
-		geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
-		geometry.addAttribute( 'position', new THREE.BufferAttribute( points, 3 ) );
+			var stringFile = '';
+			var charArray = new Uint8Array( data );
+			for ( var i = 0; i < charArray.length; i ++ ) {
 
 
+				stringFile += String.fromCharCode( charArray[ i ] );
 
 
-		if ( normals.length == points.length ) {
+			}
 
 
-			geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
+			return parseASCII( stringFile );
 
 
-		}
+		} else {
 
 
+			return parseBinary( data );
 
 
-		return geometry;
+		}
 
 
 	}
 	}
 
 

+ 1 - 1
examples/js/materials/ShadowMaterial.js

@@ -29,7 +29,7 @@ THREE.ShadowMaterial = function () {
 			THREE.ShaderChunk[ "shadowmask_pars_fragment" ],
 			THREE.ShaderChunk[ "shadowmask_pars_fragment" ],
 			"uniform float opacity;",
 			"uniform float opacity;",
 			"void main() {",
 			"void main() {",
-			"	gl_FragColor = vec4( 0.0, 0.0, 0.0, opacity - getShadowMask() );",
+			"	gl_FragColor = vec4( 0.0, 0.0, 0.0, opacity * ( 1.0  - getShadowMask() ) );",
 			"}"
 			"}"
 		].join( '\n' )
 		].join( '\n' )
 	} );
 	} );

+ 1 - 1
examples/webgl_geometry_cube.html

@@ -33,7 +33,7 @@
 
 
 				var texture = new THREE.TextureLoader().load( 'textures/crate.gif' );
 				var texture = new THREE.TextureLoader().load( 'textures/crate.gif' );
 
 
-				var geometry = new THREE.BoxGeometry( 200, 200, 200 );
+				var geometry = new THREE.BoxBufferGeometry( 200, 200, 200 );
 				var material = new THREE.MeshBasicMaterial( { map: texture } );
 				var material = new THREE.MeshBasicMaterial( { map: texture } );
 
 
 				mesh = new THREE.Mesh( geometry, material );
 				mesh = new THREE.Mesh( geometry, material );

+ 1 - 1
examples/webgl_interactive_cubes.html

@@ -51,7 +51,7 @@
 				light.position.set( 1, 1, 1 ).normalize();
 				light.position.set( 1, 1, 1 ).normalize();
 				scene.add( light );
 				scene.add( light );
 
 
-				var geometry = new THREE.BoxGeometry( 20, 20, 20 );
+				var geometry = new THREE.BoxBufferGeometry( 20, 20, 20 );
 
 
 				for ( var i = 0; i < 2000; i ++ ) {
 				for ( var i = 0; i < 2000; i ++ ) {
 
 

+ 1 - 1
examples/webgl_interactive_cubes_ortho.html

@@ -53,7 +53,7 @@
 				light.position.set( 1, 1, 1 ).normalize();
 				light.position.set( 1, 1, 1 ).normalize();
 				scene.add( light );
 				scene.add( light );
 
 
-				var geometry = new THREE.BoxGeometry( 20, 20, 20 );
+				var geometry = new THREE.BoxBufferGeometry( 20, 20, 20 );
 
 
 				for ( var i = 0; i < 2000; i ++ ) {
 				for ( var i = 0; i < 2000; i ++ ) {
 
 

+ 21 - 6
examples/webgl_materials_displacementmap.html

@@ -66,14 +66,16 @@
 			var settings = {
 			var settings = {
 				metalness: 1.0,
 				metalness: 1.0,
 				roughness: 0.4,
 				roughness: 0.4,
+				ambientIntensity: 0.2,
 				aoMapIntensity: 1.0,
 				aoMapIntensity: 1.0,
-				displacementScale: 1.0,
+				envMapIntensity: 1.0,
+				displacementScale: 2.436143, // from original model
 				normalScale: 1.0
 				normalScale: 1.0
 			};
 			};
 
 
 			var mesh, material;
 			var mesh, material;
 
 
-			var pointLight;
+			var pointLight, ambientLight;
 
 
 			var mouseX = 0;
 			var mouseX = 0;
 			var mouseY = 0;
 			var mouseY = 0;
@@ -112,6 +114,18 @@
 
 
 				} );
 				} );
 
 
+				gui.add( settings, "ambientIntensity" ).min( 0 ).max( 1 ).onChange( function( value ) {
+
+					ambientLight.intensity = value;
+
+				} );
+
+				gui.add( settings, "envMapIntensity" ).min( 0 ).max( 3 ).onChange( function( value ) {
+
+					material.envMapIntensity = value;
+
+				} );
+
 				gui.add( settings, "displacementScale" ).min( 0 ).max( 3.0 ).onChange( function( value ) {
 				gui.add( settings, "displacementScale" ).min( 0 ).max( 3.0 ).onChange( function( value ) {
 
 
 					material.displacementScale = value;
 					material.displacementScale = value;
@@ -120,7 +134,7 @@
 
 
 				gui.add( settings, "normalScale" ).min( - 1 ).max( 1 ).onChange( function( value ) {
 				gui.add( settings, "normalScale" ).min( - 1 ).max( 1 ).onChange( function( value ) {
 
 
-					material.normalScale = new THREE.Vector2( 1, - 1 ).multiplyScalar( value );
+					material.normalScale.set( 1, - 1 ).multiplyScalar( value );
 
 
 				} );
 				} );
 
 
@@ -154,7 +168,7 @@
 
 
 				// lights
 				// lights
 
 
-				var ambientLight = new THREE.AmbientLight( 0x111111 );
+				ambientLight = new THREE.AmbientLight( 0xffffff, settings.ambientIntensity );
 				scene.add( ambientLight );
 				scene.add( ambientLight );
 
 
 				pointLight = new THREE.PointLight( 0xff0000, 0.5 );
 				pointLight = new THREE.PointLight( 0xff0000, 0.5 );
@@ -206,10 +220,11 @@
 					aoMapIntensity: 1,
 					aoMapIntensity: 1,
 
 
 					displacementMap: displacementMap,
 					displacementMap: displacementMap,
-					displacementScale: 2.436143,
-					displacementBias: - 0.428408,
+					displacementScale: settings.displacementScale,
+					displacementBias: - 0.428408, // from original model
 
 
 					envMap: reflectionCube,
 					envMap: reflectionCube,
+					envMapIntensity: settings.envMapIntensity,
 
 
 					side: THREE.DoubleSide
 					side: THREE.DoubleSide
 
 

+ 3 - 3
src/core/Geometry.js

@@ -258,12 +258,12 @@ THREE.Geometry.prototype = {
 
 
 		}
 		}
 
 
-		function addFace( a, b, c ) {
+		function addFace( a, b, c, materialIndex ) {
 
 
 			var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
 			var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
 			var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
 			var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
 
 
-			var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
+			var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
 
 
 			scope.faces.push( face );
 			scope.faces.push( face );
 
 
@@ -296,7 +296,7 @@ THREE.Geometry.prototype = {
 
 
 					for ( var j = start, jl = start + count; j < jl; j += 3 ) {
 					for ( var j = start, jl = start + count; j < jl; j += 3 ) {
 
 
-						addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
+						addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex  );
 
 
 					}
 					}
 
 

+ 181 - 0
src/extras/geometries/BoxBufferGeometry.js

@@ -0,0 +1,181 @@
+/**
+ * @author Mugen87 / https://github.com/Mugen87
+ */
+
+THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
+
+	THREE.BufferGeometry.call( this );
+
+	this.type = 'BoxBufferGeometry';
+
+	this.parameters = {
+		width: width,
+		height: height,
+		depth: depth,
+		widthSegments: widthSegments,
+		heightSegments: heightSegments,
+		depthSegments: depthSegments
+	};
+
+	var scope = this;
+
+	// segments
+	widthSegments = Math.floor( widthSegments ) || 1;
+	heightSegments = Math.floor( heightSegments ) || 1;
+	depthSegments = Math.floor( depthSegments ) || 1;
+
+	// these are used to calculate buffer length
+	var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
+	var indexCount = ( vertexCount / 4 ) * 6;
+
+	// buffers
+	var indices = new ( vertexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
+	var vertices = new Float32Array( vertexCount * 3 );
+	var normals = new Float32Array( vertexCount * 3 );
+	var uvs = new Float32Array( vertexCount * 2 );
+
+	// offset variables
+	var vertexBufferOffset = 0;
+	var uvBufferOffset = 0;
+	var indexBufferOffset = 0;
+	var numberOfVertices = 0;
+
+	// group variables
+	var groupStart = 0;
+
+	// build each side of the box geometry
+	buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height,   width,  depthSegments, heightSegments, 0 ); // px
+	buildPlane( 'z', 'y', 'x',   1, - 1, depth, height, - width,  depthSegments, heightSegments, 1 ); // nx
+	buildPlane( 'x', 'z', 'y',   1,   1, width, depth,    height, widthSegments, depthSegments,  2 ); // py
+	buildPlane( 'x', 'z', 'y',   1, - 1, width, depth,  - height, widthSegments, depthSegments,  3 ); // ny
+	buildPlane( 'x', 'y', 'z',   1, - 1, width, height,   depth,  widthSegments, heightSegments, 4 ); // pz
+	buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth,  widthSegments, heightSegments, 5 ); // nz
+
+	// build geometry
+	this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
+	this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
+	this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
+	this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
+
+	// helper functions
+
+	function calculateVertexCount ( w, h, d ) {
+
+		var segments = 0;
+
+		// calculate the amount of segments for each side
+		segments += w * h * 2; // xy
+		segments += w * d * 2; // xz
+		segments += d * h * 2; // zy
+
+		return segments * 4; // four vertices per segments
+
+	}
+
+	function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
+
+		var segmentWidth	= width / gridX;
+		var segmentHeight = height / gridY;
+
+		var widthHalf = width / 2;
+		var heightHalf = height / 2;
+		var depthHalf = depth / 2;
+
+		var gridX1 = gridX + 1;
+		var gridY1 = gridY + 1;
+
+		var vertexCounter = 0;
+		var groupCount = 0;
+
+		var vector = new THREE.Vector3();
+
+		// generate vertices, normals and uvs
+
+		for ( var iy = 0; iy < gridY1; iy ++ ) {
+
+			var y = iy * segmentHeight - heightHalf;
+
+			for ( var ix = 0; ix < gridX1; ix ++ ) {
+
+				var x = ix * segmentWidth - widthHalf;
+
+				// set values to correct vector component
+				vector[ u ] = x * udir;
+				vector[ v ] = y * vdir;
+				vector[ w ] = depthHalf;
+
+				// now apply vector to vertex buffer
+				vertices[ vertexBufferOffset ] = vector.x;
+				vertices[ vertexBufferOffset + 1 ] = vector.y;
+				vertices[ vertexBufferOffset + 2 ] = vector.z;
+
+				// set values to correct vector component
+				vector[ u ] = 0;
+				vector[ v ] = 0;
+				vector[ w ] = depth > 0 ? 1 : - 1;
+
+				// now apply vector to normal buffer
+				normals[ vertexBufferOffset ] = vector.x;
+				normals[ vertexBufferOffset + 1 ] = vector.y;
+				normals[ vertexBufferOffset + 2 ] = vector.z;
+
+				// uvs
+				uvs[ uvBufferOffset ] = ix / gridX;
+				uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
+
+				// update offsets and counters
+				vertexBufferOffset += 3;
+				uvBufferOffset += 2;
+				vertexCounter += 1;
+
+			}
+
+		}
+
+		// 1. you need three indices to draw a single face
+		// 2. a single segment consists of two faces
+		// 3. so we need to generate six (2*3) indices per segment
+
+		for ( iy = 0; iy < gridY; iy ++ ) {
+
+			for ( ix = 0; ix < gridX; ix ++ ) {
+
+				// indices
+				var a = numberOfVertices + ix + gridX1 * iy;
+				var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
+				var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
+				var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
+
+				// face one
+				indices[ indexBufferOffset ] = a;
+				indices[ indexBufferOffset + 1 ] = b;
+				indices[ indexBufferOffset + 2 ] = d;
+
+				// face two
+				indices[ indexBufferOffset + 3 ] = b;
+				indices[ indexBufferOffset + 4 ] = c;
+				indices[ indexBufferOffset + 5 ] = d;
+
+				// update offsets and counters
+				indexBufferOffset += 6;
+				groupCount += 6;
+
+			}
+
+		}
+
+		// add a group to the geometry. this will ensure multi material support
+		scope.addGroup( groupStart, groupCount, materialIndex );
+
+		// calculate new start value for groups
+		groupStart += groupCount;
+
+		// update total number of vertices
+		numberOfVertices += vertexCounter;
+
+	}
+
+};
+
+THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
+THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;

+ 1 - 102
src/extras/geometries/BoxGeometry.js

@@ -18,108 +18,7 @@ THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegmen
 		depthSegments: depthSegments
 		depthSegments: depthSegments
 	};
 	};
 
 
-	this.widthSegments = widthSegments || 1;
-	this.heightSegments = heightSegments || 1;
-	this.depthSegments = depthSegments || 1;
-
-	var scope = this;
-
-	var width_half = width / 2;
-	var height_half = height / 2;
-	var depth_half = depth / 2;
-
-	buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
-	buildPlane( 'z', 'y',   1, - 1, depth, height, - width_half, 1 ); // nx
-	buildPlane( 'x', 'z',   1,   1, width, depth, height_half, 2 ); // py
-	buildPlane( 'x', 'z',   1, - 1, width, depth, - height_half, 3 ); // ny
-	buildPlane( 'x', 'y',   1, - 1, width, height, depth_half, 4 ); // pz
-	buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
-
-	function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
-
-		var w, ix, iy,
-		gridX = scope.widthSegments,
-		gridY = scope.heightSegments,
-		width_half = width / 2,
-		height_half = height / 2,
-		offset = scope.vertices.length;
-
-		if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
-
-			w = 'z';
-
-		} else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
-
-			w = 'y';
-			gridY = scope.depthSegments;
-
-		} else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
-
-			w = 'x';
-			gridX = scope.depthSegments;
-
-		}
-
-		var gridX1 = gridX + 1,
-		gridY1 = gridY + 1,
-		segment_width = width / gridX,
-		segment_height = height / gridY,
-		normal = new THREE.Vector3();
-
-		normal[ w ] = depth > 0 ? 1 : - 1;
-
-		for ( iy = 0; iy < gridY1; iy ++ ) {
-
-			for ( ix = 0; ix < gridX1; ix ++ ) {
-
-				var vector = new THREE.Vector3();
-				vector[ u ] = ( ix * segment_width - width_half ) * udir;
-				vector[ v ] = ( iy * segment_height - height_half ) * vdir;
-				vector[ w ] = depth;
-
-				scope.vertices.push( vector );
-
-			}
-
-		}
-
-		for ( iy = 0; iy < gridY; iy ++ ) {
-
-			for ( ix = 0; ix < gridX; ix ++ ) {
-
-				var a = ix + gridX1 * iy;
-				var b = ix + gridX1 * ( iy + 1 );
-				var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
-				var d = ( ix + 1 ) + gridX1 * iy;
-
-				var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
-				var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
-				var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
-				var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
-
-				var face = new THREE.Face3( a + offset, b + offset, d + offset );
-				face.normal.copy( normal );
-				face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
-				face.materialIndex = materialIndex;
-
-				scope.faces.push( face );
-				scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
-
-				face = new THREE.Face3( b + offset, c + offset, d + offset );
-				face.normal.copy( normal );
-				face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
-				face.materialIndex = materialIndex;
-
-				scope.faces.push( face );
-				scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
-
-			}
-
-		}
-
-	}
-
-	this.mergeVertices();
+	this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
 
 
 };
 };
 
 

+ 317 - 317
src/renderers/shaders/ShaderLib.js

@@ -21,39 +21,39 @@ THREE.ShaderLib = {
 
 
 		vertexShader: [
 		vertexShader: [
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "uv_pars_vertex" ],
-			THREE.ShaderChunk[ "uv2_pars_vertex" ],
-			THREE.ShaderChunk[ "envmap_pars_vertex" ],
-			THREE.ShaderChunk[ "color_pars_vertex" ],
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
-			THREE.ShaderChunk[ "skinning_pars_vertex" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <uv_pars_vertex>',
+			'#include <uv2_pars_vertex>',
+			'#include <envmap_pars_vertex>',
+			'#include <color_pars_vertex>',
+			'#include <morphtarget_pars_vertex>',
+			'#include <skinning_pars_vertex>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "uv_vertex" ],
-				THREE.ShaderChunk[ "uv2_vertex" ],
-				THREE.ShaderChunk[ "color_vertex" ],
-				THREE.ShaderChunk[ "skinbase_vertex" ],
+				'#include <uv_vertex>',
+				'#include <uv2_vertex>',
+				'#include <color_vertex>',
+				'#include <skinbase_vertex>',
 
 
 			"	#ifdef USE_ENVMAP",
 			"	#ifdef USE_ENVMAP",
 
 
-				THREE.ShaderChunk[ "beginnormal_vertex" ],
-				THREE.ShaderChunk[ "morphnormal_vertex" ],
-				THREE.ShaderChunk[ "skinnormal_vertex" ],
-				THREE.ShaderChunk[ "defaultnormal_vertex" ],
+				'#include <beginnormal_vertex>',
+				'#include <morphnormal_vertex>',
+				'#include <skinnormal_vertex>',
+				'#include <defaultnormal_vertex>',
 
 
 			"	#endif",
 			"	#endif",
 
 
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "skinning_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <begin_vertex>',
+				'#include <morphtarget_vertex>',
+				'#include <skinning_vertex>',
+				'#include <project_vertex>',
+				'#include <logdepthbuf_vertex>',
 
 
-				THREE.ShaderChunk[ "worldpos_vertex" ],
-				THREE.ShaderChunk[ "envmap_vertex" ],
+				'#include <worldpos_vertex>',
+				'#include <envmap_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -70,28 +70,28 @@ THREE.ShaderLib = {
 
 
 			"#endif",
 			"#endif",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "color_pars_fragment" ],
-			THREE.ShaderChunk[ "uv_pars_fragment" ],
-			THREE.ShaderChunk[ "uv2_pars_fragment" ],
-			THREE.ShaderChunk[ "map_pars_fragment" ],
-			THREE.ShaderChunk[ "alphamap_pars_fragment" ],
-			THREE.ShaderChunk[ "aomap_pars_fragment" ],
-			THREE.ShaderChunk[ "envmap_pars_fragment" ],
-			THREE.ShaderChunk[ "fog_pars_fragment" ],
-			THREE.ShaderChunk[ "specularmap_pars_fragment" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <color_pars_fragment>',
+			'#include <uv_pars_fragment>',
+			'#include <uv2_pars_fragment>',
+			'#include <map_pars_fragment>',
+			'#include <alphamap_pars_fragment>',
+			'#include <aomap_pars_fragment>',
+			'#include <envmap_pars_fragment>',
+			'#include <fog_pars_fragment>',
+			'#include <specularmap_pars_fragment>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
 			"	vec4 diffuseColor = vec4( diffuse, opacity );",
 			"	vec4 diffuseColor = vec4( diffuse, opacity );",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
-				THREE.ShaderChunk[ "map_fragment" ],
-				THREE.ShaderChunk[ "color_fragment" ],
-				THREE.ShaderChunk[ "alphamap_fragment" ],
-				THREE.ShaderChunk[ "alphatest_fragment" ],
-				THREE.ShaderChunk[ "specularmap_fragment" ],
+				'#include <logdepthbuf_fragment>',
+				'#include <map_fragment>',
+				'#include <color_fragment>',
+				'#include <alphamap_fragment>',
+				'#include <alphatest_fragment>',
+				'#include <specularmap_fragment>',
 
 
 			"	ReflectedLight reflectedLight;",
 			"	ReflectedLight reflectedLight;",
 			"	reflectedLight.directDiffuse = vec3( 0.0 );",
 			"	reflectedLight.directDiffuse = vec3( 0.0 );",
@@ -99,13 +99,13 @@ THREE.ShaderLib = {
 			"	reflectedLight.indirectDiffuse = diffuseColor.rgb;",
 			"	reflectedLight.indirectDiffuse = diffuseColor.rgb;",
 			"	reflectedLight.indirectSpecular = vec3( 0.0 );",
 			"	reflectedLight.indirectSpecular = vec3( 0.0 );",
 
 
-				THREE.ShaderChunk[ "aomap_fragment" ],
+				'#include <aomap_fragment>',
 
 
 			"	vec3 outgoingLight = reflectedLight.indirectDiffuse;",
 			"	vec3 outgoingLight = reflectedLight.indirectDiffuse;",
 
 
-				THREE.ShaderChunk[ "envmap_fragment" ],
-				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
-				THREE.ShaderChunk[ "fog_fragment" ],
+				'#include <envmap_fragment>',
+				'#include <linear_to_gamma_fragment>',
+				'#include <fog_fragment>',
 
 
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 
 
@@ -145,40 +145,40 @@ THREE.ShaderLib = {
 
 
 			"#endif",
 			"#endif",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "uv_pars_vertex" ],
-			THREE.ShaderChunk[ "uv2_pars_vertex" ],
-			THREE.ShaderChunk[ "envmap_pars_vertex" ],
-			THREE.ShaderChunk[ "bsdfs" ],
-			THREE.ShaderChunk[ "lights_pars" ],
-			THREE.ShaderChunk[ "color_pars_vertex" ],
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
-			THREE.ShaderChunk[ "skinning_pars_vertex" ],
-			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <uv_pars_vertex>',
+			'#include <uv2_pars_vertex>',
+			'#include <envmap_pars_vertex>',
+			'#include <bsdfs>',
+			'#include <lights_pars>',
+			'#include <color_pars_vertex>',
+			'#include <morphtarget_pars_vertex>',
+			'#include <skinning_pars_vertex>',
+			'#include <shadowmap_pars_vertex>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "uv_vertex" ],
-				THREE.ShaderChunk[ "uv2_vertex" ],
-				THREE.ShaderChunk[ "color_vertex" ],
+				'#include <uv_vertex>',
+				'#include <uv2_vertex>',
+				'#include <color_vertex>',
 
 
-				THREE.ShaderChunk[ "beginnormal_vertex" ],
-				THREE.ShaderChunk[ "morphnormal_vertex" ],
-				THREE.ShaderChunk[ "skinbase_vertex" ],
-				THREE.ShaderChunk[ "skinnormal_vertex" ],
-				THREE.ShaderChunk[ "defaultnormal_vertex" ],
+				'#include <beginnormal_vertex>',
+				'#include <morphnormal_vertex>',
+				'#include <skinbase_vertex>',
+				'#include <skinnormal_vertex>',
+				'#include <defaultnormal_vertex>',
 
 
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "skinning_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <begin_vertex>',
+				'#include <morphtarget_vertex>',
+				'#include <skinning_vertex>',
+				'#include <project_vertex>',
+				'#include <logdepthbuf_vertex>',
 
 
-				THREE.ShaderChunk[ "worldpos_vertex" ],
-				THREE.ShaderChunk[ "envmap_vertex" ],
-				THREE.ShaderChunk[ "lights_lambert_vertex" ],
-				THREE.ShaderChunk[ "shadowmap_vertex" ],
+				'#include <worldpos_vertex>',
+				'#include <envmap_vertex>',
+				'#include <lights_lambert_vertex>',
+				'#include <shadowmap_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -198,24 +198,24 @@ THREE.ShaderLib = {
 
 
 			"#endif",
 			"#endif",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "color_pars_fragment" ],
-			THREE.ShaderChunk[ "uv_pars_fragment" ],
-			THREE.ShaderChunk[ "uv2_pars_fragment" ],
-			THREE.ShaderChunk[ "map_pars_fragment" ],
-			THREE.ShaderChunk[ "alphamap_pars_fragment" ],
-			THREE.ShaderChunk[ "aomap_pars_fragment" ],
-			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
-			THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
-			THREE.ShaderChunk[ "envmap_pars_fragment" ],
-			THREE.ShaderChunk[ "bsdfs" ],
-			THREE.ShaderChunk[ "ambient_pars" ],
-			THREE.ShaderChunk[ "lights_pars" ],
-			THREE.ShaderChunk[ "fog_pars_fragment" ],
-			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
-			THREE.ShaderChunk[ "shadowmask_pars_fragment" ],
-			THREE.ShaderChunk[ "specularmap_pars_fragment" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <color_pars_fragment>',
+			'#include <uv_pars_fragment>',
+			'#include <uv2_pars_fragment>',
+			'#include <map_pars_fragment>',
+			'#include <alphamap_pars_fragment>',
+			'#include <aomap_pars_fragment>',
+			'#include <lightmap_pars_fragment>',
+			'#include <emissivemap_pars_fragment>',
+			'#include <envmap_pars_fragment>',
+			'#include <bsdfs>',
+			'#include <ambient_pars>',
+			'#include <lights_pars>',
+			'#include <fog_pars_fragment>',
+			'#include <shadowmap_pars_fragment>',
+			'#include <shadowmask_pars_fragment>',
+			'#include <specularmap_pars_fragment>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
@@ -223,18 +223,18 @@ THREE.ShaderLib = {
 			"	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
 			"	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
 			"	vec3 totalEmissiveLight = emissive;",
 			"	vec3 totalEmissiveLight = emissive;",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
-				THREE.ShaderChunk[ "map_fragment" ],
-				THREE.ShaderChunk[ "color_fragment" ],
-				THREE.ShaderChunk[ "alphamap_fragment" ],
-				THREE.ShaderChunk[ "alphatest_fragment" ],
-				THREE.ShaderChunk[ "specularmap_fragment" ],
-				THREE.ShaderChunk[ "emissivemap_fragment" ],
+				'#include <logdepthbuf_fragment>',
+				'#include <map_fragment>',
+				'#include <color_fragment>',
+				'#include <alphamap_fragment>',
+				'#include <alphatest_fragment>',
+				'#include <specularmap_fragment>',
+				'#include <emissivemap_fragment>',
 
 
 				// accumulation
 				// accumulation
 			"	reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );",
 			"	reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );",
 
 
-				THREE.ShaderChunk[ "lightmap_fragment" ],
+				'#include <lightmap_fragment>',
 
 
 			"	reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );",
 			"	reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );",
 
 
@@ -251,15 +251,15 @@ THREE.ShaderLib = {
 			"	reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();",
 			"	reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();",
 
 
 				// modulation
 				// modulation
-				THREE.ShaderChunk[ "aomap_fragment" ],
+				'#include <aomap_fragment>',
 
 
 			"	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveLight;",
 			"	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveLight;",
 
 
-				THREE.ShaderChunk[ "envmap_fragment" ],
+				'#include <envmap_fragment>',
 
 
-				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
+				'#include <linear_to_gamma_fragment>',
 
 
-				THREE.ShaderChunk[ "fog_fragment" ],
+				'#include <fog_fragment>',
 
 
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 
 
@@ -304,29 +304,29 @@ THREE.ShaderLib = {
 
 
 			"#endif",
 			"#endif",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "uv_pars_vertex" ],
-			THREE.ShaderChunk[ "uv2_pars_vertex" ],
-			THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
-			THREE.ShaderChunk[ "envmap_pars_vertex" ],
-			THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
-			THREE.ShaderChunk[ "color_pars_vertex" ],
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
-			THREE.ShaderChunk[ "skinning_pars_vertex" ],
-			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <uv_pars_vertex>',
+			'#include <uv2_pars_vertex>',
+			'#include <displacementmap_pars_vertex>',
+			'#include <envmap_pars_vertex>',
+			'#include <lights_phong_pars_vertex>',
+			'#include <color_pars_vertex>',
+			'#include <morphtarget_pars_vertex>',
+			'#include <skinning_pars_vertex>',
+			'#include <shadowmap_pars_vertex>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "uv_vertex" ],
-				THREE.ShaderChunk[ "uv2_vertex" ],
-				THREE.ShaderChunk[ "color_vertex" ],
+				'#include <uv_vertex>',
+				'#include <uv2_vertex>',
+				'#include <color_vertex>',
 
 
-				THREE.ShaderChunk[ "beginnormal_vertex" ],
-				THREE.ShaderChunk[ "morphnormal_vertex" ],
-				THREE.ShaderChunk[ "skinbase_vertex" ],
-				THREE.ShaderChunk[ "skinnormal_vertex" ],
-				THREE.ShaderChunk[ "defaultnormal_vertex" ],
+				'#include <beginnormal_vertex>',
+				'#include <morphnormal_vertex>',
+				'#include <skinbase_vertex>',
+				'#include <skinnormal_vertex>',
+				'#include <defaultnormal_vertex>',
 
 
 			"#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
 			"#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
 
 
@@ -334,19 +334,19 @@ THREE.ShaderLib = {
 
 
 			"#endif",
 			"#endif",
 
 
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "displacementmap_vertex" ],
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "skinning_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <begin_vertex>',
+				'#include <displacementmap_vertex>',
+				'#include <morphtarget_vertex>',
+				'#include <skinning_vertex>',
+				'#include <project_vertex>',
+				'#include <logdepthbuf_vertex>',
 
 
 			"	vViewPosition = - mvPosition.xyz;",
 			"	vViewPosition = - mvPosition.xyz;",
 
 
-				THREE.ShaderChunk[ "worldpos_vertex" ],
-				THREE.ShaderChunk[ "envmap_vertex" ],
-				THREE.ShaderChunk[ "lights_phong_vertex" ],
-				THREE.ShaderChunk[ "shadowmap_vertex" ],
+				'#include <worldpos_vertex>',
+				'#include <envmap_vertex>',
+				'#include <lights_phong_vertex>',
+				'#include <shadowmap_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -362,26 +362,26 @@ THREE.ShaderLib = {
 			"uniform float shininess;",
 			"uniform float shininess;",
 			"uniform float opacity;",
 			"uniform float opacity;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "color_pars_fragment" ],
-			THREE.ShaderChunk[ "uv_pars_fragment" ],
-			THREE.ShaderChunk[ "uv2_pars_fragment" ],
-			THREE.ShaderChunk[ "map_pars_fragment" ],
-			THREE.ShaderChunk[ "alphamap_pars_fragment" ],
-			THREE.ShaderChunk[ "aomap_pars_fragment" ],
-			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
-			THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
-			THREE.ShaderChunk[ "envmap_pars_fragment" ],
-			THREE.ShaderChunk[ "fog_pars_fragment" ],
-			THREE.ShaderChunk[ "bsdfs" ],
-			THREE.ShaderChunk[ "ambient_pars" ],
-			THREE.ShaderChunk[ "lights_pars" ],
-			THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
-			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
-			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
-			THREE.ShaderChunk[ "normalmap_pars_fragment" ],
-			THREE.ShaderChunk[ "specularmap_pars_fragment" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <color_pars_fragment>',
+			'#include <uv_pars_fragment>',
+			'#include <uv2_pars_fragment>',
+			'#include <map_pars_fragment>',
+			'#include <alphamap_pars_fragment>',
+			'#include <aomap_pars_fragment>',
+			'#include <lightmap_pars_fragment>',
+			'#include <emissivemap_pars_fragment>',
+			'#include <envmap_pars_fragment>',
+			'#include <fog_pars_fragment>',
+			'#include <bsdfs>',
+			'#include <ambient_pars>',
+			'#include <lights_pars>',
+			'#include <lights_phong_pars_fragment>',
+			'#include <shadowmap_pars_fragment>',
+			'#include <bumpmap_pars_fragment>',
+			'#include <normalmap_pars_fragment>',
+			'#include <specularmap_pars_fragment>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
@@ -389,28 +389,28 @@ THREE.ShaderLib = {
 			"	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
 			"	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
 			"	vec3 totalEmissiveLight = emissive;",
 			"	vec3 totalEmissiveLight = emissive;",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
-				THREE.ShaderChunk[ "map_fragment" ],
-				THREE.ShaderChunk[ "color_fragment" ],
-				THREE.ShaderChunk[ "alphamap_fragment" ],
-				THREE.ShaderChunk[ "alphatest_fragment" ],
-				THREE.ShaderChunk[ "specularmap_fragment" ],
-				THREE.ShaderChunk[ "normal_fragment" ],
-				THREE.ShaderChunk[ "emissivemap_fragment" ],
+				'#include <logdepthbuf_fragment>',
+				'#include <map_fragment>',
+				'#include <color_fragment>',
+				'#include <alphamap_fragment>',
+				'#include <alphatest_fragment>',
+				'#include <specularmap_fragment>',
+				'#include <normal_fragment>',
+				'#include <emissivemap_fragment>',
 
 
 				// accumulation
 				// accumulation
-				THREE.ShaderChunk[ "lights_phong_fragment" ],
-				THREE.ShaderChunk[ "lights_template" ],
+				'#include <lights_phong_fragment>',
+				'#include <lights_template>',
 
 
 				// modulation
 				// modulation
-				THREE.ShaderChunk[ "aomap_fragment" ],
+				'#include <aomap_fragment>',
 
 
 				"vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
 				"vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
 
 
-				THREE.ShaderChunk[ "envmap_fragment" ],
-				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
+				'#include <envmap_fragment>',
+				'#include <linear_to_gamma_fragment>',
 
 
-				THREE.ShaderChunk[ "fog_fragment" ],
+				'#include <fog_fragment>',
 
 
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 
 
@@ -458,29 +458,29 @@ THREE.ShaderLib = {
 
 
 			"#endif",
 			"#endif",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "uv_pars_vertex" ],
-			THREE.ShaderChunk[ "uv2_pars_vertex" ],
-			THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
-			THREE.ShaderChunk[ "envmap_pars_vertex" ],
-			THREE.ShaderChunk[ "color_pars_vertex" ],
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
-			THREE.ShaderChunk[ "skinning_pars_vertex" ],
-			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
-			THREE.ShaderChunk[ "specularmap_pars_fragment" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <uv_pars_vertex>',
+			'#include <uv2_pars_vertex>',
+			'#include <displacementmap_pars_vertex>',
+			'#include <envmap_pars_vertex>',
+			'#include <color_pars_vertex>',
+			'#include <morphtarget_pars_vertex>',
+			'#include <skinning_pars_vertex>',
+			'#include <shadowmap_pars_vertex>',
+			'#include <specularmap_pars_fragment>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {", // STANDARD
 			"void main() {", // STANDARD
 
 
-				THREE.ShaderChunk[ "uv_vertex" ],
-				THREE.ShaderChunk[ "uv2_vertex" ],
-				THREE.ShaderChunk[ "color_vertex" ],
+				'#include <uv_vertex>',
+				'#include <uv2_vertex>',
+				'#include <color_vertex>',
 
 
-				THREE.ShaderChunk[ "beginnormal_vertex" ],
-				THREE.ShaderChunk[ "morphnormal_vertex" ],
-				THREE.ShaderChunk[ "skinbase_vertex" ],
-				THREE.ShaderChunk[ "skinnormal_vertex" ],
-				THREE.ShaderChunk[ "defaultnormal_vertex" ],
+				'#include <beginnormal_vertex>',
+				'#include <morphnormal_vertex>',
+				'#include <skinbase_vertex>',
+				'#include <skinnormal_vertex>',
+				'#include <defaultnormal_vertex>',
 
 
 			"#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
 			"#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
 
 
@@ -488,18 +488,18 @@ THREE.ShaderLib = {
 
 
 			"#endif",
 			"#endif",
 
 
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "displacementmap_vertex" ],
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "skinning_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <begin_vertex>',
+				'#include <displacementmap_vertex>',
+				'#include <morphtarget_vertex>',
+				'#include <skinning_vertex>',
+				'#include <project_vertex>',
+				'#include <logdepthbuf_vertex>',
 
 
 			"	vViewPosition = - mvPosition.xyz;",
 			"	vViewPosition = - mvPosition.xyz;",
 
 
-				THREE.ShaderChunk[ "worldpos_vertex" ],
-				THREE.ShaderChunk[ "envmap_vertex" ],
-				THREE.ShaderChunk[ "shadowmap_vertex" ],
+				'#include <worldpos_vertex>',
+				'#include <envmap_vertex>',
+				'#include <shadowmap_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -525,27 +525,27 @@ THREE.ShaderLib = {
 
 
 			"#endif",
 			"#endif",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "color_pars_fragment" ],
-			THREE.ShaderChunk[ "uv_pars_fragment" ],
-			THREE.ShaderChunk[ "uv2_pars_fragment" ],
-			THREE.ShaderChunk[ "map_pars_fragment" ],
-			THREE.ShaderChunk[ "alphamap_pars_fragment" ],
-			THREE.ShaderChunk[ "aomap_pars_fragment" ],
-			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
-			THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
-			THREE.ShaderChunk[ "envmap_pars_fragment" ],
-			THREE.ShaderChunk[ "fog_pars_fragment" ],
-			THREE.ShaderChunk[ "bsdfs" ],
-			THREE.ShaderChunk[ "ambient_pars" ],
-			THREE.ShaderChunk[ "lights_pars" ],
-			THREE.ShaderChunk[ "lights_standard_pars_fragment" ],
-			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
-			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
-			THREE.ShaderChunk[ "normalmap_pars_fragment" ],
-			THREE.ShaderChunk[ "roughnessmap_pars_fragment" ],
-			THREE.ShaderChunk[ "metalnessmap_pars_fragment" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <color_pars_fragment>',
+			'#include <uv_pars_fragment>',
+			'#include <uv2_pars_fragment>',
+			'#include <map_pars_fragment>',
+			'#include <alphamap_pars_fragment>',
+			'#include <aomap_pars_fragment>',
+			'#include <lightmap_pars_fragment>',
+			'#include <emissivemap_pars_fragment>',
+			'#include <envmap_pars_fragment>',
+			'#include <fog_pars_fragment>',
+			'#include <bsdfs>',
+			'#include <ambient_pars>',
+			'#include <lights_pars>',
+			'#include <lights_standard_pars_fragment>',
+			'#include <shadowmap_pars_fragment>',
+			'#include <bumpmap_pars_fragment>',
+			'#include <normalmap_pars_fragment>',
+			'#include <roughnessmap_pars_fragment>',
+			'#include <metalnessmap_pars_fragment>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
@@ -553,29 +553,29 @@ THREE.ShaderLib = {
 			"	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
 			"	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
 			"	vec3 totalEmissiveLight = emissive;",
 			"	vec3 totalEmissiveLight = emissive;",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
-				THREE.ShaderChunk[ "map_fragment" ],
-				THREE.ShaderChunk[ "color_fragment" ],
-				THREE.ShaderChunk[ "alphamap_fragment" ],
-				THREE.ShaderChunk[ "alphatest_fragment" ],
-				THREE.ShaderChunk[ "specularmap_fragment" ],
-				THREE.ShaderChunk[ "roughnessmap_fragment" ],
-				THREE.ShaderChunk[ "metalnessmap_fragment" ],
-				THREE.ShaderChunk[ "normal_fragment" ],
-				THREE.ShaderChunk[ "emissivemap_fragment" ],
+				'#include <logdepthbuf_fragment>',
+				'#include <map_fragment>',
+				'#include <color_fragment>',
+				'#include <alphamap_fragment>',
+				'#include <alphatest_fragment>',
+				'#include <specularmap_fragment>',
+				'#include <roughnessmap_fragment>',
+				'#include <metalnessmap_fragment>',
+				'#include <normal_fragment>',
+				'#include <emissivemap_fragment>',
 
 
 				// accumulation
 				// accumulation
-				THREE.ShaderChunk[ "lights_standard_fragment" ],
-				THREE.ShaderChunk[ "lights_template" ],
+				'#include <lights_standard_fragment>',
+				'#include <lights_template>',
 
 
 				// modulation
 				// modulation
-				THREE.ShaderChunk[ "aomap_fragment" ],
+				'#include <aomap_fragment>',
 
 
 				"vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
 				"vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
 
 
-				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
+				'#include <linear_to_gamma_fragment>',
 
 
-				THREE.ShaderChunk[ "fog_fragment" ],
+				'#include <fog_fragment>',
 
 
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 
 
@@ -599,16 +599,16 @@ THREE.ShaderLib = {
 			"uniform float size;",
 			"uniform float size;",
 			"uniform float scale;",
 			"uniform float scale;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "color_pars_vertex" ],
-			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <color_pars_vertex>',
+			'#include <shadowmap_pars_vertex>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "color_vertex" ],
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
+				'#include <color_vertex>',
+				'#include <begin_vertex>',
+				'#include <project_vertex>',
 
 
 			"	#ifdef USE_SIZEATTENUATION",
 			"	#ifdef USE_SIZEATTENUATION",
 			"		gl_PointSize = size * ( scale / - mvPosition.z );",
 			"		gl_PointSize = size * ( scale / - mvPosition.z );",
@@ -616,9 +616,9 @@ THREE.ShaderLib = {
 			"		gl_PointSize = size;",
 			"		gl_PointSize = size;",
 			"	#endif",
 			"	#endif",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
-				THREE.ShaderChunk[ "worldpos_vertex" ],
-				THREE.ShaderChunk[ "shadowmap_vertex" ],
+				'#include <logdepthbuf_vertex>',
+				'#include <worldpos_vertex>',
+				'#include <shadowmap_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -629,26 +629,26 @@ THREE.ShaderLib = {
 			"uniform vec3 diffuse;",
 			"uniform vec3 diffuse;",
 			"uniform float opacity;",
 			"uniform float opacity;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "color_pars_fragment" ],
-			THREE.ShaderChunk[ "map_particle_pars_fragment" ],
-			THREE.ShaderChunk[ "fog_pars_fragment" ],
-			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <color_pars_fragment>',
+			'#include <map_particle_pars_fragment>',
+			'#include <fog_pars_fragment>',
+			'#include <shadowmap_pars_fragment>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
 			"	vec3 outgoingLight = vec3( 0.0 );",
 			"	vec3 outgoingLight = vec3( 0.0 );",
 			"	vec4 diffuseColor = vec4( diffuse, opacity );",
 			"	vec4 diffuseColor = vec4( diffuse, opacity );",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
-				THREE.ShaderChunk[ "map_particle_fragment" ],
-				THREE.ShaderChunk[ "color_fragment" ],
-				THREE.ShaderChunk[ "alphatest_fragment" ],
+				'#include <logdepthbuf_fragment>',
+				'#include <map_particle_fragment>',
+				'#include <color_fragment>',
+				'#include <alphatest_fragment>',
 
 
 			"	outgoingLight = diffuseColor.rgb;",
 			"	outgoingLight = diffuseColor.rgb;",
 
 
-				THREE.ShaderChunk[ "fog_fragment" ],
+				'#include <fog_fragment>',
 
 
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 
 
@@ -680,20 +680,20 @@ THREE.ShaderLib = {
 
 
 			"varying float vLineDistance;",
 			"varying float vLineDistance;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "color_pars_vertex" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <color_pars_vertex>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "color_vertex" ],
+				'#include <color_vertex>',
 
 
 			"	vLineDistance = scale * lineDistance;",
 			"	vLineDistance = scale * lineDistance;",
 
 
 			"	vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
 			"	vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
 			"	gl_Position = projectionMatrix * mvPosition;",
 			"	gl_Position = projectionMatrix * mvPosition;",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <logdepthbuf_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -709,10 +709,10 @@ THREE.ShaderLib = {
 
 
 			"varying float vLineDistance;",
 			"varying float vLineDistance;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "color_pars_fragment" ],
-			THREE.ShaderChunk[ "fog_pars_fragment" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <color_pars_fragment>',
+			'#include <fog_pars_fragment>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
@@ -725,12 +725,12 @@ THREE.ShaderLib = {
 			"	vec3 outgoingLight = vec3( 0.0 );",
 			"	vec3 outgoingLight = vec3( 0.0 );",
 			"	vec4 diffuseColor = vec4( diffuse, opacity );",
 			"	vec4 diffuseColor = vec4( diffuse, opacity );",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
-				THREE.ShaderChunk[ "color_fragment" ],
+				'#include <logdepthbuf_fragment>',
+				'#include <color_fragment>',
 
 
 			"	outgoingLight = diffuseColor.rgb;", // simple shader
 			"	outgoingLight = diffuseColor.rgb;", // simple shader
 
 
-				THREE.ShaderChunk[ "fog_fragment" ],
+				'#include <fog_fragment>',
 
 
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 			"	gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
 
 
@@ -752,16 +752,16 @@ THREE.ShaderLib = {
 
 
 		vertexShader: [
 		vertexShader: [
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <morphtarget_pars_vertex>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <begin_vertex>',
+				'#include <morphtarget_vertex>',
+				'#include <project_vertex>',
+				'#include <logdepthbuf_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -773,12 +773,12 @@ THREE.ShaderLib = {
 			"uniform float mFar;",
 			"uniform float mFar;",
 			"uniform float opacity;",
 			"uniform float opacity;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
+				'#include <logdepthbuf_fragment>',
 
 
 			"	#ifdef USE_LOGDEPTHBUF_EXT",
 			"	#ifdef USE_LOGDEPTHBUF_EXT",
 
 
@@ -811,18 +811,18 @@ THREE.ShaderLib = {
 
 
 			"varying vec3 vNormal;",
 			"varying vec3 vNormal;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <morphtarget_pars_vertex>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
 			"	vNormal = normalize( normalMatrix * normal );",
 			"	vNormal = normalize( normalMatrix * normal );",
 
 
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <begin_vertex>',
+				'#include <morphtarget_vertex>',
+				'#include <project_vertex>',
+				'#include <logdepthbuf_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -833,14 +833,14 @@ THREE.ShaderLib = {
 			"uniform float opacity;",
 			"uniform float opacity;",
 			"varying vec3 vNormal;",
 			"varying vec3 vNormal;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
 			"	gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
 			"	gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
+				'#include <logdepthbuf_fragment>',
 
 
 			"}"
 			"}"
 
 
@@ -863,8 +863,8 @@ THREE.ShaderLib = {
 
 
 			"varying vec3 vWorldPosition;",
 			"varying vec3 vWorldPosition;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
@@ -872,7 +872,7 @@ THREE.ShaderLib = {
 
 
 			"	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 			"	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <logdepthbuf_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -885,14 +885,14 @@ THREE.ShaderLib = {
 
 
 			"varying vec3 vWorldPosition;",
 			"varying vec3 vWorldPosition;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
 			"	gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
 			"	gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
+				'#include <logdepthbuf_fragment>',
 
 
 			"}"
 			"}"
 
 
@@ -915,8 +915,8 @@ THREE.ShaderLib = {
 
 
 			"varying vec3 vWorldPosition;",
 			"varying vec3 vWorldPosition;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
@@ -924,7 +924,7 @@ THREE.ShaderLib = {
 
 
 			"	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 			"	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <logdepthbuf_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -937,8 +937,8 @@ THREE.ShaderLib = {
 
 
 			"varying vec3 vWorldPosition;",
 			"varying vec3 vWorldPosition;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"void main() {",
 			"void main() {",
 
 
@@ -949,7 +949,7 @@ THREE.ShaderLib = {
 				"sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
 				"sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
 				"gl_FragColor = texture2D( tEquirect, sampleUV );",
 				"gl_FragColor = texture2D( tEquirect, sampleUV );",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
+				'#include <logdepthbuf_fragment>',
 
 
 			"}"
 			"}"
 
 
@@ -975,20 +975,20 @@ THREE.ShaderLib = {
 
 
 		vertexShader: [
 		vertexShader: [
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
-			THREE.ShaderChunk[ "skinning_pars_vertex" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
+			'#include <common>',
+			'#include <morphtarget_pars_vertex>',
+			'#include <skinning_pars_vertex>',
+			'#include <logdepthbuf_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "skinbase_vertex" ],
+				'#include <skinbase_vertex>',
 
 
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "skinning_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
-				THREE.ShaderChunk[ "logdepthbuf_vertex" ],
+				'#include <begin_vertex>',
+				'#include <morphtarget_vertex>',
+				'#include <skinning_vertex>',
+				'#include <project_vertex>',
+				'#include <logdepthbuf_vertex>',
 
 
 			"}"
 			"}"
 
 
@@ -996,8 +996,8 @@ THREE.ShaderLib = {
 
 
 		fragmentShader: [
 		fragmentShader: [
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
+			'#include <common>',
+			'#include <logdepthbuf_pars_fragment>',
 
 
 			"vec4 pack_depth( const in float depth ) {",
 			"vec4 pack_depth( const in float depth ) {",
 
 
@@ -1011,7 +1011,7 @@ THREE.ShaderLib = {
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
+				'#include <logdepthbuf_fragment>',
 
 
 			"	#ifdef USE_LOGDEPTHBUF_EXT",
 			"	#ifdef USE_LOGDEPTHBUF_EXT",
 
 
@@ -1047,18 +1047,18 @@ THREE.ShaderLib = {
 
 
 			"varying vec4 vWorldPosition;",
 			"varying vec4 vWorldPosition;",
 
 
-			THREE.ShaderChunk[ "common" ],
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
-			THREE.ShaderChunk[ "skinning_pars_vertex" ],
+			'#include <common>',
+			'#include <morphtarget_pars_vertex>',
+			'#include <skinning_pars_vertex>',
 
 
 			"void main() {",
 			"void main() {",
 
 
-				THREE.ShaderChunk[ "skinbase_vertex" ],
-				THREE.ShaderChunk[ "begin_vertex" ],
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "skinning_vertex" ],
-				THREE.ShaderChunk[ "project_vertex" ],
-				THREE.ShaderChunk[ "worldpos_vertex" ],
+				'#include <skinbase_vertex>',
+				'#include <begin_vertex>',
+				'#include <morphtarget_vertex>',
+				'#include <skinning_vertex>',
+				'#include <project_vertex>',
+				'#include <worldpos_vertex>',
 
 
 				"vWorldPosition = worldPosition;",
 				"vWorldPosition = worldPosition;",
 
 
@@ -1071,7 +1071,7 @@ THREE.ShaderLib = {
 			"uniform vec3 lightPos;",
 			"uniform vec3 lightPos;",
 			"varying vec4 vWorldPosition;",
 			"varying vec4 vWorldPosition;",
 
 
-			THREE.ShaderChunk[ "common" ],
+			'#include <common>',
 
 
 			"vec4 pack1K ( float depth ) {",
 			"vec4 pack1K ( float depth ) {",
 
 

+ 17 - 0
src/renderers/webgl/WebGLProgram.js

@@ -161,6 +161,20 @@ THREE.WebGLProgram = ( function () {
 
 
 	}
 	}
 
 
+	function parseIncludes( string ) {
+
+		var pattern = /#include +<([\w\d.]+)>/g;
+
+		function replace( match, include ) {
+
+			return THREE.ShaderChunk[ include ];
+
+		}
+
+		return string.replace( pattern, replace );
+
+	}
+
 	function unrollLoops( string ) {
 	function unrollLoops( string ) {
 
 
 		var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
 		var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
@@ -444,7 +458,10 @@ THREE.WebGLProgram = ( function () {
 
 
 		}
 		}
 
 
+		vertexShader = parseIncludes( vertexShader, parameters );
 		vertexShader = replaceLightNums( vertexShader, parameters );
 		vertexShader = replaceLightNums( vertexShader, parameters );
+
+		fragmentShader = parseIncludes( fragmentShader, parameters );
 		fragmentShader = replaceLightNums( fragmentShader, parameters );
 		fragmentShader = replaceLightNums( fragmentShader, parameters );
 
 
 		if ( material instanceof THREE.ShaderMaterial === false ) {
 		if ( material instanceof THREE.ShaderMaterial === false ) {

+ 1 - 1
src/textures/DataTexture.js

@@ -10,7 +10,7 @@ THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS
 
 
 	this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
 	this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
 	this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
 	this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
-	
+
 	this.flipY = false;
 	this.flipY = false;
 	this.generateMipmaps  = false;
 	this.generateMipmaps  = false;
 
 

+ 1 - 0
utils/build/includes/extras.json

@@ -20,6 +20,7 @@
 	"src/extras/curves/CatmullRomCurve3.js",
 	"src/extras/curves/CatmullRomCurve3.js",
 	"src/extras/curves/ClosedSplineCurve3.js",
 	"src/extras/curves/ClosedSplineCurve3.js",
 	"src/extras/geometries/BoxGeometry.js",
 	"src/extras/geometries/BoxGeometry.js",
+	"src/extras/geometries/BoxBufferGeometry.js",
 	"src/extras/geometries/CircleGeometry.js",
 	"src/extras/geometries/CircleGeometry.js",
 	"src/extras/geometries/CircleBufferGeometry.js",
 	"src/extras/geometries/CircleBufferGeometry.js",
 	"src/extras/geometries/CylinderGeometry.js",
 	"src/extras/geometries/CylinderGeometry.js",

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