Bitbybit Docs
    Preparing search index...

    Class BabylonIO

    Loading models into the scene and exporting it: glTF, glb, STL and OBJ files come in from a File, a URL or raw glb bytes as one container mesh with their children under it, and the whole scene or chosen meshes go out as .babylon, glb or STL downloads.

    Index

    Constructors

    export

    • 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.

      Parameters

      Returns void

      bitbybit.babylon.io.exportBabylon({ fileName: "my-scene" });
      
    • 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. Given the unit the scene is modelled in, the file is in metres, glTF's own unit.

      Parameters

      • inputs: ExportSceneGlbDto

        The file name, whether to leave out the skybox and ground, and the unit

      Returns void

      bitbybit.babylon.io.exportGLB({ fileName: "my-scene", discardSkyboxAndGrid: true });
      
    • Writes the whole scene, or chosen nodes, as glb bytes without downloading anything, to save, send on or load back with loadGlbFromArrayBuffer.

      Every ancestor of a chosen node is written too, so the geometry keeps its place, with the meshes' materials as they are. With the scene's unit, the file is in metres.

      Parameters

      • inputs: ExportSceneGlbBytesDto

        The nodes to write, whether to leave out the skybox and ground, whether to compress with Draco, and the unit

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The glb file as bytes

      const glb = await bitbybit.babylon.io.exportGLBBytes({ nodes: [chair], discardSkyboxAndGrid: true, compressWithDraco: false });
      const copy = await bitbybit.babylon.io.loadGlbFromArrayBuffer({ glbData: glb, fileName: "chair.glb", hidden: false });
    • Downloads a mesh and its visible child meshes as one STL file, the plain triangle format 3D printers take; lines are left out.

      Parameters

      Returns Promise<any>

      An empty object once the download has started

      await bitbybit.babylon.io.exportMeshToStl({ mesh, fileName: "part" });
      
    • Downloads several meshes, with their child meshes, as one STL file; lines are left out.

      Parameters

      Returns Promise<any>

      An empty object once the download has started

      await bitbybit.babylon.io.exportMeshesToStl({ meshes: [meshA, meshB], fileName: "parts" });
      

    load

    • 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.

      The loaded meshes cast and receive shadows and start hidden when hidden is true. Like drawn meshes, they are not pickable until bitbybit.babylon.mesh.setPickable makes them so.

      Parameters

      • inputs: AssetFileDto

        The model file and whether it starts hidden

      Returns Promise<Mesh>

      The container mesh holding the loaded model

      const file = await bitbybit.asset.getFile({ fileName: "chair.glb" });
      const model = await bitbybit.babylon.io.loadAssetIntoScene({ assetFile: file, hidden: false });
    • Loads a glTF, glb, STL or OBJ model from a File into the scene, as loadAssetIntoScene does, without giving the mesh back.

      Parameters

      • inputs: AssetFileDto

        The model file and whether it starts hidden

      Returns Promise<void>

      const file = await bitbybit.asset.getFile({ fileName: "chair.glb" });
      await bitbybit.babylon.io.loadAssetIntoSceneNoReturn({ assetFile: file, hidden: false });
    • 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.

      rootUrl is the folder and assetFile the file in it, so textures beside the model resolve; the server must allow cross-origin requests. The meshes are not pickable until bitbybit.babylon.mesh.setPickable makes them so.

      Parameters

      Returns Promise<Mesh>

      The container mesh holding the loaded model

      const model = await bitbybit.babylon.io.loadAssetIntoSceneFromRootUrl({ rootUrl: "https://example.com/models/", assetFile: "chair.glb", hidden: false });
      
    • Loads a model from a web address into the scene, as loadAssetIntoSceneFromRootUrl does, without giving the mesh back.

      Parameters

      Returns Promise<void>

      await bitbybit.babylon.io.loadAssetIntoSceneFromRootUrlNoReturn({ rootUrl: "https://example.com/models/", assetFile: "chair.glb", hidden: false });
      
    • 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.

      Like drawn meshes, the loaded ones are not pickable until bitbybit.babylon.mesh.setPickable makes them so.

      Parameters

      • inputs: AssetGlbDataDto

        The glb bytes, a name for the model and whether it starts hidden

      Returns Promise<Mesh>

      The container mesh holding the loaded model

      const glb = await bitbybit.occt.io.convertStepToGltf({ stepData: file, meshPrecision: 0.005, meshAngle: 0.5, meshRelative: true, internalVerticesMode: false, controlSurfaceDeflection: false });
      const model = await bitbybit.babylon.io.loadGlbFromArrayBuffer({ glbData: glb, fileName: "part.glb", hidden: false });
    • Loads a glb model held as bytes into the scene, as loadGlbFromArrayBuffer does, without giving the mesh back.

      Parameters

      • inputs: AssetGlbDataDto

        The glb bytes, a name for the model and whether it starts hidden

      Returns Promise<void>

      await bitbybit.babylon.io.loadGlbFromArrayBufferNoReturn({ glbData: glb, fileName: "part.glb", hidden: false });