Skip to main content

Loading and exporting with BabylonJS

  • Into the scene (babylon.io): glTF, glb, STL and OBJ models from a file, a URL or raw glb bytes, placed in the scene as meshes. A model from your project's assets is loaded with bitbybit.asset.getFile first.
  • Out of the scene (babylon.io): the scene, or chosen meshes, as GLB, STL or a .babylon file, downloaded or kept as bytes. In the editors, More > Export model does the same without code.
  • glTF tooling (babylon.gltf): a glTF file kept as its whole asset container rather than one mesh, so its material variants (KHR_materials_variants) can be listed and switched and its animation groups played.
  • Gaussian splatting (babylon.gaussianSplatting): captured real-world scenes, clouds of soft coloured blobs from .ply files, placed and cloned like meshes.
  • Screenshots (babylon.tools): the scene rendered through any camera at any size, downloaded or kept as an image.

Exact CAD formats such as STEP come from the kernels, not from the scene: getting a model out compares the two.

Every function​

Loading and exporting​

FunctionWhat it does
exportBabylonDownloads the whole scene as a .babylon file, the engine's own JSON format that its editors and loaders read back; the extension is added when missing.
exportGLBDownloads the whole scene as a glb file, the binary glTF that most 3D tools and web viewers read; discardSkyboxAndGrid leaves out the skybox and ground this library adds.
exportGLBBytesWrites the whole scene, or chosen nodes with their ancestors, as glb bytes without downloading anything, so they can be saved, sent on or loaded back with loadGlbFromArrayBuffer.
exportMeshesToStlDownloads several meshes, with their child meshes, as one STL file; lines are left out.
exportMeshToStlDownloads a mesh and its visible child meshes as one STL file, the plain triangle format 3D printers take; lines are left out.
loadAssetIntoSceneLoads a glTF, glb, STL or OBJ model from a File into the scene and gives back a container mesh with the model's meshes as its children; any other extension throws an error.
loadAssetIntoSceneFromRootUrlLoads a glTF, glb, STL or OBJ model from a web address into the scene and gives back a container mesh with the model's meshes as its children.
loadAssetIntoSceneFromRootUrlNoReturnLoads a model from a web address into the scene, as loadAssetIntoSceneFromRootUrl does, without giving the mesh back.
loadAssetIntoSceneNoReturnLoads a glTF, glb, STL or OBJ model from a File into the scene, as loadAssetIntoScene does, without giving the mesh back.
loadGlbFromArrayBufferLoads a glb model held as bytes into the scene, such as the output of occt.io.convertStepToGltf, and gives back a container mesh with the model's meshes as its children.
loadGlbFromArrayBufferNoReturnLoads a glb model held as bytes into the scene, as loadGlbFromArrayBuffer does, without giving the mesh back.

glTF​

FunctionWhat it does
getAnimationGroupsGets the animation groups of a loaded glTF asset container.
getMeshesGets all meshes of a loaded glTF asset container.
getRootNodeGets the root transform node of a loaded glTF asset.
getSelectedMaterialVariantGets the currently selected KHR_materials_variants material variant of a loaded glTF asset.
listAnimationGroupNamesLists the names of the animation groups of a loaded glTF asset container.
listMaterialVariantsLists the names of the KHR_materials_variants material variants declared by a loaded glTF asset.
loadAssetContainerLoads a glTF or glb file from an uploaded asset file into the scene and returns the asset container.
loadAssetContainerFromUrlLoads a glTF or glb file from a url into the scene and returns the asset container.
playAnimationGroupStarts playing an animation group of a loaded glTF asset.
resetMaterialVariantResets the materials of a loaded glTF asset back to the original KHR_materials_variants default.
selectMaterialVariantActivates a KHR_materials_variants material variant by name, swapping the materials of the asset accordingly.
stopAnimationGroupStops an animation group of a loaded glTF asset.

Gaussian splatting​

FunctionWhat it does
cloneMakes a copy of a Gaussian splatting mesh that shares its splat data, so the same capture can appear at several places cheaply.
createLoads a Gaussian splatting .ply file from a URL into the scene as a mesh that casts and receives shadows; nothing is loaded without a URL.
getSplatPositionsReads the center point of every splat in a Gaussian splatting mesh, in its own coordinates; the engine stores four numbers per splat and only the first three are the point.

Screenshots​

FunctionWhat it does
createScreenshotRenders the scene through camera, or the active camera when none is given, at the given size and gives the image back as a data URL.
createScreenshotAndDownloadRenders the scene through camera, or the active camera when none is given, at the given size and downloads the image in the browser.