|
@@ -11,17 +11,24 @@
|
|
|
* http://www.cs.indiana.edu/pub/techreports/TR425.pdf
|
|
|
*/
|
|
|
|
|
|
-THREE.TubeGeometry = function( path, segments, radius, radialSegments, closed ) {
|
|
|
+THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed ) {
|
|
|
|
|
|
THREE.Geometry.call( this );
|
|
|
|
|
|
- this.path = path;
|
|
|
- this.segments = segments || 64;
|
|
|
- this.radius = radius || 1;
|
|
|
- this.radialSegments = radialSegments || 8;
|
|
|
- this.closed = closed || false;
|
|
|
+ this.parameters = {
|
|
|
+ path: path,
|
|
|
+ segments: segments,
|
|
|
+ radius: radius,
|
|
|
+ radialSegments: radialSegments,
|
|
|
+ closed: closed
|
|
|
+ };
|
|
|
|
|
|
- this.grid = [];
|
|
|
+ segments = segments || 64;
|
|
|
+ radius = radius || 1;
|
|
|
+ radialSegments = radialSegments || 8;
|
|
|
+ closed = closed || false;
|
|
|
+
|
|
|
+ var grid = [];
|
|
|
|
|
|
var scope = this,
|
|
|
|
|
@@ -29,7 +36,7 @@ THREE.TubeGeometry = function( path, segments, radius, radialSegments, closed )
|
|
|
normal,
|
|
|
binormal,
|
|
|
|
|
|
- numpoints = this.segments + 1,
|
|
|
+ numpoints = segments + 1,
|
|
|
|
|
|
x, y, z,
|
|
|
tx, ty, tz,
|
|
@@ -42,7 +49,7 @@ THREE.TubeGeometry = function( path, segments, radius, radialSegments, closed )
|
|
|
a, b, c, d,
|
|
|
uva, uvb, uvc, uvd;
|
|
|
|
|
|
- var frames = new THREE.TubeGeometry.FrenetFrames( this.path, this.segments, this.closed ),
|
|
|
+ var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
|
|
|
tangents = frames.tangents,
|
|
|
normals = frames.normals,
|
|
|
binormals = frames.binormals;
|
|
@@ -58,12 +65,11 @@ THREE.TubeGeometry = function( path, segments, radius, radialSegments, closed )
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// consruct the grid
|
|
|
|
|
|
for ( i = 0; i < numpoints; i++ ) {
|
|
|
|
|
|
- this.grid[ i ] = [];
|
|
|
+ grid[ i ] = [];
|
|
|
|
|
|
u = i / ( numpoints - 1 );
|
|
|
|
|
@@ -73,19 +79,19 @@ THREE.TubeGeometry = function( path, segments, radius, radialSegments, closed )
|
|
|
normal = normals[ i ];
|
|
|
binormal = binormals[ i ];
|
|
|
|
|
|
- for ( j = 0; j < this.radialSegments; j++ ) {
|
|
|
+ for ( j = 0; j < radialSegments; j++ ) {
|
|
|
|
|
|
- v = j / this.radialSegments * 2 * Math.PI;
|
|
|
+ v = j / radialSegments * 2 * Math.PI;
|
|
|
|
|
|
- cx = -this.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
|
|
|
- cy = this.radius * Math.sin( v );
|
|
|
+ cx = -radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
|
|
|
+ cy = radius * Math.sin( v );
|
|
|
|
|
|
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;
|
|
|
|
|
|
- this.grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
|
|
|
+ grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -93,22 +99,22 @@ THREE.TubeGeometry = function( path, segments, radius, radialSegments, closed )
|
|
|
|
|
|
// construct the mesh
|
|
|
|
|
|
- for ( i = 0; i < this.segments; i++ ) {
|
|
|
+ for ( i = 0; i < segments; i++ ) {
|
|
|
|
|
|
- for ( j = 0; j < this.radialSegments; j++ ) {
|
|
|
+ for ( j = 0; j < radialSegments; j++ ) {
|
|
|
|
|
|
- ip = ( this.closed ) ? (i + 1) % this.segments : i + 1;
|
|
|
- jp = (j + 1) % this.radialSegments;
|
|
|
+ ip = ( closed ) ? (i + 1) % segments : i + 1;
|
|
|
+ jp = (j + 1) % radialSegments;
|
|
|
|
|
|
- a = this.grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
|
|
|
- b = this.grid[ ip ][ j ];
|
|
|
- c = this.grid[ ip ][ jp ];
|
|
|
- d = this.grid[ i ][ jp ];
|
|
|
+ a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
|
|
|
+ b = grid[ ip ][ j ];
|
|
|
+ c = grid[ ip ][ jp ];
|
|
|
+ d = grid[ i ][ jp ];
|
|
|
|
|
|
- uva = new THREE.Vector2( i / this.segments, j / this.radialSegments );
|
|
|
- uvb = new THREE.Vector2( ( i + 1 ) / this.segments, j / this.radialSegments );
|
|
|
- uvc = new THREE.Vector2( ( i + 1 ) / this.segments, ( j + 1 ) / this.radialSegments );
|
|
|
- uvd = new THREE.Vector2( i / this.segments, ( j + 1 ) / this.radialSegments );
|
|
|
+ uva = new THREE.Vector2( i / segments, j / radialSegments );
|
|
|
+ uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
|
|
|
+ uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
|
|
|
+ uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
|
|
|
|
|
|
this.faces.push( new THREE.Face3( a, b, d ) );
|
|
|
this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
|
|
@@ -128,7 +134,7 @@ THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
|
|
|
|
|
|
|
|
|
// For computing of Frenet frames, exposing the tangents, normals and binormals the spline
|
|
|
-THREE.TubeGeometry.FrenetFrames = function(path, segments, closed) {
|
|
|
+THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
|
|
|
|
|
|
var tangent = new THREE.Vector3(),
|
|
|
normal = new THREE.Vector3(),
|