浏览代码

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

# Conflicts:
#	src/renderers/shaders/ShaderLib.js
Ben Houston 9 年之前
父节点
当前提交
91d9af8983

文件差异内容过多而无法显示
+ 312 - 308
build/three.js


文件差异内容过多而无法显示
+ 82 - 122
build/three.min.js


+ 0 - 4
examples/js/Ocean.js

@@ -12,10 +12,6 @@
 
 	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
 	function optionalParameter( value, defaultValue ) {
 

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

@@ -17,11 +17,29 @@ THREE.STLBinaryExporter.prototype = {
 
 		return function parse( scene ) {
 
+			// We collect objects first, as we may need to convert from BufferGeometry to Geometry
+			var objects = [];
 			var triangles = 0;
 			scene.traverse( function ( object ) {
 
 				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 );
 			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 ++ ) {
 
@@ -65,7 +71,7 @@ THREE.STLBinaryExporter.prototype = {
 
 					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.y, true ); offset += 4;

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

@@ -420,7 +420,87 @@ THREE.ColladaLoader.prototype = {
 						break;
 
 					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;
 
 				}
@@ -497,24 +577,37 @@ THREE.ColladaLoader.prototype = {
 
 			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 ) {
 
 					var surface = effect.profile.surfaces[ sampler.source ];
 
 					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;
 
 					return texture;
 
 				}
 
-				console.error( 'ColladaLoder: Undefined sampler', sid );
+				console.error( 'ColladaLoder: Undefined sampler', textureObject.id );
 
 				return null;
 

+ 431 - 151
examples/js/loaders/VTKLoader.js

@@ -3,7 +3,7 @@
  * @author Alex Pletzer
  */
 
-THREE.VTKLoader = function ( manager ) {
+THREE.VTKLoader = function( manager ) {
 
 	this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
 
@@ -15,261 +15,541 @@ THREE.VTKLoader.prototype = {
 
 	load: function ( url, onLoad, onProgress, onError ) {
 
-		// Will we bump into trouble reading the whole file into memory?
 		var scope = this;
+
 		var loader = new THREE.XHRLoader( scope.manager );
-		loader.load( url, function ( text ) {
+		loader.setResponseType( 'arraybuffer' );
+		loader.load( url, function( text ) {
 
 			onLoad( scope.parse( text ) );
 
-		},
-
-		onProgress, onError );
+		}, onProgress, onError );
 
 	},
 
 	parse: function ( data ) {
 
-		// connectivity of the triangles
-		var indices = [];
+		function parseASCII( data ) {
 
-		// triangles vertices
-		var positions = [];
+			// connectivity of the triangles
+			var indices = [];
 
-		// red, green, blue colors in the range 0 to 1
-		var colors = [];
+			// triangles vertices
+			var positions = [];
 
-		// normal vector, one per vertex
-		var normals = [];
+			// red, green, blue colors in the range 0 to 1
+			var colors = [];
 
-		var result;
+			// normal vector, one per vertex
+			var normals = [];
 
-		// pattern for reading vertices, 3 floats or integers
-		var pat3Floats = /(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)/g;
+			var result;
 
-		// 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]*)/;
+			// pattern for reading vertices, 3 floats or integers
+			var pat3Floats = /(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)/g;
 
-		// indicates start of vertex data section
-		var patPOINTS = /^POINTS /;
+			// 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]*)/;
 
-		// indicates start of polygon connectivity section
-		var patPOLYGONS = /^POLYGONS /;
+			// indicates start of vertex data section
+			var patPOINTS = /^POINTS /;
 
-		// POINT_DATA number_of_values
-		var patPOINT_DATA = /^POINT_DATA[ ]+(\d+)/;
+			// indicates start of polygon connectivity section
+			var patPOLYGONS = /^POLYGONS /;
 
-		// CELL_DATA number_of_polys
-		var patCELL_DATA = /^CELL_DATA[ ]+(\d+)/;
+			// indicates start of triangle strips section
+			var patTRIANGLE_STRIPS = /^TRIANGLE_STRIPS /;
 
-		// Start of color section
-		var patCOLOR_SCALARS = /^COLOR_SCALARS[ ]+(\w+)[ ]+3/;
+			// POINT_DATA number_of_values
+			var patPOINT_DATA = /^POINT_DATA[ ]+(\d+)/;
 
-		// NORMALS Normals float
-		var patNORMALS = /^NORMALS[ ]+(\w+)[ ]+(\w+)/;
+			// CELL_DATA number_of_polys
+			var patCELL_DATA = /^CELL_DATA[ ]+(\d+)/;
 
-		var inPointsSection = false;
-		var inPolygonsSection = false;
-		var inPointDataSection = false;
-		var inCellDataSection = false;
-		var inColorSection = false;
-		var inNormalsSection = false;
+			// Start of color section
+			var patCOLOR_SCALARS = /^COLOR_SCALARS[ ]+(\w+)[ ]+3/;
 
-		var lines = data.split( '\n' );
+			// NORMALS Normals float
+			var patNORMALS = /^NORMALS[ ]+(\w+)[ ]+(\w+)/;
 
-		for ( var i in lines ) {
+			var inPointsSection = false;
+			var inPolygonsSection = false;
+			var inTriangleStripSection = false;
+			var inPointDataSection = false;
+			var inCellDataSection = false;
+			var inColorSection = false;
+			var inNormalsSection = false;
 
-			var line = lines[ i ];
+			var lines = data.split( '\n' );
 
-			if ( inPointsSection ) {
+			for ( var i in lines ) {
 
-				// get the vertices
-				while ( ( result = pat3Floats.exec( line ) ) !== null ) {
+				var line = lines[ i ];
 
-					var x = parseFloat( result[ 1 ] );
-					var y = parseFloat( result[ 2 ] );
-					var z = parseFloat( result[ 3 ] );
-					positions.push( x, y, z );
+				if ( inPointsSection ) {
 
-				}
+					// get the vertices
+					while ( ( result = pat3Floats.exec( line ) ) !== null ) {
 
-			} else if ( inPolygonsSection ) {
+						var x = parseFloat( result[ 1 ] );
+						var y = parseFloat( result[ 2 ] );
+						var z = parseFloat( result[ 3 ] );
+						positions.push( x, y, z );
 
-				if ( ( result = patConnectivity.exec( line ) ) !== null ) {
+					}
 
-					// numVertices i0 i1 i2 ...
-					var numVertices = parseInt( result[ 1 ] );
-					var inds = result[ 2 ].split( /\s+/ );
+				} else if ( inPolygonsSection ) {
 
-					if ( numVertices >= 3 ) {
+					if ( ( result = patConnectivity.exec( line ) ) !== null ) {
 
-						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 ) {
+						// numVertices i0 i1 i2 ...
+						var numVertices = parseInt( result[ 1 ] );
+						var inds = result[ 2 ].split( /\s+/ );
 
-							i1 = parseInt( inds[ k ] );
-							i2 = parseInt( inds[ k  + 1 ] );
-							indices.push( i0, i1, i2 );
-							k ++;
+						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 ) {
+
+								i1 = parseInt( inds[ k ] );
+								i2 = parseInt( inds[ k + 1 ] );
+								indices.push( i0, i1, i2 );
+								k ++;
+
+							}
 
 						}
 
 					}
 
-				}
+				} else if ( inTriangleStripSection ) {
 
-			} else if ( inPointDataSection || inCellDataSection ) {
+					if ( ( result = patConnectivity.exec( line ) ) !== null ) {
 
-				if ( inColorSection ) {
+						// numVertices i0 i1 i2 ...
+						var numVertices = parseInt( result[ 1 ] );
+						var inds = result[ 2 ].split( /\s+/ );
 
-					// Get the colors
+						if ( numVertices >= 3 ) {
 
-					while ( ( result = pat3Floats.exec( line ) ) !== null ) {
+							var i0, i1, i2;
+							// split the polygon in numVertices - 2 triangles
+							for ( var j = 0; j < numVertices - 2; j ++ ) {
+
+								if ( j % 2 === 1 ) {
+
+									i0 = parseInt( inds[ j ] );
+									i1 = parseInt( inds[ j + 2 ] );
+									i2 = parseInt( inds[ j + 1 ] );
+									indices.push( i0, i1, i2 );
+
+								} else {
 
-						var r = parseFloat( result[ 1 ] );
-						var g = parseFloat( result[ 2 ] );
-						var b = parseFloat( result[ 3 ] );
-						colors.push( r, g, b );
+									i0 = parseInt( inds[ j ] );
+									i1 = parseInt( inds[ j + 1 ] );
+									i2 = parseInt( inds[ j + 2 ] );
+									indices.push( i0, i1, i2 );
+
+								}
+
+							}
+
+						}
 
 					}
 
-				} else if ( inNormalsSection ) {
+				} else if ( inPointDataSection || inCellDataSection ) {
 
-					// Get the normal vectors
+					if ( inColorSection ) {
 
-					while ( ( result = pat3Floats.exec( line ) ) !== null ) {
+						// Get the colors
+
+						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 nx = parseFloat( result[ 1 ] );
-						var ny = parseFloat( result[ 2 ] );
-						var nz = parseFloat( result[ 3 ] );
-						normals.push( nx, ny, nz );
+					} else if ( inNormalsSection ) {
+
+						// Get the normal vectors
+
+						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 );
+
+						}
 
 					}
 
 				}
 
+				if ( patPOLYGONS.exec( line ) !== null ) {
+
+					inPolygonsSection = true;
+					inPointsSection = false;
+					inTriangleStripSection = false;
+
+				} else if ( patPOINTS.exec( line ) !== null ) {
+
+					inPolygonsSection = false;
+					inPointsSection = true;
+					inTriangleStripSection = false;
+
+				} else if ( patTRIANGLE_STRIPS.exec( line ) !== null ) {
+
+					inPolygonsSection = false;
+					inPointsSection = false;
+					inTriangleStripSection = true;
+
+				} else if ( patPOINT_DATA.exec( line ) !== null ) {
+
+					inPointDataSection = true;
+					inPointsSection = false;
+					inPolygonsSection = false;
+					inTriangleStripSection = false;
+
+				} else if ( patCELL_DATA.exec( line ) !== null ) {
+
+					inCellDataSection = true;
+					inPointsSection = false;
+					inPolygonsSection = false;
+					inTriangleStripSection = false;
+
+				} else if ( patCOLOR_SCALARS.exec( line ) !== null ) {
+
+					inColorSection = true;
+					inNormalsSection = false;
+					inPointsSection = false;
+					inPolygonsSection = false;
+					inTriangleStripSection = false;
+
+				} else if ( patNORMALS.exec( line ) !== null ) {
+
+					inNormalsSection = true;
+					inColorSection = false;
+					inPointsSection = false;
+					inPolygonsSection = false;
+					inTriangleStripSection = false;
+
+				}
+
 			}
 
-			if ( patPOLYGONS.exec( line ) !== null ) {
+			var geometry;
+			var stagger = 'point';
+
+			if ( colors.length == indices.length ) {
+
+				stagger = 'cell';
+
+			}
+
+			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 ) );
+
+				if ( colors.length == positions.length ) {
+
+					geometry.addAttribute( 'color', new THREE.BufferAttribute( new Float32Array( colors ), 3 ) );
 
-				inPolygonsSection = true;
-				inPointsSection = false;
+				}
+
+				if ( normals.length == positions.length ) {
 
-			} else if ( patPOINTS.exec( line ) !== null ) {
+					geometry.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( normals ), 3 ) );
 
-				inPolygonsSection = false;
-				inPointsSection = true;
+				}
 
-			} else if ( patPOINT_DATA.exec( line ) !== null ) {
+			} else {
 
-				inPointDataSection = true;
-				inPointsSection = false;
-				inPolygonsSection = false;
+				// 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();
 
-			} else if ( patCELL_DATA.exec( line ) !== null ) {
+				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;
 
-				inCellDataSection = true;
-				inPointsSection = false;
-				inPolygonsSection = false;
+				for ( var j = 0; j < numPoints; ++ j ) {
 
-			} else if ( patCOLOR_SCALARS.exec( line ) !== null ) {
+					x = positions[ 3 * j + 0 ];
+					y = positions[ 3 * j + 1 ];
+					z = positions[ 3 * j + 2 ];
+					geometry.vertices.push( new THREE.Vector3( x, y, z ) );
+
+				}
 
-				inColorSection = true;
-				inNormalsSection = false;
-				inPointsSection = false;
-				inPolygonsSection = false;
+				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 ) );
+
+				}
 
-			} else if ( patNORMALS.exec( line ) !== null ) {
+				if ( colors.length == numTriangles * 3 ) {
 
-				inNormalsSection = true;
-				inColorSection = false;
-				inPointsSection = false;
-				inPolygonsSection = false;
+					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 );
+
+					}
+
+				}
 
 			}
 
+			return geometry;
+
 		}
 
-		var geometry;
-		var stagger = 'point';
+		function parseBinary( data ) {
 
-		if ( colors.length == indices.length ) {
+			var count, pointIndex, i, numberOfPoints, pt, s;
+			var buffer = new Uint8Array ( data );
+			var dataView = new DataView ( data );
 
-			stagger = 'cell';
+			// Points and normals, by default, are empty
+			var points = [];
+			var normals = [];
+			var indices = [];
 
-		}
+			// Going to make a big array of strings
+			var vtk = [];
+			var index = 0;
+
+			function findString( buffer, start ) {
 
-		if ( stagger == 'point' ) {
+				var index = start;
+				var c = buffer[ index ];
+				var s = [];
+				while ( c != 10 ) {
 
-			// Nodal. Use BufferGeometry
-			geometry = new THREE.BufferGeometry();
-			geometry.setIndex( new THREE.BufferAttribute( new ( indices.length > 65535 ? Uint32Array : Uint16Array )( indices ), 1 ) );
-			geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( positions ), 3 ) );
+					s.push ( String.fromCharCode ( c ) );
+					index ++;
+					c = buffer[ index ];
 
-			if ( colors.length == positions.length ) {
+				}
 
-				geometry.addAttribute( 'color', new THREE.BufferAttribute( new Float32Array( colors ), 3 ) );
+				return { start: start,
+						end: index,
+						next: index + 1,
+						parsedString: s.join( '' ) };
 
 			}
 
-			if ( normals.length == positions.length ) {
+			var state, line;
 
-				geometry.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( normals ), 3 ) );
+			while ( true ) {
 
-			}
+				// Get a string
+				state = findString ( buffer, index );
+				line = state.parsedString;
 
-		} else {
+				if ( line.indexOf ( "POINTS" ) === 0 ) {
 
-			// 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();
+					vtk.push ( line );
+					// Add the points
+					numberOfPoints = parseInt ( line.split( " " )[ 1 ], 10 );
 
-			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;
+					// Each point is 3 4-byte floats
+					count = numberOfPoints * 4 * 3;
 
-			for ( var j = 0; j < numPoints; ++ j ) {
+					points = new Float32Array( numberOfPoints * 3 );
 
-				x = positions[ 3 * j + 0 ];
-				y = positions[ 3 * j + 1 ];
-				z = positions[ 3 * j + 2 ];
-				geometry.vertices.push( new THREE.Vector3( x, y, z ) );
+					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;
 
-			for ( var i = 0; i < numTriangles; ++ i ) {
+					}
+					// increment our next pointer
+					state.next = state.next + count + 1;
 
-				ia = indices[ 3 * i + 0 ];
-				ib = indices[ 3 * i + 1 ];
-				ic = indices[ 3 * i + 2 ];
-				geometry.faces.push( new THREE.Face3( ia, ib, ic ) );
+				} 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;
 
-			if ( colors.length == numTriangles * 3 ) {
+					indices = new Uint32Array( 3 * size - 9 * numberOfStrips );
+					var indicesIndex = 0;
 
-				for ( var i = 0; i < numTriangles; ++ 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 ++ ) {
+
+							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 ++ ) {
+
+							if ( j % 2 ) {
+
+								indices[ indicesIndex ++ ] = strip[ j ];
+								indices[ indicesIndex ++ ] = strip[ j + 2 ];
+								indices[ indicesIndex ++ ] = strip[ j + 1 ];
+
+							} else {
+
+
+								indices[ indicesIndex ++ ] = strip[ j ];
+								indices[ indicesIndex ++ ] = strip[ j + 1 ];
+								indices[ indicesIndex ++ ] = strip[ j + 2 ];
+
+							}
+
+						}
+
+					}
+					// increment our next pointer
+					state.next = state.next + count + 1;
+
+				} 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;
+
+					indices = new Uint32Array( 3 * size - 9 * numberOfStrips );
+					var indicesIndex = 0;
+
+					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 ++ ) {
+
+							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 ++ ) {
+
+							indices[ indicesIndex ++ ] = strip[ 0 ];
+							indices[ indicesIndex ++ ] = strip[ j ];
+							indices[ indicesIndex ++ ] = strip[ j + 1 ];
+
+						}
+
+					}
+					// increment our next pointer
+					state.next = state.next + count + 1;
+
+				} else if ( line.indexOf ( "POINT_DATA" ) === 0 ) {
+
+					numberOfPoints = parseInt ( line.split( " " )[ 1 ], 10 );
+
+					// Grab the next line
+					state = findString ( buffer, state.next );
+
+					// Now grab the binary data
+					count = numberOfPoints * 4 * 3;
+
+					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;
+
+					}
 
