33 *
44 * see: http://www.blackpawn.com/texts/pqtorus/
55 */
6- THREE . TorusKnotBufferGeometry = function ( radius , tube , radialSegments , tubularSegments , p , q , heightScale , arc ) {
6+ THREE . TorusKnotBufferGeometry = function ( radius , tube , tubularSegments , radialSegments , p , q , heightScale ) {
77
88 THREE . BufferGeometry . call ( this ) ;
99
@@ -12,22 +12,20 @@ THREE.TorusKnotBufferGeometry = function ( radius, tube, radialSegments, tubular
1212 this . parameters = {
1313 radius : radius ,
1414 tube : tube ,
15- radialSegments : radialSegments ,
1615 tubularSegments : tubularSegments ,
16+ radialSegments : radialSegments ,
1717 p : p ,
18- q : q ,
19- heightScale : heightScale ,
20- arc : arc
18+ q : q
2119 } ;
2220
21+ if ( heightScale !== undefined ) console . warn ( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' ) ;
22+
2323 radius = radius || 100 ;
2424 tube = tube || 40 ;
25- radialSegments = Math . floor ( radialSegments ) || 64 ;
26- tubularSegments = Math . floor ( tubularSegments ) || 6 ;
25+ tubularSegments = Math . floor ( tubularSegments ) || 64 ;
26+ radialSegments = Math . floor ( radialSegments ) || 8 ;
2727 p = p || 2 ;
2828 q = q || 3 ;
29- heightScale = heightScale || 1 ;
30- arc = arc || Math . PI * 2 ;
3129
3230 // used to calculate buffer length
3331 var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) ) ;
@@ -55,17 +53,17 @@ THREE.TorusKnotBufferGeometry = function ( radius, tube, radialSegments, tubular
5553
5654 // generate vertices, normals and uvs
5755
58- for ( i = 0 ; i <= radialSegments ; ++ i ) {
56+ for ( i = 0 ; i <= tubularSegments ; ++ i ) {
5957
60- // the radian "u" is used to calculate the position on the torus curve of the current radial segement
58+ // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
6159
62- var u = i / radialSegments * p * arc ;
60+ var u = i / tubularSegments * p * Math . PI * 2 ;
6361
6462 // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
6563 // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
6664
67- calculatePositionOnCurve ( u , p , q , radius , heightScale , P1 ) ;
68- calculatePositionOnCurve ( u + 0.01 , p , q , radius , heightScale , P2 ) ;
65+ calculatePositionOnCurve ( u , p , q , radius , P1 ) ;
66+ calculatePositionOnCurve ( u + 0.01 , p , q , radius , P2 ) ;
6967
7068 // calculate orthonormal basis
7169
@@ -79,12 +77,12 @@ THREE.TorusKnotBufferGeometry = function ( radius, tube, radialSegments, tubular
7977 B . normalize ( ) ;
8078 N . normalize ( ) ;
8179
82- for ( j = 0 ; j <= tubularSegments ; ++ j ) {
80+ for ( j = 0 ; j <= radialSegments ; ++ j ) {
8381
8482 // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
8583 // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
8684
87- var v = j / tubularSegments * Math . PI * 2 ;
85+ var v = j / radialSegments * Math . PI * 2 ;
8886 var cx = - tube * Math . cos ( v ) ;
8987 var cy = tube * Math . sin ( v ) ;
9088
@@ -103,8 +101,8 @@ THREE.TorusKnotBufferGeometry = function ( radius, tube, radialSegments, tubular
103101 normals . setXYZ ( index , normal . x , normal . y , normal . z ) ;
104102
105103 // uv
106- uv . x = i / radialSegments ;
107- uv . y = j / tubularSegments ;
104+ uv . x = i / tubularSegments ;
105+ uv . y = j / radialSegments ;
108106 uvs . setXY ( index , uv . x , uv . y ) ;
109107
110108 // increase index
@@ -116,15 +114,15 @@ THREE.TorusKnotBufferGeometry = function ( radius, tube, radialSegments, tubular
116114
117115 // generate indices
118116
119- for ( j = 1 ; j <= radialSegments ; j ++ ) {
117+ for ( j = 1 ; j <= tubularSegments ; j ++ ) {
120118
121- for ( i = 1 ; i <= tubularSegments ; i ++ ) {
119+ for ( i = 1 ; i <= radialSegments ; i ++ ) {
122120
123121 // indices
124- var a = ( tubularSegments + 1 ) * ( j - 1 ) + ( i - 1 ) ;
125- var b = ( tubularSegments + 1 ) * j + ( i - 1 ) ;
126- var c = ( tubularSegments + 1 ) * j + i ;
127- var d = ( tubularSegments + 1 ) * ( j - 1 ) + i ;
122+ var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 ) ;
123+ var b = ( radialSegments + 1 ) * j + ( i - 1 ) ;
124+ var c = ( radialSegments + 1 ) * j + i ;
125+ var d = ( radialSegments + 1 ) * ( j - 1 ) + i ;
128126
129127 // face one
130128 indices . setX ( indexOffset , a ) ; indexOffset ++ ;
@@ -149,7 +147,7 @@ THREE.TorusKnotBufferGeometry = function ( radius, tube, radialSegments, tubular
149147
150148 // this function calculates the current position on the torus curve
151149
152- function calculatePositionOnCurve ( u , p , q , radius , heightScale , position ) {
150+ function calculatePositionOnCurve ( u , p , q , radius , position ) {
153151
154152 var cu = Math . cos ( u ) ;
155153 var su = Math . sin ( u ) ;
@@ -158,7 +156,7 @@ THREE.TorusKnotBufferGeometry = function ( radius, tube, radialSegments, tubular
158156
159157 position . x = radius * ( 2 + cs ) * 0.5 * cu ;
160158 position . y = radius * ( 2 + cs ) * su * 0.5 ;
161- position . z = heightScale * radius * Math . sin ( quOverP ) * 0.5 ;
159+ position . z = radius * Math . sin ( quOverP ) * 0.5 ;
162160
163161 }
164162
0 commit comments