Skip to content

Commit 91213ea

Browse files
authored
Docs: More JSDoc. (#30719)
1 parent a94801e commit 91213ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2429
-360
lines changed

examples/jsm/loaders/3DMLoader.js

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,38 @@ import { EXRLoader } from '../loaders/EXRLoader.js';
3030

3131
const _taskCache = new WeakMap();
3232

33+
/**
34+
* A loader for Rhinoceros 3D files and objects.
35+
*
36+
* Rhinoceros is a 3D modeler used to create, edit, analyze, document, render,
37+
* animate, and translate NURBS curves, surfaces, breps, extrusions, point clouds,
38+
* as well as polygon meshes and SubD objects. `rhino3dm.js` is compiled to WebAssembly
39+
* from the open source geometry library `openNURBS`. The loader currently uses
40+
* `rhino3dm.js 8.4.0`.
41+
*
42+
* ```js
43+
* const loader = new Rhino3dmLoader();
44+
* loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/[email protected]' );
45+
*
46+
* const object = await loader.loadAsync( 'models/3dm/Rhino_Logo.3dm' );
47+
* scene.add( object );
48+
* ```
49+
*
50+
* @augments Loader
51+
*/
3352
class Rhino3dmLoader extends Loader {
3453

54+
/**
55+
* Constructs a new Rhino 3DM loader.
56+
*
57+
* @param {LoadingManager} [manager] - The loading manager.
58+
*/
3559
constructor( manager ) {
3660

3761
super( manager );
3862

63+
// internals
64+
3965
this.libraryPath = '';
4066
this.libraryPending = null;
4167
this.libraryBinary = null;
@@ -54,6 +80,12 @@ class Rhino3dmLoader extends Loader {
5480

5581
}
5682

83+
/**
84+
* Path to a folder containing the JS and WASM libraries.
85+
*
86+
* @param {string} path - The library path to set.
87+
* @return {Rhino3dmLoader} A reference to this loader.
88+
*/
5789
setLibraryPath( path ) {
5890

5991
this.libraryPath = path;
@@ -62,6 +94,14 @@ class Rhino3dmLoader extends Loader {
6294

6395
}
6496

97+
/**
98+
* Sets the maximum number of Web Workers to be used during decoding.
99+
* A lower limit may be preferable if workers are also for other
100+
* tasks in the application.
101+
*
102+
* @param {number} workerLimit - The worker limit.
103+
* @return {Rhino3dmLoader} A reference to this loader.
104+
*/
65105
setWorkerLimit( workerLimit ) {
66106

67107
this.workerLimit = workerLimit;
@@ -70,6 +110,15 @@ class Rhino3dmLoader extends Loader {
70110

71111
}
72112

113+
/**
114+
* Starts loading from the given URL and passes the loaded 3DM asset
115+
* to the `onLoad()` callback.
116+
*
117+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
118+
* @param {function(Object3D)} onLoad - Executed when the loading process has been finished.
119+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
120+
* @param {onErrorCallback} onError - Executed when errors occur.
121+
*/
73122
load( url, onLoad, onProgress, onError ) {
74123

75124
const loader = new FileLoader( this.manager );
@@ -105,12 +154,22 @@ class Rhino3dmLoader extends Loader {
105154

106155
}
107156

157+
/**
158+
* Prints debug messages to the browser console.
159+
*/
108160
debug() {
109161

110162
console.log( 'Task load: ', this.workerPool.map( ( worker ) => worker._taskLoad ) );
111163

112164
}
113165

166+
/**
167+
* Decodes the 3DM asset data with a Web Worker.
168+
*
169+
* @param {ArrayBuffer} buffer - The raw 3DM asset data as an array buffer.
170+
* @param {string} url - The asset URL.
171+
* @return {Promise<Object3D>} A Promise that resolved with the decoded 3D object.
172+
*/
114173
decodeObjects( buffer, url ) {
115174

116175
let worker;
@@ -170,6 +229,14 @@ class Rhino3dmLoader extends Loader {
170229

171230
}
172231

232+
/**
233+
* Parses the given 3DM data and passes the loaded 3DM asset
234+
* to the `onLoad()` callback.
235+
*
236+
* @param {ArrayBuffer} data - The raw 3DM asset data as an array buffer.
237+
* @param {function(Object3D)} onLoad - Executed when the loading process has been finished.
238+
* @param {onErrorCallback} onError - Executed when errors occur.
239+
*/
173240
parse( data, onLoad, onError ) {
174241

175242
this.decodeObjects( data, '' )
@@ -962,6 +1029,10 @@ class Rhino3dmLoader extends Loader {
9621029

9631030
}
9641031

1032+
/**
1033+
* Frees internal resources. This method should be called
1034+
* when the loader is no longer required.
1035+
*/
9651036
dispose() {
9661037

9671038
for ( let i = 0; i < this.workerPool.length; ++ i ) {
@@ -972,8 +1043,6 @@ class Rhino3dmLoader extends Loader {
9721043

9731044
this.workerPool.length = 0;
9741045

975-
return this;
976-
9771046
}
9781047

9791048
}

examples/jsm/loaders/3MFLoader.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import * as fflate from '../libs/fflate.module.js';
2424
const COLOR_SPACE_3MF = SRGBColorSpace;
2525

2626
/**
27-
*
28-
* 3D Manufacturing Format (3MF) specification: https://3mf.io/specification/
27+
* A loader for the [3D Manufacturing Format (3MF)]{@link https://3mf.io/specification/} format.
2928
*
3029
* The following features from the core specification are supported:
3130
*
@@ -39,18 +38,46 @@ const COLOR_SPACE_3MF = SRGBColorSpace;
3938
* - Texture 2D Groups
4039
* - Color Groups (Vertex Colors)
4140
* - Metallic Display Properties (PBR)
41+
*
42+
* ```js
43+
* const loader = new ThreeMFLoader();
44+
*
45+
* const object = await loader.loadAsync( './models/3mf/truck.3mf' );
46+
* object.rotation.set( - Math.PI / 2, 0, 0 ); // z-up conversion
47+
* scene.add( object );
48+
* ```
49+
*
50+
* @augments Loader
4251
*/
43-
4452
class ThreeMFLoader extends Loader {
4553

54+
/**
55+
* Constructs a new 3MF loader.
56+
*
57+
* @param {LoadingManager} [manager] - The loading manager.
58+
*/
4659
constructor( manager ) {
4760

4861
super( manager );
4962

63+
/**
64+
* An array of available extensions.
65+
*
66+
* @type {Array<Object>}
67+
*/
5068
this.availableExtensions = [];
5169

5270
}
5371

72+
/**
73+
* Starts loading from the given URL and passes the loaded 3MF asset
74+
* to the `onLoad()` callback.
75+
*
76+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
77+
* @param {function(Group)} onLoad - Executed when the loading process has been finished.
78+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
79+
* @param {onErrorCallback} onError - Executed when errors occur.
80+
*/
5481
load( url, onLoad, onProgress, onError ) {
5582

5683
const scope = this;
@@ -85,6 +112,12 @@ class ThreeMFLoader extends Loader {
85112

86113
}
87114

115+
/**
116+
* Parses the given 3MF data and returns the resulting group.
117+
*
118+
* @param {ArrayBuffer} data - The raw 3MF asset data as an array buffer.
119+
* @return {Group} A group representing the parsed asset.
120+
*/
88121
parse( data ) {
89122

90123
const scope = this;
@@ -1571,6 +1604,11 @@ class ThreeMFLoader extends Loader {
15711604

15721605
}
15731606

1607+
/**
1608+
* Adds a 3MF extension.
1609+
*
1610+
* @param {Object} extension - The extension to add.
1611+
*/
15741612
addExtension( extension ) {
15751613

15761614
this.availableExtensions.push( extension );

examples/jsm/loaders/AMFLoader.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,42 @@ import {
1111
import * as fflate from '../libs/fflate.module.js';
1212

1313
/**
14-
* Description: Early release of an AMF Loader following the pattern of the
15-
* example loaders in the three.js project.
14+
* A loader for the AMF format.
1615
*
17-
* Usage:
18-
* const loader = new AMFLoader();
19-
* loader.load('/path/to/project.amf', function(objecttree) {
20-
* scene.add(objecttree);
21-
* });
16+
* The loader supports materials, color and ZIP compressed files.
17+
* No constellation support (yet).
2218
*
23-
* Materials now supported, material colors supported
24-
* Zip support, requires fflate
25-
* No constellation support (yet)!
19+
* ```js
20+
* const loader = new AMFLoader();
2621
*
22+
* const object = await loader.loadAsync( './models/amf/rook.amf' );
23+
* scene.add( object );
24+
* ```
25+
*
26+
* @augments Loader
2727
*/
28-
2928
class AMFLoader extends Loader {
3029

30+
/**
31+
* Constructs a new AMF loader.
32+
*
33+
* @param {LoadingManager} [manager] - The loading manager.
34+
*/
3135
constructor( manager ) {
3236

3337
super( manager );
3438

3539
}
3640

41+
/**
42+
* Starts loading from the given URL and passes the loaded AMF asset
43+
* to the `onLoad()` callback.
44+
*
45+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
46+
* @param {function(Group)} onLoad - Executed when the loading process has been finished.
47+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
48+
* @param {onErrorCallback} onError - Executed when errors occur.
49+
*/
3750
load( url, onLoad, onProgress, onError ) {
3851

3952
const scope = this;
@@ -69,6 +82,12 @@ class AMFLoader extends Loader {
6982

7083
}
7184

85+
/**
86+
* Parses the given AMF data and returns the resulting group.
87+
*
88+
* @param {ArrayBuffer} data - The raw AMF asset data as an array buffer.
89+
* @return {Group} A group representing the parsed asset.
90+
*/
7291
parse( data ) {
7392

7493
function loadDocument( data ) {

examples/jsm/loaders/BVHLoader.js

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,65 @@ import {
1111
} from 'three';
1212

1313
/**
14-
* Description: reads BVH files and outputs a single Skeleton and an AnimationClip
14+
* A loader for the BVH format.
1515
*
16-
* Currently only supports bvh files containing a single root.
16+
* Imports BVH files and outputs a single {@link Skeleton} and {@link AnimationClip}.
17+
* The loader only supports BVH files containing a single root right now.
1718
*
19+
* ```js
20+
* const loader = new BVHLoader();
21+
* const result = await loader.loadAsync( 'models/bvh/pirouette.bvh' );
22+
*
23+
* // visualize skeleton
24+
* const skeletonHelper = new THREE.SkeletonHelper( result.skeleton.bones[ 0 ] );
25+
* scene.add( result.skeleton.bones[ 0 ] );
26+
* scene.add( skeletonHelper );
27+
*
28+
* // play animation clip
29+
* mixer = new THREE.AnimationMixer( result.skeleton.bones[ 0 ] );
30+
* mixer.clipAction( result.clip ).play();
31+
* ```
32+
*
33+
* @augments Loader
1834
*/
19-
2035
class BVHLoader extends Loader {
2136

37+
/**
38+
* Constructs a new BVH loader.
39+
*
40+
* @param {LoadingManager} [manager] - The loading manager.
41+
*/
2242
constructor( manager ) {
2343

2444
super( manager );
2545

46+
/**
47+
* Whether to animate bone positions or not.
48+
*
49+
* @type {boolean}
50+
* @default true
51+
*/
2652
this.animateBonePositions = true;
53+
54+
/**
55+
* Whether to animate bone rotations or not.
56+
*
57+
* @type {boolean}
58+
* @default true
59+
*/
2760
this.animateBoneRotations = true;
2861

2962
}
3063

64+
/**
65+
* Starts loading from the given URL and passes the loaded BVH asset
66+
* to the `onLoad()` callback.
67+
*
68+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
69+
* @param {function({skeleton:Skeleton,clip:AnimationClip})} onLoad - Executed when the loading process has been finished.
70+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
71+
* @param {onErrorCallback} onError - Executed when errors occur.
72+
*/
3173
load( url, onLoad, onProgress, onError ) {
3274

3375
const scope = this;
@@ -62,15 +104,19 @@ class BVHLoader extends Loader {
62104

63105
}
64106

107+
/**
108+
* Parses the given BVH data and returns the resulting data.
109+
*
110+
* @param {string} text - The raw BVH data as a string.
111+
* @return {{skeleton:Skeleton,clip:AnimationClip}} An object representing the parsed asset.
112+
*/
65113
parse( text ) {
66114

67-
/*
68-
reads a string array (lines) from a BVH file
69-
and outputs a skeleton structure including motion data
115+
// reads a string array (lines) from a BVH file
116+
// and outputs a skeleton structure including motion data
70117

71-
returns thee root node:
72-
{ name: '', channels: [], children: [] }
73-
*/
118+
// returns thee root node:
119+
// { name: '', channels: [], children: [] }
74120
function readBvh( lines ) {
75121

76122
// read model structure

0 commit comments

Comments
 (0)