[name]
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.
Example
[example:webgl_loader_msgpack WebGL / loader / msgpack]
[example:webgl_morphtargets_human WebGL / morphtargets / human]
var loader = new THREE.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
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.
[page:Cache Cache] is a cache module that holds the response from each request made through this loader, so each file is requested once.
Constructor
[name] ( [param:LoadingManager manager] )
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use.
Default is [page:DefaultLoadingManager].
Properties
[property:LoadingManager manager]
The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
[property:String mimeType]
The expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType].
See [page:.setMimeType]. Default is *undefined*.
[property:String path]
The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.
[property:object requestHeader]
The [link:https://developer.mozilla.org/en-US/docs/Glossary/Request_header request header] used in HTTP request. See [page:.setRequestHeader]. Default is *undefined*.
[property:String responseType]
The expected response type. See [page:.setResponseType]. Default is *undefined*.
[property:String withCredentials]
Whether the XMLHttpRequest uses credentials. See [page:.setWithCredentials].
Default is *undefined*.
Methods
[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )
[page:String url] — the path or URL to the file. This can also be a
[link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] (optional) — Will be called when loading completes. The argument will be the loaded response.
[page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the XMLHttpRequest instance,
which contains .[page:Integer total] and .[page:Integer loaded] bytes.
[page:Function onError] (optional) — Will be called if an error occurs.
Load the URL and pass the response to the onLoad function.
[method:FileLoader setMimeType]( [param:String mimeType] )
Set the expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType]
of the file being loaded. Note that in many cases this will be determined automatically, so by default it is *undefined*.
[method:FileLoader setPath]( [param:String path] )
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.
[method:FileLoader setRequestHeader]( [param:object requestHeader] )
[page:object 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 [link:https://developer.mozilla.org/en-US/docs/Glossary/Request_header request header] used in HTTP request.
[method:FileLoader setResponseType]( [param:String responseType] )
Change the response type. Valid values are:
[page:String text] or empty string (default) - returns the data as [page:String string].
[page:String arraybuffer] - loads the data into a [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ArrayBuffer] and returns that.
[page:String blob] - returns the data as a [link:https://developer.mozilla.org/en/docs/Web/API/Blob Blob].
[page:String document] - parses the file using the [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].
[page:String json] - parses the file using [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse JSON.parse].
[method:FileLoader setWithCredentials]( [param:Boolean value] )
Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or
TLS client certificates. See [link:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials XMLHttpRequest.withCredentials].
Note that this has no effect if you are loading files locally or from the same domain.
Source
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]