Constructor
new LoadingManager(onLoadopt, onProgressopt, onErroropt)
Constructs a new loading manager.
Name | Type | Attributes | Description |
---|---|---|---|
onLoad | function | <optional> | Executes when all items have been loaded. |
onProgress | function | <optional> | Executes when single items have been loaded. |
onError | function | <optional> | Executes when an error occurs. |
Members
onError :function|undefined
Executes when an error occurs.
- function |
undefined
- Default Value
- undefined
onLoad :function|undefined
Executes when all items have been loaded.
- function |
undefined
- Default Value
- undefined
onProgress :function|undefined
Executes when single items have been loaded.
- function |
undefined
- Default Value
- undefined
onStart :function|undefined
Executes when an item starts loading.
- function |
undefined
- Default Value
- undefined
Methods
itemEnd(url)
This should be called by any loader using the manager when the loader ended loading an item.
Name | Type | Description |
---|---|---|
url | string | The URL of the loaded item. |
itemError(url)
This should be called by any loader using the manager when the loader encounters an error when loading an item.
Name | Type | Description |
---|---|---|
url | string | The URL of the item that produces an error. |
itemStart(url)
This should be called by any loader using the manager when the loader starts loading an item.
Name | Type | Description |
---|---|---|
url | string | The URL to load. |
resolveURL(url) → {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.
Name | Type | Description |
---|---|---|
url | string | The URL to load. |
The resolved URL.
- Type:
- string
setURLModifier(transform) → {LoadingManager}
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.
Name | Type | Description |
---|---|---|
transform | function | URL modifier callback. Called with an URL and must return a resolved URL. |
A reference to this loading manager.
- Type:
- LoadingManager
const blobs = { 'fish.gltf': blob1, 'diffuse.png': blob2, 'normal.png': blob3 };
const manager = new 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 GLTFLoader(manager);
loader.load('fish.gltf', gltf => {
scene.add(gltf.scene);
objectURLs.forEach(url => URL.revokeObjectURL(url));
});