Allow to load multiple copies of same IFC model
xeolabs opened this issue · 0 comments
Bug
To reproduce this issue, we load a project that contains two copies of the same IFC model.
We then note that objects between the two models have the same IDs within the BIMViewer, which causes ambiguity; the tree view does not synchronize correctly with object states.
Fix
First, update to @xeokit/xeokit-bim-viewer 2.4.7-beta-2
Below we'll describe how to configure a project so that it can contain multiple copies of the same IFC model, without getting weird behaviour in the BIMViewer (ID clashes, tree view issues).
Take a look at the data in this example project: https://github.com/xeokit/xeokit-bim-viewer/tree/master/app/data/projects/IfcOpenHouse4_multiple
This project can be viewed live here.
The index.json
file (located at the root of the example project directory structure) is the manifest of all the models within the project. For each model, we can now specify globalizeObjectIds:true
to ensure that its IDs will not clash with the other copies of that model.
{
"id": "IfcOpenHouse4",
"name": "IfcOpenHouse4",
"models": [
{
"id": "house1",
"name": "House 1",
"origin": [0,0,-5],
"globalizeObjectIds": true
},
{
"id": "house2",
"name": "House 2",
"origin": [0,0,10],
"globalizeObjectIds": true
}
],
"viewerConfigs": {
},
"viewerContent": {
"modelsLoaded": [
"house1", "house2"
]
},
"viewerState": {
"tabOpen": "classes",
"expandObjectsTree": 1,
"expandClassesTree": 1,
"expandStoreysTree": 2
}
}
Once the project is loaded, and both its models are loaded, we can now switch the visibility of an object in one of the models, and we see that only the tree node for that object updating.
Accessing Objects with JavaScript
To access the object programmatically, we have two options:
Option 1: supply the UUID of the original IFC element, which will update the corresponding object in both models. This UUID will "expand" to reference both copies of that object:
bimViewer.viewer.scene.setObjectsSelected(["2KoBar2pfAWBou8q$ldGHy"], true)
Option 2: Supply the UUID of the original IFC element, this time prefixed with the ID of the model (note the '#' delimiter):
bimViewer.viewer.scene.setObjectsSelected(["house2#2KoBar2pfAWBou8q$ldGHy"], true)
The disadvantage here is that we would need to know the model IDs that we configured in the index.json
.
Querying Properties
When we query properties on an object that belongs to one of our models, we get the original UUID (which is shared with the same object in the other model), but now we also get the "Viewer ID", which is the prefixed ID of the object within the BIMViewer: