Prompt specification
Build or customize the Three.js 3D scene "Jammed wheel fault isolation" 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: Jammed wheel fault isolation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/jammed-wheel-fault-isolation-x0258
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows wind-up toy diagnosis and repair. Show a toy wheel blocked by a misplaced spacer; remove nearby parts one at a time until the obstructing contact becomes visible and rotation resumes. Voxel style.
Working Three.js Starter (jammed-wheel-fault-isolation-x0258):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Wind-Up Toy Diagnosis</title>
<style>
:root {
--ink: #17313a;
--muted: #60747a;
--panel: rgba(248, 250, 247, 0.93);
--line: rgba(23, 49, 58, 0.14);
--cyan: #16a9c4;
--orange: #f07824;
--green: #198b67;
--red: #c74738;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd7d7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
[hidden] { display: none !important; }
#hud {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: 342px;
max-width: calc(100vw - 36px);
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 18px 55px rgba(28, 48, 53, 0.19),
inset 0 1px 0 rgba(255, 255, 255, 0.9);
backdrop-filter: blur(15px);
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(22, 169, 196, 0.12);
}
h1 {
margin: 8px 0 12px;
font-size: 24px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
#status {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border-radius: 7px;
background: rgba(199, 71, 56, 0.12);
color: var(--red);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#status::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
}
#status.ok {
color: var(--green);
background: rgba(25, 139, 103, 0.12);
}
#status.found {
color: var(--orange);
background: rgba(240, 120, 36, 0.13);
}
#caseNo {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
}
#instruction {
min-height: 46px;
margin: 0 0 13px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.progress-wrap {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 15px;
}
.progress {
position: relative;
flex: 1;
height: 7px;
overflow: hidden;
border-radius: 4px;
background: rgba(23, 49, 58, 0.1);
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--green));
transition: width 320ms ease;
}
#progressText {
min-width: 29px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
text-align: right;
}
#checklist {
display: grid;
gap: 7px;
margin: 0 0 15px;
padding: 0;
list-style: none;
}
.step {
display: grid;
grid-template-columns: 29px 1fr auto;
align-items: center;
gap: 9px;
min-height: 42px;
padding: 7px 9px 7px 7px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.53);
transition: 180ms ease;
}
.step.done {
border-color: rgba(25, 139, 103, 0.25);
background: rgba(25, 139, 103, 0.075);
}
.step.exposed {
border-color: rgba(240, 120, 36, 0.45);
background: rgba(240, 120, 36, 0.1);
animation: amberPulse 1.4s ease-in-out infinite;
}
.step.removing {
border-color: rgba(240, 120, 36, 0.35);
background: rgba(240, 120, 36, 0.07);
}
@keyframes amberPulse {
50% { box-shadow: 0 0 0 4px rgba(240, 120, 36, 0.07); }
}
.step-dot {
display: grid;
place-items: center;
width: 27px;
height: 27px;
border-radius: 7px;
background: rgba(23, 49, 58, 0.08);
color: var(--muted);
font-size: 11px;
font-weight: 900;
}
.step.done .step-dot {
background: var(--green);
color: white;
}
.step.exposed .step-dot {
background: var(--orange);
color: white;
}
.step b {
display: block;
margin-bottom: 1px;
font-size: 12px;
letter-spacing: -0.01em;
}
.step small {
display: block;
color: var(--muted);
font-size: 10px;
}
.step-state {
color: var(--muted);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.12em;
}
.step.done .step-state { color: var(--green); }
.step.exposed .step-state { color: var(--orange); }
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 40px;
border: 0;
border-radius: 10px;
padding: 9px 11px;
background: var(--ink);
color: white;
font: inherit;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.035em;
cursor: pointer;
transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.42; cursor: default; transform: none; }
button.secondary {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
}
#repairButton {
grid-column: 1 / -1;
background: var(--orange);
box-shadow: 0 7px 18px rgba(240, 120, 36, 0.23);
}
.controls-note {
margin-top: 11px;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
letter-spacing: 0.02em;
}
#modeBadge {
position: fixed;
z-index: 5;
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 8px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
background: rgba(248, 250, 247, 0.8);
box-shadow: 0 9px 28px rgba(28, 48, 53, 0.13);
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
#modeBadge span {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(240, 120, 36, 0.12);
}
#modeBadge.repaired span {
background: var(--green);
box-shadow: 0 0 0 4px rgba(25, 139, 103, 0.12);
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.part-tag {
position: absolute;
display: none;
align-items: center;
gap: 6px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 7px;
background: rgba(248, 250, 247, 0.91);
box-shadow: 0 7px 18px rgba(23, 49, 58, 0.17);
color: var(--ink);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.035em;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: border-color 120ms ease, background 120ms ease;
}
.part-tag::before {
content: attr(data-number);
display: grid;
place-items: center;
width: 17px;
height: 17px;
border-radius: 5px;
background: var(--cyan);
color: white;
font-size: 9px;
}
.part-tag.active {
border-color: var(--cyan);
background: white;
box-shadow: 0 8px 22px rgba(22, 169, 196, 0.24);
}
.part-tag.spacer::before { background: var(--orange); }
#toast {
position: fixed;
z-index: 20;
left: 50%;
bottom: 27px;
max-width: min(460px, calc(100vw - 32px));
padding: 11px 16px;
border-radius: 10px;
background: rgba(23, 49, 58, 0.93);
box-shadow: 0 12px 35px rgba(23, 49, 58, 0.24);
color: white;
font-size: 12px;
font-weight: 700;
text-align: center;
opacity: 0;
transform: translate(-50%, 12px);
transition: opacity 180ms ease, transform 180ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#hint {
position: fixed;
z-index: 4;
right: 18px;
bottom: 17px;
padding: 8px 11px;
border-radius: 8px;
background: rgba(248, 250, 247, 0.72);
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.035em;
backdrop-filter: blur(8px);
pointer-events: none;
}
@media (max-width: 700px) {
#hud {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
max-width: 330px;
padding: 14px;
max-height: 70vh;
overflow: auto;
}
h1 { font-size: 20px; }
#instruction { min-height: 0; }
#modeBadge { display: none; }
#hint { display: none; }
#toast { bottom: 15px; }
}
</style>
</head>
<body>
<div id="labels"></div>
<section id="hud" aria-label="Toy repair controls">
<div class="eyebrow">Wind-up workshop</div>
<h1>Toy Wheel Diagnosis</h1>
<div class="status-row">
<div id="status">Wheel locked</div>
<div id="caseNo">CASE 07</div>
</div>
<p id="instruction" aria-live="polite">
The front wheel cannot turn. Remove the nearby covers one at a time to expose the contact area.
</p>
<div class="progress-wrap">
<div class="progress"><div id="progressFill"></div></div>
<div id="progressText">0/4</div>
</div>
<ol id="checklist">
<li class="step" id="step-hubcap">
<span class="step-dot">1</span>
<span><b>Remove the hubcap</b><small>Outer wheel cover</small></span>
<span class="step-state">OPEN</span>
</li>
<li class="step" id="step-fender">
<span class="step-dot">2</span>
<span><b>Lift the fender</b><small>Upper wheel clearance</small></span>
<span class="step-state">OPEN</span>
</li>
<li class="step" id="step-keeper">
<span class="step-dot">3</span>
<span><b>Pull the axle keeper</b><small>Lower contact cover</small></span>
<span class="step-state">OPEN</span>
</li>
<li class="step" id="step-spacer">
<span class="step-dot">4</span>
<span><b>Remove the spacer</b><small>Misplaced orange ring</small></span>
<span class="step-state">HIDDEN</span>
</li>
</ol>
<div class="actions">
<button id="repairButton" hidden>Remove orange spacer</button>
<button id="testButton">Test wind-up</button>
<button id="resetButton" class="secondary">Reset repair</button>
</div>
<div class="controls-note">
Click a highlighted 3D part to remove it. Drag to orbit, scroll/pinch to zoom,
and double-click the scene to reset the camera.
</div>
</section>
<div id="modeBadge"><span></span><b id="modeText">Inspection in progress</b></div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="hint">DRAG TO ORBIT · SCROLL TO ZOOM · CLICK PARTS</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd7d7);
scene.fog = new THREE.Fog(0xcbd7d7, 13, 27);
const camera = new THREE.PerspectiveCamera(
40,
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute("aria-label", "Interactive voxel wind-up toy repair scene");
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf7fbff, 0x8b6b50, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d8, 4.1);
sun.position.set(5.5, 9, 6.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x91d9ed, 1.1);
fill.position.set(-5, 4, -4);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.03,
flatShading: true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
}
function addBox(parent, size, position, mat, rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const wood = material(0xc99564, { roughness: 0.9 });
const woodDark = material(0xa9774e, { roughness: 0.94 });
const trayMat = material(0x35515a, { roughness: 0.72 });
const navy = material(0x203b46);
const red = material(0xe7604e);
const redDark = material(0xb94238);
const yellow = material(0xf2c94c);
const cream = material(0xf5ead3);
const glass = material(0x76bfd0, { roughness: 0.28, metalness: 0.12 });
const glassDark = material(0x38788c, { roughness: 0.25, metalness: 0.15 });
const tireMat = material(0x253139, { roughness: 0.96 });
const tireEdge = material(0x34434b, { roughness: 0.96 });
const hubMat = material(0xbcc8c7, { roughness: 0.5, metalness: 0.45 });
// Workbench.
addBox(scene, [13, 0.56, 8], [0, -0.28, 0], wood);
for (let x = -5; x <= 5; x += 1.25) {
addBox(scene, [0.018, 0.012, 7.8], [x, 0.006, 0], woodDark);
}
const grid = new THREE.GridHelper(10, 20, 0x52666a, 0x52666a);
grid.position.y = 0.015;
grid.material.transparent = true;
grid.material.opacity = 0.11;
scene.add(grid);
// Parts tray.
addBox(scene, [4.5, 0.14, 1.55], [-3.25, 0.07, 2.65], trayMat);
addBox(scene, [4.18, 0.025, 1.23], [-3.25, 0.155, 2.65], material(0x243b43));
for (let x = -4.55; x < -1.1; x += 0.84) {
addBox(scene, [0.025, 0.025, 1.05], [x, 0.18, 2.65], material(0x6c858a));
}
// Simple voxel workshop shelf and bins.
addBox(scene, [8.5, 0.18, 0.55], [0, 2.85, -3.55], woodDark);
addBox(scene, [1.25, 0.65, 0.85], [-2.65, 3.25, -3.5], material(0x6faebb));
addBox(scene, [0.95, 0.55, 0.75], [2.55, 3.19, -3.5], material(0xe5b858));
addBox(scene, [1.4, 0.42, 0.8], [0.5, 3.13, -3.5], material(0xd66a57));
// Voxel screwdriver on the bench.
const screwdriver = new THREE.Group();
screwdriver.position.set(4.4, 0.13, -1.9);
screwdriver.rotation.y = -0.35;
scene.add(screwdriver);
addBox(screwdriver, [0.9, 0.18, 0.22], [0, 0, 0], material(0xef8e3d));
addBox(screwdriver, [1.35, 0.075, 0.075], [-1.03, 0, 0], material(0x8ea1a5), [0, 0, 0.03]);
addBox(screwdriver, [0.28, 0.055, 0.24], [-1.68, 0, 0], material(0x8ea1a5));
// Toy.
const toy = new THREE.Group();
scene.add(toy);
addBox(toy, [4.35, 0.38, 2.5], [0, 0.76, 0], navy);
addBox(toy, [4.12, 0.62, 2.38], [-0.03, 1.12, 0], red);
addBox(toy, [1.55, 0.43, 2.27], [1.38, 1.61, 0], red);
addBox(toy, [1.74, 1.04, 2.02], [-0.55, 2.02, 0], redDark);
addBox(toy, [1.94, 0.18, 2.15], [-0.55, 2.61, 0], yellow);
// Block-built windows.
addBox(toy, [1.47, 0.62, 0.075], [-0.55, 2.08, 1.025], glass);
addBox(toy, [1.47, 0.62, 0.075], [-0.55, 2.08, -1.025], glassDark);
addBox(toy, [0.075, 0.59, 1.66], [0.345, 2.1, 0], glass);
addBox(toy, [0.075, 0.57, 1.63], [-1.435, 2.1, 0], glassDark);
addBox(toy, [0.18, 0.72, 0.17], [-0.55, 2.05, 1.07], red);
addBox(toy, [0.18, 0.72, 0.17], [-0.55, 2.05, -1.07], red);
// Hood details, grille and lights.
addBox(toy, [0.55, 0.05, 0.95], [1.58, 1.85, 0], yellow);
addBox(toy, [0.16, 0.3, 0.8], [2.16, 1.27, 0], navy);
addBox(toy, [0.2, 0.28, 0.38], [2.16, 1.43, 0.77], cream);
addBox(toy, [0.2, 0.28, 0.38], [2.16, 1.43, -0.77], cream);
addBox(toy, [0.28, 0.3, 2.66], [2.28, 0.76, 0], navy);
addBox(toy, [0.28, 0.3, 2.62], [-2.26, 0.77, 0], navy);
addBox(toy, [0.18, 0.16, 0.54], [-1.6, 1.5, 0], yellow);
// Rear wind-up key.
addBox(toy, [0.16, 0.38, 0.4], [-2.28, 1.46, 0], navy);
const keyRotor = new THREE.Group();
keyRotor.position.set(-2.55, 1.46, 0);
toy.add(keyRotor);
addBox(keyRotor, [0.7, 0.14, 0.14], [-0.23, 0, 0], hubMat);
addBox(keyRotor, [0.17, 0.74, 0.15], [-0.62, 0, 0], yellow);
addBox(keyRotor, [0.17, 0.15, 0.62], [-0.62, 0, 0], yellow);
function makeWheel(x, z) {
const wheel = new THREE.Group();
wheel.position.set(x, 0.67, z);
toy.add(wheel);
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2;
const block = addBox(
wheel,
[0.4, 0.4, 0.56],
[Math.cos(a) * 0.43, Math.sin(a) * 0.43, 0],
i % 2 ? tireMat : tireEdge,
[0, 0, a + Math.PI / 2]
);
block.castShadow = true;
}
addBox(wheel, [0.47, 0.47, 0.59], [0, 0, 0], hubMat);
addBox(wheel, [0.66, 0.11, 0.61], [0, 0, 0], yellow, [0, 0, 0.12]);
addBox(wheel, [0.11, 0.66, 0.61], [0, 0, 0], yellow, [0, 0, 0.12]);
addBox(wheel, [0.2, 0.2, 0.64], [0, 0, 0], red);
return wheel;
}
const wheels = [
makeWheel(1.55, 1.48),
makeWheel(1.55, -1.48),
makeWheel(-1.52, 1.48),
makeWheel(-1.52, -1.48)
];
const focusWheel = wheels[0];
// Fixed fender blocks on the other wheels.
addBox(toy, [1.45, 0.22, 0.72], [-1.52, 1.24, 1.48], redDark);
addBox(toy, [1.45, 0.22, 0.72], [-1.52, 1.24, -1.48], redDark);
addBox(toy, [0.23, 0.58, 0.72], [-0.78, 1.02, 1.48], redDark);
addBox(toy, [0.23, 0.58, 0.72], [-0.78, 1.02, -1.48], redDark);
const parts = new Map();
const partOrder = ["hubcap", "fender", "keeper", "spacer"];
const labelLayer = document.getElementById("labels");
function registerPart(id, name, group, number, offset) {
group.userData.partId = id;
const materials = new Set();
group.traverse((object) => {
if (object.isMesh) {
object.userData.partId = id;
materials.add(object.material);
}
});
const label = document.createElement("div");
label.className = `part-tag${id === "spacer" ? " spacer" : ""}`;
label.dataset.number = number;
label.textContent = name;
labelLayer.appendChild(label);
const part = {
id,
name,
group,
materials: [...materials],
removed: false,
label,
offset,
home: {
parent: group.parent,
position: group.position.clone(),
quaternion: group.quaternion.clone(),
scale: group.scale.clone()
}
};
parts.set(id, part);
return part;
}
// 1: Hubcap over the wheel hub.
const hubcapGroup = new THREE.Group();
hubcapGroup.position.set(1.55, 0.67, 1.84);
toy.add(hubcapGroup);
const hubcapMat = material(0xf3c84b, { metalness: 0.18 });
for (let i = 0; i < 8; i++) {
const a = (i / 8) * Math.PI * 2;
addBox(
hubcapGroup,
[0.14, 0.14, 0.13],
[Math.cos(a) * 0.24, Math.sin(a) * 0.24, 0],
hubcapMat,
[0, 0, a]
);
}
addBox(hubcapGroup, [0.25, 0.25, 0.14], [0, 0, 0], hubcapMat);
registerPart("hubcap", "HUB CAP", hubcapGroup, "1", [54, 25]);
// 2: Lift-off front fender.
const fenderGroup = new THREE.Group();
fenderGroup.position.set(1.55, 1.3, 1.53);
toy.add(fenderGroup);
const fenderMat = material(0x5bb8c1);
addBox(fenderGroup, [1.56, 0.22, 0.94], [0, 0, 0], fenderMat);
addBox(fenderGroup, [0.24, 0.56, 0.94], [0.72, -0.25, 0], fenderMat);
addBox(fenderGroup, [0.13, 0.13, 0.18], [-0.48, -0.19, 0.51], cream);
registerPart("fender", "LIFT FENDER", fenderGroup, "2", [42, -35]);
// 3: Lower axle keeper.
const keeperGroup = new THREE.Group();
keeperGroup.position.set(1.55, 0.37, 1.91);
toy.add(keeperGroup);
const keeperMat = material(0x344c59, { metalness: 0.25 });
addBox(keeperGroup, [0.62, 0.16, 0.16], [0, 0, 0], keeperMat);
addBox(keeperGroup, [0.16, 0.35, 0.16], [-0.24, 0.12, 0], keeperMat);
addBox(keeperGroup, [0.16, 0.35, 0.16], [0.24, 0.12, 0], keeperMat);
registerPart("keeper", "AXLE KEEPER", keeperGroup, "3", [62, 24]);
// 4: The obstruction itself, hidden until the covers are removed.
const spacerGroup = new THREE.Group();
spacerGroup.position.set(1.55, 0.67, 1.76);
toy.add(spacerGroup);
const spacerMat = material(
0xff8426,
{
roughness: 0.5,
metalness: 0.08,
emissive: 0xff5a00,
emissiveIntensity: 0.34
}
);
for (let i = 0; i < 10; i++) {
const a = (i / 10) * Math.PI * 2;
addBox(
spacerGroup,
[0.16, 0.16, 0.15],
[Math.cos(a) * 0.31, Math.sin(a) * 0.31, 0],
spacerMat,
[0, 0, a]
);
}
spacerGroup.visible = false;
registerPart("spacer", "MISPLACED SPACER", spacerGroup, "4", [80, -34]);
const state = {
exposed: false,
spacerRemoved: false,
fixed: false,
hovered: null,
run: null,
elapsed: 0
};
const statusEl = document.getElementById("status");
const modeText = document.getElementById("modeText");
const modeBadge = document.getElementById("modeBadge");
const instructionEl = document.getElementById("instruction");
const progressFill = document.getElementById("progressFill");
const progressText = document.getElementById("progressText");
const repairButton = document.getElementById("repairButton");
const testButton = document.getElementById("testButton");
const toastEl = document.getElementById("toast");
let toastTimer;
function toast(message) {
toastEl.textContent = message;
toastEl.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toastEl.classList.remove("show"), 2700);
}
function updateUI() {
const removedNearby = ["hubcap", "fender", "keeper"]
.filter((id) => parts.get(id).removed).length;
for (const id of partOrder) {
const part = parts.get(id);
const row = document.getElementById(`step-${id}`);
const stateLabel = row.querySelector(".step-state");
row.classList.toggle("done", part.removed && !(id === "spacer" && !state.fixed));
row.classList.remove("exposed", "removing");
if (id === "spacer") {
if (state.spacerRemoved && !state.fixed) {
row.classList.add("removing");
stateLabel.textContent = "OUT";
} else if (state.fixed) {
stateLabel.textContent = "REMOVED";
} else if (state.exposed) {
row.classList.add("exposed");
stateLabel.textContent = "VISIBLE";
} else {
stateLabel.textContent = "HIDDEN";
}
} else {
stateLabel.textContent = part.removed ? "REMOVED" : "OPEN";
}
}
const completed = removedNearby + (state.fixed ? 1 : 0);
progressFill.style.width = `${completed * 25}%`;
progressText.textContent = `${completed}/4`;
statusEl.classList.remove("ok", "found");
if (state.fixed) {
statusEl.textContent = "Rotation restored";
statusEl.classList.add("ok");
instructionEl.textContent =
"The spacer is out. The axle is clear, the wheel is turning, and the wind-up toy is rolling.";
modeText.textContent = "Repair complete";
modeBadge.classList.add("repaired");
testButton.textContent = "Wind up again";
} else if (state.spacerRemoved) {
statusEl.textContent = "Spacer removed";
instructionEl.textContent = "The obstruction is clear. The wheel is ready to turn again.";
modeText.textContent = "Final check";
} else if (state.exposed) {
statusEl.textContent = "Obstruction visible";
statusEl.classList.add("found");
instructionEl.textContent =
"The orange ring is the misplaced spacer. Click it, or use the button below, to pull it out.";
modeText.textContent = "Cause identified";
} else if (removedNearby > 0) {
statusEl.textContent = `Clearing ${removedNearby}/3`;
instructionEl.textContent =
removedNearby === 1
? "One cover is off. The fender and axle keeper still obstruct the contact area."
: "Two covers are off. Remove the final nearby part to expose the axle contact.";
modeText.textContent = "Inspection in progress";
} else {
statusEl.textContent = "Wheel locked";
instructionEl.textContent =
"The front wheel cannot turn. Remove the nearby covers one at a time to expose the contact area.";
modeText.textContent = "Inspection in progress";
}
repairButton.hidden = !state.exposed || state.spacerRemoved;
}
const tweens = [];
function isActuallyVisible(object) {
let current = object;
while (current) {
if (!current.visible) return false;
current = current.parent;
}
return true;
}
function setHover(part) {
const nextId = part?.id ?? null;
if (state.hovered === nextId) return;
const previous = state.hovered ? parts.get(state.hovered) : null;
if (previous && !previous.removed) {
for (const mat of previous.materials) {
if (previous.id === "spacer") {
mat.emissive.setHex(0xff5a00);
mat.emissiveIntensity = 0.34;
} else {
mat.emissive.setHex(0x000000);
mat.emissiveIntensity = 0;
}
}
}
state.hovered = nextId;
if (part && !part.removed) {
for (const mat of part.materials) {
mat.emissive.setHex(part.id === "spacer" ? 0xff7a13 : 0x20c8e1);
mat.emissiveIntensity = part.id === "spacer" ? 0.62 : 0.38;
}
}
}
const destinations = {
hubcap: { x: -4.75, y: 0.2, z: 2.68, scale: 0.66 },
fender: { x: -3.48, y: 0.24, z: 2.7, scale: 0.36 },
keeper: { x: -2.48, y: 0.2, z: 2.72, scale: 0.62 },
spacer: { x: -1.48, y: 0.2, z: 2.7, scale: 0.72 }
};
function removePart(part) {
if (!part || part.removed) return;
if (part.id === "spacer" && !state.exposed) return;
setHover(null);
part.removed = true;
if (part.id === "spacer") {
state.spacerRemoved = true;
}
const startPosition = new THREE.Vector3();
const startQuaternion = new THREE.Quaternion();
const startScale = new THREE.Vector3();
part.group.getWorldPosition(startPosition);
part.group.getWorldQuaternion(startQuaternion);
part.group.getWorldScale(startScale);
scene.attach(part.group);
const destination = destinations[part.id];
const endPosition = new THREE.Vector3(destination.x, destination.y, destination.z);
const endScale = new THREE.Vector3(destination.scale, destination.scale, destination.scale);
const endQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0, part.id === "fender" ? 0.55 : 0, part.id === "keeper" ? 0.2 : 0)
);
tweens.push({
object: part.group,
elapsed: 0,
duration: part.id === "fender" ? 0.9 : 0.76,
startPosition,
endPosition,
startQuaternion,
endQuaternion,
startScale,
endScale,
onComplete: () => {
part.group.visible = false;
if (part.id === "spacer") {
state.fixed = true;
updateUI();
toast("Spacer removed — the wheel is turning and the toy is rolling.");
startRun(true);
}
}
});
updateUI();
if (part.id !== "spacer") {
const remaining = ["hubcap", "fender", "keeper"].filter(
(id) => !parts.get(id).removed
).length;
if (remaining === 0) {
state.exposed = true;
spacerGroup.visible = true;
spacerGroup.scale.setScalar(0.72);
updateUI();
toast("Contact area exposed: an orange spacer is jammed against the axle.");
} else {
toast(`${part.name.toLowerCase()} removed. ${remaining} nearby part${remaining === 1 ? "" : "s"} left.`);
}
}
}
function restorePart(part) {
if (part.group.parent) part.group.parent.remove(part.group);
part.home.parent.add(part.group);
part.group.position.copy(part.home.position);
part.group.quaternion.copy(part.home.quaternion);
part.group.scale.copy(part.home.scale);
part.group.visible = true;
part.removed = false;
}
function resetRepair() {
tweens.length = 0;
state.exposed = false;
state.spacerRemoved = false;
state.fixed = false;
state.run = null;
setHover(null);
for (const part of parts.values()) restorePart(part);
spacerGroup.visible = false;
spacerGroup.scale.setScalar(1);
toy.position.set(0, 0, 0);
toy.rotation.set(0, 0, 0);
keyRotor.rotation.set(0, 0, 0);
for (const wheel of wheels) wheel.rotation.z = 0;
updateUI();
toast("Repair reset. Start by removing the nearby wheel covers.");
}
function startRun(auto = false) {
if (!state.fixed) {
state.run = {
mode: "blocked",
elapsed: 0,
duration: 1.35,
startX: toy.position.x
};
toast("The key turns, but the wheel only twitches. The axle is still obstructed.");
return;
}
state.run = {
mode: "drive",
elapsed: 0,
duration: 4.8,
startX: toy.position.x,
targetX: auto ? 2.45 : Math.min(4.8, toy.position.x + 1.75)
};
}
repairButton.addEventListener("click", () => removePart(parts.get("spacer")));
testButton.addEventListener("click", () => startRun(false));
document.getElementById("resetButton").addEventListener("click", resetRepair);
// Direct camera controls: no addons.
const cameraTarget = new THREE.Vector3(0.15, 1.05, 0.2);
let cameraYaw = 0.61;
let cameraPitch = 0.48;
let cameraDistance = 11.3;
let pointerDown = false;
let pointerMoved = false;
let startPointerX = 0;
let startPointerY = 0;
let lastPointerX = 0;
let lastPointerY = 0;
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);
}
function resetCamera() {
cameraYaw = 0.61;
cameraPitch = 0.48;
cameraDistance = 11.3;
updateCamera();
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function partAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(scene.children, true);
for (const hit of hits) {
if (!isActuallyVisible(hit.object)) continue;
let current = hit.object;
let partId = null;
while (current) {
if (current.userData.partId) {
partId = current.userData.partId;
break;
}
current = current.parent;
}
if (!partId) continue;
const part = parts.get(partId);
if (!part || part.removed) continue;
if (partId === "spacer" && !state.exposed) continue;
return part;
}
return null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
pointerMoved = false;
startPointerX = lastPointerX = event.clientX;
startPointerY = lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
const totalX = event.clientX - startPointerX;
const totalY = event.clientY - startPointerY;
if (Math.hypot(totalX, totalY) > 4) pointerMoved = true;
if (pointerMoved) {
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.005, 0.18, 1.02);
updateCamera();
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else {
setHover(partAt(event.clientX, event.clientY));
renderer.domElement.style.cursor = state.hovered ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerMoved) {
const selected = partAt(event.clientX, event.clientY);
if (selected) removePart(selected);
}
pointerDown = false;
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch {}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerDown) setHover(null);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.008,
7.2,
16.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetRepair();
});
// Projected HTML labels.
const projected = new THREE.Vector3();
function updateLabels() {
for (const id of partOrder) {
const part = parts.get(id);
if (part.removed || (id === "spacer" && !state.exposed)) {
part.label.style.display = "none";
continue;
}
part.group.getWorldPosition(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
if (!visible) {
part.label.style.display = "none";
continue;
}
const x = (projected.x * 0.5 + 0.5) * innerWidth + part.offset[0];
const y = (-projected.y * 0.5 + 0.5) * innerHeight + part.offset[1];
part.label.style.left = `${x}px`;
part.label.style.top = `${y}px`;
part.label.style.display = "flex";
part.label.classList.toggle("active", state.hovered === id);
}
}
function updateTweens(dt) {
for (let i = tweens.length - 1; i >= 0; i--) {
const tween = tweens[i];
tween.elapsed += dt;
const p = THREE.MathUtils.clamp(tween.elapsed / tween.duration, 0, 1);
const eased = 1 - Math.pow(1 - p, 3);
tween.object.position.lerpVectors(tween.startPosition, tween.endPosition, eased);
tween.object.position.y += Math.sin(Math.PI * p) * 0.85;
tween.object.quaternion.slerpQuaternions(
tween.startQuaternion,
tween.endQuaternion,
eased
);
tween.object.scale.lerpVectors(tween.startScale, tween.endScale, eased);
if (p >= 1) {
tween.object.position.copy(tween.endPosition);
tween.object.scale.copy(tween.endScale);
tween.onComplete?.();
tweens.splice(i, 1);
}
}
}
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
state.elapsed += dt;
updateTweens(dt);
if (state.run) {
const run = state.run;
run.elapsed += dt;
const p = THREE.MathUtils.clamp(run.elapsed / run.duration, 0, 1);
if (run.mode === "blocked") {
focusWheel.rotation.z = Math.sin(run.elapsed * 31) * 0.055;
toy.position.x = run.startX + Math.sin(run.elapsed * 25) * 0.024;
keyRotor.rotation.x -= dt * 11;
} else {
const eased = 1 - Math.pow(1 - p, 3);
toy.position.x = THREE.MathUtils.lerp(run.startX, run.targetX, eased);
toy.position.y = Math.abs(Math.sin(run.elapsed * 8.5)) * 0.018;
keyRotor.rotation.x -= dt * (run.elapsed < 1.35 ? 12 : 5 * (1 - p));
}
if (p >= 1) {
if (run.mode === "blocked") {
toy.position.x = run.startX;
focusWheel.rotation.z = 0;
}
toy.position.y = 0;
state.run = null;
}
} else if (!state.fixed) {
focusWheel.rotation.z = Math.sin(state.elapsed * 1.7) * 0.009;
}
if (state.fixed) {
for (const wheel of wheels) wheel.rotation.z = -toy.position.x / 0.64;
}
if (state.exposed && !state.spacerRemoved) {
const pulse = 0.38 + Math.sin(state.elapsed * 4.4) * 0.18;
for (const mat of parts.get("spacer").materials) {
mat.emissiveIntensity = pulse;
}
spacerGroup.scale.setScalar(
THREE.MathUtils.lerp(
spacerGroup.scale.x,
1,
1 - Math.pow(0.001, dt)
)
);
}
updateLabels();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
updateUI();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```