glTF Exporter

The glTF Exporter allowsBabylon.js models to be exported to the glTF 2.0 format.

Installation

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

npm

npm install --save babylonjs babylonjs-serializers

yarn

yarn add babylonjs babylonjs-serializers

javascript

To include theBabylon.js 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 shouldExportNode which accepts aBabylon.js 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 = {
shouldExportNode: function (node) {
return node !== skybox;
},
};
BABYLON.GLTF2Export.GLBAsync(scene, "fileName", options).then((glb) => {
glb.downloadFiles();
});

Supported features

  • ✔️ Scene JSON string Export (.gltf)

  • ✔️ Scene Binary Export (.glb)

  • ✔️ Node Export

  • ⚠️ Camera Export

    • Cameras are currently exported as an empty nodes.
  • ✔️ Mesh Export

  • ⚠️ Material Export

    • ✔️ Metal Roughness Materials pbrMetallicRoughness
      • A conversion from StandardMaterial to MetallicRoughness has been implemented to try to match as close as visibly possible, though not all Babylon.js features are supported in glTF.
    • ❌ Specular Glossiness Materials Extension KHR_materials_pbrSpecularGlossiness
      • SpecularGlossiness has been superseeded by KHR_materials_specular. KHR_materials_pbrSpecularGlossiness will not be supported.
    • ❌ Specular Materials Extension KHR_materials_specular
    • ❌ Material Index of Refraction Extension KHR_materials_ior
    • ❌ Material Volume Extension KHR_materials_volume
    • ✔️ Unlit Materials Extension KHR_materials_unlit
    • ✔️ Occlusion, Roughness, Emissive (ORM) map
    • ✔️ Material Alpha Coverage modes
    • ✔️ Double sided materials
    • ❌ Material variants KHR_materials_variants
  • ✔️ Animation

    • ✔️ Node Translate, Rotate, Scaling animation
    • ✔️ Skeletal Animation
      • As skeletons in glTF are represented as collections of nodes in the scene, skeletal animation is exported as TRS animation
    • ✔️ Morph Target Weight Animation
    • ✔️ Multiple animations
      • In scene, AnimationGroups will be exported as a single glTF Animation.
      • In scene, Animations not associated with an AnimationGroup will be exported as a single glTF animation.
  • ✔️ Buffer View and Accessor Reuse

  • ✔️ Extras Data

  • ❌ XMP Metadata KHR_XMP

  • ⚠️ Asset Info

    • Copyright field specification not supported.

Key:

✔️ Full support ⚠️ Partial Support ❌ No Support

Coming soon