# Three-Live & XR-Live Complete LLM Reference (`llms-full.txt`) > Auto-generated from `docs/` and `skills/`. Do not edit by hand; run `node scripts/build_llms_txt.js`. ================================================================================ SOURCE: docs/llm-guide.md ================================================================================ # LLM & Agent Authoring Guide (`three-live` & `xr-live`) This guide is designed for **LLMs, coding assistants, and autonomous agents** generating 3D and Spatial Computing (AR/VR/XR) code with `` and ``. - **Repository Agent Instructions:** [`AGENTS.md`](../AGENTS.md) - **Installable Agent Skills:** - [`skills/three-live-authoring/SKILL.md`](../skills/three-live-authoring/SKILL.md) (building 3D/XR scenes and apps) - [`skills/xr-live-plugin-dev/SKILL.md`](../skills/xr-live-plugin-dev/SKILL.md) (contributing cross-platform traits and plugins) - **Single-File Context Feeds:** [`/llms.txt`](../llms.txt) (concise index) and [`/llms-full.txt`](../llms-full.txt) (complete reference) You can copy the **System Prompt Snippet** below directly into any LLM prompt or agent skill to guarantee valid, zero-hallucination output. -------------------------------------------------------------------------------- ## Copy-Paste System Prompt Snippet for LLMs ```markdown You are authoring 3D and Spatial Computing scenes using Google's `three-live` and `xr-live` web components. ### 1. Choose the Right Component & Bundle - Use `` (`three-live.min.js` or `three-live-full.min.js`) for 3D product viewers, procedural Three.js scenes, `KHR_interactivity` behavior graphs, PBR Next materials, and 1-tap mobile AR handoff (Quick Look / Scene Viewer / WebXR). - Use `` (`xr-live.min.js` or `xr-live-full.min.js`) when the scene requires interactive 6DoF WebXR, declarative spatial traits (`userData.xr`), spatial HTML cards (`
`), depth occlusion & physics (`xr-depth`), 25-joint hand tracking (`xr-hands`), any of the 14 spatial plugins (`head-follow`, `manipulation-handles`, `world-understanding`, `gemini-live`, `spatial-paint`, `depth-particles`, `splat-loader`, `spatial-measure`, `magnetic-snap`, `gaze-dwell`, `exploded-view`, `persistent-anchors`, `spatial-locomotion`, `shared-room`), or any of the 5 `xr-live-sim` simulation plugins (`character-controller`, `steering-agents`, `hit-zones`, `objectives`, `synth-audio`; available in `xr-live-sim.min.js` and `xr-live-full.min.js`). ### 2. Procedural ` ``` ### Template 2: Full Spatial Computing Scene with Extended XR Traits (``) ```html

Spatial Control Panel

Drag corner handles to scale, or pinch in empty space to paint in 3D.

