Skip to content

Commit f294fef

Browse files
Update TorusGeometry with thetaStart and thetaLength (mrdoob#32760)
1 parent c3a8142 commit f294fef

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

docs/scenes/geometry-browser.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,16 @@
558558
tube: 3,
559559
radialSegments: 16,
560560
tubularSegments: 100,
561-
arc: twoPi
561+
arc: twoPi,
562+
thetaStart: 0,
563+
thetaLength: twoPi
562564
};
563565

564566
function generateGeometry() {
565567

566568
updateGroupGeometry( mesh,
567569
new TorusGeometry(
568-
data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc
570+
data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc, data.thetaStart, data.thetaLength
569571
)
570572
);
571573

@@ -578,6 +580,8 @@
578580
folder.add( data, 'radialSegments', 2, 30 ).step( 1 ).onChange( generateGeometry );
579581
folder.add( data, 'tubularSegments', 3, 200 ).step( 1 ).onChange( generateGeometry );
580582
folder.add( data, 'arc', 0.1, twoPi ).onChange( generateGeometry );
583+
folder.add( data, 'thetaStart', 0.1, twoPi ).onChange( generateGeometry );
584+
folder.add( data, 'thetaLength', 0.1, twoPi ).onChange( generateGeometry );
581585

582586
generateGeometry();
583587

src/geometries/TorusGeometry.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ class TorusGeometry extends BufferGeometry {
2525
* @param {number} [radialSegments=12] - The number of radial segments.
2626
* @param {number} [tubularSegments=48] - The number of tubular segments.
2727
* @param {number} [arc=Math.PI*2] - Central angle in radians.
28+
* @param {number} [thetaStart=0] - Start of the tubular sweep in radians.
29+
* @param {number} [thetaLength=Math.PI*2] - Length of the tubular sweep in radians.
2830
*/
29-
constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2 ) {
31+
constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI * 2 ) {
3032

3133
super();
3234

@@ -44,7 +46,9 @@ class TorusGeometry extends BufferGeometry {
4446
tube: tube,
4547
radialSegments: radialSegments,
4648
tubularSegments: tubularSegments,
47-
arc: arc
49+
arc: arc,
50+
thetaStart: thetaStart,
51+
thetaLength: thetaLength,
4852
};
4953

5054
radialSegments = Math.floor( radialSegments );
@@ -67,10 +71,11 @@ class TorusGeometry extends BufferGeometry {
6771

6872
for ( let j = 0; j <= radialSegments; j ++ ) {
6973

74+
const v = thetaStart + ( j / radialSegments ) * thetaLength;
75+
7076
for ( let i = 0; i <= tubularSegments; i ++ ) {
7177

7278
const u = i / tubularSegments * arc;
73-
const v = j / radialSegments * Math.PI * 2;
7479

7580
// vertex
7681

0 commit comments

Comments
 (0)