-					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 );
+					// Increment past our data
+					state.next = state.next + count;
 
 				}
 
-			 }
+				// Increment index
+				index = state.next;
+
+				if ( index >= buffer.byteLength ) {
+
+					break;
+
+				}
+
+			}
+
+			var geometry = new THREE.BufferGeometry();
+			geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
+			geometry.addAttribute( 'position', new THREE.BufferAttribute( points, 3 ) );
+
+			if ( normals.length == points.length ) {
+
+				geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
+
+			}
+
+			return geometry;
 
 		}
 
-		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 stringFile = '';
+			var charArray = new Uint8Array( data );
+			for ( var i = 0; i < charArray.length; i ++ ) {
+
+				stringFile += String.fromCharCode( charArray[ i ] );
+
+			}
+
+			return parseASCII( stringFile );
+
+		} else {
+
+			return parseBinary( data );
+
+		}
 
 	}
 

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

@@ -29,7 +29,7 @@ THREE.ShadowMaterial = function () {
 			THREE.ShaderChunk[ "shadowmask_pars_fragment" ],
 			"uniform float opacity;",
 			"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' )
 	} );

+ 20 - 14
examples/webgl_effects_cardboard.html

@@ -25,37 +25,39 @@
 
 			function init() {
 
-				camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 100 );
-				camera.position.set( 3, 2, 3 );
-				camera.lookAt( new THREE.Vector3() );
-				camera.focalLength = camera.position.distanceTo( new THREE.Vector3() );
-
 				scene = new THREE.Scene();
 
