Docs
Concepts

Rendering

Renderers draw what the World layer defines, follow its events, report what the pointer does, and never change world state.

A renderer is a reader. It draws every Scene Object, follows the scene's events to stay in step, and reports what a person does with the pointer. It never writes to the world: a click, a hover or a drag becomes a value passed to your code, and your code decides what, if anything, changes.

Five readers ship today, and the Readers sandbox runs three of them side by side on one scene. @klorad/engine-three draws it in 3D with three.js. @klorad/engine-openlayers draws it as a plan with OpenLayers. @klorad/engine-cesium draws it on the globe with CesiumJS; the BIM sandbox shows it beside the other two. @klorad/engine-mapbox draws it on a GL map with Mapbox GL JS or MapLibre GL JS, solids raised to their height; the Map sandbox shows it beside three.js. The projection for agents (describeScene, agentText) reads it as text and relations. Each declares what it draws (ReaderCapabilities) and reports what it draws only as a symbol, instead of approximating it silently. None of them reads a store: they are given a Scene, and a scene made by createChunkedScene holds only the chunks of a package that a view needs.

Frames

The scene's local frame (east, north, up in metres) maps to three.js as east is +x, up is +y, north is -z. localToThree, threeToLocal and geoToThree convert for code that adds its own three.js objects.

What it draws

Every object is drawn from its geometry: a box, a cylinder, a sphere, a pin, a glTF model, or one of the shapes of a map (a footprint raised to a height, a flat area, a line with a width). Volumes are lighter at the foot than at the top, shaded by which way each face looks and edged, so a scene reads like a model on a survey sheet from every side. The ground is a grid that fades toward its edge.

With no style function, colour encodes correspondence (objects, shadows and twins each have their own) and freshness (a shadow whose readings have gone stale is drawn in the stale colour). A newer reading or a Behaviour's Animation brightens the object for a moment. A shadow or a twin with a compact body also stands in a ring on the ground, and the moment sends a second ring outward from it; an area, a line or a long bar has no ring, because one around it would say nothing. A new object rises into place.

Your own looks

objectStyle maps an object's state to how it looks: colour, opacity, a height scale, a glow, a pose and a label. It receives the object, its current readings, whether they are stale, and the palette.

render.ts
import { createScene } from "@klorad/api/world";
import { createThreeRenderer } from "@klorad/engine-three";

const scene = createScene({ coordinateSystem: { origin: { lat: 40.62637, lon: 22.94838 } } });
scene.add({ name: "Exhibition hall", position: { east: 0, north: 0 }, geometry: { kind: "box", width: 24, depth: 14, height: 7 } });

const renderer = createThreeRenderer({
  container: document.getElementById("view")!,
  scene,
  onPick: (id) => renderer.select(id),
  objectStyle: ({ object, readings, stale, palette }) => {
    if (stale) return { color: palette.stale };
    const people = readings.occupancy?.value;
    return typeof people === "number" ? { color: palette.shadow, heightScale: people / 20 } : { color: object.color ?? palette.object };
  },
});
renderer.frame();

In React, ThreeView from @klorad/engine-three/react takes the same options and reads the scene from the nearest KloradProvider. See Style objects by readings.

The pointer and the camera

The renderer reports three things a person does. onPick is a click: the object under it, and where the click met the ground, on Earth and in metres. onPointer is the same on every move. onDrag is the selected object being dragged over the ground. None of them changes anything; an object moves only when your code calls scene.update.

The camera is described as a map would describe it: the point it looks at, the compass bearing it looks along, how steeply it looks down and how far it stands. view() reads it, setView() moves it and frame() points it at objects.

view-controls.ts
import { createScene } from "@klorad/api/world";
import { createThreeRenderer } from "@klorad/engine-three";

const scene = createScene({ coordinateSystem: { origin: { lat: 40.62637, lon: 22.94838 } } });
scene.add({ id: "kiosk", name: "Kiosk", position: { east: 0, north: 0 }, geometry: { kind: "box", width: 6, depth: 4, height: 3 } });

const readout = document.getElementById("readout")!;
const renderer = createThreeRenderer({
  container: document.getElementById("view")!,
  scene,
  // A click selects. A click on empty ground also says where it landed, here to put a pin there.
  onPick: (id, hit) => {
    renderer.select(id);
    if (!id && hit.geo) scene.add({ name: "Pin", position: hit.geo, geometry: { kind: "marker" } });
  },
  // Where the pointer is, on Earth.
  onPointer: (hit) => (readout.textContent = hit?.geo ? `${hit.geo.lat.toFixed(5)}, ${hit.geo.lon.toFixed(5)}` : ""),
  // The renderer moves nothing. A drag becomes a move because this line updates the scene.
  onDrag: ({ objectId, position }) => scene.update(objectId, { position }),
});

// The camera, in the words of a map.
document.getElementById("north")!.onclick = () => renderer.setView({ heading: 0 });
document.getElementById("above")!.onclick = () => renderer.setView({ tilt: 89.5, heading: 0 });
document.getElementById("all")!.onclick = () => renderer.frame();
document.getElementById("kiosk")!.onclick = () => renderer.frame(["kiosk"]);

By default the view takes every gesture, as an app that fills its page wants. Inside a page that scrolls, cooperativeGestures leaves the wheel and the vertical swipe to the page.

See Navigation and selection.

Try it in your browserExample: Compare geographic and local coordinatesThessaloniki's waterfront, where every point of the scene is a real place on Earth.

Something wrong or unclear? Tell us.