Prompt specification
Build or customize the Three.js 3D scene "Receiver follows spoken event" 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: Receiver follows spoken event
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/receiver-follows-spoken-event-x0438
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing hearing assistance systems. Trigger a speaker event and animate a symbolic signal through the loop to a receiver; simultaneously display a caption so the causal sequence remains visible. Voxel style.
Working Three.js Starter (receiver-follows-spoken-event-x0438):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#07111f" />
<title>Hearing Loop — Voxel Signal Demonstration</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(9, 22, 38, 0.88);
--line: rgba(145, 202, 255, 0.22);
--cyan: #55dcff;
--cyan-soft: #bdefff;
--amber: #ffbd59;
--green: #78efb2;
--muted: #829ab2;
--white: #edf7ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--white);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
cursor: grab;
}
.vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(180deg, rgba(3, 9, 17, 0.48), transparent 24%),
linear-gradient(0deg, rgba(3, 9, 17, 0.55), transparent 35%),
radial-gradient(circle at center, transparent 46%, rgba(2, 8, 15, 0.38));
}
.topbar {
position: fixed;
z-index: 10;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 15px;
}
.brand-mark {
width: 39px;
height: 39px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(45deg);
}
.brand-mark span {
display: block;
background: var(--cyan);
box-shadow: 0 0 16px rgba(85, 220, 255, 0.3);
}
.brand-mark span:nth-child(2),
.brand-mark span:nth-child(4),
.brand-mark span:nth-child(8) {
opacity: 0.34;
}
.brand-mark span:nth-child(5) {
background: var(--amber);
}
.eyebrow {
margin: 0 0 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 36px);
line-height: 1;
letter-spacing: 0.07em;
font-weight: 800;
}
.subtitle {
margin: 7px 0 0;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.1em;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.control {
min-height: 42px;
padding: 0 14px;
border: 1px solid var(--line);
background: rgba(8, 20, 35, 0.78);
color: var(--cyan-soft);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease,
transform 150ms ease;
}
.control:hover {
border-color: rgba(85, 220, 255, 0.7);
background: rgba(19, 49, 72, 0.92);
transform: translateY(-1px);
}
.control:focus-visible {
outline: 2px solid var(--amber);
outline-offset: 3px;
}
.control.primary {
display: flex;
align-items: center;
gap: 10px;
min-width: 185px;
justify-content: center;
color: #07111f;
background: var(--cyan);
border-color: var(--cyan);
box-shadow: 0 0 24px rgba(85, 220, 255, 0.18);
}
.control.primary:hover {
background: #8ae8ff;
}
.button-led {
width: 7px;
height: 7px;
background: #07111f;
box-shadow: 0 0 0 3px rgba(7, 17, 31, 0.13);
}
.control.primary.running .button-led {
animation: blink 700ms steps(2, end) infinite;
}
@keyframes blink {
50% {
background: var(--amber);
}
}
.interaction-hint {
position: fixed;
z-index: 4;
top: 102px;
right: 29px;
color: rgba(173, 210, 236, 0.63);
font-size: 9px;
letter-spacing: 0.09em;
pointer-events: none;
}
.scene-label {
position: fixed;
z-index: 4;
left: 0;
top: 0;
padding: 7px 9px;
border-left: 2px solid var(--cyan);
background: rgba(5, 15, 27, 0.78);
color: var(--cyan-soft);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.18);
}
.scene-label::after {
content: "";
display: block;
width: 1px;
height: 14px;
margin-top: 6px;
background: linear-gradient(var(--cyan), transparent);
}
.scene-label.amber {
border-color: var(--amber);
color: #ffe0a8;
}
.scene-label.amber::after {
background: linear-gradient(var(--amber), transparent);
}
.caption-panel {
position: fixed;
z-index: 10;
left: 50%;
bottom: 24px;
width: min(880px, calc(100% - 36px));
transform: translateX(-50%);
padding: 16px 18px 14px;
border: 1px solid var(--line);
background:
linear-gradient(135deg, rgba(13, 34, 53, 0.95), rgba(7, 18, 31, 0.91));
box-shadow:
0 18px 55px rgba(0, 0, 0, 0.38),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(12px);
}
.caption-panel::before,
.caption-panel::after {
content: "";
position: absolute;
width: 9px;
height: 9px;
pointer-events: none;
}
.caption-panel::before {
top: -1px;
left: -1px;
border-top: 2px solid var(--cyan);
border-left: 2px solid var(--cyan);
}
.caption-panel::after {
right: -1px;
bottom: -1px;
border-right: 2px solid var(--amber);
border-bottom: 2px solid var(--amber);
}
.progress-track {
position: absolute;
top: -1px;
left: -1px;
right: -1px;
height: 2px;
overflow: hidden;
background: rgba(85, 220, 255, 0.07);
}
.progress-fill {
width: 100%;
height: 100%;
transform: scaleX(0);
transform-origin: left;
background: linear-gradient(90deg, var(--cyan), var(--amber));
box-shadow: 0 0 12px rgba(85, 220, 255, 0.45);
}
.caption-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.13em;
}
.phase-badge {
color: var(--amber);
font-weight: 900;
}
#captionText {
min-height: 44px;
color: #e8f5ff;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: clamp(13px, 1.6vw, 16px);
line-height: 1.45;
}
.steps {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 13px;
}
.step {
position: relative;
padding: 9px 10px 8px;
border-top: 2px solid rgba(112, 151, 181, 0.22);
color: #647c93;
background: rgba(255, 255, 255, 0.018);
transition:
color 180ms ease,
border-color 180ms ease,
background 180ms ease;
}
.step::after {
content: "";
position: absolute;
top: -4px;
right: -4px;
width: 5px;
height: 5px;
background: transparent;
}
.step.done {
color: #9eb8cc;
border-color: rgba(85, 220, 255, 0.48);
}
.step.active {
color: #07111f;
border-color: var(--cyan);
background: var(--cyan);
}
.step.active::after {
background: var(--amber);
}
.step b {
display: block;
margin-bottom: 3px;
font-size: 10px;
letter-spacing: 0.1em;
}
.step small {
display: block;
font-size: 8px;
letter-spacing: 0.08em;
opacity: 0.72;
}
.loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: var(--bg);
color: var(--cyan);
font-size: 11px;
letter-spacing: 0.18em;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.topbar {
top: 16px;
left: 16px;
right: 16px;
gap: 10px;
}
.brand {
gap: 10px;
}
.brand-mark {
width: 27px;
height: 27px;
}
.eyebrow {
font-size: 8px;
}
h1 {
font-size: 20px;
}
.subtitle,
.interaction-hint {
display: none;
}
.top-actions {
flex-wrap: wrap;
justify-content: flex-end;
}
.control {
min-height: 37px;
padding: 0 9px;
font-size: 8px;
}
.control.primary {
min-width: 140px;
}
.caption-panel {
bottom: 12px;
width: calc(100% - 24px);
padding: 13px 13px 11px;
}
.caption-meta {
font-size: 7px;
}
.steps {
gap: 4px;
}
.step {
padding: 8px 5px 7px;
text-align: center;
}
.step b {
font-size: 8px;
}
.step small {
display: none;
}
.scene-label {
font-size: 7px;
padding: 5px 7px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel hearing assistance system"></canvas>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span><span></span>
</div>
<div>
<p class="eyebrow">ASSISTIVE LISTENING / VISUAL MODEL</p>
<h1>HEARING LOOP</h1>
<p class="subtitle">SOURCE → LOOP → RECEIVER → AUDIBLE OUTPUT</p>
</div>
</div>
<div class="top-actions">
<button class="control" id="audioBtn" type="button" aria-pressed="true">SOUND ON</button>
<button class="control" id="speedBtn" type="button">SPEED 1×</button>
<button class="control primary" id="triggerBtn" type="button">
<span class="button-led"></span>
<span id="triggerText">TRIGGER SPEAKER</span>
</button>
</div>
</header>
<div class="interaction-hint">DRAG TO ORBIT · WHEEL TO ZOOM · CLICK THE SPEAKER</div>
<div class="scene-label" id="sourceLabel">01 / SPEAKER</div>
<div class="scene-label" id="loopLabel">02 / HEARING LOOP</div>
<div class="scene-label amber" id="receiverLabel">03 / RECEIVER</div>
<section class="caption-panel" aria-label="Live causal caption">
<div class="progress-track"><div class="progress-fill" id="progressFill"></div></div>
<div class="caption-meta">
<span class="phase-badge" id="phaseBadge">SYSTEM READY</span>
<span>LIVE CAUSAL CAPTION</span>
<span id="captionCount">00 / 04</span>
</div>
<div id="captionText" aria-live="polite">
Trigger the speaker to begin. The caption will explain each causal step as the symbolic signal travels.
</div>
<div class="steps" aria-label="Causal sequence">
<div class="step" data-step="0">
<b>01 SOURCE</b>
<small>Speaker event</small>
</div>
<div class="step" data-step="1">
<b>02 LOOP</b>
<small>Signal transmission</small>
</div>
<div class="step" data-step="2">
<b>03 RECEIVER</b>
<small>Signal capture</small>
</div>
<div class="step" data-step="3">
<b>04 OUTPUT</b>
<small>Amplified delivery</small>
</div>
</div>
</section>
<div class="loading" id="loading">ASSEMBLING VOXEL HEARING SYSTEM...</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 19, 38);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const orbit = {
yaw: 0.52,
pitch: 0.61,
distance: 20,
target: new THREE.Vector3(0, 0.72, 0)
};
function updateCamera() {
const cp = Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * orbit.distance * cp,
orbit.target.y + Math.sin(orbit.pitch) * orbit.distance,
orbit.target.z + Math.cos(orbit.yaw) * orbit.distance * cp
);
camera.lookAt(orbit.target);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(11.4, 18.8 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9e6ff, 0x0a1322, 1.75));
const keyLight = new THREE.DirectionalLight(0xe7f5ff, 3.4);
keyLight.position.set(7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3b9cff, 1.35);
rimLight.position.set(-10, 6, -8);
scene.add(rimLight);
const sourceLight = new THREE.PointLight(0x4bdcff, 0.25, 7, 2);
sourceLight.position.set(-5.95, 1.35, 0);
scene.add(sourceLight);
const receiverLight = new THREE.PointLight(0xffbd59, 0.2, 6, 2);
receiverLight.position.set(7.35, 1.85, 0);
scene.add(receiverLight);
// -------------------------------------------------------------------------
// Helpers and voxel environment
// -------------------------------------------------------------------------
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.08,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
}
function box(parent, width, height, depth, material, x = 0, y = 0, z = 0) {
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;
}
let randomSeed = 78231;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const world = new THREE.Group();
scene.add(world);
// Raised voxel platform.
const platformMat = makeMaterial(0x101f31, { roughness: 0.9 });
box(world, 22, 0.34, 12.4, platformMat, 0, -0.39, 0);
// Individually colored floor tiles.
const nx = 25;
const nz = 14;
const tileGeometry = new THREE.BoxGeometry(0.78, 0.08, 0.78);
const tileMaterial = makeMaterial(0xffffff, { roughness: 0.94 });
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, nx * nz);
const dummy = new THREE.Object3D();
const tilePalette = [
0x11283b,
0x142d42,
0x173248,
0x193a51,
0x1c4058
];
let tileIndex = 0;
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const x = (ix - (nx - 1) / 2) * 0.86;
const z = (iz - (nz - 1) / 2) * 0.86;
dummy.position.set(x, -0.17, z);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const color = new THREE.Color(
tilePalette[Math.floor(random() * tilePalette.length)]
);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
world.add(tiles);
// Low rear wall and voxel pillars.
const wallMat = makeMaterial(0x0c1b2c, { roughness: 0.95 });
const wallAccentMat = makeMaterial(0x143048, { roughness: 0.85 });
box(world, 22, 2.6, 0.28, wallMat, 0, 1.0, -5.9);
for (let i = 0; i < 11; i++) {
const x = -9.5 + i * 1.9;
const h = 0.22 + random() * 0.34;
box(world, 1.22, h, 0.18, wallAccentMat, x, 2.32, -5.72);
}
for (const x of [-9.8, 9.8]) {
box(world, 0.45, 3.3, 0.55, wallMat, x, 1.3, -5.55);
box(world, 0.62, 0.22, 0.72, wallAccentMat, x, 3.03, -5.55);
}
// -------------------------------------------------------------------------
// Hearing-loop path
// -------------------------------------------------------------------------
const LOOP_RX = 5.8;
const LOOP_RZ = 3.0;
const LOOP_Y = 0.37;
const loopCount = 104;
const loopGeometry = new THREE.BoxGeometry(0.29, 0.11, 0.14);
const loopMaterial = makeMaterial(0xffffff, {
roughness: 0.55,
metalness: 0.2,
emissive: 0x081522,
emissiveIntensity: 0.15
});
const loopMesh = new THREE.InstancedMesh(
loopGeometry,
loopMaterial,
loopCount
);
const loopBaseColor = new THREE.Color(0x29445f);
const loopLiveColor = new THREE.Color(0x36c8f5);
const loopHeadColor = new THREE.Color(0xc7f6ff);
const loopTempColor = new THREE.Color();
for (let i = 0; i < loopCount; i++) {
const angle = (i / loopCount) * Math.PI * 2;
const x = Math.cos(angle) * LOOP_RX;
const z = Math.sin(angle) * LOOP_RZ;
const tangentX = -Math.sin(angle) * LOOP_RX;
const tangentZ = Math.cos(angle) * LOOP_RZ;
dummy.position.set(x, LOOP_Y, z);
dummy.rotation.set(0, -Math.atan2(tangentZ, tangentX), 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
loopMesh.setMatrixAt(i, dummy.matrix);
loopMesh.setColorAt(i, loopBaseColor);
}
loopMesh.instanceMatrix.needsUpdate = true;
if (loopMesh.instanceColor) loopMesh.instanceColor.needsUpdate = true;
loopMesh.castShadow = true;
loopMesh.receiveShadow = true;
world.add(loopMesh);
// Small data motes moving around the complete closed loop.
const moteMaterial = new THREE.MeshBasicMaterial({
color: 0x5bdcff,
transparent: true,
opacity: 0.3
});
const motes = [];
for (let i = 0; i < 20; i++) {
const mote = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.075, 0.075),
moteMaterial
);
mote.userData.angle = (i / 20) * Math.PI * 2;
mote.userData.offset = random() * Math.PI * 2;
world.add(mote);
motes.push(mote);
}
// -------------------------------------------------------------------------
// Voxel loudspeaker
// -------------------------------------------------------------------------
const speaker = new THREE.Group();
speaker.position.set(-6.6, 0, 0);
world.add(speaker);
const speakerBodyMat = makeMaterial(0xe5edf4, { roughness: 0.62 });
const speakerPanelMat = makeMaterial(0x244b68, {
roughness: 0.58,
metalness: 0.12,
emissive: 0x071d2b,
emissiveIntensity: 0.05
});
const speakerDarkMat = makeMaterial(0x091522, { roughness: 0.8 });
const speakerTrimMat = makeMaterial(0x3fdcff, {
roughness: 0.45,
emissive: 0x0a617b,
emissiveIntensity: 0.25
});
box(speaker, 1.65, 0.22, 1.7, speakerDarkMat, 0, 0.02, 0);
box(speaker, 0.58, 0.72, 0.58, speakerBodyMat, 0, 0.48, 0);
box(speaker, 0.92, 1.65, 1.25, speakerBodyMat, 0, 1.55, 0);
box(speaker, 0.08, 1.38, 1.03, speakerPanelMat, 0.49, 1.56, 0);
function addSquareDriver(parent, x, y, size, outerMaterial, innerMaterial) {
const group = new THREE.Group();
group.position.set(x, y, 0);
parent.add(group);
box(group, 0.13, 0.09, size, outerMaterial, 0, size / 2, 0);
box(group, 0.13, 0.09, size, outerMaterial, 0, -size / 2, 0);
box(group, 0.13, size, 0.09, outerMaterial, 0, 0, size / 2);
box(group, 0.13, size, 0.09, outerMaterial, 0, 0, -size / 2);
box(group, 0.16, size * 0.39, size * 0.39, innerMaterial, 0.07, 0, 0);
return group;
}
addSquareDriver(speaker, 0.58, 1.2, 0.58, speakerTrimMat, speakerDarkMat);
addSquareDriver(speaker, 0.58, 1.93, 0.39, speakerTrimMat, speakerDarkMat);
const speakerLedMat = makeMaterial(0x23465b, {
emissive: 0x0b2534,
emissiveIntensity: 0.1
});
box(speaker, 0.11, 0.11, 0.18, speakerLedMat, 0.58, 2.27, 0.38);
// Three expanding square-wave packets from the loudspeaker.
const sourceWaves = [];
const sourceEmitter = new THREE.Vector3(-6.02, 1.3, 0);
for (let i = 0; i < 3; i++) {
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0x67e3ff,
transparent: true,
opacity: 0,
depthWrite: false
});
const wave = new THREE.Group();
const waveSize = 1;
box(wave, 0.035, 0.055, waveSize, waveMaterial, 0, waveSize / 2, 0);
box(wave, 0.035, 0.055, waveSize, waveMaterial, 0, -waveSize / 2, 0);
box(wave, 0.035, waveSize, 0.055, waveMaterial, 0, 0, waveSize / 2);
box(wave, 0.035, waveSize, 0.055, waveMaterial, 0, 0, -waveSize / 2);
world.add(wave);
sourceWaves.push({ group: wave, material: waveMaterial });
}
// -------------------------------------------------------------------------
// Voxel listener and assistive receiver
// -------------------------------------------------------------------------
const listener = new THREE.Group();
listener.position.set(6.9, 0, 0);
world.add(listener);
const skinMat = makeMaterial(0xe8b98d, { roughness: 0.88 });
const jacketMat = makeMaterial(0x245779, { roughness: 0.8 });
const hairMat = makeMaterial(0x27313f, { roughness: 0.95 });
const darkMat = makeMaterial(0x091522, { roughness: 0.85 });
const receiverMat = makeMaterial(0xe6eff7, { roughness: 0.5 });
const receiverAccentMat = makeMaterial(0xffb94f, {
roughness: 0.42,
emissive: 0x6f3908,
emissiveIntensity: 0.15
});
box(listener, 1.55, 0.2, 1.55, darkMat, 0, 0.01, 0);
box(listener, 0.9, 1.15, 0.7, jacketMat, 0, 0.7, 0);
box(listener, 0.33, 0.35, 0.33, skinMat, 0, 1.39, 0);
box(listener, 0.86, 0.9, 0.82, skinMat, 0, 1.91, 0);
box(listener, 0.96, 0.22, 0.91, hairMat, 0, 2.39, -0.02);
box(listener, 0.9, 0.55, 0.2, hairMat, 0, 2.05, -0.38);
box(listener, 0.16, 0.16, 0.13, skinMat, 0, 1.87, 0.48);
box(listener, 0.09, 0.09, 0.05, darkMat, -0.19, 2.04, 0.43);
box(listener, 0.09, 0.09, 0.05, darkMat, 0.19, 2.04, 0.43);
// Ear-level receiver.
box(listener, 0.16, 0.25, 0.23, receiverMat, 0.49, 1.87, 0);
box(listener, 0.13, 0.13, 0.13, receiverAccentMat, 0.59, 1.87, 0);
// Receiver pack clipped near the shoulder.
box(listener, 0.33, 0.58, 0.31, receiverMat, 0.37, 1.35, 0.28);
const receiverLedMat = makeMaterial(0x24475b, {
emissive: 0x071b27,
emissiveIntensity: 0.1
});
box(listener, 0.11, 0.11, 0.07, receiverLedMat, 0.56, 1.43, 0.38);
// Small loop coupler at floor/receiver level.
const couplerX = LOOP_RX - listener.position.x;
box(listener, 0.34, 0.2, 0.38, receiverMat, couplerX, 0.36, 0);
box(listener, 0.16, 0.1, 0.18, receiverAccentMat, couplerX, 0.48, 0);
const loopEnd = new THREE.Vector3(LOOP_RX, 0.43, 0);
const earPoint = new THREE.Vector3(7.39, 1.87, 0);
// Visible receiver-to-ear connection made from voxel blocks.
const outputControl = new THREE.Vector3(6.55, 0.95, 0.34);
function outputPoint(t) {
const q = THREE.MathUtils.clamp(t, 0, 1);
const a = loopEnd.clone();
const b = outputControl;
const c = earPoint;
const x =
(1 - q) * (1 - q) * a.x +
2 * (1 - q) * q * b.x +
q * q * c.x;
const y =
(1 - q) * (1 - q) * a.y +
2 * (1 - q) * q * b.y +
q * q * c.y;
const z =
(1 - q) * (1 - q) * a.z +
2 * (1 - q) * q * b.z +
q * q * c.z;
return new THREE.Vector3(x, y, z);
}
const outputCubes = [];
const outputCubeCount = 11;
for (let i = 0; i < outputCubeCount; i++) {
const t = i / (outputCubeCount - 1);
const material = new THREE.MeshBasicMaterial({
color: 0xffbd59,
transparent: true,
opacity: 0.08,
depthWrite: false
});
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.105, 0.105, 0.105),
material
);
cube.position.copy(outputPoint(t));
world.add(cube);
outputCubes.push(cube);
}
// -------------------------------------------------------------------------
// Symbolic signal packet and trail
// -------------------------------------------------------------------------
const signalGroup = new THREE.Group();
world.add(signalGroup);
const signalCoreMat = makeMaterial(0x5be4ff, {
roughness: 0.2,
metalness: 0.35,
emissive: 0x20bfe9,
emissiveIntensity: 1.4
});
const signalCornerMat = makeMaterial(0xe9fbff, {
roughness: 0.35,
emissive: 0x64dfff,
emissiveIntensity: 0.55
});
const signalCore = box(
signalGroup,
0.33,
0.33,
0.33,
signalCoreMat,
0,
0,
0
);
for (const x of [-1, 1]) {
for (const y of [-1, 1]) {
for (const z of [-1, 1]) {
box(
signalGroup,
0.095,
0.095,
0.095,
signalCornerMat,
x * 0.23,
y * 0.23,
z * 0.23
);
}
}
}
const trail = [];
for (let i = 0; i < 10; i++) {
const material = new THREE.MeshBasicMaterial({
color: i % 2 === 0 ? 0x45d9ff : 0x278eb7,
transparent: true,
opacity: 0.32 * (1 - i / 10),
depthWrite: false
});
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.15, 0.15),
material
);
cube.visible = false;
world.add(cube);
trail.push(cube);
}
const outputPulseMaterial = new THREE.MeshBasicMaterial({
color: 0xffc367,
transparent: true,
opacity: 0.95
});
const outputPulse = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.25, 0.25),
outputPulseMaterial
);
outputPulse.visible = false;
world.add(outputPulse);
const loopStart = new THREE.Vector3(-LOOP_RX, LOOP_Y, 0);
function routePoint(q) {
const t = THREE.MathUtils.clamp(q, 0, 1);
// First move from the speaker into the loop.
if (t < 0.1) {
return sourceEmitter.clone().lerp(loopStart, t / 0.1);
}
const loopT = (t - 0.1) / 0.9;
const angle = Math.PI * (1 - loopT);
return new THREE.Vector3(
Math.cos(angle) * LOOP_RX,
LOOP_Y,
Math.sin(angle) * LOOP_RZ
);
}
function segmentProgress(angle) {
if (angle > Math.PI + 0.0001) return -1;
return 0.1 + 0.9 * ((Math.PI - angle) / Math.PI);
}
function updateLoopColors(phaseId, progress) {
let reached = -1;
if (phaseId === "transmit") reached = progress;
if (phaseId === "receive" || phaseId === "output" || phaseId === "complete") {
reached = 1;
}
for (let i = 0; i < loopCount; i++) {
const angle = (i / loopCount) * Math.PI * 2;
const q = segmentProgress(angle);
loopTempColor.copy(loopBaseColor);
if (q >= 0 && reached >= q) {
loopTempColor.copy(loopLiveColor);
if (reached - q < 0.085) {
loopTempColor.lerp(loopHeadColor, 0.82);
}
}
loopMesh.setColorAt(i, loopTempColor);
}
if (loopMesh.instanceColor) loopMesh.instanceColor.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Sequence and captions
// -------------------------------------------------------------------------
const PHASES = [
{
id: "source",
duration: 1.45,
badge: "01 / SOURCE EVENT",
caption:
"SPEAKER EVENT — The loudspeaker emits a short audio cue into the room. The causal sequence has begun."
},
{
id: "transmit",
duration: 5.4,
badge: "02 / LOOP TRANSMISSION",
caption:
"HEARING LOOP — The speaker’s audio is converted into an electromagnetic signal and carried around the loop."
},
{
id: "receive",
duration: 1.15,
badge: "03 / RECEIVER CAPTURE",
caption:
"RECEIVER — The assistive receiver couples to the hearing loop and captures the transmitted signal."
},
{
id: "output",
duration: 1.35,
badge: "04 / AUDIBLE OUTPUT",
caption:
"OUTPUT — The receiver amplifies the captured signal and delivers the audio directly to the listener’s ear."
}
];
const phaseBadge = document.querySelector("#phaseBadge");
const captionText = document.querySelector("#captionText");
const captionCount = document.querySelector("#captionCount");
const triggerBtn = document.querySelector("#triggerBtn");
const triggerText = document.querySelector("#triggerText");
const progressFill = document.querySelector("#progressFill");
const stepElements = [...document.querySelectorAll(".step")];
let running = false;
let completed = false;
let currentPhaseId = "ready";
let phaseIndex = 0;
let phaseTime = 0;
let speed = 1;
function setPhaseUI(id) {
if (id === "ready") {
phaseBadge.textContent = "SYSTEM READY";
captionCount.textContent = "00 / 04";
captionText.textContent =
"Trigger the speaker to begin. The caption will explain each causal step as the symbolic signal travels.";
stepElements.forEach((step) => {
step.classList.remove("active", "done");
});
triggerText.textContent = "TRIGGER SPEAKER";
triggerBtn.classList.remove("running");
return;
}
if (id === "complete") {
phaseBadge.textContent = "SEQUENCE COMPLETE";
captionCount.textContent = "04 / 04";
captionText.textContent =
"SEQUENCE COMPLETE — Speaker event → loop transmission → receiver capture → amplified ear-level output. Replay at any time.";
stepElements.forEach((step) => step.classList.add("done"));
triggerText.textContent = "REPLAY SEQUENCE";
triggerBtn.classList.remove("running");
return;
}
const index = PHASES.findIndex((phase) => phase.id === id);
const phase = PHASES[index];
phaseBadge.textContent = phase.badge;
captionCount.textContent = `${String(index + 1).padStart(2, "0")} / 04`;
captionText.textContent = phase.caption;
stepElements.forEach((step, i) => {
step.classList.toggle("done", i < index);
step.classList.toggle("active", i === index);
});
triggerText.textContent = "RESTART SEQUENCE";
triggerBtn.classList.add("running");
}
function startSequence() {
running = true;
completed = false;
phaseIndex = 0;
phaseTime = 0;
currentPhaseId = "source";
setPhaseUI("source");
updateLoopColors("source", 0);
playAudioCue();
}
function updateSequence(dt) {
if (!running) return;
phaseTime += dt * speed;
const phase = PHASES[phaseIndex];
const p = Math.min(1, phaseTime / phase.duration);
if (p >= 1) {
phaseIndex++;
phaseTime = 0;
if (phaseIndex >= PHASES.length) {
running = false;
completed = true;
currentPhaseId = "complete";
setPhaseUI("complete");
} else {
currentPhaseId = PHASES[phaseIndex].id;
setPhaseUI(currentPhaseId);
}
}
}
function setLed(material, color, intensity) {
material.color.setHex(color);
material.emissive.setHex(color);
material.emissiveIntensity = intensity;
}
function applyVisuals(phaseId, p) {
const speakerActive = phaseId === "source";
const receiving = phaseId === "receive";
const outputting = phaseId === "output";
const complete = phaseId === "complete";
// Speaker light and cabinet emission.
if (speakerActive) {
setLed(speakerLedMat, 0xffbd59, 1.7);
speakerPanelMat.emissive.setHex(0x0b536c);
speakerPanelMat.emissiveIntensity = 0.34;
sourceLight.color.setHex(0x54ddff);
sourceLight.intensity = 1.8;
} else {
setLed(speakerLedMat, 0x23465b, 0.12);
speakerPanelMat.emissive.setHex(0x071d2b);
speakerPanelMat.emissiveIntensity = 0.05;
sourceLight.intensity = 0.22;
}
// Receiver light.
if (receiving) {
setLed(receiverLedMat, 0x55dcff, 1.8);
receiverAccentMat.emissive.setHex(0x0e536b);
receiverAccentMat.emissiveIntensity = 0.4;
receiverLight.color.setHex(0x55dcff);
receiverLight.intensity = 1.7;
} else if (outputting || complete) {
setLed(receiverLedMat, 0xffbd59, 1.6);
receiverAccentMat.emissive.setHex(0x80500d);
receiverAccentMat.emissiveIntensity = 0.65;
receiverLight.color.setHex(0xffbd59);
receiverLight.intensity = 1.4;
} else {
setLed(receiverLedMat, 0x24475b, 0.12);
receiverAccentMat.emissive.setHex(0x6f3908);
receiverAccentMat.emissiveIntensity = 0.15;
receiverLight.intensity = 0.18;
}
// Symbolic packet visibility.
signalGroup.visible =
phaseId === "source" ||
phaseId === "transmit" ||
phaseId === "receive";
trail.forEach((cube) => {
cube.visible = phaseId === "transmit";
});
if (phaseId === "source") {
signalGroup.position.copy(sourceEmitter);
signalGroup.scale.setScalar(0.82 + Math.sin(phaseTime * 10) * 0.06);
sourceWaves.forEach((wave, i) => {
const waveProgress = (phaseTime * 1.1 + i / sourceWaves.length) % 1;
wave.group.visible = true;
wave.group.position.set(
sourceEmitter.x + 0.05 + waveProgress * 0.68,
sourceEmitter.y,
sourceEmitter.z
);
wave.group.scale.setScalar(0.26 + waveProgress * 0.9);
wave.material.opacity = 0.58 * (1 - waveProgress);
});
} else {
sourceWaves.forEach((wave) => {
wave.group.visible = false;
wave.material.opacity = 0;
});
}
if (phaseId === "transmit") {
const q = p;
signalGroup.position.copy(routePoint(q));
signalGroup.scale.setScalar(1 + Math.sin(phaseTime * 9) * 0.08);
trail.forEach((cube, i) => {
const trailQ = Math.max(0, q - i * 0.018);
cube.position.copy(routePoint(trailQ));
cube.rotation.set(phaseTime * 1.6, phaseTime * 1.2, phaseTime);
cube.scale.setScalar(1 - i * 0.065);
cube.material.opacity = 0.34 * (1 - i / trail.length);
});
updateLoopColors(phaseId, q);
}
if (receiving) {
signalGroup.position.copy(loopEnd);
signalGroup.scale.setScalar(1 + Math.sin(phaseTime * 16) * 0.18);
updateLoopColors(phaseId, 1);
}
// Output path illumination and moving output packet.
outputPulse.visible = outputting || complete;
outputCubes.forEach((cube, i) => {
const t = i / (outputCubeCount - 1);
if (outputting) {
const lit = t <= p;
cube.material.opacity = lit ? 0.9 : 0.08;
cube.scale.setScalar(lit ? 1 : 0.5);
} else if (complete) {
cube.material.opacity = 0.78;
cube.scale.setScalar(0.85);
} else {
cube.material.opacity = 0.08;
cube.scale.setScalar(0.5);
}
});
if (outputting) {
outputPulse.position.copy(outputPoint(p));
outputPulse.scale.setScalar(0.9 + Math.sin(phaseTime * 18) * 0.18);
} else if (complete) {
outputPulse.position.copy(earPoint);
outputPulse.scale.setScalar(0.9);
}
if (receiving || outputting || complete) {
updateLoopColors(phaseId, 1);
} else if (phaseId === "ready" || phaseId === "source") {
updateLoopColors(phaseId, 0);
}
}
// -------------------------------------------------------------------------
// Lightweight synthesized audio cue
// -------------------------------------------------------------------------
let audioContext = null;
let soundEnabled = true;
function playAudioCue() {
if (!soundEnabled) return;
const AudioContextClass =
window.AudioContext || window.webkitAudioContext;
if (!AudioContextClass) return;
if (!audioContext) audioContext = new AudioContextClass();
if (audioContext.state === "suspended") audioContext.resume();
const now = audioContext.currentTime;
[330, 440, 660].forEach((frequency, i) => {
const oscillator = audioContext.createOscillator();
const gain = audioContext.createGain();
const start = now + i * 0.13;
oscillator.type = "sine";
oscillator.frequency.setValueAtTime(frequency, start);
gain.gain.setValueAtTime(0.0001, start);
gain.gain.exponentialRampToValueAtTime(0.055, start + 0.018);
gain.gain.exponentialRampToValueAtTime(0.0001, start + 0.15);
oscillator.connect(gain);
gain.connect(audioContext.destination);
oscillator.start(start);
oscillator.stop(start + 0.17);
});
}
// -------------------------------------------------------------------------
// UI controls
// -------------------------------------------------------------------------
triggerBtn.addEventListener("click", startSequence);
const speedBtn = document.querySelector("#speedBtn");
const speedOptions = [1, 1.5, 0.75];
speedBtn.addEventListener("click", () => {
const currentIndex = speedOptions.indexOf(speed);
const nextIndex = (currentIndex + 1) % speedOptions.length;
speed = speedOptions[nextIndex];
speedBtn.textContent = `SPEED ${speed}×`;
});
const audioBtn = document.querySelector("#audioBtn");
audioBtn.addEventListener("click", () => {
soundEnabled = !soundEnabled;
audioBtn.textContent = soundEnabled ? "SOUND ON" : "SOUND OFF";
audioBtn.setAttribute("aria-pressed", String(soundEnabled));
});
document.addEventListener("keydown", (event) => {
if (
event.code === "Space" &&
event.target === document.body &&
!event.repeat
) {
event.preventDefault();
startSequence();
}
});
// -------------------------------------------------------------------------
// Direct camera controls and speaker picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let dragMoved = 0;
let previousX = 0;
let previousY = 0;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function speakerWasHit(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObject(speaker, true).length > 0;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
dragMoved = 0;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
dragMoved += Math.abs(dx) + Math.abs(dy);
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.004,
0.32,
1.18
);
previousX = event.clientX;
previousY = event.clientY;
} else {
canvas.style.cursor = speakerWasHit(event) ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
if (dragging && dragMoved < 7 && speakerWasHit(event)) {
startSequence();
}
dragging = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = event.deltaY > 0 ? 0.92 : 1.08;
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * factor,
0.72,
1.7
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#sourceLabel"),
position: new THREE.Vector3(-6.6, 2.85, 0)
},
{
element: document.querySelector("#loopLabel"),
position: new THREE.Vector3(0, 0.55, 3.04)
},
{
element: document.querySelector("#receiverLabel"),
position: new THREE.Vector3(6.9, 2.85, 0)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
labels.forEach((label) => {
projected.copy(label.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity =
projected.z > -1 && projected.z < 1 ? "1" : "0";
});
}
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
updateSequence(dt);
let p = 0;
let overall = 0;
if (running) {
p = Math.min(1, phaseTime / PHASES[phaseIndex].duration);
overall = (phaseIndex + p) / PHASES.length;
} else if (completed) {
p = 1;
overall = 1;
}
applyVisuals(currentPhaseId, p);
progressFill.style.transform = `scaleX(${overall})`;
// Ambient motion for the small data motes.
motes.forEach((mote, i) => {
const angle =
mote.userData.angle + elapsed * (0.055 + (i % 3) * 0.008);
const radius = 1 + Math.sin(elapsed * 1.4 + mote.userData.offset) * 0.025;
mote.position.set(
Math.cos(angle) * (LOOP_RX + 0.18) * radius,
0.49 + Math.sin(elapsed * 1.7 + i) * 0.08,
Math.sin(angle) * (LOOP_RZ + 0.18) * radius
);
mote.rotation.set(elapsed * 0.7, elapsed * 0.9, elapsed * 0.5);
mote.scale.setScalar(0.72 + Math.sin(elapsed * 2.1 + i) * 0.2);
});
// The signal packet gently rotates while travelling.
if (signalGroup.visible) {
signalGroup.rotation.set(
elapsed * 0.65,
elapsed * 1.05,
elapsed * 0.42
);
}
updateCamera();
renderer.render(scene, camera);
updateLabels();
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
}
}
setPhaseUI("ready");
updateLoopColors("ready", 0);
animate();
</script>
</body>
</html>
```