``` ### Template 3: Collaborative CAD Studio (`exploded-view` + `spatial-measure` + `magnetic-snap` + `shared-room`) ```html ``` ================================================================================ SOURCE: skills/three-live-authoring/references/xr-traits-and-plugins.md ================================================================================ # `` & `` Complete Traits, Plugins & Events Reference ## 1. `` Host Attributes `` inherits every `` attribute (`src`, `ios-src`, `poster`, `scale`, `camera-orbit`, `camera-target`, `min-camera-orbit`, `max-camera-orbit`, `field-of-view`, `selected-mesh`, `camera-controls`, `ar`, `ar-modes`, `ar-scale`, `ar-placement`, `script-src`, `sandbox`, `allow-client-scripts`, `exposure`, `environment-image`, `skybox-image`, `shadow-intensity`, `shadow-softness`, `tone-mapping`, `autoplay`, `animation-name`, `auto-rotate`) and adds: Attribute | Values | Default | Description :-------------------- | :--------------------------------------------------------------------------------------------- | :---------- | :---------- `xr-mode` | `'ar' \| 'vr' \| 'inline' \| 'auto'` | `'auto'` | Target WebXR session mode. `xr-depth` | `'occlusion' \| 'occlusion-physics' \| 'mesh' \| 'none'` | `'none'` | Hardware depth occlusion and analytical heightfield physics collision. `xr-hands` | `'gestures' \| 'joints' \| 'pinch' \| 'none'` | `'none'` | 25-joint `XRHand` tracking and gesture classification (`pinch`, `grab`, `point`, `palm-up`). `xr-simulator` | `'living-room' \| 'office' \| 'tabletop' \| 'none'` | `'none'` | Enables the desktop 6DoF keyboard/mouse simulator with room floor/table planes. `xr-profile` | `'quest3' \| 'android-xr' \| 'visionos' \| 'auto'` | `'auto'` | Target hardware profile hint. `sound-feedback` | boolean attribute | `false` | Plays procedural Web Audio earcons (`grab`, `release`, `bounce`, `hover`) on interaction. `world-understanding` | `'' \| 'planes' \| 'planes reticle' \| 'false'` | — | Activates `xr-live-world-understanding` plane/mesh tracking and optional gaze reticle. `spatial-paint` | `'' \| '#rrggbb' \| 'false'` | — | Activates `xr-live-spatial-paint`; pinching in empty space extrudes Catmull-Rom 3D tube strokes. `spatial-measure` | `'' \| 'bounds' \| 'tape' \| 'all' \| 'none'` | — | Activates `xr-live-spatial-measure` 3D dimension callouts and/or interactive AR tape measure. `measure-unit` | `'auto' \| 'm' \| 'cm' \| 'mm' \| 'in' \| 'ft-in'` | `'auto'` | Default display unit for `spatial-measure`. `magnetic-snap` | `'' \| 'grid' \| 'surface' \| 'sockets' \| 'all' \| 'none'` | — | Activates `xr-live-magnetic-snap` socket, grid, surface, and yaw snapping. `snap-grid` | `number` or `'gx gy gz'` (meters) | — | Default Cartesian snap grid spacing in meters. `snap-angle` | `number` (`0..180` degrees) | `0` | Default rotational yaw snap increment in degrees. `gaze-dwell` | `'' \| 'auto' \| 'false' \| 'none'` | — | Activates `xr-live-gaze-dwell` hands-free eye/head gaze reticle and radial dwell selection. `dwell-time` | `number` (`250..10000` ms) | `1200` | Default dwell duration in milliseconds for `gaze-dwell`. `explode` | `number` (`0..1`) | `0` | Normalized multi-part assembly explosion factor (`xr-live-exploded-view`). `explode-mode` | `'radial' \| 'axial-x' \| 'axial-y' \| 'axial-z' \| 'hierarchical'` | `'radial'` | Automatic explosion vector strategy when parts omit `userData.xr.explode.direction`. `explode-scale` | `number` | `1.0` | Multiplier applied to per-part explosion distances. `section-plane` | `'none' \| 'x:' \| 'y:' \| 'z:' \| '-x:' \| '-y:' \| '-z:' \| 'interactive'` | `'none'` | Real-time GPU cross-section clipping plane in scene (model) space (`d` in meters; the cut follows the model through AR placement and turntable rotation) with optional draggable gizmo frame. `persistent-anchors` | `''` or `string` (namespace) | — | Activates `xr-live-persistent-anchors` cross-session transform persistence (`xr-live:anchors:`). `persist-url-hash` | boolean attribute | `false` | Encodes persisted node poses into `#xr-state=` (`<= 8192` bytes) for link sharing. `locomotion` | `'' \| 'teleport' \| 'snap-turn' \| 'smooth' \| 'teleport snap-turn' \| 'none'` | — | Activates `xr-live-spatial-locomotion` parabolic teleportation, snap-turns, or smooth glide. `snap-turn-deg` | `number` (degrees) | `30` | Horizontal thumbstick snap-turn increment in degrees. `comfort-vignette` | boolean attribute | `true` | Shows a `120ms` peripheral FOV comfort vignette during teleports and snap-turns. `shared-room` | `''` or `'wss://...'` | — | Joins a multi-user room via `BroadcastChannel("xr-live:room:")` or a `wss://` relay (`xr-live-shared-room`). `peer-name` | `string` (max `32` chars) | — | Local peer display name broadcast in `shared-room`. `peer-color` | `'#rrggbb'` | `'#38bdf8'` | Local peer 3D visor & laser ray tint color in `shared-room`. `webmcp` | boolean attribute | `false` | Registers `inspect_xr_scene`, `place_xr_object_at_gaze`, and `capture_xr_view` on `navigator.modelContext`. `webmcp-allow-depth` | boolean attribute | `false` | Opt-in gate allowing `capture_xr_view` to include the 8×8 metric `depthGridMeters` array. `webmcp-omit-pose` | boolean attribute | `false` | When present, `inspect_xr_scene` omits `headPosition` entirely. ## 3. Declarative `KHR_interactivity` Authoring (`userData.interactivity`) Any mesh or group inside `

