[page:Loader] →

[name]

A loader for loading glTF 2.0 resource.
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 2.0 extensions:

Example

// Instantiate a loader var loader = new THREE.GLTFLoader(); // Optional: Provide a DRACOLoader instance to decode compressed mesh data THREE.DRACOLoader.setDecoderPath( '/examples/js/libs/draco' ); loader.setDRACOLoader( new THREE.DRACOLoader() ); // Load a glTF resource loader.load( // resource URL 'models/gltf/duck/duck.gltf', // called when the resource is loaded 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> gltf.asset; // Object }, // called when loading is in progresses function ( xhr ) { console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' ); }, // called when loading has errors function ( error ) { console.log( 'An error happened' ); } ); [example:webgl_loader_gltf]

Browser compatibility

GLTFLoader relies on ES6 Promises, which are not supported in IE11. To use the loader in IE11, you must include a polyfill providing a Promise replacement.



Constructor

[name]( [param: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]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

[page:String url] — A string containing the path/URL of the .gltf or .glb file.
[page:Function onLoad] — A function to be called after the loading is successfully completed. The function receives the loaded JSON response returned from [page:Function parse].
[page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, that contains .[page:Integer total] and .[page:Integer loaded] bytes.
[page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.
Begin loading from url and call the callback function with the parsed response content.

[method:null setPath]( [param: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]( [param:String value] )

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

[method:null setDRACOLoader]( [param:DRACOLoader dracoLoader] )

[page:DRACOLoader dracoLoader] — Instance of THREE.DRACOLoader, to be used for decoding assets compressed with the KHR_draco_mesh_compression extension.
Refer to this [link:https://github.com/mrdoob/three.js/tree/dev/examples/js/libs/draco#readme readme] for the details of Draco and its decoder.

[method:null parse]( [param:ArrayBuffer data], [param:String path], [param:Function onLoad], [param:Function onError] )

[page:ArrayBuffer data] — glTF asset to parse, as an ArrayBuffer or JSON string.
[page:String path] — The base path from which to find subsequent glTF resources such as textures and .bin data files.
[page:Function onLoad] — A function to be called when parse completes.
[page:Function onError] — (optional) A function to be called if an error occurs during parsing. The function receives error as an argument.
Parse a glTF-based ArrayBuffer or JSON String and fire [page:Function onLoad] callback when complete. The argument to [page:Function onLoad] will be an [page:object] that contains loaded parts: .[page:Scene scene], .[page:Array scenes], .[page:Array cameras], .[page:Array animations], and .[page:Object asset].

Source

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