Browse Source

Merge pull request #16571 from Mugen87/dev30

JSM: Added more module and TS files for geometries.
Michael Herzog 6 years ago
parent
commit
212274917d

+ 8 - 0
docs/manual/en/introduction/Import-via-modules.html

@@ -124,6 +124,14 @@
 						<li>TypedGeometryExporter</li>
 					</ul>
 				</li>
+				<li>geometries
+					<ul>
+						<li>BoxLineGeometry</li>
+						<li>DecalGeometry</li>
+						<li>ParametricGeometries</li>
+						<li>TeapotBufferGeometry</li>
+					</ul>
+				</li>
 				<li>loaders
 					<ul>
 						<li>3MFLoader</li>

+ 13 - 13
examples/js/geometries/BoxLineGeometry.js

@@ -28,10 +28,10 @@ THREE.BoxLineGeometry = function ( width, height, depth, widthSegments, heightSe
 
 	for ( var i = 0; i <= widthSegments; i ++ ) {
 
-		vertices.push( x, - heightHalf, - depthHalf, x,   heightHalf, - depthHalf );
-		vertices.push( x,   heightHalf, - depthHalf, x,   heightHalf,   depthHalf );
-		vertices.push( x,   heightHalf,   depthHalf, x, - heightHalf,   depthHalf );
-		vertices.push( x, - heightHalf,   depthHalf, x, - heightHalf, - depthHalf );
+		vertices.push( x, - heightHalf, - depthHalf, x, heightHalf, - depthHalf );
+		vertices.push( x, heightHalf, - depthHalf, x, heightHalf, depthHalf );
+		vertices.push( x, heightHalf, depthHalf, x, - heightHalf, depthHalf );
+		vertices.push( x, - heightHalf, depthHalf, x, - heightHalf, - depthHalf );
 
 		x += segmentWidth;
 
@@ -39,10 +39,10 @@ THREE.BoxLineGeometry = function ( width, height, depth, widthSegments, heightSe
 
 	for ( var i = 0; i <= heightSegments; i ++ ) {
 
-		vertices.push( - widthHalf, y, - depthHalf,   widthHalf, y, - depthHalf );
-		vertices.push(   widthHalf, y, - depthHalf,   widthHalf, y,   depthHalf );
-		vertices.push(   widthHalf, y,   depthHalf, - widthHalf, y,   depthHalf );
-		vertices.push( - widthHalf, y,   depthHalf, - widthHalf, y, - depthHalf );
+		vertices.push( - widthHalf, y, - depthHalf, widthHalf, y, - depthHalf );
+		vertices.push( widthHalf, y, - depthHalf, widthHalf, y, depthHalf );
+		vertices.push( widthHalf, y, depthHalf, - widthHalf, y, depthHalf );
+		vertices.push( - widthHalf, y, depthHalf, - widthHalf, y, - depthHalf );
 
 		y += segmentHeight;
 
@@ -50,10 +50,10 @@ THREE.BoxLineGeometry = function ( width, height, depth, widthSegments, heightSe
 
 	for ( var i = 0; i <= depthSegments; i ++ ) {
 
-		vertices.push( - widthHalf, - heightHalf, z, - widthHalf,   heightHalf, z );
-		vertices.push( - widthHalf,   heightHalf, z,   widthHalf,   heightHalf, z );
-		vertices.push(   widthHalf,   heightHalf, z,   widthHalf, - heightHalf, z );
-		vertices.push(   widthHalf, - heightHalf, z, - widthHalf, - heightHalf, z );
+		vertices.push( - widthHalf, - heightHalf, z, - widthHalf, heightHalf, z );
+		vertices.push( - widthHalf, heightHalf, z, widthHalf, heightHalf, z );
+		vertices.push( widthHalf, heightHalf, z, widthHalf, - heightHalf, z );
+		vertices.push( widthHalf, - heightHalf, z, - widthHalf, - heightHalf, z );
 
 		z += segmentDepth;
 
@@ -61,7 +61,7 @@ THREE.BoxLineGeometry = function ( width, height, depth, widthSegments, heightSe
 
 	this.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
 
-}
+};
 
 THREE.BoxLineGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
 THREE.BoxLineGeometry.prototype.constructor = THREE.BoxLineGeometry;

+ 202 - 210
examples/js/geometries/DecalGeometry.js

@@ -16,342 +16,334 @@
  *
  */
 
-( function () {
+THREE.DecalGeometry = function ( mesh, position, orientation, size ) {
 
-	function DecalGeometry( mesh, position, orientation, size ) {
+	THREE.BufferGeometry.call( this );
 
-		THREE.BufferGeometry.call( this );
+	// buffers
 
-		// buffers
+	var vertices = [];
+	var normals = [];
+	var uvs = [];
 
-		var vertices = [];
-		var normals = [];
-		var uvs = [];
+	// helpers
 
-		// helpers
+	var plane = new THREE.Vector3();
 
-		var plane = new THREE.Vector3();
+	// this matrix represents the transformation of the decal projector
 
-		// this matrix represents the transformation of the decal projector
+	var projectorMatrix = new THREE.Matrix4();
+	projectorMatrix.makeRotationFromEuler( orientation );
+	projectorMatrix.setPosition( position );
 
-		var projectorMatrix = new THREE.Matrix4();
-		projectorMatrix.makeRotationFromEuler( orientation );
-		projectorMatrix.setPosition( position );
+	var projectorMatrixInverse = new THREE.Matrix4().getInverse( projectorMatrix );
 
-		var projectorMatrixInverse = new THREE.Matrix4().getInverse( projectorMatrix );
+	// generate buffers
 
-		// generate buffers
+	generate();
 
-		generate();
+	// build geometry
 
-		// build geometry
+	this.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
+	this.addAttribute( 'normal', new THREE.Float32BufferAttribute( normals, 3 ) );
+	this.addAttribute( 'uv', new THREE.Float32BufferAttribute( uvs, 2 ) );
 
-		this.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
-		this.addAttribute( 'normal', new THREE.Float32BufferAttribute( normals, 3 ) );
-		this.addAttribute( 'uv', new THREE.Float32BufferAttribute( uvs, 2 ) );
+	function generate() {
 
-		function generate() {
+		var i;
+		var geometry = new THREE.BufferGeometry();
+		var decalVertices = [];
 
-			var i;
-			var geometry = new THREE.BufferGeometry();
-			var decalVertices = [];
+		var vertex = new THREE.Vector3();
+		var normal = new THREE.Vector3();
 
-			var vertex = new THREE.Vector3();
-			var normal = new THREE.Vector3();
+		// handle different geometry types
 
-			// handle different geometry types
+		if ( mesh.geometry.isGeometry ) {
 
-			if ( mesh.geometry.isGeometry ) {
+			geometry.fromGeometry( mesh.geometry );
 
-				geometry.fromGeometry( mesh.geometry );
+		} else {
 
-			} else {
+			geometry.copy( mesh.geometry );
 
-				geometry.copy( mesh.geometry );
-
-			}
+		}
 
-			var positionAttribute = geometry.attributes.position;
-			var normalAttribute = geometry.attributes.normal;
+		var positionAttribute = geometry.attributes.position;
+		var normalAttribute = geometry.attributes.normal;
 
-			// first, create an array of 'DecalVertex' objects
-			// three consecutive 'DecalVertex' objects represent a single face
-			//
-			// this data structure will be later used to perform the clipping
+		// first, create an array of 'DecalVertex' objects
+		// three consecutive 'DecalVertex' objects represent a single face
+		//
+		// this data structure will be later used to perform the clipping
 
-			if ( geometry.index !== null ) {
+		if ( geometry.index !== null ) {
 
-				// indexed BufferGeometry
+			// indexed BufferGeometry
 
-				var index = geometry.index;
+			var index = geometry.index;
 
-				for ( i = 0; i < index.count; i ++ ) {
+			for ( i = 0; i < index.count; i ++ ) {
 
-					vertex.fromBufferAttribute( positionAttribute, index.getX( i ) );
-					normal.fromBufferAttribute( normalAttribute, index.getX( i ) );
+				vertex.fromBufferAttribute( positionAttribute, index.getX( i ) );
+				normal.fromBufferAttribute( normalAttribute, index.getX( i ) );
 
-					pushDecalVertex( decalVertices, vertex, normal );
+				pushDecalVertex( decalVertices, vertex, normal );
 
-				}
-
-			} else {
+			}
 
-				// non-indexed BufferGeometry
+		} else {
 
-				for ( i = 0; i < positionAttribute.count; i ++ ) {
+			// non-indexed BufferGeometry
 
-					vertex.fromBufferAttribute( positionAttribute, i );
-					normal.fromBufferAttribute( normalAttribute, i );
+			for ( i = 0; i < positionAttribute.count; i ++ ) {
 
-					pushDecalVertex( decalVertices, vertex, normal );
+				vertex.fromBufferAttribute( positionAttribute, i );
+				normal.fromBufferAttribute( normalAttribute, i );
 
-				}
+				pushDecalVertex( decalVertices, vertex, normal );
 
 			}
 
-			// second, clip the geometry so that it doesn't extend out from the projector
-
-			decalVertices = clipGeometry( decalVertices, plane.set( 1, 0, 0 ) );
-			decalVertices = clipGeometry( decalVertices, plane.set( - 1, 0, 0 ) );
-			decalVertices = clipGeometry( decalVertices, plane.set( 0, 1, 0 ) );
-			decalVertices = clipGeometry( decalVertices, plane.set( 0, - 1, 0 ) );
-			decalVertices = clipGeometry( decalVertices, plane.set( 0, 0, 1 ) );
-			decalVertices = clipGeometry( decalVertices, plane.set( 0, 0, - 1 ) );
-
-			// third, generate final vertices, normals and uvs
-
-			for ( i = 0; i < decalVertices.length; i ++ ) {
-
-				var decalVertex = decalVertices[ i ];
-
-				// create texture coordinates (we are still in projector space)
+		}
 
-				uvs.push(
-					0.5 + ( decalVertex.position.x / size.x ),
-					0.5 + ( decalVertex.position.y / size.y )
-				);
+		// second, clip the geometry so that it doesn't extend out from the projector
 
-				// transform the vertex back to world space
+		decalVertices = clipGeometry( decalVertices, plane.set( 1, 0, 0 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( - 1, 0, 0 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( 0, 1, 0 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( 0, - 1, 0 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( 0, 0, 1 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( 0, 0, - 1 ) );
 
-				decalVertex.position.applyMatrix4( projectorMatrix );
+		// third, generate final vertices, normals and uvs
 
-				// now create vertex and normal buffer data
+		for ( i = 0; i < decalVertices.length; i ++ ) {
 
-				vertices.push( decalVertex.position.x, decalVertex.position.y, decalVertex.position.z );
-				normals.push( decalVertex.normal.x, decalVertex.normal.y, decalVertex.normal.z );
+			var decalVertex = decalVertices[ i ];
 
-			}
+			// create texture coordinates (we are still in projector space)
 
-		}
+			uvs.push(
+				0.5 + ( decalVertex.position.x / size.x ),
+				0.5 + ( decalVertex.position.y / size.y )
+			);
 
-		function pushDecalVertex( decalVertices, vertex, normal ) {
+			// transform the vertex back to world space
 
-			// transform the vertex to world space, then to projector space
+			decalVertex.position.applyMatrix4( projectorMatrix );
 
-			vertex.applyMatrix4( mesh.matrixWorld );
-			vertex.applyMatrix4( projectorMatrixInverse );
+			// now create vertex and normal buffer data
 
-			decalVertices.push( new DecalVertex( vertex.clone(), normal.clone() ) );
+			vertices.push( decalVertex.position.x, decalVertex.position.y, decalVertex.position.z );
+			normals.push( decalVertex.normal.x, decalVertex.normal.y, decalVertex.normal.z );
 
 		}
 
-		function clipGeometry( inVertices, plane ) {
+	}
 
-			var outVertices = [];
+	function pushDecalVertex( decalVertices, vertex, normal ) {
 
-			var s = 0.5 * Math.abs( size.dot( plane ) );
+		// transform the vertex to world space, then to projector space
 
-			// a single iteration clips one face,
-			// which consists of three consecutive 'DecalVertex' objects
+		vertex.applyMatrix4( mesh.matrixWorld );
+		vertex.applyMatrix4( projectorMatrixInverse );
 
-			for ( var i = 0; i < inVertices.length; i += 3 ) {
+		decalVertices.push( new THREE.DecalVertex( vertex.clone(), normal.clone() ) );
 
-				var v1Out, v2Out, v3Out, total = 0;
-				var nV1, nV2, nV3, nV4;
+	}
 
-				var d1 = inVertices[ i + 0 ].position.dot( plane ) - s;
-				var d2 = inVertices[ i + 1 ].position.dot( plane ) - s;
-				var d3 = inVertices[ i + 2 ].position.dot( plane ) - s;
+	function clipGeometry( inVertices, plane ) {
 
-				v1Out = d1 > 0;
-				v2Out = d2 > 0;
-				v3Out = d3 > 0;
+		var outVertices = [];
 
-				// calculate, how many vertices of the face lie outside of the clipping plane
+		var s = 0.5 * Math.abs( size.dot( plane ) );
 
-				total = ( v1Out ? 1 : 0 ) + ( v2Out ? 1 : 0 ) + ( v3Out ? 1 : 0 );
+		// a single iteration clips one face,
+		// which consists of three consecutive 'DecalVertex' objects
 
-				switch ( total ) {
+		for ( var i = 0; i < inVertices.length; i += 3 ) {
 
-					case 0: {
+			var v1Out, v2Out, v3Out, total = 0;
+			var nV1, nV2, nV3, nV4;
 
-						// the entire face lies inside of the plane, no clipping needed
+			var d1 = inVertices[ i + 0 ].position.dot( plane ) - s;
+			var d2 = inVertices[ i + 1 ].position.dot( plane ) - s;
+			var d3 = inVertices[ i + 2 ].position.dot( plane ) - s;
 
-						outVertices.push( inVertices[ i ] );
-						outVertices.push( inVertices[ i + 1 ] );
-						outVertices.push( inVertices[ i + 2 ] );
-						break;
+			v1Out = d1 > 0;
+			v2Out = d2 > 0;
+			v3Out = d3 > 0;
 
-					}
+			// calculate, how many vertices of the face lie outside of the clipping plane
 
-					case 1: {
+			total = ( v1Out ? 1 : 0 ) + ( v2Out ? 1 : 0 ) + ( v3Out ? 1 : 0 );
 
-						// one vertex lies outside of the plane, perform clipping
+			switch ( total ) {
 
-						if ( v1Out ) {
+				case 0: {
 
-							nV1 = inVertices[ i + 1 ];
-							nV2 = inVertices[ i + 2 ];
-							nV3 = clip( inVertices[ i ], nV1, plane, s );
-							nV4 = clip( inVertices[ i ], nV2, plane, s );
+					// the entire face lies inside of the plane, no clipping needed
 
-						}
+					outVertices.push( inVertices[ i ] );
+					outVertices.push( inVertices[ i + 1 ] );
+					outVertices.push( inVertices[ i + 2 ] );
+					break;
 
-						if ( v2Out ) {
+				}
 
-							nV1 = inVertices[ i ];
-							nV2 = inVertices[ i + 2 ];
-							nV3 = clip( inVertices[ i + 1 ], nV1, plane, s );
-							nV4 = clip( inVertices[ i + 1 ], nV2, plane, s );
+				case 1: {
 
-							outVertices.push( nV3 );
-							outVertices.push( nV2.clone() );
-							outVertices.push( nV1.clone() );
+					// one vertex lies outside of the plane, perform clipping
 
-							outVertices.push( nV2.clone() );
-							outVertices.push( nV3.clone() );
-							outVertices.push( nV4 );
-							break;
+					if ( v1Out ) {
 
-						}
+						nV1 = inVertices[ i + 1 ];
+						nV2 = inVertices[ i + 2 ];
+						nV3 = clip( inVertices[ i ], nV1, plane, s );
+						nV4 = clip( inVertices[ i ], nV2, plane, s );
 
-						if ( v3Out ) {
+					}
 
-							nV1 = inVertices[ i ];
-							nV2 = inVertices[ i + 1 ];
-							nV3 = clip( inVertices[ i + 2 ], nV1, plane, s );
-							nV4 = clip( inVertices[ i + 2 ], nV2, plane, s );
+					if ( v2Out ) {
 
-						}
+						nV1 = inVertices[ i ];
+						nV2 = inVertices[ i + 2 ];
+						nV3 = clip( inVertices[ i + 1 ], nV1, plane, s );
+						nV4 = clip( inVertices[ i + 1 ], nV2, plane, s );
 
-						outVertices.push( nV1.clone() );
-						outVertices.push( nV2.clone() );
 						outVertices.push( nV3 );
-
-						outVertices.push( nV4 );
-						outVertices.push( nV3.clone() );
 						outVertices.push( nV2.clone() );
+						outVertices.push( nV1.clone() );
 
+						outVertices.push( nV2.clone() );
+						outVertices.push( nV3.clone() );
+						outVertices.push( nV4 );
 						break;
 
 					}
 
-					case 2: {
+					if ( v3Out ) {
 
-						// two vertices lies outside of the plane, perform clipping
+						nV1 = inVertices[ i ];
+						nV2 = inVertices[ i + 1 ];
+						nV3 = clip( inVertices[ i + 2 ], nV1, plane, s );
+						nV4 = clip( inVertices[ i + 2 ], nV2, plane, s );
 
-						if ( ! v1Out ) {
-
-							nV1 = inVertices[ i ].clone();
-							nV2 = clip( nV1, inVertices[ i + 1 ], plane, s );
-							nV3 = clip( nV1, inVertices[ i + 2 ], plane, s );
-							outVertices.push( nV1 );
-							outVertices.push( nV2 );
-							outVertices.push( nV3 );
+					}
 
-						}
+					outVertices.push( nV1.clone() );
+					outVertices.push( nV2.clone() );
+					outVertices.push( nV3 );
 
-						if ( ! v2Out ) {
+					outVertices.push( nV4 );
+					outVertices.push( nV3.clone() );
+					outVertices.push( nV2.clone() );
 
-							nV1 = inVertices[ i + 1 ].clone();
-							nV2 = clip( nV1, inVertices[ i + 2 ], plane, s );
-							nV3 = clip( nV1, inVertices[ i ], plane, s );
-							outVertices.push( nV1 );
-							outVertices.push( nV2 );
-							outVertices.push( nV3 );
+					break;
 
-						}
+				}
 
-						if ( ! v3Out ) {
+				case 2: {
 
-							nV1 = inVertices[ i + 2 ].clone();
-							nV2 = clip( nV1, inVertices[ i ], plane, s );
-							nV3 = clip( nV1, inVertices[ i + 1 ], plane, s );
-							outVertices.push( nV1 );
-							outVertices.push( nV2 );
-							outVertices.push( nV3 );
+					// two vertices lies outside of the plane, perform clipping
 
-						}
+					if ( ! v1Out ) {
 
-						break;
+						nV1 = inVertices[ i ].clone();
+						nV2 = clip( nV1, inVertices[ i + 1 ], plane, s );
+						nV3 = clip( nV1, inVertices[ i + 2 ], plane, s );
+						outVertices.push( nV1 );
+						outVertices.push( nV2 );
+						outVertices.push( nV3 );
 
 					}
 
-					case 3: {
+					if ( ! v2Out ) {
 
-						// the entire face lies outside of the plane, so let's discard the corresponding vertices
-
-						break;
+						nV1 = inVertices[ i + 1 ].clone();
+						nV2 = clip( nV1, inVertices[ i + 2 ], plane, s );
+						nV3 = clip( nV1, inVertices[ i ], plane, s );
+						outVertices.push( nV1 );
+						outVertices.push( nV2 );
+						outVertices.push( nV3 );
 
 					}
 
-				}
+					if ( ! v3Out ) {
 
-			}
+						nV1 = inVertices[ i + 2 ].clone();
+						nV2 = clip( nV1, inVertices[ i ], plane, s );
+						nV3 = clip( nV1, inVertices[ i + 1 ], plane, s );
+						outVertices.push( nV1 );
+						outVertices.push( nV2 );
+						outVertices.push( nV3 );
 
-			return outVertices;
+					}
 
-		}
+					break;
 
-		function clip( v0, v1, p, s ) {
+				}
 
-			var d0 = v0.position.dot( p ) - s;
-			var d1 = v1.position.dot( p ) - s;
+				case 3: {
 
-			var s0 = d0 / ( d0 - d1 );
+					// the entire face lies outside of the plane, so let's discard the corresponding vertices
 
-			var v = new DecalVertex(
-				new THREE.Vector3(
-					v0.position.x + s0 * ( v1.position.x - v0.position.x ),
-					v0.position.y + s0 * ( v1.position.y - v0.position.y ),
-					v0.position.z + s0 * ( v1.position.z - v0.position.z )
-				),
-				new THREE.Vector3(
-					v0.normal.x + s0 * ( v1.normal.x - v0.normal.x ),
-					v0.normal.y + s0 * ( v1.normal.y - v0.normal.y ),
-					v0.normal.z + s0 * ( v1.normal.z - v0.normal.z )
-				)
-			);
+					break;
 
-			// need to clip more values (texture coordinates)? do it this way:
-			// intersectpoint.value = a.value + s * ( b.value - a.value );
+				}
 
-			return v;
+			}
 
 		}
 
+		return outVertices;
+
 	}
 
-	DecalGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
-	DecalGeometry.prototype.constructor = DecalGeometry;
+	function clip( v0, v1, p, s ) {
+
+		var d0 = v0.position.dot( p ) - s;
+		var d1 = v1.position.dot( p ) - s;
+
+		var s0 = d0 / ( d0 - d1 );
 
-	// helper
+		var v = new THREE.DecalVertex(
+			new THREE.Vector3(
+				v0.position.x + s0 * ( v1.position.x - v0.position.x ),
+				v0.position.y + s0 * ( v1.position.y - v0.position.y ),
+				v0.position.z + s0 * ( v1.position.z - v0.position.z )
+			),
+			new THREE.Vector3(
+				v0.normal.x + s0 * ( v1.normal.x - v0.normal.x ),
+				v0.normal.y + s0 * ( v1.normal.y - v0.normal.y ),
+				v0.normal.z + s0 * ( v1.normal.z - v0.normal.z )
+			)
+		);
 
-	function DecalVertex( position, normal ) {
+		// need to clip more values (texture coordinates)? do it this way:
+		// intersectpoint.value = a.value + s * ( b.value - a.value );
 
-		this.position = position;
-		this.normal = normal;
+		return v;
 
 	}
 
-	DecalVertex.prototype.clone = function () {
+};
+
+THREE.DecalGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
+THREE.DecalGeometry.prototype.constructor = THREE.DecalGeometry;
+
+// helper
+
+THREE.DecalVertex = function ( position, normal ) {
 
-		return new DecalVertex( this.position.clone(), this.normal.clone() );
+	this.position = position;
+	this.normal = normal;
 
-	};
+};
 
-	// export
+THREE.DecalVertex.prototype.clone = function () {
 
-	THREE.DecalGeometry = DecalGeometry;
+	return new this.constructor( this.position.clone(), this.normal.clone() );
 
-} )();
+};

+ 1 - 4
examples/js/geometries/TeapotBufferGeometry.js

@@ -3,9 +3,7 @@
  *
  * Tessellates the famous Utah teapot database by Martin Newell into triangles.
  *
- * THREE.TeapotBufferGeometry = function ( size, segments, bottom, lid, body, fitLid, blinn )
- *
- * defaults: size = 50, segments = 10, bottom = true, lid = true, body = true,
+ * Parameters: size = 50, segments = 10, bottom = true, lid = true, body = true,
  *   fitLid = false, blinn = true
  *
  * size is a relative scale: I've scaled the teapot to fit vertically between -1 and 1.
@@ -50,7 +48,6 @@
  * See https://en.wikipedia.org/wiki/Utah_teapot for the history of the teapot
  *
  */
-/*global THREE */
 
 THREE.TeapotBufferGeometry = function ( size, segments, bottom, lid, body, fitLid, blinn ) {
 

+ 7 - 0
examples/jsm/geometries/BoxLineGeometry.d.ts

@@ -0,0 +1,7 @@
+import {
+  BufferGeometry
+} from '../../../src/Three';
+
+export class BoxLineGeometry extends BufferGeometry {
+  constructor(width?: number, height?: number, depth?: number, widthSegments?: number, heightSegments?: number, depthSegments?: number);
+}

+ 74 - 0
examples/jsm/geometries/BoxLineGeometry.js

@@ -0,0 +1,74 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ */
+
+import {
+	BufferGeometry,
+	Float32BufferAttribute
+} from "../../../build/three.module.js";
+
+var BoxLineGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
+
+	BufferGeometry.call( this );
+
+	width = width || 1;
+	height = height || 1;
+	depth = depth || 1;
+
+	widthSegments = Math.floor( widthSegments ) || 1;
+	heightSegments = Math.floor( heightSegments ) || 1;
+	depthSegments = Math.floor( depthSegments ) || 1;
+
+	var widthHalf = width / 2;
+	var heightHalf = height / 2;
+	var depthHalf = depth / 2;
+
+	var segmentWidth = width / widthSegments;
+	var segmentHeight = height / heightSegments;
+	var segmentDepth = depth / depthSegments;
+
+	var vertices = [];
+
+	var x = - widthHalf, y = - heightHalf, z = - depthHalf;
+
+	for ( var i = 0; i <= widthSegments; i ++ ) {
+
+		vertices.push( x, - heightHalf, - depthHalf, x, heightHalf, - depthHalf );
+		vertices.push( x, heightHalf, - depthHalf, x, heightHalf, depthHalf );
+		vertices.push( x, heightHalf, depthHalf, x, - heightHalf, depthHalf );
+		vertices.push( x, - heightHalf, depthHalf, x, - heightHalf, - depthHalf );
+
+		x += segmentWidth;
+
+	}
+
+	for ( var i = 0; i <= heightSegments; i ++ ) {
+
+		vertices.push( - widthHalf, y, - depthHalf, widthHalf, y, - depthHalf );
+		vertices.push( widthHalf, y, - depthHalf, widthHalf, y, depthHalf );
+		vertices.push( widthHalf, y, depthHalf, - widthHalf, y, depthHalf );
+		vertices.push( - widthHalf, y, depthHalf, - widthHalf, y, - depthHalf );
+
+		y += segmentHeight;
+
+	}
+
+	for ( var i = 0; i <= depthSegments; i ++ ) {
+
+		vertices.push( - widthHalf, - heightHalf, z, - widthHalf, heightHalf, z );
+		vertices.push( - widthHalf, heightHalf, z, widthHalf, heightHalf, z );
+		vertices.push( widthHalf, heightHalf, z, widthHalf, - heightHalf, z );
+		vertices.push( widthHalf, - heightHalf, z, - widthHalf, - heightHalf, z );
+
+		z += segmentDepth;
+
+	}
+
+	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+
+};
+
+BoxLineGeometry.prototype = Object.create( BufferGeometry.prototype );
+BoxLineGeometry.prototype.constructor = BoxLineGeometry;
+
+export { BoxLineGeometry };

+ 15 - 0
examples/jsm/geometries/DecalGeometry.d.ts

@@ -0,0 +1,15 @@
+import {
+  BufferGeometry,
+  Euler,
+  Mesh,
+  Vector3
+} from '../../../src/Three';
+
+export class DecalGeometry extends BufferGeometry {
+  constructor(mesh: Mesh, position: Vector3, orientation: Euler, size: Vector3);
+}
+
+export class DecalVertex {
+  constructor(position: Vector3, normal: Vector3);
+  clone(): DecalVertex;
+}

+ 358 - 0
examples/jsm/geometries/DecalGeometry.js

@@ -0,0 +1,358 @@
+/**
+ * @author Mugen87 / https://github.com/Mugen87
+ * @author spite / https://github.com/spite
+ *
+ * You can use this geometry to create a decal mesh, that serves different kinds of purposes.
+ * e.g. adding unique details to models, performing dynamic visual environmental changes or covering seams.
+ *
+ * Constructor parameter:
+ *
+ * mesh — Any mesh object
+ * position — Position of the decal projector
+ * orientation — Orientation of the decal projector
+ * size — Size of the decal projector
+ *
+ * reference: http://blog.wolfire.com/2009/06/how-to-project-decals/
+ *
+ */
+
+import {
+	BufferGeometry,
+	Float32BufferAttribute,
+	Matrix4,
+	Vector3
+} from "../../../build/three.module.js";
+
+var DecalGeometry = function ( mesh, position, orientation, size ) {
+
+	BufferGeometry.call( this );
+
+	// buffers
+
+	var vertices = [];
+	var normals = [];
+	var uvs = [];
+
+	// helpers
+
+	var plane = new Vector3();
+
+	// this matrix represents the transformation of the decal projector
+
+	var projectorMatrix = new Matrix4();
+	projectorMatrix.makeRotationFromEuler( orientation );
+	projectorMatrix.setPosition( position );
+
+	var projectorMatrixInverse = new Matrix4().getInverse( projectorMatrix );
+
+	// generate buffers
+
+	generate();
+
+	// build geometry
+
+	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
+	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
+
+	function generate() {
+
+		var i;
+		var geometry = new BufferGeometry();
+		var decalVertices = [];
+
+		var vertex = new Vector3();
+		var normal = new Vector3();
+
+		// handle different geometry types
+
+		if ( mesh.geometry.isGeometry ) {
+
+			geometry.fromGeometry( mesh.geometry );
+
+		} else {
+
+			geometry.copy( mesh.geometry );
+
+		}
+
+		var positionAttribute = geometry.attributes.position;
+		var normalAttribute = geometry.attributes.normal;
+
+		// first, create an array of 'DecalVertex' objects
+		// three consecutive 'DecalVertex' objects represent a single face
+		//
+		// this data structure will be later used to perform the clipping
+
+		if ( geometry.index !== null ) {
+
+			// indexed BufferGeometry
+
+			var index = geometry.index;
+
+			for ( i = 0; i < index.count; i ++ ) {
+
+				vertex.fromBufferAttribute( positionAttribute, index.getX( i ) );
+				normal.fromBufferAttribute( normalAttribute, index.getX( i ) );
+
+				pushDecalVertex( decalVertices, vertex, normal );
+
+			}
+
+		} else {
+
+			// non-indexed BufferGeometry
+
+			for ( i = 0; i < positionAttribute.count; i ++ ) {
+
+				vertex.fromBufferAttribute( positionAttribute, i );
+				normal.fromBufferAttribute( normalAttribute, i );
+
+				pushDecalVertex( decalVertices, vertex, normal );
+
+			}
+
+		}
+
+		// second, clip the geometry so that it doesn't extend out from the projector
+
+		decalVertices = clipGeometry( decalVertices, plane.set( 1, 0, 0 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( - 1, 0, 0 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( 0, 1, 0 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( 0, - 1, 0 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( 0, 0, 1 ) );
+		decalVertices = clipGeometry( decalVertices, plane.set( 0, 0, - 1 ) );
+
+		// third, generate final vertices, normals and uvs
+
+		for ( i = 0; i < decalVertices.length; i ++ ) {
+
+			var decalVertex = decalVertices[ i ];
+
+			// create texture coordinates (we are still in projector space)
+
+			uvs.push(
+				0.5 + ( decalVertex.position.x / size.x ),
+				0.5 + ( decalVertex.position.y / size.y )
+			);
+
+			// transform the vertex back to world space
+
+			decalVertex.position.applyMatrix4( projectorMatrix );
+
+			// now create vertex and normal buffer data
+
+			vertices.push( decalVertex.position.x, decalVertex.position.y, decalVertex.position.z );
+			normals.push( decalVertex.normal.x, decalVertex.normal.y, decalVertex.normal.z );
+
+		}
+
+	}
+
+	function pushDecalVertex( decalVertices, vertex, normal ) {
+
+		// transform the vertex to world space, then to projector space
+
+		vertex.applyMatrix4( mesh.matrixWorld );
+		vertex.applyMatrix4( projectorMatrixInverse );
+
+		decalVertices.push( new DecalVertex( vertex.clone(), normal.clone() ) );
+
+	}
+
+	function clipGeometry( inVertices, plane ) {
+
+		var outVertices = [];
+
+		var s = 0.5 * Math.abs( size.dot( plane ) );
+
+		// a single iteration clips one face,
+		// which consists of three consecutive 'DecalVertex' objects
+
+		for ( var i = 0; i < inVertices.length; i += 3 ) {
+
+			var v1Out, v2Out, v3Out, total = 0;
+			var nV1, nV2, nV3, nV4;
+
+			var d1 = inVertices[ i + 0 ].position.dot( plane ) - s;
+			var d2 = inVertices[ i + 1 ].position.dot( plane ) - s;
+			var d3 = inVertices[ i + 2 ].position.dot( plane ) - s;
+
+			v1Out = d1 > 0;
+			v2Out = d2 > 0;
+			v3Out = d3 > 0;
+
+			// calculate, how many vertices of the face lie outside of the clipping plane
+
+			total = ( v1Out ? 1 : 0 ) + ( v2Out ? 1 : 0 ) + ( v3Out ? 1 : 0 );
+
+			switch ( total ) {
+
+				case 0: {
+
+					// the entire face lies inside of the plane, no clipping needed
+
+					outVertices.push( inVertices[ i ] );
+					outVertices.push( inVertices[ i + 1 ] );
+					outVertices.push( inVertices[ i + 2 ] );
+					break;
+
+				}
+
+				case 1: {
+
+					// one vertex lies outside of the plane, perform clipping
+
+					if ( v1Out ) {
+
+						nV1 = inVertices[ i + 1 ];
+						nV2 = inVertices[ i + 2 ];
+						nV3 = clip( inVertices[ i ], nV1, plane, s );
+						nV4 = clip( inVertices[ i ], nV2, plane, s );
+
+					}
+
+					if ( v2Out ) {
+
+						nV1 = inVertices[ i ];
+						nV2 = inVertices[ i + 2 ];
+						nV3 = clip( inVertices[ i + 1 ], nV1, plane, s );
+						nV4 = clip( inVertices[ i + 1 ], nV2, plane, s );
+
+						outVertices.push( nV3 );
+						outVertices.push( nV2.clone() );
+						outVertices.push( nV1.clone() );
+
+						outVertices.push( nV2.clone() );
+						outVertices.push( nV3.clone() );
+						outVertices.push( nV4 );
+						break;
+
+					}
+
+					if ( v3Out ) {
+
+						nV1 = inVertices[ i ];
+						nV2 = inVertices[ i + 1 ];
+						nV3 = clip( inVertices[ i + 2 ], nV1, plane, s );
+						nV4 = clip( inVertices[ i + 2 ], nV2, plane, s );
+
+					}
+
+					outVertices.push( nV1.clone() );
+					outVertices.push( nV2.clone() );
+					outVertices.push( nV3 );
+
+					outVertices.push( nV4 );
+					outVertices.push( nV3.clone() );
+					outVertices.push( nV2.clone() );
+
+					break;
+
+				}
+
+				case 2: {
+
+					// two vertices lies outside of the plane, perform clipping
+
+					if ( ! v1Out ) {
+
+						nV1 = inVertices[ i ].clone();
+						nV2 = clip( nV1, inVertices[ i + 1 ], plane, s );
+						nV3 = clip( nV1, inVertices[ i + 2 ], plane, s );
+						outVertices.push( nV1 );
+						outVertices.push( nV2 );
+						outVertices.push( nV3 );
+
+					}
+
+					if ( ! v2Out ) {
+
+						nV1 = inVertices[ i + 1 ].clone();
+						nV2 = clip( nV1, inVertices[ i + 2 ], plane, s );
+						nV3 = clip( nV1, inVertices[ i ], plane, s );
+						outVertices.push( nV1 );
+						outVertices.push( nV2 );
+						outVertices.push( nV3 );
+
+					}
+
+					if ( ! v3Out ) {
+
+						nV1 = inVertices[ i + 2 ].clone();
+						nV2 = clip( nV1, inVertices[ i ], plane, s );
+						nV3 = clip( nV1, inVertices[ i + 1 ], plane, s );
+						outVertices.push( nV1 );
+						outVertices.push( nV2 );
+						outVertices.push( nV3 );
+
+					}
+
+					break;
+
+				}
+
+				case 3: {
+
+					// the entire face lies outside of the plane, so let's discard the corresponding vertices
+
+					break;
+
+				}
+
+			}
+
+		}
+
+		return outVertices;
+
+	}
+
+	function clip( v0, v1, p, s ) {
+
+		var d0 = v0.position.dot( p ) - s;
+		var d1 = v1.position.dot( p ) - s;
+
+		var s0 = d0 / ( d0 - d1 );
+
+		var v = new DecalVertex(
+			new Vector3(
+				v0.position.x + s0 * ( v1.position.x - v0.position.x ),
+				v0.position.y + s0 * ( v1.position.y - v0.position.y ),
+				v0.position.z + s0 * ( v1.position.z - v0.position.z )
+			),
+			new Vector3(
+				v0.normal.x + s0 * ( v1.normal.x - v0.normal.x ),
+				v0.normal.y + s0 * ( v1.normal.y - v0.normal.y ),
+				v0.normal.z + s0 * ( v1.normal.z - v0.normal.z )
+			)
+		);
+
+		// need to clip more values (texture coordinates)? do it this way:
+		// intersectpoint.value = a.value + s * ( b.value - a.value );
+
+		return v;
+
+	}
+
+};
+
+DecalGeometry.prototype = Object.create( BufferGeometry.prototype );
+DecalGeometry.prototype.constructor = DecalGeometry;
+
+// helper
+
+var DecalVertex = function ( position, normal ) {
+
+	this.position = position;
+	this.normal = normal;
+
+};
+
+DecalVertex.prototype.clone = function () {
+
+	return new this.constructor( this.position.clone(), this.normal.clone() );
+
+};
+
+export { DecalGeometry, DecalVertex };

+ 27 - 0
examples/jsm/geometries/ParametricGeometries.d.ts

@@ -0,0 +1,27 @@
+import {
+  Curve,
+  Vector3
+} from '../../../src/Three';
+
+export namespace ParametricGeometries  {
+  export function klein(v: number, u: number, target: Vector3): Vector3;
+  export function plane(width: number, height: number, target: Vector3): Vector3;
+  export function mobius(u: number, t: number, target: Vector3): Vector3;
+  export function mobius3d(u: number, t: number, target: Vector3): Vector3;
+
+  export class TubeGeometry {
+    constructor(path: Curve<Vector3>, segments?: number, radius?: number, segmentsRadius?: number, closed?: boolean, debug?: boolean);
+  }
+
+  export class TorusKnotGeometry {
+    constructor(radius?: number, tube?: number, segmentsT?: number, segmentsR?: number, p?: number, q?: number);
+  }
+
+  export class SphereGeometry {
+    constructor(size: number, u: number, v): number;
+  }
+
+  export class PlaneGeometry {
+    constructor(width: number, depth: number, segmentsWidth: number, segmentsDepth: number);
+  }
+}

+ 274 - 0
examples/jsm/geometries/ParametricGeometries.js

@@ -0,0 +1,274 @@
+/*
+ * @author zz85
+ *
+ * Experimenting of primitive geometry creation using Surface Parametric equations
+ *
+ */
+
+import {
+	ArrowHelper,
+	Curve,
+	Geometry,
+	Object3D,
+	ParametricGeometry,
+	Vector3
+} from "../../../build/three.module.js";
+
+var ParametricGeometries = {
+
+	klein: function ( v, u, target ) {
+
+		u *= Math.PI;
+		v *= 2 * Math.PI;
+
+		u = u * 2;
+		var x, y, z;
+		if ( u < Math.PI ) {
+
+			x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( u ) * Math.cos( v );
+			z = - 8 * Math.sin( u ) - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( u ) * Math.cos( v );
+
+		} else {
+
+			x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( v + Math.PI );
+			z = - 8 * Math.sin( u );
+
+		}
+
+		y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
+
+		target.set( x, y, z );
+
+	},
+
+	plane: function ( width, height ) {
+
+		return function ( u, v, target ) {
+
+			var x = u * width;
+			var y = 0;
+			var z = v * height;
+
+			target.set( x, y, z );
+
+		};
+
+	},
+
+	mobius: function ( u, t, target ) {
+
+		// flat mobius strip
+		// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
+		u = u - 0.5;
+		var v = 2 * Math.PI * t;
+
+		var x, y, z;
+
+		var a = 2;
+
+		x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
+		y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
+		z = u * Math.sin( v / 2 );
+
+		target.set( x, y, z );
+
+	},
+
+	mobius3d: function ( u, t, target ) {
+
+		// volumetric mobius strip
+
+		u *= Math.PI;
+		t *= 2 * Math.PI;
+
+		u = u * 2;
+		var phi = u / 2;
+		var major = 2.25, a = 0.125, b = 0.65;
+
+		var x, y, z;
+
+		x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
+		z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
+		y = ( major + x ) * Math.sin( u );
+		x = ( major + x ) * Math.cos( u );
+
+		target.set( x, y, z );
+
+	}
+
+};
+
+
+/*********************************************
+ *
+ * Parametric Replacement for TubeGeometry
+ *
+ *********************************************/
+
+ParametricGeometries.TubeGeometry = function ( path, segments, radius, segmentsRadius, closed, debug ) {
+
+	this.path = path;
+	this.segments = segments || 64;
+	this.radius = radius || 1;
+	this.segmentsRadius = segmentsRadius || 8;
+	this.closed = closed || false;
+	if ( debug ) this.debug = new Object3D();
+
+	var scope = this, numpoints = this.segments + 1;
+
+	var frames = path.computeFrenetFrames( segments, closed ),
+		tangents = frames.tangents,
+		normals = frames.normals,
+		binormals = frames.binormals;
+
+	// proxy internals
+
+	this.tangents = tangents;
+	this.normals = normals;
+	this.binormals = binormals;
+
+	var ParametricTube = function ( u, v, target ) {
+
+		v *= 2 * Math.PI;
+
+		var i = u * ( numpoints - 1 );
+		i = Math.floor( i );
+
+		var pos = path.getPointAt( u );
+
+		var tangent = tangents[ i ];
+		var normal = normals[ i ];
+		var binormal = binormals[ i ];
+
+		if ( scope.debug ) {
+
+			scope.debug.add( new ArrowHelper( tangent, pos, radius, 0x0000ff ) );
+			scope.debug.add( new ArrowHelper( normal, pos, radius, 0xff0000 ) );
+			scope.debug.add( new ArrowHelper( binormal, pos, radius, 0x00ff00 ) );
+
+		}
+
+		var cx = - scope.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
+		var cy = scope.radius * Math.sin( v );
+
+		pos.x += cx * normal.x + cy * binormal.x;
+		pos.y += cx * normal.y + cy * binormal.y;
+		pos.z += cx * normal.z + cy * binormal.z;
+
+		target.copy( pos );
+
+	};
+
+	ParametricGeometry.call( this, ParametricTube, segments, segmentsRadius );
+
+};
+
+ParametricGeometries.TubeGeometry.prototype = Object.create( Geometry.prototype );
+ParametricGeometries.TubeGeometry.prototype.constructor = ParametricGeometries.TubeGeometry;
+
+
+/*********************************************
+  *
+  * Parametric Replacement for TorusKnotGeometry
+  *
+  *********************************************/
+ParametricGeometries.TorusKnotGeometry = function ( radius, tube, segmentsT, segmentsR, p, q ) {
+
+	this.radius = radius || 200;
+	this.tube = tube || 40;
+	this.segmentsT = segmentsT || 64;
+	this.segmentsR = segmentsR || 8;
+	this.p = p || 2;
+	this.q = q || 3;
+
+	function TorusKnotCurve() {
+
+		Curve.call( this );
+
+	}
+
+	TorusKnotCurve.prototype = Object.create( Curve.prototype );
+	TorusKnotCurve.prototype.constructor = TorusKnotCurve;
+
+	TorusKnotCurve.prototype.getPoint = function ( t, optionalTarget ) {
+
+		var point = optionalTarget || new Vector3();
+
+		t *= Math.PI * 2;
+
+		var r = 0.5;
+
+		var x = ( 1 + r * Math.cos( q * t ) ) * Math.cos( p * t );
+		var y = ( 1 + r * Math.cos( q * t ) ) * Math.sin( p * t );
+		var z = r * Math.sin( q * t );
+
+		return point.set( x, y, z ).multiplyScalar( radius );
+
+	};
+
+	var segments = segmentsT;
+	var radiusSegments = segmentsR;
+	var extrudePath = new TorusKnotCurve();
+
+	ParametricGeometries.TubeGeometry.call( this, extrudePath, segments, tube, radiusSegments, true, false );
+
+};
+
+ParametricGeometries.TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
+ParametricGeometries.TorusKnotGeometry.prototype.constructor = ParametricGeometries.TorusKnotGeometry;
+
+
+/*********************************************
+  *
+  * Parametric Replacement for SphereGeometry
+  *
+  *********************************************/
+ParametricGeometries.SphereGeometry = function ( size, u, v ) {
+
+	function sphere( u, v, target ) {
+
+		u *= Math.PI;
+		v *= 2 * Math.PI;
+
+		var x = size * Math.sin( u ) * Math.cos( v );
+		var y = size * Math.sin( u ) * Math.sin( v );
+		var z = size * Math.cos( u );
+
+		target.set( x, y, z );
+
+	}
+
+	ParametricGeometry.call( this, sphere, u, v );
+
+};
+
+ParametricGeometries.SphereGeometry.prototype = Object.create( Geometry.prototype );
+ParametricGeometries.SphereGeometry.prototype.constructor = ParametricGeometries.SphereGeometry;
+
+
+/*********************************************
+  *
+  * Parametric Replacement for PlaneGeometry
+  *
+  *********************************************/
+
+ParametricGeometries.PlaneGeometry = function ( width, depth, segmentsWidth, segmentsDepth ) {
+
+	function plane( u, v, target ) {
+
+		var x = u * width;
+		var y = 0;
+		var z = v * depth;
+
+		target.set( x, y, z );
+
+	}
+
+	ParametricGeometry.call( this, plane, segmentsWidth, segmentsDepth );
+
+};
+
+ParametricGeometries.PlaneGeometry.prototype = Object.create( Geometry.prototype );
+ParametricGeometries.PlaneGeometry.prototype.constructor = ParametricGeometries.PlaneGeometry;
+
+export { ParametricGeometries };

+ 7 - 0
examples/jsm/geometries/TeapotBufferGeometry.d.ts

@@ -0,0 +1,7 @@
+import {
+  BufferGeometry
+} from '../../../src/Three';
+
+export class TeapotBufferGeometry extends BufferGeometry {
+  constructor(size?: number, segments?: number, bottom?: boolean, lid?: boolean, body?: boolean, fitLid?: boolean, blinn?: number);
+}

+ 725 - 0
examples/jsm/geometries/TeapotBufferGeometry.js

@@ -0,0 +1,725 @@
+/**
+ * @author Eric Haines / http://erichaines.com/
+ *
+ * Tessellates the famous Utah teapot database by Martin Newell into triangles.
+ *
+ * Parameters: size = 50, segments = 10, bottom = true, lid = true, body = true,
+ *   fitLid = false, blinn = true
+ *
+ * size is a relative scale: I've scaled the teapot to fit vertically between -1 and 1.
+ * Think of it as a "radius".
+ * segments - number of line segments to subdivide each patch edge;
+ *   1 is possible but gives degenerates, so two is the real minimum.
+ * bottom - boolean, if true (default) then the bottom patches are added. Some consider
+ *   adding the bottom heresy, so set this to "false" to adhere to the One True Way.
+ * lid - to remove the lid and look inside, set to true.
+ * body - to remove the body and leave the lid, set this and "bottom" to false.
+ * fitLid - the lid is a tad small in the original. This stretches it a bit so you can't
+ *   see the teapot's insides through the gap.
+ * blinn - Jim Blinn scaled the original data vertically by dividing by about 1.3 to look
+ *   nicer. If you want to see the original teapot, similar to the real-world model, set
+ *   this to false. True by default.
+ *   See http://en.wikipedia.org/wiki/File:Original_Utah_Teapot.jpg for the original
+ *   real-world teapot (from http://en.wikipedia.org/wiki/Utah_teapot).
+ *
+ * Note that the bottom (the last four patches) is not flat - blame Frank Crow, not me.
+ *
+ * The teapot should normally be rendered as a double sided object, since for some
+ * patches both sides can be seen, e.g., the gap around the lid and inside the spout.
+ *
+ * Segments 'n' determines the number of triangles output.
+ *   Total triangles = 32*2*n*n - 8*n    [degenerates at the top and bottom cusps are deleted]
+ *
+ *   size_factor   # triangles
+ *       1          56
+ *       2         240
+ *       3         552
+ *       4         992
+ *
+ *      10        6320
+ *      20       25440
+ *      30       57360
+ *
+ * Code converted from my ancient SPD software, http://tog.acm.org/resources/SPD/
+ * Created for the Udacity course "Interactive Rendering", http://bit.ly/ericity
+ * Lesson: https://www.udacity.com/course/viewer#!/c-cs291/l-68866048/m-106482448
+ * YouTube video on teapot history: https://www.youtube.com/watch?v=DxMfblPzFNc
+ *
+ * See https://en.wikipedia.org/wiki/Utah_teapot for the history of the teapot
+ *
+ */
+
+import {
+	BufferAttribute,
+	BufferGeometry,
+	Matrix4,
+	Vector3,
+	Vector4
+} from "../../../build/three.module.js";
+
+var TeapotBufferGeometry = function ( size, segments, bottom, lid, body, fitLid, blinn ) {
+
+	// 32 * 4 * 4 Bezier spline patches
+	var teapotPatches = [
+		/*rim*/
+		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+		3, 16, 17, 18, 7, 19, 20, 21, 11, 22, 23, 24, 15, 25, 26, 27,
+		18, 28, 29, 30, 21, 31, 32, 33, 24, 34, 35, 36, 27, 37, 38, 39,
+		30, 40, 41, 0, 33, 42, 43, 4, 36, 44, 45, 8, 39, 46, 47, 12,
+		/*body*/
+		12, 13, 14, 15, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
+		15, 25, 26, 27, 51, 60, 61, 62, 55, 63, 64, 65, 59, 66, 67, 68,
+		27, 37, 38, 39, 62, 69, 70, 71, 65, 72, 73, 74, 68, 75, 76, 77,
+		39, 46, 47, 12, 71, 78, 79, 48, 74, 80, 81, 52, 77, 82, 83, 56,
+		56, 57, 58, 59, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+		59, 66, 67, 68, 87, 96, 97, 98, 91, 99, 100, 101, 95, 102, 103, 104,
+		68, 75, 76, 77, 98, 105, 106, 107, 101, 108, 109, 110, 104, 111, 112, 113,
+		77, 82, 83, 56, 107, 114, 115, 84, 110, 116, 117, 88, 113, 118, 119, 92,
+		/*handle*/
+		120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
+		123, 136, 137, 120, 127, 138, 139, 124, 131, 140, 141, 128, 135, 142, 143, 132,
+		132, 133, 134, 135, 144, 145, 146, 147, 148, 149, 150, 151, 68, 152, 153, 154,
+		135, 142, 143, 132, 147, 155, 156, 144, 151, 157, 158, 148, 154, 159, 160, 68,
+		/*spout*/
+		161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176,
+		164, 177, 178, 161, 168, 179, 180, 165, 172, 181, 182, 169, 176, 183, 184, 173,
+		173, 174, 175, 176, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
+		176, 183, 184, 173, 188, 197, 198, 185, 192, 199, 200, 189, 196, 201, 202, 193,
+		/*lid*/
+		203, 203, 203, 203, 204, 205, 206, 207, 208, 208, 208, 208, 209, 210, 211, 212,
+		203, 203, 203, 203, 207, 213, 214, 215, 208, 208, 208, 208, 212, 216, 217, 218,
+		203, 203, 203, 203, 215, 219, 220, 221, 208, 208, 208, 208, 218, 222, 223, 224,
+		203, 203, 203, 203, 221, 225, 226, 204, 208, 208, 208, 208, 224, 227, 228, 209,
+		209, 210, 211, 212, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
+		212, 216, 217, 218, 232, 241, 242, 243, 236, 244, 245, 246, 240, 247, 248, 249,
+		218, 222, 223, 224, 243, 250, 251, 252, 246, 253, 254, 255, 249, 256, 257, 258,
+		224, 227, 228, 209, 252, 259, 260, 229, 255, 261, 262, 233, 258, 263, 264, 237,
+		/*bottom*/
+		265, 265, 265, 265, 266, 267, 268, 269, 270, 271, 272, 273, 92, 119, 118, 113,
+		265, 265, 265, 265, 269, 274, 275, 276, 273, 277, 278, 279, 113, 112, 111, 104,
+		265, 265, 265, 265, 276, 280, 281, 282, 279, 283, 284, 285, 104, 103, 102, 95,
+		265, 265, 265, 265, 282, 286, 287, 266, 285, 288, 289, 270, 95, 94, 93, 92
+	];
+
+	var teapotVertices = [
+		1.4, 0, 2.4,
+		1.4, - 0.784, 2.4,
+		0.784, - 1.4, 2.4,
+		0, - 1.4, 2.4,
+		1.3375, 0, 2.53125,
+		1.3375, - 0.749, 2.53125,
+		0.749, - 1.3375, 2.53125,
+		0, - 1.3375, 2.53125,
+		1.4375, 0, 2.53125,
+		1.4375, - 0.805, 2.53125,
+		0.805, - 1.4375, 2.53125,
+		0, - 1.4375, 2.53125,
+		1.5, 0, 2.4,
+		1.5, - 0.84, 2.4,
+		0.84, - 1.5, 2.4,
+		0, - 1.5, 2.4,
+		- 0.784, - 1.4, 2.4,
+		- 1.4, - 0.784, 2.4,
+		- 1.4, 0, 2.4,
+		- 0.749, - 1.3375, 2.53125,
+		- 1.3375, - 0.749, 2.53125,
+		- 1.3375, 0, 2.53125,
+		- 0.805, - 1.4375, 2.53125,
+		- 1.4375, - 0.805, 2.53125,
+		- 1.4375, 0, 2.53125,
+		- 0.84, - 1.5, 2.4,
+		- 1.5, - 0.84, 2.4,
+		- 1.5, 0, 2.4,
+		- 1.4, 0.784, 2.4,
+		- 0.784, 1.4, 2.4,
+		0, 1.4, 2.4,
+		- 1.3375, 0.749, 2.53125,
+		- 0.749, 1.3375, 2.53125,
+		0, 1.3375, 2.53125,
+		- 1.4375, 0.805, 2.53125,
+		- 0.805, 1.4375, 2.53125,
+		0, 1.4375, 2.53125,
+		- 1.5, 0.84, 2.4,
+		- 0.84, 1.5, 2.4,
+		0, 1.5, 2.4,
+		0.784, 1.4, 2.4,
+		1.4, 0.784, 2.4,
+		0.749, 1.3375, 2.53125,
+		1.3375, 0.749, 2.53125,
+		0.805, 1.4375, 2.53125,
+		1.4375, 0.805, 2.53125,
+		0.84, 1.5, 2.4,
+		1.5, 0.84, 2.4,
+		1.75, 0, 1.875,
+		1.75, - 0.98, 1.875,
+		0.98, - 1.75, 1.875,
+		0, - 1.75, 1.875,
+		2, 0, 1.35,
+		2, - 1.12, 1.35,
+		1.12, - 2, 1.35,
+		0, - 2, 1.35,
+		2, 0, 0.9,
+		2, - 1.12, 0.9,
+		1.12, - 2, 0.9,
+		0, - 2, 0.9,
+		- 0.98, - 1.75, 1.875,
+		- 1.75, - 0.98, 1.875,
+		- 1.75, 0, 1.875,
+		- 1.12, - 2, 1.35,
+		- 2, - 1.12, 1.35,
+		- 2, 0, 1.35,
+		- 1.12, - 2, 0.9,
+		- 2, - 1.12, 0.9,
+		- 2, 0, 0.9,
+		- 1.75, 0.98, 1.875,
+		- 0.98, 1.75, 1.875,
+		0, 1.75, 1.875,
+		- 2, 1.12, 1.35,
+		- 1.12, 2, 1.35,
+		0, 2, 1.35,
+		- 2, 1.12, 0.9,
+		- 1.12, 2, 0.9,
+		0, 2, 0.9,
+		0.98, 1.75, 1.875,
+		1.75, 0.98, 1.875,
+		1.12, 2, 1.35,
+		2, 1.12, 1.35,
+		1.12, 2, 0.9,
+		2, 1.12, 0.9,
+		2, 0, 0.45,
+		2, - 1.12, 0.45,
+		1.12, - 2, 0.45,
+		0, - 2, 0.45,
+		1.5, 0, 0.225,
+		1.5, - 0.84, 0.225,
+		0.84, - 1.5, 0.225,
+		0, - 1.5, 0.225,
+		1.5, 0, 0.15,
+		1.5, - 0.84, 0.15,
+		0.84, - 1.5, 0.15,
+		0, - 1.5, 0.15,
+		- 1.12, - 2, 0.45,
+		- 2, - 1.12, 0.45,
+		- 2, 0, 0.45,
+		- 0.84, - 1.5, 0.225,
+		- 1.5, - 0.84, 0.225,
+		- 1.5, 0, 0.225,
+		- 0.84, - 1.5, 0.15,
+		- 1.5, - 0.84, 0.15,
+		- 1.5, 0, 0.15,
+		- 2, 1.12, 0.45,
+		- 1.12, 2, 0.45,
+		0, 2, 0.45,
+		- 1.5, 0.84, 0.225,
+		- 0.84, 1.5, 0.225,
+		0, 1.5, 0.225,
+		- 1.5, 0.84, 0.15,
+		- 0.84, 1.5, 0.15,
+		0, 1.5, 0.15,
+		1.12, 2, 0.45,
+		2, 1.12, 0.45,
+		0.84, 1.5, 0.225,
+		1.5, 0.84, 0.225,
+		0.84, 1.5, 0.15,
+		1.5, 0.84, 0.15,
+		- 1.6, 0, 2.025,
+		- 1.6, - 0.3, 2.025,
+		- 1.5, - 0.3, 2.25,
+		- 1.5, 0, 2.25,
+		- 2.3, 0, 2.025,
+		- 2.3, - 0.3, 2.025,
+		- 2.5, - 0.3, 2.25,
+		- 2.5, 0, 2.25,
+		- 2.7, 0, 2.025,
+		- 2.7, - 0.3, 2.025,
+		- 3, - 0.3, 2.25,
+		- 3, 0, 2.25,
+		- 2.7, 0, 1.8,
+		- 2.7, - 0.3, 1.8,
+		- 3, - 0.3, 1.8,
+		- 3, 0, 1.8,
+		- 1.5, 0.3, 2.25,
+		- 1.6, 0.3, 2.025,
+		- 2.5, 0.3, 2.25,
+		- 2.3, 0.3, 2.025,
+		- 3, 0.3, 2.25,
+		- 2.7, 0.3, 2.025,
+		- 3, 0.3, 1.8,
+		- 2.7, 0.3, 1.8,
+		- 2.7, 0, 1.575,
+		- 2.7, - 0.3, 1.575,
+		- 3, - 0.3, 1.35,
+		- 3, 0, 1.35,
+		- 2.5, 0, 1.125,
+		- 2.5, - 0.3, 1.125,
+		- 2.65, - 0.3, 0.9375,
+		- 2.65, 0, 0.9375,
+		- 2, - 0.3, 0.9,
+		- 1.9, - 0.3, 0.6,
+		- 1.9, 0, 0.6,
+		- 3, 0.3, 1.35,
+		- 2.7, 0.3, 1.575,
+		- 2.65, 0.3, 0.9375,
+		- 2.5, 0.3, 1.125,
+		- 1.9, 0.3, 0.6,
+		- 2, 0.3, 0.9,
+		1.7, 0, 1.425,
+		1.7, - 0.66, 1.425,
+		1.7, - 0.66, 0.6,
+		1.7, 0, 0.6,
+		2.6, 0, 1.425,
+		2.6, - 0.66, 1.425,
+		3.1, - 0.66, 0.825,
+		3.1, 0, 0.825,
+		2.3, 0, 2.1,
+		2.3, - 0.25, 2.1,
+		2.4, - 0.25, 2.025,
+		2.4, 0, 2.025,
+		2.7, 0, 2.4,
+		2.7, - 0.25, 2.4,
+		3.3, - 0.25, 2.4,
+		3.3, 0, 2.4,
+		1.7, 0.66, 0.6,
+		1.7, 0.66, 1.425,
+		3.1, 0.66, 0.825,
+		2.6, 0.66, 1.425,
+		2.4, 0.25, 2.025,
+		2.3, 0.25, 2.1,
+		3.3, 0.25, 2.4,
+		2.7, 0.25, 2.4,
+		2.8, 0, 2.475,
+		2.8, - 0.25, 2.475,
+		3.525, - 0.25, 2.49375,
+		3.525, 0, 2.49375,
+		2.9, 0, 2.475,
+		2.9, - 0.15, 2.475,
+		3.45, - 0.15, 2.5125,
+		3.45, 0, 2.5125,
+		2.8, 0, 2.4,
+		2.8, - 0.15, 2.4,
+		3.2, - 0.15, 2.4,
+		3.2, 0, 2.4,
+		3.525, 0.25, 2.49375,
+		2.8, 0.25, 2.475,
+		3.45, 0.15, 2.5125,
+		2.9, 0.15, 2.475,
+		3.2, 0.15, 2.4,
+		2.8, 0.15, 2.4,
+		0, 0, 3.15,
+		0.8, 0, 3.15,
+		0.8, - 0.45, 3.15,
+		0.45, - 0.8, 3.15,
+		0, - 0.8, 3.15,
+		0, 0, 2.85,
+		0.2, 0, 2.7,
+		0.2, - 0.112, 2.7,
+		0.112, - 0.2, 2.7,
+		0, - 0.2, 2.7,
+		- 0.45, - 0.8, 3.15,
+		- 0.8, - 0.45, 3.15,
+		- 0.8, 0, 3.15,
+		- 0.112, - 0.2, 2.7,
+		- 0.2, - 0.112, 2.7,
+		- 0.2, 0, 2.7,
+		- 0.8, 0.45, 3.15,
+		- 0.45, 0.8, 3.15,
+		0, 0.8, 3.15,
+		- 0.2, 0.112, 2.7,
+		- 0.112, 0.2, 2.7,
+		0, 0.2, 2.7,
+		0.45, 0.8, 3.15,
+		0.8, 0.45, 3.15,
+		0.112, 0.2, 2.7,
+		0.2, 0.112, 2.7,
+		0.4, 0, 2.55,
+		0.4, - 0.224, 2.55,
+		0.224, - 0.4, 2.55,
+		0, - 0.4, 2.55,
+		1.3, 0, 2.55,
+		1.3, - 0.728, 2.55,
+		0.728, - 1.3, 2.55,
+		0, - 1.3, 2.55,
+		1.3, 0, 2.4,
+		1.3, - 0.728, 2.4,
+		0.728, - 1.3, 2.4,
+		0, - 1.3, 2.4,
+		- 0.224, - 0.4, 2.55,
+		- 0.4, - 0.224, 2.55,
+		- 0.4, 0, 2.55,
+		- 0.728, - 1.3, 2.55,
+		- 1.3, - 0.728, 2.55,
+		- 1.3, 0, 2.55,
+		- 0.728, - 1.3, 2.4,
+		- 1.3, - 0.728, 2.4,
+		- 1.3, 0, 2.4,
+		- 0.4, 0.224, 2.55,
+		- 0.224, 0.4, 2.55,
+		0, 0.4, 2.55,
+		- 1.3, 0.728, 2.55,
+		- 0.728, 1.3, 2.55,
+		0, 1.3, 2.55,
+		- 1.3, 0.728, 2.4,
+		- 0.728, 1.3, 2.4,
+		0, 1.3, 2.4,
+		0.224, 0.4, 2.55,
+		0.4, 0.224, 2.55,
+		0.728, 1.3, 2.55,
+		1.3, 0.728, 2.55,
+		0.728, 1.3, 2.4,
+		1.3, 0.728, 2.4,
+		0, 0, 0,
+		1.425, 0, 0,
+		1.425, 0.798, 0,
+		0.798, 1.425, 0,
+		0, 1.425, 0,
+		1.5, 0, 0.075,
+		1.5, 0.84, 0.075,
+		0.84, 1.5, 0.075,
+		0, 1.5, 0.075,
+		- 0.798, 1.425, 0,
+		- 1.425, 0.798, 0,
+		- 1.425, 0, 0,
+		- 0.84, 1.5, 0.075,
+		- 1.5, 0.84, 0.075,
+		- 1.5, 0, 0.075,
+		- 1.425, - 0.798, 0,
+		- 0.798, - 1.425, 0,
+		0, - 1.425, 0,
+		- 1.5, - 0.84, 0.075,
+		- 0.84, - 1.5, 0.075,
+		0, - 1.5, 0.075,
+		0.798, - 1.425, 0,
+		1.425, - 0.798, 0,
+		0.84, - 1.5, 0.075,
+		1.5, - 0.84, 0.075
+	];
+
+	BufferGeometry.call( this );
+
+	size = size || 50;
+
+	// number of segments per patch
+	segments = segments !== undefined ? Math.max( 2, Math.floor( segments ) || 10 ) : 10;
+
+	// which parts should be visible
+	bottom = bottom === undefined ? true : bottom;
+	lid = lid === undefined ? true : lid;
+	body = body === undefined ? true : body;
+
+	// Should the lid be snug? It's not traditional, but we make it snug by default
+	fitLid = fitLid === undefined ? true : fitLid;
+
+	// Jim Blinn scaled the teapot down in size by about 1.3 for
+	// some rendering tests. He liked the new proportions that he kept
+	// the data in this form. The model was distributed with these new
+	// proportions and became the norm. Trivia: comparing images of the
+	// real teapot and the computer model, the ratio for the bowl of the
+	// real teapot is more like 1.25, but since 1.3 is the traditional
+	// value given, we use it here.
+	var blinnScale = 1.3;
+	blinn = blinn === undefined ? true : blinn;
+
+	// scale the size to be the real scaling factor
+	var maxHeight = 3.15 * ( blinn ? 1 : blinnScale );
+
+	var maxHeight2 = maxHeight / 2;
+	var trueSize = size / maxHeight2;
+
+	// Number of elements depends on what is needed. Subtract degenerate
+	// triangles at tip of bottom and lid out in advance.
+	var numTriangles = bottom ? ( 8 * segments - 4 ) * segments : 0;
+	numTriangles += lid ? ( 16 * segments - 4 ) * segments : 0;
+	numTriangles += body ? 40 * segments * segments : 0;
+
+	var indices = new Uint32Array( numTriangles * 3 );
+
+	var numVertices = bottom ? 4 : 0;
+	numVertices += lid ? 8 : 0;
+	numVertices += body ? 20 : 0;
+	numVertices *= ( segments + 1 ) * ( segments + 1 );
+
+	var vertices = new Float32Array( numVertices * 3 );
+	var normals = new Float32Array( numVertices * 3 );
+	var uvs = new Float32Array( numVertices * 2 );
+
+	// Bezier form
+	var ms = new Matrix4();
+	ms.set(
+		- 1.0, 3.0, - 3.0, 1.0,
+		3.0, - 6.0, 3.0, 0.0,
+		- 3.0, 3.0, 0.0, 0.0,
+		1.0, 0.0, 0.0, 0.0 );
+
+	var g = [];
+	var i, r, c;
+
+	var sp = [];
+	var tp = [];
+	var dsp = [];
+	var dtp = [];
+
+	// M * G * M matrix, sort of see
+	// http://www.cs.helsinki.fi/group/goa/mallinnus/curves/surfaces.html
+	var mgm = [];
+
+	var vert = [];
+	var sdir = [];
+	var tdir = [];
+
+	var norm = new Vector3();
+
+	var tcoord;
+
+	var sstep, tstep;
+	var vertPerRow;
+
+	var s, t, sval, tval, p;
+	var dsval = 0;
+	var dtval = 0;
+
+	var normOut = new Vector3();
+	var v1, v2, v3, v4;
+
+	var gmx = new Matrix4();
+	var tmtx = new Matrix4();
+
+	var vsp = new Vector4();
+	var vtp = new Vector4();
+	var vdsp = new Vector4();
+	var vdtp = new Vector4();
+
+	var vsdir = new Vector3();
+	var vtdir = new Vector3();
+
+	var mst = ms.clone();
+	mst.transpose();
+
+	// internal function: test if triangle has any matching vertices;
+	// if so, don't save triangle, since it won't display anything.
+	var notDegenerate = function ( vtx1, vtx2, vtx3 ) {
+
+		// if any vertex matches, return false
+		return ! ( ( ( vertices[ vtx1 * 3 ] === vertices[ vtx2 * 3 ] ) &&
+					 ( vertices[ vtx1 * 3 + 1 ] === vertices[ vtx2 * 3 + 1 ] ) &&
+					 ( vertices[ vtx1 * 3 + 2 ] === vertices[ vtx2 * 3 + 2 ] ) ) ||
+				   ( ( vertices[ vtx1 * 3 ] === vertices[ vtx3 * 3 ] ) &&
+					 ( vertices[ vtx1 * 3 + 1 ] === vertices[ vtx3 * 3 + 1 ] ) &&
+					 ( vertices[ vtx1 * 3 + 2 ] === vertices[ vtx3 * 3 + 2 ] ) ) ||
+				   ( ( vertices[ vtx2 * 3 ] === vertices[ vtx3 * 3 ] ) &&
+					 ( vertices[ vtx2 * 3 + 1 ] === vertices[ vtx3 * 3 + 1 ] ) &&
+					 ( vertices[ vtx2 * 3 + 2 ] === vertices[ vtx3 * 3 + 2 ] ) ) );
+
+	};
+
+
+	for ( i = 0; i < 3; i ++ ) {
+
+		mgm[ i ] = new Matrix4();
+
+	}
+
+	var minPatches = body ? 0 : 20;
+	var maxPatches = bottom ? 32 : 28;
+
+	vertPerRow = segments + 1;
+
+	var surfCount = 0;
+
+	var vertCount = 0;
+	var normCount = 0;
+	var uvCount = 0;
+
+	var indexCount = 0;
+
+	for ( var surf = minPatches; surf < maxPatches; surf ++ ) {
+
+		// lid is in the middle of the data, patches 20-27,
+		// so ignore it for this part of the loop if the lid is not desired
+		if ( lid || ( surf < 20 || surf >= 28 ) ) {
+
+			// get M * G * M matrix for x,y,z
+			for ( i = 0; i < 3; i ++ ) {
+
+				// get control patches
+				for ( r = 0; r < 4; r ++ ) {
+
+					for ( c = 0; c < 4; c ++ ) {
+
+						// transposed
+						g[ c * 4 + r ] = teapotVertices[ teapotPatches[ surf * 16 + r * 4 + c ] * 3 + i ];
+
+						// is the lid to be made larger, and is this a point on the lid
+						// that is X or Y?
+						if ( fitLid && ( surf >= 20 && surf < 28 ) && ( i !== 2 ) ) {
+
+							// increase XY size by 7.7%, found empirically. I don't
+							// increase Z so that the teapot will continue to fit in the
+							// space -1 to 1 for Y (Y is up for the final model).
+							g[ c * 4 + r ] *= 1.077;
+
+						}
+
+						// Blinn "fixed" the teapot by dividing Z by blinnScale, and that's the
+						// data we now use. The original teapot is taller. Fix it:
+						if ( ! blinn && ( i === 2 ) ) {
+
+							g[ c * 4 + r ] *= blinnScale;
+
+						}
+
+					}
+
+				}
+
+				gmx.set( g[ 0 ], g[ 1 ], g[ 2 ], g[ 3 ], g[ 4 ], g[ 5 ], g[ 6 ], g[ 7 ], g[ 8 ], g[ 9 ], g[ 10 ], g[ 11 ], g[ 12 ], g[ 13 ], g[ 14 ], g[ 15 ] );
+
+				tmtx.multiplyMatrices( gmx, ms );
+				mgm[ i ].multiplyMatrices( mst, tmtx );
+
+			}
+
+			// step along, get points, and output
+			for ( sstep = 0; sstep <= segments; sstep ++ ) {
+
+				s = sstep / segments;
+
+				for ( tstep = 0; tstep <= segments; tstep ++ ) {
+
+					t = tstep / segments;
+
+					// point from basis
+					// get power vectors and their derivatives
+					for ( p = 4, sval = tval = 1.0; p --; ) {
+
+						sp[ p ] = sval;
+						tp[ p ] = tval;
+						sval *= s;
+						tval *= t;
+
+						if ( p === 3 ) {
+
+							dsp[ p ] = dtp[ p ] = 0.0;
+							dsval = dtval = 1.0;
+
+						} else {
+
+							dsp[ p ] = dsval * ( 3 - p );
+							dtp[ p ] = dtval * ( 3 - p );
+							dsval *= s;
+							dtval *= t;
+
+						}
+
+					}
+
+					vsp.fromArray( sp );
+					vtp.fromArray( tp );
+					vdsp.fromArray( dsp );
+					vdtp.fromArray( dtp );
+
+					// do for x,y,z
+					for ( i = 0; i < 3; i ++ ) {
+
+						// multiply power vectors times matrix to get value
+						tcoord = vsp.clone();
+						tcoord.applyMatrix4( mgm[ i ] );
+						vert[ i ] = tcoord.dot( vtp );
+
+						// get s and t tangent vectors
+						tcoord = vdsp.clone();
+						tcoord.applyMatrix4( mgm[ i ] );
+						sdir[ i ] = tcoord.dot( vtp );
+
+						tcoord = vsp.clone();
+						tcoord.applyMatrix4( mgm[ i ] );
+						tdir[ i ] = tcoord.dot( vdtp );
+
+					}
+
+					// find normal
+					vsdir.fromArray( sdir );
+					vtdir.fromArray( tdir );
+					norm.crossVectors( vtdir, vsdir );
+					norm.normalize();
+
+					// if X and Z length is 0, at the cusp, so point the normal up or down, depending on patch number
+					if ( vert[ 0 ] === 0 && vert[ 1 ] === 0 ) {
+
+						// if above the middle of the teapot, normal points up, else down
+						normOut.set( 0, vert[ 2 ] > maxHeight2 ? 1 : - 1, 0 );
+
+					} else {
+
+						// standard output: rotate on X axis
+						normOut.set( norm.x, norm.z, - norm.y );
+
+					}
+
+					// store it all
+					vertices[ vertCount ++ ] = trueSize * vert[ 0 ];
+					vertices[ vertCount ++ ] = trueSize * ( vert[ 2 ] - maxHeight2 );
+					vertices[ vertCount ++ ] = - trueSize * vert[ 1 ];
+
+					normals[ normCount ++ ] = normOut.x;
+					normals[ normCount ++ ] = normOut.y;
+					normals[ normCount ++ ] = normOut.z;
+
+					uvs[ uvCount ++ ] = 1 - t;
+					uvs[ uvCount ++ ] = 1 - s;
+
+				}
+
+			}
+
+			// save the faces
+			for ( sstep = 0; sstep < segments; sstep ++ ) {
+
+				for ( tstep = 0; tstep < segments; tstep ++ ) {
+
+					v1 = surfCount * vertPerRow * vertPerRow + sstep * vertPerRow + tstep;
+					v2 = v1 + 1;
+					v3 = v2 + vertPerRow;
+					v4 = v1 + vertPerRow;
+
+					// Normals and UVs cannot be shared. Without clone(), you can see the consequences
+					// of sharing if you call geometry.applyMatrix( matrix ).
+					if ( notDegenerate( v1, v2, v3 ) ) {
+
+						indices[ indexCount ++ ] = v1;
+						indices[ indexCount ++ ] = v2;
+						indices[ indexCount ++ ] = v3;
+
+					}
+					if ( notDegenerate( v1, v3, v4 ) ) {
+
+						indices[ indexCount ++ ] = v1;
+						indices[ indexCount ++ ] = v3;
+						indices[ indexCount ++ ] = v4;
+
+					}
+
+				}
+
+			}
+
+			// increment only if a surface was used
+			surfCount ++;
+
+		}
+
+	}
+
+	this.setIndex( new BufferAttribute( indices, 1 ) );
+	this.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
+	this.addAttribute( 'normal', new BufferAttribute( normals, 3 ) );
+	this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ) );
+
+	this.computeBoundingSphere();
+
+};
+
+
+TeapotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
+TeapotBufferGeometry.prototype.constructor = TeapotBufferGeometry;
+
+export { TeapotBufferGeometry };

+ 5 - 0
utils/modularize.js

@@ -42,6 +42,11 @@ var files = [
 	{ path: 'exporters/STLExporter.js', dependencies: [], ignoreList: [] },
 	{ path: 'exporters/TypedGeometryExporter.js', dependencies: [], ignoreList: [] },
 
+	{ path: 'geometries/BoxLineGeometry.js', dependencies: [], ignoreList: [] },
+	{ path: 'geometries/DecalGeometry.js', dependencies: [], ignoreList: [] },
+	{ path: 'geometries/ParametricGeometries.js', dependencies: [], ignoreList: [] },
+	{ path: 'geometries/TeapotBufferGeometry.js', dependencies: [], ignoreList: [] },
+
 	{ path: 'loaders/3MFLoader.js', dependencies: [], ignoreList: [] },
 	{ path: 'loaders/AMFLoader.js', dependencies: [], ignoreList: [] },
 	{ path: 'loaders/AssimpJSONLoader.js', dependencies: [], ignoreList: [] },