A loader for loading a JSON resource. Unlike the [page:JSONLoader], this one make use of the
.type attributes of objects to map them to their original classes.
Note that this loader can't load [page:Geometries]. Use [page:JSONLoader] instead for that.
This uses the [page:FileLoader] internally for loading files.
[example:webgl_animation_scene WebGL / animation / scene]
[example:webgl_loader_json_claraio WebGL / loader / json / claraio]
[example:webgl_loader_msgpack WebGL / loader / msgpack]
var 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
var object = loader.parse( a_json_object );
scene.add( object );
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
Creates a new [name].
If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin] attribute of the image to the value of *crossOrigin*, prior to starting the load. Default is *"anonymous"*.
The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
The base path or URL from which textures will be loaded. See [page:.setTexturePath]. Default is the empty string.
[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.
[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.
[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.
Internally it uses [page:JSONLoader] for geometries and [page:BufferGeometryLoader] for buffer geometries.
[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].
[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].
[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].
[page:Object json] — required. The JSON source to parse.
This is used [page:.parse] to parse any textures in the JSON structure.
[page:Object json] — required. The JSON source to parse.
This is used [page:.parse] to parse any objects in the JSON structure.
Objects can be of the following types:
[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
[page:String value] — The base path or URL from which textures will be loaded.