glTF Exporter
The glTF Exporter allows BabylonJS 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 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 shouldExportNode
which accepts a BabylonJS 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
- Currently the following material types are supported:
PBRMaterial
- Not all Babylon
PBRMaterial
features are supported in glTF.
- Not all Babylon
MetallicRoughnessMaterial
StandardMaterial
- A conversion from
StandardMaterial
toMetallicRoughness
has been implemented to try to match as close as visibly possible, though not all BabylonJS features are supported in glTF.
- A conversion from
SpecularGlossinessMaterial
- glTF Exporter converts
SpecularGlossiness
materials toMetallicRoughness
to match core glTF 2.0 specification.
- glTF Exporter converts
- Node-based TRS animation
Coming soon
- Skinning animation
- Morph Targets