Prompt specification
Build or customize the Three.js 3D scene "Wave-type museum bridge" 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: Wave-type museum bridge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wave-type-museum-bridge-x1599
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows transverse and longitudinal waves. Compose rope, sound-tube, and surface-water teaching stations with explicit simplified motion models; identify which particle-motion analogy applies and avoid equating all waves with one geometry. Voxel style.
Working Three.js Starter (wave-type-museum-bridge-x1599):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Three Media, Three Particle Motions — Voxel Wave Lab</title>
<style>
:root {
--bg: #0b111b;
--panel: rgba(15, 24, 37, 0.94);
--panel-solid: #111c2b;
--line: #2a3a50;
--text: #f2f7ff;
--muted: #9eb0c7;
--orange: #ff8a42;
--cyan: #35d7ff;
--blue: #4d83ff;
--yellow: #ffe36b;
--accent: var(--yellow);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
width: 100%;
height: 100dvh;
display: grid;
grid-template-rows: 76px minmax(0, 1fr);
}
header {
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 22px;
background: #0e1724;
border-bottom: 1px solid var(--line);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
}
.brand {
min-width: 0;
display: flex;
align-items: center;
gap: 13px;
}
.voxel-mark {
width: 38px;
height: 38px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(-4deg);
}
.voxel-mark i {
display: block;
background: var(--orange);
box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.16);
}
.voxel-mark i:nth-child(1),
.voxel-mark i:nth-child(5),
.voxel-mark i:nth-child(9) {
background: var(--cyan);
}
.voxel-mark i:nth-child(3),
.voxel-mark i:nth-child(7) {
background: var(--blue);
}
h1,
h2,
h3,
p {
margin: 0;
}
.brand h1 {
font-size: clamp(16px, 1.6vw, 22px);
line-height: 1.05;
letter-spacing: -0.02em;
white-space: nowrap;
}
.brand p {
margin-top: 5px;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.02em;
white-space: nowrap;
}
.toolbar {
display: flex;
align-items: center;
gap: 9px;
flex: 0 0 auto;
}
.tool-button,
.speed-control {
min-height: 36px;
border: 1px solid var(--line);
background: #142033;
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.28);
}
.tool-button {
padding: 0 13px;
cursor: pointer;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.tool-button:hover,
.tool-button:focus-visible {
background: #1b2c45;
border-color: #527093;
outline: none;
}
.tool-button.active {
color: #07101b;
background: var(--yellow);
border-color: var(--yellow);
}
.speed-control {
display: flex;
align-items: center;
gap: 9px;
padding: 0 11px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.speed-control output {
min-width: 35px;
color: var(--text);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 92px;
accent-color: var(--yellow);
cursor: pointer;
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 25%, rgba(45, 78, 120, 0.18), transparent 48%),
#0b121d;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.stage-note {
position: absolute;
z-index: 3;
top: 18px;
left: 20px;
width: 250px;
padding: 12px 14px;
background: rgba(12, 21, 33, 0.82);
border: 1px solid var(--line);
box-shadow: 7px 7px 0 rgba(0, 0, 0, 0.16);
pointer-events: none;
}
.stage-note strong {
display: block;
margin-bottom: 5px;
color: var(--yellow);
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.stage-note p {
color: #b8c7da;
font-size: 12px;
line-height: 1.45;
}
.inspector {
position: absolute;
z-index: 5;
top: 18px;
right: 18px;
width: 352px;
max-height: calc(100% - 108px);
overflow: auto;
padding: 18px;
background: var(--panel);
border: 1px solid var(--line);
border-top: 3px solid var(--accent);
box-shadow: 9px 9px 0 rgba(0, 0, 0, 0.18);
scrollbar-width: thin;
scrollbar-color: #3a4e68 transparent;
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.inspector h2 {
margin-top: 8px;
font-size: 23px;
line-height: 1.12;
letter-spacing: -0.025em;
}
.lead {
margin-top: 10px;
color: #b6c6da;
font-size: 13px;
line-height: 1.52;
}
.equation {
position: relative;
margin-top: 15px;
padding: 13px 13px 12px;
overflow-x: auto;
background: #0a121e;
border: 1px solid #283a53;
color: #eef6ff;
box-shadow: inset 4px 0 0 var(--accent);
}
.equation small {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.equation code {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 12px;
white-space: nowrap;
}
.detail-list {
margin: 14px 0 0;
border-top: 1px solid var(--line);
}
.detail {
display: grid;
grid-template-columns: 88px 1fr;
gap: 10px;
padding: 9px 0;
border-bottom: 1px solid rgba(42, 58, 80, 0.72);
font-size: 12px;
line-height: 1.42;
}
.detail dt {
color: var(--muted);
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.detail dd {
margin: 0;
color: #e8f0fb;
}
.analogy {
margin-top: 14px;
padding: 12px 13px;
background: rgba(255, 227, 107, 0.08);
border: 1px solid rgba(255, 227, 107, 0.28);
color: #e7edf7;
font-size: 12px;
line-height: 1.5;
}
.analogy strong {
display: block;
margin-bottom: 4px;
color: var(--yellow);
font-size: 9px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.caution {
margin-top: 11px;
color: #92a7bf;
font-size: 11px;
line-height: 1.48;
}
.compare-title {
margin-top: 16px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.compare-row {
display: grid;
grid-template-columns: 8px 1fr;
gap: 10px;
margin-top: 10px;
padding: 10px 11px;
background: #101b2a;
border: 1px solid #26374c;
}
.compare-row i {
width: 8px;
height: 100%;
min-height: 34px;
background: var(--row-color);
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.2);
}
.compare-row strong {
display: block;
font-size: 12px;
}
.compare-row span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.station-nav {
position: absolute;
z-index: 6;
left: 20px;
bottom: 18px;
display: flex;
gap: 8px;
}
.station-button {
min-width: 142px;
padding: 10px 12px;
text-align: left;
cursor: pointer;
background: rgba(13, 23, 36, 0.94);
border: 1px solid var(--line);
box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.18);
transition:
transform 120ms ease,
border-color 120ms ease,
background 120ms ease;
}
.station-button:hover,
.station-button:focus-visible {
transform: translateY(-2px);
border-color: #567392;
outline: none;
}
.station-button.active {
background: #1a2a40;
border-color: var(--station-color);
box-shadow:
5px 5px 0 rgba(0, 0, 0, 0.18),
inset 4px 0 0 var(--station-color);
}
.station-button b {
display: block;
color: var(--station-color);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.station-button span {
display: block;
margin-top: 4px;
color: #e7eff9;
font-size: 12px;
font-weight: 800;
}
.station-button small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.world-labels {
position: absolute;
z-index: 4;
inset: 0;
pointer-events: none;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
min-width: max-content;
padding: 7px 9px;
transform: translate(-50%, -50%);
pointer-events: auto;
cursor: pointer;
background: rgba(10, 18, 29, 0.9);
border: 1px solid #40536c;
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.22);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 17px;
background: #61758f;
}
.world-label b {
color: var(--label-color);
}
.world-label span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.world-label:hover,
.world-label:focus-visible {
border-color: var(--label-color);
outline: none;
}
.controls-hint {
position: absolute;
right: 20px;
bottom: 17px;
z-index: 3;
color: #6f849e;
font-size: 10px;
letter-spacing: 0.05em;
pointer-events: none;
}
@media (max-width: 1080px) {
.inspector {
width: 320px;
}
.station-button {
min-width: 124px;
}
.brand p {
display: none;
}
}
@media (max-width: 820px) {
#app {
grid-template-rows: 68px minmax(0, 1fr);
}
header {
padding: 0 12px;
}
.brand .voxel-mark {
width: 31px;
height: 31px;
}
.brand h1 {
font-size: 15px;
}
.speed-control {
display: none;
}
.stage-note {
display: none;
}
.inspector {
top: 12px;
right: 12px;
width: 300px;
max-height: calc(100% - 98px);
padding: 14px;
}
.inspector h2 {
font-size: 20px;
}
.station-nav {
left: 10px;
right: 10px;
bottom: 10px;
gap: 5px;
}
.station-button {
min-width: 0;
flex: 1;
padding: 8px;
}
.station-button small {
display: none;
}
.controls-hint {
display: none;
}
}
@media (max-width: 560px) {
.tool-button {
padding: 0 9px;
font-size: 10px;
}
#overview {
display: none;
}
.inspector {
width: min(285px, calc(100vw - 24px));
}
.detail {
grid-template-columns: 76px 1fr;
}
.world-label {
padding: 5px 6px;
font-size: 9px;
}
.world-label span {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="voxel-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<h1>Waves aren’t one geometry</h1>
<p>Three media. Three particle motions. One traveling-disturbance idea.</p>
</div>
</div>
<div class="toolbar">
<button class="tool-button active" id="overview" type="button">
All stations
</button>
<button class="tool-button" id="pause" type="button" aria-pressed="false">
Ⅱ Pause
</button>
<label class="speed-control" for="speed">
Speed
<input id="speed" type="range" min="0.25" max="2" step="0.25" value="1" />
<output id="speedValue" for="speed">1.0×</output>
</label>
</div>
</header>
<main id="stage">
<canvas
id="scene"
aria-label="Interactive voxel wave laboratory showing a rope, an air tube, and surface water"
></canvas>
<div class="stage-note">
<strong>Read the arrows</strong>
<p>
Arrows show the direction the wave pattern travels. They do not show the
path of every particle. Drag to orbit; scroll to zoom.
</p>
</div>
<div class="world-labels" aria-label="Wave station labels">
<button class="world-label" data-station="rope" style="--label-color: var(--orange)" type="button">
<b>01</b> Rope <span>transverse</span>
</button>
<button class="world-label" data-station="tube" style="--label-color: var(--cyan)" type="button">
<b>02</b> Air tube <span>longitudinal</span>
</button>
<button class="world-label" data-station="water" style="--label-color: var(--blue)" type="button">
<b>03</b> Water <span>orbital</span>
</button>
</div>
<aside class="inspector" id="inspector" aria-live="polite"></aside>
<nav class="station-nav" aria-label="Teaching stations">
<button
class="station-button"
data-station="rope"
style="--station-color: var(--orange)"
type="button"
>
<b>01 / Transverse</b>
<span>Rope</span>
<small>side-to-side displacement</small>
</button>
<button
class="station-button"
data-station="tube"
style="--station-color: var(--cyan)"
type="button"
>
<b>02 / Longitudinal</b>
<span>Air tube</span>
<small>back-and-forth displacement</small>
</button>
<button
class="station-button"
data-station="water"
style="--station-color: var(--blue)"
type="button"
>
<b>03 / Surface</b>
<span>Water</span>
<small>orbital particle motion</small>
</button>
</nav>
<div class="controls-hint">DRAG TO ORBIT · SCROLL TO ZOOM · KEYS 1 / 2 / 3 / 0</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* ------------------------------------------------------------------
DOM and educational content
------------------------------------------------------------------ */
const stage = document.querySelector("#stage");
const canvas = document.querySelector("#scene");
const inspector = document.querySelector("#inspector");
const overviewButton = document.querySelector("#overview");
const pauseButton = document.querySelector("#pause");
const speedInput = document.querySelector("#speed");
const speedValue = document.querySelector("#speedValue");
const stationButtons = [...document.querySelectorAll("[data-station]")];
const worldLabelButtons = [...document.querySelectorAll(".world-label")];
const stationInfo = {
rope: {
accent: "#ff8a42",
eyebrow: "01 / ROPE STATION",
type: "Transverse wave",
title: "The rope moves up and down as the wave moves right.",
lead:
"Each marked point of the rope oscillates perpendicular to the direction of travel. The x position of a rope particle is fixed.",
equation: "yᵢ(t) = yᵢ⁰ + A sin(kxᵢ − ωt) · envelope(x)",
details: [
["Particle motion", "Vertical: perpendicular to the wave’s rightward travel."],
["Travel", "The crest and trough pattern moves in +x."],
["Visible thing", "The changing shape of the rope—not a path followed by its particles."],
["Analogy", "A row of people leaning side-to-side while the pattern travels along the row."],
["Boundary", "The envelope keeps both rope ends anchored."],
],
caution:
"The rope’s visible wave is transverse. That geometry does not define every kind of wave."
},
tube: {
accent: "#35d7ff",
eyebrow: "02 / SOUND-TUBE STATION",
type: "Longitudinal wave",
title: "Air parcels push and pull along the tube.",
lead:
"The enlarged cyan blocks represent neighboring air parcels. Their spacing changes as compressions and rarefactions travel toward +x.",
equation: "xᵢ(t) = xᵢ⁰ + A sin(kxᵢ⁰ − ωt)",
details: [
["Particle motion", "Parallel to the wave’s rightward travel."],
["Travel", "Compression and rarefaction bands move in +x."],
["Visible thing", "Changing spacing between air parcels; sound itself is not visible."],
["Analogy", "A compression moving through a slinky: each bead nudges its neighbors and returns."],
["Pattern", "Bright blocks mark compressed regions; darker blocks mark expanded regions."],
],
caution:
"A longitudinal wave is described by compression and rarefaction, not by a visible up-and-down crest."
},
water: {
accent: "#4d83ff",
eyebrow: "03 / SURFACE-WATER STATION",
type: "Surface wave with orbital motion",
title: "The surface pattern moves, while particles move in loops.",
lead:
"A simplified deep-water model lets each surface parcel trace an ellipse in a vertical slice containing the travel direction.",
equation: "φᵢ = kxᵢ − ωt; uᵢ ≈ U cosφᵢ; wᵢ ≈ W sinφᵢ",
details: [
["Particle motion", "A small horizontal-and-vertical orbit, not a simple up-and-down line."],
["Travel", "The wave height pattern moves in +x."],
["Visible thing", "The tiled surface shape; the yellow voxel ring marks an orbital path."],
["Analogy", "A float traces a small loop while distant crests pass beneath it."],
["Simplification", "This model resembles deep water; shallow-water particles move mostly up and down."],
],
caution:
"Water is the geometry reminder: particle motion can be orbital, so it is not accurately labeled merely transverse or longitudinal."
}
};
function renderComparison() {
inspector.style.setProperty("--accent", "#ffe36b");
inspector.innerHTML = `
<div class="eyebrow">Compare / Medium map</div>
<h2>Travel is not the same as particle motion.</h2>
<p class="lead">
All three patterns travel to the right. What the particles do depends on the
medium and its restoring forces—not on a universal sine-shaped geometry.
</p>
<div class="compare-title">Particle-motion analogies</div>
<div class="compare-row" style="--row-color: var(--orange)">
<i></i>
<div>
<strong>Rope · transverse</strong>
<span>Particles move up and down, perpendicular to travel.</span>
</div>
</div>
<div class="compare-row" style="--row-color: var(--cyan)">
<i></i>
<div>
<strong>Air tube · longitudinal</strong>
<span>Particles move back and forth, parallel to travel.</span>
</div>
</div>
<div class="compare-row" style="--row-color: var(--blue)">
<i></i>
<div>
<strong>Surface water · orbital</strong>
<span>Particles trace loops in a vertical slice while crests travel on.</span>
</div>
</div>
<div class="equation">
<small>Shared wave idea</small>
<code>phase = kx − ωt, pattern speed v = ω/k</code>
</div>
<div class="analogy">
<strong>Key distinction</strong>
The equation describes a traveling phase pattern. It does not, by itself,
prescribe a particle’s geometry. The medium supplies that geometry.
</div>
<p class="caution">
Select a station to inspect its explicit teaching-scale model. The blocks
and tiles are enlarged particle markers, not literal chunks of each medium.
</p>
`;
}
function renderStation(id) {
const info = stationInfo[id];
inspector.style.setProperty("--accent", info.accent);
inspector.innerHTML = `
<div class="eyebrow">${info.eyebrow}</div>
<h2>${info.title}</h2>
<p class="lead">${info.lead}</p>
<div class="equation">
<small>Simplified motion model</small>
<code>${info.equation}</code>
</div>
<dl class="detail-list">
${info.details
.map(
([term, description]) => `
<div class="detail">
<dt>${term}</dt>
<dd>${description}</dd>
</div>
`
)
.join("")}
</dl>
<div class="analogy">
<strong>Remember</strong>
${info.caution}
</div>
`;
}
/* ------------------------------------------------------------------
Three.js setup
------------------------------------------------------------------ */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b121d);
scene.fog = new THREE.Fog(0x0b121d, 54, 108);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 250);
const hemisphere = new THREE.HemisphereLight(0xc9e2ff, 0x171323, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3dc, 3.1);
keyLight.position.set(-12, 24, 16);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -30;
keyLight.shadow.camera.right = 30;
keyLight.shadow.camera.top = 22;
keyLight.shadow.camera.bottom = -16;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 70;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4e88ff, 1.6);
rimLight.position.set(18, 9, -18);
scene.add(rimLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0x111a27,
roughness: 0.98,
metalness: 0.02
}),
dark: new THREE.MeshStandardMaterial({
color: 0x263349,
roughness: 0.88,
metalness: 0.08
}),
darker: new THREE.MeshStandardMaterial({
color: 0x182335,
roughness: 0.9,
metalness: 0.06
}),
steel: new THREE.MeshStandardMaterial({
color: 0x60728a,
roughness: 0.65,
metalness: 0.35
}),
rope: new THREE.MeshStandardMaterial({
color: 0xff7d32,
roughness: 0.72,
metalness: 0.05
}),
ropeLink: new THREE.MeshStandardMaterial({
color: 0xc95b26,
roughness: 0.76
}),
ropeGhost: new THREE.MeshStandardMaterial({
color: 0x715445,
roughness: 1
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x35d7ff,
roughness: 0.55,
metalness: 0.08
}),
cyanDark: new THREE.MeshStandardMaterial({
color: 0x167b9d,
roughness: 0.8
}),
blue: new THREE.MeshStandardMaterial({
color: 0x3978ee,
roughness: 0.62,
metalness: 0.04
}),
blueDark: new THREE.MeshStandardMaterial({
color: 0x16396c,
roughness: 0.92
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xffe36b,
roughness: 0.58,
metalness: 0.08
}),
orange: new THREE.MeshStandardMaterial({
color: 0xff9b42,
roughness: 0.65
}),
glass: new THREE.MeshStandardMaterial({
color: 0x3a7692,
roughness: 0.35,
metalness: 0.05,
transparent: true,
opacity: 0.2,
depthWrite: false
})
};
function box(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makePlatform(group, accentHex) {
const accent = new THREE.MeshStandardMaterial({
color: 0x172437,
roughness: 0.88,
metalness: 0.08,
emissive: new THREE.Color(accentHex),
emissiveIntensity: 0.018
});
box(group, [10.4, 0.44, 7.15], [0, -0.26, 0], accent);
box(group, [9.95, 0.08, 6.72], [0, 0, 0], materials.darker);
const edgeMaterial = new THREE.MeshStandardMaterial({
color: accentHex,
emissive: new THREE.Color(accentHex),
emissiveIntensity: 0.13,
roughness: 0.62
});
for (let i = 0; i < 9; i++) {
box(
group,
[0.92, 0.09, 0.12],
[-4.05 + i * 1.01, 0.06, 3.53],
edgeMaterial,
false
);
}
return { accent, edgeMaterial };
}
function makeVoxelArrow(parent, colorMaterial, z, y = 0.12) {
const arrow = new THREE.Group();
arrow.position.z = z;
arrow.position.y = y;
box(arrow, [2.1, 0.12, 0.16], [-0.15, 0, 0], colorMaterial, false);
box(arrow, [0.27, 0.2, 0.3], [1.05, 0, 0], colorMaterial, false);
box(arrow, [0.27, 0.17, 0.3], [0.76, 0, 0.27], colorMaterial, false);
box(arrow, [0.27, 0.17, 0.3], [0.76, 0, -0.27], colorMaterial, false);
parent.add(arrow);
return arrow;
}
/* ------------------------------------------------------------------
Station 1: transverse rope
------------------------------------------------------------------ */
function createRopeStation() {
const group = new THREE.Group();
group.position.x = -12;
const platform = makePlatform(group, 0xff8a42);
makeVoxelArrow(group, materials.orange, 2.8, 0.12);
const baseY = 2.25;
const count = 25;
const length = 8.4;
const spacing = length / (count - 1);
const waveNumber = (Math.PI * 2) / 3.35;
const markers = [];
const links = [];
const baseXs = [];
for (let i = 0; i < count; i++) {
const x = -length / 2 + i * spacing;
baseXs.push(x);
box(
group,
[0.13, 0.13, 0.13],
[x, baseY, 0.18],
materials.ropeGhost,
false
);
const marker = box(group, [0.34, 0.34, 0.34], [x, baseY, 0], materials.rope);
markers.push(marker);
if (i < count - 1) {
links.push(
box(
group,
[1, 0.13, 0.13],
[x, baseY, 0],
materials.ropeLink
)
);
}
}
// Blocky anchor posts.
for (const x of [-4.62, 4.62]) {
for (let level = 0; level < 6; level++) {
box(
group,
[0.44, 0.42, 0.48],
[x, 0.24 + level * 0.42, 0],
materials.steel
);
}
box(group, [0.72, 0.22, 0.72], [x, 2.72, 0], materials.dark);
}
const unitX = new THREE.Vector3(1, 0, 0);
const direction = new THREE.Vector3();
const midpoint = new THREE.Vector3();
function update(time) {
for (let i = 0; i < count; i++) {
const x = baseXs[i];
const normalized = i / (count - 1);
const envelope = Math.sin(Math.PI * normalized);
const phase = waveNumber * x - time * 2.48;
const y = baseY + 0.78 * Math.sin(phase) * envelope;
markers[i].position.set(x, y, 0);
markers[i].rotation.z = 0.12 * Math.cos(phase) * envelope;
}
for (let i = 0; i < links.length; i++) {
const a = markers[i].position;
const b = markers[i + 1].position;
direction.subVectors(b, a);
const lengthNow = direction.length();
midpoint.addVectors(a, b).multiplyScalar(0.5);
links[i].position.copy(midpoint);
links[i].quaternion.setFromUnitVectors(unitX, direction.normalize());
links[i].scale.set(lengthNow, 0.13, 0.13);
}
}
return {
id: "rope",
group,
platform,
labelHeight: 4.3,
update
};
}
/* ------------------------------------------------------------------
Station 2: longitudinal sound tube
------------------------------------------------------------------ */
function createTubeStation() {
const group = new THREE.Group();
const platform = makePlatform(group, 0x35d7ff);
makeVoxelArrow(group, materials.cyan, 2.45, 0.12);
// Square, open-front teaching tube.
box(group, [9.8, 0.16, 2.6], [0, 0.57, 0], materials.darker);
box(group, [9.8, 2.9, 0.08], [0, 2.05, -1.27], materials.glass, false);
for (const z of [-1.25, 1.25]) {
box(group, [9.8, 0.16, 0.17], [0, 0.66, z], materials.steel);
box(group, [9.8, 0.16, 0.17], [0, 3.46, z], materials.steel);
}
for (let i = 0; i <= 8; i++) {
const x = -4.8 + i * 1.2;
box(group, [0.16, 2.8, 0.16], [x, 2.05, -1.25], materials.steel);
box(group, [0.16, 0.16, 2.5], [x, 3.46, 0], materials.steel);
}
const count = 31;
const spacing = 0.31;
const rows = [1.18, 1.92, 2.66];
const waveNumber = (Math.PI * 2) / 4.15;
const amplitude = 0.18;
const particleGeometry = new THREE.BoxGeometry(0.21, 0.21, 0.21);
const particleMesh = new THREE.InstancedMesh(
particleGeometry,
materials.cyan,
count * rows.length
);
particleMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
particleMesh.castShadow = true;
particleMesh.receiveShadow = true;
group.add(particleMesh);
const dummy = new THREE.Object3D();
const baseXs = [];
const baseColor = new THREE.Color(0x1db8ee);
const compressedColor = new THREE.Color(0xffe36b);
const tempColor = new THREE.Color();
for (let i = 0; i < count; i++) {
const x = -4.65 + i * spacing;
baseXs.push(x);
box(group, [0.1, 0.09, 0.1], [x, 0.69, 0], materials.cyanDark, false);
}
// Source diaphragm and receiver wall.
for (let i = 0; i < 4; i++) {
box(group, [0.55, 0.45, 0.55], [-5.18, 0.9 + i * 0.48, 0], materials.orange);
}
for (let i = 0; i < 6; i++) {
box(group, [0.45, 0.42, 2.55], [5.18, 0.85 + i * 0.42, 0], materials.dark);
}
const piston = box(group, [0.16, 1.6, 2.15], [-4.86, 2.05, 0], materials.yellow);
function update(time) {
for (let row = 0; row < rows.length; row++) {
for (let i = 0; i < count; i++) {
const index = row * count + i;
const baseX = baseXs[i];
const phase = waveNumber * baseX - time * 2.48;
const displacement = amplitude * Math.sin(phase);
dummy.position.set(baseX + displacement, rows[row], 0);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
particleMesh.setMatrixAt(index, dummy.matrix);
const compression = Math.max(0, Math.cos(phase));
tempColor.copy(baseColor).lerp(compressedColor, compression * 0.92);
particleMesh.setColorAt(index, tempColor);
}
}
particleMesh.instanceMatrix.needsUpdate = true;
if (particleMesh.instanceColor) {
particleMesh.instanceColor.needsUpdate = true;
}
piston.position.x = -4.86 + 0.12 * Math.sin(-time * 2.48);
}
return {
id: "tube",
group,
platform,
labelHeight: 4.35,
update
};
}
/* ------------------------------------------------------------------
Station 3: surface water with orbital particle motion
------------------------------------------------------------------ */
function createWaterStation() {
const group = new THREE.Group();
group.position.x = 12;
const platform = makePlatform(group, 0x4d83ff);
makeVoxelArrow(group, materials.blue, 2.9, 0.12);
// Voxel basin.
box(group, [9.65, 0.2, 4.25], [0, 0.38, 0], materials.blueDark);
box(group, [9.8, 0.55, 0.18], [0, 0.62, -2.08], materials.dark);
box(group, [9.8, 0.55, 0.18], [0, 0.62, 2.08], materials.dark);
box(group, [0.18, 0.55, 4.2], [-4.8, 0.62, 0], materials.dark);
box(group, [0.18, 0.55, 4.2], [4.8, 0.62, 0], materials.dark);
const nx = 19;
const nz = 7;
const spacing = 0.48;
const surfaceY = 1.03;
const waveNumber = (Math.PI * 2) / 4.2;
const horizontalAmplitude = 0.28;
const verticalAmplitude = 0.45;
const waterGeometry = new THREE.BoxGeometry(0.46, 0.28, 0.46);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x3978ee,
roughness: 0.54,
metalness: 0.05
});
const waterMesh = new THREE.InstancedMesh(
waterGeometry,
waterMaterial,
nx * nz
);
waterMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
waterMesh.castShadow = true;
waterMesh.receiveShadow = true;
group.add(waterMesh);
const dummy = new THREE.Object3D();
const baseXs = [];
const baseZs = [];
const deepBlue = new THREE.Color(0x245bc8);
const crestBlue = new THREE.Color(0x54d5ff);
const tempColor = new THREE.Color();
for (let ix = 0; ix < nx; ix++) {
baseXs.push(-((nx - 1) * spacing) / 2 + ix * spacing);
}
for (let iz = 0; iz < nz; iz++) {
baseZs.push(-((nz - 1) * spacing) / 2 + iz * spacing);
}
// A blocky orbit marker in the x–y plane.
const orbitCenterX = 0;
const orbitCenterY = surfaceY;
const orbitZ = 1.67;
for (let i = 0; i < 16; i++) {
const angle = (i / 16) * Math.PI * 2;
box(
group,
[0.11, 0.11, 0.11],
[
orbitCenterX + horizontalAmplitude * 1.65 * Math.cos(angle),
orbitCenterY + verticalAmplitude * 1.65 * Math.sin(angle),
orbitZ
],
materials.yellow,
false
);
}
box(
group,
[0.07, 1.45, 0.07],
[orbitCenterX, orbitCenterY, orbitZ],
materials.yellow,
false
);
function update(time) {
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const index = iz * nx + ix;
const baseX = baseXs[ix];
const baseZ = baseZs[iz];
const phase = waveNumber * baseX - time * 2.12;
const horizontal = horizontalAmplitude * Math.cos(phase);
const vertical = verticalAmplitude * Math.sin(phase);
dummy.position.set(baseX + horizontal, surfaceY + vertical, baseZ);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
waterMesh.setMatrixAt(index, dummy.matrix);
const brightness = (vertical / verticalAmplitude + 1) * 0.5;
tempColor.copy(deepBlue).lerp(crestBlue, brightness);
waterMesh.setColorAt(index, tempColor);
}
}
waterMesh.instanceMatrix.needsUpdate = true;
if (waterMesh.instanceColor) {
waterMesh.instanceColor.needsUpdate = true;
}
}
return {
id: "water",
group,
platform,
labelHeight: 4.25,
update
};
}
const rope = createRopeStation();
const tube = createTubeStation();
const water = createWaterStation();
const stations = {
rope,
tube,
water
};
for (const station of Object.values(stations)) {
scene.add(station.group);
station.group.traverse((object) => {
object.userData.stationId = station.id;
});
station.update(0);
}
// Shared ground platform.
box(scene, [52, 0.5, 18], [0, -0.72, 0], materials.ground);
// Sparse background voxel columns for depth.
const backgroundMaterial = new THREE.MeshStandardMaterial({
color: 0x172235,
roughness: 1
});
for (const [x, z, h] of [
[-20, -7, 1.2],
[-18, -6, 2.4],
[18, -7, 1.8],
[20, -6, 3.1],
[21, -5, 1.3],
[-5, -8, 0.8],
[7, -8, 1.1]
]) {
box(scene, [0.75, h, 0.75], [x, -0.45 + h / 2, z], backgroundMaterial);
}
/* ------------------------------------------------------------------
Camera controls implemented directly, without addons
------------------------------------------------------------------ */
const cameraState = {
target: new THREE.Vector3(0, 1.1, 0),
desiredTarget: new THREE.Vector3(0, 1.1, 0),
distance: 42,
desiredDistance: 42,
yaw: 0.16,
desiredYaw: 0.16,
pitch: 0.44,
desiredPitch: 0.44
};
function overviewDistance() {
const halfFov = THREE.MathUtils.degToRad(camera.fov * 0.5);
return THREE.MathUtils.clamp(
20 / (Math.tan(halfFov) * camera.aspect),
38,
72
);
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
cameraState.distance = overviewDistance();
cameraState.desiredDistance = cameraState.distance;
let selectedId = null;
let paused = false;
let speed = 1;
let simulationTime = 0;
function setSelected(id) {
selectedId = id;
for (const button of stationButtons) {
const active = button.dataset.station === id;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
overviewButton.classList.toggle("active", id === null);
for (const station of Object.values(stations)) {
const active = station.id === id;
const glow = active ? 0.15 : id === null ? 0.04 : 0.012;
station.platform.accent.emissiveIntensity = glow;
station.platform.edgeMaterial.emissiveIntensity = active ? 0.65 : 0.22;
}
if (id === null) {
renderComparison();
cameraState.desiredTarget.set(0, 1.1, 0);
cameraState.desiredDistance = overviewDistance();
cameraState.desiredYaw = 0.16;
cameraState.desiredPitch = 0.44;
} else {
renderStation(id);
const station = stations[id];
cameraState.desiredTarget.set(station.group.position.x, 1.15, 0);
cameraState.desiredDistance = 15.2;
cameraState.desiredYaw = 0.2;
cameraState.desiredPitch = 0.39;
}
}
overviewButton.addEventListener("click", () => setSelected(null));
for (const button of stationButtons) {
button.addEventListener("click", () => setSelected(button.dataset.station));
}
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "▶ Play" : "Ⅱ Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
pauseButton.classList.toggle("active", paused);
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
speedValue.value = `${speed.toFixed(1)}×`;
});
const drag = {
active: false,
pointerId: null,
lastX: 0,
lastY: 0,
moved: false
};
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
drag.active = true;
drag.pointerId = event.pointerId;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
drag.moved = false;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!drag.active || event.pointerId !== drag.pointerId) return;
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
drag.moved = true;
}
cameraState.desiredYaw -= dx * 0.0055;
cameraState.desiredPitch = THREE.MathUtils.clamp(
cameraState.desiredPitch + dy * 0.0045,
0.13,
1.12
);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
canvas.addEventListener("pointerup", (event) => {
if (!drag.active || event.pointerId !== drag.pointerId) return;
drag.active = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (!drag.moved) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(scene.children, true);
if (hits.length) {
let object = hits[0].object;
while (object && !object.userData.stationId) {
object = object.parent;
}
if (object?.userData.stationId) {
setSelected(object.userData.stationId);
}
}
}
});
canvas.addEventListener("pointercancel", () => {
drag.active = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredDistance = THREE.MathUtils.clamp(
cameraState.desiredDistance + event.deltaY * 0.018,
8,
78
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
} else if (event.key === "1") {
setSelected("rope");
} else if (event.key === "2") {
setSelected("tube");
} else if (event.key === "3") {
setSelected("water");
} else if (event.key === "0") {
setSelected(null);
}
});
/* ------------------------------------------------------------------
World labels and animation loop
------------------------------------------------------------------ */
const labelAnchors = [
{ element: worldLabelButtons[0], station: rope },
{ element: worldLabelButtons[1], station: tube },
{ element: worldLabelButtons[2], station: water }
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const anchor of labelAnchors) {
anchor.station.group.updateWorldMatrix(true, false);
projected.set(0, anchor.station.labelHeight, 0);
anchor.station.group.localToWorld(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
anchor.element.style.display = visible ? "flex" : "none";
anchor.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
anchor.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 6.5);
cameraState.target.lerp(cameraState.desiredTarget, smoothing);
cameraState.distance = THREE.MathUtils.lerp(
cameraState.distance,
cameraState.desiredDistance,
smoothing
);
cameraState.yaw = THREE.MathUtils.lerp(
cameraState.yaw,
cameraState.desiredYaw,
smoothing
);
cameraState.pitch = THREE.MathUtils.lerp(
cameraState.pitch,
cameraState.desiredPitch,
smoothing
);
const horizontalDistance =
cameraState.distance * Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + horizontalDistance * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.distance * Math.sin(cameraState.pitch),
cameraState.target.z + horizontalDistance * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
setSelected(null);
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
simulationTime += delta * speed;
}
rope.update(simulationTime);
tube.update(simulationTime);
water.update(simulationTime);
updateCamera(delta);
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```