Prompt specification
Build or customize the Three.js 3D scene "Neighborhood bicycle maintenance table" 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: Neighborhood bicycle maintenance table
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-bicycle-maintenance-table-x0243
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows bicycle inner-tube repair. Compose a wheel, pump, tube, patch kit, and inspection tray; show an educational diagnosis-to-repair sequence while keeping every detached part associated with its original assembly. Stylized solid forms.
Working Three.js Starter (neighborhood-bicycle-maintenance-table-x0243):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Inner Tube Repair — Guided Workshop</title>
<style>
:root {
--ink: #18383d;
--muted: #5d7476;
--paper: #fffdf7;
--line: rgba(24, 56, 61, 0.14);
--teal: #168e8a;
--coral: #ef6b58;
--gold: #e5aa3f;
--violet: #7357b8;
--shadow: 0 18px 50px rgba(30, 54, 56, 0.14);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #e9e6dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.topbar {
position: absolute;
z-index: 10;
top: 22px;
left: 24px;
right: 24px;
display: flex;
justify-content: space-between;
align-items: flex-start;
pointer-events: none;
}
.brand {
max-width: 370px;
padding: 16px 18px 15px;
border: 1px solid rgba(255,255,255,0.78);
border-radius: 18px;
background: rgba(255,253,247,0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.2vw, 30px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 8px 0 0;
max-width: 310px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.top-actions {
display: flex;
gap: 9px;
pointer-events: auto;
}
.icon-button {
min-height: 42px;
padding: 0 14px;
border: 1px solid rgba(255,255,255,0.85);
border-radius: 13px;
background: rgba(255,253,247,0.91);
color: var(--ink);
box-shadow: 0 8px 24px rgba(30,54,56,0.11);
cursor: pointer;
font-size: 12px;
font-weight: 750;
}
.icon-button:hover { transform: translateY(-1px); }
.lesson {
position: absolute;
z-index: 10;
left: 24px;
bottom: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 20px 17px;
border: 1px solid rgba(255,255,255,0.84);
border-radius: 22px;
background: rgba(255,253,247,0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.lesson-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
#stage-kicker {
color: var(--coral);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#stage-metric {
padding: 5px 8px;
border-radius: 999px;
background: #edf4ef;
color: #487064;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
#stage-title {
margin: 0;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
#stage-body {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
#stage-tip {
margin: 12px 0 0;
padding: 10px 11px;
border-left: 3px solid var(--gold);
border-radius: 0 9px 9px 0;
background: #fbf3df;
color: #665633;
font-size: 11px;
line-height: 1.45;
}
.controls {
position: absolute;
z-index: 12;
bottom: 24px;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border: 1px solid rgba(255,255,255,0.86);
border-radius: 17px;
background: rgba(255,253,247,0.93);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.control-button {
height: 42px;
min-width: 42px;
padding: 0 13px;
border: 0;
border-radius: 12px;
background: #edf0ea;
color: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 800;
transition: transform 0.16s ease, background 0.16s ease;
}
.control-button:hover:not(:disabled) {
transform: translateY(-1px);
background: #e1e8df;
}
.control-button.primary {
min-width: 108px;
background: var(--ink);
color: white;
}
.control-button:disabled {
opacity: 0.36;
cursor: default;
}
.progress {
position: absolute;
z-index: 9;
left: 50%;
bottom: 86px;
transform: translateX(-50%);
display: flex;
gap: 6px;
padding: 7px 10px;
border-radius: 999px;
background: rgba(255,253,247,0.78);
backdrop-filter: blur(8px);
}
.step-dot {
width: 19px;
height: 5px;
padding: 0;
border: 0;
border-radius: 999px;
background: rgba(24,56,61,0.18);
cursor: pointer;
transition: width 0.25s ease, background 0.25s ease;
}
.step-dot.active {
width: 34px;
background: var(--coral);
}
.step-dot.done { background: rgba(22,142,138,0.48); }
.legend {
position: absolute;
z-index: 10;
right: 24px;
bottom: 24px;
width: 210px;
padding: 14px 15px;
border: 1px solid rgba(255,255,255,0.84);
border-radius: 17px;
background: rgba(255,253,247,0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.legend h2 {
margin: 0 0 10px;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin: 7px 0;
color: var(--muted);
font-size: 10px;
}
.swatch {
width: 20px;
border-top: 2px dashed var(--teal);
}
.swatch.violet { border-color: var(--violet); }
.swatch.gold { border-color: var(--gold); }
.swatch.solid { border-top-style: solid; border-color: var(--ink); }
.scene-label {
position: absolute;
z-index: 6;
display: none;
padding: 6px 9px;
border-left: 3px solid var(--teal);
border-radius: 2px 8px 8px 2px;
background: rgba(255,253,247,0.92);
box-shadow: 0 6px 18px rgba(30,54,56,0.12);
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.04em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
}
.scene-label.coral { border-color: var(--coral); }
.scene-label.gold { border-color: var(--gold); }
.scene-label.violet { border-color: var(--violet); }
.hint {
position: absolute;
z-index: 7;
top: 23px;
left: 50%;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 999px;
background: rgba(24,56,61,0.82);
color: white;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #ece9df;
color: var(--ink);
transition: opacity 0.35s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.loader {
text-align: center;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.loader::before {
content: "";
display: block;
width: 42px;
height: 42px;
margin: 0 auto 13px;
border: 5px solid rgba(22,142,138,0.18);
border-top-color: var(--teal);
border-radius: 50%;
animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 900px) {
.hint, .legend { display: none; }
.brand { max-width: 285px; }
.subtitle { display: none; }
.lesson { width: 330px; }
.progress { bottom: 86px; }
}
@media (max-width: 620px) {
.topbar { top: 12px; left: 12px; right: 12px; }
.brand { padding: 12px 14px; }
.top-actions { flex-direction: column; }
.icon-button { min-height: 36px; padding: 0 10px; }
.lesson {
left: 12px;
bottom: 76px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
#stage-title { font-size: 21px; }
#stage-body { font-size: 11px; }
#stage-tip { display: none; }
.controls { bottom: 12px; }
.control-button { height: 38px; min-width: 38px; padding: 0 10px; }
.control-button.primary { min-width: 84px; }
.progress { bottom: 62px; }
}
</style>
</head>
<body>
<div id="app"></div>
<header class="topbar">
<div class="brand">
<p class="eyebrow">Workshop / Tire Care</p>
<h1>Inner-tube repair</h1>
<p class="subtitle">A guided diagnosis-to-repair sequence with every loose part linked to its home.</p>
</div>
<div class="top-actions">
<button id="reset-view" class="icon-button" type="button">Reset view</button>
</div>
</header>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<section class="lesson" aria-live="polite">
<div class="lesson-top">
<span id="stage-kicker">01 / BASELINE</span>
<span id="stage-metric">CHECK</span>
</div>
<h2 id="stage-title">Read the tire</h2>
<p id="stage-body"></p>
<p id="stage-tip"></p>
</section>
<nav id="progress" class="progress" aria-label="Repair steps"></nav>
<div class="controls">
<button id="prev" class="control-button" type="button" aria-label="Previous step">←</button>
<button id="play" class="control-button primary" type="button">Pause</button>
<button id="next" class="control-button" type="button" aria-label="Next step">→</button>
</div>
<aside class="legend">
<h2>Association map</h2>
<div class="legend-row"><span class="swatch"></span>Tube ↔ wheel valve</div>
<div class="legend-row"><span class="swatch violet"></span>Patch ↔ kit slot</div>
<div class="legend-row"><span class="swatch gold"></span>Prep block ↔ kit</div>
<div class="legend-row"><span class="swatch solid"></span>Live pump hose</div>
</aside>
<div id="loading"><div class="loader">Preparing the workshop</div></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9e6dc");
scene.fog = new THREE.Fog("#e9e6dc", 15, 27);
const camera = new THREE.PerspectiveCamera(39, innerWidth / innerHeight, 0.1, 60);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight("#fff8e8", "#8ca6a0", 2.25);
scene.add(hemi);
const key = new THREE.DirectionalLight("#fff6df", 3.25);
key.position.set(-4, 9, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 1;
key.shadow.camera.far = 24;
key.shadow.bias = -0.0003;
scene.add(key);
const fill = new THREE.DirectionalLight("#b7e1dd", 1.2);
fill.position.set(6, 4, -5);
scene.add(fill);
const colors = {
ink: "#17383d",
tire: "#26383a",
tread: "#304548",
rim: "#d4dcd5",
metal: "#526a6d",
tube: "#ed705d",
tubeDark: "#c94e43",
tray: "#70b9b1",
trayDark: "#4b918d",
water: "#8dd2d0",
patch: "#188d89",
patchEdge: "#0c6667",
sand: "#d8aa69",
pump: "#e8ae3f",
cream: "#fff8e8",
glass: "#bdebe6",
violet: "#7357b8"
};
const materials = {
ink: new THREE.MeshStandardMaterial({ color: colors.ink, roughness: 0.8 }),
rim: new THREE.MeshStandardMaterial({ color: colors.rim, roughness: 0.62, metalness: 0.18 }),
metal: new THREE.MeshStandardMaterial({ color: colors.metal, roughness: 0.55, metalness: 0.32 }),
tube: new THREE.MeshStandardMaterial({ color: colors.tube, roughness: 0.72 }),
tubeDark: new THREE.MeshStandardMaterial({ color: colors.tubeDark, roughness: 0.75 }),
tray: new THREE.MeshStandardMaterial({ color: colors.tray, roughness: 0.8 }),
trayDark: new THREE.MeshStandardMaterial({ color: colors.trayDark, roughness: 0.82 }),
water: new THREE.MeshStandardMaterial({ color: colors.water, roughness: 0.28, transparent: true, opacity: 0.45 }),
patch: new THREE.MeshStandardMaterial({ color: colors.patch, roughness: 0.78 }),
patchEdge: new THREE.MeshStandardMaterial({ color: colors.patchEdge, roughness: 0.85 }),
sand: new THREE.MeshStandardMaterial({ color: colors.sand, roughness: 1 }),
pump: new THREE.MeshStandardMaterial({ color: colors.pump, roughness: 0.65 }),
cream: new THREE.MeshStandardMaterial({ color: colors.cream, roughness: 0.86 }),
glass: new THREE.MeshStandardMaterial({ color: colors.glass, roughness: 0.25, transparent: true, opacity: 0.5, depthWrite: false })
};
function addMesh(geometry, material, parent = scene, position = null) {
const object = new THREE.Mesh(geometry, material);
if (position) object.position.copy(position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, material, parent = scene, x = 0, y = 0, z = 0) {
return addMesh(new THREE.BoxGeometry(w, h, d), material, parent, new THREE.Vector3(x, y, z));
}
function cylinder(radiusTop, radiusBottom, height, material, parent = scene, x = 0, y = 0, z = 0, segments = 24) {
return addMesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material,
parent,
new THREE.Vector3(x, y, z)
);
}
const up = new THREE.Vector3(0, 1, 0);
function cylinderBetween(a, b, radius, material, parent = scene, radialSegments = 8) {
const delta = new THREE.Vector3().subVectors(b, a);
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, delta.length(), radialSegments),
material,
parent
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, delta.normalize());
return mesh;
}
// Ground and visual stage.
const floor = addMesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({ color: "#e3e0d5", roughness: 1 }),
scene,
new THREE.Vector3(0, -0.025, 0)
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const stageDisc = addMesh(
new THREE.CylinderGeometry(7.5, 7.5, 0.12, 80),
new THREE.MeshStandardMaterial({ color: "#efede4", roughness: 0.95 }),
scene,
new THREE.Vector3(0.2, -0.08, 0.2)
);
stageDisc.receiveShadow = true;
// Bicycle wheel.
const wheel = new THREE.Group();
wheel.position.set(-2.72, 1.93, 0);
scene.add(wheel);
const tireMaterial = new THREE.MeshStandardMaterial({
color: colors.tire,
roughness: 0.94,
transparent: true,
opacity: 0.56,
depthWrite: false
});
const treadMaterial = new THREE.MeshStandardMaterial({
color: colors.tread,
roughness: 0.95,
transparent: true,
opacity: 0.72,
depthWrite: false
});
addMesh(new THREE.TorusGeometry(1.62, 0.16, 14, 80), tireMaterial, wheel);
addMesh(new THREE.TorusGeometry(1.48, 0.035, 8, 80), treadMaterial, wheel, new THREE.Vector3(0, 0, 0.14));
for (let i = 0; i < 34; i++) {
const angle = (i / 34) * Math.PI * 2;
const tread = box(0.28, 0.055, 0.24, treadMaterial, wheel,
Math.cos(angle) * 1.79,
Math.sin(angle) * 1.79,
0
);
tread.rotation.z = angle + Math.PI / 2;
}
addMesh(new THREE.TorusGeometry(1.355, 0.058, 10, 80), materials.rim, wheel);
addMesh(new THREE.TorusGeometry(1.255, 0.018, 6, 80), materials.metal, wheel, new THREE.Vector3(0, 0, 0.045));
for (let i = 0; i < 18; i++) {
const angle = (i / 18) * Math.PI * 2;
const inner = new THREE.Vector3(Math.cos(angle + 0.13) * 0.18, Math.sin(angle + 0.13) * 0.18, 0.04);
const outer = new THREE.Vector3(Math.cos(angle) * 1.29, Math.sin(angle) * 1.29, 0);
cylinderBetween(inner, outer, 0.014, materials.metal, wheel, 6);
}
const hub = cylinder(0.16, 0.16, 0.48, materials.ink, wheel, 0, 0, 0);
hub.rotation.x = Math.PI / 2;
const hubCap = cylinder(0.085, 0.085, 0.55, materials.rim, wheel, 0, 0, 0);
hubCap.rotation.x = Math.PI / 2;
const valveAngle = 0.25;
const rimPort = new THREE.Object3D();
rimPort.position.set(Math.cos(valveAngle) * 1.355, Math.sin(valveAngle) * 1.355, 0.14);
wheel.add(rimPort);
const hosePort = new THREE.Object3D();
hosePort.position.set(Math.cos(valveAngle) * 1.04, Math.sin(valveAngle) * 1.04, 0.16);
wheel.add(hosePort);
const rimValve = cylinder(0.055, 0.055, 0.16, materials.metal, wheel,
Math.cos(valveAngle) * 1.355,
Math.sin(valveAngle) * 1.355,
0.12
);
rimValve.quaternion.setFromUnitVectors(
up,
new THREE.Vector3(Math.cos(valveAngle), Math.sin(valveAngle), 0)
);
// Inner tube, with a visible puncture and valve.
const tube = new THREE.Group();
scene.add(tube);
addMesh(new THREE.TorusGeometry(1.34, 0.075, 12, 88), materials.tube, tube);
const tubeValveAngle = 0.25;
const radial = new THREE.Vector3(Math.cos(tubeValveAngle), Math.sin(tubeValveAngle), 0);
const tubeValve = cylinder(0.052, 0.052, 0.34, materials.metal, tube,
radial.x * 1.18,
radial.y * 1.18,
0.12
);
tubeValve.quaternion.setFromUnitVectors(up, radial);
const valveBase = new THREE.Object3D();
valveBase.position.set(radial.x * 1.355, radial.y * 1.355, 0.12);
tube.add(valveBase);
const valveCap = new THREE.Object3D();
valveCap.position.set(radial.x * 1.015, radial.y * 1.015, 0.12);
tube.add(valveCap);
const capMesh = cylinder(0.072, 0.072, 0.12, materials.ink, tube,
radial.x * 1.015,
radial.y * 1.015,
0.12
);
capMesh.quaternion.setFromUnitVectors(up, radial);
const punctureAngle = 2.34;
const punctureLocal = new THREE.Vector3(
Math.cos(punctureAngle) * 1.34,
Math.sin(punctureAngle) * 1.34,
0.083
);
const punctureMarker = addMesh(
new THREE.SphereGeometry(0.085, 18, 12),
new THREE.MeshStandardMaterial({
color: "#ffdf4d",
emissive: "#9b6700",
emissiveIntensity: 0.25,
roughness: 0.55
}),
tube,
punctureLocal
);
const localPatchPosition = new THREE.Vector3(
Math.cos(punctureAngle) * 1.34,
Math.sin(punctureAngle) * 1.34,
0.092
);
const localPatchQuaternion = new THREE.Quaternion().setFromUnitVectors(
up,
new THREE.Vector3(0, 0, 1)
);
// Inspection tray with shallow water.
const inspectionTray = new THREE.Group();
inspectionTray.position.set(1.0, 0, 1.12);
scene.add(inspectionTray);
box(3.7, 0.12, 2.18, materials.trayDark, inspectionTray, 0, 0.12, 0);
box(3.48, 0.035, 1.96, materials.water, inspectionTray, 0, 0.195, 0);
box(3.7, 0.2, 0.13, materials.tray, inspectionTray, 0, 0.22, -1.025);
box(3.7, 0.2, 0.13, materials.tray, inspectionTray, 0, 0.22, 1.025);
box(0.13, 0.2, 1.93, materials.tray, inspectionTray, -1.785, 0.22, 0);
box(0.13, 0.2, 1.93, materials.tray, inspectionTray, 1.785, 0.22, 0);
// Small brush and soap bottle in the inspection area.
const brush = new THREE.Group();
brush.position.set(2.45, 0.34, 1.85);
brush.rotation.y = -0.35;
scene.add(brush);
box(0.72, 0.08, 0.18, materials.cream, brush, 0, 0, 0);
box(0.15, 0.1, 0.3, materials.sand, brush, 0.33, 0, 0);
for (let i = 0; i < 9; i++) {
box(0.018, 0.035, 0.29, materials.ink, brush, -0.31 + i * 0.075, -0.01, 0);
}
const soapBottle = new THREE.Group();
soapBottle.position.set(-0.48, 0.3, 1.73);
scene.add(soapBottle);
cylinder(0.17, 0.2, 0.38, materials.cream, soapBottle, 0, 0, 0);
cylinder(0.09, 0.09, 0.11, materials.trayDark, soapBottle, 0, 0.24, 0);
box(0.22, 0.09, 0.12, materials.trayDark, soapBottle, 0.1, 0.3, 0);
// Patch kit.
const kit = new THREE.Group();
kit.position.set(4.55, 0, 1.05);
scene.add(kit);
box(2.22, 0.13, 1.72, materials.trayDark, kit, 0, 0.12, 0);
box(2.04, 0.035, 1.54, materials.cream, kit, 0, 0.2, 0);
box(2.22, 0.19, 0.11, materials.tray, kit, 0, 0.22, -0.805);
box(2.22, 0.19, 0.11, materials.tray, kit, 0, 0.22, 0.805);
box(0.11, 0.19, 1.5, materials.tray, kit, -1.055, 0.22, 0);
box(0.11, 0.19, 1.5, materials.tray, kit, 1.055, 0.22, 0);
const patchHome = new THREE.Vector3(4.02, 0.34, 1.01);
const patchHomeQuaternion = new THREE.Quaternion();
const patchOutline = addMesh(
new THREE.TorusGeometry(0.205, 0.018, 8, 40),
materials.patchEdge,
kit,
new THREE.Vector3(-0.53, 0.24, -0.04)
);
patchOutline.rotation.x = Math.PI / 2;
const patch = new THREE.Group();
scene.add(patch);
const patchRim = cylinder(0.205, 0.205, 0.045, materials.patchEdge, patch);
const patchFace = cylinder(0.176, 0.176, 0.052, materials.patch, patch, 0, 0.008, 0);
patch.position.copy(patchHome);
const sandHome = new THREE.Vector3(4.02, 0.34, 1.55);
const sand = new THREE.Group();
scene.add(sand);
box(0.5, 0.055, 0.62, materials.sand, sand);
for (let i = 0; i < 12; i++) {
const fleck = box(
0.018,
0.008,
0.025 + (i % 3) * 0.01,
i % 2 ? materials.cream : materials.tubeDark,
sand,
-0.18 + (i % 4) * 0.12,
0.032,
-0.22 + Math.floor(i / 4) * 0.15
);
fleck.rotation.y = i * 0.47;
}
sand.position.copy(sandHome);
const glue = new THREE.Group();
glue.position.set(5.22, 0.34, 1.42);
scene.add(glue);
const glueTube = cylinder(0.13, 0.16, 0.46, materials.pump, glue, 0, 0, 0);
glueTube.rotation.z = Math.PI / 2;
cylinder(0.07, 0.1, 0.15, materials.ink, glue, 0.27, 0, 0);
cylinder(0.045, 0.06, 0.12, materials.cream, glue, 0.39, 0, 0);
// Printed patch-kit card.
function makeInstructionTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 640;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fff9e9";
ctx.fillRect(0, 0, 512, 640);
ctx.fillStyle = "#17383d";
ctx.fillRect(0, 0, 512, 104);
ctx.fillStyle = "#fff9e9";
ctx.font = "900 45px sans-serif";
ctx.fillText("PATCH KIT", 34, 68);
ctx.fillStyle = "#ef705d";
ctx.font = "800 26px sans-serif";
ctx.fillText("1 ABRADE", 40, 166);
ctx.fillText("2 CEMENT", 40, 218);
ctx.fillText("3 PRESS", 40, 270);
ctx.fillStyle = "#506b6c";
ctx.font = "600 23px sans-serif";
ctx.fillText("Round the edges.", 42, 200);
ctx.fillText("Wait until tacky.", 42, 252);
ctx.fillText("Hold until set.", 42, 304);
ctx.strokeStyle = "#c9bfa6";
ctx.lineWidth = 5;
ctx.beginPath();
ctx.arc(256, 455, 102, 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = "#188d89";
ctx.beginPath();
ctx.arc(256, 455, 73, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#17383d";
ctx.font = "800 20px sans-serif";
ctx.textAlign = "center";
ctx.fillText("60–90 SEC", 256, 592);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const instructionCard = addMesh(
new THREE.PlaneGeometry(0.72, 0.9),
new THREE.MeshStandardMaterial({
map: makeInstructionTexture(),
roughness: 0.92,
side: THREE.DoubleSide
}),
scene,
new THREE.Vector3(4.85, 0.235, 0.56)
);
instructionCard.rotation.x = -Math.PI / 2;
// Floor pump.
const pump = new THREE.Group();
pump.position.set(4.45, 0, -1.28);
scene.add(pump);
box(1.2, 0.15, 0.72, materials.ink, pump, 0, 0.13, 0);
cylinder(0.245, 0.245, 1.66, materials.pump, pump, 0, 1.05, 0);
cylinder(0.29, 0.29, 0.12, materials.ink, pump, 0, 1.91, 0);
cylinder(0.16, 0.16, 0.18, materials.metal, pump, 0, 0.3, 0);
const pumpHandle = new THREE.Group();
pumpHandle.position.set(0, 2.73, 0);
pump.add(pumpHandle);
cylinder(0.055, 0.055, 1.0, materials.metal, pumpHandle, 0, -0.47, 0);
const handleBar = cylinder(0.095, 0.095, 1.08, materials.ink, pumpHandle, 0, 0, 0);
handleBar.rotation.z = Math.PI / 2;
cylinder(0.13, 0.13, 0.16, materials.cream, pumpHandle, -0.54, 0, 0).rotation.z = Math.PI / 2;
cylinder(0.13, 0.13, 0.16, materials.cream, pumpHandle, 0.54, 0, 0).rotation.z = Math.PI / 2;
const gaugeFace = cylinder(0.18, 0.18, 0.055, materials.cream, pump, 0, 1.54, 0.27);
gaugeFace.rotation.x = Math.PI / 2;
const gaugeNeedle = box(0.018, 0.14, 0.015, materials.tubeDark, pump, 0.045, 1.58, 0.31);
gaugeNeedle.rotation.z = -0.55;
const pumpBasePort = new THREE.Object3D();
pumpBasePort.position.set(-0.2, 0.28, 0.06);
pump.add(pumpBasePort);
// A flexible hose built from solid segments so it can remain attached to the tube.
const hoseMaterial = new THREE.MeshStandardMaterial({ color: "#31494c", roughness: 0.82 });
const hoseSegments = [];
for (let i = 0; i < 26; i++) {
const segment = cylinder(0.034, 0.034, 1, hoseMaterial, scene);
segment.castShadow = true;
hoseSegments.push(segment);
}
const airBead = addMesh(
new THREE.SphereGeometry(0.065, 12, 8),
new THREE.MeshStandardMaterial({
color: "#71e4be",
emissive: "#1c8d68",
emissiveIntensity: 0.8,
roughness: 0.35
})
);
// Soap bubbles at the puncture.
const bubbleGroup = new THREE.Group();
scene.add(bubbleGroup);
const bubbles = [];
for (let i = 0; i < 9; i++) {
const bubble = addMesh(
new THREE.SphereGeometry(0.045 + (i % 3) * 0.018, 14, 10),
new THREE.MeshStandardMaterial({
color: "#e5ffff",
roughness: 0.12,
transparent: true,
opacity: 0.5,
depthWrite: false
}),
bubbleGroup
);
bubble.castShadow = false;
bubbles.push(bubble);
}
// Dashed association links.
function makeAssociation(color) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.12,
gapSize: 0.075,
transparent: true,
opacity: 0.9,
depthTest: false
});
const line = new THREE.Line(geometry, material);
line.renderOrder = 9;
scene.add(line);
return line;
}
function updateAssociation(line, a, b) {
const attribute = line.geometry.attributes.position;
attribute.setXYZ(0, a.x, a.y, a.z);
attribute.setXYZ(1, b.x, b.y, b.z);
attribute.needsUpdate = true;
line.geometry.computeBoundingSphere();
line.computeLineDistances();
}
const tubeLink = makeAssociation(colors.tray);
const patchLink = makeAssociation(colors.violet);
const sandLink = makeAssociation(colors.gold);
const cureRing = addMesh(
new THREE.TorusGeometry(0.29, 0.022, 8, 48),
new THREE.MeshBasicMaterial({
color: colors.pump,
transparent: true,
opacity: 0.82,
depthTest: false
})
);
cureRing.renderOrder = 10;
cureRing.castShadow = false;
// Guided sequence.
const stages = [
{
kicker: "01 / BASELINE",
title: "Read the tire",
metric: "Check",
body: "Inspect the tread, sidewalls, bead and rim before changing anything. The tire is made transparent so the inner tube and its valve can be seen.",
tip: "Start with a visual check. An unstable bead or damaged casing may require a tire replacement instead of a patch.",
targets: { detach: 0, patch: 0, sand: 0, pump: 0, bubbles: 0, opacity: 0.56, spin: 0 }
},
{
kicker: "02 / DIAGNOSE",
title: "Find the air leak",
metric: "Soap test",
body: "Move the tube into the inspection tray, add a little air and check for bubbles or a hissing sound. The yellow marker identifies the puncture.",
tip: "The live pump hose stays connected to the detached tube, so no part becomes visually or functionally orphaned.",
targets: { detach: 1, patch: 0, sand: 0, pump: 0.65, bubbles: 1, opacity: 0.5, spin: 0 }
},
{
kicker: "03 / ISOLATE",
title: "Keep the valve identified",
metric: "Valve link",
body: "Lay the tube flat without stretching it. The dashed association line ties its valve back to the original rim port.",
tip: "Never use a sharp tool near the tube. Mark the hole and remember which side of the tube faces the tire.",
targets: { detach: 1, patch: 0, sand: 0, pump: 0, bubbles: 0.16, opacity: 0.46, spin: 0 }
},
{
kicker: "04 / ABRADE",
title: "Prepare the rubber",
metric: "120–180 grit",
body: "Use the kit’s abrasive block to round and feather the damaged area. A clean, slightly fuzzy surface gives the cement more grip.",
tip: "Abrade only the damaged zone. The block remains linked to its patch-kit slot while it is away.",
targets: { detach: 1, patch: 0, sand: 1, pump: 0, bubbles: 0, opacity: 0.46, spin: 0 }
},
{
kicker: "05 / BOND",
title: "Apply the patch",
metric: "Center + press",
body: "Position the vulcanizing patch over the hole, press from the center outward and remove any excess cement.",
tip: "The patch moves from its labeled kit slot. While in transit, the violet link shows exactly where it belongs.",
targets: { detach: 1, patch: 1, sand: 0, pump: 0, bubbles: 0, opacity: 0.46, spin: 0 }
},
{
kicker: "06 / CURE",
title: "Let the bond set",
metric: "60–90 sec",
body: "Give the cement time to cure before installation. The patch remains centered on the tube while the timer ring completes its cycle.",
tip: "Cure time varies with temperature and cement type. Follow the kit’s stated dwell time rather than relying only on touch.",
targets: { detach: 1, patch: 1, sand: 0, pump: 0, bubbles: 0, opacity: 0.46, spin: 0 }
},
{
kicker: "07 / REINSTALL",
title: "Return it to the wheel",
metric: "Valve first",
body: "Insert the valve through the rim, place the tube inside the tire and seat the bead carefully all around the circumference.",
tip: "The valve is still attached to the tube, while the dashed line provides a visual reference to its wheel home.",
targets: { detach: 0, patch: 1, sand: 0, pump: 0, bubbles: 0, opacity: 0.78, spin: 0 }
},
{
kicker: "08 / INFLATE",
title: "Add air gradually",
metric: "Short pulses",
body: "Inflate in short pulses and watch the bead, pressure and repaired area. The wheel can be spun gently as the tire seats.",
tip: "Add only the pressure recommended for the tire and rim. The repaired section should remain flat and quiet.",
targets: { detach: 0, patch: 1, sand: 0, pump: 1, bubbles: 0, opacity: 0.96, spin: 1 }
},
{
kicker: "09 / VERIFY",
title: "Confirm the repair",
metric: "Final check",
body: "Recheck the pressure, inspect the bead and spin the wheel. The tube, patch, tools and pump are all restored to their original relationships.",
tip: "A successful repair should hold pressure, show no bubbles and leave the tire seated evenly.",
targets: { detach: 0, patch: 1, sand: 0, pump: 0, bubbles: 0, opacity: 1, spin: 0.24 }
}
];
let stageIndex = 0;
let autoPlaying = !reduceMotion;
let stageClock = 0;
const stageDuration = 5.1;
const current = { ...stages[0].targets };
const target = { ...stages[0].targets };
const kickerEl = document.getElementById("stage-kicker");
const titleEl = document.getElementById("stage-title");
const bodyEl = document.getElementById("stage-body");
const tipEl = document.getElementById("stage-tip");
const metricEl = document.getElementById("stage-metric");
const playEl = document.getElementById("play");
const prevEl = document.getElementById("prev");
const nextEl = document.getElementById("next");
const progressEl = document.getElementById("progress");
const stepButtons = stages.map((stage, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = "step-dot";
button.setAttribute("aria-label", `Go to step ${index + 1}: ${stage.title}`);
button.addEventListener("click", () => {
setStage(index);
stageClock = 0;
});
progressEl.appendChild(button);
return button;
});
function setStage(index) {
stageIndex = Math.max(0, Math.min(stages.length - 1, index));
const stage = stages[stageIndex];
Object.assign(target, stage.targets);
kickerEl.textContent = stage.kicker;
titleEl.textContent = stage.title;
bodyEl.textContent = stage.body;
tipEl.textContent = stage.tip;
metricEl.textContent = stage.metric;
stepButtons.forEach((button, i) => {
button.classList.toggle("active", i === stageIndex);
button.classList.toggle("done", i < stageIndex);
});
prevEl.disabled = stageIndex === 0;
nextEl.textContent = stageIndex === stages.length - 1 ? "↺" : "→";
playEl.textContent = autoPlaying ? "Pause" : "Play";
}
playEl.addEventListener("click", () => {
if (stageIndex === stages.length - 1 && !autoPlaying) {
setStage(0);
stageClock = 0;
autoPlaying = true;
} else {
autoPlaying = !autoPlaying;
}
playEl.textContent = autoPlaying ? "Pause" : "Play";
});
prevEl.addEventListener("click", () => {
setStage(stageIndex - 1);
stageClock = 0;
});
nextEl.addEventListener("click", () => {
if (stageIndex === stages.length - 1) {
setStage(0);
stageClock = 0;
autoPlaying = false;
playEl.textContent = "Play";
} else {
setStage(stageIndex + 1);
stageClock = 0;
}
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowRight") nextEl.click();
if (event.key === "ArrowLeft") prevEl.click();
if (event.code === "Space") {
event.preventDefault();
playEl.click();
}
});
setStage(0);
playEl.textContent = autoPlaying ? "Pause" : "Play";
// DOM callouts projected from 3D positions.
const labels = [];
function addLabel(text, anchor, visible, className = "") {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.textContent = text;
app.appendChild(element);
labels.push({ element, anchor, visible });
return element;
}
const worldFrom = (object, local) => object.localToWorld(local.clone());
addLabel("TIRE CASING", () => worldFrom(wheel, new THREE.Vector3(-0.85, 1.52, 0.18)), () => stageIndex === 0);
addLabel("RIM + BEAD", () => worldFrom(wheel, new THREE.Vector3(0.75, -1.19, 0.16)), () => stageIndex === 0, "coral");
addLabel("INNER TUBE", () => worldFrom(tube, new THREE.Vector3(-0.7, -0.9, 0.12)), () => stageIndex === 0 || stageIndex === 2, "coral");
addLabel("LEAK / SOAP BUBBLES", () => bubbleGroup.getWorldPosition(new THREE.Vector3()), () => stageIndex === 1, "gold");
addLabel("PUNCTURE MARK", () => worldFrom(tube, punctureLocal), () => stageIndex === 1 || stageIndex === 3, "gold");
addLabel("VALVE ↔ RIM", () => tubeLink.geometry.attributes.position.getX(0) !== 0 ? new THREE.Vector3(
(tubeLink.geometry.attributes.position.getX(0) + tubeLink.geometry.attributes.position.getX(1)) / 2,
(tubeLink.geometry.attributes.position.getY(0) + tubeLink.geometry.attributes.position.getY(1)) / 2 + 0.13,
(tubeLink.geometry.attributes.position.getZ(0) + tubeLink.geometry.attributes.position.getZ(1)) / 2
) : new THREE.Vector3(), () => stageIndex === 2 || stageIndex === 6);
addLabel("INSPECTION TRAY", () => new THREE.Vector3(0.4, 0.36, 1.95), () => stageIndex === 2 || stageIndex === 3, "coral");
addLabel("ABRADE EDGE", () => sand.getWorldPosition(new THREE.Vector3()), () => stageIndex === 3, "gold");
addLabel("PATCH ↔ KIT", () => patch.getWorldPosition(new THREE.Vector3()), () => stageIndex === 4 && current.patch > 0.08 && current.patch < 0.94, "violet");
addLabel("VULCANIZING PATCH", () => patch.getWorldPosition(new THREE.Vector3()), () => stageIndex === 5 || stageIndex === 6, "violet");
addLabel("CURE 60–90 SEC", () => patch.getWorldPosition(new THREE.Vector3()), () => stageIndex === 5, "gold");
addLabel("TUBE RETURNS TO RIM", () => worldFrom(tube, new THREE.Vector3(0, 1.05, 0.15)), () => stageIndex === 6, "coral");
addLabel("GRADUATE AIRFLOW", () => pump.getWorldPosition(new THREE.Vector3(0, 2.25, 0)), () => stageIndex === 7, "gold");
addLabel("BEAD SEATED", () => worldFrom(wheel, new THREE.Vector3(0.95, 1.12, 0.18)), () => stageIndex === 7, "coral");
addLabel("REPAIR VERIFIED", () => patch.getWorldPosition(new THREE.Vector3()), () => stageIndex === 8, "gold");
// Direct camera controls; no addons are imported.
const cameraTarget = new THREE.Vector3(0.2, 1.25, 0.18);
let cameraYaw = 0.56;
let cameraPitch = 0.46;
let cameraDistance = 11.4;
let dragging = false;
let previousX = 0;
let previousY = 0;
function resetCamera() {
cameraYaw = 0.56;
cameraPitch = 0.46;
cameraDistance = 11.4;
cameraTarget.set(0.2, 1.25, 0.18);
}
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraDistance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.005, 0.18, 1.02);
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined && 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();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.008,
7.2,
16.5
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset-view").addEventListener("click", resetCamera);
renderer.domElement.style.cursor = "grab";
function damp(value, destination, speed, delta) {
return THREE.MathUtils.lerp(value, destination, 1 - Math.exp(-speed * delta));
}
const clock = new THREE.Clock();
const temporaryA = new THREE.Vector3();
const temporaryB = new THREE.Vector3();
const temporaryC = new THREE.Vector3();
const installedTubePosition = new THREE.Vector3();
const trayTubePosition = new THREE.Vector3(1.0, 0.36, 1.12);
const trayTubeQuaternion = new THREE.Quaternion().setFromEuler(new THREE.Vector3(-Math.PI / 2, 0, 0));
const installedTubeQuaternion = new THREE.Quaternion();
const attachedPatchPosition = new THREE.Vector3();
const attachedPatchQuaternion = new THREE.Quaternion();
const rimWorld = new THREE.Vector3();
const valveBaseWorld = new THREE.Vector3();
const valveCapWorld = new THREE.Vector3();
const pumpPortWorld = new THREE.Vector3();
const punctureWorld = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
const visible = label.visible();
if (!visible) {
label.element.style.display = "none";
continue;
}
const point = label.anchor();
point.project(camera);
const onScreen = point.z > -1 && point.z < 1 && Math.abs(point.x) < 1.15 && Math.abs(point.y) < 1.15;
if (!onScreen) {
label.element.style.display = "none";
continue;
}
label.element.style.display = "block";
label.element.style.left = `${(point.x * 0.5 + 0.5) * innerWidth}px`;
label.element.style.top = `${(-point.y * 0.5 + 0.5) * innerHeight}px`;
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (autoPlaying) {
stageClock += delta;
if (stageClock >= stageDuration) {
stageClock = 0;
if (stageIndex < stages.length - 1) {
setStage(stageIndex + 1);
} else {
autoPlaying = false;
playEl.textContent = "Replay";
}
}
}
for (const key of Object.keys(current)) {
current[key] = damp(current[key], target[key], 2.7, delta);
}
// Wheel motion.
wheel.rotation.z += delta * current.spin * 0.55;
// Tube transitions between the wheel and inspection tray.
installedTubePosition.copy(wheel.position);
installedTubePosition.z += 0.02;
installedTubeQuaternion.copy(wheel.quaternion);
tube.position.lerpVectors(installedTubePosition, trayTubePosition, current.detach);
tube.quaternion.slerpQuaternions(installedTubeQuaternion, trayTubeQuaternion, current.detach);
const tubeScale = THREE.MathUtils.lerp(1, 0.72, current.detach);
tube.scale.setScalar(tubeScale);
tube.updateMatrixWorld(true);
// Patch target on the tube.
attachedPatchPosition.copy(tube.localToWorld(localPatchPosition.clone()));
attachedPatchQuaternion.copy(tube.quaternion).multiply(localPatchQuaternion);
patch.position.lerpVectors(patchHome, attachedPatchPosition, current.patch);
patch.quaternion.slerpQuaternions(patchHomeQuaternion, attachedPatchQuaternion, current.patch);
patchOutline.material.opacity = 1;
patchOutline.visible = current.patch < 0.96;
// Abrasive block moves to the puncture and performs a small scrubbing motion.
temporaryA.copy(attachedPatchPosition);
temporaryA.add(new THREE.Vector3(0.18, 0.10, 0));
sand.position.lerpVectors(sandHome, temporaryA, current.sand);
sand.quaternion.slerpQuaternions(new THREE.Quaternion(), attachedPatchQuaternion, current.sand);
if (current.sand > 0.2) {
sand.position.x += Math.sin(time * 11) * 0.075 * current.sand;
sand.position.y += Math.abs(Math.cos(time * 11)) * 0.014 * current.sand;
}
punctureMarker.scale.setScalar(Math.max(0.001, 1 - current.patch));
// Association links.
rimWorld.copy(rimPort.getWorldPosition(new THREE.Vector3()));
valveBaseWorld.copy(valveBase.getWorldPosition(new THREE.Vector3()));
valveCapWorld.copy(valveCap.getWorldPosition(new THREE.Vector3()));
updateAssociation(tubeLink, valveBaseWorld, rimWorld);
tubeLink.visible = current.detach > 0.025 && current.detach < 0.985;
updateAssociation(patchLink, patch.position, patchHome);
patchLink.visible = current.patch > 0.025 && current.patch < 0.975;
updateAssociation(sandLink, sand.position, sandHome);
sandLink.visible = current.sand > 0.025 && current.sand < 0.975;
// Flexible live hose from the pump to the tube valve.
pumpBasePort.getWorldPosition(pumpPortWorld);
temporaryB.copy(pumpPortWorld);
temporaryB.y = 0.23;
temporaryC.copy(valveCapWorld).lerp(pumpPortWorld, 0.48);
temporaryC.y = 0.18;
const hoseCurve = new THREE.CatmullRomCurve3([
pumpPortWorld.clone(),
new THREE.Vector3(pumpPortWorld.x - 0.38, 0.24, pumpPortWorld.z - 0.26),
temporaryC.clone(),
valveCapWorld.clone()
]);
for (let i = 0; i < hoseSegments.length; i++) {
const a = hoseCurve.getPoint(i / hoseSegments.length);
const b = hoseCurve.getPoint((i + 1) / hoseSegments.length);
const segment = hoseSegments[i];
const direction = new THREE.Vector3().subVectors(b, a);
segment.position.copy(a).add(b).multiplyScalar(0.5);
segment.scale.set(1, direction.length(), 1);
segment.quaternion.setFromUnitVectors(up, direction.normalize());
}
const airActive = current.pump > 0.12;
airBead.visible = airActive;
if (airActive) {
airBead.position.copy(hoseCurve.getPointAt((time * 0.22) % 1));
airBead.scale.setScalar(0.8 + Math.sin(time * 10) * 0.16);
}
// Pump handle movement.
pumpHandle.position.y = THREE.MathUtils.lerp(2.73, 2.22, current.pump);
gaugeNeedle.rotation.z = -0.55 + Math.sin(time * 13) * 0.13 * current.pump;
// Bubble animation at the puncture.
bubbleGroup.visible = current.bubbles > 0.01;
if (bubbleGroup.visible) {
punctureWorld.copy(tube.localToWorld(punctureLocal.clone()));
bubbleGroup.position.copy(punctureWorld);
bubbles.forEach((bubble, i) => {
const cycle = (time * 0.52 + i * 0.19) % 1;
bubble.position.set(
Math.sin(i * 2.7) * 0.065,
cycle * 0.36,
Math.cos(i * 1.9) * 0.045
);
const scale = (0.35 + cycle * 0.85) * current.bubbles;
bubble.scale.setScalar(scale);
});
}
// Cure ring around the patch.
cureRing.visible = stageIndex === 5 && current.patch > 0.94;
if (cureRing.visible) {
cureRing.position.copy(patch.position);
const zToY = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 0, 1), up);
cureRing.quaternion.copy(patch.quaternion).multiply(zToY);
cureRing.scale.setScalar(1 + Math.sin(time * 3.5) * 0.08);
cureRing.material.opacity = 0.55 + Math.sin(time * 3.5) * 0.18;
}
// Tire transparency for the explanatory cutaway.
tireMaterial.opacity = current.opacity;
treadMaterial.opacity = THREE.MathUtils.lerp(0.7, 1, current.opacity);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateCamera();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```