Show a building as BIM
Load a prepared building tileset and select its elements, in three.js, on a plan and on the globe. What you need before you start, and what Klorad One does for you.
Load a prepared building tileset and select its elements. Each selected element can carry properties and connect to your application's data.
Before you start
With the SDK you need a prepared tileset: a 3D Tiles 1.1 tileset whose features carry
each element's IFC GlobalId in a globalId column (EXT_mesh_features with
EXT_structural_metadata). IFC conversion is not in the SDK packages: turning an IFC file
into such a tileset is a preprocessing step you run before. Klorad One has its own path: an
IFC file put in an organisation's library is converted on the platform
(below). Placement is manual: where the IFC file places the building on
Earth (IfcMapConversion) is not read yet, so you position the building's object yourself.
Selection by element works in three.js and on the globe (Cesium); on an OpenLayers plan an
element is the area of its footprint.
To try the code before you have a tileset of your own, use the one the BIM example streams: a small two storey guardhouse written as IFC 4.3 for these docs (guardhouse.ifc) and converted the way Klorad One converts it (tileset.json). It is a stand in drawn to the size of a real guardhouse, not a survey.
How a building is held
A building model is two things. What it looks like is a lot of triangles, best streamed as 3D Tiles so a large building opens quickly. What it means is a structure (site, building, storeys, rooms) and the elements in it, each with its class, its type, the systems it belongs to and its property sets. Klorad keeps them apart and joins them by the element's id.
- The building's model is one Scene Object whose geometry is a model in the format
"3d-tiles": a 3D Tiles 1.1 tileset. Each element is a feature of its tiles (EXT_mesh_features), and the tiles' property table (EXT_structural_metadata) names it in aglobalIdcolumn. - Each part you want to work with is a Scene Object with the geometry
feature:ofnames the building's object,featurethe element's id. Its body is drawn by the building's model, so it adds no geometry of its own to load or draw; it carries a name, a classification, relations and properties like any other object, and it can be a Digital Shadow bound to a sensor.
import { createScene, TILESET_FORMAT } from "@klorad/api/world";
import { createThreeRenderer } from "@klorad/engine-three";
import { createMapRenderer } from "@klorad/engine-openlayers";
import { createCesiumRenderer } from "@klorad/engine-cesium";
const scene = createScene({ coordinateSystem: { origin: { lat: 40.6262, lon: 22.9479, height: 6 } } });
// The building's model: a 3D Tiles 1.1 tileset whose features carry a `globalId` column.
scene.add({ id: "guardhouse", name: "Guardhouse", position: { east: 0, north: 0 }, geometry: { kind: "model", uri: "asset:guardhouse", format: TILESET_FORMAT } });
// A storey and one element of it, each drawn by the building's model as one of its features.
scene.add({ id: "ground", name: "Ground floor", position: { east: 0, north: 0 }, geometry: { kind: "feature", of: "guardhouse", feature: "2O2Fr$t4X7Zf8NOew3FL00" }, classifications: { ifc: "IfcBuildingStorey" } });
scene.add({
id: "camera-1",
name: "Camera Control room",
position: { east: 0.2, north: 4.3, up: 2.75 },
geometry: { kind: "feature", of: "guardhouse", feature: "2O2Fr$t4X7Zf8NOew3FLOH", footprint: [[-0.125, -0.125], [0.125, -0.125], [0.125, 0.125], [-0.125, 0.125]], height: 0.2 },
classifications: { ifc: "IfcAudioVisualAppliance" },
relations: [{ kind: "in", to: "ground" }],
properties: { "ifc.systems": "CCTV", "ifc.pset.Pset_AudioVisualApplianceTypeCamera.Resolution": "3840 x 2160" },
});
// Where `asset:` files are fetched from; a building's tileset is asked for with the purpose "tileset".
const assetUrl = (assetId: string, purpose?: "tileset") => (purpose === "tileset" ? `/tiles/${assetId}/tileset.json` : `/files/${assetId}`);
// One selection, three readers: a click in any of them names the element's object, never the building.
const views: { select(id: string | null): void }[] = [];
const select = (id: string | null) => views.forEach((v) => v.select(id));
views.push(createThreeRenderer({ container: document.getElementById("depth")!, scene, assetUrl, onPick: select }));
views.push(createMapRenderer({ container: document.getElementById("plan")!, scene, onPick: select }));
// Cesium reads its workers and assets from CESIUM_BASE_URL; serve the `cesium` package's Build/Cesium there.
(window as { CESIUM_BASE_URL?: string }).CESIUM_BASE_URL = "/cesium/";
views.push(createCesiumRenderer({ container: document.getElementById("globe")!, scene, assetUrl, onPick: select }));What the readers do
| Reader | The building | A feature object |
|---|---|---|
@klorad/engine-three | Streams the tiles about the object's place and heading. | A click on its triangles names it; selected, its triangles are laid over in palette.feature. Its outline and height, when given, frame it and place its label. |
@klorad/engine-openlayers | A symbol at its place. | Its footprint, turned by its heading, as an area on the plan. |
@klorad/engine-cesium | Streams the tiles on the globe, placed by the object. | A click on its feature names it; selected, a 3D Tiles style colours it. |
A feature object is not dragged, turned or scaled on its own: it moves with its building. To move the building, move the building's object.
Where the tileset comes from
With the SDK alone, you bring the tileset: any 3D Tiles 1.1 tileset whose features carry the
element's id in a globalId column works as above. Turning an IFC file into one is a
preprocessing step the packages do not include.
In Klorad One
This section is about the platform's editor, not the SDK. Klorad One makes the tileset for you:
- Put the IFC file in the organisation's library. It is read once on the platform's worker: its meaning is kept beside the file, and its geometry is written as a tileset in the library's storage.
- Place the building in a site. It streams as tiles.
- In the Model section of the placed building, choose Bring in as BIM. Its site, storeys
and rooms become objects above where the building stands, each
inthe part that holds it. Its elements stay features of the model, so a large building adds a handful of objects to the scene, not one per element. - In Edit, find an element: each building is listed under the scene's objects, storeys by elevation, rooms, and in each the elements by class, with a search by name, class or GlobalId. A storey can be shown on its own.
- Pick an element, in the list or in the view, to see its facts and property sets, read when it is picked.
- Choose Make it an object to turn one element into a
featureobject you can name, describe and bind like any other. Its IFC property sets become properties namedifc.pset.<Set>.<Property>.
Bring in again with a new version of the file updates the objects by GlobalId and keeps
their bindings and the properties you added; a part the new file no longer has is marked
ifc.missing, never removed.
Elements without objects in three.js
A click on an element that has no object of its own reports the building's object and the
element's id in PointerHit.feature. The renderer can highlight such a feature and show only
some features of a model:
renderer.selectFeature({ of: "building", feature: hit.feature });
renderer.setFeatureFilter("building", new Set(["2O2Fr$t4X7Zf8NOew3FLOH"]));
renderer.setFeatureFilter("building", null); // the whole building againIn React, the same is the selectedFeature and featureFilters props of the three.js view.
The globe shows part of a building the same way: featureFilters on CesiumView, or
setFeatureFilters({ building: new Set([...]) }) on its renderer. On the plan, only elements
that are objects are drawn and picked.
Any 3D Tiles 1.1 tileset whose features carry a globalId property works the same way with
the SDK: name it as the building's model and add feature objects for the elements you want
to work with.
Limits
- Where the IFC file places the building on Earth (
IfcMapConversion) is not read yet; the building stands at the scene's origin, or at its site's reference point, and you place it. - Context around a building (a city mesh, terrain) is an external space, not part of the building's tileset.
Something wrong or unclear? Tell us.
Put a basemap and terrain under a scene
Draw a scene over a basemap on the map, on the globe and in the 3D scene, turn terrain on under the globe and the 3D scene, hide place labels, and change any of it while the view runs.
Group objects into a compound object
A whole made of parts that stay Scene Objects of their own; move or turn the whole and its parts go with it, edit a part and only the part changes.