Prompt specification
Build or customize the Three.js 3D scene "Two walls and two echo arrivals" 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: Two walls and two echo arrivals
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-walls-and-two-echo-arrivals-x1542
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: two walls and two echo arrivals. Place reflectors at different distances from one pulse source; animate outgoing and returning fronts and show distinct arrival times under a constant-speed assumption. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (two-walls-and-two-echo-arrivals-x1542):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Echo Lab — Two Walls, Two Arrivals</title>
<style>
:root {
color-scheme: dark;
--bg: #07111d;
--panel: rgba(9, 22, 37, 0.78);
--line: rgba(142, 190, 218, 0.2);
--text: #eaf6ff;
--muted: #91aabd;
--cyan: #48e7ff;
--amber: #ffc45c;
--pink: #ff6bb3;
}
* { 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;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 30%, rgba(1, 7, 14, 0.28) 78%),
linear-gradient(180deg, rgba(1, 7, 14, 0.22), transparent 25%, transparent 72%, rgba(1, 7, 14, 0.42));
}
.hero {
position: fixed;
top: 28px;
left: 30px;
width: min(390px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: currentColor;
box-shadow: 0 0 13px currentColor;
}
h1 {
margin: 0;
font-size: clamp(28px, 3.5vw, 48px);
font-weight: 720;
line-height: 1.02;
letter-spacing: -0.045em;
text-shadow: 0 3px 25px rgba(0, 0, 0, 0.35);
}
.hero p {
max-width: 350px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.status {
position: fixed;
top: 26px;
left: 50%;
z-index: 4;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
min-width: 190px;
padding: 10px 14px;
border: 1px solid rgba(72, 231, 255, 0.25);
border-radius: 999px;
background: rgba(5, 17, 29, 0.7);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.2);
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(14px);
}
.status-dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
animation: statusPulse 1.2s ease-in-out infinite;
}
@keyframes statusPulse {
50% { opacity: 0.42; transform: scale(0.72); }
}
.model {
position: fixed;
top: 26px;
right: 26px;
z-index: 4;
width: 326px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 65px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(18px);
}
.model-head {
padding: 17px 18px 14px;
border-bottom: 1px solid var(--line);
}
.model-kicker {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.model-main {
display: flex;
align-items: end;
justify-content: space-between;
gap: 15px;
margin-top: 7px;
}
.speed {
font-size: 27px;
font-weight: 720;
letter-spacing: -0.035em;
}
.speed span {
color: var(--muted);
font-size: 12px;
font-weight: 500;
letter-spacing: 0;
}
.formula {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
}
.echo-list {
padding: 7px 9px 9px;
}
.echo-row {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 10px;
padding: 11px 9px;
border-radius: 12px;
transition: background 180ms ease, transform 180ms ease;
}
.echo-row.active {
background: rgba(255, 255, 255, 0.045);
transform: translateX(2px);
}
.echo-row .dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--row-color);
opacity: 0.45;
box-shadow: 0 0 0 transparent;
transition: opacity 180ms ease, box-shadow 180ms ease;
}
.echo-row.active .dot,
.echo-row.arrived .dot {
opacity: 1;
box-shadow: 0 0 13px var(--row-color);
}
.echo-name {
font-size: 12px;
font-weight: 760;
letter-spacing: 0.02em;
}
.echo-sub {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.arrival {
text-align: right;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.arrival strong {
display: block;
color: var(--row-color);
font-size: 15px;
}
.arrival span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.model-foot {
display: flex;
justify-content: space-between;
padding: 11px 18px 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.model-foot strong {
color: var(--text);
font-weight: 700;
}
.timeline {
position: fixed;
z-index: 4;
right: 26px;
bottom: 24px;
left: 26px;
width: min(880px, calc(100vw - 52px));
margin: auto;
padding: 14px 17px 12px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(7, 18, 31, 0.78);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
}
.timeline-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 16px;
}
.timeline-title {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.clock {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
color: var(--cyan);
font-size: 12px;
}
.track {
position: relative;
height: 3px;
margin: 0 6px 22px;
border-radius: 99px;
background: rgba(151, 193, 217, 0.16);
}
.progress {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--amber), var(--pink));
box-shadow: 0 0 14px rgba(72, 231, 255, 0.45);
}
.now-dot {
position: absolute;
top: 50%;
left: 0;
width: 11px;
height: 11px;
border: 2px solid #dffaff;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 15px var(--cyan);
transform: translate(-50%, -50%);
}
.marker {
position: absolute;
top: 50%;
width: 1px;
height: 12px;
background: rgba(222, 241, 252, 0.42);
transform: translate(-50%, -50%);
}
.marker span {
position: absolute;
top: 18px;
left: 50%;
width: max-content;
color: #a8bfce;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.04em;
transform: translateX(-50%);
white-space: nowrap;
}
.marker.pulse span { color: var(--cyan); }
.marker.near span { color: var(--amber); }
.marker.far span { color: var(--pink); }
.timeline-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
color: var(--muted);
font-size: 9px;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 15px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
display: inline-block;
width: 14px;
height: 2px;
border-radius: 99px;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
.legend .out { color: var(--cyan); }
.legend .return-a { color: var(--amber); }
.legend .return-b { color: var(--pink); }
.controls {
display: flex;
align-items: center;
gap: 10px;
white-space: nowrap;
}
button {
border: 1px solid rgba(142, 190, 218, 0.24);
border-radius: 999px;
padding: 7px 10px;
background: rgba(255, 255, 255, 0.04);
color: var(--text);
cursor: pointer;
font: inherit;
font-size: 9px;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(72, 231, 255, 0.55);
background: rgba(72, 231, 255, 0.08);
}
@media (max-width: 900px) {
.hero { top: 18px; left: 18px; width: 320px; }
.hero p { display: none; }
.status { top: auto; bottom: 145px; }
.model { top: 16px; right: 16px; width: 290px; }
.timeline { right: 16px; bottom: 16px; left: 16px; width: auto; }
}
@media (max-width: 620px) {
.hero { width: calc(100vw - 32px); }
h1 { max-width: 245px; font-size: 29px; }
.model {
top: auto;
right: 12px;
bottom: 136px;
width: 224px;
}
.model-head { padding: 12px; }
.speed { font-size: 21px; }
.echo-list { padding: 4px; }
.echo-row { padding: 8px 6px; }
.echo-sub { display: none; }
.model-foot { display: none; }
.status { bottom: 382px; min-width: 170px; }
.timeline { right: 12px; bottom: 12px; left: 12px; padding: 12px; }
.marker span { display: none; }
.timeline-bottom { align-items: flex-start; }
.legend { gap: 8px; }
.controls > span { display: none; }
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="vignette"></div>
<header class="hero">
<div class="eyebrow">Acoustic geometry / 01</div>
<h1>Two walls.<br>Two arrivals.</h1>
<p>
One pulse meets two reflectors at different ranges. The returning fronts
return to the source at different times under a constant-speed model.
</p>
</header>
<div class="status">
<span class="status-dot"></span>
<span id="statusText">Pulse in flight</span>
</div>
<aside class="model">
<div class="model-head">
<div class="model-kicker">Constant-speed assumption</div>
<div class="model-main">
<div class="speed">6.0 <span>m·s⁻¹</span></div>
<div class="formula">T = 2d / v</div>
</div>
</div>
<div class="echo-list">
<div class="echo-row" id="nearRow" style="--row-color: var(--amber)">
<span class="dot"></span>
<div>
<div class="echo-name">E1 · Near reflector</div>
<div class="echo-sub">5 m one way · hits at 0.83 s</div>
</div>
<div class="arrival">
<strong>1.67 s</strong>
<span>arrival</span>
</div>
</div>
<div class="echo-row" id="farRow" style="--row-color: var(--pink)">
<span class="dot"></span>
<div>
<div class="echo-name">E2 · Far reflector</div>
<div class="echo-sub">7 m one way · hits at 1.17 s</div>
</div>
<div class="arrival">
<strong>2.33 s</strong>
<span>arrival</span>
</div>
</div>
</div>
<div class="model-foot">
<span>Arrival separation</span>
<strong>0.67 s</strong>
</div>
</aside>
<section class="timeline">
<div class="timeline-top">
<span class="timeline-title">One pulse cycle · repeated every 4 seconds</span>
<span class="clock" id="clockText">t = 0.00 s</span>
</div>
<div class="track" id="track">
<div class="progress" id="progress"></div>
<div class="now-dot" id="nowDot"></div>
</div>
<div class="timeline-bottom">
<div class="legend">
<span class="out"><i></i>Outgoing</span>
<span class="return-a"><i></i>E1 return</span>
<span class="return-b"><i></i>E2 return</span>
</div>
<div class="controls">
<span>Drag to orbit · wheel to zoom</span>
<button id="resetView" type="button">Reset view</button>
</div>
</div>
</section>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.Fog(0x07111d, 22, 48);
const renderer = new THREE.WebGLRenderer({ 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;
renderer.localClippingEnabled = true;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(42, window.innerWidth / window.innerHeight, 0.1, 100);
// Direct camera controls: no examples/addons are used.
const cameraTarget = new THREE.Vector3(-1, 0.35, -0.45);
const initialView = { radius: 19.2, theta: 0.055, phi: 0.72 };
let cameraRadius = initialView.radius;
let cameraTheta = initialView.theta;
let cameraPhi = initialView.phi;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
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);
}
function resetCamera() {
cameraRadius = initialView.radius;
cameraTheta = initialView.theta;
cameraPhi = initialView.phi;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.005, 0.28, 1.36);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
const stopDragging = () => { dragging = false; };
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
10.5,
29
);
updateCamera();
}, { passive: false });
document.querySelector("#resetView").addEventListener("click", resetCamera);
updateCamera();
// Lighting.
scene.add(new THREE.HemisphereLight(0x8dc8e8, 0x08101a, 1.6));
const keyLight = new THREE.DirectionalLight(0xd8f3ff, 2.2);
keyLight.position.set(2, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 18;
keyLight.shadow.camera.bottom = -18;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0002;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x315cff, 1.3);
rimLight.position.set(-8, 7, -8);
scene.add(rimLight);
const CYAN = 0x48e7ff;
const AMBER = 0xffc45c;
const PINK = 0xff6bb3;
const SOURCE_POINT = new THREE.Vector3(0, 0.12, 0);
const SPEED = 6.0;
const NEAR_DISTANCE = 5.0;
const FAR_DISTANCE = 7.0;
const NEAR_HIT = NEAR_DISTANCE / SPEED;
const FAR_HIT = FAR_DISTANCE / SPEED;
const NEAR_ARRIVAL = 2 * NEAR_HIT;
const FAR_ARRIVAL = 2 * FAR_HIT;
const CYCLE = 4.0;
const nearWallX = 5.35;
const farWallX = -7.35;
// Clip wavefronts to the space between the walls.
const clipPlanes = [
new THREE.Plane(new THREE.Vector3(-1, 0, 0), nearWallX),
new THREE.Plane(new THREE.Vector3(1, 0, 0), -farWallX)
];
// Floor and grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 48),
new THREE.MeshStandardMaterial({
color: 0x07121e,
roughness: 0.92,
metalness: 0.08
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const chamberFloor = new THREE.Mesh(
new THREE.PlaneGeometry(nearWallX - farWallX, 14),
new THREE.MeshStandardMaterial({
color: 0x0b1b2c,
roughness: 0.76,
metalness: 0.16,
transparent: true,
opacity: 0.9
})
);
chamberFloor.rotation.x = -Math.PI / 2;
chamberFloor.position.set((nearWallX + farWallX) * 0.5, 0.005, 0);
chamberFloor.receiveShadow = true;
scene.add(chamberFloor);
const grid = new THREE.GridHelper(50, 50, 0x2c5770, 0x173246);
grid.position.y = 0.018;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const chamberGrid = new THREE.GridHelper(12, 24, 0x2a5268, 0x1a3548);
chamberGrid.position.set(-1, 0.026, 0);
chamberGrid.scale.z = 14 / 12;
chamberGrid.material.transparent = true;
chamberGrid.material.opacity = 0.26;
scene.add(chamberGrid);
function createWall(x, accent, isNear) {
const group = new THREE.Group();
const inward = isNear ? -1 : 1;
const faceX = x + inward * 0.18;
const body = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 2.8, 14),
new THREE.MeshStandardMaterial({
color: 0x12263a,
roughness: 0.48,
metalness: 0.42,
emissive: new THREE.Color(accent).multiplyScalar(0.045)
})
);
body.position.set(x, 1.4, 0);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const trimMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 1.5,
roughness: 0.35,
metalness: 0.25
});
const topRail = new THREE.Mesh(
new THREE.BoxGeometry(0.4, 0.075, 14.05),
trimMaterial
);
topRail.position.set(x, 2.83, 0);
group.add(topRail);
for (const y of [0.48, 1.38, 2.25]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.035, 14),
new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.35,
roughness: 0.55
})
);
rail.position.set(faceX, y, 0);
group.add(rail);
}
for (let z = -6; z <= 6; z += 2) {
const panel = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 2.4, 0.055),
new THREE.MeshStandardMaterial({
color: 0x37536a,
emissive: 0x10283a,
emissiveIntensity: 0.5,
roughness: 0.7
})
);
panel.position.set(faceX, 1.38, z);
group.add(panel);
}
const base = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.16, 14.1),
new THREE.MeshStandardMaterial({
color: 0x0d1d2d,
roughness: 0.62,
metalness: 0.48
})
);
base.position.set(x, 0.08, 0);
base.castShadow = true;
group.add(base);
scene.add(group);
}
createWall(nearWallX, AMBER, true);
createWall(farWallX, PINK, false);
function createTextSprite(title, subtitle, accent, width = 512, height = 128) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
context.fillStyle = "rgba(6, 18, 31, 0.82)";
context.strokeStyle = "rgba(154, 203, 230, 0.25)";
context.lineWidth = 2;
context.beginPath();
context.roundRect(5, 5, width - 10, height - 10, 22);
context.fill();
context.stroke();
context.fillStyle = `#${new THREE.Color(accent).getHexString()}`;
context.fillRect(20, 22, 5, height - 44);
context.textBaseline = "middle";
context.fillStyle = "#eef9ff";
context.font = "700 27px system-ui, sans-serif";
context.fillText(title, 40, subtitle ? 43 : height / 2);
if (subtitle) {
context.fillStyle = "#96afc0";
context.font = "600 18px system-ui, sans-serif";
context.fillText(subtitle, 40, 84);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
}));
sprite.renderOrder = 20;
return sprite;
}
function addLabel(sprite, x, y, z, scaleX, scaleY) {
sprite.position.set(x, y, z);
sprite.scale.set(scaleX, scaleY, 1);
scene.add(sprite);
}
const sourceLabel = createTextSprite("PULSE SOURCE", "P0", CYAN);
addLabel(sourceLabel, 0, 2.02, 0, 2.75, 0.69);
const nearLabel = createTextSprite("E1 · NEAR", "5 m", AMBER);
addLabel(nearLabel, 5, 2.18, 0, 2.75, 0.69);
const farLabel = createTextSprite("E2 · FAR", "7 m", PINK);
addLabel(farLabel, -7, 2.18, 0, 2.75, 0.69);
const nearDistanceLabel = createTextSprite("5 m", "", AMBER, 256, 96);
addLabel(nearDistanceLabel, 2.5, 0.38, 0.28, 1.25, 0.47);
const farDistanceLabel = createTextSprite("7 m", "", PINK, 256, 96);
addLabel(farDistanceLabel, -3.5, 0.38, 0.28, 1.25, 0.47);
function createRoute(endX, color, direction) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.075, 0),
new THREE.Vector3(endX, 0.075, 0)
]);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: 0.42,
dashSize: 0.22,
gapSize: 0.16,
depthWrite: false
})
);
line.computeLineDistances();
scene.add(line);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.34, 16),
new THREE.MeshBasicMaterial({ color, transparent: true, opacity: 0.65 })
);
arrow.rotation.z = direction > 0 ? -Math.PI / 2 : Math.PI / 2;
arrow.position.set(endX * 0.56, 0.12, 0);
scene.add(arrow);
}
createRoute(5, AMBER, 1);
createRoute(-7, PINK, -1);
// Source assembly.
const sourceGroup = new THREE.Group();
sourceGroup.position.copy(SOURCE_POINT);
scene.add(sourceGroup);
const sourceBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.68, 0.82, 0.22, 48),
new THREE.MeshStandardMaterial({
color: 0x102c40,
roughness: 0.3,
metalness: 0.7
})
);
sourceBase.position.y = 0.1;
sourceBase.castShadow = true;
sourceGroup.add(sourceBase);
const sourceRing = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.055, 12, 64),
new THREE.MeshBasicMaterial({ color: CYAN })
);
sourceRing.rotation.x = Math.PI / 2;
sourceRing.position.y = 0.235;
sourceGroup.add(sourceRing);
const sourceCoreMaterial = new THREE.MeshStandardMaterial({
color: CYAN,
emissive: CYAN,
emissiveIntensity: 2.4,
roughness: 0.18,
metalness: 0.05
});
const sourceCore = new THREE.Mesh(
new THREE.SphereGeometry(0.27, 32, 24),
sourceCoreMaterial
);
sourceCore.position.y = 0.68;
sourceCore.castShadow = true;
sourceGroup.add(sourceCore);
const sourceHaloMaterial = new THREE.MeshBasicMaterial({
color: CYAN,
transparent: true,
opacity: 0.2,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const sourceHalo = new THREE.Mesh(
new THREE.SphereGeometry(0.4, 24, 16),
sourceHaloMaterial
);
sourceHalo.position.y = 0.68;
sourceGroup.add(sourceHalo);
const sourceLight = new THREE.PointLight(CYAN, 2.4, 5, 2);
sourceLight.position.y = 0.75;
sourceGroup.add(sourceLight);
const sourceBeam = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.14, 1.45, 20, 1, true),
new THREE.MeshBasicMaterial({
color: CYAN,
transparent: true,
opacity: 0.12,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide
})
);
sourceBeam.position.y = 1.15;
sourceGroup.add(sourceBeam);
function createReflector(x, color, wallDirection) {
const group = new THREE.Group();
group.position.set(x, 0, 0);
scene.add(group);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.72,
roughness: 0.22,
metalness: 0.48
});
const disc = new THREE.Mesh(
new THREE.CylinderGeometry(0.48, 0.48, 0.18, 40),
material
);
disc.rotation.z = Math.PI / 2;
disc.position.y = 0.88;
disc.castShadow = true;
group.add(disc);
const outerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.64, 0.055, 12, 56),
new THREE.MeshBasicMaterial({ color })
);
outerRing.rotation.y = Math.PI / 2;
outerRing.position.y = 0.88;
group.add(outerRing);
const innerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.35, 0.025, 8, 48),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.62
})
);
innerRing.rotation.y = Math.PI / 2;
innerRing.position.set(-wallDirection * 0.105, 0.88, 0);
group.add(innerRing);
const bracket = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.12, 0.18),
new THREE.MeshStandardMaterial({
color: 0x294459,
roughness: 0.5,
metalness: 0.65
})
);
bracket.position.set(wallDirection * 0.27, 0.88, 0);
bracket.castShadow = true;
group.add(bracket);
const flashMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const flash = new THREE.Mesh(
new THREE.TorusGeometry(0.7, 0.04, 10, 56),
flashMaterial
);
flash.rotation.y = Math.PI / 2;
flash.position.y = 0.88;
group.add(flash);
const light = new THREE.PointLight(color, 1.4, 4.5, 2);
light.position.set(-wallDirection * 0.45, 1, 0);
group.add(light);
return { group, material, flash, flashMaterial, light };
}
const nearReflector = createReflector(5, AMBER, 1);
const farReflector = createReflector(-7, PINK, -1);
function createWave(color) {
const group = new THREE.Group();
group.position.y = 0.105;
const coreMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
blending: THREE.AdditiveBlending,
depthWrite: false,
clippingPlanes: clipPlanes
});
const haloMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
blending: THREE.AdditiveBlending,
depthWrite: false,
clippingPlanes: clipPlanes
});
const core = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.023, 10, 160),
coreMaterial
);
core.rotation.x = Math.PI / 2;
const halo = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.075, 8, 160),
haloMaterial
);
halo.rotation.x = Math.PI / 2;
group.add(core, halo);
scene.add(group);
return { group, coreMaterial, haloMaterial };
}
const outgoingWave = createWave(CYAN);
const nearReturnWave = createWave(AMBER);
const farReturnWave = createWave(PINK);
nearReturnWave.group.position.x = 5;
farReturnWave.group.position.x = -7;
function setWave(wave, radius, opacity) {
wave.group.visible = opacity > 0.002 && radius > 0.001;
wave.group.scale.setScalar(Math.max(radius, 0.0001));
wave.coreMaterial.opacity = opacity;
wave.haloMaterial.opacity = opacity * 0.22;
}
// Timeline event markers.
const track = document.querySelector("#track");
const markerData = [
{ time: 0, label: "Pulse", className: "pulse" },
{ time: NEAR_HIT, label: "E1 hit", className: "near" },
{ time: FAR_HIT, label: "E2 hit", className: "far" },
{ time: NEAR_ARRIVAL, label: "E1 arrives", className: "near" },
{ time: FAR_ARRIVAL, label: "E2 arrives", className: "far" }
];
for (const event of markerData) {
const marker = document.createElement("div");
marker.className = `marker ${event.className}`;
marker.style.left = `${event.time / CYCLE * 100}%`;
marker.innerHTML = `<span>${event.label}</span>`;
track.appendChild(marker);
}
const progress = document.querySelector("#progress");
const nowDot = document.querySelector("#nowDot");
const clockText = document.querySelector("#clockText");
const statusText = document.querySelector("#statusText");
const nearRow = document.querySelector("#nearRow");
const farRow = document.querySelector("#farRow");
const cyanColor = new THREE.Color(CYAN);
const amberColor = new THREE.Color(AMBER);
const pinkColor = new THREE.Color(PINK);
const tempColor = new THREE.Color();
function updateReflector(reflector, hitTime, time) {
const age = time - hitTime;
const active = age >= 0 && age < 0.42;
if (active) {
const strength = 1 - age / 0.42;
reflector.flash.visible = true;
reflector.flashMaterial.opacity = strength * 0.92;
const scale = 1 + age * 1.45;
reflector.flash.scale.setScalar(scale);
reflector.material.emissiveIntensity = 0.72 + strength * 2.5;
reflector.light.intensity = 1.4 + strength * 3.5;
} else {
reflector.flash.visible = false;
reflector.flashMaterial.opacity = 0;
reflector.material.emissiveIntensity = 0.72;
reflector.light.intensity = 1.4;
}
}
function updateReturnWave(wave, distance, hitTime, arrivalTime, time) {
const age = time - hitTime;
const holdDuration = 0.2;
if (age < 0) {
setWave(wave, 0, 0);
return;
}
const radius = Math.min(SPEED * age, distance);
let opacity;
if (age <= arrivalTime - hitTime) {
opacity = 0.78;
} else if (age <= arrivalTime - hitTime + holdDuration) {
opacity = 0.78 * (1 - (age - (arrivalTime - hitTime)) / holdDuration);
} else {
opacity = 0;
}
setWave(wave, radius, opacity);
}
const startTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const elapsed = (now - startTime) / 1000;
const time = elapsed % CYCLE;
// Outgoing circular front: radius = v t.
const outgoingFade = time <= FAR_HIT
? 1
: Math.max(0, 1 - (time - FAR_HIT) / 0.16);
const outgoingRadius = Math.min(SPEED * time, FAR_DISTANCE);
setWave(outgoingWave, outgoingRadius, 0.64 * outgoingFade);
// Reflected circular fronts: radius = v (t - t_hit).
updateReturnWave(nearReturnWave, NEAR_DISTANCE, NEAR_HIT, NEAR_ARRIVAL, time);
updateReturnWave(farReturnWave, FAR_DISTANCE, FAR_HIT, FAR_ARRIVAL, time);
updateReflector(nearReflector, NEAR_HIT, time);
updateReflector(farReflector, FAR_HIT, time);
// Source emission and echo-arrival flashes.
const emissionStrength = time < 0.28 ? 1 - time / 0.28 : 0;
const nearArrivalAge = time - NEAR_ARRIVAL;
const farArrivalAge = time - FAR_ARRIVAL;
const nearArrivalStrength = nearArrivalAge >= 0 && nearArrivalAge < 0.34
? 1 - nearArrivalAge / 0.34
: 0;
const farArrivalStrength = farArrivalAge >= 0 && farArrivalAge < 0.34
? 1 - farArrivalAge / 0.34
: 0;
const strongestArrival = Math.max(nearArrivalStrength, farArrivalStrength);
const glow = Math.max(emissionStrength, strongestArrival);
tempColor.copy(cyanColor);
if (nearArrivalStrength >= farArrivalStrength && nearArrivalStrength > 0) {
tempColor.lerp(amberColor, nearArrivalStrength);
} else if (farArrivalStrength > 0) {
tempColor.lerp(pinkColor, farArrivalStrength);
}
sourceCoreMaterial.color.copy(tempColor);
sourceCoreMaterial.emissive.copy(tempColor);
sourceCoreMaterial.emissiveIntensity = 2.2 + glow * 4.5;
sourceHaloMaterial.color.copy(tempColor);
sourceHaloMaterial.opacity = 0.16 + glow * 0.32;
sourceRing.material.color.copy(tempColor);
sourceBeam.material.color.copy(tempColor);
sourceBeam.material.opacity = 0.08 + emissionStrength * 0.18;
sourceLight.color.copy(tempColor);
sourceLight.intensity = 2 + glow * 5;
sourceHalo.scale.setScalar(1 + glow * 0.48);
// HUD state.
let status;
if (time < NEAR_HIT) {
status = "Pulse in flight";
} else if (time < FAR_HIT) {
status = "E1 · Reflecting";
} else if (time < NEAR_ARRIVAL) {
status = "Two returns in flight";
} else if (time < FAR_ARRIVAL) {
status = "E1 arrived · E2 inbound";
} else {
status = "Two echoes arrived";
}
statusText.textContent = status;
nearRow.classList.toggle("active", time >= NEAR_HIT && time < NEAR_ARRIVAL + 0.34);
nearRow.classList.toggle("arrived", time >= NEAR_ARRIVAL);
farRow.classList.toggle("active", time >= FAR_HIT && time < FAR_ARRIVAL + 0.34);
farRow.classList.toggle("arrived", time >= FAR_ARRIVAL);
const cycleProgress = time / CYCLE * 100;
progress.style.width = `${cycleProgress}%`;
nowDot.style.left = `${cycleProgress}%`;
clockText.textContent = `t = ${time.toFixed(2)} s`;
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```