A low level class for loading resources with Fetch, used internally 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 v3d.FileLoader(); //load a text file and output the result to the console loader.load( // resource URL 'example.txt', // onLoad callback function(data) { // output the text to the console console.log(data) }, // onProgress callback function(xhr) { console.log((xhr.loaded / xhr.total * 100) + '% loaded'); }, // onError callback function(err) { console.error('An error happened'); } );

Note: The cache must be enabled using v3d.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.


FileLoader (manager : LoadingManager)

manager — The loadingManager for the loader to use. Default is DefaultLoadingManager.


See the base Loader class for common properties.

.mimeType : String

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

.responseType : String

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


See the base Loader class for common methods.

.load(url : String, onLoad : Function, onProgress : Function, onError : Function)

url — the path or URL to the file. This can also be a Data URI.
onLoad (optional) — Will be called when loading completes. The argument will be the loaded response.
onProgress (optional) — Will be called while load progresses. 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.
onError (optional) — Will be called if an error occurs.

Load the URL and pass the response to the onLoad function.

.setMimeType(mimeType : String) → this

Set the expected mimeType of the file being loaded. Note that in many cases this will be determined automatically, so by default it is undefined.

.setResponseType(responseType : String) → this

Change the response type. Valid values are:
'text' or empty string (default) — returns the data as String.
'arraybuffer' — loads the data into a ArrayBuffer and returns that.
'blob' — returns the data as a Blob.
'document' — parses the file using the DOMParser.
'json' — parses the file using JSON.parse.


For more info on how to obtain the source code of this module see this page.