Browse Source

Updated builds.

Mr.doob 8 years ago
parent
commit
ea5e956e0a
2 changed files with 504 additions and 462 deletions
  1. 200 161
      build/three.js
  2. 304 301
      build/three.min.js

+ 200 - 161
build/three.js

@@ -606,6 +606,8 @@
 				default: throw new Error( 'index is out of range: ' + index );
 				default: throw new Error( 'index is out of range: ' + index );
 
 
 			}
 			}
+			
+			return this;
 
 
 		},
 		},
 
 
@@ -1372,6 +1374,8 @@
 				default: throw new Error( 'index is out of range: ' + index );
 				default: throw new Error( 'index is out of range: ' + index );
 
 
 			}
 			}
+			
+			return this;
 
 
 		},
 		},
 
 
@@ -2679,6 +2683,8 @@
 				default: throw new Error( 'index is out of range: ' + index );
 				default: throw new Error( 'index is out of range: ' + index );
 
 
 			}
 			}
+			
+			return this;
 
 
 		},
 		},
 
 
@@ -24482,264 +24488,252 @@
 	PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
 	PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
 
 
 	/**
 	/**
-	 * @author WestLangley / https://github.com/WestLangley
-	 * @author zz85 / https://github.com/zz85
-	 * @author miningold / https://github.com/miningold
-	 * @author jonobr1 / https://github.com/jonobr1
+	 * @author Mugen87 / https://github.com/Mugen87
 	 *
 	 *
-	 * Modified from the TorusKnotGeometry by @oosmoxiecode
+	 * Creates a tube which extrudes along a 3d spline.
 	 *
 	 *
-	 * Creates a tube which extrudes along a 3d spline
+	 * Uses parallel transport frames as described in:
 	 *
 	 *
-	 * Uses parallel transport frames as described in
 	 * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
 	 * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
 	 */
 	 */
 
 