-				var geometry = new THREE.CubeGeometry( 1, 1, 1 );
-				var material = new THREE.MeshStandardMaterial();
+				camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10 );
+				camera.position.set( 3, 2, 3 );
+				camera.focalLength = camera.position.distanceTo( scene.position );
+				camera.lookAt( scene.position );
+
+				var geometry = new THREE.TorusKnotGeometry( 0.4, 0.15, 150, 20 );;
+				var material = new THREE.MeshStandardMaterial( { roughness: 0.01, metalness: 0.2 } );
 				var mesh = new THREE.Mesh( geometry, material );
-				mesh.position.y = 0.5;
+				mesh.position.y = 0.75;
 				mesh.castShadow = true;
 				mesh.receiveShadow = true;
 				scene.add( mesh );
 
-				var geometry = new THREE.PlaneGeometry( 4, 4 );
-				geometry.rotateX( - Math.PI / 2 );
-				var material = new THREE.MeshStandardMaterial();
+				var geometry = new THREE.BoxGeometry( 3, 0.1, 3 );
+				var material = new THREE.MeshStandardMaterial( { roughness: 1.0, metalness: 0.0 } );
 				var mesh = new THREE.Mesh( geometry, material );
+				mesh.position.y = - 0.1;
 				mesh.castShadow = true;
 				mesh.receiveShadow = true;
 				scene.add( mesh );
 
