Abstract base class for implementing resource loaders.

This class provides the common functionality and interface that all loaders must implement, including loading manager integration, path handling, and configuration options for cross-origin requests.

class MyCustomLoader extends AcCmLoader {
load(url: string, onLoad: (data: MyDataType) => void, onProgress?: AcCmLoaderProgressCallback, onError?: AcCmOnErrorCallback): void {
// Implementation specific loading logic
const fullUrl = this.resolveURL(url)
// ... fetch and process data
onLoad(processedData)
}
}

Constructors

Properties

crossOrigin: string

The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS. Default is anonymous.

path: string

The base path from which the asset will be loaded. Default is the empty string.

requestHeader: HeadersInit

The request header used in HTTP request.

resourcePath: string

The base path from which additional resources like textures will be loaded. Default is the empty string.

withCredentials: boolean

Whether the XMLHttpRequest uses credentials. Default is false.

Methods

  • This method needs to be implement by all concrete loaders. It holds the logic for loading the asset from the backend.

    Parameters

    • url: string

      The path or URL to the file. This can also be a Data URI.

    • OptionalonLoad: (data: unknown) => void

      (optional) — Will be called when loading completes.

    • OptionalonProgress: AcCmLoaderProgressCallback

      (optional) — Will be called while load progresses.

    • OptionalonError: AcCmOnErrorCallback

      (optional) — Will be called if an error occurs.

    Returns void

  • This method is equivalent to 'load', but returns a Promise.

    Parameters

    • url: string

      A string containing the path/URL of the file to be loaded.

    • onProgress: AcCmLoaderProgressCallback

      (optional) — A function to be called while the loading is in progress. The argument will be the ProgressEvent instance, which contains .lengthComputable, .total and .loaded. If the server does not set the Content-Length header; .total will be 0.

    Returns Promise<unknown>

    Return a promise.

  • Set the request header used in HTTP request.

    Parameters

    • requestHeader: HeadersInit

      key: The name of the header whose value is to be set. value: The value to set as the body of the header.

    Returns AcCmLoader

    Return this object

  • Set whether the XMLHttpRequest uses credentials such as cookies, authorization headers or TLS client certificates. Note that this has no effect if you are loading files locally or from the same domain.

    Parameters

    • value: boolean

      The flag whether the XMLHttpRequest uses credentials.

    Returns AcCmLoader

    Return this object