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 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
ObjectLoader
function ObjectLoader( manager: LoadingManager ): void;
manager — The loadingManager for the loader to use. Default is THREE.DefaultLoadingManager.
Creates a new ObjectLoader.
Properties
See the base Loader class for common properties.
Methods
See the base Loader class for common methods.
load
function 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
function 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 three.js object. This is used internally
by .load() but can also be used directly to parse a previously loaded
JSON structure.
parseGeometries
function parseGeometries( json: Object ): Object;
json — required. The JSON source to parse.
This is used by .parse() to parse any .ufferGeometry in the JSON structure.
parseMaterials
function 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
function 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
function 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
function 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
function 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.