-	function TubeGeometry( path, segments, radius, radialSegments, closed, taper ) {
+	function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
 
 
-		Geometry.call( this );
+		BufferGeometry.call( this );
 
 
-		this.type = 'TubeGeometry';
+		this.type = 'TubeBufferGeometry';
 
 
 		this.parameters = {
 		this.parameters = {
 			path: path,
 			path: path,
-			segments: segments,
+			tubularSegments: tubularSegments,
 			radius: radius,
 			radius: radius,
 			radialSegments: radialSegments,
 			radialSegments: radialSegments,
-			closed: closed,
-			taper: taper
+			closed: closed
 		};
 		};
 
 
-		segments = segments || 64;
+		tubularSegments = tubularSegments || 64;
 		radius = radius || 1;
 		radius = radius || 1;
 		radialSegments = radialSegments || 8;
 		radialSegments = radialSegments || 8;
-		closed = closed || false;
-		taper = taper || TubeGeometry.NoTaper;
+		closed = closed || false;
 
 
-		var grid = [];
+		var frames = new FrenetFrames( path, tubularSegments, closed );
 
 
-		var scope = this,
+		// expose internals
+
+		this.tangents = frames.tangents;
+		this.normals = frames.normals;
+		this.binormals = frames.binormals;
 
 
-			tangent,
-			normal,
-			binormal,
+		// helper variables
+
+		var vertex = new Vector3();
+		var normal = new Vector3();
+		var uv = new Vector2();
+
+		var i, j;
+
+		// buffer
 
 
-			numpoints = segments + 1,
+		var vertices = [];
+		var normals = [];
+		var uvs = [];
+		var indices = [];
 
 
-			u, v, r,
+		// create buffer data
 
 
-			cx, cy,
-			pos, pos2 = new Vector3(),
-			i, j,
-			ip, jp,
-			a, b, c, d,
-			uva, uvb, uvc, uvd;
+		generateBufferData();
 
 
-		var frames = new TubeGeometry.FrenetFrames( path, segments, closed ),
-			tangents = frames.tangents,
-			normals = frames.normals,
-			binormals = frames.binormals;
+		// build geometry
 
 
-		// proxy internals
-		this.tangents = tangents;
-		this.normals = normals;
-		this.binormals = binormals;
+		this.setIndex( ( indices.length > 65535 ? Uint32Attribute : Uint16Attribute )( indices, 1 ) );
+		this.addAttribute( 'position', Float32Attribute( vertices, 3 ) );
+		this.addAttribute( 'normal', Float32Attribute( normals, 3 ) );
+		this.addAttribute( 'uv', Float32Attribute( uvs, 2 ) );
+
+		// functions
+
+		function generateBufferData() {
+
+			for ( i = 0; i < tubularSegments; i ++ ) {
+
+				generateSegment( i );
+
+			}
 
 
-		function vert( x, y, z ) {
+			// if the geometry is not closed, generate the last row of vertices and normals
+			// at the regular position on the given path
+			//
+			// if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
+
+			generateSegment( ( closed === false ) ? tubularSegments : 0 );
+
+			// uvs are generated in a separate function.
+			// this makes it easy compute correct values for closed geometries
+
+			generateUVs();
 
 
-			return scope.vertices.push( new Vector3( x, y, z ) ) - 1;
+			// finally create faces
+
+			generateIndices();
 
 
 		}
 		}
 
 
-		// construct the grid
+		function generateSegment( i ) {
+
+			// we use getPointAt to sample evenly distributed points from the given path
+
+			var P = path.getPointAt( i / tubularSegments );
+
+			// retrieve corresponding normal and binormal
 
 
-		for ( i = 0; i < numpoints; i ++ ) {
+			var N = frames.normals[ i ];
+			var B = frames.binormals[ i ];
 
 
-			grid[ i ] = [];
+			// generate normals and vertices for the current segment
 
 
-			u = i / ( numpoints - 1 );
+			for ( j = 0; j <= radialSegments; j ++ ) {
 
 
-			pos = path.getPointAt( u );
+				var v = j / radialSegments * Math.PI * 2;
 
 
-			tangent = tangents[ i ];
-			normal = normals[ i ];
-			binormal = binormals[ i ];
+				var sin =   Math.sin( v );
+				var cos = - Math.cos( v );
 
 
-			r = radius * taper( u );
+				// normal
 
 
-			for ( j = 0; j < radialSegments; j ++ ) {
+				normal.x = ( cos * N.x + sin * B.x );
+				normal.y = ( cos * N.y + sin * B.y );
+				normal.z = ( cos * N.z + sin * B.z );
+				normal.normalize();
 
 
-				v = j / radialSegments * 2 * Math.PI;
+				normals.push( normal.x, normal.y, normal.z );
 
 
-				cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
-				cy = r * Math.sin( v );
+				// vertex
 
 
-				pos2.copy( pos );
-				pos2.x += cx * normal.x + cy * binormal.x;
-				pos2.y += cx * normal.y + cy * binormal.y;
-				pos2.z += cx * normal.z + cy * binormal.z;
+				vertex.x = P.x + radius * normal.x;
+				vertex.y = P.y + radius * normal.y;
+				vertex.z = P.z + radius * normal.z;
 
 
-				grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
 
 			}
 			}
 
 
 		}
 		}
 
 
+		function generateIndices() {
 
 
-		// construct the mesh
-
-		for ( i = 0; i < segments; i ++ ) {
-
-			for ( j = 0; j < radialSegments; j ++ ) {
+			for ( j = 1; j <= tubularSegments; j ++ ) {
 
 
-				ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
-				jp = ( j + 1 ) % radialSegments;
+				for ( i = 1; i <= radialSegments; i ++ ) {
 
 
-				a = grid[ i ][ j ];		// *** NOT NECESSARILY PLANAR ! ***
-				b = grid[ ip ][ j ];
-				c = grid[ ip ][ jp ];
-				d = grid[ i ][ jp ];
+					var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
+					var b = ( radialSegments + 1 ) * j + ( i - 1 );
+					var c = ( radialSegments + 1 ) * j + i;
+					var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
 
 
-				uva = new Vector2( i / segments, j / radialSegments );
-				uvb = new Vector2( ( i + 1 ) / segments, j / radialSegments );
-				uvc = new Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
-				uvd = new Vector2( i / segments, ( j + 1 ) / radialSegments );
+					// faces
 
 
-				this.faces.push( new Face3( a, b, d ) );
-				this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
+					indices.push( a, b, d );
+					indices.push( b, c, d );
 
 
-				this.faces.push( new Face3( b, c, d ) );
-				this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
+				}
 
 
 			}
 			}
 
 
 		}
 		}
 
 
-		this.computeFaceNormals();
-		this.computeVertexNormals();
+		function generateUVs() {
 
 
-	}
+			for ( i = 0; i <= tubularSegments; i ++ ) {
 
 
-	TubeGeometry.prototype = Object.create( Geometry.prototype );
-	TubeGeometry.prototype.constructor = TubeGeometry;
+				for ( j = 0; j <= radialSegments; j ++ ) {
 
 
-	TubeGeometry.NoTaper = function ( u ) {
+					uv.x = i / tubularSegments;
+					uv.y = j / radialSegments;
 
 
-		return 1;
+					uvs.push( uv.x, uv.y );
 
 
-	};
+				}
+
+			}
 
 
-	TubeGeometry.SinusoidalTaper = function ( u ) {
+		}
 
 
-		return Math.sin( Math.PI * u );
+	}
 
 
-	};
+	TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
+	TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
 
 
 	// For computing of Frenet frames, exposing the tangents, normals and binormals the spline
 	// For computing of Frenet frames, exposing the tangents, normals and binormals the spline
