Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/loaders/AnimationLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@ import { AnimationClip } from '../animation/AnimationClip.js';
import { FileLoader } from './FileLoader.js';
import { Loader } from './Loader.js';

/**
* Class for loading animation clips in the JSON format. The files are internally
* loaded via {@link FileLoader}.
*
* ```js
* const loader = new THREE.AnimationLoader();
* const animations = await loader.loadAsync( 'animations/animation.js' );
* ```
*
* @augments Loader
*/
class AnimationLoader extends Loader {

/**
* Constructs a new animation loader.
*
* @param {LoadingManager} [manager] - The loading manager.
*/
constructor( manager ) {

super( manager );

}

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

const scope = this;
Expand Down Expand Up @@ -44,6 +69,12 @@ class AnimationLoader extends Loader {

}

/**
* Parses the given JSON object and returns an array of animation clips.
*
* @param {Object} json - The serialized animation clips.
* @return {Array<AnimationClip>} The parsed animation clips.
*/
parse( json ) {

const animations = [];
Expand Down
31 changes: 31 additions & 0 deletions src/loaders/AudioLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,45 @@ import { AudioContext } from '../audio/AudioContext.js';
import { FileLoader } from './FileLoader.js';
import { Loader } from './Loader.js';

/**
* Class for loading audio buffers. Audios are internally
* loaded via {@link FileLoader}.
*
* ```js
* const audioListener = new THREE.AudioListener();
* const ambientSound = new THREE.Audio( audioListener );
*
* const loader = new THREE.AudioLoader();
* const audioBuffer = await loader.loadAsync( 'audio/ambient_ocean.ogg' );
*
* ambientSound.setBuffer( audioBuffer );
* ambientSound.play();
* ```
*
* @augments Loader
*/
class AudioLoader extends Loader {

/**
* Constructs a new audio loader.
*
* @param {LoadingManager} [manager] - The loading manager.
*/
constructor( manager ) {

super( manager );

}

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

const scope = this;
Expand Down
34 changes: 34 additions & 0 deletions src/loaders/BufferGeometryLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,42 @@ import { InterleavedBufferAttribute } from '../core/InterleavedBufferAttribute.j
import { InterleavedBuffer } from '../core/InterleavedBuffer.js';
import { getTypedArray } from '../utils.js';

/**
* Class for loading geometries. The files are internally
* loaded via {@link FileLoader}.
*
* ```js
* const loader = new THREE.BufferGeometryLoader();
* const geometry = await loader.loadAsync( 'models/json/pressure.json' );
*
* const material = new THREE.MeshBasicMaterial( { color: 0xF5F5F5 } );
* const object = new THREE.Mesh( geometry, material );
* scene.add( object );
* ```
*
* @augments Loader
*/
class BufferGeometryLoader extends Loader {

/**
* Constructs a new geometry loader.
*
* @param {LoadingManager} [manager] - The loading manager.
*/
constructor( manager ) {

super( manager );

}

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

const scope = this;
Expand Down Expand Up @@ -52,6 +80,12 @@ class BufferGeometryLoader extends Loader {

}

/**
* Parses the given JSON object and returns a geometry.
*
* @param {Object} json - The serialized geometry.
* @return {BufferGeometry} The parsed geometry.
*/
parse( json ) {

const interleavedBufferMap = {};
Expand Down
45 changes: 45 additions & 0 deletions src/loaders/Cache.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
/**
* @class
* @classdesc A simple caching system, used internally by {@link FileLoader}.
* To enable caching across all loaders that use {@link FileLoader}, add `THREE.Cache.enabled = true.` once in your app.
* @hideconstructor
*/
const Cache = {

/**
* Whether caching is enabled or not.
*
* @static
* @type {boolean}
* @default false
*/
enabled: false,

/**
* A dictionary that holds cached files.
*
* @static
* @type {Object<string,Object>}
*/
files: {},

/**
* Adds a cache entry with a key to reference the file. If this key already
* holds a file, it is overwritten.
*
* @static
* @param {string} key - The key to reference the cached file.
* @param {Object} file - The file to be cached.
*/
add: function ( key, file ) {

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

},

/**
* Gets the cached value for the given key.
*
* @static
* @param {string} key - The key to reference the cached file.
* @return {Object|undefined} The cached file. If the key does not exist `undefined` is returned.
*/
get: function ( key ) {

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

},

/**
* Removes the cached file associated with the given key.
*
* @static
* @param {string} key - The key to reference the cached file.
*/
remove: function ( key ) {

delete this.files[ key ];

},

/**
* Remove all values from the cache.
*
* @static
*/
clear: function () {

this.files = {};
Expand Down
27 changes: 24 additions & 3 deletions src/loaders/CompressedTextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,40 @@ import { CompressedTexture } from '../textures/CompressedTexture.js';
import { Loader } from './Loader.js';

/**
* Abstract Base class to block based textures loader (dds, pvr, ...)
* Abstract base class for loading compressed texture formats S3TC, ASTC or ETC.
* Textures are internally loaded via {@link FileLoader}.
*
* Sub classes have to implement the parse() method which will be used in load().
* Derived classes have to implement the `parse()` method which holds the parsing
* for the respective format.
*
* @abstract
* @augments Loader
*/

class CompressedTextureLoader extends Loader {

/**
* Constructs a new compressed texture loader.
*
* @param {LoadingManager} [manager] - The loading manager.
*/
constructor( manager ) {

super( manager );

}

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

const scope = this;
Expand Down
45 changes: 45 additions & 0 deletions src/loaders/CubeTextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,59 @@ import { CubeTexture } from '../textures/CubeTexture.js';
import { Loader } from './Loader.js';
import { SRGBColorSpace } from '../constants.js';

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

/**
* Constructs a new cube texture loader.
*
* @param {LoadingManager} [manager] - The loading manager.
*/
constructor( manager ) {

super( manager );

}

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

const texture = new CubeTexture();
Expand Down
27 changes: 24 additions & 3 deletions src/loaders/DataTextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,40 @@ import { DataTexture } from '../textures/DataTexture.js';
import { Loader } from './Loader.js';

/**
* Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
* Abstract base class for loading binary texture formats RGBE, EXR or TGA.
* Textures are internally loaded via {@link FileLoader}.
*
* Sub classes have to implement the parse() method which will be used in load().
* Derived classes have to implement the `parse()` method which holds the parsing
* for the respective format.
*
* @abstract
* @augments Loader
*/

class DataTextureLoader extends Loader {

/**
* Constructs a new data texture loader.
*
* @param {LoadingManager} [manager] - The loading manager.
*/
constructor( manager ) {

super( manager );

}

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

const scope = this;
Expand Down
Loading
Loading