-				var light = new THREE.DirectionalLight( 0xffffff );
+				var light = new THREE.DirectionalLight( 0x8800ff );
 				light.position.set( - 1, 1.5, 0.5 );
 				light.castShadow = true;
+				light.shadow.camera.zoom = 4;
 				scene.add( light );
 
-				var light = new THREE.DirectionalLight( 0xff0000, 1.5 );
+				var light = new THREE.DirectionalLight( 0xff0000 );
 				light.position.set( 1, 1.5, - 0.5 );
 				light.castShadow = true;
+				light.shadow.camera.zoom = 4;
 				scene.add( light );
 
 				//
@@ -118,11 +120,15 @@
 
 			function render() {
 
-				var time = performance.now() * 0.0005;
+				var time = performance.now() * 0.0002;
 				camera.position.x = Math.cos( time ) * 4;
 				camera.position.z = Math.sin( time ) * 4;
 				camera.lookAt( new THREE.Vector3() );
 
+				var mesh = scene.children[ 0 ];
+				mesh.rotation.x = time * 2;
+				mesh.rotation.y = time * 5;
+
 				effect.render( scene, camera );
 
 			}

+ 1 - 1
examples/webgl_geometry_cube.html

@@ -33,7 +33,7 @@
 
 				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 } );
 
 				mesh = new THREE.Mesh( geometry, material );

