Prompt specification
Build or customize the Three.js 3D scene "Speaker interference listening-room map" 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: Speaker interference listening-room map
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/speaker-interference-listening-room-map-x1551
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring interference between coherent wave sources. Compose two speakers and a clearly synthetic amplitude field across a small room; exclude wall reflections explicitly and distinguish pressure amplitude from perceived loudness. Voxel style.
Working Three.js Starter (speaker-interference-listening-room-map-x1551):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coherence Room — Synthetic Interference Field</title>
<style>
:root {
color-scheme: dark;
--bg: #07101d;
--panel: rgba(10, 21, 37, 0.82);
--panel-strong: rgba(13, 27, 47, 0.94);
--border: rgba(153, 190, 220, 0.18);
--text: #eaf4ff;
--muted: #8ea6bd;
--cyan: #42c8ff;
--amber: #ffad58;
--coral: #ff5964;
--violet: #685ee8;
--green: #72e6bc;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: crosshair;
}
.glass {
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px) saturate(130%);
-webkit-backdrop-filter: blur(18px) saturate(130%);
}
.topbar {
position: fixed;
z-index: 5;
top: 20px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 3px;
font-size: clamp(25px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 760;
}
h1 span {
color: #91a8bf;
font-weight: 420;
}
.subtitle {
color: var(--muted);
font-size: 12px;
}
.status-row {
display: flex;
align-items: center;
gap: 9px;
padding: 9px 13px;
border-radius: 999px;
color: #cde4ef;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 14px var(--green);
}
.panel {
position: fixed;
z-index: 6;
top: 92px;
right: 24px;
width: 332px;
max-height: calc(100vh - 116px);
overflow: auto;
border-radius: 18px;
padding: 18px;
scrollbar-width: thin;
scrollbar-color: #344b64 transparent;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #a8bed2;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.mini-pill {
padding: 4px 7px;
border: 1px solid var(--border);
border-radius: 999px;
color: #a9c1d5;
font-size: 9px;
letter-spacing: 0.08em;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
padding: 4px;
border-radius: 12px;
background: rgba(1, 8, 17, 0.56);
border: 1px solid rgba(151, 187, 216, 0.12);
}
.segmented button {
border: 0;
border-radius: 9px;
padding: 10px 8px;
background: transparent;
color: var(--muted);
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: 160ms ease;
}
.segmented button:hover {
color: white;
background: rgba(255, 255, 255, 0.035);
}
.segmented button.active {
color: #06101c;
background: linear-gradient(135deg, #d5f4ff, #78d9ff);
box-shadow: 0 6px 18px rgba(66, 200, 255, 0.16);
}
.mode-description {
min-height: 61px;
margin: 12px 1px 17px;
color: #a8bdcf;
font-size: 11px;
line-height: 1.55;
}
.mode-description strong {
color: #f0f7ff;
}
.control {
display: block;
margin: 0 0 20px;
}
.control-heading {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 10px;
font-size: 11px;
color: #c9d9e6;
}
output {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 99px;
appearance: none;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--fill, 50%),
#273b50 var(--fill, 50%),
#273b50 100%
);
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #dff7ff;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 5px rgba(66, 200, 255, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #dff7ff;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 5px rgba(66, 200, 255, 0.12);
}
.scale {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #647f96;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.formula {
padding: 11px 12px;
border: 1px solid rgba(116, 162, 197, 0.14);
border-radius: 11px;
background: rgba(2, 9, 18, 0.46);
color: #a9c8dc;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
line-height: 1.65;
}
.formula .accent {
color: var(--cyan);
}
.assumption {
margin-top: 12px;
color: #7f99ae;
font-size: 10px;
line-height: 1.55;
}
.assumption strong {
color: #b8d0e0;
}
.button-row {
display: grid;
grid-template-columns: 1.25fr 1fr 1fr;
gap: 7px;
margin-top: 16px;
}
.button-row button {
min-height: 36px;
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: #c8d9e6;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition: 150ms ease;
}
.button-row button:hover {
border-color: rgba(66, 200, 255, 0.46);
color: white;
background: rgba(66, 200, 255, 0.08);
}
.button-row button.active {
border-color: rgba(114, 230, 188, 0.52);
color: #aaffdf;
background: rgba(114, 230, 188, 0.09);
}
.audio-note {
min-height: 14px;
margin-top: 8px;
color: #668096;
font-size: 9px;
line-height: 1.4;
}
.metrics {
position: fixed;
z-index: 5;
left: 24px;
bottom: 24px;
width: 330px;
padding: 16px;
border-radius: 17px;
pointer-events: none;
}
.probe-heading {
display: flex;
justify-content: space-between;
align-items: center;
color: #9db3c6;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.probe-heading span:last-child {
color: #66839a;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0;
text-transform: none;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.metric {
min-height: 74px;
padding: 11px;
border: 1px solid rgba(141, 182, 212, 0.12);
border-radius: 11px;
background: rgba(2, 9, 18, 0.36);
}
.metric label {
display: block;
color: #8099ae;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin: 6px 0 3px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 19px;
font-weight: 650;
}
.metric small {
display: block;
color: #637d92;
font-size: 8px;
line-height: 1.25;
}
#pValue.positive {
color: var(--amber);
}
#pValue.negative {
color: var(--cyan);
}
#levelValue {
color: #c7d8e6;
}
#proxyValue {
color: #c3baff;
}
.path-info {
display: flex;
justify-content: space-between;
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid rgba(145, 181, 208, 0.11);
color: #7892a7;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
}
.legend {
position: fixed;
z-index: 5;
left: 50%;
bottom: 24px;
width: 390px;
transform: translateX(-50%);
padding: 13px 15px;
border-radius: 14px;
pointer-events: none;
}
.legend-title {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-title span:last-child {
color: #688299;
letter-spacing: 0;
text-transform: none;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.legend-bar {
height: 8px;
border-radius: 99px;
border: 1px solid rgba(255, 255, 255, 0.08);
}
.legend-bar.pressure {
background: linear-gradient(
90deg,
#42c8ff 0%,
#17324a 49%,
#24405b 51%,
#ffad58 100%
);
}
.legend-bar.loudness {
background: linear-gradient(
90deg,
#202044 0%,
#4c58be 34%,
#8c75d2 55%,
#ffad58 76%,
#ff5964 100%
);
}
.legend-labels {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #7892a7;
font-size: 8px;
}
.legend-note {
margin-top: 8px;
color: #647f94;
font-size: 8px;
line-height: 1.35;
}
.nav-hint {
position: fixed;
z-index: 4;
top: 94px;
left: 24px;
padding: 8px 10px;
border-radius: 8px;
color: #698399;
font-size: 9px;
pointer-events: none;
}
@media (max-width: 1080px) {
.metrics {
width: 285px;
}
.legend {
width: 330px;
}
}
@media (max-width: 820px) {
.topbar {
left: 14px;
right: 14px;
top: 14px;
}
.status-row {
padding: 8px 10px;
font-size: 8px;
}
.panel {
top: 78px;
right: 12px;
width: 285px;
max-height: 43vh;
padding: 14px;
}
.nav-hint,
.metrics {
display: none;
}
.legend {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
transform: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive synthetic acoustic interference field"></canvas>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Acoustics / Synthetic Field</div>
<h1>Coherence <span>Room</span></h1>
<div class="subtitle">Two coherent point sources · voxel pressure field · free-space propagation</div>
</div>
<div class="status-row glass">
<span class="status-dot"></span>
WALL REFLECTIONS EXCLUDED
</div>
</header>
<div class="nav-hint glass">DRAG TO ORBIT · WHEEL TO ZOOM · CLICK THE FLOOR TO PROBE</div>
<aside class="panel glass">
<div class="section-title">
<span>Field Encoding</span>
<span class="mini-pill">VISUAL TIME ×0.015</span>
</div>
<div class="segmented" role="group" aria-label="Visualization mode">
<button id="pressureMode" class="active" aria-pressed="true">Signed pressure</button>
<button id="loudnessMode" aria-pressed="false">Loudness proxy</button>
</div>
<p class="mode-description" id="modeDescription">
<strong>Pressure p(t)</strong> is signed and instantaneous:
cyan indicates rarefaction, amber indicates compression.
</p>
<label class="control">
<span class="control-heading">
<span>Source frequency</span>
<output id="frequencyOutput">220 Hz</output>
</span>
<input id="frequency" type="range" min="80" max="420" step="1" value="220">
<span class="scale">
<span>80 Hz</span>
<span id="wavelengthOutput">λ 1.56 m</span>
<span>420 Hz</span>
</span>
</label>
<label class="control">
<span class="control-heading">
<span>Source B phase lag</span>
<output id="phaseOutput">0°</output>
</span>
<input id="phase" type="range" min="0" max="360" step="1" value="0">
<span class="scale">
<span>0°</span>
<span>A → B</span>
<span>360°</span>
</span>
</label>
<div class="formula">
<span class="accent">p(x,z,t)</span> = Σ A<sub>i</sub>/(r<sub>i</sub>+0.55)<br>
· cos(k r<sub>i</sub> − ωt − φ<sub>i</sub>)<br>
<span class="accent">k</span> = 2πf/343 · <span class="accent">φ</span><sub>A</sub> = 0
</div>
<div class="assumption">
<strong>Model:</strong> softened point sources at a 1.05 m observation slice.
The room is only a display boundary. No wall impedance, diffraction, or reflected waves
are calculated.
</div>
<div class="button-row">
<button id="listenButton" aria-pressed="false">▶ Reference tone</button>
<button id="isoButton">Perspective</button>
<button id="topButton">Top view</button>
</div>
<div class="audio-note" id="audioNote">
Optional audio is two phase-locked oscillators, not a room-acoustics solver.
</div>
</aside>
<section class="metrics glass">
<div class="probe-heading">
<span>Floor Probe</span>
<span id="probePosition">x 0.00 m · z 0.00 m</span>
</div>
<div class="metric-grid">
<div class="metric">
<label>Signed pressure p(t)</label>
<strong id="pValue" class="positive">+0.00</strong>
<small>relative instantaneous pressure; ± means rarefaction / compression</small>
</div>
<div class="metric">
<label>RMS relative level</label>
<strong id="levelValue">−00.0 dB</strong>
<small>20 log₁₀(pRMS/pREF); not calibrated SPL</small>
</div>
<div class="metric">
<label>Perceived loudness</label>
<strong id="proxyValue">0.00</strong>
<small>illustrative 0–1 logarithmic proxy; not subjective loudness</small>
</div>
<div class="metric">
<label>Path difference</label>
<strong id="pathValue">0.00 m</strong>
<small id="pathRatio">0.00 wavelengths</small>
</div>
</div>
<div class="path-info">
<span id="distanceA">rA —</span>
<span id="distanceB">rB —</span>
<span id="phaseValue">local phase —</span>
</div>
</section>
<section class="legend glass">
<div class="legend-title">
<span id="legendTitle">Signed Pressure</span>
<span id="legendUnits">relative p(t)</span>
</div>
<div id="legendBar" class="legend-bar pressure"></div>
<div class="legend-labels">
<span id="legendLow">−1 · rarefaction</span>
<span id="legendMid">0</span>
<span id="legendHigh">+1 · compression</span>
</div>
<div class="legend-note" id="legendNote">
Voxel height represents |p(t)|. Color retains the pressure sign.
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and DOM
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const frequencyInput = document.querySelector("#frequency");
const phaseInput = document.querySelector("#phase");
const frequencyOutput = document.querySelector("#frequencyOutput");
const phaseOutput = document.querySelector("#phaseOutput");
const wavelengthOutput = document.querySelector("#wavelengthOutput");
const pressureModeButton = document.querySelector("#pressureMode");
const loudnessModeButton = document.querySelector("#loudnessMode");
const modeDescription = document.querySelector("#modeDescription");
const listenButton = document.querySelector("#listenButton");
const audioNote = document.querySelector("#audioNote");
const isoButton = document.querySelector("#isoButton");
const topButton = document.querySelector("#topButton");
const pValue = document.querySelector("#pValue");
const levelValue = document.querySelector("#levelValue");
const proxyValue = document.querySelector("#proxyValue");
const pathValue = document.querySelector("#pathValue");
const pathRatio = document.querySelector("#pathRatio");
const probePosition = document.querySelector("#probePosition");
const distanceA = document.querySelector("#distanceA");
const distanceB = document.querySelector("#distanceB");
const phaseValue = document.querySelector("#phaseValue");
const legendTitle = document.querySelector("#legendTitle");
const legendUnits = document.querySelector("#legendUnits");
const legendBar = document.querySelector("#legendBar");
const legendLow = document.querySelector("#legendLow");
const legendMid = document.querySelector("#legendMid");
const legendHigh = document.querySelector("#legendHigh");
const legendNote = document.querySelector("#legendNote");
const SPEED_OF_SOUND = 343;
const ROOM_WIDTH = 9.8;
const ROOM_DEPTH = 6.4;
const OBSERVATION_HEIGHT = 1.05;
const SOURCE_A = new THREE.Vector2(-1.95, 1.25);
const SOURCE_B = new THREE.Vector2(1.95, 1.25);
const NX = 33;
const NZ = 21;
const SPACING = 0.29;
const MIN_X = -((NX - 1) * SPACING) / 2;
const MIN_Z = -((NZ - 1) * SPACING) / 2;
let frequency = Number(frequencyInput.value);
let sourcePhase = Number(phaseInput.value);
let mode = "pressure";
let maxMagnitude = 1;
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07101d);
scene.fog = new THREE.FogExp2(0x07101d, 0.035);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
azimuth: 0.61,
polar: 0.91,
radius: 12.8,
target: new THREE.Vector3(0, 0.42, 0)
};
function updateCamera() {
const sinPolar = Math.sin(cameraState.polar);
const cosPolar = Math.cos(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.radius * cosPolar,
cameraState.target.z +
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xb8dfff, 0x111827, 1.7));
const keyLight = new THREE.DirectionalLight(0xd8efff, 3.2);
keyLight.position.set(5, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x557bff, 1.3);
rimLight.position.set(-6, 4, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa24d, 18, 8, 2);
warmLight.position.set(4, 3, 1);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Room: display bounds only; no reflected or boundary-conditioned waves
// -------------------------------------------------------------------------
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0c1726,
roughness: 0.92,
metalness: 0.05
});
const floor = new THREE.Mesh(
new THREE.BoxGeometry(ROOM_WIDTH, 0.22, ROOM_DEPTH),
floorMaterial
);
floor.position.y = -0.11;
floor.receiveShadow = true;
scene.add(floor);
const gridPositions = [];
for (let ix = 0; ix <= NX; ix++) {
const x = MIN_X - SPACING / 2 + ix * SPACING;
gridPositions.push(x, 0.018, MIN_Z - SPACING / 2);
gridPositions.push(x, 0.018, MIN_Z + (NZ - 1) * SPACING + SPACING / 2);
}
for (let iz = 0; iz <= NZ; iz++) {
const z = MIN_Z - SPACING / 2 + iz * SPACING;
gridPositions.push(MIN_X - SPACING / 2, 0.018, z);
gridPositions.push(MIN_X + (NX - 1) * SPACING + SPACING / 2, 0.018, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x45627a,
transparent: true,
opacity: 0.23
})
);
scene.add(grid);
const roomEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(ROOM_WIDTH, 2.55, ROOM_DEPTH)
),
new THREE.LineBasicMaterial({
color: 0x6687a2,
transparent: true,
opacity: 0.28
})
);
roomEdges.position.y = 1.275;
scene.add(roomEdges);
const backWall = new THREE.Mesh(
new THREE.PlaneGeometry(ROOM_WIDTH, 2.55),
new THREE.MeshBasicMaterial({
color: 0x3c6685,
transparent: true,
opacity: 0.035,
side: THREE.DoubleSide,
depthWrite: false
})
);
backWall.position.set(0, 1.275, -ROOM_DEPTH / 2);
scene.add(backWall);
// Small voxel markers emphasize the non-reflecting cutaway boundary.
const boundaryMaterial = new THREE.MeshStandardMaterial({
color: 0x315068,
emissive: 0x102638,
emissiveIntensity: 0.5,
roughness: 0.8
});
for (let x = -ROOM_WIDTH / 2; x <= ROOM_WIDTH / 2 + 0.01; x += 0.49) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.08, 0.08, 0.08),
boundaryMaterial
);
marker.position.set(x, 0.035, -ROOM_DEPTH / 2);
scene.add(marker);
}
// -------------------------------------------------------------------------
// Text sprites
// -------------------------------------------------------------------------
function makeLabel(initialText, accent = "#cceeff") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 256;
const context = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = 4;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 10;
function setText(text) {
context.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
context.fillStyle = "rgba(6, 16, 29, 0.86)";
context.fillRect(8, 38, 1008, 180);
context.strokeStyle = "rgba(157, 205, 235, 0.35)";
context.lineWidth = 4;
context.strokeRect(8, 38, 1008, 180);
context.fillStyle = accent;
context.fillRect(8, 38, 16, 180);
context.fillStyle = "#edf8ff";
context.font = "700 62px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 520, 130);
texture.needsUpdate = true;
}
setText(initialText);
return { sprite, setText };
}
const roomLabel = makeLabel(
"WALLS = DISPLAY BOUNDS ONLY · NO REFLECTIONS",
"#72e6bc"
);
roomLabel.sprite.position.set(0, 2.72, -ROOM_DEPTH / 2 + 0.02);
roomLabel.sprite.scale.set(5.4, 1.35, 1);
scene.add(roomLabel.sprite);
const sliceLabel = makeLabel(
"HORIZONTAL OBSERVATION SLICE · y = 1.05 m",
"#42c8ff"
);
sliceLabel.sprite.position.set(0, 0.14, ROOM_DEPTH / 2 - 0.05);
sliceLabel.sprite.scale.set(4.3, 1.075, 1);
scene.add(sliceLabel.sprite);
// -------------------------------------------------------------------------
// Voxel speakers
// -------------------------------------------------------------------------
const cabinetMaterial = new THREE.MeshStandardMaterial({
color: 0x172536,
roughness: 0.68,
metalness: 0.18
});
const baffleMaterial = new THREE.MeshStandardMaterial({
color: 0x24394b,
roughness: 0.58,
metalness: 0.12
});
const coneMaterial = new THREE.MeshStandardMaterial({
color: 0x07111b,
roughness: 0.9
});
function createSpeaker(source, accentColor, labelText) {
const group = new THREE.Group();
group.position.set(source.x, 0, source.y);
const cabinet = new THREE.Mesh(
new THREE.BoxGeometry(0.94, 1.62, 0.62),
cabinetMaterial
);
cabinet.position.y = 0.86;
cabinet.castShadow = true;
cabinet.receiveShadow = true;
group.add(cabinet);
const cabinetEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(cabinet.geometry),
new THREE.LineBasicMaterial({
color: 0x69869d,
transparent: true,
opacity: 0.45
})
);
cabinetEdges.position.copy(cabinet.position);
group.add(cabinetEdges);
const baffle = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 1.53, 0.08),
baffleMaterial
);
baffle.position.set(0, 0.86, 0.34);
baffle.castShadow = true;
group.add(baffle);
const wooferOuter = new THREE.Mesh(
new THREE.BoxGeometry(0.67, 0.67, 0.11),
coneMaterial
);
wooferOuter.position.set(0, 0.68, 0.43);
group.add(wooferOuter);
const wooferInner = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.48, 0.12),
new THREE.MeshStandardMaterial({
color: 0x111f2d,
roughness: 0.85
})
);
wooferInner.position.set(0, 0.68, 0.49);
group.add(wooferInner);
const dustCap = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 0.17, 0.13),
new THREE.MeshStandardMaterial({
color: accentColor,
emissive: accentColor,
emissiveIntensity: 0.28,
roughness: 0.5
})
);
dustCap.position.set(0, 0.68, 0.57);
group.add(dustCap);
const tweeter = new THREE.Mesh(
new THREE.BoxGeometry(0.29, 0.29, 0.12),
coneMaterial
);
tweeter.position.set(0, 1.33, 0.43);
group.add(tweeter);
const tweeterCenter = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.11, 0.14),
new THREE.MeshStandardMaterial({
color: 0x7894aa,
emissive: accentColor,
emissiveIntensity: 0.18
})
);
tweeterCenter.position.set(0, 1.33, 0.51);
group.add(tweeterCenter);
for (const x of [-0.31, 0.31]) {
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.12, 0.72),
coneMaterial
);
foot.position.set(x, 0.07, 0);
foot.castShadow = true;
group.add(foot);
}
const sourceMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.13, 0.13),
new THREE.MeshBasicMaterial({ color: accentColor })
);
sourceMarker.position.set(0, OBSERVATION_HEIGHT, 0);
group.add(sourceMarker);
const ringPoints = [
new THREE.Vector3(-0.56, 0.045, -0.56),
new THREE.Vector3(0.56, 0.045, -0.56),
new THREE.Vector3(0.56, 0.045, 0.56),
new THREE.Vector3(-0.56, 0.045, 0.56)
];
const ring = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(ringPoints),
new THREE.LineBasicMaterial({
color: accentColor,
transparent: true,
opacity: 0.72
})
);
group.add(ring);
const label = makeLabel(labelText, accentColor);
label.sprite.position.set(0, 2.12, 0);
label.sprite.scale.set(2.25, 0.5625, 1);
group.add(label.sprite);
scene.add(group);
return { group, label, sourceMarker, dustCap };
}
const speakerA = createSpeaker(
SOURCE_A,
"#42c8ff",
"SOURCE A · φA = 0°"
);
const speakerB = createSpeaker(
SOURCE_B,
"#ffad58",
"SOURCE B · φB = 0°"
);
// -------------------------------------------------------------------------
// Floor tiles and instanced voxel field
// -------------------------------------------------------------------------
const cellCount = NX * NZ;
const cells = [];
for (let iz = 0; iz < NZ; iz++) {
for (let ix = 0; ix < NX; ix++) {
cells.push({
index: iz * NX + ix,
ix,
iz,
x: MIN_X + ix * SPACING,
z: MIN_Z + iz * SPACING,
re: 0,
im: 0,
magnitude: 0,
phase: 0,
rmsRatio: 0,
levelDb: -60,
proxy: 0,
rA: 0,
rB: 0
});
}
}
const tileMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.95
}),
cellCount
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
cells.forEach((cell, index) => {
dummy.position.set(cell.x, 0.027, cell.z);
dummy.scale.set(SPACING * 0.91, 0.035, SPACING * 0.91);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
tileMesh.setMatrixAt(index, dummy.matrix);
tileColor.setHex((cell.ix + cell.iz) % 2 === 0 ? 0x122235 : 0x0e1c2c);
tileMesh.setColorAt(index, tileColor);
});
tileMesh.instanceMatrix.needsUpdate = true;
tileMesh.instanceColor.needsUpdate = true;
tileMesh.receiveShadow = true;
tileMesh.frustumCulled = false;
scene.add(tileMesh);
const fieldMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.72,
metalness: 0.08,
flatShading: true
}),
cellCount
);
fieldMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
fieldMesh.receiveShadow = true;
fieldMesh.castShadow = false;
fieldMesh.frustumCulled = false;
scene.add(fieldMesh);
const neutralColor = new THREE.Color(0x16283d);
const negativeColor = new THREE.Color(0x42c8ff);
const positiveColor = new THREE.Color(0xffad58);
const lowLoudnessColor = new THREE.Color(0x202044);
const midLoudnessColor = new THREE.Color(0x665cc8);
const highLoudnessColor = new THREE.Color(0xff5964);
const warmLoudnessColor = new THREE.Color(0xffb15a);
const workingColor = new THREE.Color();
function rebuildField() {
const k = (2 * Math.PI * frequency) / SPEED_OF_SOUND;
const phaseRadians = THREE.MathUtils.degToRad(sourcePhase);
maxMagnitude = 0;
for (const cell of cells) {
const dxA = cell.x - SOURCE_A.x;
const dzA = cell.z - SOURCE_A.y;
const dxB = cell.x - SOURCE_B.x;
const dzB = cell.z - SOURCE_B.y;
cell.rA = Math.hypot(dxA, dzA);
cell.rB = Math.hypot(dxB, dzB);
const amplitudeA = 1 / (cell.rA + 0.55);
const amplitudeB = 1 / (cell.rB + 0.55);
const spatialPhaseA = k * cell.rA;
const spatialPhaseB = k * cell.rB - phaseRadians;
cell.re = amplitudeA * Math.cos(spatialPhaseA)
+ amplitudeB * Math.cos(spatialPhaseB);
cell.im = amplitudeA * Math.sin(spatialPhaseA)
+ amplitudeB * Math.sin(spatialPhaseB);
cell.magnitude = Math.hypot(cell.re, cell.im);
cell.phase = Math.atan2(cell.im, cell.re);
maxMagnitude = Math.max(maxMagnitude, cell.magnitude);
}
for (const cell of cells) {
cell.rmsRatio = Math.max(cell.magnitude / maxMagnitude, 1e-6);
cell.levelDb = Math.max(20 * Math.log10(cell.rmsRatio), -60);
cell.proxy = THREE.MathUtils.clamp((cell.levelDb + 60) / 60, 0, 1);
}
}
function pressureAt(cell, elapsedTime) {
const omega = 2 * Math.PI * frequency;
const slowTime = elapsedTime * 0.015;
return (
(cell.magnitude / maxMagnitude) *
Math.cos(cell.phase - omega * slowTime)
);
}
function updateField(elapsedTime) {
for (const cell of cells) {
let height;
let color;
if (mode === "pressure") {
const p = pressureAt(cell, elapsedTime);
const absolute = Math.abs(p);
height = 0.025 + absolute * 1.42;
if (p >= 0) {
workingColor.copy(neutralColor).lerp(
positiveColor,
THREE.MathUtils.clamp(absolute * 1.35, 0, 1)
);
} else {
workingColor.copy(neutralColor).lerp(
negativeColor,
THREE.MathUtils.clamp(absolute * 1.35, 0, 1)
);
}
} else {
height = 0.025 + cell.proxy * 1.42;
if (cell.proxy < 0.52) {
workingColor.copy(lowLoudnessColor).lerp(
midLoudnessColor,
cell.proxy / 0.52
);
} else if (cell.proxy < 0.78) {
workingColor.copy(midLoudnessColor).lerp(
warmLoudnessColor,
(cell.proxy - 0.52) / 0.26
);
} else {
workingColor.copy(warmLoudnessColor).lerp(
highLoudnessColor,
(cell.proxy - 0.78) / 0.22
);
}
}
dummy.position.set(cell.x, 0.045 + height / 2, cell.z);
dummy.scale.set(SPACING * 0.83, height, SPACING * 0.83);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
fieldMesh.setMatrixAt(cell.index, dummy.matrix);
fieldMesh.setColorAt(cell.index, workingColor);
}
fieldMesh.instanceMatrix.needsUpdate = true;
fieldMesh.instanceColor.needsUpdate = true;
}
rebuildField();
// -------------------------------------------------------------------------
// Probe selection and direct path visualization
// -------------------------------------------------------------------------
let selectedIndex = cells.findIndex(
(cell) => cell.ix === Math.floor(NX / 2) && cell.iz === Math.floor(NZ / 2)
);
const selectionBox = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(SPACING * 0.96, 1.58, SPACING * 0.96)),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.72,
depthTest: false
})
);
selectionBox.renderOrder = 8;
scene.add(selectionBox);
const probeMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.15, 0.15),
new THREE.MeshBasicMaterial({
color: 0xffffff,
depthTest: false
})
);
probeMarker.renderOrder = 9;
scene.add(probeMarker);
function makePath(color) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.62,
depthTest: false
})
);
line.renderOrder = 7;
scene.add(line);
return line;
}
const pathA = makePath(0x42c8ff);
const pathB = makePath(0xffad58);
function setPath(line, source, cell) {
const positions = line.geometry.attributes.position;
positions.setXYZ(0, source.x, 0.075, source.y);
positions.setXYZ(1, cell.x, 0.075, cell.z);
positions.needsUpdate = true;
line.geometry.computeBoundingSphere();
}
function selectCell(index) {
selectedIndex = index;
const cell = cells[index];
selectionBox.position.set(cell.x, 0.82, cell.z);
probeMarker.position.set(cell.x, OBSERVATION_HEIGHT, cell.z);
setPath(pathA, SOURCE_A, cell);
setPath(pathB, SOURCE_B, cell);
probePosition.textContent =
`x ${cell.x.toFixed(2)} m · z ${cell.z.toFixed(2)} m`;
distanceA.textContent = `rA ${cell.rA.toFixed(2)} m`;
distanceB.textContent = `rB ${cell.rB.toFixed(2)} m`;
}
selectCell(selectedIndex);
function updateProbeReadout(elapsedTime) {
const cell = cells[selectedIndex];
const p = pressureAt(cell, elapsedTime);
const delta = Math.abs(cell.rA - cell.rB);
const wavelength = SPEED_OF_SOUND / frequency;
pValue.textContent = `${p >= 0 ? "+" : "−"}${Math.abs(p).toFixed(2)}`;
pValue.classList.toggle("positive", p >= 0);
pValue.classList.toggle("negative", p < 0);
levelValue.textContent = `${cell.levelDb <= -59.9 ? "−60.0" : cell.levelDb.toFixed(1)} dB`;
proxyValue.textContent = cell.proxy.toFixed(2);
pathValue.textContent = `${delta.toFixed(2)} m`;
pathRatio.textContent = `${(delta / wavelength).toFixed(2)} wavelengths`;
phaseValue.textContent = `φ ${THREE.MathUtils.radToDeg(cell.phase).toFixed(0)}°`;
}
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
pointerStartX = previousX = event.clientX;
pointerStartY = previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (
Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
) > 4
) {
pointerMoved = true;
}
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.005,
0.08,
1.38
);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerMoved) {
pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObject(floor, false)[0];
if (hit) {
const ix = THREE.MathUtils.clamp(
Math.round((hit.point.x - MIN_X) / SPACING),
0,
NX - 1
);
const iz = THREE.MathUtils.clamp(
Math.round((hit.point.z - MIN_Z) / SPACING),
0,
NZ - 1
);
selectCell(iz * NX + ix);
}
}
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7,
22
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
switch (event.key) {
case "ArrowLeft":
cameraState.azimuth += 0.08;
break;
case "ArrowRight":
cameraState.azimuth -= 0.08;
break;
case "ArrowUp":
cameraState.polar = Math.max(0.08, cameraState.polar - 0.06);
break;
case "ArrowDown":
cameraState.polar = Math.min(1.38, cameraState.polar + 0.06);
break;
case "+":
case "=":
cameraState.radius = Math.max(7, cameraState.radius - 0.7);
break;
case "-":
cameraState.radius = Math.min(22, cameraState.radius + 0.7);
break;
default:
return;
}
event.preventDefault();
updateCamera();
});
isoButton.addEventListener("click", () => {
cameraState.azimuth = 0.61;
cameraState.polar = 0.91;
cameraState.radius = 12.8;
cameraState.target.set(0, 0.42, 0);
updateCamera();
});
topButton.addEventListener("click", () => {
cameraState.azimuth = 0;
cameraState.polar = 0.08;
cameraState.radius = 11.7;
cameraState.target.set(0, 0, 0);
updateCamera();
});
// -------------------------------------------------------------------------
// Controls and mode switching
// -------------------------------------------------------------------------
function updateRangeFill(input) {
const fraction =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) *
100;
input.style.setProperty("--fill", `${fraction}%`);
}
function updateControlReadouts() {
const wavelength = SPEED_OF_SOUND / frequency;
frequencyOutput.textContent = `${frequency} Hz`;
phaseOutput.textContent = `${sourcePhase}°`;
wavelengthOutput.textContent = `λ ${wavelength.toFixed(2)} m`;
updateRangeFill(frequencyInput);
updateRangeFill(phaseInput);
speakerB.label.setText(`SOURCE B · φB = ${sourcePhase}°`);
}
frequencyInput.addEventListener("input", () => {
frequency = Number(frequencyInput.value);
updateControlReadouts();
rebuildField();
if (audioContext && oscillatorA) {
const now = audioContext.currentTime;
oscillatorA.frequency.setTargetAtTime(frequency, now, 0.015);
oscillatorB.frequency.setTargetAtTime(frequency, now, 0.015);
delayB.delayTime.setTargetAtTime(
sourcePhase / 360 / frequency,
now,
0.02
);
}
});
phaseInput.addEventListener("input", () => {
sourcePhase = Number(phaseInput.value);
updateControlReadouts();
rebuildField();
if (audioContext && delayB) {
delayB.delayTime.setTargetAtTime(
sourcePhase / 360 / frequency,
audioContext.currentTime,
0.02
);
}
});
function setMode(nextMode) {
mode = nextMode;
const pressureActive = mode === "pressure";
pressureModeButton.classList.toggle("active", pressureActive);
loudnessModeButton.classList.toggle("active", !pressureActive);
pressureModeButton.setAttribute("aria-pressed", String(pressureActive));
loudnessModeButton.setAttribute("aria-pressed", String(!pressureActive));
if (pressureActive) {
modeDescription.innerHTML =
"<strong>Pressure p(t)</strong> is signed and instantaneous: " +
"cyan indicates rarefaction, amber indicates compression.";
legendTitle.textContent = "Signed Pressure";
legendUnits.textContent = "relative p(t)";
legendBar.className = "legend-bar pressure";
legendLow.textContent = "−1 · rarefaction";
legendMid.textContent = "0";
legendHigh.textContent = "+1 · compression";
legendNote.textContent =
"Voxel height represents |p(t)|. Color retains the pressure sign.";
} else {
modeDescription.innerHTML =
"<strong>Perceived loudness proxy</strong> uses RMS pressure over a " +
"cycle and a logarithmic response. It has no sign and is not calibrated SPL.";
legendTitle.textContent = "Relative Loudness Proxy";
legendUnits.textContent = "0–1 logarithmic index";
legendBar.className = "legend-bar loudness";
legendLow.textContent = "quiet / destructive";
legendMid.textContent = "mid-level";
legendHigh.textContent = "loud / constructive";
legendNote.textContent =
"RMS removes pressure sign. Actual loudness also depends on frequency, duration, context, and listener calibration.";
}
}
pressureModeButton.addEventListener("click", () => setMode("pressure"));
loudnessModeButton.addEventListener("click", () => setMode("loudness"));
updateControlReadouts();
updateRangeFill(frequencyInput);
updateRangeFill(phaseInput);
// -------------------------------------------------------------------------
// Optional coherent reference audio
// -------------------------------------------------------------------------
let audioContext = null;
let oscillatorA = null;
let oscillatorB = null;
let delayB = null;
let masterGain = null;
let audioEnabled = false;
async function toggleAudio() {
const AudioContextClass =
window.AudioContext || window.webkitAudioContext;
if (!AudioContextClass) {
audioNote.textContent = "Web Audio is unavailable in this browser.";
return;
}
if (!audioContext) {
audioContext = new AudioContextClass();
masterGain = audioContext.createGain();
masterGain.gain.value = 0;
oscillatorA = audioContext.createOscillator();
oscillatorB = audioContext.createOscillator();
const gainA = audioContext.createGain();
const gainB = audioContext.createGain();
delayB = audioContext.createDelay(5);
oscillatorA.type = "sine";
oscillatorB.type = "sine";
oscillatorA.frequency.value = frequency;
oscillatorB.frequency.value = frequency;
gainA.gain.value = 0.5;
gainB.gain.value = 0.5;
delayB.delayTime.value = sourcePhase / 360 / frequency;
oscillatorA.connect(gainA).connect(masterGain);
oscillatorB.connect(delayB).connect(gainB).connect(masterGain);
masterGain.connect(audioContext.destination);
oscillatorA.start();
oscillatorB.start();
}
if (audioContext.state === "suspended") {
await audioContext.resume();
}
audioEnabled = !audioEnabled;
masterGain.gain.setTargetAtTime(
audioEnabled ? 0.055 : 0,
audioContext.currentTime,
0.025
);
listenButton.classList.toggle("active", audioEnabled);
listenButton.setAttribute("aria-pressed", String(audioEnabled));
listenButton.textContent = audioEnabled ? "■ Stop tone" : "▶ Reference tone";
audioNote.textContent = audioEnabled
? `Playing ${frequency} Hz phase-locked reference sources.`
: "Optional audio is two phase-locked oscillators, not a room-acoustics solver.";
}
listenButton.addEventListener("click", toggleAudio);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
updateField(elapsed);
updateProbeReadout(elapsed);
const pulse = 0.5 + 0.5 * Math.sin(elapsed * 4.5);
speakerA.sourceMarker.scale.setScalar(0.9 + pulse * 0.35);
speakerB.sourceMarker.scale.setScalar(0.9 + (1 - pulse) * 0.35);
selectionBox.rotation.y = elapsed * 0.28;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```