KloradDocs

@klorad/api/world

The World layer. Scenes, Scene Objects, space, time, snapshots, interaction and projections. Pure TypeScript.

import { createScene } from "@klorad/api/world";

Scene

ExportKindDescription
createScene(options)functionCreates an empty scene anchored on Earth. Throws without a coordinateSystem.
ScenetypeThe scene: the only way to change world state.
SceneOptionstypeOptions of createScene.
SceneEvent, SceneListenertypeThe ordered events every change becomes.
snapshotScene(scene), restoreScene(snapshot, options?)functionTo and from a JSON SceneSnapshot.
projectScene(source, admits, name?)functionA read model holding only the objects admits accepts, kept in step. Returns a Projection (scene, stop()).

Prop

Type

Scene methods

MethodReturnsDescription
add(spec)the object, typed by its specAdds a Scene Object. Throws on a duplicate id or an invalid spec.
update(id, patch)SceneObjectPatches name, position, orientation, scale, geometry, colour or properties (merged). Throws on an unknown id.
remove(id)booleanRemoves an object and its readings.
get(id)SceneObject | undefined
objects()readonly SceneObject[]In insertion order; the same array until something changes.
observe(input)ObserveResultOffers a reading: latest, late, duplicate or rejected.
latest(id, quantity)Observation | undefinedThe current reading.
readings(id)Record<string, Observation>The current reading of every quantity; the same object until one changes.
history(id, quantity)readonly Observation[]Ordered by observedAt, then seq.
isStale(id, quantity)booleanAgainst the scene's clock, now.
boundTo(source, entity)readonly SceneObject[]The shadows and twins bound to a source entity.
subscribe(listener)() => voidEvery event, in order. Returns an unsubscribe function.
version()numberThe seq of the last event.

Scene Objects

ExportKindDescription
SceneObjecttypeDigitalObject | DigitalShadow | DigitalTwin, discriminated by correspondence.
SceneObjectSpec, DigitalObjectSpec, DigitalShadowSpec, DigitalTwinSpectypeWhat add takes.
SceneObjectPatchtypeWhat update takes.
Correspondencetype"object" | "shadow" | "twin".
SourceBindingtype{ source, entity }.
Geometrytypebox, cylinder, sphere, marker or model (a glTF uri).
Orientationtypeheading, pitch, roll in degrees.
isObservable(object)functionNarrows to a shadow or a twin.

Space

ExportKindDescription
createCoordinateSystem({ origin })functionAn East, North, Up frame in metres at a WGS84 origin: toLocal, toGeo, resolve.
Position, GeoPosition, LocalPosition, GeoPoint, LocalPointtypeA position on Earth (lat, lon, height) or in metres (east, north, up).
isLocalPosition(p)functionTrue for the local form.
geoPoint, geodeticToEcef, ecefToGeodetic, toRadians, toDegreesfunctionGeodesy helpers on WGS84.

Time

ExportKindDescription
Clock, Instanttypenow() in epoch milliseconds.
systemClockvalueThe default clock.
createManualClock(start)functionA clock you advance(ms) or set(instant), for tests.
Observation, ObservationInput, ObservationValue, ObservationQuality, ObserveResulttypeA reading: objectId, quantity, value, unit, observedAt, receivedAt, source, quality, seq.
compareObservations(a, b)functionThe Time Spectrum order: observedAt, then seq.

Interaction

ExportKindDescription
createInteraction(scene, options)functionRuns Action, Entitlement, Behaviour, Animation. Returns an Interaction.
Interactiontypeavailable(objectId, actor, world?) and perform(request).
ActionDefinition, BehaviourDefinition, BehaviourContext, AnimationRequesttypeWhat you define.
ActionRequest, ActionResult, ActionOutcome, ActionParams, ParamValue, ActortypeWhat you ask and what you get back.
Entitlement, DecisiontypeThe port Access implements.
Actuator, Command, CommandReceipttypeThe port toward devices, for Digital Twins.

Prop

Type

Something wrong or unclear? Tell your contact at Prieston Technologies.