Frames and links
Updated
Three small components finish a piece of media. A Frame draws a picture frame around an image, a video or a document. An Attribution records who made something and where it came from, so a gallery can credit its artists. A Link turns a button into a hyperlink that opens a web page. None of them costs anything per frame, and each is a single setProps away from a script. This page explains all three and shows how scripts build hover highlights, credit walls and tracked links with them.
Before you start
Section titled “Before you start”- Image surfaces. A Frame wraps the plane an image, video or document draws on. See Images.
- Selection events. The hover and click examples rely on a Selectable and a Signal Emitter on the framed entity. See Input and interaction.
- UI buttons. A Link lives on UI entities. See UI.
A Frame (comp-frame, script class FrameComponent) draws a flat border just outside the edge of its entity’s surface, so it never covers the picture. It follows the surface’s size, including when intrinsic sizing or a new PDF page changes it.
It works on Image, KTX2, SVG, GIF, Lottie, Video and PDF entities. A surface with no flat extent, such as a 360 sphere, has no frame; the frame comes back if the surface becomes planar again.
| Prop | Type | Default | Description |
|---|---|---|---|
src |
string | none | A texture for the frame, such as wood grain. Absent, a flat colour. |
color |
string | '#ffffff' |
The frame colour, or the tint multiplied onto src. |
thickness |
number | 0.05 |
Border width in metres, outward from the surface’s edge. |
gap |
number | 0 |
Space between the surface’s edge and the frame, in metres. The scene shows through it, like a passe-partout cut-out. |
offset |
number | 0.001 |
Distance in front of the surface, so the frame does not flicker against it. |
opacity |
number | 1 |
Overall opacity. Below 1 the frame is drawn transparent. |
side |
'double' | 'front' | 'back' |
'double' |
Which faces are drawn. |
repeat |
number | 1 |
How many times src tiles around the frame. |
An SVG surface is a 1 × 1 box scaled by its entity, so its frame is sized in the same units and scales with it.
Attribution
Section titled “Attribution”An Attribution (comp-attribution, script class AttributionComponent) is information, not a visual: it stores the credit for a work so scripts, and the people who browse the scene, can find it. Images, documents, text and many other entities accept it.
| Prop | Type | Default | Description |
|---|---|---|---|
title |
string | '' |
The work’s title. |
author |
string | '' |
Who made it. |
link |
string | none | Where it comes from: its page, source or licence. |
Each value must be a string; setProps throws a TypeError otherwise.
A Link (comp-link, script class LinkComponent) turns its entity into a hyperlink: pressing it opens url, in a new tab by default. It is offered on UI Button, UI Label, UI Image, UI List Item and UI Avatar entities.
| Prop | Type | Default | Description |
|---|---|---|---|
url |
string | none | The page to open. Empty, the link does nothing. |
target |
'_blank' | '_self' |
'_blank' |
_blank opens a new tab; _self replaces the current page, leaving the experience. |
| Member | What it is |
|---|---|
open() |
Open the link from a script. Does nothing when the component is disabled or url is empty. |
url |
The destination, or undefined when unset. Read-only; change it with setProps. |
target |
Where it opens. Read-only. |
- It opens when the entity is pressed, and stops the press there, so entities behind it are not pressed too.
- It works in play only. In the editor, pressing the entity selects it as usual.
- It refuses
javascript:,vbscript:anddata:URLs, and anything that is not a valid URL. - Popup blockers. A browser may block a new tab that does not directly follow a click or key press. Call
open()from an input handler, not from a timer.
| Event | EventType |
Data | When |
|---|---|---|---|
Link::open |
Event |
{ url } |
The link opened its URL. |
For an entity that cannot carry a Link, such as a framed image, WebBrowser.navigateToURL(url) opens a URL in a new tab from any script. It allows http:, https:, mailto: and tel: addresses.
Examples
Section titled “Examples”1. Highlight a picture on hover
Section titled “1. Highlight a picture on hover”A framed picture whose frame turns gold and thickens while the pointer is over it. The Behavior entity is a child of an Image entity that has a Frame, a Selectable and a Signal Emitter whose signal is artwork.
#pragma lifecycle(startup)
const NORMAL = { color: '#1f2937', thickness: 0.04 };const HOVER = { color: '#d4a017', thickness: 0.07 };
function startup() { const frame = self.parent.getComponent(FrameComponent); frame.setProps(NORMAL);
on('artwork', (event) => { if (event.eventType === EventType.Selectable.Hover) frame.setProps(HOVER); if (event.eventType === EventType.Selectable.Leave) frame.setProps(NORMAL); });}A framed picture whose frame turns gold and thickens while the pointer is over it: an Image with a Frame, a Selectable and a Signal Emitter, restyled by a Behavior script.
Move the pointer over the picture and away. Drag to orbit the camera, scroll to zoom.
- The Selectable sends
Selectable::hoverwhen the pointer arrives andSelectable::leavewhen it goes. The Signal Emitter forwards both onartwork. setPropstakes several props at once, so each state is one object.- Changing a frame is cheap: it rebuilds an 8-triangle mesh.
2. A wall of credits
Section titled “2. A wall of credits”A sign that lists the title and author of every artwork in a gallery. The scene has a group entity named Gallery whose child entities carry Attributions, and a Text entity named Credits.
#pragma lifecycle(startup)
function startup() { const gallery = findEntity('Gallery'); const lines = [];
for (const child of gallery.children) { if (!isEntity(child)) continue; const credit = child.getComponent(AttributionComponent); if (!credit || !credit.props.title) continue; const author = credit.props.author || 'Unknown artist'; lines.push(`${credit.props.title} by ${author}`); }
const credits = findEntity('Credits').getComponent(TextComponent); credits.setProps({ text: lines.length ? lines.join('\n') : 'No credits yet', fontSize: 0.08, maxWidth: 2, textAlign: 'left', anchorX: 'left', anchorY: 'top', });}A small gallery whose pieces carry Attribution components: at start the script reads each title and author and writes them on a credits sign, with "Unknown artist" where no author is set.
Read the credits sign on the right: it was written from the pieces' Attributions. Drag to orbit the camera, scroll to zoom.
gallery.childrenholds the gallery’s direct children.isEntityskips anything that is not an entity, such as a plain object added by a script.getComponentreturnsundefinedwhen the entity has no Attribution, so theifskips uncredited children.- The list is built once, in
startup, and set in onesetPropscall.
3. A tracked ticket button
Section titled “3. A tracked ticket button”A UI button with a Link whose address records which room the visitor came from, and a counter of how many times it opened. Pressing T opens it too. The scene has a UI Button named Tickets Button with a Link and a Signal Emitter whose signal is tickets.
#pragma lifecycle(startup, update)
const BASE = 'https://example.com/tickets';const ROOM = 'lobby';
let link;let opened = 0;
function startup() { link = findEntity('Tickets Button').getComponent(LinkComponent); link.setProps({ url: `${BASE}?from=${ROOM}`, target: '_blank' });
on('tickets', (event) => { if (event.eventType !== EventType.Link.Open) return; opened++; log(`Tickets opened ${opened} time(s): ${event.data.url}`); });}
function update() { if (Input.keyboard.isKeyReleased(Key.T)) link.open();}A UI button with a Link opens a ticket page whose address records the room the visitor came from; pressing T opens it from a script too, and every opening is counted from the Link::open event.
Press the Tickets button, or click the view and press T: the page opens in a new tab (example.com) and the log counts the openings. Drag to orbit the camera, scroll to zoom.
setProps({ url })sets the address at start, so one scene can send different rooms to different pages.Link::openreports every opening, whether from a press on the button or fromopen().open()runs from a key press, which browsers accept as a user gesture.target: '_blank'keeps the experience open in its own tab.
Snippets
Section titled “Snippets”1. Open an artwork’s source on click
Section titled “1. Open an artwork’s source on click”Clicking a framed picture opens the page its Attribution links to. The Behavior entity is a child of an Image entity with an Attribution, a Selectable and a Signal Emitter whose signal is artwork.
#pragma lifecycle(startup)
function startup() { const artwork = self.parent; const credit = artwork.getComponent(AttributionComponent);
on('artwork', (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again if (!credit || !credit.props.link) { log('No source link for this artwork'); return; } WebBrowser.navigateToURL(credit.props.link); });}- A Link is offered only on UI entities, so a framed image opens its page with
WebBrowser.navigateToURLinstead. - The call happens inside the click handler, so the browser treats the new tab as the user’s request rather than a popup.
- The Attribution is the single source of truth: change its
linkin the editor and the click follows.
2. Switch frame styles
Section titled “2. Switch frame styles”A picture that cycles through frame styles (plain black, oak and gilded) each time it is clicked. The Behavior entity is a child of an Image entity with a Frame, a Selectable and a Signal Emitter whose signal is painting.
#pragma lifecycle(startup)
const STYLES = [ { name: 'Black', src: undefined, color: '#111111', thickness: 0.03, gap: 0 }, { name: 'Oak', src: '/assets/textures/oak.jpg', color: '#ffffff', thickness: 0.08, gap: 0, repeat: 4 }, { name: 'Gilded', src: '/assets/textures/gold-leaf.jpg', color: '#ffe8a3', thickness: 0.1, gap: 0.03, repeat: 6 },];
let frame;let index = 0;
function apply() { const { name, ...props } = STYLES[index]; frame.setProps(props); log(`Frame: ${name}`);}
function startup() { frame = self.parent.getComponent(FrameComponent); apply();
on('painting', (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again index = (index + 1) % STYLES.length; apply(); });}src: undefinedremoves the texture: a prop set toundefinedtakes its default, here a flat colour.repeattiles the wood or gold texture around the frame so the grain is not stretched.gapleaves a thin space between the picture and the gilded frame, like a mount.- The
nameis taken out of each style beforesetProps, since it is not a Frame prop.
Common mistakes
Section titled “Common mistakes”- Expecting a frame around a 360 image. A sphere has no edge; the frame appears only on planar surfaces.
- Sizing a frame for an SVG in metres. An SVG is a 1 × 1 box scaled by its entity; its frame scales with it.
- Putting a Link on an image or a mesh. A Link is offered on UI entities. Use
WebBrowser.navigateToURLfrom a click handler elsewhere. - Opening links from a timer. Browsers block new tabs that do not follow a user’s click or key press.
- Setting a number as an Attribution value. Every Attribution value must be a string.
- Using
target: '_self'by accident. It replaces the page and ends the visitor’s session in the world.