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.

      Parameters

      • inputs: ExportSceneGlbDto

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

      Returns void

      bitbybit.babylon.io.exportGLB({ fileName: "my-scene", discardSkyboxAndGrid: true });
      
    • 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.

      Every ancestor of a chosen node is written too, so the geometry keeps its place, and the file carries the materials the meshes have at the time of the call.

      Parameters

      • inputs: ExportSceneGlbBytesDto

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

      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.

      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 name in it, so textures beside the model resolve too; the server must allow cross-origin requests.

      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.

      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 });