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)" },
] as const;
/** A pumping room drawn from four files in four 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: "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 }) });
}