[page:Loader] →

[name]

A loader for loading a .gltf resource in JSON format.

The glTF file format is a JSON file format to enable rapid delivery and loading of 3D content.

Constructor

[name]( [page:LoadingManager manager] )

[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
Creates a new [name].

Properties

Methods

[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )

[page:String url] — required
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded JSON response returned from [page:Function parse].
[page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, that contains .[page:Integer total] and .[page:Integer loaded] bytes.
[page:Function onError] — Will be called when load errors.
Begin loading from url and call the callback function with the parsed response content.

[method:null setPath]( [page:String path] )

[page:String path] — Base path for loading additional resources e.g. textures, GLSL shaders, .bin data.
Set the base path for additional resources.

[method:null setCrossOrigin]( [page:String value] )

[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.

[method:null parse]( [page:Object json], [page:Function callBack], [page:String path] )

[page:Object json] — JSON object to parse.
[page:Function callBack] — Will be called when parse completes.
[page:String path] — The base path from which to find subsequent glTF resources such as textures, GLSL shaders and .bin data files.
Parse a glTF-based JSON structure and fire [page:Function callback] when complete. The argument to [page:Function callback] will be an [page:object] that contains loaded parts: .[page:Scene scene], .[page:Array cameras], .[page:Array animations] and .[page:Array shaders]

Notes

When using custom shaders provided within a glTF file [page:THREE.GLTFLoader.Shaders] should be updated on each render loop. See [example:webgl_loader_gltf] demo source code for example usage.
This class is often used with [page:THREE.GLTFLoader.Animations THREE.GLTFLoader.Animations] to animate parsed animations. See [example:webgl_loader_gltf] demo source code for example usage.

Example

// instantiate a loader var loader = new THREE.GLTFLoader(); // load a glTF resource loader.load( // resource URL 'models/gltf/duck/duck.json', // Function when resource is loaded function ( object ) { scene.add( object.scene ); } ); [example:webgl_loader_gltf]

Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/GLTFLoader.js examples/js/loaders/GLTFLoader.js]