Prompt specification
Build or customize the Three.js 3D scene "Water channel path illustration" 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 channel path illustration
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/water-channel-path-illustration-x0618
Scene Description Prompt:
Water channel path illustration. Show shallow symbolic water beneath two sole patterns; animate paths through open grooves while a caption explains that this is geometric drainage visualization, not a grip test. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (water-channel-path-illustration-x0618):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Water Channel Path — Geometric Drainage Illustration</title>
<style>
:root {
color-scheme: dark;
--bg: #061017;
--panel: rgba(13, 30, 39, 0.78);
--line: rgba(159, 222, 232, 0.16);
--text: #edf7f5;
--muted: #8fa9af;
--cyan: #70e8f4;
--cyan-strong: #b9ffff;
--warm: #f0eee4;
}
* {
box-sizing: border-box;
}
html,
body {
min-height: 100%;
margin: 0;
}
body {
overflow-x: hidden;
background:
radial-gradient(circle at 12% 0%, rgba(22, 79, 91, 0.28), transparent 34rem),
radial-gradient(circle at 95% 80%, rgba(18, 63, 72, 0.18), transparent 30rem),
var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
.app {
width: min(1600px, 100%);
min-height: 100vh;
margin: 0 auto;
padding: 24px 28px 20px;
display: grid;
grid-template-rows: auto minmax(460px, 1fr) auto;
gap: 18px;
}
header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
padding: 4px 2px 2px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--cyan);
font-size: 0.7rem;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(2rem, 4vw, 4.1rem);
font-weight: 620;
letter-spacing: -0.055em;
line-height: 0.96;
}
.intro {
max-width: 610px;
margin: 11px 0 0;
color: var(--muted);
font-size: clamp(0.88rem, 1.4vw, 1rem);
line-height: 1.55;
}
.study-id {
flex: 0 0 auto;
display: grid;
gap: 5px;
justify-items: end;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.68rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.study-id strong {
color: var(--text);
font-size: 0.75rem;
font-weight: 650;
}
.stage {
position: relative;
min-height: 460px;
overflow: hidden;
isolation: isolate;
border: 1px solid var(--line);
border-radius: 26px;
background:
radial-gradient(circle at 50% 42%, rgba(24, 78, 91, 0.36), transparent 43%),
linear-gradient(180deg, rgba(10, 28, 37, 0.82), rgba(4, 14, 21, 0.94));
box-shadow:
0 24px 90px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.025);
}
.stage::after {
content: "";
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
border-radius: inherit;
box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.24);
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
}
.controls {
position: absolute;
z-index: 5;
top: 16px;
right: 16px;
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(7, 20, 27, 0.7);
backdrop-filter: blur(14px);
box-shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
}
button {
appearance: none;
border: 1px solid rgba(168, 222, 227, 0.17);
border-radius: 9px;
padding: 8px 11px;
background: rgba(202, 237, 239, 0.055);
color: var(--text);
font: inherit;
font-size: 0.76rem;
font-weight: 650;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(112, 232, 244, 0.12);
border-color: rgba(112, 232, 244, 0.38);
}
button:active {
transform: translateY(1px);
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
button.primary {
min-width: 88px;
border-color: rgba(112, 232, 244, 0.34);
background: rgba(112, 232, 244, 0.13);
color: var(--cyan-strong);
}
.speed {
display: flex;
align-items: center;
gap: 7px;
padding: 0 5px;
color: var(--muted);
font-size: 0.67rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 72px;
accent-color: var(--cyan);
cursor: pointer;
}
.stage-meta {
position: absolute;
z-index: 4;
top: 20px;
left: 22px;
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.66rem;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 15px var(--cyan);
animation: status-pulse 1.6s ease-in-out infinite;
}
.status-dot.paused {
background: #89979a;
box-shadow: none;
animation: none;
}
@keyframes status-pulse {
50% {
opacity: 0.35;
transform: scale(0.75);
}
}
.legend {
position: absolute;
z-index: 4;
left: 18px;
bottom: 17px;
display: flex;
flex-wrap: wrap;
gap: 7px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(158, 219, 228, 0.13);
border-radius: 999px;
background: rgba(5, 18, 25, 0.68);
color: #a8bec2;
backdrop-filter: blur(10px);
font-size: 0.68rem;
letter-spacing: 0.02em;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
}
.swatch.voxel {
background: var(--warm);
box-shadow: 0 0 8px rgba(240, 238, 228, 0.15);
}
.swatch.water {
border: 1px solid var(--cyan);
background: rgba(112, 232, 244, 0.28);
}
.swatch.path {
width: 14px;
height: 3px;
border: 0;
border-radius: 999px;
background: var(--cyan-strong);
box-shadow: 0 0 8px var(--cyan);
}
.world-label {
position: absolute;
z-index: 3;
display: grid;
gap: 3px;
min-width: 122px;
padding: 8px 10px;
border-left: 2px solid rgba(112, 232, 244, 0.7);
background: linear-gradient(90deg, rgba(4, 16, 22, 0.75), transparent);
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.62rem;
letter-spacing: 0.1em;
line-height: 1.3;
text-transform: uppercase;
transform: translate(-50%, -50%);
pointer-events: none;
white-space: nowrap;
}
.world-label span {
color: var(--muted);
font-size: 0.55rem;
letter-spacing: 0.06em;
}
.caption {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 18px;
padding: 17px 20px;
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(11, 28, 36, 0.7);
}
.caption-icon {
position: relative;
width: 42px;
height: 42px;
border: 1px solid rgba(112, 232, 244, 0.3);
border-radius: 50%;
background: rgba(112, 232, 244, 0.07);
}
.caption-icon::before,
.caption-icon::after {
content: "";
position: absolute;
left: 9px;
width: 22px;
height: 8px;
border-top: 1.5px solid var(--cyan);
border-radius: 50%;
}
.caption-icon::before {
top: 13px;
}
.caption-icon::after {
top: 21px;
left: 12px;
width: 16px;
}
.caption h2 {
margin: 0 0 4px;
font-size: 0.88rem;
font-weight: 680;
letter-spacing: -0.01em;
}
.caption p {
margin: 0;
max-width: 980px;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.55;
}
.caption strong {
color: #d5e3e2;
font-weight: 650;
}
.caption-tag {
padding: 7px 10px;
border: 1px solid rgba(240, 238, 228, 0.16);
border-radius: 999px;
color: #c8d1cb;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.61rem;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
@media (max-width: 800px) {
.app {
padding: 17px 14px;
grid-template-rows: auto minmax(440px, 1fr) auto;
gap: 12px;
}
header {
align-items: flex-start;
}
.study-id {
display: none;
}
.stage {
min-height: 440px;
border-radius: 20px;
}
.controls {
top: 10px;
right: 10px;
}
.stage-meta {
top: 20px;
left: 15px;
}
.speed {
display: none;
}
.legend {
left: 10px;
right: 10px;
bottom: 10px;
}
.caption {
grid-template-columns: auto 1fr;
padding: 15px;
}
.caption-tag {
display: none;
}
}
@media (max-width: 520px) {
.stage-meta {
top: 60px;
}
.legend-item {
padding: 6px 8px;
font-size: 0.61rem;
}
.caption {
gap: 12px;
}
.caption-icon {
width: 35px;
height: 35px;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div>
<p class="eyebrow">Hydraulic geometry / illustration 02</p>
<h1>Water channel path</h1>
<p class="intro">
Two mirrored voxel sole patterns over a shallow symbolic water field.
Animated packets trace open drainage grooves from toe toward heel.
</p>
</div>
<div class="study-id">
<span>Model classification</span>
<strong>Geometric drainage only</strong>
<span>Scale and depth are schematic</span>
</div>
</header>
<main class="stage" aria-label="Interactive three-dimensional water channel illustration">
<div id="viewport"></div>
<div class="stage-meta">
<span class="status-dot" id="statusDot"></span>
<span id="statusText">Flow active</span>
</div>
<div class="controls" aria-label="Animation controls">
<button class="primary" id="toggleFlow" type="button">Pause</button>
<button id="restartFlow" type="button">Restart</button>
<label class="speed">
Speed
<input
id="flowSpeed"
type="range"
min="0.4"
max="2"
step="0.1"
value="1"
aria-label="Flow animation speed"
>
</label>
</div>
<div class="world-label" id="leftLabel">
Left sole pattern
<span>Two open channel routes</span>
</div>
<div class="world-label" id="rightLabel">
Right sole pattern
<span>Two open channel routes</span>
</div>
<div class="legend" aria-label="Illustration legend">
<div class="legend-item">
<span class="swatch voxel"></span>
Voxel tread blocks
</div>
<div class="legend-item">
<span class="swatch water"></span>
Shallow water field
</div>
<div class="legend-item">
<span class="swatch path"></span>
Animated flow route
</div>
</div>
</main>
<footer class="caption">
<div class="caption-icon" aria-hidden="true"></div>
<div>
<h2>Geometric drainage visualization — not a grip test.</h2>
<p>
Animated routes show symbolic water moving through open grooves between
modeled sole voxels. <strong>This is not a grip, slip-resistance, or
traction test.</strong> Block spacing, depth, water volume, and flow
speed are illustrative rather than measured.
</p>
</div>
<div class="caption-tag">Schematic · non-physical scale</div>
</footer>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const toggleButton = document.getElementById("toggleFlow");
const restartButton = document.getElementById("restartFlow");
const speedInput = document.getElementById("flowSpeed");
const statusText = document.getElementById("statusText");
const statusDot = document.getElementById("statusDot");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07151d, 0.025);
const camera = new THREE.OrthographicCamera(-7, 7, 5, -5, 0.1, 100);
camera.position.set(0, 10.5, 11.5);
camera.lookAt(0, 0.15, 0);
const hemisphere = new THREE.HemisphereLight(0xc8f4ff, 0x071018, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfffbef, 3.4);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65dff2, 1.9);
rimLight.position.set(6, 4, -6);
scene.add(rimLight);
const waterGlow = new THREE.PointLight(0x35d7ee, 14, 12, 2);
waterGlow.position.set(0, 2.5, -2.8);
scene.add(waterGlow);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x071219,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.32;
floor.receiveShadow = true;
scene.add(floor);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x138ca5,
emissive: 0x073744,
emissiveIntensity: 0.55,
roughness: 0.28,
metalness: 0.05,
transparent: true,
opacity: 0.18,
depthWrite: false
});
const water = new THREE.Mesh(
new THREE.BoxGeometry(8.4, 0.07, 6.6),
waterMaterial
);
water.position.y = 0.035;
water.renderOrder = 1;
scene.add(water);
const waterEdge = new THREE.LineSegments(
new THREE.EdgesGeometry(water.geometry),
new THREE.LineBasicMaterial({
color: 0x76eaf4,
transparent: true,
opacity: 0.2,
depthWrite: false
})
);
waterEdge.position.copy(water.position);
waterEdge.renderOrder = 2;
scene.add(waterEdge);
// A custom grid clipped to the rectangular water field.
const gridVertices = [];
const halfWidth = 4.2;
const halfDepth = 3.3;
const gridY = 0.082;
for (let x = -halfWidth; x <= halfWidth + 0.001; x += 0.35) {
gridVertices.push(x, gridY, -halfDepth, x, gridY, halfDepth);
}
for (let z = -halfDepth; z <= halfDepth + 0.001; z += 0.35) {
gridVertices.push(-halfWidth, gridY, z, halfWidth, gridY, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x7ed8e4,
transparent: true,
opacity: 0.075,
depthWrite: false
})
);
grid.renderOrder = 2;
scene.add(grid);
const blockGeometry = new THREE.BoxGeometry(0.285, 0.30, 0.285);
const leftMaterial = new THREE.MeshStandardMaterial({
color: 0xeeeFe8,
roughness: 0.74,
metalness: 0.015
});
const rightMaterial = new THREE.MeshStandardMaterial({
color: 0xdfe9e6,
roughness: 0.76,
metalness: 0.015
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0xaebfbd,
roughness: 0.82,
metalness: 0.01
});
const routeLineMaterial = new THREE.MeshBasicMaterial({
color: 0x53d9e9,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const routeDashMaterial = new THREE.MeshBasicMaterial({
color: 0x81eef5,
transparent: true,
opacity: 0.48,
depthWrite: false
});
const packetGeometry = new THREE.BoxGeometry(0.075, 0.05, 0.17);
const packetMaterial = new THREE.MeshBasicMaterial({
color: 0xc6ffff,
transparent: true,
opacity: 0.96,
depthWrite: false
});
const routes = [];
function makeCurve(points, mirror = 1) {
const curve = new THREE.CatmullRomCurve3(
points.map(([x, z]) => new THREE.Vector3(x * mirror, 0.145, z)),
false,
"centripetal"
);
return curve;
}
function addRoute(group, curve, phaseOffset) {
const line = new THREE.Mesh(
new THREE.TubeGeometry(curve, 90, 0.018, 5, false),
routeLineMaterial
);
line.renderOrder = 3;
group.add(line);
const dashCount = 38;
const dashGeometry = new THREE.BoxGeometry(0.065, 0.035, 0.065);
const dashes = new THREE.InstancedMesh(
dashGeometry,
routeDashMaterial,
dashCount
);
dashes.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
dashes.renderOrder = 4;
group.add(dashes);
const packets = [];
const packetCount = 9;
for (let i = 0; i < packetCount; i++) {
const packet = new THREE.Mesh(packetGeometry, packetMaterial);
packet.renderOrder = 5;
group.add(packet);
packets.push({
mesh: packet,
phase: (i / packetCount + phaseOffset) % 1
});
}
routes.push({
curve,
dashes,
dashCount,
packets,
phaseOffset
});
}
function nearestDistanceSquared(x, z, samples) {
let minimum = Infinity;
for (let i = 0; i < samples.length - 1; i++) {
const a = samples[i];
const b = samples[i + 1];
const abx = b.x - a.x;
const abz = b.z - a.z;
const apx = x - a.x;
const apz = z - a.z;
const lengthSquared = abx * abx + abz * abz;
const t = lengthSquared > 0
? THREE.MathUtils.clamp(
(apx * abx + apz * abz) / lengthSquared,
0,
1
)
: 0;
const dx = x - (a.x + abx * t);
const dz = z - (a.z + abz * t);
const distanceSquared = dx * dx + dz * dz;
if (distanceSquared < minimum) {
minimum = distanceSquared;
}
}
return minimum;
}
const mainPoints = [
[-0.18, -2.48],
[-0.23, -2.05],
[ 0.22, -1.52],
[ 0.10, -0.88],
[-0.30, -0.26],
[-0.10, 0.37],
[ 0.28, 0.98],
[ 0.13, 1.59],
[ 0.00, 2.43]
];
const outerPoints = [
[-0.79, -1.82],
[-0.88, -1.28],
[-0.72, -0.68],
[-0.93, -0.03],
[-0.79, 0.65],
[-0.55, 1.27],
[-0.32, 2.12]
];
const rowWidths = [
4, 6, 7, 7, 7, 7, 6, 6,
5, 5, 5, 6, 6, 6, 5, 4
];
const rowOffsets = [
0, 0, 0, 0, 0, -0.12, 0, 0.14,
0.17, 0.06, 0, 0, 0, 0, 0, 0
];
function buildSole({ mirror, material, positionX, rotationY }) {
const group = new THREE.Group();
group.position.x = positionX;
group.rotation.y = rotationY;
const mainCurve = makeCurve(mainPoints, mirror);
const outerCurve = makeCurve(outerPoints, mirror);
const mainSamples = mainCurve.getPoints(70);
const outerSamples = outerCurve.getPoints(70);
const spacing = 0.34;
const rows = rowWidths.length;
for (let row = 0; row < rows; row++) {
const z = (row - (rows - 1) / 2) * spacing;
const offset = rowOffsets[row];
const width = rowWidths[row];
for (let column = -4; column <= 4; column++) {
const x = column * spacing + offset;
const relativeX = column * spacing;
if (Math.abs(relativeX) > (width - 1) * spacing * 0.5) {
continue;
}
const mainDistance = nearestDistanceSquared(x, z, mainSamples);
const outerDistance = nearestDistanceSquared(x, z, outerSamples);
// Leave geometric open grooves where the animated routes pass.
if (mainDistance < 0.205 || outerDistance < 0.205) {
continue;
}
const block = new THREE.Mesh(
blockGeometry,
(row + column + 20) % 8 === 0 ? accentMaterial : material
);
block.position.set(x, 0.60, z);
block.castShadow = true;
block.receiveShadow = true;
group.add(block);
}
}
addRoute(group, mainCurve, 0);
addRoute(group, outerCurve, 0.36);
scene.add(group);
return group;
}
const leftSole = buildSole({
mirror: 1,
material: leftMaterial,
positionX: -2.05,
rotationY: -0.065
});
const rightSole = buildSole({
mirror: -1,
material: rightMaterial,
positionX: 2.05,
rotationY: 0.065
});
const dummy = new THREE.Object3D();
const zAxis = new THREE.Vector3(0, 0, 1);
let running = true;
let elapsed = 0;
let speed = Number(speedInput.value);
let previousTime = performance.now();
function updateFlow(time) {
for (const route of routes) {
for (let i = 0; i < route.dashCount; i++) {
const u = i / route.dashCount;
const point = route.curve.getPointAt(u);
dummy.position.copy(point);
dummy.rotation.set(0, 0, 0);
const pulse = 0.8 + 0.2 * Math.sin(time * 4.2 - i * 0.52);
dummy.scale.setScalar(pulse);
dummy.updateMatrix();
route.dashes.setMatrixAt(i, dummy.matrix);
}
route.dashes.instanceMatrix.needsUpdate = true;
for (const packet of route.packets) {
const u = (
time * 0.105 * speed +
packet.phase +
route.phaseOffset
) % 1;
const point = route.curve.getPointAt(u);
const tangent = route.curve.getTangentAt(u).normalize();
packet.mesh.position.copy(point);
packet.mesh.quaternion.setFromUnitVectors(zAxis, tangent);
const packetPulse = 0.88 + 0.12 * Math.sin(time * 8 + packet.phase * 20);
packet.mesh.scale.setScalar(packetPulse);
}
}
waterMaterial.opacity = 0.17 + Math.sin(time * 1.15) * 0.018;
waterEdge.material.opacity = 0.18 + Math.sin(time * 1.15) * 0.035;
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const aspect = width / Math.max(height, 1);
renderer.setSize(width, height, false);
const minimumWidth = 9.5;
const viewWidth = Math.max(minimumWidth, minimumWidth * aspect);
const viewHeight = viewWidth / aspect;
camera.left = -viewWidth / 2;
camera.right = viewWidth / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
const labelEntries = [
{
element: document.getElementById("leftLabel"),
group: leftSole,
localPosition: new THREE.Vector3(0, 1.0, 2.87)
},
{
element: document.getElementById("rightLabel"),
group: rightSole,
localPosition: new THREE.Vector3(0, 1.0, 2.87)
}
];
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const entry of labelEntries) {
const worldPosition = entry.localPosition.clone();
entry.group.localToWorld(worldPosition);
worldPosition.project(camera);
const x = (worldPosition.x * 0.5 + 0.5) * width;
const y = (-worldPosition.y * 0.5 + 0.5) * height;
entry.element.style.left = `${x}px`;
entry.element.style.top = `${y}px`;
}
}
function setRunning(value) {
running = value;
toggleButton.textContent = running ? "Pause" : "Play";
statusText.textContent = running ? "Flow active" : "Flow paused";
statusDot.classList.toggle("paused", !running);
}
toggleButton.addEventListener("click", () => {
setRunning(!running);
});
restartButton.addEventListener("click", () => {
elapsed = 0;
updateFlow(elapsed);
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
setRunning(!running);
}
});
window.addEventListener("resize", resize);
resize();
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
setRunning(false);
}
function animate(now) {
const delta = THREE.MathUtils.clamp((now - previousTime) / 1000, 0, 0.05);
previousTime = now;
if (running) {
elapsed += delta * speed;
}
updateFlow(elapsed);
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```