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.
var 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.
manager — The loadingManager for the loader to use. Default is DefaultLoadingManager.
The loadingManager the loader is using. Default is DefaultLoadingManager.
The expected mimeType. See .setMimeType. Default is undefined.
The base path from which files will be loaded. See .setPath. Default is undefined.
The request header used in HTTP request. See .setRequestHeader. Default is undefined.
The expected response type. See .setResponseType. Default is undefined.
Whether the XMLHttpRequest uses credentials. See .setWithCredentials. Default is undefined.
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 XMLHttpRequest instance,
which contains .total and .loaded bytes.
onError (optional) — Will be called if an error occurs.
Load the URL and pass the response to the onLoad function.
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.
Set the base path or URL from which to load files. This can be useful if you are loading many models from the same directory.
requestHeader - key: The name of the header whose value is to be set. value: The value to set as the body of the header.
Set the request header used in HTTP request.
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.
Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or
TLS client certificates. See XMLHttpRequest.withCredentials.
Note that this has no effect if you are loading files locally or from the same domain.
For more info on how to obtain the source code of this module see this page.