-	TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
-
-		var	normal = new Vector3(),
 
 
-			tangents = [],
-			normals = [],
-			binormals = [],
+	function FrenetFrames( path, segments, closed ) {
 
 
-			vec = new Vector3(),
-			mat = new Matrix4(),
+		var	normal = new Vector3();
 
 
-			numpoints = segments + 1,
-			theta,
-			smallest,
+		var tangents = [];
+		var normals = [];
+		var binormals = [];
 
 
-			tx, ty, tz,
-			i, u;
+		var vec = new Vector3();
+		var mat = new Matrix4();
 
 
+		var i, u, theta;
 
 
 		// expose internals
 		// expose internals
+
 		this.tangents = tangents;
 		this.tangents = tangents;
 		this.normals = normals;
 		this.normals = normals;
 		this.binormals = binormals;
 		this.binormals = binormals;
 
 
 		// compute the tangent vectors for each segment on the path
 		// compute the tangent vectors for each segment on the path
 
 
-		for ( i = 0; i < numpoints; i ++ ) {
+		for ( i = 0; i <= segments; i ++ ) {
 
 
-			u = i / ( numpoints - 1 );
+			u = i / segments;
 
 
 			tangents[ i ] = path.getTangentAt( u );
 			tangents[ i ] = path.getTangentAt( u );
 			tangents[ i ].normalize();
 			tangents[ i ].normalize();
 
 
 		}
 		}
 
 
-		initialNormal3();
-
-		/*
-		function initialNormal1(lastBinormal) {
-			// fixed start binormal. Has dangers of 0 vectors
-			normals[ 0 ] = new THREE.Vector3();
-			binormals[ 0 ] = new THREE.Vector3();
-			if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
-			normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
-			binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
-		}
-
-		function initialNormal2() {
+		// select an initial normal vector perpendicular to the first tangent vector,
+		// and in the direction of the minimum tangent xyz component
 
 
-			// This uses the Frenet-Serret formula for deriving binormal
-			var t2 = path.getTangentAt( epsilon );
+		normals[ 0 ] = new Vector3();
+		binormals[ 0 ] = new Vector3();
+		var min = Number.MAX_VALUE;
+		var tx = Math.abs( tangents[ 0 ].x );
+		var ty = Math.abs( tangents[ 0 ].y );
+		var tz = Math.abs( tangents[ 0 ].z );
 
 
-			normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
-			binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
+		if ( tx <= min ) {
 
 
-			normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
-			binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
+			min = tx;
+			normal.set( 1, 0, 0 );
 
 
 		}
 		}
-		*/
-
-		function initialNormal3() {
 
 
-			// select an initial normal vector perpendicular to the first tangent vector,
-			// and in the direction of the smallest tangent xyz component
+		if ( ty <= min ) {
 
 
-			normals[ 0 ] = new Vector3();
-			binormals[ 0 ] = new Vector3();
-			smallest = Number.MAX_VALUE;
-			tx = Math.abs( tangents[ 0 ].x );
-			ty = Math.abs( tangents[ 0 ].y );
-			tz = Math.abs( tangents[ 0 ].z );
+			min = ty;
+			normal.set( 0, 1, 0 );
 
 
-			if ( tx <= smallest ) {
-
-				smallest = tx;
-				normal.set( 1, 0, 0 );
-
-			}
-
-			if ( ty <= smallest ) {
-
-				smallest = ty;
-				normal.set( 0, 1, 0 );
-
-			}
-
-			if ( tz <= smallest ) {
+		}
 
 
-				normal.set( 0, 0, 1 );
+		if ( tz <= min ) {
 
 
-			}
+			normal.set( 0, 0, 1 );
 
 
-			vec.crossVectors( tangents[ 0 ], normal ).normalize();
+		}
 
 
-			normals[ 0 ].crossVectors( tangents[ 0 ], vec );
-			binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
+		vec.crossVectors( tangents[ 0 ], normal ).normalize();
 
 
-		}
+		normals[ 0 ].crossVectors( tangents[ 0 ], vec );
+		binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
 
 
 
 
 		// compute the slowly-varying normal and binormal vectors for each segment on the path
 		// compute the slowly-varying normal and binormal vectors for each segment on the path
 
 
-		for ( i = 1; i < numpoints; i ++ ) {
+		for ( i = 1; i <= segments; i ++ ) {
 
 
 			normals[ i ] = normals[ i - 1 ].clone();
 			normals[ i ] = normals[ i - 1 ].clone();
 
 
@@ -24761,21 +24755,20 @@
 
 
 		}
 		}
 
 
-
 		// if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
 		// if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
 
 
 		if ( closed ) {
 		if ( closed ) {
 
 
-			theta = Math.acos( exports.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
-			theta /= ( numpoints - 1 );
+			theta = Math.acos( exports.Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
+			theta /= segments;
 
 
-			if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
+			if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
 
 
 				theta = - theta;
 				theta = - theta;
 
 
 			}
 			}
 
 
-			for ( i = 1; i < numpoints; i ++ ) {
+			for ( i = 1; i <= segments; i ++ ) {
 
 
 				// twist a little...
 				// twist a little...
 				normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
 				normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
@@ -24785,7 +24778,51 @@
 
 
 		}
 		}
 
 
-	};
+	}
+
+	/**
+	 * @author oosmoxiecode / https://github.com/oosmoxiecode
+	 * @author WestLangley / https://github.com/WestLangley
+	 * @author zz85 / https://github.com/zz85
+	 * @author miningold / https://github.com/miningold
+	 * @author jonobr1 / https://github.com/jonobr1
+	 *
+	 * Creates a tube which extrudes along a 3d spline.
+	 */
+
+	function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
+
+		Geometry.call( this );
+
+		this.type = 'TubeGeometry';
+
+		this.parameters = {
+			path: path,
+			tubularSegments: tubularSegments,
+			radius: radius,
+			radialSegments: radialSegments,
+			closed: closed
+		};
+
+		if( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
+
+		var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
+
+		// expose internals
+
+		this.tangents = bufferGeometry.tangents;
+		this.normals = bufferGeometry.normals;
+		this.binormals = bufferGeometry.binormals;
+
+		// create geometry
+
+		this.fromBufferGeometry( bufferGeometry );
+		this.mergeVertices();
+
+	}
+
+	TubeGeometry.prototype = Object.create( Geometry.prototype );
+	TubeGeometry.prototype.constructor = TubeGeometry;
 
 
 	/**
 	/**
 	 * @author Mugen87 / https://github.com/Mugen87
 	 * @author Mugen87 / https://github.com/Mugen87
@@ -25189,7 +25226,7 @@
 				cx = contour[ verts[ w ] ].x;
 				cx = contour[ verts[ w ] ].x;
 				cy = contour[ verts[ w ] ].y;
 				cy = contour[ verts[ w ] ].y;
 
 
-				if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
+				if ( ( bx - ax ) * ( cy - ay ) - ( by - ay ) * ( cx - ax ) <= 0 ) return false;
 
 
 				var aX, aY, bX, bY, cX, cY;
 				var aX, aY, bX, bY, cX, cY;
 				var apx, apy, bpx, bpy, cpx, cpy;
 				var apx, apy, bpx, bpy, cpx, cpy;
@@ -27919,6 +27956,7 @@
 		PolyhedronGeometry: PolyhedronGeometry,
 		PolyhedronGeometry: PolyhedronGeometry,
 		PolyhedronBufferGeometry: PolyhedronBufferGeometry,
 		PolyhedronBufferGeometry: PolyhedronBufferGeometry,
 		TubeGeometry: TubeGeometry,
 		TubeGeometry: TubeGeometry,
+		TubeBufferGeometry: TubeBufferGeometry,
 		TorusKnotGeometry: TorusKnotGeometry,
 		TorusKnotGeometry: TorusKnotGeometry,
 		TorusKnotBufferGeometry: TorusKnotBufferGeometry,
 		TorusKnotBufferGeometry: TorusKnotBufferGeometry,
 		TorusGeometry: TorusGeometry,
 		TorusGeometry: TorusGeometry,
@@ -41873,6 +41911,7 @@
 	exports.PolyhedronGeometry = PolyhedronGeometry;
 	exports.PolyhedronGeometry = PolyhedronGeometry;
 	exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
 	exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
 	exports.TubeGeometry = TubeGeometry;
 	exports.TubeGeometry = TubeGeometry;
+	exports.TubeBufferGeometry = TubeBufferGeometry;
 	exports.TorusKnotGeometry = TorusKnotGeometry;
 	exports.TorusKnotGeometry = TorusKnotGeometry;
 	exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
 	exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
 	exports.TorusGeometry = TorusGeometry;
 	exports.TorusGeometry = TorusGeometry;

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


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