Skip to content

Commit

Permalink
Docs: More JSDoc. (#30615)
Browse files Browse the repository at this point in the history
* Docs: More JSDoc.

* JSDoc: Improve page title.
  • Loading branch information
Mugen87 authored Feb 26, 2025
1 parent ff1b141 commit 2676030
Show file tree
Hide file tree
Showing 23 changed files with 766 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/geometries/BoxGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,45 @@ import { BufferGeometry } from '../core/BufferGeometry.js';
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
import { Vector3 } from '../math/Vector3.js';

/**
* A geometry class for a rectangular cuboid with a given width, height, and depth.
* On creation, the cuboid is centred on the origin, with each edge parallel to one
* of the axes.
*
* ```js
* const geometry = new THREE.BoxGeometry( 1, 1, 1 );
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
* const cube = new THREE.Mesh( geometry, material );
* scene.add( cube );
* ```
*
* @augments BufferGeometry
*/
class BoxGeometry extends BufferGeometry {

/**
* Constructs a new box geometry.
*
* @param {number} [width=1] - The width. That is, the length of the edges parallel to the X axis.
* @param {number} [height=1] - The height. That is, the length of the edges parallel to the Y axis.
* @param {number} [depth=1] - The depth. That is, the length of the edges parallel to the Z axis.
* @param {number} [widthSegments=1] - Number of segmented rectangular faces along the width of the sides.
* @param {number} [heightSegments=1] - Number of segmented rectangular faces along the height of the sides.
* @param {number} [depthSegments=1] - Number of segmented rectangular faces along the depth of the sides.
*/
constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {

super();

this.type = 'BoxGeometry';

/**
* Holds the constructor parameters that have been
* used to generate the geometry. Any modification
* after instantiation does not change the geometry.
*
* @type {Object}
*/
this.parameters = {
width: width,
height: height,
Expand Down Expand Up @@ -169,6 +200,13 @@ class BoxGeometry extends BufferGeometry {

}

/**
* Factory method for creating an instance of this class from the given
* JSON object.
*
* @param {Object} data - A JSON object representing the serialized geometry.
* @return {BoxGeometry} A new instance.
*/
static fromJSON( data ) {

return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );
Expand Down
34 changes: 34 additions & 0 deletions src/geometries/CapsuleGeometry.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import { Path } from '../extras/core/Path.js';
import { LatheGeometry } from './LatheGeometry.js';

/**
* A geometry class for a capsule with given radii and height. It is constructed using a lathe.
*
* ```js
* const geometry = new THREE.CapsuleGeometry( 1, 1, 4, 8 );
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
* const capsule = new THREE.Mesh( geometry, material );
* scene.add( capsule );
* ```
*
* @augments LatheGeometry
*/
class CapsuleGeometry extends LatheGeometry {

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

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

this.type = 'CapsuleGeometry';

/**
* Holds the constructor parameters that have been
* used to generate the geometry. Any modification
* after instantiation does not change the geometry.
*
* @type {Object}
*/
this.parameters = {
radius: radius,
length: length,
Expand All @@ -22,6 +49,13 @@ class CapsuleGeometry extends LatheGeometry {

}

/**
* Factory method for creating an instance of this class from the given
* JSON object.
*
* @param {Object} data - A JSON object representing the serialized geometry.
* @return {CapsuleGeometry} A new instance.
*/
static fromJSON( data ) {

return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments );
Expand Down
40 changes: 40 additions & 0 deletions src/geometries/CircleGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,47 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
import { Vector3 } from '../math/Vector3.js';
import { Vector2 } from '../math/Vector2.js';

/**
* A simple shape of Euclidean geometry. It is constructed from a
* number of triangular segments that are oriented around a central point and
* extend as far out as a given radius. It is built counter-clockwise from a
* start angle and a given central angle. It can also be used to create
* regular polygons, where the number of segments determines the number of
* sides.
*
* ```js
* const geometry = new THREE.CircleGeometry( 5, 32 );
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
* const circle = new THREE.Mesh( geometry, material );
* scene.add( circle )
* ```
*
* @augments BufferGeometry
*/
class CircleGeometry extends BufferGeometry {

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

super();

this.type = 'CircleGeometry';

/**
* Holds the constructor parameters that have been
* used to generate the geometry. Any modification
* after instantiation does not change the geometry.
*
* @type {Object}
*/
this.parameters = {
radius: radius,
segments: segments,
Expand Down Expand Up @@ -89,6 +122,13 @@ class CircleGeometry extends BufferGeometry {

}

/**
* Factory method for creating an instance of this class from the given
* JSON object.
*
* @param {Object} data - A JSON object representing the serialized geometry.
* @return {CircleGeometry} A new instance.
*/
static fromJSON( data ) {

return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );
Expand Down
38 changes: 38 additions & 0 deletions src/geometries/ConeGeometry.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
import { CylinderGeometry } from './CylinderGeometry.js';

/**
* A geometry class for representing a cone.
*
* ```js
* const geometry = new THREE.ConeGeometry( 5, 20, 32 );
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
* const cone = new THREE.Mesh(geometry, material );
* scene.add( cone );
* ```
*
* @augments CylinderGeometry
*/
class ConeGeometry extends CylinderGeometry {

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

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

this.type = 'ConeGeometry';

/**
* Holds the constructor parameters that have been
* used to generate the geometry. Any modification
* after instantiation does not change the geometry.
*
* @type {Object}
*/
this.parameters = {
radius: radius,
height: height,
Expand All @@ -20,6 +51,13 @@ class ConeGeometry extends CylinderGeometry {

}

/**
* Factory method for creating an instance of this class from the given
* JSON object.
*
* @param {Object} data - A JSON object representing the serialized geometry.
* @return {ConeGeometry} A new instance.
*/
static fromJSON( data ) {

return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
Expand Down
39 changes: 39 additions & 0 deletions src/geometries/CylinderGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,46 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
import { Vector3 } from '../math/Vector3.js';
import { Vector2 } from '../math/Vector2.js';

/**
* A geometry class for representing a cylinder.
*
* ```js
* const geometry = new THREE.CylinderGeometry( 5, 5, 20, 32 );
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
* const cylinder = new THREE.Mesh( geometry, material );
* scene.add( cylinder );
* ```
*
* @augments BufferGeometry
*/
class CylinderGeometry extends BufferGeometry {

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

super();

this.type = 'CylinderGeometry';

/**
* Holds the constructor parameters that have been
* used to generate the geometry. Any modification
* after instantiation does not change the geometry.
*
* @type {Object}
*/
this.parameters = {
radiusTop: radiusTop,
radiusBottom: radiusBottom,
Expand Down Expand Up @@ -281,6 +313,13 @@ class CylinderGeometry extends BufferGeometry {

}

/**
* Factory method for creating an instance of this class from the given
* JSON object.
*
* @param {Object} data - A JSON object representing the serialized geometry.
* @return {CylinderGeometry} A new instance.
*/
static fromJSON( data ) {

return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
Expand Down
32 changes: 32 additions & 0 deletions src/geometries/DodecahedronGeometry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { PolyhedronGeometry } from './PolyhedronGeometry.js';

/**
* A geometry class for representing a dodecahedron.
*
* ```js
* const geometry = new THREE.DodecahedronGeometry();
* const material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
* const dodecahedron = new THREE.Mesh( geometry, material );
* scene.add( dodecahedron );
* ```
*
* @augments PolyhedronGeometry
*/
class DodecahedronGeometry extends PolyhedronGeometry {

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

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

this.type = 'DodecahedronGeometry';

/**
* Holds the constructor parameters that have been
* used to generate the geometry. Any modification
* after instantiation does not change the geometry.
*
* @type {Object}
*/
this.parameters = {
radius: radius,
detail: detail
};

}

/**
* Factory method for creating an instance of this class from the given
* JSON object.
*
* @param {Object} data - A JSON object representing the serialized geometry.
* @return {DodecahedronGeometry} A new instance.
*/
static fromJSON( data ) {

return new DodecahedronGeometry( data.radius, data.detail );
Expand Down
28 changes: 28 additions & 0 deletions src/geometries/EdgesGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,42 @@ const _v1 = /*@__PURE__*/ new Vector3();
const _normal = /*@__PURE__*/ new Vector3();
const _triangle = /*@__PURE__*/ new Triangle();

/**
* Can be used as a helper object to view the edges of a geometry.
*
* ```js
* const geometry = new THREE.BoxGeometry();
* const edges = new THREE.EdgesGeometry( geometry );
* const line = new THREE.LineSegments( edges );
* scene.add( line );
* ```
*
* Note: It is not yet possible to serialize/deserialize instances of this class.
*
* @augments BufferGeometry
*/
class EdgesGeometry extends BufferGeometry {

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

super();

this.type = 'EdgesGeometry';

/**
* Holds the constructor parameters that have been
* used to generate the geometry. Any modification
* after instantiation does not change the geometry.
*
* @type {Object}
*/
this.parameters = {
geometry: geometry,
thresholdAngle: thresholdAngle
Expand Down
Loading

0 comments on commit 2676030

Please sign in to comment.