Prompt specification
Build or customize the Three.js 3D scene "Backstage Scene Change Diorama" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Backstage Scene Change Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/backstage-scene-change-diorama-x3355
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: backstage scene change diorama. Create a theatre cutaway with flats, wings, and storage positions. Show a bounded scene change whose moving pieces avoid actors and remain hidden from the selected audience view. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (backstage-scene-change-diorama-x3355):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backstage Scene Change — Voxel Theatre Diorama</title>
<style>
:root {
--bg: #090c13;
--panel: rgba(16, 21, 32, 0.9);
--panel-border: rgba(150, 190, 220, 0.18);
--text: #edf5ff;
--muted: #94a8bd;
--cyan: #68e3ff;
--green: #75f0ae;
--amber: #ffc76b;
--red: #ff7185;
--violet: #b29cff;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: absolute;
z-index: 10;
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 14px;
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(14px);
}
#titlePanel {
top: 18px;
left: 18px;
width: min(430px, calc(100vw - 36px));
padding: 16px 18px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.5vw, 29px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
max-width: 390px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#controlPanel {
top: 18px;
right: 18px;
width: 318px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 15px;
}
.section {
padding: 12px 0;
border-bottom: 1px solid rgba(150, 190, 220, 0.11);
}
.section:first-child { padding-top: 0; }
.section:last-child {
padding-bottom: 0;
border-bottom: 0;
}
.section-title {
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.row {
display: flex;
gap: 7px;
flex-wrap: wrap;
}
button {
appearance: none;
border: 1px solid rgba(150, 190, 220, 0.19);
border-radius: 8px;
padding: 8px 10px;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: 150ms ease;
}
button:hover {
border-color: rgba(104, 227, 255, 0.6);
background: rgba(104, 227, 255, 0.11);
}
button.active {
border-color: var(--cyan);
color: #071119;
background: var(--cyan);
}
button.primary {
width: 100%;
color: #071119;
background: var(--cyan);
border-color: var(--cyan);
font-size: 12px;
padding: 10px;
}
.view-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.view-grid .wide {
grid-column: 1 / -1;
}
.status-grid {
display: grid;
gap: 7px;
}
.status-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 12px;
padding: 8px 9px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
font-size: 11px;
}
.status-label { color: var(--muted); }
.status-value {
color: var(--green);
font-weight: 800;
letter-spacing: 0.035em;
text-align: right;
}
.status-value.warn { color: var(--amber); }
.status-value.bad { color: var(--red); }
.status-value.cyan { color: var(--cyan); }
.phase {
margin-top: 8px;
color: var(--amber);
font-size: 11px;
font-weight: 750;
line-height: 1.4;
}
.help {
margin: 8px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
label.toggle {
display: flex;
align-items: center;
gap: 8px;
margin: 7px 0;
color: #c7d5e4;
font-size: 11px;
cursor: pointer;
}
label.toggle input {
accent-color: var(--cyan);
width: 14px;
height: 14px;
}
#timelinePanel {
left: 50%;
bottom: 18px;
width: min(760px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 13px 15px 12px;
}
.timeline-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin-bottom: 9px;
}
#phaseLabel {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.045em;
}
#timeLabel {
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--cyan);
cursor: pointer;
}
.timeline-notes {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 7px;
color: #71869b;
font-size: 9px;
letter-spacing: 0.055em;
text-transform: uppercase;
}
#legend {
left: 18px;
bottom: 18px;
padding: 11px 13px;
color: var(--muted);
font-size: 10px;
line-height: 1.8;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: 0 0 10px currentColor;
}
#loading {
position: absolute;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #090c13;
color: var(--cyan);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 850px) {
#titlePanel {
width: calc(100vw - 36px);
}
#controlPanel {
top: auto;
right: 18px;
bottom: 114px;
width: min(300px, calc(100vw - 36px));
max-height: 48vh;
}
#legend { display: none; }
#timelinePanel {
bottom: 12px;
width: calc(100vw - 24px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel backstage theatre diorama"></canvas>
<section id="titlePanel" class="panel">
<div class="eyebrow">Backstage Systems / Cue 42</div>
<h1>Midnight Garden Scene Change</h1>
<p class="subtitle">
A cutaway voxel theatre showing wing flats, dock storage, actor holding,
travel paths, and an audience sightline protected by a downstage traveler.
</p>
</section>
<section id="controlPanel" class="panel">
<div class="section">
<div class="section-title">Camera</div>
<div class="view-grid">
<button id="overviewBtn" class="wide active">Cutaway Diorama</button>
<button id="centerBtn">Centre Stalls</button>
<button id="leftBtn">Left Stalls</button>
<button id="rightBtn">Right Stalls</button>
</div>
<p class="help">
Drag the diorama to orbit. Scroll to zoom. Audience cameras are fixed
so the selected sightline can be audited accurately.
</p>
</div>
<div class="section">
<div class="section-title">Selected Audience View</div>
<div class="status-grid">
<div class="status-row">
<span class="status-label">Selected seat</span>
<span id="seatValue" class="status-value cyan">Centre stalls</span>
</div>
<div class="status-row">
<span class="status-label">Moving-flat sightline</span>
<span id="sightValue" class="status-value">Revealed</span>
</div>
</div>
</div>
<div class="section">
<div class="section-title">Cue Safety Audit</div>
<div class="status-grid">
<div class="status-row">
<span class="status-label">Motion envelope</span>
<span id="boundsValue" class="status-value">Bounded</span>
</div>
<div class="status-row">
<span class="status-label">Actor clearance</span>
<span id="clearanceValue" class="status-value">—</span>
</div>
<div class="status-row">
<span class="status-label">Flat separation</span>
<span id="flatGapValue" class="status-value">—</span>
</div>
<div class="status-row">
<span class="status-label">Transit visibility</span>
<span id="auditValue" class="status-value">Masked</span>
</div>
</div>
<div id="phase" class="phase">SET / REVEAL COMPLETE</div>
<p class="help">
Moving scenery remains behind the opaque traveler throughout transit.
The final parked set is intentionally visible when the reveal opens.
</p>
</div>
<div class="section">
<div class="section-title">Diagnostic Overlays</div>
<label class="toggle">
<input id="envelopeToggle" type="checkbox" checked>
Show bounded cue envelope
</label>
<label class="toggle">
<input id="pathsToggle" type="checkbox" checked>
Show flat travel paths
</label>
<label class="toggle">
<input id="sightToggle" type="checkbox">
Show selected audience rays
</label>
</div>
</section>
<section id="timelinePanel" class="panel">
<div class="timeline-head">
<span id="phaseLabel">SET / REVEAL COMPLETE</span>
<span id="timeLabel">100% · 0.0 s</span>
</div>
<input id="timeline" type="range" min="0" max="1000" value="1000" step="1"
aria-label="Scene change timeline">
<div class="timeline-notes">
<span>Hold</span>
<span>City flat</span>
<span>Moon flat</span>
<span>Traveler opens</span>
<span>Reveal</span>
</div>
</section>
<div id="legend" class="panel">
<div class="legend-item">
<span class="swatch" style="color:#68e3ff;background:#68e3ff"></span>
Scenery travel route
</div>
<div class="legend-item">
<span class="swatch" style="color:#ffc76b;background:#ffc76b"></span>
Actor quiet hold
</div>
<div class="legend-item">
<span class="swatch" style="color:#75f0ae;background:#75f0ae"></span>
Cue envelope
</div>
</div>
<div id="loading">Building theatre diorama…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
Renderer and scene
--------------------------------------------------------------------------- */
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x090c13);
scene.fog = new THREE.Fog(0x090c13, 25, 52);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const audienceCamera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
80
);
const clock = new THREE.Clock();
const raycaster = new THREE.Raycaster();
const COLORS = {
ink: 0x111722,
stage: 0x303846,
stageEdge: 0xc18b46,
wall: 0x242b38,
trim: 0x59677b,
red: 0x8e3148,
redDark: 0x4e1d31,
redLight: 0xb94c61,
cyan: 0x68e3ff,
green: 0x75f0ae,
amber: 0xffc76b,
violet: 0xb29cff,
blue: 0x5a82bd,
teal: 0x397e83,
gold: 0xf0bc66,
cream: 0xf5e6bd,
wood: 0x805a3e
};
const DECK_TOP = 0.52;
const occluders = [];
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0.02,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true,
side: options.side ?? THREE.FrontSide
});
}
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = `${color}-${options.emissive ?? 0}-${options.emissiveIntensity ?? 0}-${options.opacity ?? 1}`;
if (!materialCache.has(key)) {
materialCache.set(key, standardMaterial(color, options));
}
return materialCache.get(key);
}
function box(w, h, d, color, x, y, z, parent = scene, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
options.material ?? getMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, color = "#bdeeff", width = 2.4, depthTest = true) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
ctx.fillStyle = "rgba(8, 13, 21, 0.86)";
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.beginPath();
ctx.roundRect(5, 8, 502, 112, 18);
ctx.fill();
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "800 38px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.25, 1);
return sprite;
}
function addLabel(text, x, y, z, color = "#bdeeff", width = 2.4, parent = scene) {
const sprite = makeLabel(text, color, width);
sprite.position.set(x, y, z);
parent.add(sprite);
return sprite;
}
function addOutlineRect(x, z, w, d, color, y = DECK_TOP + 0.025, parent = scene) {
const thickness = 0.055;
const material = getMaterial(color, {
emissive: color,
emissiveIntensity: 0.75
});
box(w, 0.025, thickness, material, x, y, z - d / 2, parent, { castShadow: false });
box(w, 0.025, thickness, material, x, y, z + d / 2, parent, { castShadow: false });
box(thickness, 0.025, d, material, x - w / 2, y, z, parent, { castShadow: false });
box(thickness, 0.025, d, material, x + w / 2, y, z, parent, { castShadow: false });
}
function addPath(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.28,
gapSize: 0.16,
transparent: true,
opacity: 0.8,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
scene.add(line);
return line;
}
/* --------------------------------------------------------------------------
Lighting
--------------------------------------------------------------------------- */
scene.add(new THREE.HemisphereLight(0xa7c8ef, 0x241a28, 1.45));
const keyLight = new THREE.DirectionalLight(0xffe3bc, 2.6);
keyLight.position.set(8, 15, -9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 16;
keyLight.shadow.camera.bottom = -14;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x688dff, 1.25);
rimLight.position.set(-10, 8, 8);
scene.add(rimLight);
function addStageSpot(color, x, z, targetX, targetZ) {
const light = new THREE.SpotLight(color, 28, 25, 0.38, 0.52, 1.2);
light.position.set(x, 6.5, z);
light.target.position.set(targetX, 1.5, targetZ);
scene.add(light, light.target);
box(0.38, 0.22, 0.38, 0x202633, x, 6.65, z);
box(0.26, 0.05, 0.26, color, x, 6.51, z, scene, {
emissive: color,
emissiveIntensity: 2.5,
castShadow: false
});
}
addStageSpot(0xffc96f, -4.2, -2.0, -2.7, 1.8);
addStageSpot(0x7ee7ff, 4.2, -2.0, 2.7, 1.8);
addStageSpot(0xb39cff, 0, 4.4, 0, 1.8);
/* --------------------------------------------------------------------------
Theatre architecture
--------------------------------------------------------------------------- */
box(17.2, 0.52, 8.8, COLORS.stage, 0, 0.26, 1.0);
box(17.3, 0.16, 0.22, COLORS.stageEdge, 0, 0.52, -3.35);
box(4.4, 0.52, 8.8, 0x272e3a, -10.9, 0.26, 1.0);
box(4.4, 0.52, 8.8, 0x272e3a, 10.9, 0.26, 1.0);
box(26.2, 0.16, 0.18, COLORS.stageEdge, 0, 0.26, -3.35);
box(26.2, 5.45, 0.34, COLORS.wall, 0, 2.72, 5.55);
box(0.3, 2.15, 8.9, 0x1c2330, -13.0, 1.08, 1.0);
box(0.3, 2.15, 8.9, 0x1c2330, 13.0, 1.08, 1.0);
for (let x = -12; x <= 12; x += 2) {
box(0.06, 4.9, 0.05, 0x394456, x, 2.95, 5.34, scene, { castShadow: false });
}
// Cutaway fly tower and overhead grid.
box(0.26, 5.0, 0.26, 0x424d60, -6.15, 3.0, 4.95);
box(0.26, 5.0, 0.26, 0x424d60, 6.15, 3.0, 4.95);
box(12.6, 0.24, 0.24, 0x424d60, 0, 5.38, 4.95);
box(0.18, 0.18, 8.0, 0x303a4a, 0, 5.38, 1.0);
// Proscenium frame.
box(0.62, 5.25, 0.62, COLORS.redDark, -6.55, 3.15, -2.72);
box(0.62, 5.25, 0.62, COLORS.redDark, 6.55, 3.15, -2.72);
box(13.75, 0.62, 0.68, COLORS.redDark, 0, 5.42, -2.72);
box(0.12, 4.65, 0.12, COLORS.gold, -6.18, 2.95, -3.08);
box(0.12, 4.65, 0.12, COLORS.gold, 6.18, 2.95, -3.08);
box(12.35, 0.12, 0.12, COLORS.gold, 0, 5.05, -3.08);
// Proscenium side legs.
for (const x of [-7.35, 7.35]) {
box(0.8, 4.5, 0.55, COLORS.redDark, x, 2.77, -2.35);
box(0.12, 4.1, 0.12, COLORS.gold, x + (x < 0 ? 0.33 : -0.33), 2.7, -2.65);
}
// Stage grid.
const gridVertices = [];
for (let x = -6; x <= 6; x += 1) {
gridVertices.push(x, DECK_TOP + 0.008, -3.1, x, DECK_TOP + 0.008, 5.25);
}
for (let z = -3; z <= 5; z += 1) {
gridVertices.push(-6, DECK_TOP + 0.008, z, 6, DECK_TOP + 0.008, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute("position", new THREE.Float32BufferAttribute(gridVertices, 3));
scene.add(new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({ color: 0x526071, transparent: true, opacity: 0.35 })
));
// Auditorium floor and stepped seating.
box(17.2, 0.28, 9.0, 0x171c27, 0, -0.14, -7.7);
for (let row = 0; row < 5; row++) {
const z = -5.0 - row * 1.22;
const y = 0.08 + row * 0.16;
box(15.4, 0.18, 1.1, 0x222938, 0, y - 0.18, z);
for (let col = 0; col < 9; col++) {
const x = (col - 4) * 1.53;
if (col === 4 && row < 2) continue;
const seat = new THREE.Group();
seat.position.set(x, y, z);
scene.add(seat);
box(0.68, 0.18, 0.64, COLORS.redDark, 0, 0.22, 0, seat);
box(0.68, 0.76, 0.16, COLORS.red, 0, 0.63, 0.27, seat);
box(0.12, 0.32, 0.12, 0x171c27, -0.22, 0.02, 0, seat);
box(0.12, 0.32, 0.12, 0x171c27, 0.22, 0.02, 0, seat);
}
}
addLabel("AUDIENCE / HOUSE", 0, 1.1, -9.4, "#91a9c3", 3.1);
addLabel("WING L", -7.35, 0.85, -0.2, "#b8c8dc", 1.5);
addLabel("WING R", 7.35, 0.85, -0.2, "#b8c8dc", 1.5);
addLabel("DOCK / STORE", 7.8, 4.45, 4.9, "#68e3ff", 2.7);
addLabel("WING STORE", -7.8, 4.45, 4.9, "#b29cff", 2.7);
// Storage racks.
for (const side of [-1, 1]) {
const x = side * 8.1;
box(0.16, 3.3, 0.16, 0x5a6678, x - 0.9, 2.17, 4.85);
box(0.16, 3.3, 0.16, 0x5a6678, x + 0.9, 2.17, 4.85);
box(2.05, 0.14, 0.75, 0x4b586b, x, 0.68, 4.85);
box(2.05, 0.14, 0.16, 0x5a6678, x, 3.65, 4.85);
}
// Spare stored flats, deliberately muted and outside the active route.
for (let i = 0; i < 4; i++) {
box(0.34, 2.25, 0.2, i % 2 ? 0x3c4554 : 0x485263,
-9.25 + i * 0.48, 1.78, 4.15);
}
for (let i = 0; i < 3; i++) {
box(0.34, 2.0, 0.2, i % 2 ? 0x3d4552 : 0x4b5361,
8.75 + i * 0.5, 1.65, 4.15);
}
// Props, crates, ladder, and tape marks.
box(0.78, 0.72, 0.78, COLORS.wood, -7.55, 0.88, 3.7);
box(0.62, 0.62, 0.62, 0x596274, -7.55, 1.55, 3.7);
box(0.68, 0.68, 0.68, 0x394354, 7.5, 0.86, 3.5);
for (let i = 0; i < 7; i++) {
box(0.08, 0.08, 0.5, 0x5d6878, -5.9, 0.58 + i * 0.48, 4.8);
}
for (let i = 0; i < 7; i++) {
box(0.52, 0.08, 0.08, 0x5d6878, -5.9, 0.58 + i * 0.48, 4.8);
}
const tapeMaterial = getMaterial(COLORS.amber, {
emissive: COLORS.amber,
emissiveIntensity: 0.25
});
for (const [x, z] of [[-4.35, -1.65], [4.1, -1.65], [-0.1, -2.0]]) {
const tape = box(0.7, 0.025, 0.06, tapeMaterial, x, DECK_TOP + 0.02, z, scene, {
castShadow: false
});
tape.rotation.y = Math.PI / 4;
}
/* --------------------------------------------------------------------------
Scenery flats
--------------------------------------------------------------------------- */
function createMoonFlat() {
const group = new THREE.Group();
scene.add(group);
const tile = 0.42;
const cols = 8;
const rows = 7;
const palette = [0x3b7779, 0x4d9690, 0x2d5f68, 0x75a89b];
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
let occupied = false;
if (row <= 4) occupied = col < 2 || col > 5;
else if (row === 5) occupied = col !== 3 && col !== 4;
else occupied = true;
if (!occupied) continue;
const x = (col - (cols - 1) / 2) * tile;
const y = 0.42 + row * tile;
const color = palette[(row + col) % palette.length];
box(tile * 0.93, tile * 0.93, 0.36, color, x, y, 0, group);
}
}
// Golden inner arch voxels.
for (const side of [-1, 1]) {
box(0.16, 1.68, 0.42, COLORS.gold, side * 1.03, 1.28, -0.02, group);
}
box(1.92, 0.16, 0.42, COLORS.gold, 0, 2.13, -0.02, group);
box(3.35, 0.16, 0.82, 0x26313c, 0, 0.11, 0, group);
box(0.34, 0.2, 0.9, 0x161d26, -1.22, 0.08, 0, group);
box(0.34, 0.2, 0.9, 0x161d26, 1.22, 0.08, 0, group);
addLabel("MOON GATE", 0, 3.28, 0, "#f0c879", 2.0, group);
return {
group,
name: "Moon Gate",
w: 3.36,
h: 2.94,
d: 0.82,
start: new THREE.Vector3(6.2, DECK_TOP, 4.0),
end: new THREE.Vector3(-2.65, DECK_TOP, 1.78)
};
}
function createCityFlat() {
const group = new THREE.Group();
scene.add(group);
const tile = 0.42;
const cols = 7;
const rows = 6;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const color = (row + col) % 3 === 0 ? 0x394a70 : (row + col) % 3 === 1 ? 0x52658f : 0x29395b;
const x = (col - 3) * tile;
const y = 0.42 + row * tile;
box(tile * 0.94, tile * 0.94, 0.34, color, x, y, 0, group);
if ((row + col) % 2 === 0 && row < 4) {
box(0.12, 0.16, 0.04, COLORS.gold, x, y, -0.19, group, {
emissive: COLORS.gold,
emissiveIntensity: 1.1,
castShadow: false
});
}
}
}
box(2.95, 0.16, 0.82, 0x26313c, 0, 0.11, 0, group);
box(0.34, 0.2, 0.9, 0x161d26, -1.08, 0.08, 0, group);
box(0.34, 0.2, 0.9, 0x161d26, 1.08, 0.08, 0, group);
addLabel("CITY FLAT", 0, 2.85, 0, "#9dc7ff", 1.9, group);
return {
group,
name: "City Flat",
w: 2.94,
h: 2.52,
d: 0.82,
start: new THREE.Vector3(-6.2, DECK_TOP, 2.65),
end: new THREE.Vector3(2.72, DECK_TOP, 2.0)
};
}
const moonFlat = createMoonFlat();
const cityFlat = createCityFlat();
const cityCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-6.2, DECK_TOP, 2.65),
new THREE.Vector3(-4.8, DECK_TOP, 2.78),
new THREE.Vector3(-1.0, DECK_TOP, 2.78),
new THREE.Vector3(1.1, DECK_TOP, 2.36),
new THREE.Vector3(2.72, DECK_TOP, 2.0)
], false, "centripetal");
const moonCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(6.2, DECK_TOP, 4.0),
new THREE.Vector3(5.55, DECK_TOP, 3.9),
new THREE.Vector3(3.1, DECK_TOP, 3.52),
new THREE.Vector3(0.0, DECK_TOP, 3.0),
new THREE.Vector3(-2.65, DECK_TOP, 1.78)
], false, "centripetal");
const cityPath = addPath(cityCurve.getPoints(80), COLORS.violet);
const moonPath = addPath(moonCurve.getPoints(80), COLORS.cyan);
addOutlineRect(-6.2, 2.65, 3.3, 1.2, COLORS.violet);
addOutlineRect(6.2, 4.0, 3.7, 1.2, COLORS.cyan);
addOutlineRect(-2.65, 1.78, 3.7, 1.2, COLORS.cyan);
addOutlineRect(2.72, 2.0, 3.3, 1.2, COLORS.violet);
/* --------------------------------------------------------------------------
Actors in quiet holding positions
--------------------------------------------------------------------------- */
function createActor(x, z, costume, hair, number) {
const group = new THREE.Group();
group.position.set(x, DECK_TOP, z);
scene.add(group);
box(0.22, 0.17, 0.43, 0x171c25, -0.18, 0.09, -0.03, group);
box(0.22, 0.17, 0.43, 0x171c25, 0.18, 0.09, -0.03, group);
box(0.17, 0.58, 0.2, 0x26303f, -0.18, 0.43, 0, group);
box(0.17, 0.58, 0.2, 0x26303f, 0.18, 0.43, 0, group);
box(0.63, 0.69, 0.38, costume, 0, 1.02, 0, group);
box(0.16, 0.63, 0.18, costume, -0.41, 0.97, 0, group);
box(0.16, 0.63, 0.18, costume, 0.41, 0.97, 0, group);
box(0.39, 0.39, 0.37, 0xe4b895, 0, 1.57, 0, group);
box(0.43, 0.12, 0.4, hair, 0, 1.8, 0.015, group);
box(0.31, 0.1, 0.08, hair, 0, 1.73, -0.2, group);
addOutlineRect(x, z, 1.15, 1.0, COLORS.amber);
addLabel(`ACTOR ${number} / QUIET`, x, 2.24, z, "#ffc76b", 1.6);
return {
group,
name: `Actor ${number}`,
w: 0.92,
h: 1.9,
d: 0.5
};
}
const actors = [
createActor(-4.35, -1.65, 0x5e7fa7, 0x382a24, 1),
createActor(4.1, -1.65, 0x8a4e6e, 0x17141a, 2),
createActor(-0.1, -2.0, 0x4d8876, 0x9b623f, 3)
];
/* --------------------------------------------------------------------------
Downstage masking traveler
--------------------------------------------------------------------------- */
function createTravelerHalf(side) {
const group = new THREE.Group();
group.position.z = 0.44;
scene.add(group);
const width = 8.2;
const height = 4.6;
const depth = 0.36;
const panel = box(
width, height, depth,
side < 0 ? COLORS.redDark : 0x582039,
0, height / 2, 0,
group,
{ roughness: 0.94 }
);
occluders.push(panel);
for (let x = -3.65; x <= 3.65; x += 0.46) {
box(
0.17, height - 0.08, 0.1,
side < 0 ? COLORS.red : COLORS.redLight,
x, height / 2, -0.23,
group,
{ roughness: 0.96 }
);
}
box(width, 0.18, 0.52, 0x301723, 0, height - 0.04, -0.04, group);
box(width, 0.14, 0.5, 0x23131b, 0, 0.07, -0.04, group);
return { group, width, height, depth };
}
const travelerLeft = createTravelerHalf(-1);
const travelerRight = createTravelerHalf(1);
box(25.8, 0.18, 0.22, 0x4c5668, 0, 5.18, 0.44);
addLabel("MASK TRAVELER", 0, 4.86, 0.18, "#d590a0", 2.4);
// Proscenium also counts as a legitimate sightline occluder.
const portalOccluders = [];
for (const x of [-6.55, 6.55]) {
portalOccluders.push(
box(0.62, 5.25, 0.62, COLORS.redDark, x, 3.15, -2.72)
);
}
portalOccluders.push(
box(13.75, 0.62, 0.68, COLORS.redDark, 0, 5.42, -2.72)
);
occluders.push(...portalOccluders);
/* --------------------------------------------------------------------------
Cue envelope and diagnostic overlays
--------------------------------------------------------------------------- */
const cueBounds = {
min: new THREE.Vector3(-13.0, DECK_TOP, 0.10),
max: new THREE.Vector3(13.0, 5.32, 4.55)
};
const envelopeGeometry = new THREE.BoxGeometry(
cueBounds.max.x - cueBounds.min.x,
cueBounds.max.y - cueBounds.min.y,
cueBounds.max.z - cueBounds.min.z
);
const envelope = new THREE.LineSegments(
new THREE.EdgesGeometry(envelopeGeometry),
new THREE.LineBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
envelope.position.set(
(cueBounds.min.x + cueBounds.max.x) / 2,
(cueBounds.min.y + cueBounds.max.y) / 2,
(cueBounds.min.z + cueBounds.max.z) / 2
);
scene.add(envelope);
const rayPositions = new Float32Array(2 * 18 * 3);
const rayGeometry = new THREE.BufferGeometry();
rayGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rayPositions, 3).setUsage(THREE.DynamicDrawUsage)
);
const rayMaterial = new THREE.LineBasicMaterial({
color: COLORS.green,
transparent: true,
opacity: 0.35,
depthTest: false,
depthWrite: false
});
const audienceRays = new THREE.LineSegments(rayGeometry, rayMaterial);
audienceRays.renderOrder = 20;
audienceRays.visible = false;
scene.add(audienceRays);
/* --------------------------------------------------------------------------
Cue state
--------------------------------------------------------------------------- */
const state = {
t: 1,
playing: false,
duration: 5.8,
cameraMode: "overview",
audienceIndex: 0,
showEnvelope: true,
showPaths: true,
showRays: false
};
const audienceViews = [
{
name: "Centre stalls",
position: new THREE.Vector3(0, 2.85, -11.8),
target: new THREE.Vector3(0, 2.1, 1.5)
},
{
name: "Left stalls",
position: new THREE.Vector3(-3.4, 2.85, -11.35),
target: new THREE.Vector3(0.25, 2.1, 1.6)
},
{
name: "Right stalls",
position: new THREE.Vector3(3.4, 2.85, -11.35),
target: new THREE.Vector3(-0.25, 2.1, 1.6)
}
];
function clamp01(v) {
return Math.min(1, Math.max(0, v));
}
function ease(v) {
const x = clamp01(v);
return x * x * (3 - 2 * x);
}
function cueProgress(t) {
return {
city: ease((t - 0.08) / 0.40),
moon: ease((t - 0.35) / 0.39),
traveler: ease((t - 0.79) / 0.19)
};
}
function applyState(t) {
const p = cueProgress(t);
cityFlat.group.position.copy(cityCurve.getPointAt(p.city));
moonFlat.group.position.copy(moonCurve.getPointAt(p.moon));
travelerLeft.group.position.x = -4.1 - p.traveler * 4.6;
travelerRight.group.position.x = 4.1 + p.traveler * 4.6;
}
function phaseFor(t) {
const p = cueProgress(t);
if (t < 0.08) return "HOLD / TRAVELER CLOSED";
if (p.city < 0.995) return "CITY FLAT / WING TO SET";
if (p.moon < 0.995) return "MOON FLAT / DOCK TO SET";
if (p.traveler < 0.995) return "TRAVELER OPENING / REVEAL";
return "SET / REVEAL COMPLETE";
}
function movingPieceAt(t) {
const p = cueProgress(t);
return {
cityMoving: p.city < 0.995,
moonMoving: p.moon < 0.995
};
}
/* --------------------------------------------------------------------------
Geometric safety validation
--------------------------------------------------------------------------- */
function makeDataBox(data) {
const p = data.group.position;
return new THREE.Box3(
new THREE.Vector3(p.x - data.w / 2, DECK_TOP, p.z - data.d / 2),
new THREE.Vector3(p.x + data.w / 2, DECK_TOP + data.h, p.z + data.d / 2)
);
}
function travelerBox(traveler, x) {
return new THREE.Box3(
new THREE.Vector3(x - traveler.width / 2, DECK_TOP, 0.44 - traveler.depth / 2),
new THREE.Vector3(x + traveler.width / 2, DECK_TOP + traveler.height, 0.44 + traveler.depth / 2)
);
}
function boxGap(a, b) {
const dx = Math.max(a.min.x - b.max.x, b.min.x - a.max.x, 0);
const dy = Math.max(a.min.y - b.max.y, b.min.y - a.max.y, 0);
const dz = Math.max(a.min.z - b.max.z, b.min.z - a.max.z, 0);
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
function withinBounds(box) {
return (
box.min.x >= cueBounds.min.x &&
box.max.x <= cueBounds.max.x &&
box.min.y >= cueBounds.min.y &&
box.max.y <= cueBounds.max.y &&
box.min.z >= cueBounds.min.z &&
box.max.z <= cueBounds.max.z
);
}
function validateCue() {
let bounded = true;
let minActorClearance = Infinity;
let minFlatGap = Infinity;
const samples = 140;
for (let i = 0; i <= samples; i++) {
const t = i / samples;
applyState(t);
const cityBox = makeDataBox(cityFlat);
const moonBox = makeDataBox(moonFlat);
const leftBox = travelerBox(travelerLeft, travelerLeft.group.position.x);
const rightBox = travelerBox(travelerRight, travelerRight.group.position.x);
for (const movingBox of [cityBox, moonBox, leftBox, rightBox]) {
if (!withinBounds(movingBox)) bounded = false;
}
for (const actor of actors) {
const actorBox = makeDataBox(actor);
minActorClearance = Math.min(
minActorClearance,
boxGap(cityBox, actorBox),
boxGap(moonBox, actorBox),
boxGap(leftBox, actorBox),
boxGap(rightBox, actorBox)
);
}
minFlatGap = Math.min(
minFlatGap,
boxGap(cityBox, moonBox),
boxGap(cityBox, leftBox),
boxGap(cityBox, rightBox),
boxGap(moonBox, leftBox),
boxGap(moonBox, rightBox)
);
}
applyState(state.t);
return {
bounded,
minActorClearance,
minFlatGap
};
}
/* --------------------------------------------------------------------------
Audience visibility audit using actual Three.js raycasts
--------------------------------------------------------------------------- */
function flatAuditPoints(data) {
const p = data.group.position;
const points = [];
for (const x of [-data.w / 2, 0, data.w / 2]) {
for (const y of [0.12, data.h]) {
for (const z of [-data.d / 2, data.d / 2]) {
points.push(new THREE.Vector3(p.x + x, DECK_TOP + y, p.z + z));
}
}
}
points.push(new THREE.Vector3(p.x, DECK_TOP + data.h * 0.5, p.z));
return points;
}
function targetIsVisible(point) {
const origin = audienceCamera.position;
const direction = point.clone().sub(origin);
const distance = direction.length();
direction.normalize();
raycaster.set(origin, direction);
raycaster.near = 0;
raycaster.far = Math.max(0, distance - 0.04);
const hits = raycaster.intersectObjects(occluders, false);
return hits.length === 0;
}
function auditTransitVisibility() {
const savedT = state.t;
let exposedSamples = 0;
audienceCamera.position.copy(audienceViews[state.audienceIndex].position);
audienceCamera.lookAt(audienceViews[state.audienceIndex].target);
audienceCamera.updateMatrixWorld(true);
for (let i = 0; i <= 40; i++) {
const t = 0.76 * i / 40;
applyState(t);
scene.updateMatrixWorld(true);
const moving = movingPieceAt(t);
const pieces = [];
if (moving.cityMoving) pieces.push(cityFlat);
if (moving.moonMoving) pieces.push(moonFlat);
let exposed = false;
for (const piece of pieces) {
for (const point of flatAuditPoints(piece)) {
if (targetIsVisible(point)) {
exposed = true;
break;
}
}
if (exposed) break;
}
if (exposed) exposedSamples++;
}
applyState(savedT);
scene.updateMatrixWorld(true);
return exposedSamples;
}
/* --------------------------------------------------------------------------
Camera controls — implemented directly without addons
--------------------------------------------------------------------------- */
const overviewTarget = new THREE.Vector3(0, 1.75, 0.4);
const spherical = new THREE.Spherical(27, 1.02, 2.48);
const currentLook = new THREE.Vector3();
const desiredLook = new THREE.Vector3();
camera.position.set(
overviewTarget.x + spherical.radius * Math.sin(spherical.phi) * Math.sin(spherical.theta),
overviewTarget.y + spherical.radius * Math.cos(spherical.phi),
overviewTarget.z + spherical.radius * Math.sin(spherical.phi) * Math.cos(spherical.theta)
);
currentLook.copy(overviewTarget);
let pointerDown = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (state.cameraMode !== "overview") return;
pointerDown = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown || state.cameraMode !== "overview") return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(spherical.phi - dy * 0.005, 0.35, 1.43);
});
canvas.addEventListener("pointerup", (event) => {
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
});
canvas.addEventListener("wheel", (event) => {
if (state.cameraMode !== "overview") return;
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(spherical.radius + event.deltaY * 0.015, 16, 42);
}, { passive: false });
function setCameraMode(mode) {
state.cameraMode = mode;
document.querySelector("#overviewBtn").classList.toggle("active", mode === "overview");
document.querySelector("#centerBtn").classList.toggle("active", mode === "audience" && state.audienceIndex === 0);
document.querySelector("#leftBtn").classList.toggle("active", mode === "audience" && state.audienceIndex === 1);
document.querySelector("#rightBtn").classList.toggle("active", mode === "audience" && state.audienceIndex === 2);
}
function selectAudience(index) {
state.audienceIndex = index;
document.querySelector("#seatValue").textContent = audienceViews[index].name;
setCameraMode("audience");
updateVisibilityAudit();
}
document.querySelector("#overviewBtn").addEventListener("click", () => setCameraMode("overview"));
document.querySelector("#centerBtn").addEventListener("click", () => selectAudience(0));
document.querySelector("#leftBtn").addEventListener("click", () => selectAudience(1));
document.querySelector("#rightBtn").addEventListener("click", () => selectAudience(2));
/* --------------------------------------------------------------------------
UI
--------------------------------------------------------------------------- */
const timeline = document.querySelector("#timeline");
const playButton = document.createElement("button");
playButton.className = "primary";
timeline.after(playButton);
const resetButton = document.createElement("button");
resetButton.textContent = "Reset cue";
resetButton.style.width = "100%";
resetButton.style.marginTop = "7px";
playButton.after(resetButton);
playButton.addEventListener("click", () => {
if (state.t >= 0.999) {
state.t = 0;
applyState(state.t);
}
state.playing = !state.playing;
updatePlayButton();
});
resetButton.addEventListener("click", () => {
state.t = 0;
state.playing = false;
applyState(state.t);
updatePlayButton();
updateUI();
});
function updatePlayButton() {
playButton.textContent = state.playing
? "Pause scene change"
: state.t >= 0.999
? "Run scene change"
: "Resume scene change";
}
timeline.addEventListener("input", () => {
state.t = Number(timeline.value) / 1000;
state.playing = false;
applyState(state.t);
updatePlayButton();
updateUI();
});
document.querySelector("#envelopeToggle").addEventListener("change", (event) => {
state.showEnvelope = event.target.checked;
envelope.visible = state.showEnvelope;
});
document.querySelector("#pathsToggle").addEventListener("change", (event) => {
state.showPaths = event.target.checked;
cityPath.visible = state.showPaths;
moonPath.visible = state.showPaths;
});
document.querySelector("#sightToggle").addEventListener("change", (event) => {
state.showRays = event.target.checked;
audienceRays.visible = state.showRays && state.cameraMode === "audience";
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
audienceCamera.aspect = window.innerWidth / window.innerHeight;
audienceCamera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
/* --------------------------------------------------------------------------
Status and sightline visualization
--------------------------------------------------------------------------- */
const safety = validateCue();
let transitExposureCount = auditTransitVisibility();
function setStatus(id, text, type = "") {
const element = document.querySelector(id);
element.textContent = text;
element.className = `status-value ${type}`;
}
function updateVisibilityAudit() {
transitExposureCount = auditTransitVisibility();
if (transitExposureCount > 0) {
setStatus("#auditValue", "Exposed", "bad");
} else {
setStatus("#auditValue", "Masked", "");
}
}
function currentSightlineState() {
const p = cueProgress(state.t);
const moving = movingPieceAt(state.t);
if (!moving.cityMoving && !moving.moonMoving) {
if (p.traveler < 0.995) return { state: "Opening", type: "warn" };
return { state: "Revealed", type: "cyan" };
}
audienceCamera.position.copy(audienceViews[state.audienceIndex].position);
audienceCamera.lookAt(audienceViews[state.audienceIndex].target);
audienceCamera.updateMatrixWorld(true);
scene.updateMatrixWorld(true);
const pieces = [];
if (moving.cityMoving) pieces.push(cityFlat);
if (moving.moonMoving) pieces.push(moonFlat);
for (const piece of pieces) {
for (const point of flatAuditPoints(piece)) {
if (targetIsVisible(point)) {
return { state: "Exposed", type: "bad" };
}
}
}
return { state: "Masked", type: "" };
}
function updateRayGeometry() {
if (!state.showRays || state.cameraMode !== "audience") {
audienceRays.visible = false;
return;
}
audienceRays.visible = true;
audienceCamera.position.copy(audienceViews[state.audienceIndex].position);
audienceCamera.lookAt(audienceViews[state.audienceIndex].target);
audienceCamera.updateMatrixWorld(true);
scene.updateMatrixWorld(true);
const moving = movingPieceAt(state.t);
const pieces = [];
if (moving.cityMoving) pieces.push(cityFlat);
if (moving.moonMoving) pieces.push(moonFlat);
let cursor = 0;
for (const piece of pieces) {
for (const point of flatAuditPoints(piece)) {
const visible = targetIsVisible(point);
rayMaterial.color.setHex(visible ? COLORS.red : COLORS.green);
rayPositions[cursor++] = audienceCamera.position.x;
rayPositions[cursor++] = audienceCamera.position.y;
rayPositions[cursor++] = audienceCamera.position.z;
rayPositions[cursor++] = point.x;
rayPositions[cursor++] = point.y;
rayPositions[cursor++] = point.z;
}
}
for (let i = cursor; i < rayPositions.length; i++) rayPositions[i] = 0;
rayGeometry.attributes.position.needsUpdate = true;
rayGeometry.setDrawRange(0, cursor / 3);
}
function updateUI() {
const phase = phaseFor(state.t);
const sight = currentSightlineState();
document.querySelector("#phaseLabel").textContent = phase;
document.querySelector("#phase").textContent = phase;
const seconds = (state.t * state.duration).toFixed(1);
document.querySelector("#timeLabel").textContent =
`${Math.round(state.t * 100)}% · ${seconds} s`;
timeline.value = String(Math.round(state.t * 1000));
setStatus("#boundsValue", safety.bounded ? "Bounded" : "Violation", safety.bounded ? "" : "bad");
setStatus(
"#clearanceValue",
`${safety.minActorClearance.toFixed(2)} m clear`,
safety.minActorClearance >= 0.45 ? "" : "bad"
);
setStatus(
"#flatGapValue",
`${safety.minFlatGap.toFixed(2)} m min`,
safety.minFlatGap >= 0.25 ? "" : "warn"
);
setStatus("#sightValue", sight.state, sight.type);
setStatus(
"#auditValue",
transitExposureCount > 0 ? "Exposed" : "Masked",
transitExposureCount > 0 ? "bad" : ""
);
updateRayGeometry();
}
updatePlayButton();
updateUI();
/* --------------------------------------------------------------------------
Render loop
--------------------------------------------------------------------------- */
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.playing) {
state.t = Math.min(1, state.t + delta / state.duration);
applyState(state.t);
if (state.t >= 1) {
state.playing = false;
updatePlayButton();
}
}
const smoothing = 1 - Math.exp(-delta * 6.5);
if (state.cameraMode === "overview") {
desiredLook.copy(overviewTarget);
const desiredPosition = new THREE.Vector3().setFromSpherical(spherical).add(overviewTarget);
camera.position.lerp(desiredPosition, smoothing);
} else {
const view = audienceViews[state.audienceIndex];
desiredLook.copy(view.target);
camera.position.lerp(view.position, smoothing);
}
currentLook.lerp(desiredLook, smoothing);
camera.lookAt(currentLook);
// Gentle stage-light shimmer during the cue.
const cuePulse = state.playing ? 0.9 + Math.sin(clock.elapsedTime * 7) * 0.1 : 1;
scene.traverse((object) => {
if (object.isSpotLight) object.intensity = 28 * cuePulse;
});
updateUI();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```