Prompt specification
Build or customize the Three.js 3D scene "Water-supply transient museum display" 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: Water-supply transient museum display
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/water-supply-transient-museum-display-x1495
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing pressure waves caused by valve closure. Compose a small pipe network, valve, and surge-storage chamber; show conceptual wave travel and storage response without offering plumbing design or pressure-rating claims. Voxel style.
Working Three.js Starter (water-supply-transient-museum-display-x1495):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Pressure-Wave Study</title>
<style>
:root {
color-scheme: dark;
--bg: #07131e;
--panel: rgba(10, 25, 38, 0.88);
--panel-border: rgba(150, 205, 230, 0.2);
--text: #eaf7ff;
--muted: #91aebe;
--cyan: #54e4ff;
--orange: #ff835f;
--violet: #bb91ff;
--green: #70e6ad;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--text);
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#app canvas {
cursor: grab;
touch-action: none;
}
#app canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 18px 20px;
border-radius: 16px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.readout {
top: 20px;
right: 20px;
width: 290px;
padding: 15px;
border-radius: 16px;
}
.readout-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--green);
box-shadow: 0 0 14px rgba(112, 230, 173, 0.8);
}
.status-dot.closing {
background: var(--orange);
box-shadow: 0 0 14px rgba(255, 131, 95, 0.8);
}
.status-dot.wave {
background: var(--cyan);
box-shadow: 0 0 14px rgba(84, 228, 255, 0.8);
}
.readout-row {
display: flex;
justify-content: space-between;
gap: 20px;
padding: 7px 0;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: var(--muted);
font-size: 12px;
}
.readout-row strong {
color: var(--text);
font-weight: 700;
}
#phaseText {
min-height: 34px;
margin: 11px 0 0;
color: var(--cyan);
font-size: 12px;
line-height: 1.45;
}
.legend {
right: 20px;
bottom: 116px;
width: 290px;
padding: 15px;
border-radius: 16px;
}
.legend-title {
margin-bottom: 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
margin: 8px 0;
color: var(--muted);
font-size: 12px;
}
.swatch {
width: 23px;
height: 10px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: 0 0 12px currentColor;
}
.swatch.compression {
color: var(--orange);
background: var(--orange);
}
.swatch.relief {
color: var(--cyan);
background: var(--cyan);
}
.swatch.exchange {
color: var(--violet);
background: var(--violet);
}
.controls {
left: 50%;
bottom: 20px;
width: min(920px, calc(100vw - 40px));
padding: 13px 15px;
border-radius: 16px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 10px;
}
button {
min-height: 42px;
padding: 0 16px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 9px;
background: rgba(255, 255, 255, 0.07);
color: var(--text);
font: inherit;
font-size: 13px;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease,
border-color 150ms ease;
}
button:hover:not(:disabled) {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 255, 255, 0.26);
transform: translateY(-1px);
}
button.primary {
color: #09202b;
border-color: transparent;
background: var(--cyan);
}
button.primary:hover:not(:disabled) {
background: #82ecff;
}
button:disabled {
opacity: 0.42;
cursor: default;
}
.speed-control {
display: flex;
align-items: center;
gap: 10px;
margin-left: auto;
padding-left: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
white-space: nowrap;
}
input[type="range"] {
width: 100px;
accent-color: var(--cyan);
cursor: pointer;
}
#speedValue {
min-width: 35px;
color: var(--text);
text-align: right;
}
.disclaimer {
position: fixed;
z-index: 9;
bottom: 101px;
left: 20px;
max-width: min(460px, calc(100vw - 40px));
padding: 8px 11px;
border-left: 3px solid var(--orange);
background: rgba(7, 19, 30, 0.82);
color: #b6c8d3;
font-size: 10px;
line-height: 1.45;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 6px;
background: rgba(7, 19, 30, 0.82);
color: #dff5ff;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.025em;
white-space: nowrap;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
.scene-label.orange {
color: var(--orange);
}
.scene-label.cyan {
color: var(--cyan);
}
.scene-label.violet {
color: var(--violet);
}
.help {
position: fixed;
z-index: 8;
top: 178px;
left: 20px;
color: rgba(210, 235, 245, 0.6);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.intro {
display: none;
}
.readout {
top: 113px;
right: 12px;
width: 235px;
padding: 12px;
}
.legend {
display: none;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
flex-wrap: wrap;
padding: 10px;
}
button {
flex: 1 1 auto;
padding: 0 11px;
}
.speed-control {
width: 100%;
margin: 0;
padding: 3px 4px 0;
}
input[type="range"] {
flex: 1;
}
.disclaimer {
bottom: 122px;
left: 12px;
max-width: calc(100vw - 24px);
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<header class="panel brand">
<div class="eyebrow">Conceptual flow visualization</div>
<h1>Valve-Closure Pressure Waves</h1>
<p class="intro">
Explore a stylized pipe network as a valve closes. Colored voxel pulses
symbolize compression, pressure relief, and exchange with a surge-storage
chamber.
</p>
</header>
<aside class="panel readout">
<div class="readout-title">
Visualization state
<span id="statusDot" class="status-dot"></span>
</div>
<div class="readout-row">
<span>Valve</span>
<strong id="valveState">Open</strong>
</div>
<div class="readout-row">
<span>Chamber fill</span>
<strong id="levelValue">14%</strong>
</div>
<div class="readout-row">
<span>Animation</span>
<strong id="animationState">Ready</strong>
</div>
<p id="phaseText">Close the valve to begin the conceptual wave sequence.</p>
</aside>
<aside class="panel legend">
<div class="legend-title">Wave symbols</div>
<div class="legend-item">
<span class="swatch compression"></span>
<span>Upstream compression</span>
</div>
<div class="legend-item">
<span class="swatch relief"></span>
<span>Downstream pressure relief</span>
</div>
<div class="legend-item">
<span class="swatch exchange"></span>
<span>Chamber exchange / return</span>
</div>
</aside>
<div id="labels"></div>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<div class="disclaimer">
Illustrative concept only. This is not a hydraulic solver and provides no
plumbing design, pressure prediction, sizing guidance, or pressure-rating
information.
</div>
<nav class="panel controls" aria-label="Animation controls">
<button id="closeBtn" class="primary">Close valve</button>
<button id="pauseBtn">Pause</button>
<button id="resetBtn">Reset</button>
<label class="speed-control" for="speed">
Visual speed
<input id="speed" type="range" min="0.5" max="1.5" step="0.1" value="1">
<span id="speedValue">1.0×</span>
</label>
</nav>
<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 app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131e);
scene.fog = new THREE.Fog(0x07131e, 25, 46);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
app.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-12, 12, 8, -8, 0.1, 100);
const orbit = {
theta: 0.70,
phi: 0.92,
zoom: 1,
target: new THREE.Vector3(0.3, 2.35, -0.7),
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const frustumHeight = Math.max(14.5, 24.5 / aspect) / orbit.zoom;
camera.left = -frustumHeight * aspect * 0.5;
camera.right = frustumHeight * aspect * 0.5;
camera.top = frustumHeight * 0.5;
camera.bottom = -frustumHeight * 0.5;
camera.updateProjectionMatrix();
const radius = 25;
camera.position.set(
orbit.target.x + radius * Math.sin(orbit.phi) * Math.sin(orbit.theta),
orbit.target.y + radius * Math.cos(orbit.phi),
orbit.target.z + radius * Math.sin(orbit.phi) * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.70;
orbit.phi = 0.92;
orbit.zoom = 1;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.lastX;
const dy = event.clientY - orbit.lastY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.42,
1.34
);
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
updateCamera();
});
function endDrag(event) {
orbit.dragging = false;
renderer.domElement.classList.remove("dragging");
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.65
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", updateCamera);
updateCamera();
// -------------------------------------------------------------------------
// Lighting and materials
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbfeaff, 0x14202c, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(8, 16, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -17;
keyLight.shadow.camera.right = 17;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -14;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x48cfff, 1.6);
rimLight.position.set(-11, 8, -9);
scene.add(rimLight);
const unitCube = new THREE.BoxGeometry(1, 1, 1);
const materials = {
shell: new THREE.MeshStandardMaterial({
color: 0x557789,
roughness: 0.58,
metalness: 0.18
}),
shellDark: new THREE.MeshStandardMaterial({
color: 0x294658,
roughness: 0.62,
metalness: 0.2
}),
rib: new THREE.MeshStandardMaterial({
color: 0x7ba4b8,
roughness: 0.42,
metalness: 0.3
}),
fluid: new THREE.MeshStandardMaterial({
color: 0x0b6170,
emissive: 0x063945,
emissiveIntensity: 0.7,
transparent: true,
opacity: 0.78,
roughness: 0.35
}),
dark: new THREE.MeshStandardMaterial({
color: 0x172b39,
roughness: 0.72,
metalness: 0.15
}),
pale: new THREE.MeshStandardMaterial({
color: 0x9ebdca,
roughness: 0.48,
metalness: 0.28
}),
orange: new THREE.MeshStandardMaterial({
color: 0xff835f,
emissive: 0xb83d20,
emissiveIntensity: 0.75,
roughness: 0.45
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x54e4ff,
emissive: 0x168ba3,
emissiveIntensity: 0.9,
roughness: 0.4
}),
glass: new THREE.MeshStandardMaterial({
color: 0x6dcce0,
transparent: true,
opacity: 0.1,
roughness: 0.18,
metalness: 0.08,
depthWrite: false,
side: THREE.DoubleSide
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(unitCube, 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;
}
// -------------------------------------------------------------------------
// Voxel platform
// -------------------------------------------------------------------------
addBox(
scene,
[26.5, 0.5, 18],
[0, -0.38, -1.1],
new THREE.MeshStandardMaterial({
color: 0x0c1d29,
roughness: 0.9,
metalness: 0.05
}),
false
);
const tileCountX = 18;
const tileCountZ = 12;
const tileGeometry = new THREE.BoxGeometry(1, 1, 1);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
metalness: 0.03,
vertexColors: true
});
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCountX * tileCountZ
);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
let tileIndex = 0;
for (let x = 0; x < tileCountX; x++) {
for (let z = 0; z < tileCountZ; z++) {
dummy.position.set(
-12.1 + x * 1.42,
-0.09,
-7.1 + z * 1.42
);
dummy.scale.set(1.35, 0.11, 1.35);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const shade = 0.025 + ((x * 7 + z * 11) % 5) * 0.005;
tiles.setColorAt(
tileIndex,
new THREE.Color().setHSL(0.54, 0.28, shade)
);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// -------------------------------------------------------------------------
// Cutaway voxel pipe construction
// -------------------------------------------------------------------------
const pipeY = 1.28;
function makePipeX(x1, x2) {
const min = Math.min(x1, x2);
const max = Math.max(x1, x2);
const length = max - min;
const cells = Math.ceil(length / 0.5);
for (let i = 0; i < cells; i++) {
const x = min + (i + 0.5) * (length / cells);
addBox(
scene,
[length / cells - 0.015, 0.22, 1.5],
[x, 0.58, 0],
materials.shell
);
addBox(
scene,
[length / cells - 0.015, 0.57, 0.2],
[x, 0.94, 0.65],
materials.shellDark
);
addBox(
scene,
[length / cells - 0.015, 0.24, 0.2],
[x, 0.76, -0.65],
materials.shell
);
if (i % 4 === 1) {
addBox(
scene,
[0.11, 0.72, 0.16],
[x, 0.98, 0.73],
materials.rib
);
addBox(
scene,
[0.11, 0.48, 0.16],
[x, 0.86, -0.73],
materials.rib
);
}
}
addBox(
scene,
[length, 0.12, 1.06],
[(min + max) * 0.5, 0.79, 0],
materials.fluid,
false
);
}
function makePipeZ(z1, z2, x) {
const min = Math.min(z1, z2);
const max = Math.max(z1, z2);
const length = max - min;
const cells = Math.ceil(length / 0.5);
for (let i = 0; i < cells; i++) {
const z = min + (i + 0.5) * (length / cells);
addBox(
scene,
[1.5, 0.22, length / cells - 0.015],
[x, 0.58, z],
materials.shell
);
addBox(
scene,
[0.2, 0.57, length / cells - 0.015],
[x + 0.65, 0.94, z],
materials.shellDark
);
addBox(
scene,
[0.2, 0.24, length / cells - 0.015],
[x - 0.65, 0.76, z],
materials.shell
);
if (i % 4 === 1) {
addBox(
scene,
[0.16, 0.72, 0.11],
[x + 0.73, 0.98, z],
materials.rib
);
addBox(
scene,
[0.16, 0.48, 0.11],
[x - 0.73, 0.86, z],
materials.rib
);
}
}
addBox(
scene,
[1.06, 0.12, length],
[x, 0.79, (min + max) * 0.5],
materials.fluid,
false
);
}
makePipeX(-9.3, -0.8);
makePipeX(0.8, 9.3);
makePipeZ(-0.55, -6.2, 4.8);
// Pipe supports.
[-7.5, -3.5, 2.8, 8.0].forEach((x) => {
addBox(scene, [0.45, 0.65, 1.0], [x, 0.22, 0], materials.dark);
});
[-2.2, -5.0].forEach((z) => {
addBox(scene, [0.9, 0.65, 0.45], [4.8, 0.22, z], materials.dark);
});
// Voxel supply module.
addBox(scene, [1.45, 2.35, 2.25], [-10.0, 0.95, 0], materials.shellDark);
addBox(scene, [1.65, 0.32, 2.4], [-10.0, 2.2, 0], materials.rib);
addBox(scene, [0.42, 1.1, 0.42], [-10.2, 2.7, -0.65], materials.shell);
addBox(scene, [0.42, 1.1, 0.42], [-10.2, 2.7, 0.65], materials.shell);
addBox(scene, [0.36, 0.65, 1.2], [-9.28, 1.35, 0], materials.fluid);
// Outlet cap.
addBox(scene, [0.3, 1.55, 1.6], [9.45, 1.0, 0], materials.shellDark);
addBox(scene, [0.12, 0.75, 0.8], [9.64, 1.35, 0], materials.fluid, false);
// Branch cap.
addBox(scene, [1.6, 1.55, 0.3], [4.8, 1.0, -6.35], materials.shellDark);
// -------------------------------------------------------------------------
// Voxel valve
// -------------------------------------------------------------------------
[-0.48, 0.48].forEach((x) => {
addBox(scene, [0.22, 1.95, 0.22], [x, 1.32, 0.79], materials.rib);
addBox(scene, [0.22, 1.95, 0.22], [x, 1.32, -0.79], materials.rib);
addBox(scene, [0.22, 0.22, 1.8], [x, 2.23, 0], materials.rib);
});
const gateGroup = new THREE.Group();
gateGroup.position.set(0, 3.35, 0);
scene.add(gateGroup);
addBox(gateGroup, [0.22, 1.45, 1.38], [0, 0, 0], materials.orange);
addBox(gateGroup, [0.12, 1.35, 0.12], [0, 1.0, 0], materials.pale);
addBox(gateGroup, [0.85, 0.14, 0.16], [0, 1.7, 0], materials.pale);
addBox(gateGroup, [0.14, 0.14, 0.85], [0, 1.7, 0], materials.pale);
// -------------------------------------------------------------------------
// Surge-storage chamber
// -------------------------------------------------------------------------
const chamberX = 5.8;
const chamberZ = 0;
const chamberBase = 2.45;
const chamberHeight = 5.1;
const chamberLevels = 12;
const cellSize = 0.425;
const chamberFootprint = 5;
// Vertical connector.
addBox(scene, [0.86, 1.15, 0.86], [chamberX, 1.95, chamberZ], materials.fluid);
addBox(scene, [0.16, 1.2, 0.16], [chamberX - 0.48, 2.0, chamberZ - 0.48], materials.rib);
addBox(scene, [0.16, 1.2, 0.16], [chamberX + 0.48, 2.0, chamberZ + 0.48], materials.rib);
// Corner columns.
[-1.34, 1.34].forEach((dx) => {
[-1.34, 1.34].forEach((dz) => {
for (let level = 0; level < chamberLevels; level++) {
addBox(
scene,
[0.32, 0.39, 0.32],
[
chamberX + dx,
chamberBase + level * cellSize + cellSize * 0.5,
chamberZ + dz
],
level % 3 === 0 ? materials.rib : materials.shell
);
}
});
});
// Horizontal frame bands.
for (let level = 0; level <= chamberLevels; level += 3) {
const y = chamberBase + level * cellSize;
[-1.34, 1.34].forEach((dz) => {
addBox(scene, [2.85, 0.13, 0.14], [chamberX, y, chamberZ + dz], materials.rib);
});
[-1.34, 1.34].forEach((dx) => {
addBox(scene, [0.14, 0.13, 2.85], [chamberX + dx, y, chamberZ], materials.rib);
});
}
// Transparent rear wall only, preserving the cutaway view.
addBox(
scene,
[2.68, chamberHeight, 0.06],
[chamberX, chamberBase + chamberHeight * 0.5, chamberZ - 1.34],
materials.glass,
false
);
// Dynamic voxel fluid inside the chamber.
const fillCount = chamberFootprint * chamberFootprint * chamberLevels;
const fillMaterial = new THREE.MeshStandardMaterial({
color: 0x58d9ef,
emissive: 0x16849a,
emissiveIntensity: 0.72,
transparent: true,
opacity: 0.62,
depthWrite: false,
roughness: 0.3
});
const chamberFill = new THREE.InstancedMesh(unitCube, fillMaterial, fillCount);
chamberFill.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
chamberFill.frustumCulled = false;
scene.add(chamberFill);
const gaugeBlocks = [];
for (let i = 0; i < chamberLevels; i++) {
const block = addBox(
scene,
[0.22, 0.27, 0.22],
[7.65, chamberBase + i * cellSize + 0.15, 1.42],
new THREE.MeshStandardMaterial({
color: 0x193542,
emissive: 0x000000,
roughness: 0.5
}),
false
);
gaugeBlocks.push(block);
}
function updateChamberFill(level) {
let index = 0;
for (let layer = 0; layer < chamberLevels; layer++) {
for (let ix = 0; ix < chamberFootprint; ix++) {
for (let iz = 0; iz < chamberFootprint; iz++) {
const centerY =
chamberBase + layer * cellSize + cellSize * 0.5;
dummy.position.set(
chamberX + (ix - (chamberFootprint - 1) / 2) * 0.47,
centerY,
chamberZ + (iz - (chamberFootprint - 1) / 2) * 0.47
);
const visible = centerY <= chamberBase + level * chamberHeight;
dummy.scale.set(
visible ? 0.43 : 0,
visible ? 0.40 : 0,
visible ? 0.43 : 0
);
dummy.updateMatrix();
chamberFill.setMatrixAt(index++, dummy.matrix);
}
}
}
chamberFill.instanceMatrix.needsUpdate = true;
gaugeBlocks.forEach((block, i) => {
const active = i / chamberLevels < level;
block.material.color.setHex(active ? 0x54e4ff : 0x193542);
block.material.emissive.setHex(active ? 0x126f82 : 0x000000);
block.material.emissiveIntensity = active ? 0.8 : 0;
});
}
// -------------------------------------------------------------------------
// Labels
// -------------------------------------------------------------------------
const labelLayer = document.getElementById("labels");
const labels = [];
function makeLabel(text, anchor, colorClass = "") {
const element = document.createElement("div");
element.className = `scene-label ${colorClass}`;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
element,
anchor: anchor.clone()
});
}
makeLabel("Supply module", new THREE.Vector3(-10, 3.05, 0));
makeLabel("Fast-close valve", new THREE.Vector3(0, 4.3, 0), "orange");
makeLabel("Compression symbol", new THREE.Vector3(-5.3, 2.0, 0), "orange");
makeLabel("Relief symbol", new THREE.Vector3(7.4, 2.0, 0), "cyan");
makeLabel("Surge-storage chamber", new THREE.Vector3(5.8, 8.05, 0), "violet");
makeLabel("Branch network", new THREE.Vector3(4.8, 2.1, -5.5));
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach(({ element, anchor }) => {
const projected = anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
element.style.display = visible ? "block" : "none";
element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
// -------------------------------------------------------------------------
// Conceptual wave routes and packets
// -------------------------------------------------------------------------
const compressionColor = 0xff835f;
const reliefColor = 0x54e4ff;
const exchangeColor = 0xbb91ff;
function route(ax, ay, az, bx, by, bz) {
const a = new THREE.Vector3(ax, ay, az);
const b = new THREE.Vector3(bx, by, bz);
return {
points: [a, b],
length: a.distanceTo(b)
};
}
const routes = {
upstream: route(0, pipeY, 0, -9.25, pipeY, 0),
downstream: route(0, pipeY, 0, 9.25, pipeY, 0),
branch: route(4.8, pipeY, 0, 4.8, pipeY, -6.15),
chamber: route(chamberX, 2.82, chamberZ, chamberX, pipeY, chamberZ),
reflected: route(chamberX, pipeY, chamberZ, 9.25, pipeY, chamberZ)
};
const waveRoot = new THREE.Group();
scene.add(waveRoot);
const waves = [];
const xAxis = new THREE.Vector3(1, 0, 0);
function spawnWave(routeData, color, options = {}) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending,
toneMapped: false
});
for (let i = 0; i < 6; i++) {
const cube = new THREE.Mesh(unitCube, material);
cube.scale.set(0.19, 0.72, 0.72);
cube.position.x = -i * 0.34;
group.add(cube);
}
group.visible = false;
waveRoot.add(group);
const wave = {
group,
material,
route: routeData,
color,
delay: options.delay ?? 0,
speed: options.speed ?? 2.75,
age: 0,
kind: options.kind ?? "wave"
};
waves.push(wave);
return wave;
}
function sampleRoute(routeData, distance) {
const d = THREE.MathUtils.clamp(distance, 0, routeData.length);
const a = routeData.points[0];
const b = routeData.points[1];
const tangent = b.clone().sub(a).normalize();
const position = a.clone().lerp(b, d / routeData.length);
return { position, tangent };
}
// -------------------------------------------------------------------------
// Animation state and UI
// -------------------------------------------------------------------------
const closeBtn = document.getElementById("closeBtn");
const pauseBtn = document.getElementById("pauseBtn");
const resetBtn = document.getElementById("resetBtn");
const speedInput = document.getElementById("speed");
const speedValue = document.getElementById("speedValue");
const valveState = document.getElementById("valveState");
const levelValue = document.getElementById("levelValue");
const animationState = document.getElementById("animationState");
const phaseText = document.getElementById("phaseText");
const statusDot = document.getElementById("statusDot");
let animationSpeed = 1;
let paused = false;
let state = "ready";
let closure = 0;
let closeElapsed = 0;
let wavesStarted = false;
let storageTriggered = false;
let reflectionTriggered = false;
let storageLevel = 0.14;
let storageTarget = 0.14;
function setPhase(title, description, dotClass = "") {
phaseText.textContent = description;
statusDot.className = `status-dot ${dotClass}`.trim();
animationState.textContent = title;
}
function startWaveEvent() {
wavesStarted = true;
spawnWave(routes.upstream, compressionColor, {
kind: "upstream",
speed: 2.55
});
spawnWave(routes.downstream, reliefColor, {
kind: "downstream",
speed: 2.65
});
spawnWave(routes.branch, reliefColor, {
kind: "branch",
delay: 0.9,
speed: 2.7
});
setPhase(
"Wave travel",
"Orange blocks move upstream while cyan blocks move toward the outlet and branch.",
"wave"
);
}
function triggerStorage() {
if (storageTriggered) return;
storageTriggered = true;
storageTarget = 0.69;
spawnWave(routes.chamber, exchangeColor, {
kind: "vertical",
speed: 2.75
});
setPhase(
"Chamber response",
"The chamber level rises and a violet exchange symbol moves toward the junction.",
"wave"
);
}
function triggerReflection() {
if (reflectionTriggered) return;
reflectionTriggered = true;
spawnWave(routes.reflected, exchangeColor, {
kind: "reflected",
speed: 2.55
});
setPhase(
"Chamber return",
"A violet return symbol travels downstream after the chamber exchange reaches the junction.",
"wave"
);
}
function removeWave(wave) {
waveRoot.remove(wave.group);
wave.material.dispose();
}
function resetSimulation() {
while (waves.length) removeWave(waves.pop());
state = "ready";
closure = 0;
closeElapsed = 0;
wavesStarted = false;
storageTriggered = false;
reflectionTriggered = false;
storageLevel = 0.14;
storageTarget = 0.14;
gateGroup.position.y = 3.35;
closeBtn.disabled = false;
closeBtn.textContent = "Close valve";
valveState.textContent = "Open";
levelValue.textContent = "14%";
animationState.textContent = "Ready";
phaseText.textContent =
"Close the valve to begin the conceptual wave sequence.";
statusDot.className = "status-dot";
updateChamberFill(storageLevel);
resetCamera();
}
closeBtn.addEventListener("click", () => {
if (state !== "ready") return;
state = "closing";
closeElapsed = 0;
closeBtn.disabled = true;
closeBtn.textContent = "Closing…";
valveState.textContent = "Moving";
animationState.textContent = "Closing";
statusDot.className = "status-dot closing";
phaseText.textContent =
"The gate moves into the pipe; wave packets remain hidden until closure completes.";
});
pauseBtn.addEventListener("click", () => {
paused = !paused;
pauseBtn.textContent = paused ? "Resume" : "Pause";
animationState.textContent = paused
? "Paused"
: state === "ready"
? "Ready"
: animationState.textContent;
});
resetBtn.addEventListener("click", resetSimulation);
speedInput.addEventListener("input", () => {
animationSpeed = Number(speedInput.value);
speedValue.textContent = `${animationSpeed.toFixed(1)}×`;
});
updateChamberFill(storageLevel);
// -------------------------------------------------------------------------
// Main animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const rawDelta = Math.min(clock.getDelta(), 0.05);
const delta = paused ? 0 : rawDelta * animationSpeed;
if (state === "closing") {
closeElapsed += delta;
const t = THREE.MathUtils.clamp(closeElapsed / 0.9, 0, 1);
closure = t * t * (3 - 2 * t);
gateGroup.position.y = 3.35 - closure * 1.84;
if (t >= 1) {
state = "closed";
valveState.textContent = "Closed";
closeBtn.textContent = "Valve closed";
startWaveEvent();
}
}
if (state === "closed" && !wavesStarted) {
startWaveEvent();
}
storageLevel +=
(storageTarget - storageLevel) *
(1 - Math.exp(-delta * 1.65));
if (Math.abs(storageLevel - storageTarget) < 0.0005) {
storageLevel = storageTarget;
}
updateChamberFill(storageLevel);
levelValue.textContent = `${Math.round(storageLevel * 100)}%`;
for (let i = waves.length - 1; i >= 0; i--) {
const wave = waves[i];
wave.age += delta;
if (wave.age < wave.delay) {
wave.group.visible = false;
continue;
}
const travelTime = wave.age - wave.delay;
const distance = travelTime * wave.speed;
if (distance > wave.route.length + 1.7) {
removeWave(wave);
waves.splice(i, 1);
continue;
}
const { position, tangent } = sampleRoute(
wave.route,
Math.min(distance, wave.route.length)
);
wave.group.visible = true;
wave.group.position.copy(position);
wave.group.quaternion.setFromUnitVectors(xAxis, tangent);
const fadeIn = Math.min(1, travelTime / 0.22);
const fadeOut =
1 -
THREE.MathUtils.clamp(
(distance - (wave.route.length - 1.2)) / 1.9,
0,
1
);
wave.material.opacity = 0.92 * fadeIn * Math.max(0, fadeOut);
if (
wave.kind === "downstream" &&
!storageTriggered &&
distance >= chamberX
) {
triggerStorage();
}
if (
wave.kind === "vertical" &&
!reflectionTriggered &&
distance >= wave.route.length
) {
triggerReflection();
}
}
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```