Prompt specification
Build or customize the Three.js 3D scene "Arrange an Ensemble for Visibility" 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: Arrange an Ensemble for Visibility
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/arrange-an-ensemble-for-visibility-x3304
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows musical instruments and ensemble arrangement. Create a stage layout tool with performers, audience positions, and blocked sight lines. Let users reposition sections and compare visibility while audio remains an optional schematic layer. Voxel style.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Render the ensemble and its positions in the visible canvas. Let users reposition performers and compare which remain visible.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (arrange-an-ensemble-for-visibility-x3304):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vox Hall — Ensemble Visibility Studio</title>
<style>
:root {
color-scheme: dark;
--bg: #0b1017;
--panel: #111923;
--panel-2: #151f2b;
--line: #263344;
--line-soft: #1d2937;
--text: #edf4f7;
--muted: #8fa1b3;
--cyan: #5ee6d2;
--amber: #ffbd66;
--red: #ff6b6b;
--blue: #72a7ff;
--purple: #bc8cff;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
border: 0;
cursor: pointer;
}
.app {
height: 100%;
display: grid;
grid-template-rows: 64px minmax(0, 1fr);
}
.topbar {
display: grid;
grid-template-columns: 260px 1fr 290px;
align-items: center;
border-bottom: 1px solid var(--line);
background: #0e151e;
z-index: 20;
}
.brand {
height: 100%;
display: flex;
align-items: center;
gap: 12px;
padding: 0 18px;
border-right: 1px solid var(--line);
}
.brand-mark {
width: 32px;
height: 32px;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 3px;
align-items: end;
padding: 5px;
border: 1px solid #3b5266;
background: #101a24;
box-shadow: inset 0 0 18px rgba(94, 230, 210, .07);
}
.brand-mark i {
display: block;
background: var(--cyan);
box-shadow: 0 0 8px rgba(94, 230, 210, .32);
}
.brand-mark i:nth-child(1) { height: 35%; }
.brand-mark i:nth-child(2) { height: 70%; }
.brand-mark i:nth-child(3) { height: 100%; }
.brand-mark i:nth-child(4) { height: 55%; }
.brand strong {
display: block;
font-size: 14px;
letter-spacing: .18em;
}
.brand small {
display: block;
color: var(--muted);
font-size: 10px;
letter-spacing: .08em;
margin-top: 3px;
}
.top-center {
display: flex;
justify-content: center;
gap: 8px;
min-width: 0;
}
.chip {
display: inline-flex;
align-items: center;
gap: 7px;
height: 27px;
padding: 0 10px;
border: 1px solid var(--line);
background: #111a24;
color: #b8c6d2;
font-size: 10px;
font-weight: 700;
letter-spacing: .1em;
white-space: nowrap;
}
.chip .dot {
width: 6px;
height: 6px;
background: var(--cyan);
border-radius: 50%;
box-shadow: 0 0 8px var(--cyan);
}
.top-actions {
height: 100%;
border-left: 1px solid var(--line);
display: flex;
align-items: center;
justify-content: flex-end;
padding: 0 14px;
}
.quiet-button,
.primary-button,
.secondary-button {
min-height: 34px;
padding: 0 12px;
border: 1px solid var(--line);
background: #17212d;
color: #d9e5eb;
font-size: 11px;
font-weight: 750;
letter-spacing: .07em;
transition: background .15s, border-color .15s, transform .15s;
}
.quiet-button:hover,
.secondary-button:hover {
background: #1c2936;
border-color: #3b5064;
}
.primary-button {
color: #071411;
background: var(--cyan);
border-color: var(--cyan);
}
.primary-button:hover { background: #83f2e2; }
button:active { transform: translateY(1px); }
.workspace {
min-height: 0;
display: grid;
grid-template-columns: 250px minmax(0, 1fr) 286px;
}
aside {
min-height: 0;
overflow-y: auto;
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #334456 transparent;
z-index: 10;
}
.left-panel {
border-right: 1px solid var(--line);
}
.right-panel {
border-left: 1px solid var(--line);
}
.panel-section {
padding: 17px 16px;
border-bottom: 1px solid var(--line-soft);
}
.section-heading {
margin: 0 0 12px;
color: #d9e5eb;
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.eyebrow {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.scene-list {
display: flex;
flex-direction: column;
gap: 4px;
}
.scene-group-label {
margin: 12px 0 4px;
color: #63778a;
font-size: 9px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
}
.scene-group-label:first-child { margin-top: 0; }
.item-button {
width: 100%;
display: grid;
grid-template-columns: 8px 1fr 16px;
align-items: center;
gap: 9px;
padding: 8px 9px;
text-align: left;
background: transparent;
border: 1px solid transparent;
color: #afbecb;
font-size: 11px;
}
.item-button:hover {
background: #17212c;
color: #edf5f8;
}
.item-button.active {
color: #effcfa;
background: #162b30;
border-color: #2d5557;
}
.item-button .swatch {
width: 7px;
height: 7px;
background: var(--cyan);
box-shadow: 0 0 6px rgba(94, 230, 210, .25);
}
.item-button .drag-mark {
color: #536879;
font-size: 12px;
text-align: center;
}
.layer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 39px;
border-bottom: 1px solid #1a2531;
}
.layer:last-child { border-bottom: 0; }
.layer-name {
font-size: 11px;
color: #cbd8e0;
}
.layer-note {
display: block;
color: #687c8f;
font-size: 9px;
margin-top: 3px;
}
.switch {
position: relative;
width: 34px;
height: 19px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
width: 100%;
height: 100%;
margin: 0;
cursor: pointer;
z-index: 2;
}
.switch span {
position: absolute;
inset: 0;
border: 1px solid #3a4b5d;
background: #202b37;
border-radius: 10px;
transition: .15s;
}
.switch span::after {
content: "";
position: absolute;
width: 13px;
height: 13px;
left: 2px;
top: 2px;
border-radius: 50%;
background: #8093a5;
transition: .15s;
}
.switch input:checked + span {
background: rgba(94, 230, 210, .18);
border-color: #4a9f96;
}
.switch input:checked + span::after {
transform: translateX(15px);
background: var(--cyan);
}
.mini-note {
color: #718598;
font-size: 10px;
line-height: 1.55;
}
.mini-note strong { color: #aebfcd; }
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 44%, rgba(39, 62, 74, .18), transparent 45%),
#0c121a;
}
#canvasHost {
position: absolute;
inset: 0;
}
#canvasHost canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.viewport-top {
position: absolute;
top: 14px;
left: 14px;
right: 14px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
z-index: 3;
}
.viewport-title {
padding: 9px 11px;
background: rgba(11, 17, 25, .78);
border: 1px solid rgba(71, 91, 108, .58);
backdrop-filter: blur(8px);
}
.viewport-title strong {
display: block;
font-size: 10px;
letter-spacing: .15em;
}
.viewport-title span {
display: block;
margin-top: 4px;
color: #7890a3;
font-size: 9px;
letter-spacing: .06em;
}
.viewport-metrics {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
max-width: 280px;
}
.metric-pill {
padding: 8px 10px;
border: 1px solid rgba(63, 82, 99, .72);
background: rgba(11, 17, 25, .82);
color: #91a5b6;
font-size: 9px;
font-weight: 750;
letter-spacing: .08em;
backdrop-filter: blur(8px);
}
.metric-pill b {
display: block;
margin-top: 3px;
color: #ecf6f7;
font-size: 15px;
letter-spacing: 0;
}
.metric-pill.warn b { color: var(--red); }
.viewport-bottom {
position: absolute;
left: 14px;
right: 14px;
bottom: 13px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
pointer-events: none;
z-index: 3;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 8px 10px;
max-width: 370px;
background: rgba(11, 17, 25, .8);
border: 1px solid rgba(55, 74, 91, .72);
backdrop-filter: blur(8px);
color: #8498a9;
font-size: 9px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 12px;
height: 2px;
display: inline-block;
background: currentColor;
}
.legend .clear { color: var(--cyan); }
.legend .blocked { color: var(--red); }
.legend .baseline { color: var(--blue); }
.gesture-hint {
max-width: 280px;
padding: 8px 10px;
text-align: right;
color: #73899b;
background: rgba(11, 17, 25, .78);
border: 1px solid rgba(55, 74, 91, .6);
font-size: 9px;
line-height: 1.45;
backdrop-filter: blur(8px);
}
.selection-box {
padding: 12px;
border: 1px solid var(--line);
background: #121c26;
min-height: 124px;
}
.selection-title {
color: #e7f1f5;
font-size: 14px;
font-weight: 750;
margin: 6px 0 4px;
}
.selection-sub {
color: #7890a3;
font-size: 10px;
line-height: 1.45;
}
.position-fields {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.position-fields label {
color: #708699;
font-size: 9px;
font-weight: 750;
letter-spacing: .1em;
}
.position-fields input {
width: 100%;
height: 32px;
margin-top: 5px;
padding: 0 9px;
color: #dce9ee;
background: #0d151e;
border: 1px solid #2b3b4c;
outline: none;
font-size: 11px;
}
.position-fields input:focus {
border-color: #4caaa1;
box-shadow: 0 0 0 2px rgba(94, 230, 210, .08);
}
.position-fields input:disabled { opacity: .35; }
.visibility-card {
border: 1px solid var(--line);
background: #101923;
overflow: hidden;
}
.visibility-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 11px;
border-bottom: 1px solid var(--line-soft);
}
.visibility-head span {
color: #8498a8;
font-size: 9px;
font-weight: 800;
letter-spacing: .12em;
}
.live-dot {
display: inline-flex;
align-items: center;
gap: 5px;
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
}
.live-dot::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 8px var(--cyan);
}
.metric-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
align-items: center;
padding: 10px 11px;
border-bottom: 1px solid #1a2632;
}
.metric-row:last-child { border-bottom: 0; }
.metric-row span {
color: #7890a3;
font-size: 10px;
}
.metric-row strong {
color: #edf5f7;
font-size: 17px;
}
.metric-row.delta strong { color: var(--amber); }
.metric-row.delta strong.good { color: var(--cyan); }
.action-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.action-row button { width: 100%; }
.block-list {
display: flex;
flex-direction: column;
gap: 6px;
margin-top: 10px;
}
.block-item {
display: grid;
grid-template-columns: 7px 1fr;
gap: 8px;
align-items: start;
padding: 7px 8px;
background: #151d27;
border: 1px solid #253241;
color: #9eb0be;
font-size: 9px;
line-height: 1.4;
}
.block-item i {
width: 6px;
height: 6px;
margin-top: 3px;
background: var(--red);
box-shadow: 0 0 6px rgba(255, 107, 107, .45);
}
.audit-box {
padding: 10px;
background: #0d151d;
border: 1px solid #243342;
}
.audit-title {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
color: #d7e4e9;
font-size: 10px;
font-weight: 750;
}
.audit-title button {
padding: 5px 8px;
border: 1px solid #33495b;
background: #15212c;
color: #a9bdca;
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
}
#auditOutput {
margin: 8px 0 0;
color: #71899a;
font-size: 9px;
line-height: 1.55;
}
.shortcut {
display: grid;
grid-template-columns: 55px 1fr;
gap: 8px;
align-items: center;
padding: 6px 0;
color: #718899;
font-size: 9px;
}
kbd {
display: inline-flex;
justify-content: center;
padding: 4px 6px;
border: 1px solid #314252;
border-bottom-color: #455b6d;
background: #17212c;
color: #a6b8c5;
font: 8px ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (max-width: 1180px) {
.workspace { grid-template-columns: 220px minmax(0, 1fr) 258px; }
.topbar { grid-template-columns: 220px 1fr 258px; }
.top-center .chip:nth-child(2) { display: none; }
.gesture-hint { display: none; }
}
@media (max-width: 880px) {
.workspace { grid-template-columns: 190px minmax(0, 1fr); }
.right-panel { display: none; }
.topbar { grid-template-columns: 190px 1fr 190px; }
.brand small { display: none; }
.top-center { justify-content: flex-start; padding-left: 10px; }
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<strong>VOX / HALL</strong>
<small>Ensemble visibility studio</small>
</div>
</div>
<div class="top-center">
<div class="chip"><span class="dot"></span> LIVE GEOMETRY</div>
<div class="chip">VOXEL STAGE / 01</div>
<div class="chip">SCHEMATIC OVERLAYS</div>
</div>
<div class="top-actions">
<button id="resetView" class="quiet-button" type="button">RESET VIEW</button>
</div>
</header>
<main class="workspace">
<aside class="left-panel">
<section class="panel-section">
<h2 class="section-heading">Movable sections</h2>
<div id="sceneList" class="scene-list"></div>
</section>
<section class="panel-section">
<h2 class="section-heading">Layers</h2>
<label class="layer">
<span class="layer-name">Visibility rays<span class="layer-note">Actual stage-to-seat checks</span></span>
<span class="switch"><input id="visibilityToggle" type="checkbox" checked><span></span></span>
</label>
<label class="layer">
<span class="layer-name">Compare baseline<span class="layer-note">Blue baseline / live geometry</span></span>
<span class="switch"><input id="compareToggle" type="checkbox"><span></span></span>
</label>
<label class="layer">
<span class="layer-name">Audio schematic<span class="layer-note">Synthetic routing only</span></span>
<span class="switch"><input id="audioToggle" type="checkbox"><span></span></span>
</label>
</section>
<section class="panel-section">
<h2 class="section-heading">Legend</h2>
<div class="mini-note">
<strong>Clear sightline</strong> reaches a stage target.<br>
<strong>Blocked sightline</strong> terminates at a physical baffle.<br>
<strong>Baseline</strong> stores positions and visibility results.
</div>
</section>
<section class="panel-section">
<h2 class="section-heading">Controls</h2>
<div class="shortcut"><kbd>DRAG</kbd><span>Move a section</span></div>
<div class="shortcut"><kbd>DRAG</kbd><span>Orbit empty space</span></div>
<div class="shortcut"><kbd>SHIFT</kbd><span>Pan the stage</span></div>
<div class="shortcut"><kbd>WHEEL</kbd><span>Zoom in or out</span></div>
</section>
</aside>
<section id="viewport" aria-label="Interactive three-dimensional stage layout">
<div id="canvasHost"></div>
<div class="viewport-top">
<div class="viewport-title">
<strong>ENSEMBLE FLOOR / PERSPECTIVE</strong>
<span id="geometryStatus">Preparing geometry…</span>
</div>
<div class="viewport-metrics">
<div class="metric-pill">VISIBLE<b id="viewportVisible">—</b></div>
<div class="metric-pill warn">BLOCKED RAYS<b id="viewportBlocked">—</b></div>
</div>
</div>
<div class="viewport-bottom">
<div class="legend">
<span class="clear"><i></i>CLEAR</span>
<span class="blocked"><i></i>BLOCKED AT BAFFLE</span>
<span class="baseline"><i></i>SAVED BASELINE</span>
</div>
<div class="gesture-hint">Drag any colored section across the floor. All sightline checks update against the actual blocker geometry.</div>
</div>
</section>
<aside class="right-panel">
<section class="panel-section">
<h2 class="section-heading">Selection</h2>
<div class="selection-box">
<div id="selectedType" class="eyebrow">No section selected</div>
<div id="selectedName" class="selection-title">Choose an object</div>
<div id="selectedDescription" class="selection-sub">Click a performer, audience block, or sightline baffle in the scene.</div>
<div class="position-fields">
<label>X POSITION<input id="posX" type="number" step="0.1" disabled></label>
<label>Z POSITION<input id="posZ" type="number" step="0.1" disabled></label>
</div>
</div>
</section>
<section class="panel-section">
<h2 class="section-heading">Visibility comparison</h2>
<div class="visibility-card">
<div class="visibility-head">
<span>SEAT → STAGE CHECKS</span>
<span class="live-dot">LIVE</span>
</div>
<div class="metric-row"><span>Baseline visible</span><strong id="baselineVisible">—</strong></div>
<div class="metric-row"><span>Current visible</span><strong id="currentVisible">—</strong></div>
<div class="metric-row delta"><span>Live difference</span><strong id="visibilityDelta">—</strong></div>
<div class="metric-row"><span>Blocked rays</span><strong id="blockedCount">—</strong></div>
</div>
<div class="action-row">
<button id="saveBaseline" class="secondary-button" type="button">SAVE BASELINE</button>
<button id="compareAction" class="primary-button" type="button">COMPARE</button>
</div>
</section>
<section class="panel-section">
<h2 class="section-heading">Active obstructions</h2>
<div id="blockList" class="block-list"></div>
</section>
<section class="panel-section">
<h2 class="section-heading">Geometry audit</h2>
<div class="audit-box">
<div class="audit-title">
<span>Runtime verification</span>
<button id="runAudit" type="button">RUN AUDIT</button>
</div>
<p id="auditOutput">Waiting for the first geometry pass.</p>
</div>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const host = $("canvasHost");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Voxel concert stage with movable ensemble sections and sightline overlays");
renderer.domElement.tabIndex = 0;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0c121a);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraState = {
azimuth: 0.50,
polar: 0.87,
target: new THREE.Vector3(0, 0.15, 1.15),
zoom: 1
};
const hemi = new THREE.HemisphereLight(0xc9e7ff, 0x29323a, 1.9);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff0d6, 3.2);
key.position.set(7, 13, 9);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -15;
key.shadow.camera.right = 15;
key.shadow.camera.top = 15;
key.shadow.camera.bottom = -15;
key.shadow.camera.near = 1;
key.shadow.camera.far = 35;
key.shadow.bias = -0.0003;
scene.add(key);
const rim = new THREE.DirectionalLight(0x70d9ff, 1.45);
rim.position.set(-9, 8, -5);
scene.add(rim);
const purple = new THREE.PointLight(0x9c72ff, 22, 18, 2);
purple.position.set(0, 5, -3);
scene.add(purple);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.03,
flatShading: true
}));
}
return materialCache.get(color);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0, override = null) {
const mesh = new THREE.Mesh(unitBox, override || material(color));
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function lineFromPoints(parent, points, color, opacity = 1, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const options = {
color,
transparent: opacity < 1,
opacity,
depthTest: false,
depthWrite: false,
toneMapped: false
};
const mat = dashed
? new THREE.LineDashedMaterial({ ...options, dashSize: 0.18, gapSize: 0.11 })
: new THREE.LineBasicMaterial(options);
const line = new THREE.Line(geometry, mat);
if (dashed) line.computeLineDistances();
line.renderOrder = 12;
parent.add(line);
return line;
}
function makeLabel(parent, text, y, z = 0, color = "#bdeee7", width = 2.9) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(9, 17, 25, 0.88)";
ctx.fillRect(0, 0, 512, 112);
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.strokeRect(2, 2, 508, 108);
ctx.fillStyle = color;
ctx.font = "700 31px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 57, 480);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
}));
sprite.position.set(0, y, z);
sprite.scale.set(width, width * 112 / 512, 1);
sprite.renderOrder = 20;
parent.add(sprite);
return sprite;
}
function createPerson(parent, color, x = 0, z = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
parent.add(group);
box(group, .18, .47, .21, 0x1c2632, -.14, .28, 0);
box(group, .18, .47, .21, 0x1c2632, .14, .28, 0);
box(group, .49, .58, .31, color, 0, .80, 0);
box(group, .32, .32, .32, 0xe2b18f, 0, 1.25, 0);
box(group, .36, .10, .35, 0x26303b, 0, 1.42, 0);
box(group, .15, .48, .17, color, -.31, .83, 0);
box(group, .15, .48, .17, color, .31, .83, 0);
return group;
}
function createCellist(parent, x, z, coat) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
createPerson(group, coat, -.08, .10, .94);
const instrument = new THREE.Group();
instrument.position.set(.30, .18, -.03);
group.add(instrument);
box(instrument, .50, .61, .22, 0x7d342c, 0, .92, 0);
box(instrument, .34, .31, .25, 0x9c4437, 0, 1.31, -.01);
box(instrument, .10, .78, .10, 0x4b261f, 0, 1.78, -.01);
box(instrument, .13, .10, .13, 0x241713, 0, 2.18, -.01);
box(instrument, .035, .84, .035, 0xe9d8b3, -.09, 1.65, -.14);
box(instrument, .035, .84, .035, 0xe9d8b3, -.03, 1.65, -.14);
box(instrument, .035, .84, .035, 0xe9d8b3, .03, 1.65, -.14);
box(instrument, .035, .84, .035, 0xe9d8b3, .09, 1.65, -.14);
box(instrument, .055, 1.22, .045, 0xc58a45, .35, 1.20, -.18);
}
function createSaxPlayer(parent, x, z, coat) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
createPerson(group, coat, -.12, .07, .93);
const sax = new THREE.Group();
sax.position.set(.30, .24, -.08);
group.add(sax);
box(sax, .12, .72, .12, 0xdda943, 0, .96, 0);
box(sax, .30, .12, .13, 0xe3b64f, .05, .62, 0);
box(sax, .24, .18, .24, 0xe8bd53, .08, .33, 0);
box(sax, .39, .09, .28, 0xf0c75c, .11, .25, 0);
box(sax, .13, .22, .13, 0x5d391f, 0, 1.42, 0);
}
function createTrumpeter(parent, x, z, coat) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
createPerson(group, coat, -.10, .08, .94);
const trumpet = new THREE.Group();
trumpet.position.set(.35, .30, -.04);
group.add(trumpet);
box(trumpet, .66, .13, .16, 0xe2b64d, .15, 1.12, 0);
box(trumpet, .15, .28, .16, 0xf0c85d, -.13, 1.03, 0);
box(trumpet, .35, .26, .27, 0xf3ca58, .48, 1.12, 0);
box(trumpet, .48, .08, .34, 0xffd86d, .61, 1.12, 0);
}
function createStand(parent, x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
box(group, .055, .92, .055, 0x5d6972, 0, .46, 0);
box(group, .48, .06, .28, 0x202a33, 0, .95, -.03);
box(group, .38, .025, .22, 0xd9d4bd, 0, .987, -.04);
box(group, .34, .035, .16, 0x313b43, 0, 1.01, -.05);
}
const stage = new THREE.Group();
scene.add(stage);
box(scene, 28, .28, 24, 0x101821, 0, -.18, 2);
const grid = new THREE.GridHelper(28, 28, 0x314758, 0x22313f);
grid.position.y = -.025;
grid.material.transparent = true;
grid.material.opacity = .26;
scene.add(grid);
box(stage, 12.8, .56, 5.8, 0x4d3428, 0, .28, -1.45);
box(stage, 12.45, .09, 5.42, 0x76513a, 0, .60, -1.45);
box(stage, 12.8, .12, .18, 0xba7950, 0, .62, 1.37);
box(stage, .18, .12, 5.8, 0xba7950, -6.31, .62, -1.45);
box(stage, .18, .12, 5.8, 0xba7950, 6.31, .62, -1.45);
box(stage, 12.4, 4.6, .18, 0x172431, 0, 2.85, -4.27);
box(stage, 12.8, .22, .30, 0x263a49, 0, 5.05, -4.25);
box(stage, .30, 4.9, .30, 0x263a49, -6.25, 2.95, -4.25);
box(stage, .30, 4.9, .30, 0x263a49, 6.25, 2.95, -4.25);
for (let i = -5; i <= 5; i++) {
box(stage, .72, .52, .16, i % 2 ? 0x3c5161 : 0x2e4352, i * 1.04, 1.16, -4.13);
}
makeLabel(stage, "VOX HALL / ENSEMBLE STUDY", 4.72, -4.16, "#87e8d8", 4.4);
// Fixed voxel piano.
const piano = new THREE.Group();
piano.position.set(-4.65, .66, -2.45);
scene.add(piano);
box(piano, 2.05, .42, 1.16, 0x151b24, 0, .92, 0);
box(piano, 2.18, .12, 1.25, 0x222c38, 0, 1.20, -.04);
box(piano, 1.78, .14, .34, 0xe8e2cf, 0, .81, .66);
for (let i = 0; i < 11; i++) {
box(piano, .035, .09, .22, 0x1a1d23, -.79 + i * .158, .91, .70);
}
box(piano, .15, .67, .15, 0x1a222c, -.75, .34, -.35);
box(piano, .15, .67, .15, 0x1a222c, .75, .34, -.35);
box(piano, .15, .67, .15, 0x1a222c, 0, .34, -.35);
makeLabel(piano, "VOXEL PIANO", 1.75, 0, "#d4c5a3", 2.2);
// Speaker stacks are physical scene objects, separate from the optional audio schematic.
for (const side of [-1, 1]) {
const speaker = new THREE.Group();
speaker.position.set(side * 5.65, .66, .58);
scene.add(speaker);
box(speaker, .76, 1.35, .64, 0x202a34, 0, .68, 0);
box(speaker, .58, .58, .08, 0x111820, 0, .96, -.34);
box(speaker, .58, .30, .08, 0x111820, 0, .48, -.34);
box(speaker, .86, .08, .72, 0x354554, 0, 1.39, 0);
}
const items = new Map();
const focusSpecs = [];
const audienceSpecs = [];
const blockerEntries = [];
const audioRings = [];
function registerItem(id, name, type, group, options = {}) {
group.userData.itemId = id;
items.set(id, {
id,
name,
type,
group,
bounds: options.bounds || { minX: -6.4, maxX: 6.4, minZ: -3.8, maxZ: 8.3 },
description: options.description || ""
});
return group;
}
function createFocusSection(id, name, color, position, bounds) {
const group = new THREE.Group();
group.position.copy(position);
scene.add(group);
registerItem(id, name, "focus", group, {
bounds,
description: "Movable ensemble section and a live visual target for audience sightlines."
});
group.userData.focusPoint = new THREE.Vector3(0, 1.12, 0);
focusSpecs.push({ id, name, group, focusPoint: group.userData.focusPoint });
makeLabel(group, name.toUpperCase(), 2.35, 0, "#bdeee7", 2.7);
return group;
}
const strings = createFocusSection(
"strings", "String section", 0xcc655f,
new THREE.Vector3(-2.85, .66, -.62),
{ minX: -4.7, maxX: -.8, minZ: -3.4, maxZ: .65 }
);
box(strings, 2.8, .18, .72, 0x3c2a2a, 0, .08, .28);
createCellist(strings, -.92, .02, 0xa94e4c);
createCellist(strings, 0, .02, 0xb96055);
createCellist(strings, .92, .02, 0x984744);
createStand(strings, -.48, -.62);
createStand(strings, .48, -.62);
const winds = createFocusSection(
"winds", "Wind section", 0xe3a84c,
new THREE.Vector3(-.65, .66, -.82),
{ minX: -2.5, maxX: 1.2, minZ: -3.4, maxZ: .65 }
);
createSaxPlayer(winds, -.74, .05, 0xd28b42);
createSaxPlayer(winds, 0, .05, 0xe2a851);
createSaxPlayer(winds, .74, .05, 0xc77c3c);
createStand(winds, -.38, -.66);
createStand(winds, .38, -.66);
const brass = createFocusSection(
"brass", "Brass section", 0xe0bd55,
new THREE.Vector3(1.35, .66, -.70),
{ minX: -.1, maxX: 3.6, minZ: -3.4, maxZ: .65 }
);
createTrumpeter(brass, -.72, .05, 0xbd9339);
createTrumpeter(brass, 0, .05, 0xd0a544);
createTrumpeter(brass, .72, .05, 0xb98b37);
createStand(brass, -.38, -.64);
createStand(brass, .38, -.64);
const percussion = createFocusSection(
"percussion", "Percussion", 0x62a8a1,
new THREE.Vector3(3.65, .66, -2.00),
{ minX: 2.2, maxX: 5.4, minZ: -3.65, maxZ: .2 }
);
box(percussion, 1.10, .85, .70, 0x9f3f3f, -.35, .54, 0);
box(percussion, .86, .08, .62, 0xe6d7bd, -.35, 1.00, 0);
box(percussion, .66, .54, .60, 0xd88b47, .72, .38, .10);
box(percussion, .72, .07, .66, 0xeee0c4, .72, .68, .10);
box(percussion, .06, 1.02, .06, 0x7b858c, .10, .55, -.12);
box(percussion, .88, .055, .24, 0xd8b04f, .18, 1.08, -.12);
box(percussion, .06, .75, .06, 0x68747c, 1.05, .48, -.30);
box(percussion, .68, .055, .18, 0xd8b04f, 1.12, .86, -.30);
const choir = createFocusSection(
"choir", "Choir", 0x8f82bd,
new THREE.Vector3(-1.50, .66, -2.73),
{ minX: -4.1, maxX: .8, minZ: -3.75, maxZ: -1.25 }
);
box(choir, 3.7, .24, 1.20, 0x393348, 0, .10, 0);
for (let i = 0; i < 5; i++) {
createPerson(choir, i % 2 ? 0x796ca1 : 0x8f82bd, -1.35 + i * .68, .03, .87);
}
createStand(choir, -1.02, -.48);
createStand(choir, 0, -.48);
createStand(choir, 1.02, -.48);
function createAudienceSection(id, name, color, position) {
const group = new THREE.Group();
group.position.copy(position);
scene.add(group);
registerItem(id, name, "audience", group, {
bounds: { minX: -5.4, maxX: 5.4, minZ: 4.1, maxZ: 8.4 },
description: "Movable audience block. Each chair is an independent eye position in the sightline calculation."
});
box(group, 3.55, .055, 2.75, 0x18232f, 0, .015, .58);
const seats = [];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
const chair = new THREE.Group();
const x = (col - 1) * .96;
const z = row * 1.16;
chair.position.set(x, 0, z);
group.add(chair);
const seatMaterial = new THREE.MeshStandardMaterial({
color: 0x3e7182, roughness: .9, metalness: .02, flatShading: true
});
box(chair, .58, .16, .55, color, 0, .48, 0, seatMaterial);
box(chair, .58, .56, .14, color, 0, .79, .24, seatMaterial);
box(chair, .07, .40, .07, 0x26313c, -.22, .23, 0);
box(chair, .07, .40, .07, 0x26313c, .22, .23, 0);
seats.push({
group: chair,
local: new THREE.Vector3(x, 0, z),
label: `${name} / ${String(row * 3 + col + 1).padStart(2, "0")}`,
material: seatMaterial
});
}
}
audienceSpecs.push({ id, name, group, seats });
makeLabel(group, name.toUpperCase(), 1.45, 2.64, "#86cbe8", 2.65);
return group;
}
createAudienceSection("audience-west", "West seats", 0x3e7182, new THREE.Vector3(-4.20, 0, 5.35));
createAudienceSection("audience-center", "Center seats", 0x3f7c7b, new THREE.Vector3(0, 0, 6.05));
createAudienceSection("audience-east", "East seats", 0x47748a, new THREE.Vector3(4.20, 0, 5.35));
function createBaffle(id, name, position) {
const group = new THREE.Group();
group.position.copy(position);
scene.add(group);
registerItem(id, name, "blocker", group, {
bounds: { minX: -3.1, maxX: 3.1, minZ: 1.8, maxZ: 4.6 },
description: "Physical synthetic sightline baffle. Ray intersections use this box mesh as the occluder."
});
const hitMesh = box(group, .76, 3.12, .76, 0x3d4651, 0, 1.56, 0);
box(group, 1.00, .18, 1.00, 0x26323d, 0, .09, 0);
box(group, .91, .16, .91, 0xbd675d, 0, 3.14, 0);
makeLabel(group, `${name.toUpperCase()} / SYNTHETIC`, 3.62, 0, "#ff9b91", 2.85);
blockerEntries.push({ id, name, group, hitMesh });
}
createBaffle("baffle-left", "Left screen", new THREE.Vector3(-.60, 0, 3.08));
createBaffle("baffle-right", "Right screen", new THREE.Vector3(.60, 0, 3.08));
// Optional synthetic audio routing layer.
const audioOverlay = new THREE.Group();
audioOverlay.visible = false;
scene.add(audioOverlay);
makeLabel(audioOverlay, "SYNTHETIC AUDIO ROUTES / NO LIVE SIGNAL", 4.55, -3.8, "#cfadff", 4.8);
for (const focus of focusSpecs) {
const overlay = new THREE.Group();
focus.group.add(overlay);
const ringColors = [0x72a7ff, 0xbc8cff, 0x5ee6d2];
for (let i = 0; i < 3; i++) {
const points = [];
const radius = .65 + i * .34;
for (let p = 0; p < 64; p++) {
const theta = p / 64 * Math.PI * 2;
points.push(new THREE.Vector3(Math.cos(theta) * radius, .035 + i * .025, Math.sin(theta) * radius));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const ring = new THREE.LineLoop(geometry, new THREE.LineBasicMaterial({
color: ringColors[i], transparent: true, opacity: .62 - i * .12,
depthTest: false, depthWrite: false, toneMapped: false
}));
ring.renderOrder = 14;
overlay.add(ring);
}
overlay.visible = false;
audioRings.push(overlay);
}
for (const x of [-4.2, 0, 4.2]) {
const curve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(x * .25, 1.2, -1.1),
new THREE.Vector3(x * .6, 3.8, 1.6),
new THREE.Vector3(x, .65, 5.1)
);
const line = lineFromPoints(audioOverlay, curve.getPoints(48), 0xbc8cff, .42, true);
line.renderOrder = 13;
}
const currentLines = new THREE.Group();
const baselineLines = new THREE.Group();
scene.add(currentLines, baselineLines);
const selectionHelper = new THREE.BoxHelper(new THREE.Object3D(), 0x65f0d7);
selectionHelper.visible = false;
selectionHelper.material.depthTest = false;
selectionHelper.material.transparent = true;
selectionHelper.material.opacity = .8;
selectionHelper.renderOrder = 30;
scene.add(selectionHelper);
let selectedId = null;
let visibilityEnabled = true;
let compareEnabled = false;
let audioEnabled = false;
let baselineSnapshot = null;
let baselineVisibility = null;
let currentVisibility = null;
let refreshQueued = false;
function currentSnapshot() {
const positions = {};
for (const [id, item] of items) {
positions[id] = { x: item.group.position.x, z: item.group.position.z };
}
return { positions };
}
function segmentBoxIntersection(start, end, box3) {
const direction = new THREE.Vector3().subVectors(end, start);
const maxDistance = direction.length();
if (maxDistance < 0.0001) return null;
direction.multiplyScalar(1 / maxDistance);
let tmin = 0;
let tmax = maxDistance - 0.035;
for (const axis of ["x", "y", "z"]) {
const origin = start[axis];
const dir = direction[axis];
const min = box3.min[axis];
const max = box3.max[axis];
if (Math.abs(dir) < 1e-8) {
if (origin < min || origin > max) return null;
} else {
let t1 = (min - origin) / dir;
let t2 = (max - origin) / dir;
if (t1 > t2) [t1, t2] = [t2, t1];
tmin = Math.max(tmin, t1);
tmax = Math.min(tmax, t2);
if (tmax < tmin) return null;
}
}
if (tmax < 0 || tmin > maxDistance) return null;
const distance = Math.max(0, tmin);
return start.clone().addScaledVector(direction, distance);
}
function computeVisibility(snapshot) {
const rays = [];
const seatScores = new Map();
const targets = focusSpecs.map((focus) => {
const position = snapshot.positions[focus.id];
const local = focus.focusPoint;
return {
id: focus.id,
name: focus.name,
point: new THREE.Vector3(
position.x + local.x,
focus.group.position.y + local.y,
position.z + local.z
)
};
});
const blockerGeometry = blockerEntries.map((entry) => {
const actualBox = new THREE.Box3().setFromObject(entry.hitMesh);
const baselinePosition = snapshot.positions[entry.id];
const dx = baselinePosition.x - entry.group.position.x;
const dz = baselinePosition.z - entry.group.position.z;
const shifted = actualBox.clone();
shifted.translate(new THREE.Vector3(dx, 0, dz));
return { id: entry.id, name: entry.name, box: shifted };
});
for (const audience of audienceSpecs) {
const sectionPosition = snapshot.positions[audience.id];
for (const seat of audience.seats) {
const start = new THREE.Vector3(
sectionPosition.x + seat.local.x,
1.05,
sectionPosition.z + seat.local.z
);
let clear = 0;
for (const target of targets) {
const end = target.point.clone();
let hit = null;
let blocker = null;
for (const candidate of blockerGeometry) {
const intersection = segmentBoxIntersection(start, end, candidate.box);
if (intersection) {
hit = intersection;
blocker = candidate;
break;
}
}
const blocked = Boolean(hit);
if (!blocked) clear++;
rays.push({
seatId: audience.id,
seatLabel: seat.label,
targetId: target.id,
targetLabel: target.name,
start,
end,
hit,
blocked,
blockerId: blocker?.id || null,
blockerName: blocker?.name || null
});
}
seatScores.set(seat.label, { clear, total: targets.length });
}
}
const visible = rays.filter((ray) => !ray.blocked).length;
const total = rays.length;
return {
rays,
seatScores,
visible,
blocked: total - visible,
total,
visiblePct: total ? (visible / total) * 100 : 0
};
}
function clearGroup(group) {
const children = [...group.children];
for (const child of children) {
group.remove(child);
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material) ? object.material : [object.material];
materials.forEach((mat) => mat.dispose());
}
});
}
}
function drawCurrentVisibility() {
clearGroup(currentLines);
if (!currentVisibility) return;
for (const ray of currentVisibility.rays) {
const end = ray.blocked ? ray.hit : ray.end;
if (ray.blocked) {
lineFromPoints(currentLines, [ray.start, end], 0xff6b6b, .92, true);
const marker = new THREE.Mesh(
new THREE.BoxGeometry(.11, .11, .11),
new THREE.MeshBasicMaterial({ color: 0xff6b6b, depthTest: false, toneMapped: false })
);
marker.position.copy(end);
marker.renderOrder = 16;
currentLines.add(marker);
} else {
lineFromPoints(currentLines, [ray.start, end], 0x5ee6d2, .085, false);
}
}
currentLines.visible = visibilityEnabled;
}
function drawBaselineVisibility() {
clearGroup(baselineLines);
if (!compareEnabled || !baselineVisibility) {
baselineLines.visible = false;
return;
}
for (const ray of baselineVisibility.rays) {
const end = ray.blocked ? ray.hit : ray.end;
lineFromPoints(baselineLines, [ray.start, end], 0x72a7ff, ray.blocked ? .72 : .07, ray.blocked);
}
for (const audience of audienceSpecs) {
const position = baselineSnapshot.positions[audience.id];
for (const seat of audience.seats) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(.12, .12, .12),
new THREE.MeshBasicMaterial({ color: 0x72a7ff, depthTest: false, toneMapped: false })
);
marker.position.set(position.x + seat.local.x, 1.05, position.z + seat.local.z);
marker.renderOrder = 15;
baselineLines.add(marker);
}
}
for (const entry of blockerEntries) {
const position = baselineSnapshot.positions[entry.id];
const geometry = new THREE.EdgesGeometry(new THREE.BoxGeometry(.84, 3.22, .84));
const material = new THREE.LineBasicMaterial({
color: 0x72a7ff, transparent: true, opacity: .68,
depthTest: false, depthWrite: false, toneMapped: false
});
const outline = new THREE.LineSegments(geometry, material);
outline.position.set(position.x, 1.61, position.z);
outline.renderOrder = 14;
baselineLines.add(outline);
}
baselineLines.visible = visibilityEnabled;
}
function updateSeatMaterials() {
for (const audience of audienceSpecs) {
for (const seat of audience.seats) {
const score = currentVisibility?.seatScores.get(seat.label);
if (!score) continue;
const ratio = score.clear / score.total;
const color = new THREE.Color(0x3e7182);
if (visibilityEnabled) {
color.lerp(new THREE.Color(0x5ee6d2), ratio * .88);
if (ratio < .7) color.lerp(new THREE.Color(0xff6b6b), (1 - ratio) * .7);
}
seat.material.color.copy(color);
}
}
}
function updateMetrics() {
const current = currentVisibility;
const baseline = baselineVisibility;
$("viewportVisible").textContent = `${current.visiblePct.toFixed(1)}%`;
$("viewportBlocked").textContent = String(current.blocked);
$("currentVisible").textContent = `${current.visiblePct.toFixed(1)}%`;
$("baselineVisible").textContent = baseline ? `${baseline.visiblePct.toFixed(1)}%` : "—";
$("blockedCount").textContent = String(current.blocked);
const delta = current.visiblePct - (baseline?.visiblePct || 0);
const deltaElement = $("visibilityDelta");
deltaElement.textContent = `${delta >= 0 ? "+" : ""}${delta.toFixed(1)} pp`;
deltaElement.classList.toggle("good", delta > .01);
const blockedExamples = current.rays.filter((ray) => ray.blocked).slice(0, 4);
const list = $("blockList");
list.replaceChildren();
if (!blockedExamples.length) {
const empty = document.createElement("div");
empty.className = "block-list";
empty.innerHTML = '<div class="mini-note">No blocked rays in the current arrangement.</div>';
list.appendChild(empty);
} else {
for (const ray of blockedExamples) {
const item = document.createElement("div");
item.className = "block-item";
const dot = document.createElement("i");
const copy = document.createElement("span");
copy.textContent = `${ray.seatLabel} → ${ray.targetLabel}: blocked by ${ray.blockerName}.`;
item.append(dot, copy);
list.appendChild(item);
}
}
const meshCount = countMeshes();
$("geometryStatus").textContent = `${meshCount} meshes · ${current.total} live sight checks · ${compareEnabled ? "baseline overlay on" : "editable layout"}`;
}
function refreshScene() {
scene.updateMatrixWorld(true);
currentVisibility = computeVisibility(currentSnapshot());
drawCurrentVisibility();
drawBaselineVisibility();
updateSeatMaterials();
updateMetrics();
}
function scheduleRefresh() {
if (refreshQueued) return;
refreshQueued = true;
requestAnimationFrame(() => {
refreshQueued = false;
refreshScene();
});
}
function selectItem(id) {
selectedId = id;
const item = items.get(id);
if (!item) {
selectionHelper.visible = false;
$("selectedType").textContent = "No section selected";
$("selectedName").textContent = "Choose an object";
$("selectedDescription").textContent = "Click a performer, audience block, or sightline baffle in the scene.";
$("posX").disabled = true;
$("posZ").disabled = true;
document.querySelectorAll(".item-button.active").forEach((button) => button.classList.remove("active"));
return;
}
selectionHelper.setFromObject(item.group);
selectionHelper.visible = true;
$("selectedType").textContent = `${item.type} section`;
$("selectedName").textContent = item.name;
$("selectedDescription").textContent = item.description;
$("posX").disabled = false;
$("posZ").disabled = false;
$("posX").value = item.group.position.x.toFixed(2);
$("posZ").value = item.group.position.z.toFixed(2);
document.querySelectorAll(".item-button").forEach((button) => {
button.classList.toggle("active", button.dataset.itemId === id);
});
}
function setItemPosition(id, x, z) {
const item = items.get(id);
if (!item || !Number.isFinite(x) || !Number.isFinite(z)) return;
item.group.position.x = THREE.MathUtils.clamp(x, item.bounds.minX, item.bounds.maxX);
item.group.position.z = THREE.MathUtils.clamp(z, item.bounds.minZ, item.bounds.maxZ);
if (selectedId === id) {
$("posX").value = item.group.position.x.toFixed(2);
$("posZ").value = item.group.position.z.toFixed(2);
}
scheduleRefresh();
}
function buildSceneList() {
const list = $("sceneList");
list.replaceChildren();
const groups = [
["Performers", [...items.values()].filter((item) => item.type === "focus")],
["Audience", [...items.values()].filter((item) => item.type === "audience")],
["Sightline baffles", [...items.values()].filter((item) => item.type === "blocker")]
];
for (const [title, groupItems] of groups) {
const heading = document.createElement("div");
heading.className = "scene-group-label";
heading.textContent = title;
list.appendChild(heading);
for (const item of groupItems) {
const button = document.createElement("button");
button.type = "button";
button.className = "item-button";
button.dataset.itemId = item.id;
const swatch = document.createElement("span");
swatch.className = "swatch";
swatch.style.background = item.type === "blocker" ? "#ff6b6b" : item.type === "audience" ? "#72a7ff" : "#5ee6d2";
const name = document.createElement("span");
name.textContent = item.name;
const drag = document.createElement("span");
drag.className = "drag-mark";
drag.textContent = "⠿";
button.append(swatch, name, drag);
button.addEventListener("click", () => selectItem(item.id));
list.appendChild(button);
}
}
}
function updateCamera() {
const { azimuth, polar, target } = cameraState;
const radius = 24;
camera.position.set(
target.x + radius * Math.sin(polar) * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * Math.sin(polar) * Math.cos(azimuth)
);
camera.lookAt(target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
cameraState.azimuth = .50;
cameraState.polar = .87;
cameraState.target.set(0, .15, 1.15);
cameraState.zoom = 1;
updateCamera();
}
function resize() {
const width = Math.max(1, host.clientWidth);
const height = Math.max(1, host.clientHeight);
const aspect = width / height;
const viewHeight = Math.max(17.5, 20 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(host);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane();
const dragPoint = new THREE.Vector3();
const dragOffset = new THREE.Vector3();
const dragRoots = [...items.values()].map((item) => item.group);
function pointerToNdc(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function pickItem() {
const hits = raycaster.intersectObjects(dragRoots, true);
for (const hit of hits) {
let object = hit.object;
while (object && !object.userData.itemId) object = object.parent;
if (object?.userData.itemId) return items.get(object.userData.itemId);
}
return null;
}
const pointerState = {
mode: null,
item: null,
lastX: 0,
lastY: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerToNdc(event);
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
if (event.button === 2 || event.shiftKey) {
pointerState.mode = "pan";
} else {
const picked = pickItem();
if (picked) {
selectItem(picked.id);
pointerState.mode = "drag";
pointerState.item = picked;
dragPlane.set(new THREE.Vector3(0, 1, 0), -picked.group.position.y);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
dragOffset.copy(picked.group.position).sub(dragPoint);
dragOffset.y = 0;
} else {
dragOffset.set(0, 0, 0);
}
} else {
pointerState.mode = "orbit";
}
}
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = pointerState.mode === "drag" ? "grabbing" : "grabbing";
event.preventDefault();
});
renderer.domElement.addEventListener("pointermove", (event) => {
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
if (pointerState.mode === "drag" && pointerState.item) {
pointerToNdc(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
setItemPosition(
pointerState.item.id,
dragPoint.x + dragOffset.x,
dragPoint.z + dragOffset.z
);
}
} else if (pointerState.mode === "orbit") {
cameraState.azimuth -= dx * .005;
cameraState.polar = THREE.MathUtils.clamp(cameraState.polar + dy * .005, .38, 1.25);
updateCamera();
} else if (pointerState.mode === "pan") {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = 18 / Math.max(1, host.clientHeight) / cameraState.zoom;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -7, 7);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -4, 8);
updateCamera();
} else {
pointerToNdc(event);
renderer.domElement.style.cursor = pickItem() ? "grab" : "default";
}
});
function endPointer(event) {
pointerState.mode = null;
pointerState.item = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "default";
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom * Math.exp(-event.deltaY * .001), .62, 1.65);
updateCamera();
}, { passive: false });
$("posX").addEventListener("change", () => {
if (!selectedId) return;
const item = items.get(selectedId);
setItemPosition(selectedId, Number($("posX").value), item.group.position.z);
});
$("posZ").addEventListener("change", () => {
if (!selectedId) return;
const item = items.get(selectedId);
setItemPosition(selectedId, item.group.position.x, Number($("posZ").value));
});
$("resetView").addEventListener("click", resetCamera);
$("visibilityToggle").addEventListener("change", (event) => {
visibilityEnabled = event.target.checked;
currentLines.visible = visibilityEnabled;
baselineLines.visible = visibilityEnabled && compareEnabled;
updateSeatMaterials();
});
function setCompare(enabled) {
compareEnabled = enabled;
$("compareToggle").checked = enabled;
$("compareAction").textContent = enabled ? "COMPARE ON" : "COMPARE";
if (enabled) {
visibilityEnabled = true;
$("visibilityToggle").checked = true;
}
drawBaselineVisibility();
currentLines.visible = visibilityEnabled;
updateSeatMaterials();
updateMetrics();
}
$("compareToggle").addEventListener("change", (event) => setCompare(event.target.checked));
$("compareAction").addEventListener("click", () => setCompare(!compareEnabled));
$("saveBaseline").addEventListener("click", () => {
baselineSnapshot = currentSnapshot();
scene.updateMatrixWorld(true);
baselineVisibility = computeVisibility(baselineSnapshot);
drawBaselineVisibility();
updateMetrics();
$("auditOutput").textContent = `Baseline captured: ${baselineVisibility.visible} clear and ${baselineVisibility.blocked} blocked checks across ${baselineVisibility.total} seat-target pairs.`;
});
$("audioToggle").addEventListener("change", (event) => {
audioEnabled = event.target.checked;
audioOverlay.visible = audioEnabled;
audioRings.forEach((ring) => { ring.visible = audioEnabled; });
});
function countMeshes() {
let count = 0;
scene.traverse((object) => {
if (object.isMesh || object.isSprite || object.isLine) count++;
});
return count;
}
function runAudit() {
scene.updateMatrixWorld(true);
const meshCount = countMeshes();
const current = computeVisibility(currentSnapshot());
const expectedChecks = audienceSpecs.reduce((sum, audience) => sum + audience.seats.length, 0) * focusSpecs.length;
const blockersActual = blockerEntries.map((entry) => {
const bounds = new THREE.Box3().setFromObject(entry.hitMesh);
return {
id: entry.id,
position: { x: entry.group.position.x, z: entry.group.position.z },
bounds: { min: bounds.min.toArray(), max: bounds.max.toArray() }
};
});
const canvasRect = renderer.domElement.getBoundingClientRect();
const checks = {
canvasVisible: canvasRect.width > 100 && canvasRect.height > 100,
geometryPresent: meshCount >= 80,
sightlineDataComplete: current.total === expectedChecks && current.rays.length === expectedChecks,
baselinePresent: Boolean(baselineSnapshot && baselineVisibility),
physicalBlockersPresent: blockersActual.length === 2 && blockersActual.every((entry) => entry.bounds.max[0] > entry.bounds.min[0])
};
const pass = Object.values(checks).every(Boolean);
const message = pass
? `PASS: ${meshCount} scene elements; ${current.total} sight checks; ${current.blocked} blocked rays; baseline and physical blocker data verified.`
: `FAIL: ${Object.entries(checks).filter(([, value]) => !value).map(([key]) => key).join(", ")}`;
$("auditOutput").textContent = message;
return {
pass,
checks,
meshCount,
canvas: { width: canvasRect.width, height: canvasRect.height },
expectedChecks,
current,
baseline: baselineVisibility,
compareEnabled,
visibilityEnabled,
audioEnabled,
blockers: blockersActual,
itemPositions: Object.fromEntries([...items].map(([id, item]) => [id, {
x: item.group.position.x,
z: item.group.position.z
}]))
};
}
$("runAudit").addEventListener("click", runAudit);
scene.updateMatrixWorld(true);
baselineSnapshot = currentSnapshot();
baselineVisibility = computeVisibility(baselineSnapshot);
buildSceneList();
resize();
updateCamera();
refreshScene();
runAudit();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
if (audioEnabled) {
audioRings.forEach((ring, index) => {
const pulse = 1 + Math.sin(elapsed * 2.2 + index * .7) * .06;
ring.scale.set(pulse, 1, pulse);
});
}
if (selectedId && items.has(selectedId)) {
selectionHelper.setFromObject(items.get(selectedId).group);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
window.__VOXHALL_READY__ = true;
window.voxHall = {
ready: true,
audit: runAudit,
getState() {
return {
ready: true,
compareEnabled,
visibilityEnabled,
audioEnabled,
currentMetrics: currentVisibility,
baselineMetrics: baselineVisibility,
positions: Object.fromEntries([...items].map(([id, item]) => [id, {
x: item.group.position.x,
z: item.group.position.z
}]))
};
},
setPosition(id, x, z) {
setItemPosition(id, Number(x), Number(z));
return this.getState();
},
compare(enabled = true) {
setCompare(Boolean(enabled));
return this.getState();
},
saveBaseline() {
$("saveBaseline").click();
return this.getState();
},
select(id) {
selectItem(id);
}
};
</script>
</body>
</html>
```