|
24492 | 24492 | *
|
24493 | 24493 | * Creates a tube which extrudes along a 3d spline.
|
24494 | 24494 | *
|
24495 |
| - * Uses parallel transport frames as described in: |
24496 |
| - * |
24497 |
| - * http://www.cs.indiana.edu/pub/techreports/TR425.pdf |
24498 | 24495 | */
|
24499 | 24496 |
|
24500 | 24497 | function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
|
|
24516 | 24513 | radialSegments = radialSegments || 8;
|
24517 | 24514 | closed = closed || false;
|
24518 | 24515 |
|
24519 |
| - var frames = new FrenetFrames( path, tubularSegments, closed ); |
| 24516 | + var frames = path.computeFrenetFrames( tubularSegments, closed ); |
24520 | 24517 |
|
24521 | 24518 | // expose internals
|
24522 | 24519 |
|
@@ -24663,123 +24660,6 @@
|
24663 | 24660 | TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
|
24664 | 24661 | TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
|
24665 | 24662 |
|
24666 |
| - // For computing of Frenet frames, exposing the tangents, normals and binormals the spline |
24667 |
| - |
24668 |
| - function FrenetFrames( path, segments, closed ) { |
24669 |
| - |
24670 |
| - var normal = new Vector3(); |
24671 |
| - |
24672 |
| - var tangents = []; |
24673 |
| - var normals = []; |
24674 |
| - var binormals = []; |
24675 |
| - |
24676 |
| - var vec = new Vector3(); |
24677 |
| - var mat = new Matrix4(); |
24678 |
| - |
24679 |
| - var i, u, theta; |
24680 |
| - |
24681 |
| - // expose internals |
24682 |
| - |
24683 |
| - this.tangents = tangents; |
24684 |
| - this.normals = normals; |
24685 |
| - this.binormals = binormals; |
24686 |
| - |
24687 |
| - // compute the tangent vectors for each segment on the path |
24688 |
| - |
24689 |
| - for ( i = 0; i <= segments; i ++ ) { |
24690 |
| - |
24691 |
| - u = i / segments; |
24692 |
| - |
24693 |
| - tangents[ i ] = path.getTangentAt( u ); |
24694 |
| - tangents[ i ].normalize(); |
24695 |
| - |
24696 |
| - } |
24697 |
| - |
24698 |
| - // select an initial normal vector perpendicular to the first tangent vector, |
24699 |
| - // and in the direction of the minimum tangent xyz component |
24700 |
| - |
24701 |
| - normals[ 0 ] = new Vector3(); |
24702 |
| - binormals[ 0 ] = new Vector3(); |
24703 |
| - var min = Number.MAX_VALUE; |
24704 |
| - var tx = Math.abs( tangents[ 0 ].x ); |
24705 |
| - var ty = Math.abs( tangents[ 0 ].y ); |
24706 |
| - var tz = Math.abs( tangents[ 0 ].z ); |
24707 |
| - |
24708 |
| - if ( tx <= min ) { |
24709 |
| - |
24710 |
| - min = tx; |
24711 |
| - normal.set( 1, 0, 0 ); |
24712 |
| - |
24713 |
| - } |
24714 |
| - |
24715 |
| - if ( ty <= min ) { |
24716 |
| - |
24717 |
| - min = ty; |
24718 |
| - normal.set( 0, 1, 0 ); |
24719 |
| - |
24720 |
| - } |
24721 |
| - |
24722 |
| - if ( tz <= min ) { |
24723 |
| - |
24724 |
| - normal.set( 0, 0, 1 ); |
24725 |
| - |
24726 |
| - } |
24727 |
| - |
24728 |
| - vec.crossVectors( tangents[ 0 ], normal ).normalize(); |
24729 |
| - |
24730 |
| - normals[ 0 ].crossVectors( tangents[ 0 ], vec ); |
24731 |
| - binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ); |
24732 |
| - |
24733 |
| - |
24734 |
| - // compute the slowly-varying normal and binormal vectors for each segment on the path |
24735 |
| - |
24736 |
| - for ( i = 1; i <= segments; i ++ ) { |
24737 |
| - |
24738 |
| - normals[ i ] = normals[ i - 1 ].clone(); |
24739 |
| - |
24740 |
| - binormals[ i ] = binormals[ i - 1 ].clone(); |
24741 |
| - |
24742 |
| - vec.crossVectors( tangents[ i - 1 ], tangents[ i ] ); |
24743 |
| - |
24744 |
| - if ( vec.length() > Number.EPSILON ) { |
24745 |
| - |
24746 |
| - vec.normalize(); |
24747 |
| - |
24748 |
| - theta = Math.acos( exports.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors |
24749 |
| - |
24750 |
| - normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) ); |
24751 |
| - |
24752 |
| - } |
24753 |
| - |
24754 |
| - binormals[ i ].crossVectors( tangents[ i ], normals[ i ] ); |
24755 |
| - |
24756 |
| - } |
24757 |
| - |
24758 |
| - // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same |
24759 |
| - |
24760 |
| - if ( closed ) { |
24761 |
| - |
24762 |
| - theta = Math.acos( exports.Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) ); |
24763 |
| - theta /= segments; |
24764 |
| - |
24765 |
| - if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) { |
24766 |
| - |
24767 |
| - theta = - theta; |
24768 |
| - |
24769 |
| - } |
24770 |
| - |
24771 |
| - for ( i = 1; i <= segments; i ++ ) { |
24772 |
| - |
24773 |
| - // twist a little... |
24774 |
| - normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) ); |
24775 |
| - binormals[ i ].crossVectors( tangents[ i ], normals[ i ] ); |
24776 |
| - |
24777 |
| - } |
24778 |
| - |
24779 |
| - } |
24780 |
| - |
24781 |
| - } |
24782 |
| - |
24783 | 24663 | /**
|
24784 | 24664 | * @author oosmoxiecode / https://github.com/oosmoxiecode
|
24785 | 24665 | * @author WestLangley / https://github.com/WestLangley
|
|
24804 | 24684 | closed: closed
|
24805 | 24685 | };
|
24806 | 24686 |
|
24807 |
| - if( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' ); |
| 24687 | + if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' ); |
24808 | 24688 |
|
24809 | 24689 | var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
|
24810 | 24690 |
|
|
25955 | 25835 | * bevelSegments: <int>, // number of bevel layers
|
25956 | 25836 | *
|
25957 | 25837 | * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
|
25958 |
| - * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals |
| 25838 | + * frames: <Object> // containing arrays of tangents, normals, binormals |
25959 | 25839 | *
|
25960 | 25840 | * uvGenerator: <Object> // object that provides UV generator functions
|
25961 | 25841 | *
|
|
26037 | 25917 |
|
26038 | 25918 | // SETUP TNB variables
|
26039 | 25919 |
|
26040 |
| - // Reuse TNB from TubeGeomtry for now. |
26041 | 25920 | // TODO1 - have a .isClosed in spline?
|
26042 | 25921 |
|
26043 |
| - splineTube = options.frames !== undefined ? options.frames : new TubeGeometry.FrenetFrames( extrudePath, steps, false ); |
| 25922 | + splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false ); |
26044 | 25923 |
|
26045 | 25924 | // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
|
26046 | 25925 |
|
@@ -33677,6 +33556,123 @@
|
33677 | 33556 | var t = this.getUtoTmapping( u );
|
33678 | 33557 | return this.getTangent( t );
|
33679 | 33558 |
|
| 33559 | + }, |
| 33560 | + |
| 33561 | + computeFrenetFrames: function ( segments, closed ) { |
| 33562 | + |
| 33563 | + // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf |
| 33564 | + |
| 33565 | + var normal = new Vector3(); |
| 33566 | + |
| 33567 | + var tangents = []; |
| 33568 | + var normals = []; |
| 33569 | + var binormals = []; |
| 33570 | + |
| 33571 | + var vec = new Vector3(); |
| 33572 | + var mat = new Matrix4(); |
| 33573 | + |
| 33574 | + var i, u, theta; |
| 33575 | + |
| 33576 | + // compute the tangent vectors for each segment on the curve |
| 33577 | + |
| 33578 | + for ( i = 0; i <= segments; i ++ ) { |
| 33579 | + |
| 33580 | + u = i / segments; |
| 33581 | + |
| 33582 | + tangents[ i ] = this.getTangentAt( u ); |
| 33583 | + tangents[ i ].normalize(); |
| 33584 | + |
| 33585 | + } |
| 33586 | + |
| 33587 | + // select an initial normal vector perpendicular to the first tangent vector, |
| 33588 | + // and in the direction of the minimum tangent xyz component |
| 33589 | + |
| 33590 | + normals[ 0 ] = new Vector3(); |
| 33591 | + binormals[ 0 ] = new Vector3(); |
| 33592 | + var min = Number.MAX_VALUE; |
| 33593 | + var tx = Math.abs( tangents[ 0 ].x ); |
| 33594 | + var ty = Math.abs( tangents[ 0 ].y ); |
| 33595 | + var tz = Math.abs( tangents[ 0 ].z ); |
| 33596 | + |
| 33597 | + if ( tx <= min ) { |
| 33598 | + |
| 33599 | + min = tx; |
| 33600 | + normal.set( 1, 0, 0 ); |
| 33601 | + |
| 33602 | + } |
| 33603 | + |
| 33604 | + if ( ty <= min ) { |
| 33605 | + |
| 33606 | + min = ty; |
| 33607 | + normal.set( 0, 1, 0 ); |
| 33608 | + |
| 33609 | + } |
| 33610 | + |
| 33611 | + if ( tz <= min ) { |
| 33612 | + |
| 33613 | + normal.set( 0, 0, 1 ); |
| 33614 | + |
| 33615 | + } |
| 33616 | + |
| 33617 | + vec.crossVectors( tangents[ 0 ], normal ).normalize(); |
| 33618 | + |
| 33619 | + normals[ 0 ].crossVectors( tangents[ 0 ], vec ); |
| 33620 | + binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ); |
| 33621 | + |
| 33622 | + |
| 33623 | + // compute the slowly-varying normal and binormal vectors for each segment on the curve |
| 33624 | + |
| 33625 | + for ( i = 1; i <= segments; i ++ ) { |
| 33626 | + |
| 33627 | + normals[ i ] = normals[ i - 1 ].clone(); |
| 33628 | + |
| 33629 | + binormals[ i ] = binormals[ i - 1 ].clone(); |
| 33630 | + |
| 33631 | + vec.crossVectors( tangents[ i - 1 ], tangents[ i ] ); |
| 33632 | + |
| 33633 | + if ( vec.length() > Number.EPSILON ) { |
| 33634 | + |
| 33635 | + vec.normalize(); |
| 33636 | + |
| 33637 | + theta = Math.acos( exports.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors |
| 33638 | + |
| 33639 | + normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) ); |
| 33640 | + |
| 33641 | + } |
| 33642 | + |
| 33643 | + binormals[ i ].crossVectors( tangents[ i ], normals[ i ] ); |
| 33644 | + |
| 33645 | + } |
| 33646 | + |
| 33647 | + // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same |
| 33648 | + |
| 33649 | + if ( closed === true ) { |
| 33650 | + |
| 33651 | + theta = Math.acos( exports.Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) ); |
| 33652 | + theta /= segments; |
| 33653 | + |
| 33654 | + if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) { |
| 33655 | + |
| 33656 | + theta = - theta; |
| 33657 | + |
| 33658 | + } |
| 33659 | + |
| 33660 | + for ( i = 1; i <= segments; i ++ ) { |
| 33661 | + |
| 33662 | + // twist a little... |
| 33663 | + normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) ); |
| 33664 | + binormals[ i ].crossVectors( tangents[ i ], normals[ i ] ); |
| 33665 | + |
| 33666 | + } |
| 33667 | + |
| 33668 | + } |
| 33669 | + |
| 33670 | + return { |
| 33671 | + tangents: tangents, |
| 33672 | + normals: normals, |
| 33673 | + binormals: binormals |
| 33674 | + }; |
| 33675 | + |
33680 | 33676 | }
|
33681 | 33677 |
|
33682 | 33678 | };
|
|
0 commit comments