Centralized loading manager that handles and tracks multiple loading operations.

This class manages the loading state across multiple file operations, providing progress tracking, error handling, and URL modification capabilities. A default global instance is created and used by loaders if not supplied manually.

Separate loading managers can be useful when you need independent loading progress tracking (e.g., separate progress bars for different types of resources).

import { AcCmLoadingManager } from './AcCmLoadingManager'

// Create a custom loading manager
const manager = new AcCmLoadingManager()

// Set up callbacks
manager.onStart = (url, loaded, total) => {
console.log(`Started loading: ${url} (${loaded}/${total})`)
}

manager.onProgress = (url, loaded, total) => {
console.log(`Progress: ${url} (${loaded}/${total})`)
}

manager.onLoad = () => {
console.log('All loading completed!')
}

manager.onError = (url) => {
console.error(`Failed to load: ${url}`)
}

Constructors

Properties

This function will be called when any item errors.

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

This function will be called when an item is complete.

This function will be called when loading starts.

Methods

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

    Parameters

    • regex: RegExp

      A regular expression.

    • loader: AcCmLoader

      The loader.

    Returns this

    Return this object

  • Retrieve the registered loader for the given file path.

    Parameters

    • file: string

      The file path.

    Returns null | RegExp | AcCmLoader

    Return the registered loader for the given file path.

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

    Parameters

    • url: string

      The loaded url

    Returns void

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

    Parameters

    • url: string

      The loaded url

    Returns void

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

    Parameters

    • url: string

      The loaded url

    Returns void

  • Remove the loader for the given regular expression.

    Parameters

    • regex: RegExp

      A regular expression.

    Returns this

    Return this object

  • 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

    Return resolved URL

  • 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

    • transform: AcCmUrlModifier

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

    Returns this

    Return this object