+ 1 - 1
examples/webgl_interactive_cubes.html

@@ -51,7 +51,7 @@
 				light.position.set( 1, 1, 1 ).normalize();
 				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 ++ ) {
 

+ 1 - 1
examples/webgl_interactive_cubes_ortho.html

@@ -53,7 +53,7 @@
 				light.position.set( 1, 1, 1 ).normalize();
 				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 ++ ) {
 

+ 21 - 6
examples/webgl_materials_displacementmap.html

@@ -66,14 +66,16 @@
 			var settings = {
 				metalness: 1.0,
 				roughness: 0.4,
+				ambientIntensity: 0.2,
 				aoMapIntensity: 1.0,
-				displacementScale: 1.0,
+				envMapIntensity: 1.0,
+				displacementScale: 2.436143, // from original model
 				normalScale: 1.0
 			};
 
 			var mesh, material;
 
-			var pointLight;
+			var pointLight, ambientLight;
 
 			var mouseX = 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 ) {
 
 					material.displacementScale = value;
@@ -120,7 +134,7 @@
 
 				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
 
-				var ambientLight = new THREE.AmbientLight( 0x111111 );
+				ambientLight = new THREE.AmbientLight( 0xffffff, settings.ambientIntensity );
 				scene.add( ambientLight );
 
 				pointLight = new THREE.PointLight( 0xff0000, 0.5 );
@@ -206,10 +220,11 @@
 					aoMapIntensity: 1,
 
 					displacementMap: displacementMap,
-					displacementScale: 2.436143,
-					displacementBias: - 0.428408,
+					displacementScale: settings.displacementScale,
+					displacementBias: - 0.428408, // from original model
 
 					envMap: reflectionCube,
+					envMapIntensity: settings.envMapIntensity,
 
 					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 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 );
 
@@ -296,7 +296,7 @@ THREE.Geometry.prototype = {
 
 					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
 	};
 
-	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 ) );
 
 };
 

文件差异内容过多而无法显示
+ 316 - 323
src/renderers/shaders/ShaderLib.js


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

@@ -192,6 +192,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 ) {
 
 		var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
@@ -477,7 +491,10 @@ THREE.WebGLProgram = ( function () {
 
 		}
 
+		vertexShader = parseIncludes( vertexShader, parameters );
 		vertexShader = replaceLightNums( vertexShader, parameters );
+
+		fragmentShader = parseIncludes( fragmentShader, parameters );
 		fragmentShader = replaceLightNums( fragmentShader, parameters );
 
 		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.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
-	
+
 	this.flipY = false;
 	this.generateMipmaps  = false;
 

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

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

部分文件因为文件数量过多而无法显示