.glTF File Loader Plugin

Setup

You can find the loader here here

Full Version

This loader supports both glTF 1.0 and 2.0 and will use the correct loader based on the glTF version string.

<script src="babylon.js"></script>
<script src="babylon.glTFFileLoader.js"></script>

Loading files locally

By default, the gltf loader will request additional files for draco compression from preview.babylonjs.com. In case you want to deliver these files locally (e.g. for GDPR compliance), you can set the DracoCompression.Configuration object to use local files:

DracoCompression.Configuration = {
decoder: {
wasmUrl: "/babylon-draco-files/draco_wasm_wrapper_gltf.js",
wasmBinaryUrl: "/babylon-draco-files/draco_decoder_gltf.wasm",
fallbackUrl: "/babylon-draco-files/draco_decoder_gltf.js",
},
};

Be sure to download the files first (from https://preview.babylonjs.com/[FILENAME]) and put them in a local path (public/babylon-draco-files, in this case).

Warning

A _root_ node is added to hold all the glTF and glb models and model parts are stored as sub-meshes. This is so applications that save models using a right handed system will be loaded correctly into Babylon.js when you add to your create scene function

scene.useRightHandedSystem = true;

This also means that loadedMeshes[0] will point to the added _root_ node and loadedMeshes[1] will point to your first loaded mesh.

Version 2 Only

This loader supports only glTF 2.0 and will fail to load glTF 1.0.

<script src="babylon.js"></script>
<script src="babylon.glTF2FileLoader.js"></script>

See Skinning for details on how skinning is implementated in Babylon.js for glTF 2.0.

Version 1 Only

This loader supports only glTF 1.0 and will fail to load glTF 2.0.

<script src="babylon.js"></script>
<script src="babylon.glTF1FileLoader.js"></script>

Loading the Scene

Use one of the static function on the SceneLoader to load a glTF asset. See Load from any file type.

See an example here: Load a glTF Asset

API (Version 2)

Properties and Methods

See the available properties and methods from the API documentation.

Extensions

See the available extensions from the API documentation.

API (Version 1)

Properties

IncrementalLoading

Set this property to false to disable incremental loading which delays the loader from calling the success callback until after loading the meshes and shaders. Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled. Defaults to true.

BABYLON.GLTFFileLoader.IncrementalLoading = false;

HomogeneousCoordinates

Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters. Defaults to false.

BABYLON.GLTFFileLoader.HomogeneousCoordinates = true;

Extensions

KHR_binary_glTF
KHR_materials_common

Coming next