ThreeJS Managers

DefaultLoadingManager

When no custom manager is specified, most loaders use a global instance of the LoadingManager.

This will suffice for most purposes, but there may be times when you want separate loading managers for textures and models, for example.

Code Example

You can optionally configure the manager's onStart, onLoad, onProgress, and onError functions. These will then be applied to all loaders that use the DefaultLoadingManager.

These are not to be confused with the similarly named functions of individual loaders, as they are intended to display information about the overall status of loading rather than dealing with the data that has been loaded.

THREE.DefaultLoadingManager.onStart = function ( url, itemsLoaded, itemsTotal ) {
	
	console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );


};


THREE.DefaultLoadingManager.onLoad = function ( ) {


	console.log( 'Loading Complete!');


};




THREE.DefaultLoadingManager.onProgress = function ( url, itemsLoaded, itemsTotal ) {


	console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );


};


THREE.DefaultLoadingManager.onError = function ( url ) {


	console.log( 'There was an error loading ' + url );


};

LoadingManager

Handles and monitors loaded and pending data. If this class is not explicitly supplied, a default global instance is created and used by loaders - see DefaultLoadingManager.

In general, that should suffice, but there are times when having separate loaders can be useful, such as when you want to show separate loading bars for objects and textures.

Code Example

This example shows how to use LoadingManager to track the progress of OBJLoader.

const manager = new THREE.LoadingManager();
manager.onStart = function ( url, itemsLoaded, itemsTotal ) {


	console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );


};


manager.onLoad = function ( ) {


	console.log( 'Loading complete!');


};




manager.onProgress = function ( url, itemsLoaded, itemsTotal ) {


	console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );


};


manager.onError = function ( url ) {


	console.log( 'There was an error loading ' + url );


};


const loader = new THREE.OBJLoader( manager );
loader.load( 'file.obj', function ( object ) {


	//


} );

Constructor

LoadingManager( onLoad : Function, onProgress : Function, onError : Function )

onLoad — (optional) this function will be called when all loaders are done.

onProgress — (optional) this function will be called when an item is complete.

onError — (optional) this function will be called a loader encounters errors.

Creates a new LoadingManager.

Properties

.onStart : Function

This function will be called when loading starts. The arguments are:

url — The url of the item just loaded.

itemsLoaded — the number of items already loaded so far.

itemsTotal — the total amount of items to be loaded.

By default this is undefined.

.onLoad : Function

This function will be called when all loading is completed. By default this is undefined, unless passed in the constructor.

.onProgress : Function

This function will be called when an item is complete. The arguments are:

url — The url of the item just loaded.

itemsLoaded — the number of items already loaded so far.

itemsTotal — the total amount of items to be loaded.

By default this is undefined, unless passed in the constructor.

.onError : Function

This function will be called when any item errors, with the argument:

url — The url of the item that errored.

By default this is undefined, unless passed in the constructor.

Methods

.addHandler ( regex : Object, loader : Loader ) : this

regex — A regular expression.

loader — The loader.

Registers a loader with the given regular expression. Can be used to define what loader should be used in order to load specific files. A typical use case is to overwrite the default loader for textures.

// add handler for TGA textures
manager.addHandler( /\.tga$/i, new TGALoader() );

.getHandler ( file : String ) : Loader

file — The file path.

Can be used to retrieve the registered loader for the given file path.

.removeHandler ( regex : Object ) : this

regex — A regular expression.

Removes the loader for the given regular expression.

.resolveURL ( url : String ) : String

url — the url to load

Given a URL, uses the URL modifier callback (if any) and returns a resolved URL. If no URL modifier is set, returns the original URL.

.setURLModifier ( callback : Function ) : this

callback — URL modifier callback. Called with url argument, and must return resolvedURL.

If provided, the callback will be passed each resource URL before a request is sent. The callback may return the original URL, or a new URL to override loading behavior. This behavior can be used to load assets from .ZIP files, drag-and-drop APIs, and Data URIs.

Note: The following methods are designed to be called internally by loaders. You shouldn't call them directly.

.itemStart ( url : String ) : undefined

url — the url to load

This should be called by any loader using the manager when the loader starts loading an url.

.itemEnd ( url : String ) : undefined

url — the loaded url

This should be called by any loader using the manager when the loader ended loading an url.

.itemError ( url : String ) : undefined

url — the loaded url

This should be called by any loader using the manager when the loader errors loading an url.


Related Topics

ThreeJS Helpers 2

PolarGridHelper The PolarGridHelper is an object to define polar grids. Grids are two-dimensional arrays of lines. Code Example const radius = 10; const radials = 16; const circles = 8; const divisions = 64; const helper =...

