Namespace dotbim

xeokit .BIM Importer and Exporter


Import and export the open, free, and simple .BIM model file format


The xeokit SDK enables the import of 3D models from the .BIM format, a JSON-based file format specifically designed for lightweight, user-friendly, and human-readable storage and sharing of 3D BIM models.

.BIM is an open-source, minimalist file format for BIM, created to be simple to read and write. It serves as a transfer format that contains triangulated meshes with an associated dictionary of information.

To import a .BIM model into xeokit, use the loadDotBIM function, which will load the file into both a SceneModel and a DataModel.



To install the xeokit SDK, run:

npm install @xeokit/sdk

In the example below, we create a Viewer with a WebGLRenderer and a Scene, which holds model geometry and materials.

Additionally, we create a Data, which holds the semantic data for our model.

We set up a View to render the model on a canvas element on the page and attach a CameraControl to manage the camera using mouse and touch input.

The Scene contains a SceneModel for model geometry and materials, while the Data holds a DataModel for IFC elements and property sets.

We then use loadDotBIM to load a .BIM file into the SceneModel and DataModel.

The SDKError class is used to handle errors during this process.

Example:

import {SDKError} from "@xeokit/sdk/core";
import {Scene} from "@xeokit/sdk/scene";
import {Data} from "@xeokit/sdk/data";
import {WebGLRenderer} from "@xeokit/sdk/webglrenderer";
import {Viewer} from "@xeokit/sdk/viewer";
import {CameraControl} from "@xeokit/sdk/cameracontrol";
import {loadDotBIM} from "@xeokit/sdk/dotbim";

const scene = new Scene();
const data = new Data();

const renderer = new WebGLRenderer({});

const viewer = new Viewer({
id: "myViewer",
scene,
renderer
});

const view = viewer.createView({
id: "myView",
elementId: "myCanvas" // Ensure this HTMLElement exists in the page
});

view.camera.eye = [1841982.93, 10.03, -5173286.74];
view.camera.look = [1842009.49, 9.68, -5173295.85];
view.camera.up = [0.0, 1.0, 0.0];

new CameraControl(view, {});

const sceneModel = scene.createModel({
id: "myModel"
});

const dataModel = data.createModel({
id: "myModel"
});

fetch("model.bim").then(response => {

response.json().then(fileData => {

loadDotBIM({
fileData,
sceneModel,
dataModel
}).then(() => {

sceneModel.build();
dataModel.build();

}).catch(err => {

sceneModel.destroy();
dataModel.destroy();

console.error(`Error loading .BIM: ${err}`);
});

}).catch(err => {
console.error(`Error creating JSON from fetch response: ${err}`);
});

}).catch(err => {
console.error(`Error fetching .BIM file: ${err}`);
});

To export the SceneModel and DataModel back to a .BIM file, use saveDotBIM:

const dotBIMJSON = saveXGF({
sceneModel,
dataModel
});

Functions

loadDotBIM
saveDotBIM