Physics Controls

Grab spheres or bounce them off real-world surfaces.

``` --- ## Recipe 3: Precision Manipulation Handles, Lazy Head-Follow HUD & Orbiting Satellites ```html ``` --- ## Recipe 4: Multimodal Gemini Live Assistant + Hold-to-Ask + World Understanding ```html ``` --- ## Recipe 5: 3D Spatial Paint, Depth Particles & Gaussian Splats ```html ``` --- ## Recipe 6: Native Android (Kotlin) & iOS/visionOS (Swift) Integration ### Android (Google Filament + Jetpack XR SceneCore) ```kotlin import com.google.threelive.ThreeLiveRuntimeSession import com.google.threelive.XRLiveSceneCoreHelper import com.google.threelive.filament.ThreeLiveFilament // 1. Install the Filament renderer once at startup ThreeLiveFilament.install() // 2. Compile procedural Three.js and step XR traits / handles / particles natively val session = ThreeLiveRuntimeSession.fromScript(scriptSource) session.stepFrame(dtSeconds = 1f / 60f) // 3. Or attach traits directly to an Android XR SceneCore entity from GLB bytes XRLiveSceneCoreHelper.attachTraitsFromGlb(xrSession, rootEntity, glbByteBuffer) ``` ### iOS & visionOS (Apple RealityKit) ```swift import ThreeLiveCompiler import RealityKit @MainActor func mountSpatialScene(script: String, in arView: ARView) async throws { let entity = try await RealityKitHelper.loadEntity(from: script) XRLiveRealityKit.installTraits(on: entity, in: arView) } ``` -------------------------------------------------------------------------------- ## Recipe 7: CAD Exploded View, Cross-Section Slicer, 3D Dimensions & Gaze Dwell ```html ``` -------------------------------------------------------------------------------- ## Recipe 8: Magnetic Socket Snapping, `#xr-state` URL Persistence & XR Locomotion ```html ``` -------------------------------------------------------------------------------- ## Recipe 9: Zero-Backend Multi-User Co-Presence & Shared Spatial Paint (`shared-room`) ```html ``` -------------------------------------------------------------------------------- ## Recipe 10: Timed Training Drill with a Safety Zone (`xr-live-sim`) Ordered task steps, a countdown, and an alarm zone around a robot cell. Load `xr-live-sim.min.js` (or use `xr-live-full.min.js`). Taps complete steps in order; out-of-order taps play an `error` cue. ```html ``` ================================================================================ SOURCE: skills/three-live-authoring/references/debugging-and-csp.md ================================================================================ # Debugging, Sandboxing & CSP Guide (`` & ``) ## 1. Why Nothing Renders (Top 4 Causes) 1. **Missing `allow-client-scripts` attribute:** - **Symptom:** `` or `` with an inline ` ``` -------------------------------------------------------------------------------- ## Observed Attributes | Attribute | Type | Bundle | Description | | :--------------------- | :--------- | :------------------- | :------------------ | | `src` | `string` | `three-live-viewer`+ | URL or path to binary `.glb` model. | | `ios-src` | `string` | `three-live-viewer`+ | Optional URL or path to Apple `.usdz` model for iOS Quick Look (auto-transcoded from GLB if omitted). | | `poster` | `string` | `three-live-viewer`+ | URL to a placeholder image shown before 3D rendering initializes. | | `scale` | `string` | `three-live-viewer`+ | Uniform or per-axis scale multiplier `"x y z"` (e.g. `"2 2 2"`). | | `camera-orbit` | `string` (str/JSON) | `three-live-viewer`+ | Initial camera orbit angles and distance\ 20deg 3m"` or `{"theta"\ "phi"\ "zoom"\ | | `camera-target` | `string` | `three-live-viewer`+ | Orbit center coordinate `"x y z"` (e.g. `"0m 1.5m 0m"`, defaults to model bounding center). | | `min-camera-orbit` | `string` | `three-live-viewer`+ | Lower bounds for camera orbit\ `"theta phi radius"` (e.g. `"-45deg 0deg 1m"` or `"auto 0deg auto"`). | | `max-camera-orbit` | `string` | `three-live-viewer`+ | Upper bounds for camera orbit (e.g. `"auto 90deg auto"` prevents orbiting beneath the ground plane). | | `field-of-view` | `string` | `three-live-viewer`+ | Vertical field of view angle (e.g. `"45deg"`, clamps between `10deg` and `90deg`). | | `selected-mesh` | `string` | `three-live-viewer`+ | Name of the sub-mesh to highlight. | | `camera-controls` | `boolean` | `three-live-viewer`+ | Enables interactive orbit/pan/zoom camera controls (disabled by default unless `camera-controls` is present, matching ``). | | `ar` | `boolean` | `three-live-viewer`+ | Enables the augmented reality launcher button. | | `ar-modes` | `string` | `three-live-viewer`+ | Space-delimited AR modes\ `quick-look`, `scene-viewer`, `webxr`. | | `ar-scale` | `string` | `three-live-viewer`+ | Controls whether the model can be scaled in AR\ `"auto"` (default) or `"fixed"`. | | `ar-placement` | `string` | `three-live-viewer`+ | Controls AR surface placement mode\ `"floor"` (default) or `"wall"`. | | `script-src` | `string` | `three-live`+ | URL or path to a server-generated procedural Three.js scene script. | | `sandbox` | `string` | `three-live`+ | Mandatory sandbox mode (`"worker"` or `"iframe"`). Default\ `"worker"`. | | `allow-client-scripts` | `boolean` | `three-live`+ | Explicit opt-in allowing client-modified script strings via `executeScript()` or inline `
Life Support Unit
``` Update a hotspot dynamically at runtime using `viewer.updateHotspot({ name, position, normal })`. ### PBR Rendering & Lighting Extensions - **Core WebGL2 PBR (`three-live-viewer`+):** - **Screen-Space Derivative Normal Maps:** Perturbs normals via GLSL `dFdx`/`dFdy` without requiring glTF vertex tangents. - **Khronos PBR Neutral Tone Mapping:** Accurate color fidelity for e-commerce products without chalky highlight desaturation. - **PBR Next Materials, HDRI & Contact Shadows (`three-live/extras`):** - **glTF PBR Next Extensions:** Shader support for Clearcoat (`KHR_materials_clearcoat`), Transmission (`KHR_materials_transmission`), Dispersion (`KHR_materials_dispersion`), Volume Attenuation (`KHR_materials_volume`), Iridescence (`KHR_materials_iridescence`), and Sheen (`KHR_materials_sheen`). - **HDRI Radiance Maps & Spherical Harmonics:** Set `environment-image="/env/studio.hdr"` to parse Radiance `.hdr` RGBE textures, prefilter GGX specular mipmaps, and project 9-coefficient Spherical Harmonics diffuse irradiance. - **Analytical Ground Contact Shadows:** Set `shadow-intensity="0.7"` and `shadow-softness="0.5"` for soft ground ambient occlusion without shadow map pass overhead. ### Animations: Rigid-Body TRS & Skeletal/Morph Plugins - **Rigid-Body Keyframe Animations (`three-live-viewer`+):** Node translation, rotation, and scale (`TRS`) keyframe tracks are built into all bundles (`el.availableAnimations`, `el.play()`, `el.pause()`). - **GPU Skeletal Skinning, Morph Targets & Cross-Fading (`three-live/animation`):** Import `three-live/animation` (or use `three-live-full.min.js`) to enable 64-joint GPU vertex skinning (`JOINTS_0`/`WEIGHTS_0`), morph target blending (`weights`), and smooth clip cross-fading (`el.crossFadeTo('Walk', 0.3)`). ### Declarative `KHR_interactivity` Behavior Graphs (`userData.interactivity`) Inside `
``` Supported action objects in `onSelect` / `onHoverIn` / `onHoverOut` / `onStart` / `onReceive[eventName]`: - `toggleTransform`: `{ action: 'toggleTransform', property: 'translation' | 'rotation' | 'scale', from?: number[], to: number[], duration?: number }` - `interpolate`: `{ action: 'interpolate', target?: string, property: 'translation' | 'rotation' | 'scale' | 'baseColorFactor' | 'metallicFactor' | 'roughnessFactor' | 'emissiveFactor', to: number | number[], duration?: number }` - `setProperty`: `{ action: 'setProperty', target?: string, property: string, value: unknown }` - `toggleVisibility`: `{ action: 'toggleVisibility', target?: string }` - `cycleMaterialColor`: `{ action: 'cycleMaterialColor', colors: Array<[number, number, number, number?]>, duration?: number }` - `playAnimation` / `stopAnimation`: `{ action: 'playAnimation', animation?: number }` / `{ action: 'stopAnimation' }` - `sendEvent`: `{ action: 'sendEvent', event: string, values?: Record }` (dispatches `interactivityEvent` on the host element). ### Pluggable Mesh & Texture Decoders Heavy decompression runtimes (Draco WASM, Meshopt, KTX2) are not bundled by default. Register external decoders on demand: ```javascript import { ThreeLiveElement } from 'three-live'; ThreeLiveElement.registerDecoder('draco', myDracoDecoder); ``` -------------------------------------------------------------------------------- ## Procedural Scene Scripting (`three-author`) `` supports two procedural scene compilation workflows: 1. **Server-Generated Scene Scripts (Default — `script-src` / `loadScriptFromSrc(url)`):** The client passes a script URL directly to the sandbox (``). The sandbox Worker loads and compiles the script directly via `importScripts` without requiring `'unsafe-eval'` or `new Function()`. 2. **Client-Modified Scene Scripts (Opt-In — `allow-client-scripts` / `ThreeLiveElement.allowClientScripts = true`):** For interactive code editors or client-modified scripts (`el.executeScript(code)` or inline ` ``` ### Security & Sandboxing Architecture Three-Live operates under a **fail-closed** security model for untrusted or AI-generated script execution: - **Isolated Web Worker (default, `sandbox="worker"`):** Scripts run in a dedicated Worker with no DOM access. Before any author code runs, the worker revokes its own ambient authority — `fetch`, `XMLHttpRequest`, `WebSocket`, `EventSource`, `importScripts`, `navigator` (and therefore `sendBeacon`), `indexedDB`, `caches`, `Worker`, `SharedWorker`, `BroadcastChannel`, `SharedArrayBuffer` and `Atomics` are all made permanently `undefined`. The channel back to the host is captured in a closure and `self.postMessage` is replaced with a throwing stub, so a script cannot forge a result message. - **Execution watchdog:** A script that exceeds `SECURITY_3D_SANDBOX_TIMEOUT_MS` (3 s) has its worker terminated and raises an `error` event. At most `SECURITY_3D_MAX_CONCURRENT_TASKS` (32) sandbox workers may be alive at once. - **Quota enforcement:** `Scene.toCanvas3D()`, `toGLB()` and `toUSDZ()` all run `SceneQuotaValidator`, so no serialization path can skip the vertex, index, mesh and texture ceilings. Scripts larger than `SECURITY_3D_MAX_SCRIPT_BYTES` (1 MiB) are rejected before execution. - **Fail-Closed Guarantee & Mandatory Sandboxing:** Sandboxing is strictly required for all live procedural compilation and cannot be bypassed. `sandbox="none"` and `sandbox="unsafe-host-realm"` are prohibited and rejected with a `SecurityError`. If Web Workers or the sandbox iframe are unavailable or blocked by Content Security Policy (CSP), Three-Live **fails closed**: it halts execution, emits an `error` event, and throws rather than evaluating code in the host realm. - **Opaque-Origin Iframe + Worker Isolation (`sandbox="iframe"`):** For hosts enforcing strict CSP (`require-trusted-types-for 'script'`, no `'unsafe-eval'` on the host document), set `sandbox="iframe"` or configure `ThreeLiveElement.sandboxIframeSrc` to point at `three-live-sandbox.html`. Three-Live mounts a hidden `