Prompt specification
Build or customize the Three.js 3D scene "Missing-segment leak 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: Missing-segment leak illustration
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/missing-segment-leak-illustration-x0262
Scene Description Prompt:
Compare voxel vessels with complete and interrupted gasket loops, showing a symbolic leak only through the gap. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (missing-segment-leak-illustration-x0262):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Vessel Gasket Comparison</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(8, 18, 32, 0.82);
--border: rgba(148, 190, 214, 0.2);
--text: #eaf6ff;
--muted: #91a9ba;
--mint: #68f5bd;
--amber: #ffb347;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111d;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.heading {
position: fixed;
top: 24px;
left: 28px;
z-index: 5;
pointer-events: none;
max-width: min(520px, calc(100vw - 56px));
}
.eyebrow {
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 6px;
font-size: clamp(22px, 3vw, 38px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls {
position: fixed;
top: 24px;
right: 24px;
z-index: 10;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
}
button {
appearance: none;
border: 1px solid var(--border);
border-radius: 9px;
padding: 9px 12px;
color: #dceef8;
background: rgba(10, 23, 39, 0.86);
font: inherit;
font-size: 12px;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(104, 245, 189, 0.65);
background: rgba(18, 39, 58, 0.95);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--mint);
outline-offset: 2px;
}
.world-label {
position: fixed;
z-index: 4;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
border: 1px solid var(--border);
border-radius: 10px;
padding: 9px 12px;
background: var(--panel);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(10px);
transition: opacity 120ms linear;
}
.world-label strong {
display: block;
font-size: 12px;
letter-spacing: 0.08em;
}
.world-label span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.05em;
}
.good strong {
color: var(--mint);
}
.warning strong {
color: var(--amber);
}
.gap-label {
padding: 6px 9px;
border-color: rgba(255, 179, 71, 0.55);
color: var(--amber);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
}
.legend {
position: fixed;
left: 24px;
bottom: 22px;
z-index: 6;
max-width: min(570px, calc(100vw - 48px));
border: 1px solid var(--border);
border-radius: 12px;
padding: 12px 14px;
background: var(--panel);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px 18px;
color: #d8e9f3;
font-size: 11px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: 0 0 12px currentColor;
}
.dot.mint {
color: var(--mint);
background: var(--mint);
}
.dot.amber {
color: var(--amber);
background: var(--amber);
}
.legend p {
margin: 8px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.hint {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
color: rgba(210, 232, 244, 0.66);
font-size: 11px;
pointer-events: none;
}
@media (max-width: 720px) {
.heading {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 92px;
}
.legend {
left: 14px;
bottom: 14px;
max-width: calc(100vw - 28px);
}
.hint {
display: none;
}
.world-label {
padding: 7px 9px;
}
}
</style>
</head>
<body>
<header class="heading">
<div class="eyebrow">Pressure boundary study</div>
<h1>Voxel Vessel Gasket Comparison</h1>
<p class="subtitle">
Identical voxel vessels. The only difference is one interrupted segment
in the right-hand gasket loop.
</p>
</header>
<nav class="controls" aria-label="View controls">
<button type="button" data-view="oblique">Oblique</button>
<button type="button" data-view="front">Front</button>
<button type="button" id="pause">Pause tracer</button>
</nav>
<div id="labelA" class="world-label good">
<strong>A · COMPLETE LOOP</strong>
<span>Continuous gasket · no escape path</span>
</div>
<div id="labelB" class="world-label warning">
<strong>B · INTERRUPTED LOOP</strong>
<span>One missing segment · localized leak</span>
</div>
<div id="gapLabel" class="world-label gap-label">ONLY OPENING</div>
<section class="legend">
<div class="legend-row">
<span class="legend-item">
<span class="dot mint"></span>
Gasket loop
</span>
<span class="legend-item">
<span class="dot amber"></span>
Symbolic leak tracer
</span>
</div>
<p>
Amber tracer cubes originate exclusively inside the opening on vessel B.
Vessel A has no leak particles.
</p>
</section>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.Fog(0x07111d, 17, 32);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
azimuth: 0.62,
polar: 1.12,
radius: 13.4,
target: new THREE.Vector3(0, -0.02, 0)
};
function updateCamera() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.polar),
cameraState.target.z +
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemiLight = new THREE.HemisphereLight(0xa9dcff, 0x16212a, 2.0);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58dfff, 1.8);
rimLight.position.set(-7, 5, -6);
scene.add(rimLight);
const mintLight = new THREE.PointLight(0x68f5bd, 10, 8, 2);
mintLight.position.set(-3.2, 1.2, 3.2);
scene.add(mintLight);
// Ground and grid
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x0a1722,
roughness: 0.94,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(40, 40, 0x315064, 0x172b3a);
grid.position.y = -2.185;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
// -------------------------------------------------------------------------
// Shared materials
// -------------------------------------------------------------------------
const bodyMatA = new THREE.MeshStandardMaterial({
color: 0x526d7c,
roughness: 0.58,
metalness: 0.34
});
const bodyMatB = new THREE.MeshStandardMaterial({
color: 0x607b89,
roughness: 0.55,
metalness: 0.36
});
const frameMat = new THREE.MeshStandardMaterial({
color: 0x263b49,
roughness: 0.36,
metalness: 0.72
});
const edgeMat = new THREE.MeshStandardMaterial({
color: 0x88a4b2,
roughness: 0.32,
metalness: 0.68
});
const frontMat = new THREE.MeshStandardMaterial({
color: 0x78b8d2,
roughness: 0.25,
metalness: 0.08,
transparent: true,
opacity: 0.25,
depthWrite: false
});
const coreMat = new THREE.MeshBasicMaterial({
color: 0x48d9e7,
transparent: true,
opacity: 0.085,
depthWrite: false
});
const gasketMat = new THREE.MeshStandardMaterial({
color: 0x68f5bd,
emissive: 0x21c98d,
emissiveIntensity: 0.9,
roughness: 0.38,
metalness: 0.18
});
const gapMat = new THREE.MeshStandardMaterial({
color: 0xffb347,
emissive: 0xff7b20,
emissiveIntensity: 2.0,
roughness: 0.3,
metalness: 0.08
});
const leakMat = new THREE.MeshStandardMaterial({
color: 0xffd27a,
emissive: 0xff7a21,
emissiveIntensity: 3.2,
roughness: 0.25,
metalness: 0.04
});
const platformMat = new THREE.MeshStandardMaterial({
color: 0x152734,
roughness: 0.62,
metalness: 0.45
});
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
const VOXEL = 0.42;
const NX = 8;
const NZ = 6;
const NY = 4;
const BODY_W = NX * VOXEL;
const BODY_D = NZ * VOXEL;
const GASKET_W = BODY_W + 0.56;
const GASKET_D = BODY_D + 0.56;
const GASKET_BAR = 0.12;
const voxelGeometry = new THREE.BoxGeometry(
VOXEL * 0.955,
VOXEL * 0.955,
VOXEL * 0.955
);
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addRectRing(
parent,
width,
depth,
bar,
height,
y,
material
) {
const frontZ = depth / 2 - bar / 2;
addBox(
parent,
[width, height, bar],
[0, y, frontZ],
material
);
addBox(
parent,
[width, height, bar],
[0, y, -frontZ],
material
);
addBox(
parent,
[bar, height, depth - bar * 2],
[width / 2 - bar / 2, y, 0],
material
);
addBox(
parent,
[bar, height, depth - bar * 2],
[-width / 2 + bar / 2, y, 0],
material
);
}
function createVoxelInstances(parent, positions, material) {
const mesh = new THREE.InstancedMesh(
voxelGeometry,
material,
positions.length
);
const dummy = new THREE.Object3D();
positions.forEach((position, index) => {
dummy.position.set(position[0], position[1], position[2]);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function buildVoxelSegment(parent, baseY) {
const solidA = [];
const solidB = [];
const transparentFront = [];
for (let iz = 0; iz < NZ; iz++) {
for (let iy = 0; iy < NY; iy++) {
for (let ix = 0; ix < NX; ix++) {
const boundary =
ix === 0 ||
ix === NX - 1 ||
iz === 0 ||
iz === NZ - 1 ||
iy === 0 ||
iy === NY - 1;
if (!boundary) continue;
const position = [
(ix - (NX - 1) / 2) * VOXEL,
baseY + (iy + 0.5) * VOXEL,
(iz - (NZ - 1) / 2) * VOXEL
];
const isTransparentFront =
iz === NZ - 1 &&
ix > 0 &&
ix < NX - 1 &&
iy > 0 &&
iy < NY - 1;
if (isTransparentFront) {
transparentFront.push(position);
} else if ((ix + iy + iz) % 3 === 0) {
solidA.push(position);
} else {
solidB.push(position);
}
}
}
}
createVoxelInstances(parent, solidA, bodyMatA);
createVoxelInstances(parent, solidB, bodyMatB);
createVoxelInstances(parent, transparentFront, frontMat);
}
function addGasket(parent, interrupted) {
const y = 0;
const frontZ = GASKET_D / 2 - GASKET_BAR / 2;
const height = 0.14;
// Rear segment is always complete.
addBox(
parent,
[GASKET_W, height, GASKET_BAR],
[0, y, -frontZ],
gasketMat
);
// Side segments are always complete.
addBox(
parent,
[GASKET_BAR, height, GASKET_D - GASKET_BAR * 2],
[GASKET_W / 2 - GASKET_BAR / 2, y, 0],
gasketMat
);
addBox(
parent,
[GASKET_BAR, height, GASKET_D - GASKET_BAR * 2],
[-GASKET_W / 2 + GASKET_BAR / 2, y, 0],
gasketMat
);
let gap = null;
if (!interrupted) {
addBox(
parent,
[GASKET_W, height, GASKET_BAR],
[0, y, frontZ],
gasketMat
);
} else {
const gapCenter = 0.72;
const gapWidth = 0.42;
const gapLeft = gapCenter - gapWidth / 2;
const gapRight = gapCenter + gapWidth / 2;
const gasketLeft = -GASKET_W / 2;
const gasketRight = GASKET_W / 2;
// Front segment to the left of the opening.
addBox(
parent,
[gapLeft - gasketLeft, height, GASKET_BAR],
[(gasketLeft + gapLeft) / 2, y, frontZ],
gasketMat
);
// Front segment to the right of the opening.
addBox(
parent,
[gasketRight - gapRight, height, GASKET_BAR],
[(gapRight + gasketRight) / 2, y, frontZ],
gasketMat
);
// Orange aperture outline marks the only possible escape path.
const outlineGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(gapWidth, 0.22, 0.15)
);
const outline = new THREE.LineSegments(
outlineGeometry,
new THREE.LineBasicMaterial({
color: 0xffb347,
transparent: true,
opacity: 0.95
})
);
outline.position.set(gapCenter, 0, frontZ + 0.04);
parent.add(outline);
gap = {
x: gapCenter,
width: gapWidth,
y,
z: frontZ + GASKET_BAR / 2 + 0.015
};
}
return gap;
}
function addVesselFrame(parent) {
const cornerX = BODY_W / 2 + 0.03;
const cornerZ = BODY_D / 2 + 0.03;
for (const x of [-cornerX, cornerX]) {
for (const z of [-cornerZ, cornerZ]) {
addBox(
parent,
[0.16, 3.62, 0.16],
[x, 0, z],
frameMat
);
}
}
// Upper and lower flange rings surround the gasket seam.
addRectRing(
parent,
BODY_W + 0.42,
BODY_D + 0.42,
0.22,
0.18,
-0.18,
frameMat
);
addRectRing(
parent,
BODY_W + 0.42,
BODY_D + 0.42,
0.22,
0.18,
0.18,
edgeMat
);
// Flange fasteners.
for (const y of [-0.18, 0.18]) {
for (let x = -1.35; x <= 1.36; x += 0.675) {
addBox(
parent,
[0.09, 0.09, 0.09],
[x, y, BODY_D / 2 + 0.25],
edgeMat
);
}
}
// Top lid.
addBox(
parent,
[BODY_W + 0.12, 0.16, BODY_D + 0.12],
[0, 1.86, 0],
frameMat
);
addBox(
parent,
[1.05, 0.18, 0.72],
[0, 2.00, 0],
edgeMat
);
// Two block feet.
for (const x of [-0.9, 0.9]) {
addBox(
parent,
[0.52, 0.28, BODY_D + 0.24],
[x, -1.94, 0],
frameMat
);
}
// Display platform.
addBox(
parent,
[4.12, 0.12, 3.18],
[0, -2.11, 0],
platformMat
);
}
// -------------------------------------------------------------------------
// Symbolic leak: every particle starts inside the actual gasket gap
// -------------------------------------------------------------------------
function seededRandom(seed) {
return function () {
let t = seed += 0x6d2b79f5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function createLeak(parent, gap) {
const random = seededRandom(8128);
const count = 76;
const particles = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.10, 0.10, 0.10),
leakMat,
count
);
particles.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
particles.frustumCulled = false;
particles.castShadow = false;
parent.add(particles);
const seeds = [];
const warm = new THREE.Color(0xffd27a);
const hot = new THREE.Color(0xff6b22);
for (let i = 0; i < count; i++) {
seeds.push({
offsetX: (random() - 0.5) * gap.width * 0.76,
phase: random(),
speed: 0.43 + random() * 0.33,
lift: random() * 0.13,
drift: (random() - 0.5) * 0.16,
scale: 0.72 + random() * 0.55
});
particles.setColorAt(
i,
new THREE.Color().lerpColors(warm, hot, random() * 0.65)
);
}
particles.instanceColor.needsUpdate = true;
const glow = new THREE.PointLight(0xff8b32, 5.0, 3.2, 2);
glow.position.set(gap.x, gap.y, gap.z + 0.08);
parent.add(glow);
const dummy = new THREE.Object3D();
function update(time) {
for (let i = 0; i < count; i++) {
const seed = seeds[i];
const age = (time * seed.speed + seed.phase) % 1;
// The x coordinate begins inside the missing gasket segment.
// The z coordinate begins at the gasket's outer face and travels out.
const x =
gap.x +
seed.offsetX +
age * seed.drift;
const y =
gap.y +
age * 0.52 +
Math.sin(age * Math.PI) * seed.lift;
const z =
gap.z +
0.025 +
age * 2.55;
const size = seed.scale * (1 - age * 0.58);
dummy.position.set(x, y, z);
dummy.rotation.set(age * 2.0, age * 3.1, age * 1.3);
dummy.scale.setScalar(size);
dummy.updateMatrix();
particles.setMatrixAt(i, dummy.matrix);
}
particles.instanceMatrix.needsUpdate = true;
glow.intensity = 4.0 + Math.sin(time * 8) * 1.1;
}
return { update };
}
// -------------------------------------------------------------------------
// Construct both comparison vessels
// -------------------------------------------------------------------------
function buildVessel(x, interrupted) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
buildVoxelSegment(group, -1.78);
buildVoxelSegment(group, 0.10);
// Internal pressure volume, visible through the transparent front voxels.
addBox(
group,
[BODY_W - 0.62, 1.55, BODY_D - 0.62],
[0, -0.96, 0],
coreMat,
false
);
addBox(
group,
[BODY_W - 0.62, 1.55, BODY_D - 0.62],
[0, 0.96, 0],
coreMat,
false
);
addVesselFrame(group);
const gap = addGasket(group, interrupted);
const leak = gap ? createLeak(group, gap) : null;
return { group, gap, leak };
}
const vesselA = buildVessel(-3.15, false);
const vesselB = buildVessel(3.15, true);
// -------------------------------------------------------------------------
// DOM labels projected from 3D anchor points
// -------------------------------------------------------------------------
const labelA = document.getElementById("labelA");
const labelB = document.getElementById("labelB");
const gapLabel = document.getElementById("gapLabel");
const anchorA = new THREE.Vector3(-3.15, 2.55, 0);
const anchorB = new THREE.Vector3(3.15, 2.55, 0);
const gapAnchor = vesselB.group.localToWorld(
new THREE.Vector3(vesselB.gap.x, 0.34, vesselB.gap.z + 0.18)
);
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.opacity = visible ? "1" : "0";
}
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * 0.005,
0.38,
1.48
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8.5,
21
);
},
{ passive: false }
);
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
if (button.dataset.view === "front") {
cameraState.azimuth = 0;
cameraState.polar = 1.28;
cameraState.radius = 12.8;
} else {
cameraState.azimuth = 0.62;
cameraState.polar = 1.12;
cameraState.radius = 13.4;
}
});
});
const pauseButton = document.getElementById("pause");
let paused = false;
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume tracer" : "Pause tracer";
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let leakTime = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) leakTime += delta;
updateCamera();
gasketMat.emissiveIntensity =
0.82 + Math.sin(clock.elapsedTime * 2.1) * 0.12;
if (vesselB.leak) vesselB.leak.update(leakTime);
scene.updateMatrixWorld();
positionLabel(labelA, anchorA);
positionLabel(labelB, anchorB);
positionLabel(gapLabel, gapAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```
Serve it locally, for example with `python -m http.server`, then open `http://localhost:8000`.
```