Loader

ObjectLoader

A loader for loading a JSON resource in the JSON Object/Scene format.

This uses the FileLoader internally for loading files.

Code Example

const 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 const object = loader.parse(a_json_object); scene.add(object);

Examples

WebGL / materials / lightmap

Constructor

ObjectLoader(manager : LoadingManager)

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

Creates a new ObjectLoader.

Properties

See the base Loader class for common properties.

Methods

See the base Loader class for common methods.

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

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 (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .lengthComputable, .total and .loaded. If the server does not set the Content-Length header; .total will be 0.
onError (optional) — 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 Verge3D object. This is used internally by .load() but can also be used directly to parse a previously loaded JSON structure.

.parseGeometries (json : Object) : Object

json — required. The JSON source to parse.

This is used by .parse() to parse any geometries in the JSON structure.

.parseMaterials (json : Object) : Object

json — required. The JSON source to parse.

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

.parseAnimations (json : Object) : Object

json — required. The JSON source to parse.

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

.parseImages (json : Object) : Object

json — required. The JSON source to parse.

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

.parseTextures (json : Object) : Object

json — required. The JSON source to parse.

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

.parseObject (json : Object, geometries : BufferGeometry, materials : Material, animations : AnimationClip) : Object3D

json — required. The JSON source to parse.
geometries — required. The geometries of the JSON.
materials — required. The materials of the JSON.
animations — required. The animations of the JSON.

This is used by .parse() to parse any 3D objects in the JSON structure.

Source

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