Inheritance: Loader →
A loader for the glTF 2.0 format.
glTF (GL Transmission Format) is an open format specification whenever possible. Be advised that image bitmaps are not automatically GC-collected when they are no longer referenced, and they require special handling during the disposal process.
GLTFLoader supports the following glTF 2.0 extensions:
The following glTF 2.0 extension is supported by an external user plugin:
const loader = new GLTFLoader();
// Optional: Provide a DRACOLoader instance to decode compressed mesh data
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath( '/examples/jsm/libs/draco/' );
loader.setDRACOLoader( dracoLoader );
const gltf = await loader.loadAsync( 'models/gltf/duck/duck.gltf' );
scene.add( gltf.scene );
GLTFLoader is an addon, and must be imported explicitly, see Installation#Addons.
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
Constructs a new glTF loader.
manager
The loading manager.
Starts loading from the given URL and passes the loaded glTF asset to the onLoad() callback.
url
The path/URL of the file to be loaded. This can also be a data URI.
onLoad
Executed when the loading process has been finished.
onProgress
Executed while the loading is in progress.
onError
Executed when errors occur.
Overrides: Loader#load
Parses the given glTF data and returns the resulting group.
data
The raw glTF data.
path
The URL base path.
onLoad
Executed when the loading process has been finished.
onError
Executed when errors occur.
Overrides: Loader#parse
Async version of GLTFLoader#parse.
data
The raw glTF data.
path
The URL base path.
Returns: A Promise that resolves with the loaded glTF when the parsing has been finished.
Registers a plugin callback. This API is internally used to implement the various glTF extensions but can also used by third-party code to add additional logic to the loader.
callback
The callback function to register.
Returns: A reference to this loader.
Sets the given Draco loader to this loader. Required for decoding assets compressed with the KHR_draco_mesh_compression extension.
dracoLoader
The Draco loader to set.
Returns: A reference to this loader.
Sets the given KTX2 loader to this loader. Required for loading KTX2 compressed textures.
ktx2Loader
The KTX2 loader to set.
Returns: A reference to this loader.
Sets the given meshopt decoder. Required for decoding assets compressed with the EXT_meshopt_compression extension.
meshoptDecoder
The meshopt decoder to set.
Returns: A reference to this loader.
Unregisters a plugin callback.
callback
The callback function to unregister.
Returns: A reference to this loader.
Loader result of GLTFLoader.
animations
Array.<AnimationClip>
An array of animation clips.
asset
Object
Meta data about the loaded asset.
cameras
Array.<Camera>
An array of cameras.
parser
GLTFParser
A reference to the internal parser.
scene
Group
The default scene.
scenes
Array.<Group>
glTF assets might define multiple scenes.
userData
Object
Additional data.