Skip to content

Commit 52a612f

Browse files
authored
Docs: More JSDoc. (#30620)
1 parent c6620ce commit 52a612f

18 files changed

+913
-10
lines changed

src/loaders/AnimationLoader.js

+31
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,39 @@ import { AnimationClip } from '../animation/AnimationClip.js';
22
import { FileLoader } from './FileLoader.js';
33
import { Loader } from './Loader.js';
44

5+
/**
6+
* Class for loading animation clips in the JSON format. The files are internally
7+
* loaded via {@link FileLoader}.
8+
*
9+
* ```js
10+
* const loader = new THREE.AnimationLoader();
11+
* const animations = await loader.loadAsync( 'animations/animation.js' );
12+
* ```
13+
*
14+
* @augments Loader
15+
*/
516
class AnimationLoader extends Loader {
617

18+
/**
19+
* Constructs a new animation loader.
20+
*
21+
* @param {LoadingManager} [manager] - The loading manager.
22+
*/
723
constructor( manager ) {
824

925
super( manager );
1026

1127
}
1228

29+
/**
30+
* Starts loading from the given URL and pass the loaded animations as an array
31+
* holding instances of {@link AnimationClip} to the `onLoad()` callback.
32+
*
33+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
34+
* @param {function(Array<AnimationClip>)} onLoad - Executed when the loading process has been finished.
35+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
36+
* @param {onErrorCallback} onError - Executed when errors occur.
37+
*/
1338
load( url, onLoad, onProgress, onError ) {
1439

1540
const scope = this;
@@ -44,6 +69,12 @@ class AnimationLoader extends Loader {
4469

4570
}
4671

72+
/**
73+
* Parses the given JSON object and returns an array of animation clips.
74+
*
75+
* @param {Object} json - The serialized animation clips.
76+
* @return {Array<AnimationClip>} The parsed animation clips.
77+
*/
4778
parse( json ) {
4879

4980
const animations = [];

src/loaders/AudioLoader.js

+31
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,45 @@ import { AudioContext } from '../audio/AudioContext.js';
22
import { FileLoader } from './FileLoader.js';
33
import { Loader } from './Loader.js';
44

5+
/**
6+
* Class for loading audio buffers. Audios are internally
7+
* loaded via {@link FileLoader}.
8+
*
9+
* ```js
10+
* const audioListener = new THREE.AudioListener();
11+
* const ambientSound = new THREE.Audio( audioListener );
12+
*
13+
* const loader = new THREE.AudioLoader();
14+
* const audioBuffer = await loader.loadAsync( 'audio/ambient_ocean.ogg' );
15+
*
16+
* ambientSound.setBuffer( audioBuffer );
17+
* ambientSound.play();
18+
* ```
19+
*
20+
* @augments Loader
21+
*/
522
class AudioLoader extends Loader {
623

24+
/**
25+
* Constructs a new audio loader.
26+
*
27+
* @param {LoadingManager} [manager] - The loading manager.
28+
*/
729
constructor( manager ) {
830

931
super( manager );
1032

1133
}
1234

35+
/**
36+
* Starts loading from the given URL and passes the loaded audio buffer
37+
* to the `onLoad()` callback.
38+
*
39+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
40+
* @param {function(AudioBuffer)} onLoad - Executed when the loading process has been finished.
41+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
42+
* @param {onErrorCallback} onError - Executed when errors occur.
43+
*/
1344
load( url, onLoad, onProgress, onError ) {
1445

1546
const scope = this;

src/loaders/BufferGeometryLoader.js

+34
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,42 @@ import { InterleavedBufferAttribute } from '../core/InterleavedBufferAttribute.j
1010
import { InterleavedBuffer } from '../core/InterleavedBuffer.js';
1111
import { getTypedArray } from '../utils.js';
1212

13+
/**
14+
* Class for loading geometries. The files are internally
15+
* loaded via {@link FileLoader}.
16+
*
17+
* ```js
18+
* const loader = new THREE.BufferGeometryLoader();
19+
* const geometry = await loader.loadAsync( 'models/json/pressure.json' );
20+
*
21+
* const material = new THREE.MeshBasicMaterial( { color: 0xF5F5F5 } );
22+
* const object = new THREE.Mesh( geometry, material );
23+
* scene.add( object );
24+
* ```
25+
*
26+
* @augments Loader
27+
*/
1328
class BufferGeometryLoader extends Loader {
1429

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

1737
super( manager );
1838

1939
}
2040

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

2351
const scope = this;
@@ -52,6 +80,12 @@ class BufferGeometryLoader extends Loader {
5280

5381
}
5482

83+
/**
84+
* Parses the given JSON object and returns a geometry.
85+
*
86+
* @param {Object} json - The serialized geometry.
87+
* @return {BufferGeometry} The parsed geometry.
88+
*/
5589
parse( json ) {
5690

5791
const interleavedBufferMap = {};

src/loaders/Cache.js

+45
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
1+
/**
2+
* @class
3+
* @classdesc A simple caching system, used internally by {@link FileLoader}.
4+
* To enable caching across all loaders that use {@link FileLoader}, add `THREE.Cache.enabled = true.` once in your app.
5+
* @hideconstructor
6+
*/
17
const Cache = {
28

9+
/**
10+
* Whether caching is enabled or not.
11+
*
12+
* @static
13+
* @type {boolean}
14+
* @default false
15+
*/
316
enabled: false,
417

18+
/**
19+
* A dictionary that holds cached files.
20+
*
21+
* @static
22+
* @type {Object<string,Object>}
23+
*/
524
files: {},
625

26+
/**
27+
* Adds a cache entry with a key to reference the file. If this key already
28+
* holds a file, it is overwritten.
29+
*
30+
* @static
31+
* @param {string} key - The key to reference the cached file.
32+
* @param {Object} file - The file to be cached.
33+
*/
734
add: function ( key, file ) {
835

936
if ( this.enabled === false ) return;
@@ -14,6 +41,13 @@ const Cache = {
1441

1542
},
1643

44+
/**
45+
* Gets the cached value for the given key.
46+
*
47+
* @static
48+
* @param {string} key - The key to reference the cached file.
49+
* @return {Object|undefined} The cached file. If the key does not exist `undefined` is returned.
50+
*/
1751
get: function ( key ) {
1852

1953
if ( this.enabled === false ) return;
@@ -24,12 +58,23 @@ const Cache = {
2458

2559
},
2660

61+
/**
62+
* Removes the cached file associated with the given key.
63+
*
64+
* @static
65+
* @param {string} key - The key to reference the cached file.
66+
*/
2767
remove: function ( key ) {
2868

2969
delete this.files[ key ];
3070

3171
},
3272

73+
/**
74+
* Remove all values from the cache.
75+
*
76+
* @static
77+
*/
3378
clear: function () {
3479

3580
this.files = {};

src/loaders/CompressedTextureLoader.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,40 @@ import { CompressedTexture } from '../textures/CompressedTexture.js';
44
import { Loader } from './Loader.js';
55

66
/**
7-
* Abstract Base class to block based textures loader (dds, pvr, ...)
7+
* Abstract base class for loading compressed texture formats S3TC, ASTC or ETC.
8+
* Textures are internally loaded via {@link FileLoader}.
89
*
9-
* Sub classes have to implement the parse() method which will be used in load().
10+
* Derived classes have to implement the `parse()` method which holds the parsing
11+
* for the respective format.
12+
*
13+
* @abstract
14+
* @augments Loader
1015
*/
11-
1216
class CompressedTextureLoader extends Loader {
1317

18+
/**
19+
* Constructs a new compressed texture loader.
20+
*
21+
* @param {LoadingManager} [manager] - The loading manager.
22+
*/
1423
constructor( manager ) {
1524

1625
super( manager );
1726

1827
}
1928

29+
/**
30+
* Starts loading from the given URL and passes the loaded compressed texture
31+
* to the `onLoad()` callback. The method also returns a new texture object which can
32+
* directly be used for material creation. If you do it this way, the texture
33+
* may pop up in your scene once the respective loading process is finished.
34+
*
35+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
36+
* @param {function(CompressedTexture)} onLoad - Executed when the loading process has been finished.
37+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
38+
* @param {onErrorCallback} onError - Executed when errors occur.
39+
* @return {CompressedTexture} The compressed texture.
40+
*/
2041
load( url, onLoad, onProgress, onError ) {
2142

2243
const scope = this;

src/loaders/CubeTextureLoader.js

+45
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,59 @@ import { CubeTexture } from '../textures/CubeTexture.js';
33
import { Loader } from './Loader.js';
44
import { SRGBColorSpace } from '../constants.js';
55

6+
/**
7+
* Class for loading cube textures. Images are internally loaded via {@link ImageLoader}.
8+
*
9+
* The loader returns an instance of {@link CubeTexture} and expects the cube map to
10+
* be defined as six separate images representing the sides of a cube. Other cube map definitions
11+
* like vertical and horizontal cross, column and row layouts are not supported.
12+
*
13+
* Note that, by convention, cube maps are specified in a coordinate system
14+
* in which positive-x is to the right when looking up the positive-z axis --
15+
* in other words, using a left-handed coordinate system. Since three.js uses
16+
* a right-handed coordinate system, environment maps used in three.js will
17+
* have pos-x and neg-x swapped.
18+
*
19+
* The loaded cube textureis in sRGB color space. Meaning {@link Texture#colorSpace}
20+
* is set to `SRGBColorSpace` by default.
21+
*
22+
* ```js
23+
* const loader = new THREE.CubeTextureLoader().setPath( 'textures/cubeMaps/' );
24+
* const cubeTexture = await loader.loadAsync( [
25+
* 'px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'
26+
* ] );
27+
* scene.background = cubeTexture;
28+
* ```
29+
*
30+
* @augments Loader
31+
*/
632
class CubeTextureLoader extends Loader {
733

34+
/**
35+
* Constructs a new cube texture loader.
36+
*
37+
* @param {LoadingManager} [manager] - The loading manager.
38+
*/
839
constructor( manager ) {
940

1041
super( manager );
1142

1243
}
1344

45+
/**
46+
* Starts loading from the given URL and pass the fully loaded cube texture
47+
* to the `onLoad()` callback. The method also returns a new cube texture object which can
48+
* directly be used for material creation. If you do it this way, the cube texture
49+
* may pop up in your scene once the respective loading process is finished.
50+
*
51+
* @param {Array<string>} urls - Array of 6 URLs to images, one for each side of the
52+
* cube texture. The urls should be specified in the following order: pos-x,
53+
* neg-x, pos-y, neg-y, pos-z, neg-z. An array of data URIs are allowed as well.
54+
* @param {function(CubeTexture)} onLoad - Executed when the loading process has been finished.
55+
* @param {onProgressCallback} onProgress - Unsupported in this loader.
56+
* @param {onErrorCallback} onError - Executed when errors occur.
57+
* @return {CubeTexture} The cube texture.
58+
*/
1459
load( urls, onLoad, onProgress, onError ) {
1560

1661
const texture = new CubeTexture();

src/loaders/DataTextureLoader.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,40 @@ import { DataTexture } from '../textures/DataTexture.js';
44
import { Loader } from './Loader.js';
55

66
/**
7-
* Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
7+
* Abstract base class for loading binary texture formats RGBE, EXR or TGA.
8+
* Textures are internally loaded via {@link FileLoader}.
89
*
9-
* Sub classes have to implement the parse() method which will be used in load().
10+
* Derived classes have to implement the `parse()` method which holds the parsing
11+
* for the respective format.
12+
*
13+
* @abstract
14+
* @augments Loader
1015
*/
11-
1216
class DataTextureLoader extends Loader {
1317

18+
/**
19+
* Constructs a new data texture loader.
20+
*
21+
* @param {LoadingManager} [manager] - The loading manager.
22+
*/
1423
constructor( manager ) {
1524

1625
super( manager );
1726

1827
}
1928

29+
/**
30+
* Starts loading from the given URL and passes the loaded data texture
31+
* to the `onLoad()` callback. The method also returns a new texture object which can
32+
* directly be used for material creation. If you do it this way, the texture
33+
* may pop up in your scene once the respective loading process is finished.
34+
*
35+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
36+
* @param {function(DataTexture)} onLoad - Executed when the loading process has been finished.
37+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
38+
* @param {onErrorCallback} onError - Executed when errors occur.
39+
* @return {DataTexture} The data texture.
40+
*/
2041
load( url, onLoad, onProgress, onError ) {
2142

2243
const scope = this;

0 commit comments

Comments
 (0)