Models and mapsStart here: 2 of 4A building from an IFC file
Select a building element
A building from an IFC file, streamed as 3D Tiles with each element a feature, the same element picked in three.js, on a plan and on the globe.
What this example defines: its scene and, where it has them, its simulated source and its styling. The page imports and runs this file; the page's own renderer, panels and controls are not in it. For a complete app to run on your machine, download the quickstart starter.
import type { MapStyleFn } from "@klorad/engine-openlayers";
import { createScene, type GeoPoint, type SceneObject, type SceneObjectSpec } from "@klorad/api/world";
import made from "./guardhouse.json";
// why: JSON is typed by its values, not by the World's types; build-bim.mjs wrote it from importCommands
const guardhouse = made as unknown as { readonly origin: GeoPoint; readonly objects: readonly SceneObjectSpec[] };
/**
* A guardhouse brought in as BIM (ADR-0064). Klorad One's worker read its IFC file once and kept
* two things: the building as 3D Tiles 1.1, every element a feature named by its IFC GlobalId,
* and its structure as Scene Objects. The site draws the tiles; the building, its storeys, its
* rooms and every element are `feature` objects of it, each `in` the part that holds it, with
* the IFC property sets as properties. `scripts/build-bim.mjs` made both from an IFC file.
*/
export function createBimDemo() {
const scene = createScene({ name: "Guardhouse as BIM", coordinateSystem: { origin: guardhouse.origin } });
for (const o of guardhouse.objects) scene.add(o);
return { scene };
}
/** Where a building's files are: its tileset is asked for with the purpose `"tileset"`. */
export const assetUrl = (assetId: string, purpose?: "tileset") => (purpose === "tileset" ? `/tiles/${assetId}/tileset.json` : `/models/${assetId}.glb`);
/** The IFC class of an object, as the import classified it. */
export const ifcClass = (o: SceneObject) => o.classifications?.ifc ?? "";
/** The parts an object holds: the objects that are `in` it, in the order of the scene. */
export const partsOf = (objects: readonly SceneObject[], id: string) => objects.filter((o) => o.relations?.some((r) => r.kind === "in" && r.to === id));
/** An element's IFC properties as rows to show: its own first, then its property sets by name. */
export function propertyRows(o: SceneObject): [string, string][] {
return Object.entries(o.properties)
.filter(([k]) => k.startsWith("ifc.") && k !== "ifc.globalId" && k !== "ifc.name")
.map(([k, v]): [string, string] => [k.replace(/^ifc\.(pset\.)?/, ""), String(v)])
.sort(([a], [b]) => Number(a.includes(".")) - Number(b.includes(".")));
}
/** The plan: rooms filled and named, elements as thin outlines, the selected part in the selection's colour with its name. */
export const bimPlanStyle: MapStyleFn = ({ object, selected, palette }) => {
const room = ifcClass(object) === "IfcSpace";
const colour = selected ? palette.selected : room ? palette.shadow : palette.object;
return { color: colour, fill: selected ? 0.6 : room ? 0.12 : 0.35, outline: colour, outlineWidth: selected ? 2.5 : room ? 1 : 0.5, ...(room || selected ? { label: object.name } : {}) };
};Click a wall, a window or a camera: each is an element of the building.
Anchor40.62620° N 22.94790° E
East, north+0.0 m +0.0 m
Digital ObjectDigital ShadowDigital TwinStale
OpenLayers
Cesium
The camera reports once the globe moves.