import {DotBIMLoaderPlugin} from '@xeokit/xeokit-sdk/src/plugins/DotBIMLoaderPlugin/DotBIMLoaderPlugin.js'
DotBIMLoaderPlugin
Extends:
Viewer plugin that loads models from .bim format.
- 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 configuringIfcSpace
elements to be always initially invisible, andIfcWindow
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 |
destroy() Destroys this DotBIMLoaderPlugin. |
|
public |
Loads a .BIM model from a file into this DotBIMLoaderPlugin's Viewer. |
Public Constructors
public constructor(viewer: Viewer, cfg: Object) source
Params:
Name | Type | Attribute | Description |
viewer | Viewer | The Viewer. |
|
cfg | Object | Plugin configuration. |
|
cfg.id | String |
|
Optional ID for this plugin, so that we can find it within Viewer#plugins. |
cfg.objectDefaults | Object |
|
Map of initial default states for each loaded Entity that represents an object. Default value is IFCObjectDefaults. |
cfg.dataSource | Object |
|
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 load(params: *): Entity source
Loads a .BIM model from a file into this DotBIMLoaderPlugin's Viewer.
Params:
Name | Type | Attribute | Description |
params | * | Loading parameters. |
|
params.id | String |
|
ID to assign to the root Entity#id, unique among all components in the Viewer's Scene, generated automatically by default. |
params.src | String |
|
Path to a .BIM file, as an alternative to the |
params.bim | * |
|
.BIM JSON, as an alternative to the |
params.objectDefaults | {String: Object} |
|
Map of initial default states for each loaded Entity that represents an object. Default value is IFCObjectDefaults. |
params.includeTypes | String[] |
|
When loading metadata, only loads objects that have MetaObjects with MetaObject#type values in this list. |
params.excludeTypes | String[] |
|
When loading metadata, never loads objects that have MetaObjects with MetaObject#type values in this list. |
params.origin | Number[] |
|
The double-precision World-space origin of the model's coordinates. |
params.position | Number[] |
|
The single-precision position, relative to |
params.scale | Number[] |
|
The model's scale. |
params.rotation | Number[] |
|
The model's orientation, as Euler angles given in degrees, for each of the X, Y and Z axis. |
params.backfaces | Boolean |
|
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 |
|
When |
Return:
Entity | Entity representing the model, which will have Entity#isModel set |