Prompt specification
Build or customize the Three.js 3D scene "Skate Wheel Inspection Station" 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: Skate Wheel Inspection Station
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/skate-wheel-inspection-station-x2007
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Build a small repair bench with an exploded wheel, axle, spacers, and bearings. Reassemble in a coherent order and preserve part alignment.
Working Three.js Starter (skate-wheel-inspection-station-x2007):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Wheel Repair Bench</title>
<style>
:root {
--ink: #173033;
--muted: #667b7b;
--paper: rgba(248, 250, 246, 0.88);
--line: rgba(23, 48, 51, 0.13);
--green: #2e655b;
--lime: #c8f36a;
--orange: #ef7951;
--gold: #f0c453;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 35% 15%, #edf2e9 0, transparent 42%),
linear-gradient(145deg, #b8c8c4, #8fa4a1);
}
body {
user-select: none;
}
#scene-canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 28px;
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
display: grid;
width: 42px;
height: 42px;
place-items: center;
border: 1px solid rgba(23, 48, 51, 0.18);
border-radius: 12px;
background: var(--paper);
box-shadow: 0 8px 25px rgba(27, 49, 48, 0.11);
backdrop-filter: blur(12px);
font-size: 21px;
}
.brand-copy small,
.panel-kicker,
.dock-label,
.status-badge {
display: block;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand-copy small {
margin-bottom: 3px;
color: var(--muted);
}
.brand-copy strong {
font-size: 17px;
letter-spacing: -0.03em;
}
.panel {
position: absolute;
top: 24px;
right: 24px;
width: 280px;
padding: 20px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--paper);
box-shadow: 0 18px 55px rgba(27, 49, 48, 0.14);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.panel-kicker {
margin-bottom: 7px;
color: var(--green);
}
.panel h2 {
margin: 0 0 5px;
font-size: 21px;
letter-spacing: -0.04em;
}
.panel-intro {
margin: 0 0 19px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.steps {
display: grid;
gap: 9px;
margin: 0;
padding: 0;
list-style: none;
}
.step {
position: relative;
display: grid;
grid-template-columns: 30px 1fr;
gap: 10px;
align-items: center;
min-height: 40px;
padding: 7px 9px;
overflow: hidden;
border: 1px solid transparent;
border-radius: 11px;
transition: border-color 180ms ease, background 180ms ease;
}
.step::after {
position: absolute;
right: 9px;
bottom: 5px;
left: 49px;
height: 2px;
border-radius: 2px;
background: var(--step-progress-color, rgba(23, 48, 51, 0.08));
content: "";
}
.step-number {
display: grid;
width: 28px;
height: 28px;
place-items: center;
border-radius: 8px;
background: rgba(23, 48, 51, 0.07);
color: var(--muted);
font-size: 10px;
font-weight: 800;
transition: 180ms ease;
}
.step-name {
font-size: 12px;
font-weight: 750;
transition: color 180ms ease;
}
.step.active {
border-color: rgba(46, 101, 91, 0.18);
background: rgba(200, 243, 106, 0.14);
}
.step.active .step-number {
background: var(--green);
color: white;
}
.step.done .step-number {
background: var(--lime);
color: var(--ink);
}
.step.done .step-name {
color: var(--green);
}
.status-badge {
position: absolute;
top: 30px;
left: 28px;
margin-top: 57px;
padding: 7px 10px;
border: 1px solid rgba(23, 48, 51, 0.12);
border-radius: 999px;
background: rgba(248, 250, 246, 0.72);
color: var(--green);
backdrop-filter: blur(10px);
}
.dock {
position: absolute;
bottom: 24px;
left: 50%;
display: flex;
width: min(720px, calc(100vw - 48px));
min-height: 72px;
align-items: center;
gap: 12px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 19px;
background: var(--paper);
box-shadow: 0 18px 55px rgba(27, 49, 48, 0.16);
backdrop-filter: blur(16px);
transform: translateX(-50%);
pointer-events: auto;
}
button {
min-height: 42px;
padding: 0 15px;
border: 1px solid rgba(23, 48, 51, 0.14);
border-radius: 11px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
button:active {
transform: translateY(1px);
}
button.primary {
min-width: 126px;
border-color: var(--green);
background: var(--green);
color: white;
box-shadow: 0 8px 18px rgba(46, 101, 91, 0.2);
}
button.primary:hover {
background: #24534b;
}
button.icon-button {
width: 42px;
padding: 0;
font-size: 17px;
}
.slider-wrap {
display: grid;
flex: 1;
min-width: 130px;
grid-template-columns: 1fr 43px;
gap: 10px;
align-items: center;
}
.slider-label {
grid-column: 1 / -1;
display: flex;
justify-content: space-between;
margin-bottom: -4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 5px;
border-radius: 999px;
outline: none;
background: linear-gradient(
to right,
var(--green) 0%,
var(--green) var(--progress, 0%),
rgba(23, 48, 51, 0.12) var(--progress, 0%),
rgba(23, 48, 51, 0.12) 100%
);
appearance: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid white;
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 7px rgba(23, 48, 51, 0.25);
appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid white;
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 7px rgba(23, 48, 51, 0.25);
}
#percentage {
color: var(--green);
font-size: 12px;
font-weight: 850;
text-align: right;
}
.hint {
position: absolute;
bottom: 108px;
left: 50%;
padding: 7px 11px;
border-radius: 999px;
background: rgba(23, 48, 51, 0.68);
color: white;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
transform: translateX(-50%);
backdrop-filter: blur(8px);
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.part-label {
position: absolute;
padding: 6px 9px;
border: 1px solid rgba(23, 48, 51, 0.14);
border-radius: 8px;
background: rgba(248, 250, 246, 0.88);
box-shadow: 0 6px 18px rgba(23, 48, 51, 0.11);
color: var(--ink);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
}
.part-label::before {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 2px;
background: var(--part-color, var(--green));
content: "";
}
.part-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 14px;
background: rgba(23, 48, 51, 0.35);
content: "";
}
@media (max-width: 800px) {
.panel,
#labels {
display: none;
}
.brand {
top: 15px;
left: 15px;
}
.brand-copy strong {
font-size: 15px;
}
.status-badge {
top: 20px;
left: 15px;
margin-top: 58px;
}
.dock {
bottom: 14px;
width: calc(100vw - 24px);
flex-wrap: wrap;
gap: 8px;
padding: 10px;
}
.slider-wrap {
order: 5;
flex-basis: 100%;
}
button {
flex: 1;
padding: 0 10px;
}
button.primary {
min-width: 110px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene-canvas"></canvas>
<div id="labels"></div>
<main class="hud">
<div class="brand">
<div class="brand-mark">⚙</div>
<div class="brand-copy">
<small>Pixel Workshop / Bench 07</small>
<strong>Wheel & Axle Service</strong>
</div>
</div>
<div class="status-badge" id="statusBadge">Exploded view</div>
<aside class="panel">
<span class="panel-kicker">Reassembly sequence</span>
<h2>Wheel service kit</h2>
<p class="panel-intro">
Every component travels along the same axle axis, preventing drift and
preserving alignment.
</p>
<ol class="steps" id="steps">
<li class="step" data-step="0">
<span class="step-number">01</span>
<span class="step-name">Seat the axle</span>
</li>
<li class="step" data-step="1">
<span class="step-number">02</span>
<span class="step-name">Slide wheel + hub</span>
</li>
<li class="step" data-step="2">
<span class="step-number">03</span>
<span class="step-name">Fit inner bearings</span>
</li>
<li class="step" data-step="3">
<span class="step-number">04</span>
<span class="step-name">Seat outer spacers</span>
</li>
<li class="step" data-step="4">
<span class="step-number">05</span>
<span class="step-name">Lock the end caps</span>
</li>
</ol>
</aside>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom · Space to toggle</div>
<section class="dock">
<button id="explodeButton">Explode</button>
<button class="primary" id="assembleButton">Reassemble</button>
<div class="slider-wrap">
<div class="slider-label">
<span>Assembly progress</span>
<span>Axis aligned</span>
</div>
<input
id="progressSlider"
type="range"
min="0"
max="100"
step="1"
value="0"
aria-label="Assembly progress"
>
<span id="percentage">0%</span>
</div>
<button class="icon-button" id="resetButton" title="Reset camera" aria-label="Reset camera">
↺
</button>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene-canvas");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: 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.12;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xbecbc8, 19, 35);
const camera = new THREE.PerspectiveCamera(
window.innerWidth < 800 ? 54 : 42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const AXIS_Y = 2.48;
const cameraState = {
target: new THREE.Vector3(0, 1.65, 0),
radius: 15.8,
theta: 0.62,
phi: 1.08
};
function applyCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.target.set(0, 1.65, 0);
cameraState.radius = window.innerWidth < 800 ? 19.5 : 15.8;
cameraState.theta = 0.62;
cameraState.phi = 1.08;
applyCamera();
}
applyCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf1f8ed, 0x6a5948, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff3d4, 3.2);
keyLight.position.set(6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9e3e7, 1.25);
fillLight.position.set(-7, 6, -5);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xc8f36a, 9, 11, 2);
rimLight.position.set(0, 5, -3);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Shared materials and voxel helpers
// -------------------------------------------------------------------------
const material = (color, roughness = 0.78, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const M = {
floor: material(0x71817d, 0.95),
floorAlt: material(0x7c8b86, 0.95),
wood: material(0xa96742, 0.86),
woodLight: material(0xbc7b50, 0.82),
woodDark: material(0x71442f, 0.9),
mat: material(0x285650, 0.96),
matLine: material(0x477a71, 0.95),
tire: material(0x172126, 0.9),
tireAlt: material(0x202d31, 0.88),
rim: material(0xdce4df, 0.5, 0.25),
steel: material(0x9aa9aa, 0.35, 0.72),
steelDark: material(0x526367, 0.42, 0.68),
bearing: material(0xf1a15c, 0.5, 0.18),
race: material(0xd4dedd, 0.3, 0.8),
spacer: material(0xe8714c, 0.66, 0.12),
cap: material(0xf0c453, 0.58, 0.2),
toolbox: material(0x355d61, 0.75, 0.08),
toolboxTop: material(0x47777a, 0.72, 0.08),
guide: new THREE.MeshStandardMaterial({
color: 0xc8f36a,
emissive: 0x5f7d20,
emissiveIntensity: 0.6,
roughness: 0.6,
transparent: true,
opacity: 0.72
})
};
const geometryCache = new Map();
function boxGeometry(w, h, d) {
const key = `${w},${h},${d}`;
if (!geometryCache.has(key)) {
geometryCache.set(key, new THREE.BoxGeometry(w, h, d));
}
return geometryCache.get(key);
}
function box(parent, size, position, mat, rotationX = 0, castShadow = true) {
const mesh = new THREE.Mesh(boxGeometry(...size), mat);
mesh.position.set(...position);
mesh.rotation.x = rotationX;
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Repair bench and workshop props
// -------------------------------------------------------------------------
const workshop = new THREE.Group();
scene.add(workshop);
// Tiled voxel floor.
box(workshop, [24, 0.22, 18], [0, -0.78, 0], M.floor, 0, false);
for (let x = -10; x <= 10; x += 2) {
for (let z = -8; z <= 8; z += 2) {
if ((x + z) % 4 === 0) {
box(
workshop,
[1.94, 0.025, 1.94],
[x, -0.655, z],
M.floorAlt,
0,
false
);
}
}
}
// Bench top, fascia, shelf, and legs.
box(workshop, [11.4, 0.32, 4.4], [0, 0.72, 0], M.woodLight);
box(workshop, [11.2, 0.18, 0.2], [0, 0.54, 2.08], M.woodDark);
box(workshop, [10.3, 0.16, 3.3], [0, -0.29, 0], M.wood);
for (const x of [-4.9, 4.9]) {
for (const z of [-1.65, 1.65]) {
box(workshop, [0.38, 1.3, 0.38], [x, -0.05, z], M.woodDark);
}
}
// Drawer fronts.
for (const x of [-3.2, -1.6, 1.6, 3.2]) {
box(workshop, [1.42, 0.45, 0.14], [x, 0.22, 2.03], M.wood);
box(workshop, [0.42, 0.07, 0.09], [x, 0.3, 2.13], M.steelDark);
}
// Cutting mat.
box(workshop, [9.6, 0.04, 2.55], [0, 0.9, 0], M.mat, 0, false);
for (let x = -4.4; x <= 4.4; x += 0.8) {
box(workshop, [0.014, 0.007, 2.35], [x, 0.925, 0], M.matLine, 0, false);
}
for (let z = -1; z <= 1; z += 0.5) {
box(workshop, [9.35, 0.007, 0.014], [0, 0.925, z], M.matLine, 0, false);
}
// Toolbox.
box(workshop, [1.45, 0.64, 0.72], [4.25, 1.24, -1.42], M.toolbox);
box(workshop, [1.52, 0.12, 0.8], [4.25, 1.61, -1.42], M.toolboxTop);
box(workshop, [0.64, 0.08, 0.12], [4.25, 1.82, -1.42], M.steelDark);
box(workshop, [0.1, 0.35, 0.1], [3.99, 1.73, -1.42], M.steelDark);
box(workshop, [0.1, 0.35, 0.1], [4.51, 1.73, -1.42], M.steelDark);
// Small vise made from blocks.
box(workshop, [0.86, 0.18, 0.62], [-4.45, 1.02, 1.25], M.steelDark);
box(workshop, [0.22, 0.54, 0.66], [-4.72, 1.28, 1.25], M.steel);
box(workshop, [0.22, 0.54, 0.66], [-4.14, 1.28, 1.25], M.steel);
box(workshop, [0.12, 0.12, 1.02], [-4.43, 1.29, 1.25], M.steelDark);
// Tray and loose blocks.
box(workshop, [1.25, 0.08, 0.88], [4.25, 0.96, 1.3], M.toolboxTop);
box(workshop, [0.18, 0.18, 0.18], [4.02, 1.1, 1.2], M.bearing);
box(workshop, [0.14, 0.14, 0.14], [4.38, 1.08, 1.42], M.cap);
// Wrench.
const wrench = new THREE.Group();
wrench.position.set(2.7, 0.97, 1.55);
wrench.rotation.y = -0.25;
workshop.add(wrench);
box(wrench, [1.2, 0.09, 0.18], [0, 0, 0], M.steel);
box(wrench, [0.25, 0.1, 0.42], [-0.62, 0, 0], M.steel);
box(wrench, [0.25, 0.1, 0.42], [0.62, 0, 0], M.steel);
box(wrench, [0.13, 0.11, 0.18], [-0.62, 0, 0], M.mat);
// Screwdriver.
const screwdriver = new THREE.Group();
screwdriver.position.set(-2.75, 0.98, 1.55);
screwdriver.rotation.y = 0.35;
workshop.add(screwdriver);
box(screwdriver, [0.9, 0.1, 0.22], [0, 0, 0], M.cap);
box(screwdriver, [0.75, 0.065, 0.08], [0.78, 0, 0], M.steel);
// -------------------------------------------------------------------------
// Axle alignment guide
// -------------------------------------------------------------------------
const guide = new THREE.Group();
scene.add(guide);
box(guide, [10.4, 0.024, 0.024], [0, AXIS_Y, 0], M.guide, 0, false);
for (let x = -5; x <= 5; x += 0.5) {
box(guide, [0.13, 0.035, 0.035], [x, AXIS_Y, 0], M.guide, 0, false);
}
// -------------------------------------------------------------------------
// Mechanical parts
// -------------------------------------------------------------------------
const parts = [];
const labels = [];
const labelRoot = document.querySelector("#labels");
function createPart({
id,
assembledX,
explodedX,
delay,
duration,
label,
color,
anchorY
}) {
const group = new THREE.Group();
group.position.set(explodedX, AXIS_Y, 0);
scene.add(group);
const anchor = new THREE.Object3D();
anchor.position.set(0, anchorY, 0);
group.add(anchor);
const part = {
id,
group,
anchor,
assembledX,
explodedX,
delay,
duration
};
parts.push(part);
const labelElement = document.createElement("div");
labelElement.className = "part-label";
labelElement.textContent = label;
labelElement.style.setProperty("--part-color", color);
labelRoot.appendChild(labelElement);
labels.push({ element: labelElement, anchor });
return group;
}
function createWheel() {
const wheel = createPart({
id: "wheel",
assembledX: 0,
explodedX: -1.55,
delay: 0.06,
duration: 0.30,
label: "Wheel + hub",
color: "#dce4df",
anchorY: 1.77
});
// Tire: individual tangent blocks form a chunky voxel ring.
const tireCount = 38;
for (let i = 0; i < tireCount; i++) {
const theta = (i / tireCount) * Math.PI * 2;
const radius = 1.43;
box(
wheel,
[0.42, 0.18, 0.18],
[0, Math.sin(theta) * radius, Math.cos(theta) * radius],
i % 3 === 0 ? M.tireAlt : M.tire,
theta + Math.PI / 2
);
}
// Inner rim.
const rimCount = 36;
for (let i = 0; i < rimCount; i++) {
const theta = (i / rimCount) * Math.PI * 2;
const radius = 1.22;
box(
wheel,
[0.28, 0.16, 0.16],
[0, Math.sin(theta) * radius, Math.cos(theta) * radius],
M.rim,
theta + Math.PI / 2
);
}
// Radial spokes.
const spokeCount = 12;
for (let i = 0; i < spokeCount; i++) {
const theta = (i / spokeCount) * Math.PI * 2;
box(
wheel,
[0.16, 1.03, 0.07],
[0, Math.sin(theta) * 0.68, Math.cos(theta) * 0.68],
M.steel,
Math.PI / 2 - theta
);
}
// Hub and axle opening.
box(wheel, [0.68, 0.47, 0.47], [0, 0, 0], M.steel);
box(wheel, [0.12, 0.34, 0.34], [-0.39, 0, 0], M.steelDark);
box(wheel, [0.12, 0.34, 0.34], [0.39, 0, 0], M.steelDark);
box(wheel, [0.08, 0.19, 0.19], [0, 0, 0], M.tire);
return wheel;
}
function createAxle() {
const axle = createPart({
id: "axle",
assembledX: 0,
explodedX: 0.38,
delay: 0,
duration: 0.16,
label: "Axle",
color: "#a8b8ba",
anchorY: 0.55
});
box(axle, [3.08, 0.15, 0.15], [0, 0, 0], M.steel);
box(axle, [0.16, 0.21, 0.21], [-1.4, 0, 0], M.steelDark);
box(axle, [0.16, 0.21, 0.21], [1.4, 0, 0], M.steelDark);
box(axle, [0.32, 0.18, 0.18], [-0.55, 0, 0], M.steelDark);
return axle;
}
function createBearing(side) {
const bearing = createPart({
id: `bearing-${side}`,
assembledX: side * 0.58,
explodedX: side * 2.65,
delay: 0.20,
duration: 0.34,
label: "Bearing",
color: "#f1a15c",
anchorY: 0.72
});
const count = 12;
for (let i = 0; i < count; i++) {
const theta = (i / count) * Math.PI * 2;
box(
bearing,
[0.27, 0.15, 0.15],
[0, Math.sin(theta) * 0.28, Math.cos(theta) * 0.28],
M.race,
theta + Math.PI / 2
);
}
for (let i = 0; i < 8; i++) {
const theta = (i / 8) * Math.PI * 2 + Math.PI / 8;
box(
bearing,
[0.29, 0.095, 0.095],
[0, Math.sin(theta) * 0.18, Math.cos(theta) * 0.18],
M.bearing,
theta + Math.PI / 2
);
}
box(bearing, [0.31, 0.11, 0.11], [0, 0, 0], M.steelDark);
return bearing;
}
function createSpacer(side) {
const spacer = createPart({
id: `spacer-${side}`,
assembledX: side * 0.98,
explodedX: side * 3.65,
delay: 0.34,
duration: 0.38,
label: "Spacer",
color: "#e8714c",
anchorY: 0.72
});
// Hollow square spacer assembled from four blocks.
box(spacer, [0.25, 0.1, 0.52], [0, 0.21, 0], M.spacer);
box(spacer, [0.25, 0.1, 0.52], [0, -0.21, 0], M.spacer);
box(spacer, [0.25, 0.32, 0.1], [0, 0, 0.21], M.spacer);
box(spacer, [0.25, 0.32, 0.1], [0, 0, -0.21], M.spacer);
return spacer;
}
function createCap(side) {
const cap = createPart({
id: `cap-${side}`,
assembledX: side * 1.32,
explodedX: side * 4.55,
delay: 0.48,
duration: 0.44,
label: "Lock cap",
color: "#f0c453",
anchorY: 0.72
});
box(cap, [0.26, 0.32, 0.32], [0, 0, 0], M.cap);
box(cap, [0.26, 0.14, 0.66], [0, 0.12, 0], M.cap);
box(cap, [0.29, 0.11, 0.11], [0, 0, 0], M.steelDark);
return cap;
}
createAxle();
createWheel();
createBearing(-1);
createBearing(1);
createSpacer(-1);
createSpacer(1);
createCap(-1);
createCap(1);
// -------------------------------------------------------------------------
// Assembly animation
// -------------------------------------------------------------------------
const clamp01 = value => Math.max(0, Math.min(1, value));
const lerp = (a, b, t) => a + (b - a) * t;
function easeInOutCubic(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
let progress = 0;
let animation = null;
function updateParts() {
for (const part of parts) {
const local = clamp01((progress - part.delay) / part.duration);
const eased = easeInOutCubic(local);
// Only X changes. Y/Z and rotation remain fixed, preserving alignment.
part.group.position.x = lerp(part.explodedX, part.assembledX, eased);
}
}
function animateTo(target, duration = 5200) {
animation = {
from: progress,
to: target,
start: performance.now(),
duration
};
}
const slider = document.querySelector("#progressSlider");
const percentage = document.querySelector("#percentage");
const statusBadge = document.querySelector("#statusBadge");
const stepElements = [...document.querySelectorAll(".step")];
const stepRanges = [
[0.00, 0.16],
[0.06, 0.36],
[0.20, 0.54],
[0.34, 0.72],
[0.48, 0.92]
];
function updateUI() {
const value = Math.round(progress * 100);
slider.value = value;
slider.style.setProperty("--progress", `${value}%`);
percentage.textContent = `${value}%`;
if (progress < 0.05) {
statusBadge.textContent = "Exploded view";
} else if (progress < 0.19) {
statusBadge.textContent = "Axle seated";
} else if (progress < 0.36) {
statusBadge.textContent = "Wheel aligned";
} else if (progress < 0.54) {
statusBadge.textContent = "Bearings fitted";
} else if (progress < 0.72) {
statusBadge.textContent = "Spacers seated";
} else if (progress < 0.98) {
statusBadge.textContent = "Caps locking";
} else {
statusBadge.textContent = "Assembly complete";
}
stepElements.forEach((element, index) => {
const [start, end] = stepRanges[index];
const local = clamp01((progress - start) / (end - start));
element.classList.toggle("active", local > 0 && local < 1);
element.classList.toggle("done", local >= 1);
element.style.setProperty("--step-progress-color", `rgba(46, 101, 91, ${0.12 + local * 0.78})`);
});
}
slider.addEventListener("input", () => {
animation = null;
progress = Number(slider.value) / 100;
updateParts();
updateUI();
});
document.querySelector("#assembleButton").addEventListener("click", () => {
animateTo(1);
});
document.querySelector("#explodeButton").addEventListener("click", () => {
animateTo(0);
});
document.querySelector("#resetButton").addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
animateTo(progress < 0.5 ? 1 : 0);
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Custom camera controls — no addons required
// -------------------------------------------------------------------------
let pointerDown = false;
let pointerButton = 0;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", event => {
pointerDown = true;
pointerButton = event.button;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
const wantsPan = pointerButton === 2 || event.shiftKey;
if (wantsPan) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const panScale = cameraState.radius * 0.0012;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(up, dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -6, 6);
cameraState.target.y = THREE.MathUtils.clamp(cameraState.target.y, -0.5, 5);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -4, 4);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.28,
1.46
);
}
applyCamera();
});
function releasePointer(event) {
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.5,
27
);
applyCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Projected HTML part labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
label.anchor.getWorldPosition(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 800 ? 54 : 42;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
function render(now) {
requestAnimationFrame(render);
if (animation) {
const elapsed = now - animation.start;
const t = clamp01(elapsed / animation.duration);
progress = lerp(animation.from, animation.to, easeInOutCubic(t));
if (t >= 1) {
progress = animation.to;
animation = null;
}
}
updateParts();
updateUI();
updateLabels();
renderer.render(scene, camera);
}
updateParts();
updateUI();
requestAnimationFrame(render);
</script>
</body>
</html>
```