Models and mapsStart here: 1 of 4Model files
Place and swap models
A pumping room drawn from glTF, STL, OBJ, PLY and KMZ files, each placed, scaled and swapped in the scene.
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 { createScene, modelFormatOf, type Scene } from "@klorad/api/world";
/** The model files of the pumping room, one per format; a model names its file by its address, and the extension says the format. */
export const MODEL_FILES = [
{ uri: "/models/kiosk.glb", name: "Control kiosk (glTF binary)" },
{ uri: "/models/pump.stl", name: "Pump (STL, Z up)" },
{ uri: "/models/tank.obj", name: "Tank (OBJ)" },
{ uri: "/models/cabinet.ply", name: "Valve cabinet (PLY, coloured by vertex)" },
{ uri: "/models/guard-house.kmz", name: "Guard house (KMZ, textured Collada)" },
] as const;
/** A pumping room drawn from five files in five formats, each placed, scaled and turned by the scene. */
export function createModelsDemo(): { readonly scene: Scene } {
const scene = createScene({ name: "Pumping room", coordinateSystem: { origin: { lat: 40.62, lon: 22.95, height: 4 } } });
scene.add({ id: "kiosk", name: "Control kiosk", position: { east: -12, north: 4 }, scale: 0.6, geometry: { kind: "model", uri: "/models/kiosk.glb" } });
scene.add({ id: "pump", name: "Pump P1", position: { east: 0, north: 0 }, scale: 2, orientation: { heading: 30 }, geometry: { kind: "model", uri: "/models/pump.stl" } });
scene.add({ id: "tank", name: "Tank T1", position: { east: 7, north: 5 }, geometry: { kind: "model", uri: "/models/tank.obj" } });
scene.add({ id: "guard", name: "Guard house", position: { east: -6, north: -10 }, orientation: { heading: 20 }, geometry: { kind: "model", uri: "/models/guard-house.kmz" } });
scene.add({ id: "cabinet", name: "Valve cabinet", position: { east: 6, north: -5 }, orientation: { heading: -90 }, scale: 1.5, geometry: { kind: "model", uri: "/models/cabinet.ply" } });
return { scene };
}
/** Swaps the file an object shows, keeping where it stands; the format comes from the new file's name. */
export function replaceModel(scene: Scene, id: string, uri: string, scale?: number) {
const format = modelFormatOf(uri);
return scene.update(id, { geometry: { kind: "model", uri, ...(format ? { format } : {}) }, ...(scale === undefined ? {} : { scale }) });
}Anchor40.62000° N 22.95000° E
East, north+0.0 m +0.0 m
Digital ObjectDigital ShadowDigital TwinStale