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 withbitbybit.asset.getFilefirst. - Out of the scene (
babylon.io): the scene, or chosen meshes, as GLB, STL or a.babylonfile, 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.plyfiles, 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
| Function | What it does |
|---|---|
exportBabylon | Downloads 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. |
exportGLB | Downloads 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. |
exportGLBBytes | Writes 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. |
exportMeshesToStl | Downloads several meshes, with their child meshes, as one STL file; lines are left out. |
exportMeshToStl | Downloads a mesh and its visible child meshes as one STL file, the plain triangle format 3D printers take; lines are left out. |
loadAssetIntoScene | Loads 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. |
loadAssetIntoSceneFromRootUrl | Loads 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. |
loadAssetIntoSceneFromRootUrlNoReturn | Loads a model from a web address into the scene, as loadAssetIntoSceneFromRootUrl does, without giving the mesh back. |
loadAssetIntoSceneNoReturn | Loads a glTF, glb, STL or OBJ model from a File into the scene, as loadAssetIntoScene does, without giving the mesh back. |
loadGlbFromArrayBuffer | Loads 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. |
loadGlbFromArrayBufferNoReturn | Loads a glb model held as bytes into the scene, as loadGlbFromArrayBuffer does, without giving the mesh back. |
glTF
| Function | What it does |
|---|---|
getAnimationGroups | Gets the animation groups of a loaded glTF asset container. |
getMeshes | Gets all meshes of a loaded glTF asset container. |
getRootNode | Gets the root transform node of a loaded glTF asset. |
getSelectedMaterialVariant | Gets the currently selected KHR_materials_variants material variant of a loaded glTF asset. |
listAnimationGroupNames | Lists the names of the animation groups of a loaded glTF asset container. |
listMaterialVariants | Lists the names of the KHR_materials_variants material variants declared by a loaded glTF asset. |
loadAssetContainer | Loads a glTF or glb file from an uploaded asset file into the scene and returns the asset container. |
loadAssetContainerFromUrl | Loads a glTF or glb file from a url into the scene and returns the asset container. |
playAnimationGroup | Starts playing an animation group of a loaded glTF asset. |
resetMaterialVariant | Resets the materials of a loaded glTF asset back to the original KHR_materials_variants default. |
selectMaterialVariant | Activates a KHR_materials_variants material variant by name, swapping the materials of the asset accordingly. |
stopAnimationGroup | Stops an animation group of a loaded glTF asset. |
Gaussian splatting
| Function | What it does |
|---|---|
clone | Makes a copy of a Gaussian splatting mesh that shares its splat data, so the same capture can appear at several places cheaply. |
create | Loads 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. |
getSplatPositions | Reads 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
| Function | What it does |
|---|---|
createScreenshot | Renders 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. |
createScreenshotAndDownload | Renders the scene through camera, or the active camera when none is given, at the given size and downloads the image in the browser. |