Capítulo 194 de 859

Chapter 194: ObjectLoader

Core Idea

A loader for loading a JSON resource in the JSON Object/Scene format. The files are internally loaded via FileLoader.

Code Examples

const loader = new THREE.ObjectLoader();
const obj = await loader.loadAsync( 'models/json/example.json' );
scene.add( obj );
// Alternatively, to parse a previously loaded JSON structure
const object = await loader.parseAsync( a_json_object );
scene.add( object );
  • What it demonstrates: Typical usage of ObjectLoader.

Reference Tables

Constructor

Signature
new ObjectLoader( manager : LoadingManager )

Methods

MethodDescription
.load( url : string, onLoad : function, onProgress : onProgressCallback, onError : onErrorCallback )Starts loading from the given URL and pass the loaded 3D object to the onLoad() callback.
.loadAsync( url : string, onProgress : onProgressCallback ) : Promise.<Object3D> (async)Async version of ObjectLoader#load.
.parse( json : Object, onLoad : onLoad ) : Object3DParses the given JSON. This is used internally by ObjectLoader#load but can also be used directly to parse a previously loaded JSON structure.
.parseAsync( json : Object ) : Promise.<Object3D> (async)Async version of ObjectLoader#parse.

Key Takeaways

  1. ObjectLoader extends: Loader
  2. Key methods: load, loadAsync, parse, parseAsync.

Connects To