Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface FileLoader

A low level class for loading resources with XMLHttpRequest, used internaly by most loaders. It can also be used directly to load any file type that does not have a loader.

Code Example

const loader = new THREE.FileLoader();
// load a text file and output the result to the console
loader.load(
'example.txt', // resource URL
function ( data ) { // onLoad callback
// output the text to the console
console.log( data )
},
function ( xhr ) { // onProgress callback
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
function ( err ) { // onError callback
console.error( 'An error happened' );
}
);

Note: The cache must be enabled using THREE.Cache.enabled = true; This is a global property and only needs to be set once to be used by all loaders that use FileLoader internally. Cache is a cache module that holds the response from each request made through this loader, so each file is requested once.

Hierarchy

Index

Constructors

constructor

Properties

crossOrigin

crossOrigin: string

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

default

'anonymous'

manager

The loadingManager the loader is using. Default is DefaultLoadingManager.

mimeType

mimeType: MimeType

The expected mimeType. See .setMimeType. Default is undefined.

path

path: string

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

default

''

requestHeader

requestHeader: {}

The request header used in HTTP request. See .setRequestHeader. Default is empty object.

default

{}

Type declaration

  • [header: string]: string

resourcePath

resourcePath: string

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

default

''

responseType

responseType: string

The expected response type. See .setResponseType. Default is undefined.

withCredentials

withCredentials: boolean

Whether the XMLHttpRequest uses credentials. See .setWithCredentials. Default is false.

default:

false

Methods

load

  • load(url: string, onLoad?: (response: string | ArrayBuffer) => void, onProgress?: (request: ProgressEvent<EventTarget>) => void, onError?: (event: ErrorEvent) => void): any
  • Load the URL and pass the response to the onLoad function.

    Parameters

    • url: string

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

    • Optional onLoad: (response: string | ArrayBuffer) => void

      Will be called when loading completes. The argument will be the loaded response.

        • (response: string | ArrayBuffer): void
        • Parameters

          • response: string | ArrayBuffer

          Returns void

    • Optional onProgress: (request: ProgressEvent<EventTarget>) => void

      Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. If the server does not set the Content-Length header; .total will be 0.

        • (request: ProgressEvent<EventTarget>): void
        • Parameters

          • request: ProgressEvent<EventTarget>

          Returns void

    • Optional onError: (event: ErrorEvent) => void

      Will be called if an error occurs.

        • (event: ErrorEvent): void
        • Parameters

          • event: ErrorEvent

          Returns void

    Returns any

loadAsync

  • loadAsync(url: string, onProgress?: (event: ProgressEvent<EventTarget>) => void): Promise<string | ArrayBuffer>
  • Load the URL and pass the response to the onLoad function.

    Parameters

    • url: string

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

    • Optional onProgress: (event: ProgressEvent<EventTarget>) => void

      Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. If the server does not set the Content-Length header; .total will be 0.

        • (event: ProgressEvent<EventTarget>): void
        • Parameters

          • event: ProgressEvent<EventTarget>

          Returns void

    Returns Promise<string | ArrayBuffer>

setCrossOrigin

setMimeType

setPath

setRequestHeader

setResourcePath

setResponseType

setWithCredentials

Generated using TypeDoc