[page:Loader] →

[name]

A loader for loading a JSON resource in the [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].

This uses the [page:FileLoader] internally for loading files.

Code Example

const loader = new THREE.ObjectLoader(); loader.load( // resource URL "models/json/example.json", // onLoad callback // Here the loaded data is assumed to be an object function ( obj ) { // Add the loaded object to the scene scene.add( obj ); }, // onProgress callback function ( xhr ) { console.log( (xhr.loaded / xhr.total * 100) + '% loaded' ); }, // onError callback function ( err ) { console.error( 'An error happened' ); } ); // Alternatively, to parse a previously loaded JSON structure const object = loader.parse( a_json_object ); scene.add( object );

Examples

[example:webgl_materials_lightmap WebGL / materials / lightmap]

Constructor

[name]( [param:LoadingManager manager] )

[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].

Creates a new [name].

Properties

See the base [page:Loader] class for common properties.

Methods

See the base [page:Loader] class for common 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] — Will be called when load completes. The argument will be the loaded [page:Object3D object].
[page:Function onProgress] — 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] — Will be called when load errors.

Begin loading from url and call onLoad with the parsed response content.

[method:Object3D parse]( [param:Object json], [param:Function onLoad] )

[page:Object json] — required. The JSON source to parse.

[page:Function onLoad] — Will be called when parsed completes. The argument will be the parsed [page:Object3D object].

Parse a JSON structure and return a threejs object. This is used internally by [page:.load], but can also be used directly to parse a previously loaded JSON structure.

[method:Object3D parseGeometries]( [param:Object json] )

[page:Object json] — required. The JSON source to parse.

This is used [page:.parse] to parse any [page:Geometry geometries] or [page:BufferGeometry buffer geometries] in the JSON structure.

[method:Object3D parseMaterials]( [param:Object json] )

[page:Object json] — required. The JSON source to parse.

This is used [page:.parse] to parse any materials in the JSON structure using [page:MaterialLoader].

[method:Object3D parseAnimations]( [param:Object json] )

[page:Object json] — required. The JSON source to parse.

This is used [page:.parse] to parse any animations in the JSON structure, using [page:AnimationClip.parse].

[method:Object3D parseImages]( [param:Object json] )

[page:Object json] — required. The JSON source to parse.

This is used [page:.parse] to parse any images in the JSON structure, using [page:ImageLoader].

[method:Object3D parseTextures]( [param:Object json] )

[page:Object json] — required. The JSON source to parse.

This is used [page:.parse] to parse any textures in the JSON structure.

[method:Object3D parseObject]( [param:Object json], [param:BufferGeometry geometries], [param:Material materials], [param:AnimationClip animations] )

[page:Object json] — required. The JSON source to parse.
[page:BufferGeometry geometries] — required. The geometries of the JSON.
[page:Material materials] — required. The materials of the JSON.
[page:AnimationClip animations] — required. The animations of the JSON.

This is used [page:.parse] to parse any objects in the JSON structure. Objects can be of the following types:

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]