Write a visual¶
A visual is a way the scene can look, as a genre is a way it can sound. Ambient, the cloud of glowing orbs, is the
default; Constellation, a still night sky, is the second. A new visual is a module of its own that depends only
on visual-api, and every host draws it: desktop, Android and Android TV, iOS, the web, phone AR, Android XR and the
offline video tool. No host needs code of its own for it.
Start from the template¶
scripts/new-visual.sh tide Tide
./kotlin test -m visual-tide -p jvm
./kotlin run -m desktopApp -- --demo --visual tide
The script copies visual-template to visual-tide, renames its classes and tests, and registers the copy in
project.yaml, shared/module.yaml, shared/src/Visuals.kt and the module lists in CI, scripts/coverage.sh and
AGENTS.md. The template is the least a visual must do, and it builds and tests with the rest of the repository, so it
always matches visual-api.
The contract¶
visual-api holds it, with no Compose:
SceneVisual:id(lowercase, for--visualand settings),name, a one-linedescriptionof how it looks,experimental, andcreate(), which makes a freshVisualInstancefor one scene.VisualInstance: the scene callsonLayoutwhen nodes join, leave or move,onPacketwhen a packet sounds,onTexturewhen the music's texture changes andstepevery frame, all on the audio clock.flatView()andspatialView()each hand back a view that fills aDisplayList.SceneModel: the mesh's facts. Its orbs (one per node, with position, role, hardware, health and signal), edges, pulses and ripples, our own node asanchor, the time of day and the music'sparams.glow,progress,spreadandedgeStrengthread them at the current frame, andreducedMotionsays the viewer asked for less motion.DisplayList: what a view fills. A backdrop gradient with an optional haze, then sprites (soft or crisp), lines and rings, closed into groups withendGroup. A flat view works in pixels, a spatial view in metres around a viewer standing on the anchor (SpatialLayout: x east, y up, north at -z).
The rules¶
- Fill, never allocate. A view's
emitruns every frame on every device, a TV included, so it reuses its scratch objects and allocates nothing on a steady frame. Allocate inonLayoutinstead. - Keep per-node state in the node's slot.
Orb.setVisualState(yourVisual, state)andvisualState(yourVisual). Two visuals hold state at once while one hands over to the other, and the scene drops the leaving one's state after. - Draw only what the handover gives you.
scene.handover.draws(instance, node)says whether a node, its edges, its pulses and its ripples are yours this frame. During a switch each node passes from the old visual to the new at its own moment over four seconds; a visual that ignores this draws every node twice. - Take every color from the brightness level. The backdrop comes from
SceneLight, and every alpha is scaled bylight.dim(scene.minuteOfDay), so the brightness slider, its blackout and the night dimming work the same way they do for Ambient. - Fill both views. A flat view and a spatial view of the same scene; phone AR, Android XR and web XR all draw the
spatial one. If you need a primitive the list lacks, add it to
visual-apiso every host learns it at once. - Honor reduced motion. Size a ripple's ring by
scene.spread(r), not its progress, so it fades in place whilescene.reducedMotionis on, and keep anything that travels or turns toscene.turnScaleof its speed. - Start as a draft.
experimental = truekeeps a visual out of the picker, so only--visual <id>and the tools reach it until it has been seen on real screens.
Tests¶
Copy the template's three: both views draw, the draft flag is set, and 2,000 nodes fill a frame in under 50 ms, a
bound that catches a frame walking every pair of nodes on CI's slowest test build. shared/test/VisualsTest.kt also switches every registered visual to and from Ambient in both views, and shared/test@jvm/visual/SpatialBoundsTest.kt checks that every registered visual's spatial view of a busy mesh stays finite, on or above the floor and within SpatialLayout.REACH_METERS of the viewer's eyes. Expected
values come from the design, never from running the code under test.
Review clips¶
renders a 20 second night clip, a night still and an afternoon still at a bright level, all of the simulated 400 node
mesh from one seed, into build/visual-review/tide/, once for each view. The flat files are the window's scene. The
spatial files are the spatial view as a headset's eye sees it from the anchor, turning once round in the 20 seconds:
the same triangles SpatialMesh builds for Android XR, through a 90 degree pinhole camera (PinholeView) and added
onto the field color as the headset and AR views add them. Attach all six to the PR; they are how a reviewer sees the
visual without building it or owning a headset. Run it for ambient too to compare. The tools take the same choice
on their own as video ... --view spatial.
Brand¶
A visual is part of æther, so the brand rules hold: the lowercase æther wordmark, "Music for the mesh.", calm motion with no cuts, and established Meshtastic terminology (node, channel, packet, hop) in names and descriptions, never invented words. Describe how a visual looks, never what traffic moves it: say "a thin ring goes out when a node is heard", not what kind of packet it was.