Reference Source
public class | source

DotBIMLoaderPlugin

Extends:

src/viewer/index.js~Plugin → DotBIMLoaderPlugin

Viewer plugin that loads models from .bim format.

[Run this example]

  • Creates an Entity representing each .bim model it loads, which will have Entity#isModel set true and will be registered by Entity#id in Scene#models.
  • Creates an Entity for each object within the .bim model. Those Entities will have Entity#isObject set true and will be registered by Entity#id in Scene#objects.
  • When loading, can set the World-space position, scale and rotation of each model within World space, along with initial properties for all the model's Entitys.
  • Allows to mask which types we want to load.
  • Allows to configure initial viewer state for specified types (color, visibility, selection, highlighted, X-rayed, pickable, etc).

Usage

In the example below we'll load a house model from a .bim file.

This will create a bunch of Entitys that represents the model and its objects, along with a MetaModel and MetaObjects that hold their metadata.

import {Viewer, DotBIMLoaderPlugin} from "xeokit-sdk.es.js";

//------------------------------------------------------------------------------------------------------------------
// 1. Create a Viewer,
// 2. Arrange the camera,
// 3. Tweak the selection material (tone it down a bit)
//------------------------------------------------------------------------------------------------------------------

// 1
const viewer = new Viewer({
     canvasId: "myCanvas",
     transparent: true
});

// 2
viewer.camera.orbitPitch(20);
viewer.camera.orbitYaw(-45);

// 3
viewer.scene.selectedMaterial.fillAlpha = 0.1;

//------------------------------------------------------------------------------------------------------------------
// 1. Create a .bim loader plugin,
// 2. Load a .bim building model, emphasizing the edges to make it look nicer
//------------------------------------------------------------------------------------------------------------------

// 1
const dotBIMLoader = new DotBIMLoaderPlugin(viewer);

// 2
var model = dotBIMLoader.load({                                    // Returns an Entity that represents the model
     id: "myModel",
     src: "House.bim",
     edges: true
});

// Find the model Entity by ID
model = viewer.scene.models["myModel"];

// Destroy the model
model.destroy();

Transforming

We have the option to rotate, scale and translate each .bim model as we load it.

This lets us load multiple models, or even multiple copies of the same model, and position them apart from each other.

In the example below, we'll rotate our model 90 degrees about its local X-axis, then translate it 100 units along its X axis.

const model = dotBIMLoader.load({
     src: "House.bim",
     rotation: [90,0,0],
     position: [100, 0, 0]
});

Including and excluding types

We can also load only those objects that have the specified types. In the example below, we'll load only the objects that represent walls.

const model = dotBIMLoader.load({
    id: "myModel",
     src: "House.bim",
     includeTypes: ["IfcWallStandardCase"]
});

We can also load only those objects that don't have the specified types. In the example below, we'll load only the objects that do not represent empty space.

const model = dotBIMLoader.load({
    id: "myModel",
     src: "House.bim",
     excludeTypes: ["IfcSpace"]
});

Configuring initial object appearances

We can specify the custom initial appearance of loaded objects according to their types.

This is useful for things like:

  • setting the colors to our objects according to their types,
  • automatically hiding IfcSpace objects, and
  • ensuring that IfcWindow objects are always transparent.
    In the example below, we'll load a model, while configuring IfcSpace elements to be always initially invisible, and IfcWindow types to be always translucent blue.
const myObjectDefaults = {

     IfcSpace: {
         visible: false
     },
     IfcWindow: {
         colorize: [0.337255, 0.303922, 0.870588], // Blue
         opacity: 0.3
     },

     //...

     DEFAULT: {
         colorize: [0.5, 0.5, 0.5]
     }
};

const model4 = dotBIMLoader.load({
     id: "myModel4",
     src: "House.bim",
     objectDefaults: myObjectDefaults // Use our custom initial default states for object Entities
});

When we don't customize the appearance of types, as just above, then IfcSpace elements tend to obscure other elements, which can be confusing.

It's often helpful to make IfcSpaces transparent and unpickable, like this:

const dotBIMLoader = new DotBIMLoaderPlugin(viewer, {
   objectDefaults: {
       IfcSpace: {
           pickable: false,
           opacity: 0.2
       }
   }
});

Alternatively, we could just make IfcSpaces invisible, which also makes them unpickable:

const dotBIMLoader = new DotBIMLoaderPlugin(viewer, {
   objectDefaults: {
       IfcSpace: {
           visible: false
       }
   }
});

Configuring a custom data source

By default, DotBIMLoaderPlugin will load .bim files and metadata JSON over HTTP.

In the example below, we'll customize the way DotBIMLoaderPlugin loads the files by configuring it with our own data source object. For simplicity, our custom data source example also uses HTTP, using a couple of xeokit utility functions.

