A loader for loading a JSON resource in the JSON Object/Scene format.
This uses the FileLoader internally for loading files.
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);
manager — The loadingManager for the loader to use. Default is v3d.DefaultLoadingManager.
Creates a new ObjectLoader.
See the base Loader class for common properties.
See the base Loader class for common methods.
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.
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.
json — required. The JSON source to parse.
This is used .parse to parse any geometries or buffer geometries in the JSON structure.
json — required. The JSON source to parse.
This is used .parse to parse any materials in the JSON structure using MaterialLoader.
json — required. The JSON source to parse.
This is used .parse to parse any animations in the JSON structure, using AnimationClip.parse.
json — required. The JSON source to parse.
This is used .parse to parse any images in the JSON structure, using ImageLoader.
json — required. The JSON source to parse.
This is used .parse to parse any textures in the JSON structure.
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 .parse to parse any objects in the JSON structure.
Objects can be of the following types:
For more info on how to obtain the source code of this module see this page.