Skip to content

GLTFLoader

Defined in: addons/src/loaders/GLTFLoader.ts:844

Reads glTF 2.0 files into the engine’s classes, with the methods of three.js’s GLTFLoader that a page needs: load, loadAsync, parse and parseAsync.

The node tree becomes Object3Ds. Each mesh primitive becomes a Mesh with a BufferGeometry and a PhysicalMaterial made from the factors of pbrMetallicRoughness. Textures, skins, animations and morph targets are skipped, and each skip is a sentence in the result’s warnings. A sparse accessor, a compressed buffer and an extension the file requires and the loader does not know are errors.

const gltf = await new GLTFLoader().loadAsync('/assets/bunny.glb');
scene.add(gltf.scene);

new GLTFLoader(): GLTFLoader

GLTFLoader

load(url, onLoad, onProgress?, onError?): void

Defined in: addons/src/loaders/GLTFLoader.ts:850

Fetches url and parses it. Calls onLoad with the result, or onError with the error (the error goes to the console when there is no onError). onProgress gets the bytes loaded while the file comes in.

string

(gltf) => void

(event) => void

(error) => void

void


loadAsync(url, onProgress?): Promise<GLTF>

Defined in: addons/src/loaders/GLTFLoader.ts:860

Fetches url and parses it. Rejects with an Error that starts with GLTFLoader:.

string

(event) => void

Promise<GLTF>


parse(data, path, onLoad, onError?): void

Defined in: addons/src/loaders/GLTFLoader.ts:869

Parses data: the text of a .gltf, the bytes of a .gltf or the bytes of a .glb. path is the directory that the file’s relative buffer URIs are read from, with or without its last /. Calls onLoad or onError, as load does.

string | ArrayBuffer | ArrayBufferView

string

(gltf) => void

(error) => void

void


parseAsync(data, path?): Promise<GLTF>

Defined in: addons/src/loaders/GLTFLoader.ts:879

Parses data as parse does and resolves to the result.

string | ArrayBuffer | ArrayBufferView

string = ''

Promise<GLTF>