Media
Updated
Media and text are how a world communicates: a poster on a wall, a film on a cinema screen, a menu on a stand, a score over a goal, a credit beside a painting. Use media entities for posters and galleries, screens and backdrops, menus and handouts, signs, labels and titles. Each one shows a single piece of media on a flat plane, or on a sphere around the player for 360 pictures and videos, and works the same in a desktop browser, on a phone and in a headset. MIRA has a dedicated entity for each kind of media (still images, compressed textures, vector graphics, animated GIFs and Lottie animations, video and live streams, PDF documents, flat text and extruded 3D text) and a few small components that finish them with frames, credits and links. This section explains what each one is for, how they load, size and play, and how Behavior scripts swap their content, react to their events and keep them cheap on phones and headsets.
Key concepts
Section titled “Key concepts”Surface. The flat plane (or, for 360 media, the sphere) an image, video or document draws on. It is sized in metres with width and height, and sits in the entity’s local XY plane.
Source. The file a media component shows, set with the src prop: a URL or an asset from the project. Changing src loads the new file; changing other props updates what is already showing.
Shared props. The picture surfaces (Image, KTX2, GIF, Lottie, Video) share the same props: width and height in metres, opacity, color tint, grayscale and zoom, and projection and side for 360 content.
Intrinsic sizing. With sizing: 'auto' (on Image, KTX2, GIF, Video and PDF), width and height become a box and the surface takes the media’s own proportions inside it, so nothing is cropped or stretched. Without it, the surface is exactly the size you give and the media is cropped to fill it.
Projection. planar draws a flat plane; equirectangular draws a sphere for 360 images and videos, seen from inside with side: 'back'.
Playback. GIF, Lottie and video play over time. They have play() and pause() methods, props such as autoplay and repeat, and events that report what actually happened.
Unlit. Images, video and documents show their own colours, untouched by scene lights. Text 3D is the exception: it is lit and can cast shadows.
Events. Media components announce when they are ready (Image::ready, Video::ready, PDF::ready…), when they fail (…::error, with a message) and when playback starts, pauses and ends. As with every component, those events reach scripts only through a Signal Emitter on the same entity.
Streams. A live source of pictures and sound published under a name, such as a player’s camera or frames a script draws. A Media Stream component plays one on a video screen.
How it works
Section titled “How it works”Each media entity is built around one component that holds its settings. An Image entity has an Image component, a Video entity a Video component, and so on. Scripts reach the component with getComponent, read its current settings in props, and change them with setProps:
const poster = findEntity('Poster').getComponent(ImageComponent);poster.setProps({ src: '/assets/poster-night.jpg', sizing: 'auto' });Loading is asynchronous. When a scene starts, it waits behind its loading screen for its images and for the first frame of each video, so the world appears with its pictures in place. A file a script loads later appears when it is ready, and the component sends a ready event (or an error event) through its Signal Emitter. A script that needs to act on the loaded media, for example to read a document’s page count, listens for that event:
on('handout', (event) => { if (event.eventType === EventType.PDF.Ready) log('pages:', event.data.pages);});Animated media only works while it can be seen, and costs work on every frame it plays. A GIF or Lottie on a hidden entity decodes no frames; a video in a scene the player has left is paused, and you should pause videos that are out of sight. Browsers add one rule of their own: a video with sound cannot start until the user has clicked, tapped or pressed a key, so MIRA starts such a video on the next press.
Text works the same way. A Text component lays its letters out in the background, so a script that wants to measure new text first awaits sync(). Text 3D builds solid geometry, which is why it suits short strings that rarely change.
Your first media script
Section titled “Your first media script”This walkthrough builds a poster that shows the next picture when clicked, with a caption underneath.
-
Add an Image entity and name it
Poster. You can leave itssrcempty: the script sets it. -
On
Poster, add a Selectable component, so it can be clicked, and a Signal Emitter with the signalposter, so its events reach scripts. -
Add a Text entity below the poster and name it
Caption. -
Add a Behavior entity anywhere in the scene and give it this script. The file names are the pictures of the live example below; replace them with pictures from your project.
PosterWithCaption.jx #pragma lifecycle(startup)const POSTERS = [{ src: '/example-assets/lemon-decal.png', title: 'Pink Lemon' },{ src: '/example-assets/bang.png', title: 'Bang!' },{ src: '/example-assets/alpha.png', title: 'Starlight' },];let poster;let caption;let index = 0;function show(i) {index = i % POSTERS.length;if (poster.props.src === POSTERS[index].src) {caption.setProps({ text: POSTERS[index].title }); // already showingreturn;}caption.setProps({ text: 'Loading…' });poster.setProps({ src: POSTERS[index].src });}function startup() {poster = findEntity('Poster').getComponent(ImageComponent);caption = findEntity('Caption').getComponent(TextComponent);poster.setProps({ sizing: 'auto', width: 1.6, height: 1.6 });caption.setProps({ fontSize: 0.1, anchorY: 'top' });show(0);on('poster', (event) => {if (event.eventType === EventType.Selectable.Select) {findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it againshow(index + 1);}if (event.eventType === EventType.Image.Ready) caption.setProps({ text: POSTERS[index].title });if (event.eventType === EventType.Image.Error) caption.setProps({ text: 'Picture unavailable' });});} -
Press Play and click the poster. Each click loads the next picture; the caption says “Loading…” until the picture is shown, then its title.
What each part does:
#pragma lifecycle(startup)tells MIRA to callstartuponce when the script starts.findEntity(name).getComponent(Class)finds each component once and keeps it.sizing: 'auto'makes every poster fit a 1.6 m box at its own proportions.- The Signal Emitter on
Posterforwards both the Selectable’s click and the Image’sreadyanderrorevents on the signalposter. One listener handles all three by comparingevent.eventTypewithEventTypeconstants.
Your first media script: clicking an Image shows the next picture, and a Text caption says “Loading…” until the Image reports ready, then the picture’s title.
Click the poster to show the next picture.
Choosing
Section titled “Choosing”| If you want … | Use … | Read |
|---|---|---|
| A photo, poster or 360 panorama from a PNG, JPEG or WebP file | Image | Images |
| Many or large pictures that load fast and stay light on phones and headsets | Image KTX2 | Images |
| A logo or icon that stays sharp at any size | Image SVG | Images |
| A short looping animation, such as an animated sticker or sign, or a loader, badge or confetti | Image GIF, or Lottie for crisp vector animation | Images |
| A 360 photo around the player | Image with projection: 'equirectangular' |
Images |
| A film, a looping backdrop or an HLS stream, on a screen or a 360 sphere | Video | Video and streams |
| A presenter filmed on a green screen | Video with Chroma Key | Video and streams |
| A player’s camera, a shared screen or frames a script draws | Video with Media Stream, and Streams |
Video and streams |
| A menu, handout or slide deck that viewers page through | Documents | |
| Flat, cheap text that changes often: a label, score, timer, name or caption | Text | Text |
| Solid, lit letters with depth for titles and logos | Text 3D | Text |
| A frame around media | Frame | Frames and links |
| Credit for a work | Attribution | Frames and links |
| A button that opens a web page | Link | Frames and links |
Entity types
Section titled “Entity types”Each kind of media is an entity type, with a page of its components, props, events and a first script:
| Entity | Type | What it is |
|---|---|---|
| Image | ent-image | An image on a plane or a 360 sphere. |
| Image GIF | ent-image-gif | An animated GIF surface. |
| Image Ktx2 | ent-image-ktx2 | A GPU-compressed image, fast to load and light on memory. |
| Image SVG | ent-image-svg | A vector SVG image. |
| Lottie | ent-lottie | A Lottie vector animation surface. |
ent-pdf | Shows the pages of a PDF document. | |
| Text | ent-text | Crisp, cheap flat text label in the world. |
| Text 3d | ent-text-3d | Extruded 3D text. |
| Video | ent-video | A video file or HLS stream on a plane or a 360 sphere. |
In scripts
Section titled “In scripts”These globals are the script classes of this section’s components, plus the helpers that work with them: Streams publishes live streams, Fonts registers font files, and Canvas makes canvases a script can draw on and stream.
| Global | What it is |
|---|---|
ImageComponent | A textured image plane (or equirectangular sphere) — the imperative equivalent of drei's <Image>. It builds a plane/sphere plus the shared surface shader (zoom, grayscale, color tint) with object-fit "cover" cropping, so the image fills the plane without distortion regardless of aspect ratio. |
KTX2Component | A GPU-compressed .ktx2 (Basis UASTC/ETC1S) image on a plane (or equirectangular sphere). Transcoded via AssetManager.loadKtx2Texture using the shared, renderer-aware KTX2 loader; the texture is owned/deduped by the AssetManager. Tagged sRGB, as KTX2 surfaces here carry color (not data) maps. |
SVGComponent | |
GIFComponent | An animated-GIF surface, decoded with gifuct-js. It shares the TexturedSurface material (zoom / grayscale / tint + object-fit "cover" cropping, plane or equirectangular sphere) but samples a texture composited from the GIF's per-frame patches (honouring disposal methods). |
LottieComponent | A Lottie/Bodymovin vector-animation surface. It shares the TexturedSurface material (zoom / grayscale / tint + object-fit "cover" cropping, plane or equirectangular sphere) but samples a texture rasterized by dotlottie-web. |
VideoComponent | A video on a plane or a 360° sphere, from src (a file or HLS). A sibling MediaStreamComponent makes it show a live stream instead: the element plays the stream (srcObject), src is not loaded, and repeat, restart and seeking do nothing; size, projection, sound and events are as for a file. A stream captured from a canvas on this page is drawn from that canvas, on the stream's frames. |
ChromaKeyComponent | Makes one color of its entity's video transparent, for green or blue screen footage: Video and UI Video. It patches the video's own material in place, in the editor and in play, so nothing is added to the scene and the video is never reloaded; off or removed, the material is put back. It samples the picture itself, replacing three's map_fragment. Every keyed video shares one GPU program per key variant — a neutral key, edge shrink on or off, the spill channel — and a prop edit only writes uniforms. Nothing runs per frame. |
MediaStreamComponent | Makes its entity's source play a live stream instead of its src: the stream published under stream in the app's stream registry, by a host (a WebRTC client) or a script. An enabled component holds the source even with an empty ID or while waiting for publication. Disabling or removing it returns playback to src. Nothing runs per frame: the registry tells it of a change. |
PDFComponent | |
TextComponent | SDF (signed-distance-field) text via troika-three-text — the imperative equivalent of drei's <Text>. Crisp at any distance and cheap, unlike the extruded geometry of Text3DComponent. This is a spatial, in-scene label; the flat uikit label is UILabelComponent. |
Text3DComponent | Extruded 3D text — the imperative equivalent of drei's <Text3D>. drei's component is React (FontLoader + TextGeometry wrapped in JSX); this ECS builds inner objects imperatively, so we call the same three-stdlib FontLoader / TextGeometry directly. This is the spatial, geometry-based text; the flat uikit label is UILabelComponent — the two are complementary. |
FrameComponent | Draws a flat frame around the planar surface of its host entity — image, ktx2, gif, svg, video or pdf. The frame is a hollow rectangle sitting just outside the surface's bounds, so it never overlaps the media: 8 vertices, 8 triangles, one unlit draw call, and no per-frame work beyond a null check. |
AttributionComponent | Optional credit metadata (title / author / link) attachable to any entity — e.g. a model's author, with a link to its source or license. Purely informational; it carries no runtime behaviour and is not tied to any particular entity or component. |
LinkComponent | Turns an entity into a clickable hyperlink: a pointer click opens LinkProps.url in a new tab (or the current one when target is '_self'). Purely event-driven with no per-frame tick. |
Streams | Live streams by name, for Media Stream components: create(id, { video, audio }) then writeVideoFrame / writeAudioFrame, publish(id, Input.camera.stream()), ids(), has(id), on(id, live => …). Optional RTC: room.state, room.subscribe, room.connect/disconnect, and explicit await room.publish(source) / await room.unpublish(source) for mic, camera and screen. |
Fonts | The app's font families: await Fonts.register(family, url, { weight, label }) for this session, unregister, has(family), families. |
Canvas | Canvases for scripts that draw their own images: labels, minimaps, dynamic textures. |
WebBrowser | Read the browser location and open new tabs. |
Components
Section titled “Components”| Component | Type | What it does |
|---|---|---|
| Attribution | comp-attribution | Credit info: title, author and a link to the source or license. |
| Chroma Key | comp-chroma-key | Makes one color of a video transparent, for green or blue screen footage. |
| Frame | comp-frame | A flat picture frame around a media surface. |
| GIF | comp-gif | An animated GIF surface. |
| Image | comp-image | An image on a plane or a 360 sphere. |
| Ktx2 | comp-ktx2 | A GPU-compressed image, fast to load and light on memory. |
| Link | comp-link | Opens a web link when the entity is clicked. |
| Lottie | comp-lottie | A Lottie vector animation surface. |
| Media Stream | comp-media-stream | Plays a live stream through this entity's sound or video, in place of its file. |
comp-pdf | Shows the pages of a PDF document. | |
| SVG | comp-svg | A vector SVG image. |
| Text | comp-text | Crisp, cheap flat text label in the world. |
| Text 3d | comp-text-3d | Extruded 3D text. |
| Video | comp-video | A video file or HLS stream on a plane or a 360 sphere. |
In this section
Section titled “In this section”| Topic | Description |
|---|---|
| Images | Still, compressed, vector, animated and 360 images: shared props, sizing, playback, events. |
| Video and streams | Video files and HLS, playback rules, green-screen keying and live streams. |
| Documents | PDF pages in the world, page turning and page events. |
| Text | Flat Text and extruded Text 3D, fonts, and efficient updates. |
| Frames and links | Frames around media, credits for works, and links to web pages. |