[page:Loader] →
[name]
A loader for *glTF* 2.0 resources.
glTF (GL Transmission Format) is an
open format specification
for efficient delivery and loading of 3D content. Assets may be provided either in JSON (.gltf)
or binary (.glb) format. External files store textures (.jpg, .png, ...) and additional binary
data (.bin). A glTF asset may deliver one or more scenes, including meshes, materials,
textures, skins, skeletons, morph targets, animations, lights, and/or cameras.
Extensions
GLTFLoader supports the following glTF extensions:
Example
// Instantiate a loader
var loader = new THREE.GLTFLoader();
// Load a glTF resource
loader.load( 'models/gltf/duck/duck.gltf', function ( gltf ) {
scene.add( gltf.scene );
gltf.animations; // Array<THREE.AnimationClip>
gltf.scene; // THREE.Scene
gltf.scenes; // Array<THREE.Scene>
gltf.cameras; // Array<THREE.Camera>
} );
[example:webgl_loader_gltf]
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 and .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 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 scenes], .[page:Array cameras], and .[page:Array animations].
Source
[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/GLTFLoader.js examples/js/loaders/GLTFLoader.js]