ObjectLoader

A loader for loading a JSON resource. Unlike the 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 Geometries. Use JSONLoader instead for that.

This uses the FileLoader internally for loading files.

Example

WebGL / animation / scene
WebGL / loader / json / claraio
WebGL / loader / msgpack

var loader = new v3d.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);

Constructor

ObjectLoader(manager : LoadingManager)

manager — The loadingManager for the loader to use. Default is v3d.DefaultLoadingManager.

Creates a new ObjectLoader.

Properties

.crossOrigin : String

If set, assigns the crossOrigin attribute of the image to the value of crossOrigin, prior to starting the load. Default is "anonymous".

.manager : LoadingManager

The loadingManager the loader is using. Default is DefaultLoadingManager.

.resourcePath : String

The base path or URL from which additional resources like textuures will be loaded. See .setResourcePath. Default is the empty string.

Methods

.load (url : String, onLoad : Function, onProgress : Function, onError : Function) : null

url — the path or URL to the file. This can also be a Data URI.
onLoad — Will be called when load completes. The argument will be the loaded object.
onProgress — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes.
onError — Will be called when load errors.

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

.parse (json : Object, onLoad : Function ) : Object3D

json — required. The JSON source to parse.

onLoad — Will be called when parsed completes. The argument will be the parsed object.

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

.parseGeometries (json : Object) : Object3D

json — required. The JSON source to parse.

This is used .parse to parse any geometries or buffer geometries in the JSON structure. Internally it uses JSONLoader for geometries and BufferGeometryLoader for buffer geometries.

.parseMaterials (json : Object) : Object3D

json — required. The JSON source to parse.

This is used .parse to parse any materials in the JSON structure using MaterialLoader.

.parseAnimations (json : Object) : Object3D

json — required. The JSON source to parse.

This is used .parse to parse any animations in the JSON structure, using AnimationClip.parse.

.parseImages (json : Object) : Object3D

json — required. The JSON source to parse.

This is used .parse to parse any images in the JSON structure, using ImageLoader.

.parseTextures (json : Object) : Object3D

json — required. The JSON source to parse.

This is used .parse to parse any textures in the JSON structure.

.parseObject (json : Object) : Object3D

json — required. The JSON source to parse.

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

.setCrossOrigin (value : String) : ObjectLoader

value — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.

.setPath (value : String) : ObjectLoader

Set the base path for the original file.

.setResourcePath (value : String) : ObjectLoader

Set the base path for dependent resources like textures.

Source

For more info on how to obtain the source code of this module see this page.