wired:scene
Scene documents, prims, and their properties.
A document is a tree of prims identified by stable IDs, with all data attached as properties. Each property resolves across layered values, strongest first:
shared: per-peer session writes (author's layer takes precedence).local: local runtime writes visible only on this peer.- Document layer: durable entries written via
commit.
A script can read any loaded document it opens, and can write its own document, documents it created, and documents authored by the same user.
Interface properties
Uses vec2, vec3, transform, color, document-id, prim-id.
Built-in properties that can be attached to a prim.
topology
Primitive assembly mode for a mesh.
point-list | |
line-list | |
line-strip | |
triangle-list | |
triangle-strip |
vertex-attribute
Per-vertex mesh attribute and its float component count.
position | 3 floats in prim-local space (required to render). |
normal | 3 floats, unit length. |
tangent | 4 floats: unit tangent plus bitangent sign. |
color | 4 floats, linear RGBA. |
uv0 | 2 floats. |
uv1 | 2 floats. |
vertex-stream
attribute: vertex-attribute | |
values: list<f32> | Packed vertex components; all streams on a mesh must share the same vertex count. Max 4 MiB. |
alpha-mode
opaque | |
mask | Discards fragments below alpha-cutoff. |
blend | |
add | |
multiply | |
premultiplied |
material
Standard PBR material. Unset fields use renderer defaults; textures are
attached via relation.
base-color: option<color> | |
emissive: option<color> | Emissive color in linear RGB (alpha ignored). |
metallic: option<f32> | 0..1. |
roughness: option<f32> | 0..1. |
alpha-mode: option<alpha-mode> | |
alpha-cutoff: option<f32> | |
double-sided: option<bool> |
address-mode
Texture wrapping mode outside 0..1 UVs.
repeat | |
mirror-repeat | |
clamp-to-edge |
filter-mode
linear | |
nearest |
image-sampler
Texture sampling parameters for a prim carrying image-data.
address-mode-u: option<address-mode> | |
address-mode-v: option<address-mode> | |
address-mode-w: option<address-mode> | |
mag-filter: option<filter-mode> | |
min-filter: option<filter-mode> | |
mipmap-filter: option<filter-mode> | |
srgb: option<bool> | Interpret image as sRGB color (true, default) or linear data such as a normal map (false). |
collider-capsule
Capsule aligned with the prim's Y axis, centered on its origin.
height: f32 | Cylinder height between the two hemispherical caps. |
radius: f32 |
collider-cylinder
Cylinder aligned with the prim's Y axis, centered on its origin.
height: f32 | |
radius: f32 |
collider
Collision shape in prim-local space.
capsule(collider-capsule) | |
convex-hull | Convex hull computed from collider-vertices. |
cuboid(vec3) | Box with full extents, centered on the origin. |
cylinder(collider-cylinder) | |
sphere(f32) | Sphere with the given radius. |
trimesh | Triangle mesh from collider-vertices and collider-indices. |
rigid-body-kind
dynamic | Driven by forces and collisions. |
kinematic | Driven by transform writes; pushes dynamic bodies. |
static | Immovable. |
rigid-body
Enables physics simulation for the prim's collider. Unset fields use simulation defaults.
kind: rigid-body-kind | |
mass: option<f32> | Mass in kilograms. |
friction: option<f32> | |
restitution: option<f32> | Bounciness: 0 for inelastic, 1 for perfectly elastic. |
linear-damping: option<f32> | |
angular-damping: option<f32> |
link-id
link-id = tuple<u64, u64>128-bit pairing token shared by both halves of a two-way portal.
portal-destination
space: document-id | Target space document ID. |
link: option<link-id> | Pairing token for a two-way portal; none creates a one-way portal. |
portal
Rectangular portal window in the prim's XY plane, facing +Z.
width: f32 | |
height: f32 | |
destination: option<portal-destination> |
spawn
Spawn region; arriving peers appear at a random XZ point within radius.
radius: f32 |
text-align
left | |
center | |
right |
text-anchor
Vertical anchor line aligned to the prim's origin.
baseline | |
top | |
middle | |
bottom |
text-billboard
none | |
yaw | Rotates around Y to face the viewer while staying upright. |
full | Rotates fully to face the viewer. |
text
Plain text rendered in the prim's XY plane along +X (no markup).
value: string | Text content (max 4 KiB). |
size: option<f32> | Em height in meters. |
align: option<text-align> | |
anchor: option<text-anchor> | |
wrap: option<f32> | Line wrap width in meters; none wraps only on newlines. |
line-height: option<f32> | Multiplier on the font's default line spacing. |
color: option<color> | |
outline: option<color> | Outline color drawn behind glyphs. |
outline-width: option<f32> | Outline width in ems. |
emissive: option<f32> | Emissive strength (0 for none). |
billboard: option<text-billboard> |
relation
Named reference from one prim to another in the same document.
shader-binding | Shader graph authored on another prim. |
base-color-texture | |
emissive-texture | |
metallic-roughness-texture | |
normal-texture | |
occlusion-texture | |
shader-texture(u8) | Texture sampled by a shader graph at slot 0..=3. |
custom(string) | Application-defined relation named group/field outside reserved host groups. |
property
Property key paired with its value.
parent(option<prim-id>) | Parent prim ID, or none for a root prim. |
name(string) | Prim name (max 1 KiB). |
transform(transform) | Local transform relative to the parent (or document root). |
reference(document-id) | Embeds another document under this prim. |
mesh-topology(topology) | |
mesh-vertices(vertex-stream) | |
mesh-indices(list<u32>) | Vertex indices (max 4 MiB). |
material(material) | |
image-sampler(image-sampler) | |
image-data(list<u8>) | Encoded PNG, JPEG, or KTX2 image bytes (max 16 MiB). |
text(text) | |
collider(collider) | |
collider-vertices(list<f32>) | Packed XYZ vertex positions (max 4 MiB). |
collider-indices(list<u32>) | Triangle indices into collider-vertices (max 4 MiB). |
rigid-body(rigid-body) | |
gravity-scale(f32) | Gravity multiplier (defaults to 1.0). |
sky(color) | Space sky color (at minimum its hue is applied). |
portal(portal) | |
spawn(spawn) | |
relation(tuple<relation, prim-id>) | |
custom(tuple<string, list<u8>>) | Opaque application data under group/field outside reserved host groups (max 64 KiB). Stored and replicated without host interpretation. |
property-key
Property key without a value.
parent | |
name | |
transform | |
reference | |
mesh-topology | |
mesh-vertices(vertex-attribute) | |
mesh-indices | |
material | |
image-sampler | |
image-data | |
text | |
collider | |
collider-vertices | |
collider-indices | |
rigid-body | |
gravity-scale | |
sky | |
portal | |
spawn | |
relation(relation) | |
custom(string) |
Interface document
Uses transform, document-id, prim-id, prim-ref, error, property, property-key.
layer
Target ephemeral layer for edits. Neither layer is durable until committed.
local | Local to this peer; discarded when the document unloads. Use for deterministic script state that every peer computes identically. |
shared | Replicated live to peers in the space for the current session. Each peer has its own session layer. The author's layer can modify any property; other peers' layers only affect state group properties and portal pairing (if trusted). Relations cannot be written to shared. |
edit
set(tuple<prim-id, property>) | Sets a property on an existing prim. Setting parent reparents the prim (cycles are rejected). |
clear(tuple<prim-id, property-key>) | Clears a property in the target layer. In local, weaker layers show through; in shared, an explicit absence is recorded for the session, masking weaker layers. Cannot clear parent (use remove). |
remove(prim-id) | Removes a prim and its descendants from the scene. |
layer-source
Layer supplying a property's resolved value.
document | Durable document layer. |
override | Override from a referencing document. |
runtime | Local peer's local layer. |
own-session | Local peer's shared session layer. |
session(string) | Another peer's shared session layer, identified by endpoint ID. |
anchor
Parent anchor for a placed document.
space | Root of the active space. |
prim(prim-ref) | Prim in any loaded document. |
document
Handle to a loaded document. Writes fail with forbidden if may-write
is false.
id
id: func() -> document-idmay-write
may-write: func() -> boolReturns whether the script can write this document (its own, one it created, or one by the same author).
contains
contains: func(prim: prim-id) -> boolReturns whether prim exists in the document.
roots
roots: func() -> list<prim-id>Root prims (no parent), ordered by ID.
prims
prims: func() -> list<prim-id>All prims in the document in arbitrary order.
children
Direct children of prim, ordered by ID.
find-by-name
find-by-name: func(name: string) -> list<prim-id>All prims whose name matches name exactly.
get
get: func(prim: prim-id, key: property-key) -> option<property>Resolved property value from the strongest layer. For transform, this
is the authored value rather than live physics motion (see
world-transform).
get-many
get-many: func(keys: list<tuple<prim-id, property-key>>) -> list<option<property>>Batched get, returning results in input order.
keys
keys: func(prim: prim-id) -> list<property-key>All property keys set on prim.
source
source: func(prim: prim-id, key: property-key) -> option<layer-source>Layer supplying the resolved value of key on prim, or none if
unset.
world-transform
Live transform of prim this frame (including physics and animation) in
the calling script's document frame. Returns not-ready before the
prim's first rendered frame.
offset-to
Transform from this document's root to other's root, or none if
either is unplaced.
world-frame
world-frame: func() -> option<transform>Transform from the calling script's document root to the engine world,
or none if unplaced. Used when converting transforms for placement into
another document.
site
site: func() -> option<prim-ref>Referencing prim that instantiated this document, or none.
create-prim
Creates a new prim under parent (or as a root) in layer.
apply
Applies up to 4096 edits atomically to layer. In local, referencing
a missing prim fails the entire batch with not-found.
commit
commit: func(keys: list<tuple<prim-id, property-key>>) -> result<_, error>Persists the resolved values of keys to the durable document layer (or
as overrides in the referencing document). Fails with forbidden if
neither is writable.
Executes only on the peer authoring the script's document; on other peers in a space it succeeds as a no-op so durable writes happen once.
place
Places or moves the document at offset relative to anchor (local
only, not persisted). Created documents stay hidden until placed.
Fails with invalid-argument if offset contains non-finite values or
any zero scale component.
script-document
Returns the calling script's own document.
script-prim
script-prim: func() -> prim-idReturns the prim the calling script is attached to.
open-document
open-document: func(id: document-id) -> result<option<document>, error>Opens a loaded document by ID, or returns none if not loaded.
create-document
Creates an empty writable document (hidden until place is called).
copy-document
Creates an independent copy of source's durable entries (excluding live
layers).
delete-document
Removes a script-created document from the scene and deletes the local copy.
Source
/// Scene documents, prims, and their properties.
///
/// A document is a tree of prims identified by stable IDs, with all data
/// attached as properties. Each property resolves across layered values,
/// strongest first:
///
/// - `shared`: per-peer session writes (author's layer takes precedence).
/// - `local`: local runtime writes visible only on this peer.
/// - Document layer: durable entries written via `commit`.
///
/// A script can read any loaded document it opens, and can write its own
/// document, documents it created, and documents authored by the same user.
package wired:scene;
/// Built-in properties that can be attached to a prim.
interface properties {
use wired:core/math.{vec2, vec3, transform, color};
use wired:core/ids.{document-id, prim-id};
/// Primitive assembly mode for a mesh.
enum topology {
point-list,
line-list,
line-strip,
triangle-list,
triangle-strip,
}
/// Per-vertex mesh attribute and its float component count.
enum vertex-attribute {
/// 3 floats in prim-local space (required to render).
position,
/// 3 floats, unit length.
normal,
/// 4 floats: unit tangent plus bitangent sign.
tangent,
/// 4 floats, linear RGBA.
color,
/// 2 floats.
uv0,
/// 2 floats.
uv1,
}
record vertex-stream {
attribute: vertex-attribute,
/// Packed vertex components; all streams on a mesh must share the same
/// vertex count. Max 4 MiB.
values: list<f32>,
}
enum alpha-mode {
opaque,
/// Discards fragments below `alpha-cutoff`.
mask,
blend,
add,
multiply,
premultiplied,
}
/// Standard PBR material. Unset fields use renderer defaults; textures are
/// attached via `relation`.
record material {
base-color: option<color>,
/// Emissive color in linear RGB (alpha ignored).
emissive: option<color>,
/// 0..1.
metallic: option<f32>,
/// 0..1.
roughness: option<f32>,
alpha-mode: option<alpha-mode>,
alpha-cutoff: option<f32>,
double-sided: option<bool>,
}
/// Texture wrapping mode outside 0..1 UVs.
enum address-mode {
repeat,
mirror-repeat,
clamp-to-edge,
}
enum filter-mode {
linear,
nearest,
}
/// Texture sampling parameters for a prim carrying `image-data`.
record image-sampler {
address-mode-u: option<address-mode>,
address-mode-v: option<address-mode>,
address-mode-w: option<address-mode>,
mag-filter: option<filter-mode>,
min-filter: option<filter-mode>,
mipmap-filter: option<filter-mode>,
/// Interpret image as sRGB color (`true`, default) or linear data such as
/// a normal map (`false`).
srgb: option<bool>,
}
/// Capsule aligned with the prim's Y axis, centered on its origin.
record collider-capsule {
/// Cylinder height between the two hemispherical caps.
height: f32,
radius: f32,
}
/// Cylinder aligned with the prim's Y axis, centered on its origin.
record collider-cylinder {
height: f32,
radius: f32,
}
/// Collision shape in prim-local space.
variant collider {
capsule(collider-capsule),
/// Convex hull computed from `collider-vertices`.
convex-hull,
/// Box with full extents, centered on the origin.
cuboid(vec3),
cylinder(collider-cylinder),
/// Sphere with the given radius.
sphere(f32),
/// Triangle mesh from `collider-vertices` and `collider-indices`.
trimesh,
}
enum rigid-body-kind {
/// Driven by forces and collisions.
dynamic,
/// Driven by transform writes; pushes dynamic bodies.
kinematic,
/// Immovable.
%static,
}
/// Enables physics simulation for the prim's collider. Unset fields use
/// simulation defaults.
record rigid-body {
kind: rigid-body-kind,
/// Mass in kilograms.
mass: option<f32>,
friction: option<f32>,
/// Bounciness: `0` for inelastic, `1` for perfectly elastic.
restitution: option<f32>,
linear-damping: option<f32>,
angular-damping: option<f32>,
}
/// 128-bit pairing token shared by both halves of a two-way portal.
type link-id = tuple<u64, u64>;
record portal-destination {
/// Target space document ID.
space: document-id,
/// Pairing token for a two-way portal; `none` creates a one-way portal.
link: option<link-id>,
}
/// Rectangular portal window in the prim's XY plane, facing +Z.
record portal {
width: f32,
height: f32,
destination: option<portal-destination>,
}
/// Spawn region; arriving peers appear at a random XZ point within `radius`.
record spawn {
radius: f32,
}
enum text-align {
left,
center,
right,
}
/// Vertical anchor line aligned to the prim's origin.
enum text-anchor {
baseline,
top,
middle,
bottom,
}
enum text-billboard {
none,
/// Rotates around Y to face the viewer while staying upright.
yaw,
/// Rotates fully to face the viewer.
full,
}
/// Plain text rendered in the prim's XY plane along +X (no markup).
record text {
/// Text content (max 4 KiB).
value: string,
/// Em height in meters.
size: option<f32>,
align: option<text-align>,
anchor: option<text-anchor>,
/// Line wrap width in meters; `none` wraps only on newlines.
wrap: option<f32>,
/// Multiplier on the font's default line spacing.
line-height: option<f32>,
color: option<color>,
/// Outline color drawn behind glyphs.
outline: option<color>,
/// Outline width in ems.
outline-width: option<f32>,
/// Emissive strength (`0` for none).
emissive: option<f32>,
billboard: option<text-billboard>,
}
/// Named reference from one prim to another in the same document.
variant relation {
/// Shader graph authored on another prim.
shader-binding,
base-color-texture,
emissive-texture,
metallic-roughness-texture,
normal-texture,
occlusion-texture,
/// Texture sampled by a shader graph at slot `0..=3`.
shader-texture(u8),
/// Application-defined relation named `group/field` outside reserved host
/// groups.
custom(string),
}
/// Property key paired with its value.
variant property {
/// Parent prim ID, or `none` for a root prim.
parent(option<prim-id>),
/// Prim name (max 1 KiB).
name(string),
/// Local transform relative to the parent (or document root).
transform(transform),
/// Embeds another document under this prim.
reference(document-id),
mesh-topology(topology),
mesh-vertices(vertex-stream),
/// Vertex indices (max 4 MiB).
mesh-indices(list<u32>),
material(material),
image-sampler(image-sampler),
/// Encoded PNG, JPEG, or KTX2 image bytes (max 16 MiB).
image-data(list<u8>),
text(text),
collider(collider),
/// Packed XYZ vertex positions (max 4 MiB).
collider-vertices(list<f32>),
/// Triangle indices into `collider-vertices` (max 4 MiB).
collider-indices(list<u32>),
rigid-body(rigid-body),
/// Gravity multiplier (defaults to `1.0`).
gravity-scale(f32),
/// Space sky color (at minimum its hue is applied).
sky(color),
portal(portal),
spawn(spawn),
relation(tuple<relation, prim-id>),
/// Opaque application data under `group/field` outside reserved host groups
/// (max 64 KiB). Stored and replicated without host interpretation.
custom(tuple<string, list<u8>>),
}
/// Property key without a value.
variant property-key {
parent,
name,
transform,
reference,
mesh-topology,
mesh-vertices(vertex-attribute),
mesh-indices,
material,
image-sampler,
image-data,
text,
collider,
collider-vertices,
collider-indices,
rigid-body,
gravity-scale,
sky,
portal,
spawn,
relation(relation),
custom(string),
}
}
interface document {
use wired:core/math.{transform};
use wired:core/ids.{document-id, prim-id, prim-ref};
use wired:core/error.{error};
use properties.{property, property-key};
/// Target ephemeral layer for edits. Neither layer is durable until committed.
enum layer {
/// Local to this peer; discarded when the document unloads. Use for
/// deterministic script state that every peer computes identically.
local,
/// Replicated live to peers in the space for the current session.
///
/// Each peer has its own session layer. The author's layer can modify any
/// property; other peers' layers only affect `state` group properties and
/// portal pairing (if trusted). Relations cannot be written to `shared`.
shared,
}
variant edit {
/// Sets a property on an existing prim. Setting `parent` reparents the prim
/// (cycles are rejected).
set(tuple<prim-id, property>),
/// Clears a property in the target layer. In `local`, weaker layers show
/// through; in `shared`, an explicit absence is recorded for the session,
/// masking weaker layers. Cannot clear `parent` (use `remove`).
clear(tuple<prim-id, property-key>),
/// Removes a prim and its descendants from the scene.
remove(prim-id),
}
/// Layer supplying a property's resolved value.
variant layer-source {
/// Durable document layer.
document,
/// Override from a referencing document.
override,
/// Local peer's `local` layer.
runtime,
/// Local peer's `shared` session layer.
own-session,
/// Another peer's `shared` session layer, identified by endpoint ID.
session(string),
}
/// Parent anchor for a placed document.
variant anchor {
/// Root of the active space.
space,
/// Prim in any loaded document.
prim(prim-ref),
}
/// Handle to a loaded document. Writes fail with `forbidden` if `may-write`
/// is `false`.
resource document {
id: func() -> document-id;
/// Returns whether the script can write this document (its own, one it
/// created, or one by the same author).
may-write: func() -> bool;
/// Returns whether `prim` exists in the document.
contains: func(prim: prim-id) -> bool;
/// Root prims (no parent), ordered by ID.
roots: func() -> list<prim-id>;
/// All prims in the document in arbitrary order.
prims: func() -> list<prim-id>;
/// Direct children of `prim`, ordered by ID.
children: func(prim: prim-id) -> list<prim-id>;
/// All prims whose `name` matches `name` exactly.
find-by-name: func(name: string) -> list<prim-id>;
/// Resolved property value from the strongest layer. For `transform`, this
/// is the authored value rather than live physics motion (see
/// `world-transform`).
get: func(prim: prim-id, key: property-key) -> option<property>;
/// Batched `get`, returning results in input order.
get-many: func(keys: list<tuple<prim-id, property-key>>) -> list<option<property>>;
/// All property keys set on `prim`.
keys: func(prim: prim-id) -> list<property-key>;
/// Layer supplying the resolved value of `key` on `prim`, or `none` if
/// unset.
source: func(prim: prim-id, key: property-key) -> option<layer-source>;
/// Live transform of `prim` this frame (including physics and animation) in
/// the calling script's document frame. Returns `not-ready` before the
/// prim's first rendered frame.
world-transform: func(prim: prim-id) -> result<transform, error>;
/// Transform from this document's root to `other`'s root, or `none` if
/// either is unplaced.
offset-to: func(other: borrow<document>) -> option<transform>;
/// Transform from the calling script's document root to the engine world,
/// or `none` if unplaced. Used when converting transforms for placement into
/// another document.
world-frame: func() -> option<transform>;
/// Referencing prim that instantiated this document, or `none`.
site: func() -> option<prim-ref>;
/// Creates a new prim under `parent` (or as a root) in `layer`.
create-prim: func(layer: layer, parent: option<prim-id>) -> result<prim-id, error>;
/// Applies up to 4096 edits atomically to `layer`. In `local`, referencing
/// a missing prim fails the entire batch with `not-found`.
apply: func(layer: layer, edits: list<edit>) -> result<_, error>;
/// Persists the resolved values of `keys` to the durable document layer (or
/// as overrides in the referencing document). Fails with `forbidden` if
/// neither is writable.
///
/// Executes only on the peer authoring the script's document; on other
/// peers in a space it succeeds as a no-op so durable writes happen once.
commit: func(keys: list<tuple<prim-id, property-key>>) -> result<_, error>;
/// Places or moves the document at `offset` relative to `anchor` (local
/// only, not persisted). Created documents stay hidden until placed.
///
/// Fails with `invalid-argument` if `offset` contains non-finite values or
/// any zero scale component.
place: func(anchor: anchor, offset: transform) -> result<_, error>;
}
/// Returns the calling script's own document.
script-document: func() -> result<document, error>;
/// Returns the prim the calling script is attached to.
script-prim: func() -> prim-id;
/// Opens a loaded document by ID, or returns `none` if not loaded.
open-document: func(id: document-id) -> result<option<document>, error>;
/// Creates an empty writable document (hidden until `place` is called).
create-document: func() -> result<document, error>;
/// Creates an independent copy of `source`'s durable entries (excluding live
/// layers).
copy-document: func(source: borrow<document>) -> result<document, error>;
/// Removes a script-created document from the scene and deletes the local
/// copy.
delete-document: func(document: document) -> result<_, error>;
}