Prompt specification
Build or customize the Three.js 3D scene "Glacier conveyor marker exhibit" 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: Glacier conveyor marker exhibit
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/glacier-conveyor-marker-exhibit-x1150
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing glacial valleys. Embed colored markers in a simplified ice tongue and animate gradual downstream displacement; identify the motion as illustrative and keep the ice within the surrounding valley. Stylized solid forms.
Working Three.js Starter (glacier-conveyor-marker-exhibit-x1150):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Illustrative Glacial Valley</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e7;
color: #173033;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 16px;
background: rgba(248, 252, 250, 0.84);
box-shadow: 0 14px 45px rgba(35, 59, 61, 0.16);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#info {
top: 18px;
left: 18px;
width: min(380px, calc(100vw - 36px));
padding: 20px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #607578;
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #17383a;
font-size: clamp(1.65rem, 4vw, 2.25rem);
line-height: 1;
letter-spacing: -0.04em;
}
.badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin: 14px 0 12px;
padding: 7px 10px;
border-radius: 999px;
background: #fff0c7;
color: #755116;
font-size: 0.69rem;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #e49b25;
content: "";
}
p {
margin: 0;
color: #425c5e;
font-size: 0.9rem;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid rgba(47, 78, 80, 0.13);
color: #4c6668;
font-size: 0.76rem;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
#controls {
right: 18px;
bottom: 18px;
padding: 12px;
}
.buttons {
display: flex;
gap: 8px;
margin-bottom: 9px;
}
button {
min-width: 112px;
padding: 9px 12px;
border: 0;
border-radius: 10px;
background: #214c4e;
color: white;
font: inherit;
font-size: 0.78rem;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease;
}
button:hover {
background: #173b3d;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(245, 177, 67, 0.7);
outline-offset: 2px;
}
button.secondary {
background: rgba(33, 76, 78, 0.11);
color: #214c4e;
}
.hint {
color: #617779;
font-size: 0.72rem;
line-height: 1.4;
text-align: center;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #dce9e7;
color: #365658;
font-size: 0.85rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 620px) {
#info {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 15px;
}
#info p {
font-size: 0.82rem;
}
#controls {
right: 10px;
bottom: 10px;
}
button {
min-width: 0;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="info" class="panel" aria-label="Scene explanation">
<div class="eyebrow">Procedural terrain study</div>
<h1>Glacial Valley</h1>
<div class="badge">Illustrative motion · Not to scale</div>
<p>
Colored tracers are embedded in a simplified ice tongue and drift gradually
downstream. Their movement is conceptual—not a measured velocity,
forecast, or geological reconstruction. The ice remains inside the
mapped valley-floor corridor.
</p>
<div class="legend" aria-label="Tracer color legend">
<span><i class="dot" style="background:#f05d3f"></i>Tracer A</span>
<span><i class="dot" style="background:#f2b134"></i>Tracer B</span>
<span><i class="dot" style="background:#7656d6"></i>Tracer C</span>
<span><i class="dot" style="background:#2aa198"></i>Tracer D</span>
</div>
</section>
<section id="controls" class="panel" aria-label="Animation and camera controls">
<div class="buttons">
<button id="flowButton" type="button" aria-pressed="false">
Pause flow
</button>
<button id="resetButton" class="secondary" type="button">
Reset view
</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</section>
<div id="loading">Building the valley…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e7);
scene.fog = new THREE.Fog(0xdce9e7, 78, 155);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
240
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional glacial valley with illustrative moving tracers"
);
// Lighting
const hemisphere = new THREE.HemisphereLight(
0xe8f7ff,
0x596353,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d5, 3.15);
sun.position.set(-32, 55, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 64;
sun.shadow.camera.bottom = -64;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 145;
sun.shadow.bias = -0.0007;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ac6d2, 0.75);
fill.position.set(30, 18, -40);
scene.add(fill);
// Shared terrain constants
const TERRAIN_Z_MIN = -49;
const TERRAIN_Z_MAX = 54;
const TERRAIN_HALF_WIDTH = 29;
const VALLEY_FLOOR_HALF_WIDTH = 6.4;
const ICE_Z_MIN = -39;
const ICE_Z_MAX = 40;
const clamp = THREE.MathUtils.clamp;
function smoothstep(edge0, edge1, value) {
const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
// The valley and ice use the same curved centerline.
function centerline(z) {
return (
3.2 * Math.sin((z + 18) * 0.055) +
0.7 * Math.sin(z * 0.11)
);
}
function floorHeight(z) {
return 0.55 - 0.006 * (z + 49);
}
function terrainHeight(z, offsetAcrossValley) {
const distance = Math.abs(offsetAcrossValley);
const wall = smoothstep(
VALLEY_FLOOR_HALF_WIDTH,
25,
distance
);
const ridge =
Math.sin(z * 0.19 + offsetAcrossValley * 0.27) * 1.05 +
Math.sin(z * 0.41 - offsetAcrossValley * 0.13) * 0.52;
const crest =
10.1 +
Math.sin(z * 0.071) * 1.6 +
Math.sin(z * 0.027 + 1.2) * 1.1;
return floorHeight(z) + wall * (crest + ridge * wall);
}
// Explicit geometric constraint: the ice is narrower than the flat
// valley floor at every cross-section, leaving visible margins.
function iceWidth(z) {
const t = clamp(
(z - ICE_Z_MIN) / (ICE_Z_MAX - ICE_Z_MIN),
0,
1
);
const naturalWidth =
5.35 - 1.75 * t + 0.32 * Math.sin(t * Math.PI * 2);
return Math.min(
naturalWidth,
VALLEY_FLOOR_HALF_WIDTH - 1.0
);
}
function iceThickness(z) {
const t = clamp(
(z - ICE_Z_MIN) / (ICE_Z_MAX - ICE_Z_MIN),
0,
1
);
return 2.85 - 1.55 * t + 0.2 * Math.sin(t * Math.PI * 2);
}
function iceSurface(z, offsetAcrossIce) {
const width = iceWidth(z);
const crown = 0.22 * Math.pow(offsetAcrossIce / width, 2);
return floorHeight(z) + iceThickness(z) - crown;
}
function terrainPoint(z, offsetAcrossValley) {
return [
centerline(z) + offsetAcrossValley,
terrainHeight(z, offsetAcrossValley),
z
];
}
function icePoint(z, offsetAcrossIce) {
return [
centerline(z) + offsetAcrossIce,
iceSurface(z, offsetAcrossIce),
z
];
}
function pushTriangle(positions, colors, a, b, c, color) {
positions.push(...a, ...b, ...c);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
// Faceted, solid terrain
const terrainPositions = [];
const terrainColors = [];
const terrainLow = new THREE.Color(0x718060);
const terrainStone = new THREE.Color(0x697573);
const terrainHigh = new THREE.Color(0x9aa7a3);
const terrainSnow = new THREE.Color(0xdce8e5);
function terrainFaceColor(height) {
const color = new THREE.Color().copy(terrainLow);
if (height < 5) {
color.lerp(terrainStone, smoothstep(0.5, 5, height));
} else {
color.copy(terrainStone);
color.lerp(terrainHigh, smoothstep(5, 10.5, height));
}
if (height > 10.8) {
color.lerp(
terrainSnow,
smoothstep(10.8, 13.2, height)
);
}
return color;
}
const terrainZSegments = 76;
const terrainXSegments = 54;
for (let iz = 0; iz < terrainZSegments; iz++) {
const z0 =
TERRAIN_Z_MIN +
((TERRAIN_Z_MAX - TERRAIN_Z_MIN) * iz) /
terrainZSegments;
const z1 =
TERRAIN_Z_MIN +
((TERRAIN_Z_MAX - TERRAIN_Z_MIN) * (iz + 1)) /
terrainZSegments;
for (let ix = 0; ix < terrainXSegments; ix++) {
const u0 =
-TERRAIN_HALF_WIDTH +
(2 * TERRAIN_HALF_WIDTH * ix) / terrainXSegments;
const u1 =
-TERRAIN_HALF_WIDTH +
(2 * TERRAIN_HALF_WIDTH * (ix + 1)) /
terrainXSegments;
const p00 = terrainPoint(z0, u0);
const p10 = terrainPoint(z1, u0);
const p11 = terrainPoint(z1, u1);
const p01 = terrainPoint(z0, u1);
const averageHeight =
(p00[1] + p10[1] + p11[1] + p01[1]) / 4;
const color = terrainFaceColor(averageHeight);
pushTriangle(
terrainPositions,
terrainColors,
p00,
p10,
p11,
color
);
pushTriangle(
terrainPositions,
terrainColors,
p00,
p11,
p01,
color
);
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrainMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
terrain.receiveShadow = true;
scene.add(terrain);
// Solid ice tongue: top, side walls, and end caps
const icePositions = [];
const iceColors = [];
const iceTop = new THREE.Color(0xc4edef);
const iceSide = new THREE.Color(0x76b9c7);
const iceEnd = new THREE.Color(0x91cdd5);
const iceZSegments = 58;
const iceXSegments = 12;
for (let iz = 0; iz < iceZSegments; iz++) {
const z0 =
ICE_Z_MIN +
((ICE_Z_MAX - ICE_Z_MIN) * iz) / iceZSegments;
const z1 =
ICE_Z_MIN +
((ICE_Z_MAX - ICE_Z_MIN) * (iz + 1)) / iceZSegments;
const width0 = iceWidth(z0);
const width1 = iceWidth(z1);
for (let ix = 0; ix < iceXSegments; ix++) {
const fraction0 = ix / iceXSegments;
const fraction1 = (ix + 1) / iceXSegments;
const u00 = -width0 + 2 * width0 * fraction0;
const u10 = -width1 + 2 * width1 * fraction0;
const u11 = -width1 + 2 * width1 * fraction1;
const u01 = -width0 + 2 * width0 * fraction1;
const p00 = icePoint(z0, u00);
const p10 = icePoint(z1, u10);
const p11 = icePoint(z1, u11);
const p01 = icePoint(z0, u01);
const shade = new THREE.Color()
.copy(iceTop)
.offsetHSL(
0,
0,
0.025 * Math.sin(z0 * 0.18 + ix * 0.7)
);
pushTriangle(
icePositions,
iceColors,
p00,
p10,
p11,
shade
);
pushTriangle(
icePositions,
iceColors,
p00,
p11,
p01,
shade
);
}
}
// Left and right ice walls
for (let iz = 0; iz < iceZSegments; iz++) {
const z0 =
ICE_Z_MIN +
((ICE_Z_MAX - ICE_Z_MIN) * iz) / iceZSegments;
const z1 =
ICE_Z_MIN +
((ICE_Z_MAX - ICE_Z_MIN) * (iz + 1)) / iceZSegments;
const left0 = -iceWidth(z0);
const left1 = -iceWidth(z1);
const right0 = iceWidth(z0);
const right1 = iceWidth(z1);
const lt0 = icePoint(z0, left0);
const lt1 = icePoint(z1, left1);
const lb0 = [
centerline(z0) + left0,
floorHeight(z0) + 0.025,
z0
];
const lb1 = [
centerline(z1) + left1,
floorHeight(z1) + 0.025,
z1
];
pushTriangle(
icePositions,
iceColors,
lt0,
lb0,
lt1,
iceSide
);
pushTriangle(
icePositions,
iceColors,
lb0,
lb1,
lt1,
iceSide
);
const rt0 = icePoint(z0, right0);
const rt1 = icePoint(z1, right1);
const rb0 = [
centerline(z0) + right0,
floorHeight(z0) + 0.025,
z0
];
const rb1 = [
centerline(z1) + right1,
floorHeight(z1) + 0.025,
z1
];
pushTriangle(
icePositions,
iceColors,
rt0,
rt1,
rb0,
iceSide
);
pushTriangle(
icePositions,
iceColors,
rb0,
rt1,
rb1,
iceSide
);
}
// Upstream and downstream end faces
for (const [z, downstream] of [
[ICE_Z_MIN, false],
[ICE_Z_MAX, true]
]) {
const width = iceWidth(z);
const segments = 12;
for (let ix = 0; ix < segments; ix++) {
const u0 = -width + (2 * width * ix) / segments;
const u1 = -width + (2 * width * (ix + 1)) / segments;
const top0 = icePoint(z, u0);
const top1 = icePoint(z, u1);
const bottom0 = [
centerline(z) + u0,
floorHeight(z) + 0.025,
z
];
const bottom1 = [
centerline(z) + u1,
floorHeight(z) + 0.025,
z
];
if (downstream) {
pushTriangle(
icePositions,
iceColors,
top0,
bottom0,
top1,
iceEnd
);
pushTriangle(
icePositions,
iceColors,
bottom0,
bottom1,
top1,
iceEnd
);
} else {
pushTriangle(
icePositions,
iceColors,
top0,
top1,
bottom0,
iceEnd
);
pushTriangle(
icePositions,
iceColors,
bottom0,
top1,
bottom1,
iceEnd
);
}
}
}
const iceGeometry = new THREE.BufferGeometry();
iceGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(icePositions, 3)
);
iceGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(iceColors, 3)
);
iceGeometry.computeVertexNormals();
const iceMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.48,
metalness: 0.025,
flatShading: true
});
const ice = new THREE.Mesh(iceGeometry, iceMaterial);
ice.castShadow = true;
ice.receiveShadow = true;
scene.add(ice);
// Low-poly downhill arrows, aligned with the downstream direction.
const arrowGeometry = new THREE.ConeGeometry(0.43, 1.25, 3);
arrowGeometry.scale(1, 1, 0.18);
arrowGeometry.rotateX(Math.PI / 2);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0x579fac,
roughness: 0.62,
metalness: 0.02,
flatShading: true
});
for (const z of [-29, -15, 1, 17, 31]) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.position.set(
centerline(z),
iceSurface(z, 0) + 0.055,
z
);
arrow.castShadow = true;
arrow.receiveShadow = true;
scene.add(arrow);
}
// A small meltwater pool beyond the illustrative ice terminus.
const poolGeometry = new THREE.CircleGeometry(1, 36);
poolGeometry.rotateX(-Math.PI / 2);
const poolMaterial = new THREE.MeshStandardMaterial({
color: 0x62aeb2,
roughness: 0.32,
metalness: 0.05
});
const pool = new THREE.Mesh(poolGeometry, poolMaterial);
pool.position.set(
centerline(44.5),
floorHeight(44.5) + 0.04,
44.5
);
pool.scale.set(4.1, 2.6, 1);
pool.receiveShadow = true;
scene.add(pool);
// Deterministic low-poly rocks along the valley sides.
let seed = 73129;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const rockGeometry = new THREE.DodecahedronGeometry(1, 0);
const rockMaterials = [
new THREE.MeshStandardMaterial({
color: 0x7b8179,
roughness: 0.96,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x68716f,
roughness: 0.96,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x8a8d80,
roughness: 0.96,
flatShading: true
})
];
for (let i = 0; i < 34; i++) {
const z = -45 + random() * 96;
const side = random() > 0.5 ? 1 : -1;
const u = side * (8.2 + random() * 16.5);
const scale = 0.35 + random() * 0.9;
const rock = new THREE.Mesh(
rockGeometry,
rockMaterials[i % rockMaterials.length]
);
rock.position.set(
centerline(z) + u,
terrainHeight(z, u) + scale * 0.22,
z
);
rock.scale.set(
scale * (0.8 + random() * 0.6),
scale * (0.55 + random() * 0.65),
scale * (0.8 + random() * 0.6)
);
rock.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// Embedded colored tracers. Their lower portions extend beneath the
// visible ice surface, while their colored caps remain visible.
const tracerColors = [
0xf05d3f,
0xf2b134,
0x7656d6,
0x2aa198
];
const tracerMaterials = tracerColors.map(
(color) =>
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.08,
roughness: 0.42,
metalness: 0.04,
flatShading: true
})
);
const tracerBodyGeometry = new THREE.CylinderGeometry(
0.2,
0.27,
0.72,
9
);
const tracerCapGeometry = new THREE.IcosahedronGeometry(0.29, 1);
const tracers = [];
const tracerCount = 24;
const tracerSpan = 75;
for (let i = 0; i < tracerCount; i++) {
const group = new THREE.Group();
const body = new THREE.Mesh(
tracerBodyGeometry,
tracerMaterials[i % tracerMaterials.length]
);
body.position.y = -0.16;
body.castShadow = true;
const cap = new THREE.Mesh(
tracerCapGeometry,
tracerMaterials[i % tracerMaterials.length]
);
cap.position.y = 0.18;
cap.scale.set(1, 0.58, 1);
cap.castShadow = true;
group.add(body, cap);
scene.add(group);
tracers.push({
group,
offset: (i / tracerCount) * tracerSpan + random() * 1.6,
speed: 0.95 + random() * 0.28,
across: (random() - 0.5) * 1.35
});
}
// Camera and direct pointer controls — no examples/addons are used.
const cameraTarget = new THREE.Vector3(0, 2.3, 0);
let yaw = 0.7;
let pitch = 0.52;
let cameraRadius = 73;
function updateCamera() {
const horizontalRadius = cameraRadius * Math.cos(pitch);
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontalRadius,
cameraTarget.y + Math.sin(pitch) * cameraRadius,
cameraTarget.z + Math.cos(yaw) * horizontalRadius
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
yaw = 0.7;
pitch = 0.52;
cameraRadius = 73;
updateCamera();
}
const canvas = renderer.domElement;
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
yaw -= deltaX * 0.006;
pitch = clamp(pitch + deltaY * 0.0045, 0.18, 1.15);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
31,
112
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
document
.getElementById("resetButton")
.addEventListener("click", resetCamera);
// Animation controls
let flowRunning = true;
let flowTime = 0;
const flowButton = document.getElementById("flowButton");
flowButton.addEventListener("click", () => {
flowRunning = !flowRunning;
flowButton.textContent = flowRunning ? "Pause flow" : "Resume flow";
flowButton.setAttribute("aria-pressed", String(!flowRunning));
});
const clock = new THREE.Clock();
function updateTracers() {
for (const tracer of tracers) {
const z =
-37 +
((tracer.offset + flowTime * tracer.speed) % tracerSpan);
const width = iceWidth(z);
const across = tracer.across * width * 0.72;
tracer.group.position.set(
centerline(z) + across,
iceSurface(z, across),
z
);
// Smoothly shrink tracers at the model boundary before recycling.
const enter = smoothstep(-37, -33.5, z);
const exit = 1 - smoothstep(35.5, 39, z);
const scale = Math.max(0.001, Math.min(enter, exit));
tracer.group.scale.setScalar(scale);
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (flowRunning) {
flowTime += delta;
}
updateTracers();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resetCamera();
updateTracers();
renderer.render(scene, camera);
loading.remove();
animate();
</script>
</body>
</html>
```