Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface LoadingManager

Handles and keeps track of loaded and pending data. A default global instance of this class is created and used by loaders if not supplied manually - see DefaultLoadingManager. In general that should be sufficient, however there are times when it can be useful to have separate loaders - for example if 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 ) {
console.log( object);
});

In addition to observing progress, a LoadingManager can be used to override resource URLs during loading. This may be helpful for assets coming from drag-and-drop events, WebSockets, WebRTC, or other APIs. An example showing how to load an in-memory model using Blob URLs is below.

// Blob or File objects created when dragging files into the webpage.
const blobs = {'fish.gltf': blob1, 'diffuse.png': blob2, 'normal.png': blob3};
const manager = new THREE.LoadingManager();
// Initialize loading manager with URL callback.
const objectURLs = [];
manager.setURLModifier( ( url ) => {
url = URL.createObjectURL( blobs[ url ] );
objectURLs.push( url );
return url;
});
// Load as usual, then revoke the blob URLs.
const loader = new THREE.GLTFLoader( manager );
loader.load( 'fish.gltf', (gltf) => {
scene.add( gltf.scene );
objectURLs.forEach( ( url ) => URL.revokeObjectURL( url ) );
});

Examples

WebGL / loader / fbx | WebGL / loader / obj | WebGL / materials / physical / reflectivity | WebGL / postprocesing / outline

Hierarchy

  • LoadingManager

Index

Constructors

constructor

  • new LoadingManager(onLoad?: () => void, onProgress?: (url: string, loaded: number, total: number) => void, onError?: (url: string) => void): I3JS.LoadingManager
  • Creates a new LoadingManager.

    Parameters

    • Optional onLoad: () => void

      this function will be called when all loaders are done.

        • (): void
        • Returns void

    • Optional onProgress: (url: string, loaded: number, total: number) => void

      this function will be called when an item is complete.

        • (url: string, loaded: number, total: number): void
        • Parameters

          • url: string
          • loaded: number
          • total: number

          Returns void

    • Optional onError: (url: string) => void

      this function will be called a loader encounters errors.

        • (url: string): void
        • Parameters

          • url: string

          Returns void

    Returns I3JS.LoadingManager

Properties

Optional onStart

onStart?: (url: string, loaded: number, total: number) => void

Type declaration

    • (url: string, loaded: number, total: number): void
    • This function will be called when loading starts. By default this is undefined. 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.

      Parameters

      • url: string
      • loaded: number
      • total: number

      Returns void

Methods

addHandler

  • 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() );

    Parameters

    • regex: RegExp

      A regular expression.

    • loader: I3JS.Loader

      The loader.

    Returns I3JS.LoadingManager

getHandler

itemEnd

  • itemEnd(url: string): void

itemError

  • itemError(url: string): void

itemStart

  • itemStart(url: string): void

onError

  • onError(url: string): void

onLoad

  • onLoad(): void

onProgress

  • onProgress(url: string, loaded: number, total: number): void
  • Will be called for each loaded item. The default is a with empty body.

    • url The url of the item just loaded.
    • loaded The number of items already loaded so far.
    • total The total amount of items to be loaded.

    Parameters

    • url: string
    • loaded: number
    • total: number

    Returns void

removeHandler

resolveURL

  • resolveURL(url: string): string
  • 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.

    Parameters

    • url: string

      The url to load

    Returns string

setURLModifier

  • 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.

    Parameters

    • Optional callback: (url: string) => string

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

        • (url: string): string
        • Parameters

          • url: string

          Returns string

    Returns I3JS.LoadingManager

Generated using TypeDoc