Prompt specification
Build or customize the Three.js 3D scene "Cave echo teaching diorama" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Cave echo teaching diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cave-echo-teaching-diorama-x1543
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing echo timing and distance. Compose a small cave chamber with a source and several marked reflection paths; label the paths illustrative and separate geometric echoes from realistic reverberation. Voxel style.
Working Three.js Starter (cave-echo-teaching-diorama-x1543):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Cave — Echo Timing & Distance</title>
<style>
:root {
--bg: #091015;
--panel: rgba(10, 17, 21, 0.88);
--line: rgba(214, 233, 238, 0.13);
--muted: #82949a;
--text: #edf6f5;
--cyan: #79e7ff;
--amber: #ffbd73;
--violet: #ba9cff;
--green: #70e0a6;
--pink: #ff7f91;
}
* {
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;
}
body {
background:
radial-gradient(circle at 45% 42%, #142229 0%, #091015 56%, #060a0d 100%);
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#stage canvas {
display: block;
touch-action: none;
outline: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px;
border: 1px solid rgba(121, 231, 255, 0.28);
border-radius: 3px;
background: rgba(5, 10, 13, 0.82);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.28);
color: #b9c9cc;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 180ms ease, border-color 180ms ease, color 180ms ease;
}
.world-label b {
color: var(--cyan);
font-size: 9px;
letter-spacing: 0.04em;
}
.world-label.source {
border-color: rgba(121, 231, 255, 0.6);
color: var(--cyan);
}
.world-label.receiver {
border-color: rgba(255, 189, 115, 0.6);
color: var(--amber);
}
.world-label.receiver b {
color: var(--amber);
}
.world-label.active {
opacity: 1;
border-color: currentColor;
color: #efffff;
background: rgba(5, 10, 13, 0.94);
}
.world-label:not(.active):not(.source):not(.receiver) {
opacity: 0.46;
}
#header {
position: fixed;
z-index: 4;
top: 22px;
left: 24px;
max-width: min(670px, calc(100vw - 440px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
content: "";
background: var(--cyan);
box-shadow: 0 0 14px rgba(121, 231, 255, 0.85);
}
h1 {
margin: 0;
font-size: clamp(27px, 3.5vw, 47px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
margin: 12px 0 0;
color: #a8b9bd;
font-size: 13px;
line-height: 1.5;
}
.header-tags {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 15px;
}
.tag {
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(11, 18, 22, 0.68);
color: #aebfc2;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.tag.illustrative {
border-color: rgba(255, 189, 115, 0.34);
color: var(--amber);
}
#panel {
position: fixed;
z-index: 5;
top: 20px;
right: 20px;
bottom: 20px;
width: 365px;
overflow: auto;
padding: 20px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #31434a transparent;
}
.section-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.section-kicker {
color: var(--cyan);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.section-number {
color: #56686e;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
h2 {
margin: 0;
font-size: 17px;
font-weight: 680;
letter-spacing: -0.02em;
}
.section-copy {
margin: 0 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.path-list {
display: grid;
gap: 7px;
}
.path-row {
width: 100%;
padding: 11px 11px 10px;
border: 1px solid rgba(214, 233, 238, 0.1);
border-left: 3px solid var(--path-color);
border-radius: 4px;
background: rgba(255, 255, 255, 0.025);
text-align: left;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.path-row:hover {
background: rgba(255, 255, 255, 0.055);
transform: translateX(-2px);
}
.path-row.selected {
border-top-color: color-mix(in srgb, var(--path-color), transparent 50%);
border-right-color: color-mix(in srgb, var(--path-color), transparent 50%);
border-bottom-color: color-mix(in srgb, var(--path-color), transparent 50%);
background: color-mix(in srgb, var(--path-color) 9%, transparent);
}
.path-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.path-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 10px;
font-weight: 830;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.path-dot {
width: 7px;
height: 7px;
background: var(--path-color);
box-shadow: 0 0 10px color-mix(in srgb, var(--path-color), transparent 30%);
}
.path-code {
color: #677a80;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.path-route {
margin: 6px 0 8px;
color: #82949a;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.path-metrics {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
}
.metric small {
display: block;
margin-bottom: 2px;
color: #607278;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
color: #dce9e9;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
font-weight: 600;
}
.metric strong.accent {
color: var(--path-color);
}
.divider {
height: 1px;
margin: 20px 0;
background: var(--line);
}
.chart-wrap {
position: relative;
height: 132px;
margin: 6px 0 8px;
overflow: hidden;
border: 1px solid rgba(214, 233, 238, 0.09);
border-radius: 4px;
background:
linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
rgba(0, 0, 0, 0.12);
background-size: 25% 25%, 12.5% 100%;
}
#tailChart {
display: block;
width: 100%;
height: 100%;
}
.chart-legend {
display: flex;
flex-wrap: wrap;
gap: 13px;
color: #8b9ca1;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-line {
width: 17px;
height: 2px;
background: var(--cyan);
}
.legend-line.tail {
height: 0;
border-top: 2px dashed var(--amber);
background: none;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 15px;
}
.stat {
min-width: 0;
padding: 10px 8px;
border: 1px solid rgba(255, 189, 115, 0.14);
border-radius: 4px;
background: rgba(255, 189, 115, 0.04);
}
.stat span {
display: block;
color: #718389;
font-size: 7px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 5px;
color: var(--amber);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
font-weight: 600;
}
.note {
margin-top: 14px;
padding: 11px 12px;
border: 1px solid rgba(255, 189, 115, 0.18);
border-radius: 4px;
background: rgba(255, 189, 115, 0.045);
color: #9c9e93;
font-size: 9px;
line-height: 1.55;
}
.note b {
color: #d6c29e;
}
.toggles {
display: flex;
flex-wrap: wrap;
gap: 13px;
margin-top: 16px;
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
color: #8fa1a6;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
user-select: none;
}
.toggle input {
width: 12px;
height: 12px;
margin: 0;
accent-color: var(--cyan);
}
.controls-note {
margin-top: 15px;
color: #556a70;
font-size: 8px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#timeline {
position: fixed;
z-index: 5;
left: 24px;
right: 405px;
bottom: 20px;
padding: 13px 16px 14px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(8, 14, 18, 0.82);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(15px);
}
.timeline-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 12px;
}
.transport {
display: flex;
align-items: center;
gap: 8px;
}
.transport button {
display: grid;
width: 31px;
height: 31px;
padding: 0;
place-items: center;
border: 1px solid rgba(121, 231, 255, 0.3);
border-radius: 4px;
background: rgba(121, 231, 255, 0.07);
color: var(--cyan);
cursor: pointer;
}
.transport button:hover {
background: rgba(121, 231, 255, 0.14);
}
.transport button.reset {
border-color: var(--line);
background: transparent;
color: #7f9298;
font-size: 13px;
}
.time-readout {
min-width: 80px;
color: #dce9eb;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
}
.timeline-title {
color: #788b91;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
text-align: right;
}
.track {
position: relative;
height: 22px;
border-bottom: 1px solid rgba(214, 233, 238, 0.16);
cursor: crosshair;
}
.track::before {
position: absolute;
right: 0;
bottom: 6px;
left: 0;
height: 1px;
content: "";
background: rgba(214, 233, 238, 0.12);
}
.progress {
position: absolute;
bottom: 6px;
left: 0;
width: 0;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(121, 231, 255, 0.45);
}
.cursor {
position: absolute;
bottom: 0;
left: 0;
width: 1px;
height: 18px;
background: #ecffff;
box-shadow: 0 0 8px rgba(121, 231, 255, 0.75);
}
.tick {
position: absolute;
bottom: -1px;
width: 1px;
height: 5px;
background: #506168;
}
.tick-label {
position: absolute;
bottom: -17px;
color: #53666c;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 7px;
transform: translateX(-50%);
}
.event-marker {
position: absolute;
bottom: 8px;
width: 7px;
height: 7px;
border: 1px solid var(--event-color);
background: #091015;
cursor: pointer;
transform: translateX(-50%) rotate(45deg);
}
.event-marker:hover {
background: var(--event-color);
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #091015;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
#header {
max-width: calc(100vw - 365px);
}
#panel {
width: 330px;
}
#timeline {
right: 365px;
}
}
@media (max-width: 680px) {
#header {
top: 15px;
left: 15px;
max-width: calc(100vw - 30px);
}
h1 {
max-width: 430px;
font-size: 29px;
}
.subtitle {
max-width: 440px;
font-size: 11px;
}
#panel {
top: 118px;
right: 12px;
bottom: 91px;
width: min(330px, calc(100vw - 24px));
padding: 15px;
}
#timeline {
right: 12px;
bottom: 12px;
left: 12px;
}
.timeline-title {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels"></div>
<header id="header">
<div class="eyebrow">Spatial acoustics / voxel study 04</div>
<h1>Echoes inside a voxel cave</h1>
<p class="subtitle">
Follow discrete source–surface–receiver paths, then compare them with
the statistically diffuse reverberant field.
</p>
<div class="header-tags">
<span class="tag">Sound speed · 343 m/s</span>
<span class="tag illustrative">Illustrative geometry</span>
<span class="tag">Drag to orbit · wheel to zoom</span>
</div>
</header>
<aside id="panel">
<div class="section-head">
<div>
<div class="section-kicker">Deterministic paths</div>
<h2>Geometric echoes</h2>
</div>
<div class="section-number">01</div>
</div>
<p class="section-copy">
Each colored line is one drawn source–surface–receiver polyline.
Distance is the total path length; echo delay is measured relative to the direct arrival.
</p>
<div id="pathList" class="path-list"></div>
<div class="divider"></div>
<div class="section-head">
<div>
<div class="section-kicker">Statistical diffuse field</div>
<h2>Realistic reverberation</h2>
</div>
<div class="section-number">02</div>
</div>
<p class="section-copy">
Real rooms contain hundreds of overlapping reflections. The scattered
amber voxels and dashed energy curve represent a diffuse decay rather than individual traced rays.
</p>
<div class="chart-wrap">
<canvas id="tailChart"></canvas>
</div>
<div class="chart-legend">
<span class="legend-item"><i class="legend-line"></i> Geometric stems</span>
<span class="legend-item"><i class="legend-line tail"></i> Diffuse tail</span>
</div>
<div class="stats">
<div class="stat">
<span>RT60</span>
<strong>1.4 s</strong>
</div>
<div class="stat">
<span>Critical dist.</span>
<strong>2.6 m</strong>
</div>
<div class="stat">
<span>Direct / reverb</span>
<strong>−5.8 dB</strong>
</div>
</div>
<div class="note">
<b>Model note:</b> The marked paths are illustrative polylines, not a
calibrated image-source solution. Geometric echoes and diffuse
reverberation are deliberately visualized as separate layers.
</div>
<div class="toggles">
<label class="toggle">
<input id="togglePaths" type="checkbox" checked>
Geometric paths
</label>
<label class="toggle">
<input id="toggleTail" type="checkbox" checked>
Diffuse field
</label>
</div>
<div class="controls-note">
Shift-drag to pan · Select a line or metric row
</div>
</aside>
<section id="timeline">
<div class="timeline-top">
<div class="transport">
<button id="playButton" aria-label="Pause simulation">❚❚</button>
<button id="resetButton" class="reset" aria-label="Reset simulation">↺</button>
<div id="timeReadout" class="time-readout">0.0 ms</div>
</div>
<div class="timeline-title">Acoustic time · 25× slow motion</div>
</div>
<div id="timeTrack" class="track">
<div id="progress" class="progress"></div>
<div id="cursor" class="cursor"></div>
<div id="eventMarkers"></div>
</div>
</section>
<div id="loading">Building voxel chamber…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const SPEED_OF_SOUND = 343;
const TIMELINE_MAX_MS = 200;
const VISUAL_TIME_RATE = 40; // simulation milliseconds per real second
const RT60_SECONDS = 1.4;
const stage = document.getElementById("stage");
const labelsRoot = document.getElementById("labels");
const pathList = document.getElementById("pathList");
const tailChart = document.getElementById("tailChart");
const timeTrack = document.getElementById("timeTrack");
const progress = document.getElementById("progress");
const cursor = document.getElementById("cursor");
const eventMarkers = document.getElementById("eventMarkers");
const timeReadout = document.getElementById("timeReadout");
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
// ------------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091015);
scene.fog = new THREE.FogExp2(0x091015, 0.021);
const camera = new THREE.PerspectiveCamera(
47,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.6, 3.2, -1.1);
let cameraTheta = 0.35;
let cameraPhi = 1.22;
let cameraRadius = 24;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xa8c7d0, 0x2a1c13, 1.85);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe1b8, 3.2);
keyLight.position.set(7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 16;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6ca4c7, 1.15);
rimLight.position.set(-10, 7, -8);
scene.add(rimLight);
// ------------------------------------------------------------------
// Deterministic random helper
// ------------------------------------------------------------------
let randomSeed = 481516;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function between(min, max) {
return min + (max - min) * random();
}
function shadeColor(hex, lightnessOffset = 0) {
const color = new THREE.Color(hex);
color.offsetHSL(between(-0.015, 0.015), between(-0.03, 0.03), lightnessOffset);
return color;
}
// ------------------------------------------------------------------
// Voxel cave construction
// ------------------------------------------------------------------
const caveBlocks = [];
function addBlock(x, y, z, sx, sy, sz, color) {
caveBlocks.push({
position: new THREE.Vector3(x, y, z),
scale: new THREE.Vector3(sx, sy, sz),
color: shadeColor(color)
});
}
// Floor.
for (let x = -10; x <= 10; x++) {
for (let z = -7; z <= 7; z++) {
addBlock(
x + between(-0.05, 0.05),
between(-0.26, -0.17),
z + between(-0.05, 0.05),
between(0.94, 0.99),
between(0.34, 0.46),
between(0.94, 0.99),
z % 3 === 0 ? 0x40342b : 0x493b31
);
}
}
// Rear wall, with a slightly irregular rock face.
for (let x = -10; x <= 10; x++) {
for (let y = 0; y <= 8; y++) {
if (y > 7 && Math.abs(x) > 8) continue;
addBlock(
x + between(-0.07, 0.07),
y + 0.42 + between(-0.08, 0.08),
-7.7 + between(-0.08, 0.22),
between(0.92, 0.99),
between(0.91, 0.98),
between(0.62, 0.88),
(x + y) % 4 === 0 ? 0x594333 : 0x66503c
);
}
}
// Left wall.
for (let z = -7; z <= 6; z++) {
for (let y = 0; y <= 7; y++) {
addBlock(
-9.75 + between(-0.18, 0.08),
y + 0.43 + between(-0.06, 0.06),
z + between(-0.06, 0.06),
between(0.65, 0.9),
between(0.91, 0.98),
between(0.92, 0.99),
(z + y) % 3 === 0 ? 0x574435 : 0x604b39
);
}
}
// Right wall is cut away near the front for a clear cutaway view.
for (let z = -7; z <= 3; z++) {
for (let y = 0; y <= 7; y++) {
addBlock(
9.75 + between(-0.08, 0.18),
y + 0.43 + between(-0.06, 0.06),
z + between(-0.06, 0.06),
between(0.65, 0.9),
between(0.91, 0.98),
between(0.92, 0.99),
(z + y) % 3 === 0 ? 0x503e32 : 0x5c4737
);
}
}
// Arched ceiling / roof.
for (let x = -9; x <= 9; x++) {
for (let z = -6; z <= 2; z++) {
const arch = 0.8 * (1 - Math.abs(x) / 10);
addBlock(
x + between(-0.06, 0.06),
8.55 + arch + between(-0.08, 0.08),
z + between(-0.06, 0.06),
between(0.92, 0.99),
between(0.55, 0.75),
between(0.92, 0.99),
(x + z) % 4 === 0 ? 0x3e342c : 0x493a30
);
}
}
const caveMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
metalness: 0.01
}),
caveBlocks.length
);
const dummy = new THREE.Object3D();
caveBlocks.forEach((block, index) => {
dummy.position.copy(block.position);
dummy.scale.copy(block.scale);
dummy.rotation.set(
between(-0.012, 0.012),
between(-0.012, 0.012),
between(-0.012, 0.012)
);
dummy.updateMatrix();
caveMesh.setMatrixAt(index, dummy.matrix);
caveMesh.setColorAt(index, block.color);
});
caveMesh.instanceMatrix.needsUpdate = true;
caveMesh.instanceColor.needsUpdate = true;
caveMesh.castShadow = true;
caveMesh.receiveShadow = true;
caveMesh.computeBoundingSphere();
scene.add(caveMesh);
// ------------------------------------------------------------------
// Source and receiver models
// ------------------------------------------------------------------
const sourcePosition = new THREE.Vector3(-4.8, 1.35, -1.2);
const receiverPosition = new THREE.Vector3(4.4, 1.15, 2.1);
function makeVoxelModel(position, accentColor, isSource) {
const group = new THREE.Group();
group.position.copy(position);
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x20282a,
roughness: 0.72,
metalness: 0.25
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: accentColor,
emissive: accentColor,
emissiveIntensity: isSource ? 2.4 : 1.5,
roughness: 0.34,
metalness: 0.12
});
const base = new THREE.Mesh(new THREE.BoxGeometry(1.1, 0.18, 1.1), darkMaterial);
base.position.y = -1.23;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const stem = new THREE.Mesh(new THREE.BoxGeometry(0.52, 0.9, 0.52), darkMaterial);
stem.position.y = -0.68;
stem.castShadow = true;
group.add(stem);
const head = new THREE.Mesh(
new THREE.BoxGeometry(isSource ? 0.72 : 0.84, 0.62, isSource ? 0.72 : 0.32),
accentMaterial
);
head.position.y = 0;
head.castShadow = true;
group.add(head);
if (isSource) {
const tip = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.28, 0.3), accentMaterial);
tip.position.y = 0.44;
group.add(tip);
} else {
const receiverFace = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.35, 0.06),
new THREE.MeshBasicMaterial({ color: 0xffd39c })
);
receiverFace.position.z = 0.19;
group.add(receiverFace);
}
scene.add(group);
return group;
}
makeVoxelModel(sourcePosition, 0x79e7ff, true);
makeVoxelModel(receiverPosition, 0xffbd73, false);
const sourceLight = new THREE.PointLight(0x54dfff, 24, 11, 2);
sourceLight.position.copy(sourcePosition).add(new THREE.Vector3(0, 0.25, 0));
scene.add(sourceLight);
const receiverLight = new THREE.PointLight(0xffaa55, 12, 7, 2);
receiverLight.position.copy(receiverPosition).add(new THREE.Vector3(0, 0.2, 0));
scene.add(receiverLight);
// ------------------------------------------------------------------
// Illustrative geometric echo paths
// ------------------------------------------------------------------
const pathDefinitions = [
{
name: "Direct",
code: "P01",
route: "S → R",
color: 0x79e7ff,
points: [sourcePosition.clone(), receiverPosition.clone()]
},
{
name: "Floor",
code: "P02",
route: "S → floor → R",
color: 0x70e0a6,
points: [
sourcePosition.clone(),
new THREE.Vector3(-0.9, 0.08, -3.5),
receiverPosition.clone()
]
},
{
name: "Back wall",
code: "P03",
route: "S → rear wall → R",
color: 0xba9cff,
points: [
sourcePosition.clone(),
new THREE.Vector3(-0.8, 4.0, -6.85),
receiverPosition.clone()
]
},
{
name: "Ceiling",
code: "P04",
route: "S → roof → R",
color: 0xffbd73,
points: [
sourcePosition.clone(),
new THREE.Vector3(0.2, 7.7, -1.5),
receiverPosition.clone()
]
},
{
name: "Right wall",
code: "P05",
route: "S → side wall → R",
color: 0xff7f91,
points: [
sourcePosition.clone(),
new THREE.Vector3(9.0, 2.8, 0.1),
receiverPosition.clone()
]
}
];
const pickables = [];
const worldLabels = [];
const paths = [];
const zAxis = new THREE.Vector3(0, 0, 1);
const tempDirection = new THREE.Vector3();
function addWorldLabel(position, html, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
labelsRoot.appendChild(element);
const entry = {
element,
position: position.clone(),
pathIndex: null
};
worldLabels.push(entry);
return entry;
}
function makeBeam(a, b, material, pathIndex) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const midpoint = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const beam = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.055, length),
material
);
beam.position.copy(midpoint);
beam.quaternion.setFromUnitVectors(zAxis, direction.clone().normalize());
beam.userData.pathIndex = pathIndex;
return beam;
}
function makeVoxelMarker(position, color, pathIndex) {
const group = new THREE.Group();
group.position.copy(position);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92
});
const center = new THREE.Mesh(new THREE.BoxGeometry(0.34, 0.34, 0.34), material);
group.add(center);
const offsets = [
[0.29, 0, 0],
[-0.29, 0, 0],
[0, 0.29, 0],
[0, -0.29, 0],
[0, 0, 0.29],
[0, 0, -0.29]
];
for (const offset of offsets) {
const cube = new THREE.Mesh(new THREE.BoxGeometry(0.13, 0.13, 0.13), material);
cube.position.set(...offset);
group.add(cube);
}
group.traverse((object) => {
if (object.isMesh) object.userData.pathIndex = pathIndex;
});
return group;
}
function makePulse(color) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({ color });
const offsets = [
[0, 0, 0],
[0.19, 0, 0],
[-0.19, 0, 0],
[0, 0.19, 0],
[0, -0.19, 0],
[0, 0, 0.19],
[0, 0, -0.19]
];
for (const offset of offsets) {
const cube = new THREE.Mesh(new THREE.BoxGeometry(0.13, 0.13, 0.13), material);
cube.position.set(...offset);
group.add(cube);
}
return group;
}
function polylineLength(points) {
let length = 0;
for (let i = 0; i < points.length - 1; i++) {
length += points[i].distanceTo(points[i + 1]);
}
return length;
}
pathDefinitions.forEach((definition, index) => {
const group = new THREE.Group();
scene.add(group);
const lineMaterial = new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.3,
depthWrite: false
});
const length = polylineLength(definition.points);
for (let segment = 0; segment < definition.points.length - 1; segment++) {
const a = definition.points[segment];
const b = definition.points[segment + 1];
const beam = makeBeam(a, b, lineMaterial, index);
group.add(beam);
pickables.push(beam);
const segmentLength = a.distanceTo(b);
const dotCount = Math.max(1, Math.floor(segmentLength / 1.05));
for (let dot = 0; dot < dotCount; dot++) {
const t = (dot + 0.5) / dotCount;
const position = new THREE.Vector3().lerpVectors(a, b, t);
const voxel = new THREE.Mesh(
new THREE.BoxGeometry(0.105, 0.105, 0.105),
lineMaterial
);
voxel.position.copy(position);
voxel.userData.pathIndex = index;
group.add(voxel);
pickables.push(voxel);
}
}
const pulse = makePulse(definition.color);
group.add(pulse);
let marker = null;
let markerLabel = null;
if (definition.points.length === 3) {
marker = makeVoxelMarker(definition.points[1], definition.color, index);
group.add(marker);
pickables.push(...marker.children);
const arrivalMs = (length / SPEED_OF_SOUND) * 1000;
const directMs = (polylineLength(pathDefinitions[0].points) / SPEED_OF_SOUND) * 1000;
const relativeDelay = arrivalMs - directMs;
markerLabel = addWorldLabel(
definition.points[1].clone().add(new THREE.Vector3(0, 0.72, 0)),
`<span>${definition.name.toUpperCase()}</span><b>+${relativeDelay.toFixed(1)} ms</b>`
);
markerLabel.pathIndex = index;
}
paths.push({
...definition,
group,
lineMaterial,
pulse,
marker,
markerLabel,
length,
arrivalMs: (length / SPEED_OF_SOUND) * 1000,
bounceArrivalMs:
definition.points.length === 3
? (definition.points[0].distanceTo(definition.points[1]) /
SPEED_OF_SOUND) *
1000
: 0
});
});
const directArrivalMs = paths[0].arrivalMs;
paths.forEach((path) => {
path.delayMs = path.arrivalMs - directArrivalMs;
});
addWorldLabel(
sourcePosition.clone().add(new THREE.Vector3(0, 1.2, 0)),
"<span>TRANSMITTER</span><b>S</b>",
"source"
);
addWorldLabel(
receiverPosition.clone().add(new THREE.Vector3(0, 1.15, 0)),
"<span>RECEIVER</span><b>R</b>",
"receiver"
);
// ------------------------------------------------------------------
// Source wavefront: three orthogonal voxel rings
// ------------------------------------------------------------------
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0x79e7ff,
transparent: true,
opacity: 0.6,
depthWrite: false
});
const sourceRipple = new THREE.Group();
const rippleCubes = [];
for (let axis = 0; axis < 3; axis++) {
for (let i = 0; i < 18; i++) {
const angle = (i / 18) * Math.PI * 2;
let unit;
if (axis === 0) {
unit = new THREE.Vector3(Math.cos(angle), 0, Math.sin(angle));
} else if (axis === 1) {
unit = new THREE.Vector3(Math.cos(angle), Math.sin(angle), 0);
} else {
unit = new THREE.Vector3(0, Math.cos(angle), Math.sin(angle));
}
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.085, 0.085, 0.085),
rippleMaterial
);
sourceRipple.add(cube);
rippleCubes.push({ cube, unit });
}
}
scene.add(sourceRipple);
// Receiver arrival flash.
const receiverFlash = new THREE.Group();
const receiverFlashMaterial = new THREE.MeshBasicMaterial({
color: 0xffd096,
transparent: true,
opacity: 0.8,
depthWrite: false
});
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.13, 0.13),
receiverFlashMaterial
);
cube.position.set(
Math.cos(angle) * 0.58,
Math.sin(angle) * 0.58,
Math.sin(angle * 2) * 0.12
);
receiverFlash.add(cube);
}
receiverFlash.position.copy(receiverPosition);
scene.add(receiverFlash);
// ------------------------------------------------------------------
// Statistical diffuse reverberation field
// ------------------------------------------------------------------
const particleCount = 150;
const diffuseMaterial = new THREE.MeshBasicMaterial({
color: 0xffb56b,
transparent: true,
opacity: 0.56,
depthWrite: false
});
const diffuseMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
diffuseMaterial,
particleCount
);
diffuseMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
diffuseMesh.frustumCulled = false;
const diffuseParticles = [];
for (let i = 0; i < particleCount; i++) {
diffuseParticles.push({
position: new THREE.Vector3(
between(-8.5, 8.5),
between(0.35, 7.7),
between(-6.4, 5.2)
),
delayMs: between(24, 195),
size: between(0.045, 0.105),
phase: between(0, Math.PI * 2),
color: new THREE.Color().setHSL(
between(0.075, 0.12),
between(0.55, 0.88),
between(0.55, 0.72)
)
});
diffuseMesh.setColorAt(i, diffuseParticles[i].color);
}
scene.add(diffuseMesh);
// ------------------------------------------------------------------
// UI construction
// ------------------------------------------------------------------
paths.forEach((path, index) => {
const row = document.createElement("button");
row.type = "button";
row.className = "path-row";
row.style.setProperty("--path-color", `#${path.color.toString(16).padStart(6, "0")}`);
row.dataset.index = index;
row.innerHTML = `
<div class="path-top">
<div class="path-name">
<i class="path-dot"></i>
${path.name}
</div>
<div class="path-code">${path.code}</div>
</div>
<div class="path-route">${path.route}</div>
<div class="path-metrics">
<div class="metric">
<small>Path</small>
<strong>${path.length.toFixed(1)} m</strong>
</div>
<div class="metric">
<small>Arrival</small>
<strong>${path.arrivalMs.toFixed(1)} ms</strong>
</div>
<div class="metric">
<small>Echo</small>
<strong class="accent">+${path.delayMs.toFixed(1)} ms</strong>
</div>
</div>
`;
row.addEventListener("click", () => selectPath(index));
pathList.appendChild(row);
const marker = document.createElement("div");
marker.className = "event-marker";
marker.style.left = `${(path.arrivalMs / TIMELINE_MAX_MS) * 100}%`;
marker.style.setProperty("--event-color", `#${path.color.toString(16).padStart(6, "0")}`);
marker.title = `${path.name}: ${path.arrivalMs.toFixed(1)} ms`;
marker.addEventListener("click", () => selectPath(index));
eventMarkers.appendChild(marker);
});
for (let tick = 0; tick <= TIMELINE_MAX_MS; tick += 50) {
const element = document.createElement("div");
element.className = "tick";
element.style.left = `${(tick / TIMELINE_MAX_MS) * 100}%`;
timeTrack.appendChild(element);
const label = document.createElement("div");
label.className = "tick-label";
label.style.left = `${(tick / TIMELINE_MAX_MS) * 100}%`;
label.textContent = tick;
timeTrack.appendChild(label);
}
let selectedPathIndex = 1;
let showPaths = true;
let showDiffuse = true;
let playing = true;
let simulationMs = 0;
function selectPath(index) {
selectedPathIndex = index;
[...pathList.children].forEach((row, rowIndex) => {
row.classList.toggle("selected", rowIndex === index);
});
paths.forEach((path, pathIndex) => {
path.lineMaterial.opacity = pathIndex === index ? 0.92 : 0.27;
if (path.marker) {
path.marker.scale.setScalar(pathIndex === index ? 1.14 : 0.82);
}
if (path.markerLabel) {
path.markerLabel.element.classList.toggle("active", pathIndex === index);
}
});
}
selectPath(selectedPathIndex);
document.getElementById("togglePaths").addEventListener("change", (event) => {
showPaths = event.target.checked;
paths.forEach((path) => {
path.group.visible = showPaths;
});
});
document.getElementById("toggleTail").addEventListener("change", (event) => {
showDiffuse = event.target.checked;
diffuseMesh.visible = showDiffuse;
});
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "❚❚" : "▶";
playButton.setAttribute(
"aria-label",
playing ? "Pause simulation" : "Play simulation"
);
});
resetButton.addEventListener("click", () => {
simulationMs = 0;
});
timeTrack.addEventListener("pointerdown", (event) => {
const rect = timeTrack.getBoundingClientRect();
const fraction = THREE.MathUtils.clamp(
(event.clientX - rect.left) / rect.width,
0,
1
);
simulationMs = fraction * TIMELINE_MAX_MS;
});
// ------------------------------------------------------------------
// Custom camera controls: orbit, zoom, and pan
// ------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const rightVector = new THREE.Vector3();
const upVector = new THREE.Vector3();
let dragging = false;
let dragMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
let pointerId = null;
let panning = false;
function updatePointer(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;
}
function pathAtPointer(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
return hits.length ? hits[0].object.userData.pathIndex : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
pointerId = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
panning = event.shiftKey || event.button === 2;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) {
const pathIndex = pathAtPointer(event);
renderer.domElement.style.cursor =
pathIndex === null ? "grab" : "pointer";
return;
}
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
if (panning) {
camera.updateMatrixWorld();
const elements = camera.matrixWorld.elements;
rightVector.set(elements[0], elements[1], elements[2]).normalize();
upVector.set(elements[4], elements[5], elements[6]).normalize();
const panScale = cameraRadius * 0.00135;
cameraTarget.addScaledVector(rightVector, -dx * panScale);
cameraTarget.addScaledVector(upVector, dy * panScale);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -6, 6);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, 1, 6);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -5, 4);
} else {
cameraTheta -= dx * 0.0055;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.0045, 0.58, 1.47);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragMoved) {
const pathIndex = pathAtPointer(event);
if (pathIndex !== null) selectPath(pathIndex);
}
dragging = false;
panning = false;
pointerId = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
panning = false;
pointerId = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
13,
38
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// ------------------------------------------------------------------
// Path animation helpers
// ------------------------------------------------------------------
function pointAlongPolyline(points, fraction) {
const targetDistance = polylineLength(points) * fraction;
let traversed = 0;
for (let i = 0; i < points.length - 1; i++) {
const segmentLength = points[i].distanceTo(points[i + 1]);
if (traversed + segmentLength >= targetDistance) {
const localDistance = targetDistance - traversed;
return new THREE.Vector3().lerpVectors(
points[i],
points[i + 1],
segmentLength === 0 ? 0 : localDistance / segmentLength
);
}
traversed += segmentLength;
}
return points[points.length - 1].clone();
}
function updateDiffuseField() {
if (!showDiffuse) return;
diffuseParticles.forEach((particle, index) => {
const arrived = simulationMs >= particle.delayMs;
if (!arrived) {
dummy.position.copy(particle.position);
dummy.scale.setScalar(0);
} else {
const decay = Math.pow(10, (-3 * particle.delayMs) / (RT60_SECONDS * 1000));
const flicker = 0.78 + 0.22 * Math.sin(simulationMs * 0.08 + particle.phase);
const scale = particle.size * (0.55 + decay) * flicker;
dummy.position.copy(particle.position);
dummy.position.y += Math.sin(simulationMs * 0.025 + particle.phase) * 0.08;
dummy.scale.set(scale, scale, scale);
}
dummy.rotation.set(
particle.phase * 0.1,
simulationMs * 0.002 + particle.phase,
0
);
dummy.updateMatrix();
diffuseMesh.setMatrixAt(index, dummy.matrix);
});
diffuseMesh.instanceMatrix.needsUpdate = true;
}
// ------------------------------------------------------------------
// Energy-time chart
// ------------------------------------------------------------------
function drawTailChart() {
const width = tailChart.clientWidth;
const height = tailChart.clientHeight;
const dpr = Math.min(window.devicePixelRatio, 2);
if (
tailChart.width !== Math.round(width * dpr) ||
tailChart.height !== Math.round(height * dpr)
) {
tailChart.width = Math.round(width * dpr);
tailChart.height = Math.round(height * dpr);
}
const context = tailChart.getContext("2d");
context.setTransform(dpr, 0, 0, dpr, 0, 0);
context.clearRect(0, 0, width, height);
const left = 27;
const right = 8;
const top = 11;
const bottom = 24;
const chartWidth = width - left - right;
const chartHeight = height - top - bottom;
const xFor = (ms) => left + (ms / TIMELINE_MAX_MS) * chartWidth;
const yFor = (db) => top + ((0 - db) / 60) * chartHeight;
context.font = "8px ui-monospace, monospace";
context.fillStyle = "#52666d";
context.strokeStyle = "rgba(214,233,238,0.075)";
context.lineWidth = 1;
for (const db of [0, -20, -40, -60]) {
const y = yFor(db);
context.beginPath();
context.moveTo(left, y);
context.lineTo(width - right, y);
context.stroke();
context.fillText(`${db}`, 3, y + 3);
}
for (let ms = 0; ms <= TIMELINE_MAX_MS; ms += 50) {
const x = xFor(ms);
context.fillStyle = "#52666d";
context.fillText(`${ms}`, x - 6, height - 6);
}
// Geometric arrivals are shown as stems.
const labels = ["D", "F", "B", "C", "W"];
paths.forEach((path, index) => {
const x = xFor(path.arrivalMs);
const stemHeight = chartHeight * (0.92 - index * 0.1);
context.strokeStyle = `#${path.color.toString(16).padStart(6, "0")}`;
context.globalAlpha = 0.8;
context.beginPath();
context.moveTo(x, top + chartHeight);
context.lineTo(x, top + chartHeight - stemHeight);
context.stroke();
context.fillStyle = context.strokeStyle;
context.fillText(labels[index], x - 2, top + chartHeight - stemHeight - 4);
});
context.globalAlpha = 1;
// Statistical reverberant energy tail.
context.strokeStyle = "#ffbd73";
context.lineWidth = 1.7;
context.setLineDash([5, 4]);
context.beginPath();
for (let ms = 0; ms <= TIMELINE_MAX_MS; ms += 2) {
const seconds = ms / 1000;
const energy = 0.54 * Math.pow(10, (-3 * seconds) / RT60_SECONDS);
const db = 10 * Math.log10(Math.max(energy, 0.0001));
const x = xFor(ms);
const y = yFor(db);
if (ms === 0) context.moveTo(x, y);
else context.lineTo(x, y);
}
context.stroke();
context.setLineDash([]);
// Simulation cursor.
const cursorX = xFor(Math.min(simulationMs, TIMELINE_MAX_MS));
context.strokeStyle = "rgba(236,255,255,0.75)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(cursorX, top);
context.lineTo(cursorX, top + chartHeight);
context.stroke();
context.fillStyle = "#91a5aa";
context.fillText("ms", width - 18, height - 6);
}
// ------------------------------------------------------------------
// HTML label projection
// ------------------------------------------------------------------
function updateWorldLabels() {
worldLabels.forEach((entry) => {
const projected = entry.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
entry.element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
entry.element.style.left = `${x}px`;
entry.element.style.top = `${y}px`;
});
}
// ------------------------------------------------------------------
// Resize
// ------------------------------------------------------------------
function handleResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
drawTailChart();
}
window.addEventListener("resize", handleResize);
// ------------------------------------------------------------------
// Main animation loop
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
simulationMs += delta * VISUAL_TIME_RATE;
if (simulationMs > TIMELINE_MAX_MS) {
simulationMs -= TIMELINE_MAX_MS;
}
}
// Source wavefront.
const rippleRadius = 0.25 + (SPEED_OF_SOUND * simulationMs) / 1000;
const rippleVisible = simulationMs < 33;
sourceRipple.visible = rippleVisible;
rippleMaterial.opacity = 0.68 * (1 - simulationMs / 33);
if (rippleVisible) {
rippleCubes.forEach(({ cube, unit }) => {
cube.position.copy(sourcePosition).addScaledVector(unit, rippleRadius);
cube.rotation.set(
simulationMs * 0.01,
simulationMs * 0.014,
simulationMs * 0.009
);
});
}
// Geometric pulses.
paths.forEach((path) => {
const fraction = THREE.MathUtils.clamp(
simulationMs / path.arrivalMs,
0,
1
);
path.pulse.visible = showPaths && simulationMs <= path.arrivalMs;
path.pulse.position.copy(pointAlongPolyline(path.points, fraction));
path.pulse.rotation.set(
simulationMs * 0.03,
simulationMs * 0.04,
simulationMs * 0.025
);
if (path.marker) {
const bounceDistance = Math.abs(simulationMs - path.bounceArrivalMs);
const bouncePulse = Math.max(0, 1 - bounceDistance / 9);
const selectedScale = path === paths[selectedPathIndex] ? 1.14 : 0.82;
const markerScale = selectedScale + bouncePulse * 0.55;
path.marker.scale.setScalar(markerScale);
}
});
// Receiver flashes at each geometric arrival.
let latestArrival = null;
paths.forEach((path) => {
if (simulationMs >= path.arrivalMs) {
if (!latestArrival || path.arrivalMs > latestArrival.arrivalMs) {
latestArrival = path;
}
}
});
if (latestArrival) {
const sinceArrival = simulationMs - latestArrival.arrivalMs;
const flash = Math.max(0, 1 - sinceArrival / 12);
receiverFlash.visible = flash > 0;
receiverFlash.scale.setScalar(0.8 + flash * 0.9);
receiverFlashMaterial.opacity = flash * 0.85;
} else {
receiverFlash.visible = false;
}
updateDiffuseField();
const progressFraction = simulationMs / TIMELINE_MAX_MS;
progress.style.width = `${progressFraction * 100}%`;
cursor.style.left = `${progressFraction * 100}%`;
timeReadout.textContent = `${simulationMs.toFixed(1)} ms`;
drawTailChart();
updateWorldLabels();
renderer.render(scene, camera);
}
drawTailChart();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => {
document.getElementById("loading").remove();
}, 400);
});
</script>
</body>
</html>
```