import * as Inputs from "../../inputs"; import * as BABYLON from "@babylonjs/core"; import type { Context } from "../../context"; /** * 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. */ export declare class BabylonIO { private readonly context; private supportedFileFormats; private objectUrl; private readonly math; constructor(context: Context); /** * 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. * @param inputs - The model file and whether it starts hidden * @returns The container mesh holding the loaded model * @group load * @shortname asset * @drawable true * @example * ```typescript * const file = await bitbybit.asset.getFile({ fileName: "chair.glb" }); * const model = await bitbybit.babylon.io.loadAssetIntoScene({ assetFile: file, hidden: false }); * ``` */ loadAssetIntoScene(inputs: Inputs.Asset.AssetFileDto): Promise; /** * Loads a glTF, glb, STL or OBJ model from a File into the scene, as `loadAssetIntoScene` does, * without giving the mesh back. * @param inputs - The model file and whether it starts hidden * @group load * @shortname asset * @example * ```typescript * const file = await bitbybit.asset.getFile({ fileName: "chair.glb" }); * await bitbybit.babylon.io.loadAssetIntoSceneNoReturn({ assetFile: file, hidden: false }); * ``` */ loadAssetIntoSceneNoReturn(inputs: Inputs.Asset.AssetFileDto): Promise; /** * 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. * @param inputs - The folder URL, the file name and whether it starts hidden * @returns The container mesh holding the loaded model * @group load * @shortname asset from url * @drawable true * @example * ```typescript * const model = await bitbybit.babylon.io.loadAssetIntoSceneFromRootUrl({ rootUrl: "https://example.com/models/", assetFile: "chair.glb", hidden: false }); * ``` */ loadAssetIntoSceneFromRootUrl(inputs: Inputs.Asset.AssetFileByUrlDto): Promise; /** * Loads a model from a web address into the scene, as `loadAssetIntoSceneFromRootUrl` does, * without giving the mesh back. * @param inputs - The folder URL, the file name and whether it starts hidden * @group load * @shortname asset from url * @example * ```typescript * await bitbybit.babylon.io.loadAssetIntoSceneFromRootUrlNoReturn({ rootUrl: "https://example.com/models/", assetFile: "chair.glb", hidden: false }); * ``` */ loadAssetIntoSceneFromRootUrlNoReturn(inputs: Inputs.Asset.AssetFileByUrlDto): Promise; /** * 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. * @param inputs - The glb bytes, a name for the model and whether it starts hidden * @returns The container mesh holding the loaded model * @group load * @shortname glb from array buffer * @drawable true * @example * ```typescript * 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 }); * ``` */ loadGlbFromArrayBuffer(inputs: Inputs.Asset.AssetGlbDataDto): Promise; /** * Loads a glb model held as bytes into the scene, as `loadGlbFromArrayBuffer` does, without * giving the mesh back. * @param inputs - The glb bytes, a name for the model and whether it starts hidden * @group load * @shortname glb from array buffer no return * @drawable true * @example * ```typescript * await bitbybit.babylon.io.loadGlbFromArrayBufferNoReturn({ glbData: glb, fileName: "part.glb", hidden: false }); * ``` */ loadGlbFromArrayBufferNoReturn(inputs: Inputs.Asset.AssetGlbDataDto): Promise; /** * 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. * @param inputs - The file name * @group export * @shortname babylon scene * @example * ```typescript * bitbybit.babylon.io.exportBabylon({ fileName: "my-scene" }); * ``` */ exportBabylon(inputs: Inputs.BabylonIO.ExportSceneDto): void; /** * 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. Back faces of * two-sided shapes are left out. * @param inputs - The file name, whether to leave out the skybox and ground, and the unit * @group export * @shortname gltf scene * @example * ```typescript * bitbybit.babylon.io.exportGLB({ fileName: "my-scene", discardSkyboxAndGrid: true }); * ``` */ exportGLB(inputs: Inputs.BabylonIO.ExportSceneGlbDto): void; /** * 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. Back faces * are left out. * @param inputs - The nodes to write, whether to leave out the skybox and ground, whether to compress with Draco, and the unit * @returns The glb file as bytes * @group export * @shortname gltf scene bytes * @example * ```typescript * 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 }); * ``` */ exportGLBBytes(inputs: Inputs.BabylonIO.ExportSceneGlbBytesDto): Promise; private metresPer; private scaled; private glbFileNameOf; private glbExportOptions; private withAncestors; /** * Downloads a mesh and its visible child meshes as one STL file, the plain triangle format 3D * printers take; lines are left out, and so is the back face of a shape drawn two-sided, so * every wall is written once. * @param inputs - The mesh and the file name * @returns An empty object once the download has started * @group export * @shortname babylon mesh to stl * @example * ```typescript * await bitbybit.babylon.io.exportMeshToStl({ mesh, fileName: "part" }); * ``` */ exportMeshToStl(inputs: Inputs.BabylonIO.ExportMeshToStlDto): Promise; /** * Downloads several meshes, with their child meshes, as one STL file; lines and the back faces * of shapes drawn two-sided are left out. * @param inputs - The meshes and the file name * @returns An empty object once the download has started * @group export * @shortname babylon meshes to stl * @example * ```typescript * await bitbybit.babylon.io.exportMeshesToStl({ meshes: [meshA, meshB], fileName: "parts" }); * ``` */ exportMeshesToStl(inputs: Inputs.BabylonIO.ExportMeshesToStlDto): Promise; private downloadStl; private loadAsset; }