Prompt specification
Build or customize the Three.js 3D scene "Small rehearsal room with movable panels" 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: Small rehearsal room with movable panels
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-rehearsal-room-with-movable-panels-x2163
Scene Description Prompt:
Please make a low-poly Three.js scene in one standalone HTML file using cdnjs. Create a rehearsal room with musicians, ceiling, and movable acoustic panels. Trace selected reflection paths to seats, clearly separating geometric visualization from a full sound simulation.
Working Three.js Starter (small-rehearsal-room-with-movable-panels-x2163):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rehearsal Room — Geometric Reflection Study</title>
<style>
:root {
--bg: #0b1119;
--panel: rgba(18, 28, 42, 0.88);
--border: rgba(153, 180, 210, 0.2);
--text: #e6edf5;
--muted: #91a1b5;
--accent: #63e6d2;
--warning: #ffd166;
}
* {
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;
}
#viewport {
position: absolute;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: absolute;
z-index: 5;
pointer-events: none;
}
.hud > * {
pointer-events: auto;
}
.topbar {
top: 18px;
left: 20px;
right: 20px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 18px;
}
.brand {
padding: 15px 17px;
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(11, 17, 25, 0.78);
backdrop-filter: blur(14px);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.24);
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 3px;
font-size: clamp(17px, 2.2vw, 25px);
letter-spacing: -0.03em;
}
.subtitle {
color: var(--muted);
font-size: 12px;
}
.mode-badge {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
margin-top: 10px;
border: 1px solid rgba(255, 209, 102, 0.45);
border-radius: 999px;
color: var(--warning);
background: rgba(255, 209, 102, 0.08);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.mode-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--warning);
box-shadow: 0 0 14px rgba(255, 209, 102, 0.8);
}
.controls {
top: 155px;
left: 20px;
width: 275px;
max-height: calc(100vh - 190px);
overflow: auto;
padding: 15px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
}
.section {
padding-bottom: 14px;
margin-bottom: 14px;
border-bottom: 1px solid rgba(153, 180, 210, 0.13);
}
.section:last-child {
margin-bottom: 0;
border-bottom: 0;
padding-bottom: 0;
}
.section-title {
margin-bottom: 9px;
color: #c7d3e1;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.source-list {
display: grid;
gap: 6px;
}
button,
select {
font: inherit;
}
.source-button,
.trace-button {
width: 100%;
border: 1px solid rgba(153, 180, 210, 0.18);
border-radius: 9px;
color: var(--muted);
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition: 140ms ease;
}
.source-button {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 10px;
text-align: left;
font-size: 12px;
}
.source-button:hover,
.source-button.active {
color: var(--text);
border-color: rgba(99, 230, 210, 0.55);
background: rgba(99, 230, 210, 0.09);
}
.source-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.source-button[data-source="voice"] {
color: #63e6d2;
}
.source-button[data-source="guitar"] {
color: #ffb454;
}
.source-button[data-source="drums"] {
color: #a78bfa;
}
.source-button.active {
color: var(--text);
}
.source-button.active .source-dot {
background: var(--source-color);
}
.check-row {
display: flex;
align-items: center;
gap: 8px;
margin: 7px 0;
color: #bac6d5;
font-size: 12px;
cursor: pointer;
}
.check-row input {
accent-color: var(--accent);
}
label.field-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
select {
width: 100%;
padding: 8px 9px;
border: 1px solid rgba(153, 180, 210, 0.2);
border-radius: 8px;
outline: none;
color: var(--text);
background: #142033;
font-size: 12px;
}
.trace-button {
padding: 10px 12px;
margin-top: 13px;
color: #06211e;
border-color: transparent;
background: var(--accent);
font-size: 12px;
font-weight: 800;
}
.trace-button:hover {
filter: brightness(1.08);
transform: translateY(-1px);
}
.panel-readout {
margin-top: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.disclaimer {
padding: 11px;
border: 1px solid rgba(255, 209, 102, 0.28);
border-radius: 9px;
color: #e6d6a7;
background: rgba(255, 209, 102, 0.06);
font-size: 11px;
line-height: 1.5;
}
.disclaimer strong {
display: block;
margin-bottom: 4px;
color: var(--warning);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
display: grid;
gap: 7px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 11px;
}
.legend-line {
width: 27px;
height: 0;
border-top: 2px dashed;
}
.bottom-info {
right: 20px;
bottom: 18px;
max-width: 330px;
padding: 11px 14px;
border: 1px solid var(--border);
border-radius: 11px;
color: var(--muted);
background: rgba(11, 17, 25, 0.72);
backdrop-filter: blur(12px);
font-size: 11px;
line-height: 1.5;
text-align: right;
}
.bottom-info b {
color: var(--text);
}
@media (max-width: 760px) {
.controls {
top: auto;
bottom: 18px;
left: 12px;
width: min(270px, calc(100vw - 24px));
max-height: 47vh;
}
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand {
max-width: 275px;
}
.bottom-info {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="hud topbar">
<div class="brand">
<div class="eyebrow">Acoustic layout lab</div>
<h1>Rehearsal Room</h1>
<div class="subtitle">Movable surfaces · selected reflection geometry</div>
<div class="mode-badge">Geometric visualization only</div>
</div>
</div>
<div class="hud controls">
<div class="section">
<div class="section-title">Sources</div>
<div class="source-list">
<button class="source-button active" data-source="voice">
<span class="source-dot"></span> Voice
</button>
<button class="source-button active" data-source="guitar">
<span class="source-dot"></span> Guitar
</button>
<button class="source-button active" data-source="drums">
<span class="source-dot"></span> Drums
</button>
</div>
</div>
<div class="section">
<div class="section-title">Path segments</div>
<label class="check-row">
<input type="checkbox" id="wallPath" checked />
Back-wall reflection
</label>
<label class="check-row">
<input type="checkbox" id="panelPath" checked />
Acoustic-panel reflection
</label>
<label class="check-row">
<input type="checkbox" id="ceilingPath" />
Ceiling reflection
</label>
</div>
<div class="section">
<div class="section-title">Destination</div>
<label class="field-label" for="seatSelect">Seat target</label>
<select id="seatSelect"></select>
<label class="field-label" for="panelSelect" style="margin-top: 12px">
Movable panel
</label>
<select id="panelSelect"></select>
<button class="trace-button" id="traceButton">Trace selected paths</button>
<div class="panel-readout" id="panelReadout"></div>
</div>
<div class="section">
<div class="disclaimer">
<strong>Not a sound simulation</strong>
Lines show idealized mirror-image geometry between selected points and
surfaces. They do not model frequency response, sound pressure,
material absorption, diffraction, occlusion, or reverberation.
</div>
</div>
<div class="section">
<div class="section-title">Legend</div>
<div class="legend">
<div class="legend-item">
<span class="legend-line" style="color: #63e6d2"></span> Voice route
</div>
<div class="legend-item">
<span class="legend-line" style="color: #ffb454"></span> Guitar route
</div>
<div class="legend-item">
<span class="legend-line" style="color: #a78bfa"></span> Drum route
</div>
</div>
</div>
</div>
<div class="hud bottom-info">
<b>Controls:</b> drag empty space to orbit · scroll to zoom ·
drag colored panels to move them · click a seat to target it
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const seatSelect = document.getElementById("seatSelect");
const panelSelect = document.getElementById("panelSelect");
const panelReadout = document.getElementById("panelReadout");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1119);
scene.fog = new THREE.Fog(0x0b1119, 22, 42);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.05;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc9e7ff, 0x20202b, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x4cd7c5, 16, 20, 2);
rimLight.position.set(-5, 4, -2);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa45b, 12, 18, 2);
warmLight.position.set(5, 3.8, 1);
scene.add(warmLight);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.04,
flatShading: true,
...options,
});
const basic = (color, options = {}) =>
new THREE.MeshBasicMaterial({
color,
...options,
});
function addBox(parent, width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
sides,
material,
x,
y,
z
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, sides),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, color = "#dbeafe", width = 1.6) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(7, 13, 22, 0.82)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(160, 190, 220, 0.3)";
ctx.lineWidth = 4;
ctx.strokeRect(2, 2, canvas.width - 4, canvas.height - 4);
ctx.fillStyle = color;
ctx.font = "700 32px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
})
);
sprite.scale.set(width, width * (96 / 512), 1);
sprite.renderOrder = 10;
return sprite;
}
// ------------------------------------------------------------
// Room shell
// ------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
const floorMaterial = standard(0x27313d);
const floor = addBox(room, 14, 0.18, 10, floorMaterial, 0, -0.1, 0);
floor.receiveShadow = true;
const grid = new THREE.GridHelper(14, 28, 0x536273, 0x364352);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.42;
room.add(grid);
const wallMaterial = standard(0x66778a, {
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide,
});
const backWall = addBox(
room,
14,
5,
0.18,
wallMaterial.clone(),
0,
2.5,
-5.02
);
backWall.castShadow = false;
addBox(room, 0.18, 5, 10, wallMaterial.clone(), -7.02, 2.5, 0);
addBox(room, 0.18, 5, 10, wallMaterial.clone(), 7.02, 2.5, 0);
const ceilingMaterial = standard(0x8ba0b5, {
transparent: true,
opacity: 0.1,
depthWrite: false,
side: THREE.DoubleSide,
});
addBox(room, 14, 0.16, 10, ceilingMaterial, 0, 5.3, 0);
const beamMaterial = standard(0x536273);
for (const x of [-5.2, -1.75, 1.75, 5.2]) {
addBox(room, 0.16, 0.28, 9.7, beamMaterial, x, 5.02, 0);
}
for (const z of [-3.4, 0, 3.4]) {
addBox(room, 13.6, 0.2, 0.14, beamMaterial, 0, 5.03, z);
}
// Suspended ceiling absorbers.
const cloudMaterial = standard(0x536a7e);
const cloudMaterial2 = standard(0x43566b);
[
[-4.5, -2.5, cloudMaterial],
[0, -2.5, cloudMaterial2],
[4.5, -2.5, cloudMaterial],
[-2.25, 1.2, cloudMaterial2],
[2.25, 1.2, cloudMaterial],
].forEach(([x, z, material]) => {
const cloud = addBox(room, 2.35, 0.12, 1.55, material, x, 4.77, z);
cloud.rotation.y = x > 0 ? -0.12 : 0.12;
cloud.castShadow = false;
});
// Low stage under the musicians.
addBox(room, 8.6, 0.2, 3.3, standard(0x35404b), 0, 0.1, -1.15);
const roomLabel = makeLabel("REHEARSAL ROOM", "#b8c7d8", 2.5);
roomLabel.position.set(-4.8, 4.15, -4.83);
room.add(roomLabel);
const studyLabel = makeLabel(
"GEOMETRIC PATH STUDY",
"#ffd166",
2.7
);
studyLabel.position.set(3.8, 3.65, -4.83);
room.add(studyLabel);
// ------------------------------------------------------------
// Musicians
// ------------------------------------------------------------
const sources = {};
const sourceColors = {
voice: 0x63e6d2,
guitar: 0xffb454,
drums: 0xa78bfa,
};
function addMusician(name, type, x, z, bodyColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const bodyMat = standard(bodyColor);
const skinMat = standard(0xd59a72);
const darkMat = standard(0x202733);
addCylinder(group, 0.25, 0.34, 0.85, 6, bodyMat, 0, 1.08, 0);
addBox(group, 0.17, 0.7, 0.19, darkMat, -0.16, 0.48, 0);
addBox(group, 0.17, 0.7, 0.19, darkMat, 0.16, 0.48, 0);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.25, 0),
skinMat
);
head.position.set(0, 1.73, 0);
head.castShadow = true;
group.add(head);
addBox(group, 0.31, 0.11, 0.28, darkMat, 0, 1.91, 0.015);
const leftArm = addCylinder(
group,
0.08,
0.09,
0.62,
5,
bodyMat,
-0.34,
1.13,
0.05
);
leftArm.rotation.z = -0.45;
const rightArm = addCylinder(
group,
0.08,
0.09,
0.62,
5,
bodyMat,
0.34,
1.13,
0.05
);
rightArm.rotation.z = 0.45;
if (type === "guitar") {
const guitarMat = standard(0xc45b35);
addBox(group, 0.7, 0.76, 0.16, guitarMat, 0, 1.08, 0.26);
const neck = addBox(
group,
0.16,
0.9,
0.12,
standard(0x593829),
0.42,
1.4,
0.27
);
neck.rotation.z = -0.22;
addBox(group, 0.1, 0.13, 0.13, darkMat, 0.22, 1.29, 0.37);
}
if (type === "voice") {
addCylinder(
group,
0.025,
0.025,
1.55,
6,
darkMat,
0.64,
0.78,
0.2
);
const mic = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 8, 6),
standard(0x222933)
);
mic.position.set(0.64, 1.57, 0.2);
group.add(mic);
}
if (type === "drums") {
const drumMat = standard(0x8b3f4d);
addCylinder(group, 0.52, 0.52, 0.55, 12, drumMat, 0, 0.64, 0.5);
addCylinder(group, 0.32, 0.32, 0.42, 10, drumMat, -0.56, 0.52, 0.42);
addCylinder(group, 0.04, 0.04, 1.25, 6, darkMat, 0, 0.92, -0.1);
addCylinder(group, 0.42, 0.42, 0.035, 12, standard(0xb9a36b), 0, 1.58, -0.1);
}
const label = makeLabel(name.toUpperCase(), "#" + sourceColors[type].toString(16).padStart(6, "0"), 1.25);
label.position.set(0, 2.35, 0);
group.add(label);
const anchorHeight = type === "voice" ? 1.65 : type === "guitar" ? 1.28 : 1.45;
const anchor = new THREE.Vector3(x, anchorHeight, z + 0.1);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.08, 8, 6),
basic(sourceColors[type])
);
marker.position.copy(anchor);
marker.renderOrder = 5;
scene.add(marker);
sources[type] = {
name,
type,
group,
anchor,
marker,
color: sourceColors[type],
};
}
addMusician("Voice", "voice", -3.8, -0.85, 0x286c72);
addMusician("Guitar", "guitar", -0.75, -1.25, 0x9a5e32);
addMusician("Drums", "drums", 3.25, -1.05, 0x554b83);
// ------------------------------------------------------------
// Audience seats
// ------------------------------------------------------------
const seats = [];
const seatMaterial = standard(0x3d6174);
const seatBackMaterial = standard(0x426d80);
const seatLegMaterial = standard(0x1f2935);
for (let row = 0; row < 2; row++) {
for (let column = 0; column < 6; column++) {
const index = seats.length;
const x = -4.7 + column * 1.88;
const z = 2.65 + row * 1.42;
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const seat = {
index,
group,
target: new THREE.Vector3(x, 1.13, z),
};
const cushion = addBox(
group,
0.78,
0.13,
0.7,
seatMaterial,
0,
0.64,
0
);
cushion.userData.seat = seat;
const back = addBox(
group,
0.78,
0.76,
0.13,
seatBackMaterial,
0,
1.08,
-0.3
);
back.userData.seat = seat;
addBox(
group,
0.07,
0.57,
0.07,
seatLegMaterial,
-0.29,
0.3,
0.22
);
addBox(
group,
0.07,
0.57,
0.07,
seatLegMaterial,
0.29,
0.3,
0.22
);
addBox(
group,
0.07,
0.57,
0.07,
seatLegMaterial,
-0.29,
0.3,
-0.22
);
addBox(
group,
0.07,
0.57,
0.07,
seatLegMaterial,
0.29,
0.3,
-0.22
);
const label = makeLabel("S" + (index + 1), "#c7d3e1", 0.52);
label.position.set(0, 1.62, -0.28);
group.add(label);
seats.push(seat);
const option = document.createElement("option");
option.value = String(index);
option.textContent = `Seat S${index + 1}`;
seatSelect.appendChild(option);
}
}
seatSelect.value = "7";
// ------------------------------------------------------------
// Movable acoustic panels
// ------------------------------------------------------------
const panels = [];
const panelMeshes = [];
function createPanel(name, x, z, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const bodyMaterial = standard(color, {
emissive: 0x000000,
emissiveIntensity: 0.6,
});
const body = addBox(
group,
2.15,
2.65,
0.22,
bodyMaterial,
0,
1.7,
0
);
const trimMaterial = standard(0x24313e);
addBox(group, 2.3, 0.11, 0.28, trimMaterial, 0, 3.05, 0);
addBox(group, 2.3, 0.11, 0.28, trimMaterial, 0, 0.36, 0);
const ribMaterial = standard(color, {
emissive: color,
emissiveIntensity: 0.08,
});
[-0.68, 0, 0.68].forEach((ribX) => {
addBox(group, 0.055, 2.43, 0.25, ribMaterial, ribX, 1.7, 0.01);
});
addBox(group, 0.12, 0.65, 0.12, trimMaterial, -0.78, 0.12, 0);
addBox(group, 0.12, 0.65, 0.12, trimMaterial, 0.78, 0.12, 0);
const ring = new THREE.Mesh(
new THREE.RingGeometry(1.22, 1.32, 32),
basic(color, {
transparent: true,
opacity: 0.78,
side: THREE.DoubleSide,
depthWrite: false,
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.025;
group.add(ring);
const label = makeLabel(name, "#" + color.toString(16).padStart(6, "0"), 1.05);
label.position.set(0, 3.48, 0);
group.add(label);
const panel = {
name,
group,
body,
ring,
color,
};
body.userData.panel = panel;
panelMeshes.push(body);
panels.push(panel);
const option = document.createElement("option");
option.value = String(panels.length - 1);
option.textContent = name;
panelSelect.appendChild(option);
}
createPanel("P1", -4.55, -3.2, 0x3a8f91);
createPanel("P2", 0, -3.25, 0xb66b38);
createPanel("P3", 4.55, -3.2, 0x7163a8);
panelSelect.value = "1";
let selectedPanel = panels[1];
function selectPanel(panel) {
selectedPanel = panel;
panelSelect.value = String(panels.indexOf(panel));
panels.forEach((item) => {
const active = item === selectedPanel;
item.ring.visible = active;
item.body.material.emissive.setHex(active ? item.color : 0x000000);
item.body.material.emissiveIntensity = active ? 0.18 : 0;
});
updatePanelReadout();
drawPaths();
}
function updatePanelReadout() {
const p = selectedPanel;
panelReadout.textContent =
`${p.name} selected · X ${p.group.position.x.toFixed(1)} m · ` +
`Z ${p.group.position.z.toFixed(1)} m · drag panel to reposition`;
}
// ------------------------------------------------------------
// Geometric reflection paths
// ------------------------------------------------------------
const pathLayer = new THREE.Group();
pathLayer.renderOrder = 4;
scene.add(pathLayer);
const activeSources = new Set(["voice", "guitar", "drums"]);
function disposeObject(object) {
object.traverse((child) => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const materials = Array.isArray(child.material)
? child.material
: [child.material];
materials.forEach((material) => {
if (material.map) material.map.dispose();
material.dispose();
});
}
});
}
function clearPaths() {
[...pathLayer.children].forEach((child) => {
disposeObject(child);
pathLayer.remove(child);
});
}
function reflectionPoint(source, target, axis, planeValue) {
const mirrored = target.clone();
mirrored[axis] = 2 * planeValue - target[axis];
const denominator = mirrored[axis] - source[axis];
if (Math.abs(denominator) < 0.00001) return null;
const t = (planeValue - source[axis]) / denominator;
if (t < 0 || t > 1) return null;
return source.clone().lerp(mirrored, t);
}
function addDashedSegment(a, b, color) {
const geometry = new THREE.BufferGeometry().setFromPoints([a, b]);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.25,
gapSize: 0.12,
transparent: true,
opacity: 0.94,
depthTest: false,
depthWrite: false,
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 7;
pathLayer.add(line);
}
function addPathMarker(point, color, radius = 0.075) {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(radius, 8, 6),
basic(color, {
depthTest: false,
depthWrite: false,
})
);
marker.position.copy(point);
marker.renderOrder = 8;
pathLayer.add(marker);
}
function addRoute(source, target, axis, planeValue, label, color) {
const bounce = reflectionPoint(source, target, axis, planeValue);
if (!bounce) return false;
addDashedSegment(source, bounce, color);
addDashedSegment(bounce, target, color);
addPathMarker(bounce, color, 0.09);
const pathLabel = makeLabel(label, "#" + color.toString(16).padStart(6, "0"), 0.85);
pathLabel.position.copy(bounce).add(new THREE.Vector3(0, 0.24, 0));
pathLayer.add(pathLabel);
return true;
}
function drawPaths() {
clearPaths();
const seat = seats[Number(seatSelect.value)];
const panel = panels[Number(panelSelect.value)];
const target = seat.target.clone();
const useWall = document.getElementById("wallPath").checked;
const usePanel = document.getElementById("panelPath").checked;
const useCeiling = document.getElementById("ceilingPath").checked;
let routeCount = 0;
Object.values(sources).forEach((source) => {
if (!activeSources.has(source.type)) return;
addPathMarker(source.anchor, source.color, 0.07);
addPathMarker(target, source.color, 0.06);
if (useWall) {
const ok = addRoute(
source.anchor,
target,
"z",
-4.9,
"BACK WALL",
source.color
);
if (ok) routeCount++;
}
if (usePanel) {
const panelSurface = panel.group.position.z + 0.12;
const ok = addRoute(
source.anchor,
target,
"z",
panelSurface,
panel.name,
source.color
);
if (ok) routeCount++;
}
if (useCeiling) {
const ok = addRoute(
source.anchor,
target,
"y",
5.0,
"CEILING",
source.color
);
if (ok) routeCount++;
}
});
panelReadout.textContent =
`${panel.name} selected · X ${panel.group.position.x.toFixed(1)} m · ` +
`Z ${panel.group.position.z.toFixed(1)} m · ` +
`${routeCount} geometric route${routeCount === 1 ? "" : "s"}`;
}
// ------------------------------------------------------------
// UI interactions
// ------------------------------------------------------------
document.querySelectorAll(".source-button").forEach((button) => {
button.addEventListener("click", () => {
const type = button.dataset.source;
if (activeSources.has(type)) {
activeSources.delete(type);
button.classList.remove("active");
} else {
activeSources.add(type);
button.classList.add("active");
}
drawPaths();
});
});
seatSelect.addEventListener("change", drawPaths);
panelSelect.addEventListener("change", () => {
selectPanel(panels[Number(panelSelect.value)]);
});
document.getElementById("wallPath").addEventListener("change", drawPaths);
document.getElementById("panelPath").addEventListener("change", drawPaths);
document.getElementById("ceilingPath").addEventListener("change", drawPaths);
document.getElementById("traceButton").addEventListener("click", drawPaths);
// ------------------------------------------------------------
// Custom camera and direct manipulation
// ------------------------------------------------------------
const cameraState = {
yaw: 0.35,
pitch: 0.72,
distance: 18.5,
target: new THREE.Vector3(0, 1.45, -0.15),
};
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
camera.position.set(
target.x + Math.sin(yaw) * Math.cos(pitch) * distance,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * Math.cos(pitch) * distance
);
camera.lookAt(target);
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const floorPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const floorPoint = new THREE.Vector3();
let orbiting = false;
let draggingPanel = false;
let lastPointerX = 0;
let lastPointerY = 0;
let dragOffset = new THREE.Vector2();
function setPointer(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 findPanelHit() {
const hits = raycaster.intersectObjects(panelMeshes, false);
return hits.length ? hits[0].object.userData.panel : null;
}
function findSeatHit() {
const seatMeshes = [];
seats.forEach((seat) => {
seat.group.traverse((child) => {
if (child.isMesh && child.userData.seat) {
seatMeshes.push(child);
}
});
});
const hits = raycaster.intersectObjects(seatMeshes, false);
return hits.length ? hits[0].object.userData.seat : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
setPointer(event);
const panelHit = findPanelHit();
const seatHit = findSeatHit();
if (panelHit) {
selectPanel(panelHit);
draggingPanel = true;
orbiting = false;
if (raycaster.ray.intersectPlane(floorPlane, floorPoint)) {
dragOffset.set(
floorPoint.x - panelHit.group.position.x,
floorPoint.z - panelHit.group.position.z
);
}
renderer.domElement.setPointerCapture(event.pointerId);
return;
}
if (seatHit) {
seatSelect.value = String(seatHit.index);
drawPaths();
return;
}
orbiting = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (draggingPanel) {
setPointer(event);
if (raycaster.ray.intersectPlane(floorPlane, floorPoint)) {
selectedPanel.group.position.x = THREE.MathUtils.clamp(
floorPoint.x - dragOffset.x,
-5.75,
5.75
);
selectedPanel.group.position.z = THREE.MathUtils.clamp(
floorPoint.z - dragOffset.y,
-4.25,
2.65
);
drawPaths();
}
return;
}
if (orbiting) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.24,
1.28
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
}
});
function endPointer(event) {
draggingPanel = false;
orbiting = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.012,
10,
28
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
selectPanel(selectedPanel);
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```