Capítulo 674 de 859

Chapter 674: LoadingManager

Core Idea

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.

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.

Key Concepts

  • abortController : AbortController: Used for aborting ongoing requests in loaders using this manager.
  • onError : function | undefined: Executes when an error occurs.
  • onLoad : function | undefined: Executes when all items have been loaded.
  • onProgress : function | undefined: Executes when single items have been loaded.
  • onStart : function | undefined: Executes when an item starts loading.

Code Examples

const manager = new THREE.LoadingManager();
manager.onLoad = () => console.log( 'Loading complete!' );
const loader1 = new OBJLoader( manager );
const loader2 = new ColladaLoader( manager );
  • What it demonstrates: Typical usage of LoadingManager.

Reference Tables

Constructor

Signature
new LoadingManager( onLoad : function, onProgress : function, onError : function )

Properties

PropertyDescription
.abortController : AbortControllerUsed for aborting ongoing requests in loaders using this manager.
`.onError : functionundefined`
`.onLoad : functionundefined`
`.onProgress : functionundefined`
`.onStart : functionundefined`

Methods

MethodDescription
.abort() : LoadingManagerCan be used to abort ongoing loading requests in loaders using this manager. The abort only works if the loaders implement Loader#abort and AbortSignal.any() is supported in th…
.addHandler( regex : string, loader : Loader ) : LoadingManagerRegisters 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 textu…
.getHandler( file : string ) : LoaderCan be used to retrieve the registered loader for the given file path.
.itemEnd( url : string )This should be called by any loader using the manager when the loader ended loading an item.
.itemError( url : string )This should be called by any loader using the manager when the loader encounters an error when loading an item.
.itemStart( url : string )This should be called by any loader using the manager when the loader starts loading an item.
.removeHandler( regex : string ) : LoadingManagerRemoves the loader for the given regular expression.
.resolveURL( url : string ) : stringGiven 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( transform : function ) : LoadingManagerIf 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 …

Key Takeaways

  1. Most relevant properties: abortController, onError, onLoad, onProgress.
  2. Key methods: abort, addHandler, getHandler, itemEnd.

Connects To