import {utils} from "xeokit-sdk.es.js";

class MyDataSource {

     constructor() {
     }

     // Gets the contents of the given .bim file in a JSON object
     getDotBIM(src, ok, error) {
         utils.loadJSON(dotBIMSrc,
            (json) => {
                ok(json);
            },
            function (errMsg) {
                error(errMsg);
            });
     }
}

const dotBIMLoader2 = new DotBIMLoaderPlugin(viewer, {
      dataSource: new MyDataSource()
});

const model5 = dotBIMLoader2.load({
     id: "myModel5",
     src: "House.bim"
});

Constructor Summary

Public Constructor
public

constructor(viewer: Viewer, cfg: Object)

Member Summary

Public Members
public set

Sets a custom data source through which the DotBIMLoaderPlugin can .BIM files.

public get

Gets the custom data source through which the DotBIMLoaderPlugin can load .BIM files.

public set

objectDefaults: {String: Object}

Sets map of initial default states for each loaded Entity that represents an object.

public get

objectDefaults: {String: Object}

Gets map of initial default states for each loaded Entity that represents an object.

Method Summary

Public Methods
public

Destroys this DotBIMLoaderPlugin.

public

load(params: *): Entity

Loads a .BIM model from a file into this DotBIMLoaderPlugin's Viewer.

Public Constructors

public constructor(viewer: Viewer, cfg: Object) source

Params:

NameTypeAttributeDescription
viewer Viewer

The Viewer.

cfg Object

Plugin configuration.

cfg.id String
  • optional
  • default: "DotBIMLoader"

Optional ID for this plugin, so that we can find it within Viewer#plugins.

cfg.objectDefaults Object
  • optional

Map of initial default states for each loaded Entity that represents an object. Default value is IFCObjectDefaults.

cfg.dataSource Object
  • optional

A custom data source through which the DotBIMLoaderPlugin can load metadata, glTF and binary attachments. Defaults to an instance of DotBIMDefaultDataSource, which loads over HTTP.

Public Members

public set dataSource: Object source

Sets a custom data source through which the DotBIMLoaderPlugin can .BIM files.

Default value is DotBIMDefaultDataSource, which loads via an XMLHttpRequest.

public get dataSource: Object source

Gets the custom data source through which the DotBIMLoaderPlugin can load .BIM files.

Default value is DotBIMDefaultDataSource, which loads via an XMLHttpRequest.

public set objectDefaults: {String: Object} source

Sets map of initial default states for each loaded Entity that represents an object.

Default value is IFCObjectDefaults.

public get objectDefaults: {String: Object} source

Gets map of initial default states for each loaded Entity that represents an object.

Default value is IFCObjectDefaults.

Public Methods

public destroy() source

Destroys this DotBIMLoaderPlugin.

public load(params: *): Entity source

Loads a .BIM model from a file into this DotBIMLoaderPlugin's Viewer.

Params:

NameTypeAttributeDescription
params *

Loading parameters.

params.id String
  • optional

ID to assign to the root Entity#id, unique among all components in the Viewer's Scene, generated automatically by default.

params.src String
  • optional

Path to a .BIM file, as an alternative to the bim parameter.

params.bim *
  • optional

.BIM JSON, as an alternative to the src parameter.

params.objectDefaults {String: Object}
  • optional

Map of initial default states for each loaded Entity that represents an object. Default value is IFCObjectDefaults.

params.includeTypes String[]
  • optional

When loading metadata, only loads objects that have MetaObjects with MetaObject#type values in this list.

params.excludeTypes String[]
  • optional

When loading metadata, never loads objects that have MetaObjects with MetaObject#type values in this list.

params.origin Number[]
  • optional
  • default: [0,0,0]

The double-precision World-space origin of the model's coordinates.

params.position Number[]
  • optional
  • default: [0,0,0]

The single-precision position, relative to origin.

params.scale Number[]
  • optional
  • default: [1,1,1]

The model's scale.

params.rotation Number[]
  • optional
  • default: [0,0,0]

The model's orientation, as Euler angles given in degrees, for each of the X, Y and Z axis.

params.backfaces Boolean
  • optional
  • default: true

When true, always show backfaces, even on objects for which the .BIM material is single-sided. When false, only show backfaces on geometries whenever the .BIM material is double-sided.

params.dtxEnabled Boolean
  • optional
  • default: true

When true (default) use data textures (DTX), where appropriate, to represent the returned model. Set false to always use vertex buffer objects (VBOs). Note that DTX is only applicable to non-textured triangle meshes, and that VBOs are always used for meshes that have textures, line segments, or point primitives. Only works while DTX#enabled is also true.

Return:

Entity

Entity representing the model, which will have Entity#isModel set true and will be registered by Entity#id in Scene#models