Skip to content

Panels ​

createPanel(options) returns {id, canvas, present}. Options default to {widthPixels: 1024, heightPixels: 512, widthMeters: 1.2, interactive: false}. Optional container assigns the panel to an active scene container; omission or 0 keeps root-scene ownership. setPanelContainer transfers it later. Pixel dimensions must be 1–4096; width must be greater than zero and at most 10 meters. Physical height follows the pixel aspect ratio.

The canvas retains its pixels until changed. Draw only when content changes, then call canvas.present() or panel.present() to request a texture upload. Coordinates are pixels with origin at the top left. Color channels are clamped to 0–255.

Canvas methodArguments and behavior
clear(r=0, g=0, b=0, a=255)Fill the canvas.
text(x, y, text, r=255, g=255, b=255, a=255, pixels=32)Draw text; return font/draw success.
measureText(text, pixels=32)Return the width in pixels that text would draw with the panel's font, or null without a usable font. Text with several lines measures as its widest line; empty text is 0.
rect(x, y, width, height, r, g, b, a, fill=false)Outline or filled rectangle.
line(x1, y1, x2, y2, r, g, b, a)Draw a line.
circle(x, y, radius, r, g, b, a, fill=false)Outline or filled circle.
image(x, y, path)Decode/draw an image at native size; return success.
present()Schedule upload of the retained canvas.

Text is UTF-8. x and y place the top left of the first line, and lines are pixels + 4 apart. Use measureText to center, right-align or wrap text.

panelLoadFont(panel, path) stores the chosen font path; font loading occurs when text is drawn. Canvas text defaults to 32 pixels unless supplied explicitly. Font files must exist on the runtime host.

Draw and present a retained canvas with a clickable button: panels.js.

Placement ​

panelSetTransform(panel, mode, x, y, z, options) supports:

ModePosition and orientation
'world'Fixed relative to the scene anchor.
'viewerFacing'Fixed position relative to the anchor, facing the HMD.
'headLocked'HMD-relative position; positive Z places it forward.
'arbitrary'Anchor-relative position and the explicit rotation below.
'object'Follows the object options.objectId, at an offset in that object's frame.

Object placement keeps the panel at (x, y, z) meters from the object, measured along the object's own axes, and turns the panel with the object, as if attached to it. The offset does not change with the object's scale. With viewerFacing: true in the options, the panel keeps that position but turns to face the headset. The panel follows every change to the object, including grabs and physics, after they are applied each frame. It is shown only while both the panel and the object are visible. Removing the object, directly or by disposing its container, detaches the panel: it stays hidden until it is placed again. Object placement requires objectId to name a live object of the same script. viewerFacing must be a boolean and defaults to false. Other modes take no options. Unknown modes, non-finite positions and invalid options throw and leave the placement unchanged.

panelSetRotation(panel, m00, m01, m02, m10, m11, m12, m20, m21, m22) sets the row-major 3×3 rotation used by arbitrary placement. panelSetVisible(panel, visible) changes visibility. removePanel(panel) removes it; its native surface detaches before backing resources are freed. These globals accept either the returned panel object or its numeric ID.

Unchanged panels retain their compositor submission. Uploaded content is submitted once per update, placement is submitted when its computed transform changes, and visibility is submitted on transitions. Head-locked and viewer-facing panels continue following the headset. Content changed while hidden appears when the panel is shown again. Failed submissions are retried automatically.

Compare placement modes, rotation, visibility, removal and a label on a grabbable box: panel-placement.js.

Pointer events ​

The engine's controller laser drives interactive panels, and the trigger clicks them. Events arrive through onInputEvent or pollInputEvents. Match objectId === panel.id and a panel.* type. Hover events are panel.hoverStart, panel.hover, and panel.hoverEnd. Buttons use panel.pointerDown/panel.pointerUp, control: 'left', and down. x and y are canvas pixels from the top left.

The closest hit along the laser wins, whether panel or model, so a panel blocks objects behind it. A press stays on its panel until the trigger is released, and the panel receives panel.pointerUp even if the laser has moved away. Clicks work whether or not setLaserVisible draws the beam. The panel example redraws a button only after a click.

Saving and restoring panels ​

Scene snapshots preserve owned panels, including their lossless retained pixels, size, placement, rotation, visibility, input configuration and font settings. loadSceneContainer / restoreSceneContainer return panels with normal canvas handles, plus panelIds and panelMap for reconnecting script callbacks. See the complete persistence contract for pixel encodings and file/decoded-memory limits. The panel save example demonstrates editing and clicking a restored panel.

Released under the GNU AGPL v3.0 only.