Skip to content

Commit 2676030

Browse files
authored
Docs: More JSDoc. (#30615)
* Docs: More JSDoc. * JSDoc: Improve page title.
1 parent ff1b141 commit 2676030

23 files changed

+766
-1
lines changed

src/geometries/BoxGeometry.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,45 @@ import { BufferGeometry } from '../core/BufferGeometry.js';
22
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
33
import { Vector3 } from '../math/Vector3.js';
44

5+
/**
6+
* A geometry class for a rectangular cuboid with a given width, height, and depth.
7+
* On creation, the cuboid is centred on the origin, with each edge parallel to one
8+
* of the axes.
9+
*
10+
* ```js
11+
* const geometry = new THREE.BoxGeometry( 1, 1, 1 );
12+
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
13+
* const cube = new THREE.Mesh( geometry, material );
14+
* scene.add( cube );
15+
* ```
16+
*
17+
* @augments BufferGeometry
18+
*/
519
class BoxGeometry extends BufferGeometry {
620

21+
/**
22+
* Constructs a new box geometry.
23+
*
24+
* @param {number} [width=1] - The width. That is, the length of the edges parallel to the X axis.
25+
* @param {number} [height=1] - The height. That is, the length of the edges parallel to the Y axis.
26+
* @param {number} [depth=1] - The depth. That is, the length of the edges parallel to the Z axis.
27+
* @param {number} [widthSegments=1] - Number of segmented rectangular faces along the width of the sides.
28+
* @param {number} [heightSegments=1] - Number of segmented rectangular faces along the height of the sides.
29+
* @param {number} [depthSegments=1] - Number of segmented rectangular faces along the depth of the sides.
30+
*/
731
constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
832

933
super();
1034

1135
this.type = 'BoxGeometry';
1236

37+
/**
38+
* Holds the constructor parameters that have been
39+
* used to generate the geometry. Any modification
40+
* after instantiation does not change the geometry.
41+
*
42+
* @type {Object}
43+
*/
1344
this.parameters = {
1445
width: width,
1546
height: height,
@@ -169,6 +200,13 @@ class BoxGeometry extends BufferGeometry {
169200

170201
}
171202

203+
/**
204+
* Factory method for creating an instance of this class from the given
205+
* JSON object.
206+
*
207+
* @param {Object} data - A JSON object representing the serialized geometry.
208+
* @return {BoxGeometry} A new instance.
209+
*/
172210
static fromJSON( data ) {
173211

174212
return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );

src/geometries/CapsuleGeometry.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
import { Path } from '../extras/core/Path.js';
22
import { LatheGeometry } from './LatheGeometry.js';
33

4+
/**
5+
* A geometry class for a capsule with given radii and height. It is constructed using a lathe.
6+
*
7+
* ```js
8+
* const geometry = new THREE.CapsuleGeometry( 1, 1, 4, 8 );
9+
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
10+
* const capsule = new THREE.Mesh( geometry, material );
11+
* scene.add( capsule );
12+
* ```
13+
*
14+
* @augments LatheGeometry
15+
*/
416
class CapsuleGeometry extends LatheGeometry {
517

18+
/**
19+
* Constructs a new capsule geometry.
20+
*
21+
* @param {number} [radius=1] - Radius of the capsule.
22+
* @param {number} [length=1] - Length of the middle section.
23+
* @param {number} [capSegments=4] - Number of curve segments used to build the caps.
24+
* @param {number} [radialSegments=8] - Number of segmented faces around the circumference of the capsule.
25+
*/
626
constructor( radius = 1, length = 1, capSegments = 4, radialSegments = 8 ) {
727

828
const path = new Path();
@@ -13,6 +33,13 @@ class CapsuleGeometry extends LatheGeometry {
1333

1434
this.type = 'CapsuleGeometry';
1535

36+
/**
37+
* Holds the constructor parameters that have been
38+
* used to generate the geometry. Any modification
39+
* after instantiation does not change the geometry.
40+
*
41+
* @type {Object}
42+
*/
1643
this.parameters = {
1744
radius: radius,
1845
length: length,
@@ -22,6 +49,13 @@ class CapsuleGeometry extends LatheGeometry {
2249

2350
}
2451

52+
/**
53+
* Factory method for creating an instance of this class from the given
54+
* JSON object.
55+
*
56+
* @param {Object} data - A JSON object representing the serialized geometry.
57+
* @return {CapsuleGeometry} A new instance.
58+
*/
2559
static fromJSON( data ) {
2660

2761
return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments );

src/geometries/CircleGeometry.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,47 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
33
import { Vector3 } from '../math/Vector3.js';
44
import { Vector2 } from '../math/Vector2.js';
55

6+
/**
7+
* A simple shape of Euclidean geometry. It is constructed from a
8+
* number of triangular segments that are oriented around a central point and
9+
* extend as far out as a given radius. It is built counter-clockwise from a
10+
* start angle and a given central angle. It can also be used to create
11+
* regular polygons, where the number of segments determines the number of
12+
* sides.
13+
*
14+
* ```js
15+
* const geometry = new THREE.CircleGeometry( 5, 32 );
16+
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
17+
* const circle = new THREE.Mesh( geometry, material );
18+
* scene.add( circle )
19+
* ```
20+
*
21+
* @augments BufferGeometry
22+
*/
623
class CircleGeometry extends BufferGeometry {
724

25+
/**
26+
* Constructs a new circle geometry.
27+
*
28+
* @param {number} [radius=1] - Radius of the circle.
29+
* @param {number} [segments=32] - Number of segments (triangles), minimum = `3`.
30+
* @param {number} [thetaStart=0] - Start angle for first segment in radians.
31+
* @param {number} [thetaLength=Math.PI*2] - The central angle, often called theta,
32+
* of the circular sector in radians. The default value results in a complete circle.
33+
*/
834
constructor( radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2 ) {
935

1036
super();
1137

1238
this.type = 'CircleGeometry';
1339

40+
/**
41+
* Holds the constructor parameters that have been
42+
* used to generate the geometry. Any modification
43+
* after instantiation does not change the geometry.
44+
*
45+
* @type {Object}
46+
*/
1447
this.parameters = {
1548
radius: radius,
1649
segments: segments,
@@ -89,6 +122,13 @@ class CircleGeometry extends BufferGeometry {
89122

90123
}
91124

125+
/**
126+
* Factory method for creating an instance of this class from the given
127+
* JSON object.
128+
*
129+
* @param {Object} data - A JSON object representing the serialized geometry.
130+
* @return {CircleGeometry} A new instance.
131+
*/
92132
static fromJSON( data ) {
93133

94134
return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );

src/geometries/ConeGeometry.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
import { CylinderGeometry } from './CylinderGeometry.js';
22

3+
/**
4+
* A geometry class for representing a cone.
5+
*
6+
* ```js
7+
* const geometry = new THREE.ConeGeometry( 5, 20, 32 );
8+
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
9+
* const cone = new THREE.Mesh(geometry, material );
10+
* scene.add( cone );
11+
* ```
12+
*
13+
* @augments CylinderGeometry
14+
*/
315
class ConeGeometry extends CylinderGeometry {
416

17+
/**
18+
* Constructs a new cone geometry.
19+
*
20+
* @param {number} [radius=1] - Radius of the cone base.
21+
* @param {number} [height=1] - Height of the cone.
22+
* @param {number} [radialSegments=32] - Number of segmented faces around the circumference of the cone.
23+
* @param {number} [heightSegments=1] - Number of rows of faces along the height of the cone.
24+
* @param {boolean} [openEnded=false] - Whether the base of the cone is open or capped.
25+
* @param {boolean} [thetaStart=0] - Start angle for first segment, in radians.
26+
* @param {boolean} [thetaLength=Math.PI*2] - The central angle, often called theta, of the circular sector, in radians.
27+
* The default value results in a complete cone.
28+
*/
529
constructor( radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
630

731
super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
832

933
this.type = 'ConeGeometry';
1034

35+
/**
36+
* Holds the constructor parameters that have been
37+
* used to generate the geometry. Any modification
38+
* after instantiation does not change the geometry.
39+
*
40+
* @type {Object}
41+
*/
1142
this.parameters = {
1243
radius: radius,
1344
height: height,
@@ -20,6 +51,13 @@ class ConeGeometry extends CylinderGeometry {
2051

2152
}
2253

54+
/**
55+
* Factory method for creating an instance of this class from the given
56+
* JSON object.
57+
*
58+
* @param {Object} data - A JSON object representing the serialized geometry.
59+
* @return {ConeGeometry} A new instance.
60+
*/
2361
static fromJSON( data ) {
2462

2563
return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );

src/geometries/CylinderGeometry.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,46 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
33
import { Vector3 } from '../math/Vector3.js';
44
import { Vector2 } from '../math/Vector2.js';
55

6+
/**
7+
* A geometry class for representing a cylinder.
8+
*
9+
* ```js
10+
* const geometry = new THREE.CylinderGeometry( 5, 5, 20, 32 );
11+
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
12+
* const cylinder = new THREE.Mesh( geometry, material );
13+
* scene.add( cylinder );
14+
* ```
15+
*
16+
* @augments BufferGeometry
17+
*/
618
class CylinderGeometry extends BufferGeometry {
719

20+
/**
21+
* Constructs a new cylinder geometry.
22+
*
23+
* @param {number} [radiusTop=1] - Radius of the cylinder at the top.
24+
* @param {number} [radiusBottom=1] - Radius of the cylinder at the bottom.
25+
* @param {number} [height=1] - Height of the cylinder.
26+
* @param {number} [radialSegments=32] - Number of segmented faces around the circumference of the cylinder.
27+
* @param {number} [heightSegments=1] - Number of rows of faces along the height of the cylinder.
28+
* @param {boolean} [openEnded=false] - Whether the base of the cylinder is open or capped.
29+
* @param {boolean} [thetaStart=0] - Start angle for first segment, in radians.
30+
* @param {boolean} [thetaLength=Math.PI*2] - The central angle, often called theta, of the circular sector, in radians.
31+
* The default value results in a complete cylinder.
32+
*/
833
constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
934

1035
super();
1136

1237
this.type = 'CylinderGeometry';
1338

39+
/**
40+
* Holds the constructor parameters that have been
41+
* used to generate the geometry. Any modification
42+
* after instantiation does not change the geometry.
43+
*
44+
* @type {Object}
45+
*/
1446
this.parameters = {
1547
radiusTop: radiusTop,
1648
radiusBottom: radiusBottom,
@@ -281,6 +313,13 @@ class CylinderGeometry extends BufferGeometry {
281313

282314
}
283315

316+
/**
317+
* Factory method for creating an instance of this class from the given
318+
* JSON object.
319+
*
320+
* @param {Object} data - A JSON object representing the serialized geometry.
321+
* @return {CylinderGeometry} A new instance.
322+
*/
284323
static fromJSON( data ) {
285324

286325
return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );

src/geometries/DodecahedronGeometry.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
import { PolyhedronGeometry } from './PolyhedronGeometry.js';
22

3+
/**
4+
* A geometry class for representing a dodecahedron.
5+
*
6+
* ```js
7+
* const geometry = new THREE.DodecahedronGeometry();
8+
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
9+
* const dodecahedron = new THREE.Mesh( geometry, material );
10+
* scene.add( dodecahedron );
11+
* ```
12+
*
13+
* @augments PolyhedronGeometry
14+
*/
315
class DodecahedronGeometry extends PolyhedronGeometry {
416

17+
/**
18+
* Constructs a new dodecahedron geometry.
19+
*
20+
* @param {number} [radius=1] - Radius of the dodecahedron.
21+
* @param {number} [detail=0] - Setting this to a value greater than `0` adds vertices making it no longer a dodecahedron.
22+
*/
523
constructor( radius = 1, detail = 0 ) {
624

725
const t = ( 1 + Math.sqrt( 5 ) ) / 2;
@@ -47,13 +65,27 @@ class DodecahedronGeometry extends PolyhedronGeometry {
4765

4866
this.type = 'DodecahedronGeometry';
4967

68+
/**
69+
* Holds the constructor parameters that have been
70+
* used to generate the geometry. Any modification
71+
* after instantiation does not change the geometry.
72+
*
73+
* @type {Object}
74+
*/
5075
this.parameters = {
5176
radius: radius,
5277
detail: detail
5378
};
5479

5580
}
5681

82+
/**
83+
* Factory method for creating an instance of this class from the given
84+
* JSON object.
85+
*
86+
* @param {Object} data - A JSON object representing the serialized geometry.
87+
* @return {DodecahedronGeometry} A new instance.
88+
*/
5789
static fromJSON( data ) {
5890

5991
return new DodecahedronGeometry( data.radius, data.detail );

src/geometries/EdgesGeometry.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,42 @@ const _v1 = /*@__PURE__*/ new Vector3();
99
const _normal = /*@__PURE__*/ new Vector3();
1010
const _triangle = /*@__PURE__*/ new Triangle();
1111

12+
/**
13+
* Can be used as a helper object to view the edges of a geometry.
14+
*
15+
* ```js
16+
* const geometry = new THREE.BoxGeometry();
17+
* const edges = new THREE.EdgesGeometry( geometry );
18+
* const line = new THREE.LineSegments( edges );
19+
* scene.add( line );
20+
* ```
21+
*
22+
* Note: It is not yet possible to serialize/deserialize instances of this class.
23+
*
24+
* @augments BufferGeometry
25+
*/
1226
class EdgesGeometry extends BufferGeometry {
1327

28+
/**
29+
* Constructs a new edges geometry.
30+
*
31+
* @param {?BufferGeometry} [geometry=null] - The geometry.
32+
* @param {number} [thresholdAngle=1] - An edge is only rendered if the angle (in degrees)
33+
* between the face normals of the adjoining faces exceeds this value.
34+
*/
1435
constructor( geometry = null, thresholdAngle = 1 ) {
1536

1637
super();
1738

1839
this.type = 'EdgesGeometry';
1940

41+
/**
42+
* Holds the constructor parameters that have been
43+
* used to generate the geometry. Any modification
44+
* after instantiation does not change the geometry.
45+
*
46+
* @type {Object}
47+
*/
2048
this.parameters = {
2149
geometry: geometry,
2250
thresholdAngle: thresholdAngle

0 commit comments

Comments
 (0)