[page:Loader] →
[name]
A loader for loading objects in JSON format.
Constructor
[name]( [page:Boolean showStatus] )
[page:Boolean showStatus] — Show the status of loading div.
Creates a new [name].
Properties
[property:boolean withCredentials]
If true, the ajax request will use cookies.
Properties inherited from [page:Loader]
[property:Boolean showStatus]
If true, show loading status in the statusDomElement.
[property:DOMElement statusDomElement]
This is the recipient of status messages.
[property:Function onLoadStart]
Will be called when load starts.
The default is a function with empty body.
[property:Function onLoadComplete]
Will be called when load completes.
The default is a function with empty body.
Methods
[method:null load]( [page:String url], [page:Function callback], [page:String texturePath] )
[page:String url] — required
[page:Function callback] — required. Will be called when load completes. The arguments will be the loaded [page:Object3D] and the loaded [page:Array materials].
[page:String texturePath] — optional. If not specified, textures will be assumed to be in the same folder as the Javascript model file.
[method:null loadAjaxJSON]([page:JSONLoader context], [page:String url], [page:Function callback], [page:String texturePath], [page:Function callbackProgress])
[page:JSONLoader context] — The [page:JSONLoader] instance
[page:String url] — required
[page:Function callback] — required. This function will be called with the loaded model as an instance of [page:Geometry geometry] when the load is completed.
[page:String texturePath] — Base path for textures.
[page:Function callbackProgress] — Will be called while load progresses. The argument will be an [page:Object] containing two attributes: .[page:Integer total] and .[page:Integer loaded] bytes.
Begin loading from url and call callback with the parsed response content.
[method:Object3D parse]( [page:Object json], [page:String texturePath] )
[page:String json] — JSON object to parse.
[page:String texturePath] — Base path for textures.
Parse a JSON structure and return an [page:Object] containing the parsed .[page:Geometry] and .[page:Array materials].
Methods inherited from [page:Loader]
[method:Boolean needsTangents]( [page:Array materials] )
[page:Array materials] — an array of [page:Material]
Checks if the loaded object needs tangents based on its materials.
[method:null updateProgress]( [page:object progress] )
[page:Object progress] — an object containing loaded(contains the amount of bytes loaded) and optionally total (containing the total amount of bytes).
Updates the DOM object with the progress made.
[method:Material createMaterial]( [page:object m], [page:string texturePath] )
[page:Object m] — The parameters to create the material.
[page:String texturePath] — The base path of the textures.
Creates the Material based on the parameters m.
[method:Array initMaterials]( [page:Array materials], [page:string texturePath] )
[page:Array materials] — an array of parameters to create materials.
[page:String texturePath] — The base path of the textures.
Creates an array of [page:Material] based on the array of parameters m. The index of the parameters decide the correct index of the materials.
[method:String extractUrlBase]( [page:string url] )
[page:String url] — The url to extract the base url from.
Extract the base from the URL.
[method:DOMElement addStatusElement]()
Add a DOM element to indicate the progress and return the DOMElement
Example
// instantiate a loader
var loader = new THREE.JSONLoader();
// load a resource
loader.load(
// resource URL
'models/animated/monster/monster.js',
// Function when resource is loaded
function ( geometry, materials ) {
var material = new THREE.MeshFaceMaterial( materials );
var object = new THREE.Mesh( geometry, material );
scene.add( object );
}
);
[example:webgl_loader_json_blender]
Source
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]