Skip to content

Commit 54f8b10

Browse files
authored
Docs: More JSDoc. (mrdoob#30692)
1 parent 560af5a commit 54f8b10

17 files changed

+513
-164
lines changed

examples/jsm/utils/BufferGeometryUtils.js

+88-29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ import {
1111
Vector3,
1212
} from 'three';
1313

14+
/** @module BufferGeometryUtils */
15+
16+
/**
17+
* Computes vertex tangents using the MikkTSpace algorithm. MikkTSpace generates the same tangents consistently,
18+
* and is used in most modelling tools and normal map bakers. Use MikkTSpace for materials with normal maps,
19+
* because inconsistent tangents may lead to subtle visual issues in the normal map, particularly around mirrored
20+
* UV seams.
21+
*
22+
* In comparison to this method, {@link BufferGeometry#computeTangents} (a custom algorithm) generates tangents that
23+
* probably will not match the tangents in other software. The custom algorithm is sufficient for general use with a
24+
* custom material, and may be faster than MikkTSpace.
25+
*
26+
* Returns the original BufferGeometry. Indexed geometries will be de-indexed. Requires position, normal, and uv attributes.
27+
*
28+
* @param {BufferGeometry} geometry - The geometry to compute tangents for.
29+
* @param {Object} MikkTSpace - Instance of `examples/jsm/libs/mikktspace.module.js`, or `mikktspace` npm package.
30+
* Aawait `MikkTSpace.ready` before use.
31+
* @param {boolean} [negateSign=true] - Whether to negate the sign component (.w) of each tangent.
32+
* Required for normal map conventions in some formats, including glTF.
33+
* @return {BufferGeometry} The updated geometry.
34+
*/
1435
function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
1536

1637
if ( ! MikkTSpace || ! MikkTSpace.isReady ) {
@@ -100,9 +121,11 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
100121
}
101122

102123
/**
103-
* @param {Array<BufferGeometry>} geometries
104-
* @param {boolean} useGroups
105-
* @return {?BufferGeometry}
124+
* Merges a set of geometries into a single instance. All geometries must have compatible attributes.
125+
*
126+
* @param {Array<BufferGeometry>} geometries - The geometries to merge.
127+
* @param {boolean} [useGroups=false] - Whether to use groups or not.
128+
* @return {?BufferGeometry} The merged geometry. Returns `null` if the merge does not succeed.
106129
*/
107130
function mergeGeometries( geometries, useGroups = false ) {
108131

@@ -296,8 +319,11 @@ function mergeGeometries( geometries, useGroups = false ) {
296319
}
297320

298321
/**
299-
* @param {Array<BufferAttribute>} attributes
300-
* @return {?BufferAttribute}
322+
* Merges a set of attributes into a single instance. All attributes must have compatible properties and types.
323+
* Instances of {@link InterleavedBufferAttribute} are not supported.
324+
*
325+
* @param {Array<BufferAttribute>} attributes - The attributes to merge.
326+
* @return {?BufferAttribute} The merged attribute. Returns `null` if the merge does not succeed.
301327
*/
302328
function mergeAttributes( attributes ) {
303329

@@ -389,10 +415,12 @@ function mergeAttributes( attributes ) {
389415
}
390416

391417
/**
392-
* @param {BufferAttribute} attribute
393-
* @return {BufferAttribute}
418+
* Performs a deep clone of the given buffer attribute.
419+
*
420+
* @param {BufferAttribute} attribute - The attribute to clone.
421+
* @return {BufferAttribute} The cloned attribute.
394422
*/
395-
export function deepCloneAttribute( attribute ) {
423+
function deepCloneAttribute( attribute ) {
396424

397425
if ( attribute.isInstancedInterleavedBufferAttribute || attribute.isInterleavedBufferAttribute ) {
398426

@@ -411,8 +439,11 @@ export function deepCloneAttribute( attribute ) {
411439
}
412440

413441
/**
414-
* @param {Array<BufferAttribute>} attributes
415-
* @return {Array<InterleavedBufferAttribute>}
442+
* Interleaves a set of attributes and returns a new array of corresponding attributes that share a
443+
* single {@link InterleavedBuffer} instance. All attributes must have compatible types.
444+
*
445+
* @param {Array<BufferAttribute>} attributes - The attributes to interleave.
446+
* @return {Array<InterleavedBufferAttribute>} An array of interleaved attributes. If interleave does not succeed, the method returns `null`.
416447
*/
417448
function interleaveAttributes( attributes ) {
418449

@@ -475,8 +506,13 @@ function interleaveAttributes( attributes ) {
475506

476507
}
477508

478-
// returns a new, non-interleaved version of the provided attribute
479-
export function deinterleaveAttribute( attribute ) {
509+
/**
510+
* Returns a new, non-interleaved version of the given attribute.
511+
*
512+
* @param {InterleavedBufferAttribute} attribute - The interleaved attribute.
513+
* @return {BufferAttribute} The non-interleaved attribute.
514+
*/
515+
function deinterleaveAttribute( attribute ) {
480516

481517
const cons = attribute.data.array.constructor;
482518
const count = attribute.count;
@@ -523,8 +559,12 @@ export function deinterleaveAttribute( attribute ) {
523559

524560
}
525561

526-
// deinterleaves all attributes on the geometry
527-
export function deinterleaveGeometry( geometry ) {
562+
/**
563+
* Deinterleaves all attributes on the given geometry.
564+
*
565+
* @param {BufferGeometry} geometry - The geometry to deinterleave.
566+
*/
567+
function deinterleaveGeometry( geometry ) {
528568

529569
const attributes = geometry.attributes;
530570
const morphTargets = geometry.morphTargets;
@@ -567,8 +607,10 @@ export function deinterleaveGeometry( geometry ) {
567607
}
568608

569609
/**
570-
* @param {BufferGeometry} geometry
571-
* @return {number}
610+
* Returns the amount of bytes used by all attributes to represent the geometry.
611+
*
612+
* @param {BufferGeometry} geometry - The geometry.
613+
* @return {number} The estimate bytes used.
572614
*/
573615
function estimateBytesUsed( geometry ) {
574616

@@ -590,9 +632,11 @@ function estimateBytesUsed( geometry ) {
590632
}
591633

592634
/**
593-
* @param {BufferGeometry} geometry
594-
* @param {number} tolerance
595-
* @return {BufferGeometry}
635+
* Returns a new geometry with vertices for which all similar vertex attributes (within tolerance) are merged.
636+
*
637+
* @param {BufferGeometry} geometry - The geometry to merge vertices for.
638+
* @param {number} [tolerance=1e-4] - The tolerance value.
639+
* @return {BufferGeometry} - The new geometry with merged vertices.
596640
*/
597641
function mergeVertices( geometry, tolerance = 1e-4 ) {
598642

@@ -753,9 +797,12 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
753797
}
754798

755799
/**
756-
* @param {BufferGeometry} geometry
757-
* @param {number} drawMode
758-
* @return {BufferGeometry}
800+
* Returns a new indexed geometry based on `TrianglesDrawMode` draw mode.
801+
* This mode corresponds to the `gl.TRIANGLES` primitive in WebGL.
802+
*
803+
* @param {BufferGeometry} geometry - The geometry to convert.
804+
* @param {number} drawMode - The current draw mode.
805+
* @return {BufferGeometry} The new geometry using `TrianglesDrawMode`.
759806
*/
760807
function toTrianglesDrawMode( geometry, drawMode ) {
761808

@@ -864,9 +911,13 @@ function toTrianglesDrawMode( geometry, drawMode ) {
864911

865912
/**
866913
* Calculates the morphed attributes of a morphed/skinned BufferGeometry.
867-
* Helpful for Raytracing or Decals.
868-
* @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
869-
* @return {Object} An Object with original position/normal attributes and morphed ones.
914+
*
915+
* Helpful for Raytracing or Decals (i.e. a `DecalGeometry` applied to a morphed Object with a `BufferGeometry`
916+
* will use the original `BufferGeometry`, not the morphed/skinned one, generating an incorrect result.
917+
* Using this function to create a shadow `Object3`D the `DecalGeometry` can be correctly generated).
918+
*
919+
* @param {Mesh|Line|Points} object - The 3D object tocompute morph attributes for.
920+
* @return {Object} An object with original position/normal attributes and morphed ones.
870921
*/
871922
function computeMorphedAttributes( object ) {
872923

@@ -1142,6 +1193,12 @@ function computeMorphedAttributes( object ) {
11421193

11431194
}
11441195

1196+
/**
1197+
* Merges the {@link BufferGeometry#groups} for the given geometry.
1198+
*
1199+
* @param {BufferGeometry} geometry - The geometry to modify.
1200+
* @return {BufferGeometry} - The updated geometry
1201+
*/
11451202
function mergeGroups( geometry ) {
11461203

11471204
if ( geometry.groups.length === 0 ) {
@@ -1244,15 +1301,14 @@ function mergeGroups( geometry ) {
12441301

12451302
}
12461303

1247-
12481304
/**
12491305
* Modifies the supplied geometry if it is non-indexed, otherwise creates a new,
12501306
* non-indexed geometry. Returns the geometry with smooth normals everywhere except
12511307
* faces that meet at an angle greater than the crease angle.
12521308
*
1253-
* @param {BufferGeometry} geometry
1254-
* @param {number} [creaseAngle]
1255-
* @return {BufferGeometry}
1309+
* @param {BufferGeometry} geometry - The geometry to modify.
1310+
* @param {number} [creaseAngle=Math.PI/3] - The crease angle in radians.
1311+
* @return {BufferGeometry} - The updated geometry
12561312
*/
12571313
function toCreasedNormals( geometry, creaseAngle = Math.PI / 3 /* 60 degrees */ ) {
12581314

@@ -1363,6 +1419,9 @@ export {
13631419
computeMikkTSpaceTangents,
13641420
mergeGeometries,
13651421
mergeAttributes,
1422+
deepCloneAttribute,
1423+
deinterleaveAttribute,
1424+
deinterleaveGeometry,
13661425
interleaveAttributes,
13671426
estimateBytesUsed,
13681427
mergeVertices,

examples/jsm/utils/CameraUtils.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
Vector3
55
} from 'three';
66

7+
/** @module CameraUtils */
8+
79
const _va = /*@__PURE__*/ new Vector3(), // from pe to pa
810
_vb = /*@__PURE__*/ new Vector3(), // from pe to pb
911
_vc = /*@__PURE__*/ new Vector3(), // from pe to pc
@@ -14,16 +16,17 @@ const _va = /*@__PURE__*/ new Vector3(), // from pe to pa
1416
_quat = /*@__PURE__*/ new Quaternion(); // temporary quaternion
1517

1618

17-
/** Set a PerspectiveCamera's projectionMatrix and quaternion
19+
/**
20+
* Set projection matrix and the orientation of a perspective camera
1821
* to exactly frame the corners of an arbitrary rectangle.
1922
* NOTE: This function ignores the standard parameters;
20-
* do not call updateProjectionMatrix() after this!
23+
* do not call `updateProjectionMatrix()` after this.
2124
*
22-
* @param {PerspectiveCamera} camera
23-
* @param {Vector3} bottomLeftCorner
24-
* @param {Vector3} bottomRightCorner
25-
* @param {Vector3} topLeftCorner
26-
* @param {boolean} [estimateViewFrustum=false]
25+
* @param {PerspectiveCamera} camera - The camera.
26+
* @param {Vector3} bottomLeftCorner - The bottom-left corner point.
27+
* @param {Vector3} bottomRightCorner - The bottom-right corner point.
28+
* @param {Vector3} topLeftCorner - The top-left corner point.
29+
* @param {boolean} [estimateViewFrustum=false] - If set to `true`, the function tries to estimate the camera's FOV.
2730
*/
2831
function frameCorners( camera, bottomLeftCorner, bottomRightCorner, topLeftCorner, estimateViewFrustum = false ) {
2932

examples/jsm/utils/GeometryCompressionUtils.js

+20-30
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
1-
/**
2-
* Octahedron and Quantization encodings based on work by:
3-
*
4-
* @link https://github.com/tsherif/mesh-quantization-example
5-
*
6-
*/
7-
81
import {
92
BufferAttribute,
103
Matrix3,
114
Matrix4,
125
Vector3
136
} from 'three';
147

8+
/** @module GeometryCompressionUtils */
159

10+
// Octahedron and Quantization encodings based on work by: https://github.com/tsherif/mesh-quantization-example
1611

1712
/**
18-
* Make the input geometry's normal attribute encoded and compressed by 3 different methods.
19-
*
20-
* @param {THREE.BufferGeometry} geometry
21-
* @param {string} encodeMethod "DEFAULT" || "OCT1Byte" || "OCT2Byte" || "ANGLES"
13+
* Compressed the given geometry's `normal` attribute by the selected encode method.
2214
*
15+
* @param {BufferGeometry} geometry - The geometry whose normals should be compressed.
16+
* @param {('DEFAULT'|'OCT1Byte'|'OCT2Byte'|'ANGLES')} encodeMethod - The compression method.
2317
*/
2418
function compressNormals( geometry, encodeMethod ) {
2519

2620
const normal = geometry.attributes.normal;
2721

2822
if ( ! normal ) {
2923

30-
console.error( 'Geometry must contain normal attribute. ' );
24+
console.error( 'THREE.GeometryCompressionUtils.compressNormals(): Geometry must contain normal attribute.' );
3125

3226
}
3327

3428
if ( normal.isPacked ) return;
3529

3630
if ( normal.itemSize != 3 ) {
3731

38-
console.error( 'normal.itemSize is not 3, which cannot be encoded. ' );
32+
console.error( 'THREE.GeometryCompressionUtils.compressNormals(): normal.itemSize is not 3, which cannot be encoded.' );
3933

4034
}
4135

@@ -63,11 +57,10 @@ function compressNormals( geometry, encodeMethod ) {
6357

6458
} else if ( encodeMethod == 'OCT1Byte' ) {
6559

66-
/**
67-
* It is not recommended to use 1-byte octahedron normals encoding unless you want to extremely reduce the memory usage
68-
* As it makes vertex data not aligned to a 4 byte boundary which may harm some WebGL implementations and sometimes the normal distortion is visible
69-
* Please refer to @zeux 's comments in https://github.com/mrdoob/three.js/pull/18208
70-
*/
60+
61+
// It is not recommended to use 1-byte octahedron normals encoding unless you want to extremely reduce the memory usage
62+
// As it makes vertex data not aligned to a 4 byte boundary which may harm some WebGL implementations and sometimes the normal distortion is visible
63+
// Please refer to @zeux 's comments in https://github.com/mrdoob/three.js/pull/18208
7164

7265
result = new Int8Array( count * 2 );
7366

@@ -127,28 +120,26 @@ function compressNormals( geometry, encodeMethod ) {
127120

128121
}
129122

130-
131123
/**
132-
* Make the input geometry's position attribute encoded and compressed.
133-
*
134-
* @param {THREE.BufferGeometry} geometry
135-
*
136-
*/
124+
* Compressed the given geometry's `position` attribute.
125+
*
126+
* @param {BufferGeometry} geometry - The geometry whose position values should be compressed.
127+
*/
137128
function compressPositions( geometry ) {
138129

139130
const position = geometry.attributes.position;
140131

141132
if ( ! position ) {
142133

143-
console.error( 'Geometry must contain position attribute. ' );
134+
console.error( 'THREE.GeometryCompressionUtils.compressPositions(): Geometry must contain position attribute.' );
144135

145136
}
146137

147138
if ( position.isPacked ) return;
148139

149140
if ( position.itemSize != 3 ) {
150141

151-
console.error( 'position.itemSize is not 3, which cannot be packed. ' );
142+
console.error( 'THREE.GeometryCompressionUtils.compressPositions(): position.itemSize is not 3, which cannot be packed.' );
152143

153144
}
154145

@@ -171,18 +162,17 @@ function compressPositions( geometry ) {
171162
}
172163

173164
/**
174-
* Make the input geometry's uv attribute encoded and compressed.
175-
*
176-
* @param {THREE.BufferGeometry} geometry
165+
* Compressed the given geometry's `uv` attribute.
177166
*
167+
* @param {BufferGeometry} geometry - The geometry whose texture coordinates should be compressed.
178168
*/
179169
function compressUvs( geometry ) {
180170

181171
const uvs = geometry.attributes.uv;
182172

183173
if ( ! uvs ) {
184174

185-
console.error( 'Geometry must contain uv attribute. ' );
175+
console.error( 'THREE.GeometryCompressionUtils.compressUvs(): Geometry must contain uv attribute.' );
186176

187177
}
188178

0 commit comments

Comments
 (0)