extensions

glTF Exporter


glTF Exporter

The glTF Exporter allows BabylonJS models to be exported to the glTF 2.0 format.

Installation

npm

The glTF Exporter can be installed by using the babylonjs-serializers npm module

npm install --save babylonjs babylonjs-serializers

javascript

To include the BabylonJS serializers in javascript, include a script tag in the html <head> tag, referencing the non-minified or minified compiled javascript:

<!-- links to the latest version of the serializers -->
<script src="https://preview.babylonjs.com/serializers/babylonjs.serializers.js"></script>

<!-- links to the latest version of the minified serializers -->
<script src="https://preview.babylonjs.com/serializers/babylonjs.serializers.min.js"></script>

If only the glTF serializer is desired, it can be specifically targeted with this <head> tag:

<!-- links to the latest version of the glTF serializer -->
<script src="https://preview.babylonjs.com/serializers/babylonjs.glTF2Serializer.js"></script>

<!-- links to the latest version of the minified glTF serializer -->
<script src="https://preview.babylonjs.com/serializers/babylonjs.glTF2Serializer.min.js"></script>

Exporting a Scene to glTF

BABYLON.GLTF2Export.GLTFAsync(scene, "fileName").then((gltf) => {
    gltf.downloadFiles();
});

To download to glb format, simply replace the GLTFAsync static function with GLBAsync:

BABYLON.GLTF2Export.GLBAsync(scene, "fileName").then((glb) => {
    glb.downloadFiles();
};

Export options

glTF Exporter accepts an optional options parameter with certain functions and properties defined.

Excluding geometry

Sometimes you may need to exclude geometry from export, such as the skybox. You can define a boolean callback called shouldExportTransformNode which accepts a BabylonJS transform node as an argument and returns a boolean, specifying if the node should be exported or not:

// Initializer code...
let skybox = scene.createDefaultSkybox(hdrTexture, true, 100, 0.3);
// scene setup code...

let options = {
    shouldExportTransformNode: function(transformNode) {
        return transformNode !== skybox;
    }
}

BABYLON.GLTF2Export.GLBAsync(scene, "fileName", options).then((glb) => {
    glb.downloadFiles();
});

Supported features

  • Currently the following material types are supported:
    • PBRMaterial
      • Not all Babylon PBRMaterial features are supported in glTF.
    • MetallicRoughnessMaterial
    • StandardMaterial
      • A conversion from StandardMaterial to MetallicRoughness has been implemented to try to match as close as visibly possible, though not all BabylonJS features are supported in glTF.
    • SpecularGlossinessMaterial
      • glTF Exporter converts SpecularGlossiness materials to MetallicRoughness to match core glTF 2.0 specification.
  • Node-based TRS animation

Coming soon

  • Skinning animation
  • Morph Targets