4 minutes read.

ThreeJS AnimationMixer

The AnimationMixer is a player that allows you to play animations on a specific object in the scene. When many items in a scene are animated individually, each object may...

2 minutes read.

ThreeJS AnimationClip

An AnimationClip is a group of keyframe tracks that may be reused to depict an animation. The "Animation System" page in the "Next Steps" part of the handbook provides an overview...

2 minutes read.

ThreeJS AnimationAction

AnimationActions are used to schedule the playback of animations saved in AnimationClips. Note that the majority of AnimationAction's methods can be chained together. The "Animation System" page in the "Next Steps" part...

6 minutes read.

ThreeJS Geometries-1

BoxGeometry BoxGeometry is a geometry class for a rectangular cuboid with a given 'width', 'height', and 'depth'. On creation, the cuboid is centered on the origin, with each edge parallel to...

7 minutes read.

ThreeJS Creating VR Content

This article gives a quick introduction of the main components of a three.js-based web-based VR application. Workflow      First, you have to include VRButton.js into your project. import { VRButton } from...

1 minute read.

ThreeJS Matrix Transformations

Three.js encodes 3D transformations using matrices for translations (position), rotations, and scaling. Every Object3D instance has a matrix that records the location, rotation, and scale of the object. This page...

2 minutes read.

ThreeJS Property Binding and Mixer

PropertyBinding Internally, this holds a reference to real property in the scene graph. Constructor PropertyBinding( rootNode : Object3D, path, parsedPath ) -- rootNode: -- path -- parsedPath (optional) Properties The properties are as follows: .path : Number.parsedPath...

2 minutes read.

ThreeJS Interpolant

CubicInterpolant Code Example const interpolant = new THREE.CubicInterpolant(new Float32Array( 2 ),new Float32Array( 2 ),1,new Float32Array( 1 ));interpolant.evaluate( 0.5 ); Constructor CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) parameterPositions -- array of positions sampleValues -- array of samples sampleSize...

2 minutes read.

ThreeJS Scenes

Fog This class contains the parameters that define linear fog, i.e., that grows linearly denser with the distance. Constructor Fog( color : Integer, near : Float, far : Float ) The color parameter is...

3 minutes read.

ThreeJS Managers

DefaultLoadingManager When no custom manager is specified, most loaders use a global instance of the LoadingManager. This will suffice for most purposes, but there may be times when you want separate loading...

4 minutes read.

ThreeJS Keyframe Tracks and Animation

A KeyframeTrack is a timed series of keyframes that are made up of lists of times and related values and are used to animate an object's unique property. BooleanKeyframeTrack A Track of...

3 minutes read.

ThreeJS Lights

Light Abstract base class for lights - all other light types inherit the properties and methods described here. Constructor Light( color : Integer, intensity : Float ) color - (optional) hexadecimal color of the...

10 minutes read.

ThreeJS Loader 1

AnimationLoader Class for loading AnimationClips in JSON format. This uses the FileLoader internally for loading files. Code Example // instantiate a loader const loader = new THREE.AnimationLoader(); // load a resource loader.load( // resource URL 'animations/animation.js', // onLoad callback function...

8 minutes read.

ThreeJS Uniform

Uniforms are global GLSL variables. They are passed to shader programs. Code Example When declaring a uniform of a ShaderMaterial, it is declared by value or by object. uniforms: { time: { value: 1.0...

2 minutes read.

ThreeJS BufferAttribute

This class stores data for an attribute associated with a BufferGeometry (such as vertex positions, face indices, normals, colours, UVs, and any custom attributes), allowing for more efficient data passing...

4 minutes read.

ThreeJS Disposing an Object

The disposal of unwanted library entities is a crucial component of improving performance and avoiding memory leaks in your programme. When you create a three.js type instance, you set aside...

4 minutes read.

ThreeJS InterleavedBuffer

The term "interleaved" refers to the packing of multiple attributes, possibly of different types (e.g., position, normal, uv, colour) into a single array buffer. Constructor InterleavedBuffer( array : TypedArray, stride : Integer...

3 minutes read.

ThreeJS Testing with npm

This article explains how to install three.js in a node.js environment so that automated tests may be run. Tests can be done manually or with the help of automated CI...

4 minutes read.

ThreeJS Using post-processing

Many three.js applications render their 3D objects directly to the screen. Sometimes, however, you want to apply one or more graphical effects like Depth-Of-Field, Bloom, Film Grain or various types...

2 minutes read.