Docs
Guides

Choose what visitors can see

Build the filtered package a public view shows, through a declared filter. The package is local; hosting and publishing it is a separate step.

A public World is never the internal World. A declared filter names which objects, properties, readings and alarms are public; publicPackage keeps only those and is the only thing a public World is made from: the public view visitors see of your scene.

A package, not a website

publicPackage builds a filtered package in your code. It does not publish a hosted world or create a public URL; serving the package is your application's job, or Klorad One's. To put a world inside another site, see Embed a published world.

publish.ts
import { createScene, packScene, publicPackage, type PublicationFilter } from "@klorad/api/world";

const scene = createScene({ name: "Northgate", coordinateSystem: { origin: { lat: 40.66, lon: 22.865 } } });
scene.add({ id: "office", name: "Operations office", position: { east: 0, north: -35 }, properties: { kind: "building", tenant: "Northgate SA" } });
scene.add({ id: "gate-cam", name: "Gate camera", position: { east: 0, north: -75 }, properties: { kind: "camera" } });
scene.add({ id: "crac", name: "Server room cooling", position: { east: 5, north: -33 }, correspondence: "twin", binding: { source: "bms", entity: "p:northgate:r:crac" }, properties: { kind: "equipment" } });
scene.observe({ objectId: "crac", quantity: "temperature", value: 22.5, observedAt: Date.now(), source: "bms" });
scene.observe({ objectId: "crac", quantity: "setpoint", value: 21, observedAt: Date.now(), source: "bms" });

// Nothing is public that the filter does not name.
const filter: PublicationFilter = {
  exclude: { kind: ["camera"] },
  properties: ["kind"],
  quantities: ["temperature"],
  alarms: ["server-room-hot"],
};

export async function publicView() {
  const pub = await publicPackage(await packScene(scene), filter, "Northgate, public view");
  const objects = pub.chunks.flatMap((c) => c.objects);
  objects.map((o) => o.id); // ["office", "crac"]: the camera stays inside
  objects.find((o) => o.id === "office")?.properties; // { kind: "building" }: the tenant stays inside
  JSON.stringify(pub).includes("p:northgate"); // false: no source or device id leaves
  return pub;
}

What the projection does

  • Keeps the objects the filter admits: by layer, by class, by id, and never one whose properties match exclude.
  • Keeps only the properties named in properties.
  • Turns a shadow or a twin into a shadow bound to an anonymous source, so no source or device id leaves and nothing public can be actuated.
  • Keeps the readings of the quantities named in quantities, and drops relations to objects that are not public, provenance and extensions.
  • Keeps the scene's 3D Tiles context only when externalSpaces is true.
  • Keeps the model files public objects are drawn from only when models is true, and lists only those files among its assets; otherwise a model shows as a marker where it stands.
  • Keeps the scene's named views, or the views you pass as the fourth argument, in order: a viewer starts at the first. checkPublicViews(views) gives their problems.
  • Carries immersive as it is: whether the World may be walked in a VR headset. The projection is the same either way; a viewer reads it from the filter.

In Klorad One

This section is about the platform, not the SDK. Klorad One publishes each projection as an immutable version at /p/<slug>, with an installable app, and hides every version at once when the World is unpublished.

Try it in your browserExample: Choose what visitors can seeThe public package keeps only what the operator chooses to publish, and none of the site's device ids.

Something wrong or unclear? Tell us.