Prompt specification
Build or customize the Three.js 3D scene "Reassemble-and-test learning game" 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: Reassemble-and-test learning game
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reassemble-and-test-learning-game-x0260
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts wind-up toy diagnosis and repair. Build a modular toy mechanism with an ordered disassembly record; users restore components and run a motion test that identifies the first remaining blocked connection. Low-poly.
Working Three.js Starter (reassemble-and-test-learning-game-x0260):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Clockwork Repair Bay</title>
<style>
:root {
--ink: #243039;
--muted: #6f7778;
--paper: rgba(247, 243, 234, 0.92);
--line: rgba(36, 48, 57, 0.14);
--teal: #287c78;
--teal-light: #d9ebe5;
--coral: #d65e4b;
--coral-light: #f7dfd8;
--amber: #d69b32;
--amber-light: #f7ebcc;
--shadow: 0 16px 45px rgba(46, 40, 31, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e0d4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 0;
left: 0;
right: 0;
height: 78px;
padding: 0 24px;
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
background: linear-gradient(
180deg,
rgba(248, 245, 237, 0.96),
rgba(248, 245, 237, 0.82)
);
border-bottom: 1px solid var(--line);
backdrop-filter: blur(14px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
color: white;
background: var(--ink);
border-radius: 11px;
flex: 0 0 auto;
}
.brand-mark svg {
width: 24px;
height: 24px;
}
.brand strong {
display: block;
font-size: 14px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.brand span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
}
.unit-pill {
justify-self: center;
padding: 8px 13px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
background: rgba(255, 255, 255, 0.45);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.top-status {
justify-self: end;
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 5px rgba(214, 155, 50, 0.12);
}
.panel {
position: fixed;
z-index: 10;
top: 96px;
bottom: 22px;
overflow: auto;
padding: 18px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 20px;
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(36, 48, 57, 0.22) transparent;
}
.parts-panel {
left: 22px;
width: 302px;
}
.diagnostic-panel {
right: 22px;
width: 346px;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
h2 {
margin-bottom: 0;
font-size: 20px;
line-height: 1.1;
letter-spacing: -0.03em;
}
.count {
padding: 6px 9px;
border-radius: 8px;
background: var(--amber-light);
color: #8a641f;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
white-space: nowrap;
text-transform: uppercase;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 18px 2px 9px;
color: var(--muted);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.parts-list,
.connection-list,
.record-list {
display: grid;
gap: 7px;
margin: 0;
padding: 0;
list-style: none;
}
.part-button {
width: 100%;
display: grid;
grid-template-columns: 39px 1fr auto;
align-items: center;
gap: 10px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.56);
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
transform 140ms ease,
border-color 140ms ease,
background 140ms ease;
}
.part-button:hover {
transform: translateX(2px);
border-color: rgba(40, 124, 120, 0.42);
background: white;
}
.part-button:active {
transform: translateX(2px) scale(0.99);
}
.part-code {
display: grid;
place-items: center;
height: 34px;
border-radius: 9px;
background: #edf0ec;
color: #687172;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
font-weight: 800;
}
.part-name {
display: block;
font-size: 12px;
font-weight: 800;
}
.part-meta {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.part-state {
display: flex;
align-items: center;
gap: 6px;
color: var(--teal);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.part-state::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
}
.part-button.staged {
border-color: rgba(214, 155, 50, 0.35);
background: rgba(247, 235, 204, 0.7);
}
.part-button.staged .part-state,
.part-button.staged .part-code {
color: #9a6c18;
}
.part-button.fixed {
opacity: 0.68;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
.actions .wide {
grid-column: 1 / -1;
}
.btn {
min-height: 39px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.62);
color: var(--ink);
font-size: 11px;
font-weight: 850;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
opacity 140ms ease;
}
.btn:hover:not(:disabled) {
transform: translateY(-1px);
background: white;
}
.btn:active:not(:disabled) {
transform: translateY(0);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.42;
}
.btn.primary {
border-color: var(--teal);
background: var(--teal);
color: white;
box-shadow: 0 7px 18px rgba(40, 124, 120, 0.2);
}
.btn.primary:hover:not(:disabled) {
background: #226e6a;
}
.btn.danger {
color: #a34434;
}
.connection-list {
gap: 4px;
}
.connection-row {
display: grid;
grid-template-columns: 31px 1fr auto;
align-items: center;
gap: 9px;
padding: 8px 9px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.42);
border: 1px solid transparent;
}
.connection-row.blocked {
border-color: rgba(214, 94, 75, 0.28);
background: var(--coral-light);
}
.connection-row.waiting {
opacity: 0.52;
}
.connection-code {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 900;
color: var(--muted);
}
.connection-name {
font-size: 10px;
font-weight: 800;
line-height: 1.25;
}
.connection-state {
font-size: 8px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
color: var(--teal);
}
.connection-row.blocked .connection-state {
color: var(--coral);
}
.test-card {
margin-top: 13px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.58);
}
.test-card.running {
border-color: rgba(40, 124, 120, 0.35);
}
.test-card.pass {
border-color: rgba(40, 124, 120, 0.38);
background: var(--teal-light);
}
.test-card.fail {
border-color: rgba(214, 94, 75, 0.35);
background: var(--coral-light);
}
.test-topline {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 6px;
}
.test-state {
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.result-code {
color: var(--teal);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
font-weight: 900;
}
.test-card h3 {
margin-bottom: 5px;
font-size: 15px;
line-height: 1.2;
}
.test-card p {
margin-bottom: 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.test-card .btn {
width: 100%;
}
.record-list {
gap: 0;
border-left: 1px solid rgba(36, 48, 57, 0.15);
margin-left: 10px;
padding-left: 13px;
}
.record-item {
position: relative;
padding: 0 0 13px;
}
.record-item::before {
content: "";
position: absolute;
top: 4px;
left: -17px;
width: 7px;
height: 7px;
border: 2px solid var(--paper);
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 1px rgba(36, 48, 57, 0.12);
}
.record-item.refitted::before {
background: var(--teal);
}
.record-head {
display: flex;
justify-content: space-between;
gap: 10px;
}
.record-name {
font-size: 11px;
font-weight: 850;
}
.record-time {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.record-note {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.record-state {
display: inline-block;
margin-top: 4px;
color: #9a6c18;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.record-item.refitted .record-state {
color: var(--teal);
}
.reset-button {
width: 100%;
margin-top: 5px;
}
.scene-hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
background: rgba(36, 48, 57, 0.72);
color: white;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(8px);
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
top: 92px;
max-width: min(440px, calc(100vw - 32px));
transform: translate(-50%, -12px);
padding: 11px 15px;
border-radius: 10px;
background: var(--ink);
color: white;
box-shadow: 0 10px 28px rgba(36, 48, 57, 0.25);
font-size: 11px;
font-weight: 700;
text-align: center;
opacity: 0;
pointer-events: none;
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#tooltip {
position: fixed;
z-index: 25;
display: none;
padding: 7px 9px;
border-radius: 8px;
background: rgba(36, 48, 57, 0.92);
color: white;
font-size: 10px;
font-weight: 750;
pointer-events: none;
white-space: nowrap;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #e8e0d4;
color: var(--ink);
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
text-align: center;
}
.loader-gear {
width: 42px;
height: 42px;
margin: 0 auto 14px;
border: 8px dotted var(--teal);
border-radius: 50%;
animation: spin 1.4s linear infinite;
}
.loader span {
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 980px) {
.parts-panel {
width: 270px;
left: 12px;
}
.diagnostic-panel {
width: 300px;
right: 12px;
}
.unit-pill {
display: none;
}
.topbar {
grid-template-columns: 1fr 1fr;
}
}
@media (max-width: 720px) {
.topbar {
height: 66px;
padding: 0 13px;
}
.brand span,
.top-status span:last-child {
display: none;
}
.parts-panel {
display: none;
}
.diagnostic-panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 44vh;
padding: 14px;
}
.scene-hint {
bottom: calc(44vh + 22px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D wind-up toy repair scene"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M12 2.7v3M12 18.3v3M2.7 12h3M18.3 12h3M5.2 5.2l2.1 2.1M16.7 16.7l2.1 2.1M18.8 5.2l-2.1 2.1M7.3 16.7l-2.1 2.1"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
<circle cx="12" cy="12" r="5.2" stroke="currentColor" stroke-width="1.8"/>
<circle cx="12" cy="12" r="1.7" fill="currentColor"/>
</svg>
</div>
<div>
<strong>Clockwork Repair Bay</strong>
<span>Modular mechanism service terminal</span>
</div>
</div>
<div class="unit-pill">Milo M-08 · Bench 03</div>
<div class="top-status">
<span class="status-dot"></span>
<span id="headerStatus">1 component staged</span>
</div>
</header>
<aside class="panel parts-panel" aria-label="Assembly components">
<div class="panel-heading">
<div>
<p class="eyebrow">Repair order</p>
<h2>Assembly map</h2>
</div>
<div class="count" id="progressText">6 / 7</div>
</div>
<div class="section-title">
<span>Components</span>
<span>Click to inspect</span>
</div>
<ul class="parts-list" id="partsList"></ul>
<div class="actions">
<button class="btn" id="teardownBtn">Continue teardown</button>
<button class="btn" id="restoreNextBtn">Restore next</button>
<button class="btn wide" id="restoreAllBtn">Restore all staged parts</button>
</div>
</aside>
<aside class="panel diagnostic-panel" aria-label="Diagnostic and disassembly record">
<div class="panel-heading">
<div>
<p class="eyebrow">Torque path</p>
<h2>Connection test</h2>
</div>
<div class="count" id="connectionCount">5 linked</div>
</div>
<ul class="connection-list" id="connectionList"></ul>
<section class="test-card" id="testCard" aria-live="polite">
<div class="test-topline">
<span class="test-state" id="testState">Ready for test</span>
<span class="result-code" id="resultCode">C-03</span>
</div>
<h3 id="resultTitle">One coupling is open</h3>
<p id="resultBody">
The output gear is staged on the service bench. Refit it to complete the torque path.
</p>
<button class="btn primary" id="runTestBtn">Run motion test</button>
</section>
<div class="section-title">
<span>Ordered disassembly record</span>
<span>Newest last</span>
</div>
<ol class="record-list" id="recordList"></ol>
<button class="btn danger reset-button" id="resetBtn">Reset repair ticket</button>
</aside>
<div class="scene-hint">Drag to orbit · Scroll to zoom · Click a component</div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="tooltip"></div>
<div id="loading">
<div class="loader">
<div class="loader-gear"></div>
<span>Preparing repair bay</span>
</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 $ = (selector) => document.querySelector(selector);
const canvas = $("#scene");
const toastElement = $("#toast");
const tooltip = $("#tooltip");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e0d4);
scene.fog = new THREE.Fog(0xe8e0d4, 10, 24);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
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.08;
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 1.28, 0);
let cameraYaw = 0.58;
let cameraPitch = 0.39;
let cameraRadius = 7.4;
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.sin(cameraPitch),
cameraTarget.z + horizontal * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff7e8, 0x776c5b, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 3.4);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9fc9cf, 1.4);
fillLight.position.set(-5, 4, -3);
scene.add(fillLight);
const materials = {
navy: new THREE.MeshStandardMaterial({
color: 0x34434b,
roughness: 0.72,
metalness: 0.12,
flatShading: true
}),
teal: new THREE.MeshStandardMaterial({
color: 0x3f8c88,
roughness: 0.65,
metalness: 0.12,
flatShading: true
}),
tealDark: new THREE.MeshStandardMaterial({
color: 0x276663,
roughness: 0.72,
metalness: 0.1,
flatShading: true
}),
coral: new THREE.MeshStandardMaterial({
color: 0xd9614d,
roughness: 0.66,
metalness: 0.08,
flatShading: true
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xe0ad43,
roughness: 0.62,
metalness: 0.1,
flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xe8ddc3,
roughness: 0.8,
flatShading: true
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x293239,
roughness: 0.9,
flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0x8c999a,
roughness: 0.4,
metalness: 0.55,
flatShading: true
}),
white: new THREE.MeshStandardMaterial({
color: 0xf6f0df,
roughness: 0.68,
flatShading: true
})
};
function mesh(geometry, material, parent, position = [0, 0, 0]) {
const object = new THREE.Mesh(geometry, material);
object.position.set(...position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function rod(parent, a, b, radius, material, sides = 8) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const geometry = new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
sides
);
const object = mesh(geometry, material, parent);
object.position.copy(start).add(end).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
return object;
}
const workbench = mesh(
new THREE.PlaneGeometry(32, 32),
new THREE.MeshStandardMaterial({
color: 0xc8bba7,
roughness: 0.95,
flatShading: true
}),
scene
);
workbench.rotation.x = -Math.PI / 2;
workbench.position.y = -0.025;
workbench.castShadow = false;
const tray = mesh(
new THREE.CylinderGeometry(1.72, 1.82, 0.07, 8),
new THREE.MeshStandardMaterial({
color: 0x9faea8,
roughness: 0.88,
flatShading: true
}),
scene,
[1.85, 0.01, 0.45]
);
tray.castShadow = false;
const PARTS = [
{ id: "key", code: "K-01", name: "Winding key", short: "Key" },
{ id: "barrel", code: "S-02", name: "Spring barrel", short: "Barrel" },
{ id: "drive", code: "G-03", name: "Drive gear", short: "Drive gear" },
{ id: "output", code: "G-04", name: "Output gear", short: "Output gear" },
{ id: "axle", code: "X-05", name: "Output axle", short: "Axle" },
{ id: "chassis", code: "C-06", name: "Toy chassis", short: "Chassis" },
{ id: "base", code: "B-07", name: "Service base", short: "Base" }
];
const PART_BY_ID = Object.fromEntries(PARTS.map((part) => [part.id, part]));
const CONNECTIONS = [
{
code: "C-01",
name: "Winding key → Spring barrel",
required: ["key", "barrel"],
position: [-0.03, 0.72, 0.43]
},
{
code: "C-02",
name: "Spring barrel → Drive gear",
required: ["barrel", "drive"],
position: [-0.18, 0.86, 0.42]
},
{
code: "C-03",
name: "Drive gear → Output gear",
required: ["drive", "output"],
position: [0, 1.16, 0.47]
},
{
code: "C-04",
name: "Output gear → Output axle",
required: ["output", "axle"],
position: [0, 1.32, 0.28]
},
{
code: "C-05",
name: "Output axle → Chassis",
required: ["axle", "chassis"],
position: [0, 0.71, 0.11]
},
{
code: "C-06",
name: "Chassis → Service base",
required: ["chassis", "base"],
position: [0, 0.19, 0.2]
}
];
const TEARDOWN_ORDER = [
"output",
"drive",
"axle",
"barrel",
"key",
"chassis"
];
const components = {};
const interactiveMeshes = [];
function createComponent({
id,
home,
park = home,
homeRotation = [0, 0, 0],
parkRotation = [0, 0, 0],
build
}) {
const group = new THREE.Group();
const visual = new THREE.Group();
group.position.set(...home);
group.rotation.set(...homeRotation);
group.add(visual);
scene.add(group);
build(visual);
visual.traverse((child) => {
if (child.isMesh) {
child.userData.component = id;
interactiveMeshes.push(child);
}
});
components[id] = {
id,
group,
visual,
home: new THREE.Vector3(...home),
park: new THREE.Vector3(...park),
homeQuaternion: new THREE.Quaternion().setFromEuler(
new THREE.Euler(...homeRotation)
),
parkQuaternion: new THREE.Quaternion().setFromEuler(
new THREE.Euler(...parkRotation)
)
};
}
function buildGear(parent, radius, colorMaterial, toothCount = 12) {
mesh(
new THREE.CylinderGeometry(radius * 0.78, radius * 0.78, 0.15, 12),
colorMaterial,
parent
);
const toothGeometry = new THREE.BoxGeometry(0.18, 0.15, 0.14);
for (let i = 0; i < toothCount; i++) {
const angle = (i / toothCount) * Math.PI * 2;
const tooth = mesh(
toothGeometry,
colorMaterial,
parent,
[
Math.cos(angle) * radius * 0.87,
0,
Math.sin(angle) * radius * 0.87
]
);
tooth.rotation.y = -angle;
}
mesh(
new THREE.CylinderGeometry(radius * 0.23, radius * 0.23, 0.22, 10),
materials.steel,
parent
);
mesh(
new THREE.CylinderGeometry(radius * 0.09, radius * 0.09, 0.25, 8),
materials.rubber,
parent
);
}
createComponent({
id: "base",
home: [0, 0, 0],
build(parent) {
mesh(
new THREE.CylinderGeometry(1.02, 1.12, 0.15, 8),
materials.tealDark,
parent,
[0, 0.075, 0]
);
mesh(
new THREE.CylinderGeometry(0.87, 0.92, 0.07, 8),
materials.teal,
parent,
[0, 0.18, 0]
);
for (let i = 0; i < 4; i++) {
const angle = (i / 4) * Math.PI * 2 + Math.PI / 4;
mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.04, 8),
materials.steel,
parent,
[Math.cos(angle) * 0.78, 0.225, Math.sin(angle) * 0.78]
);
}
}
});
let chassisBody;
let leftArm;
let rightArm;
let headPivot;
createComponent({
id: "chassis",
home: [0, 0, 0],
park: [0, 0.14, -2.35],
parkRotation: [0, -0.22, 0],
build(parent) {
chassisBody = new THREE.Group();
parent.add(chassisBody);
for (const x of [-0.35, 0.35]) {
mesh(
new THREE.BoxGeometry(0.42, 0.2, 0.64),
materials.rubber,
chassisBody,
[x, 0.31, 0.06]
);
rod(
chassisBody,
[x, 0.4, 0.02],
[x, 0.83, -0.02],
0.09,
materials.tealDark
);
}
mesh(
new THREE.BoxGeometry(0.9, 0.22, 0.46),
materials.tealDark,
chassisBody,
[0, 0.86, -0.02]
);
mesh(
new THREE.BoxGeometry(0.95, 0.94, 0.13),
materials.tealDark,
chassisBody,
[0, 1.39, -0.25]
);
for (const x of [-0.53, 0.53]) {
rod(
chassisBody,
[x, 1.05, -0.17],
[x, 1.87, -0.17],
0.07,
materials.steel,
6
);
}
rod(
chassisBody,
[-0.53, 1.87, -0.17],
[0.53, 1.87, -0.17],
0.075,
materials.steel,
6
);
leftArm = new THREE.Group();
rightArm = new THREE.Group();
leftArm.position.set(-0.61, 1.82, -0.11);
rightArm.position.set(0.61, 1.82, -0.11);
chassisBody.add(leftArm, rightArm);
for (const arm of [leftArm, rightArm]) {
rod(arm, [0, 0, 0], [0, -0.35, 0], 0.075, materials.cream, 6);
mesh(
new THREE.SphereGeometry(0.11, 8, 6),
materials.steel,
arm,
[0, -0.39, 0]
);
}
rod(
chassisBody,
[0, 1.91, -0.16],
[0, 2.12, -0.16],
0.06,
materials.steel,
6
);
headPivot = new THREE.Group();
headPivot.position.set(0, 2.1, -0.12);
chassisBody.add(headPivot);
mesh(
new THREE.BoxGeometry(0.91, 0.68, 0.66),
materials.cream,
headPivot
);
mesh(
new THREE.BoxGeometry(0.72, 0.38, 0.045),
materials.navy,
headPivot,
[0, 0.03, 0.35]
);
for (const x of [-0.18, 0.18]) {
mesh(
new THREE.SphereGeometry(0.055, 8, 6),
materials.yellow,
headPivot,
[x, 0.06, 0.39]
);
}
mesh(
new THREE.BoxGeometry(0.18, 0.025, 0.025),
materials.coral,
headPivot,
[0, -0.1, 0.39]
);
rod(
headPivot,
[0, 0.34, 0],
[0, 0.61, 0],
0.025,
materials.navy,
6
);
mesh(
new THREE.SphereGeometry(0.07, 8, 6),
materials.coral,
headPivot,
[0, 0.64, 0]
);
}
});
createComponent({
id: "axle",
home: [0, 1.05, 0.16],
park: [1.7, 0.26, -0.2],
parkRotation: [Math.PI / 2, 0.2, 0],
build(parent) {
mesh(
new THREE.CylinderGeometry(0.065, 0.065, 1.12, 8),
materials.steel,
parent
);
mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.16, 8),
materials.navy,
parent
);
mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.12, 8),
materials.yellow,
parent,
[0, 0.39, 0]
);
}
});
createComponent({
id: "drive",
home: [0, 0.98, 0.43],
park: [2.45, 0.26, 0.65],
parkRotation: [0.05, 0.3, -0.08],
build(parent) {
buildGear(parent, 0.48, materials.teal, 12);
}
});
createComponent({
id: "output",
home: [0, 1.32, 0.43],
park: [1.42, 0.26, 0.65],
parkRotation: [0.05, -0.3, 0.08],
build(parent) {
buildGear(parent, 0.39, materials.coral, 10);
mesh(
new THREE.CylinderGeometry(0.09, 0.09, 0.3, 8),
materials.steel,
parent
);
}
});
createComponent({
id: "barrel",
home: [-0.46, 0.71, 0.41],
park: [2.45, 0.27, -0.35],
parkRotation: [0, 0, Math.PI / 2],
build(parent) {
const shell = mesh(
new THREE.CylinderGeometry(0.25, 0.25, 0.66, 10),
materials.yellow,
parent
);
shell.rotation.z = Math.PI / 2;
for (const x of [-0.26, -0.13, 0, 0.13, 0.26]) {
const ring = mesh(
new THREE.TorusGeometry(0.21, 0.018, 5, 12),
materials.steel,
parent,
[x, 0, 0]
);
ring.rotation.y = Math.PI / 2;
}
const marker = mesh(
new THREE.BoxGeometry(0.58, 0.035, 0.07),
materials.coral,
parent,
[0, 0.24, 0]
);
marker.rotation.z = Math.PI / 2;
}
});
createComponent({
id: "key",
home: [0.39, 0.71, 0.41],
park: [1.42, 0.26, -1.25],
parkRotation: [0, 0.35, 0],
build(parent) {
const shaft = mesh(
new THREE.CylinderGeometry(0.07, 0.07, 0.55, 8),
materials.steel,
parent
);
shaft.rotation.z = Math.PI / 2;
const loop = mesh(
new THREE.TorusGeometry(0.25, 0.075, 6, 12),
materials.coral,
parent,
[0.38, 0, 0]
);
loop.rotation.y = Math.PI / 2;
mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.11, 8),
materials.coral,
parent,
[-0.25, 0, 0]
);
}
});
const connectionMarkers = CONNECTIONS.map((connection) => {
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0x4d9b7d,
emissive: 0x173f34,
emissiveIntensity: 0.28,
roughness: 0.4,
metalness: 0.15
});
const marker = mesh(
new THREE.TorusGeometry(0.115, 0.025, 5, 16),
markerMaterial,
scene,
connection.position
);
marker.castShadow = false;
marker.receiveShadow = false;
return { ...connection, mesh: marker, material: markerMaterial };
});
const state = {
installed: new Set(PARTS.map((part) => part.id)),
detached: new Set(),
record: [],
testRunning: false,
testResult: null,
testStart: 0,
testBlocked: -1,
testToken: 0,
teardownRunning: false,
teardownToken: 0,
sessionStart: performance.now()
};
function initialState() {
state.installed = new Set(PARTS.map((part) => part.id));
state.installed.delete("output");
state.detached = new Set(["output"]);
state.record = [
{
seq: 1,
id: "output",
time: "00:00.0",
note: "Found loose at the output coupling",
status: "staged"
}
];
state.testRunning = false;
state.testResult = null;
state.testBlocked = -1;
state.sessionStart = performance.now();
state.teardownRunning = false;
state.teardownToken++;
}
initialState();
function formatTime(milliseconds) {
const seconds = Math.max(0, milliseconds) / 1000;
const minutes = Math.floor(seconds / 60);
const remainder = seconds - minutes * 60;
return `${String(minutes).padStart(2, "0")}:${remainder
.toFixed(1)
.padStart(4, "0")}`;
}
let toastTimer;
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastElement.classList.remove("show");
}, 2400);
}
function firstBlockedIndex() {
return CONNECTIONS.findIndex((connection) =>
connection.required.some((id) => !state.installed.has(id))
);
}
function connectionState(index, blockedIndex) {
if (blockedIndex === -1) return "linked";
if (index < blockedIndex) return "linked";
if (index === blockedIndex) return "blocked";
return "waiting";
}
function renderParts() {
const list = $("#partsList");
list.replaceChildren();
for (const part of PARTS) {
const fixed = part.id === "base";
const staged = state.detached.has(part.id);
const button = document.createElement("button");
button.className = `part-button${staged ? " staged" : ""}${
fixed ? " fixed" : ""
}`;
button.type = "button";
button.dataset.part = part.id;
const code = document.createElement("span");
code.className = "part-code";
code.textContent = part.code;
const label = document.createElement("span");
const name = document.createElement("span");
name.className = "part-name";
name.textContent = part.name;
const meta = document.createElement("span");
meta.className = "part-meta";
meta.textContent = fixed
? "Fixed fixture"
: staged
? "Available on parts tray"
: "Mounted in mechanism";
label.append(name, meta);
const status = document.createElement("span");
status.className = "part-state";
status.textContent = fixed ? "Fixed" : staged ? "Staged" : "Mounted";
button.append(code, label, status);
button.addEventListener("click", () => inspectPart(part.id));
list.append(button);
}
const mountedCount = state.installed.size;
$("#progressText").textContent = `${mountedCount} / ${PARTS.length}`;
$("#headerStatus").textContent =
state.detached.size === 1
? "1 component staged"
: `${state.detached.size} components staged`;
$("#restoreNextBtn").disabled = state.detached.size === 0;
$("#restoreAllBtn").disabled = state.detached.size === 0;
}
function renderConnections() {
const list = $("#connectionList");
list.replaceChildren();
const blockedIndex = firstBlockedIndex();
CONNECTIONS.forEach((connection, index) => {
const status = connectionState(index, blockedIndex);
const item = document.createElement("li");
item.className = `connection-row ${status}`;
const code = document.createElement("span");
code.className = "connection-code";
code.textContent = connection.code;
const name = document.createElement("span");
name.className = "connection-name";
name.textContent = connection.name;
const stateLabel = document.createElement("span");
stateLabel.className = "connection-state";
stateLabel.textContent = status;
item.append(code, name, stateLabel);
list.append(item);
});
const linkedCount = blockedIndex === -1
? CONNECTIONS.length
: blockedIndex;
$("#connectionCount").textContent =
blockedIndex === -1
? `${linkedCount} linked`
: `${linkedCount} linked · 1 open`;
for (let i = 0; i < connectionMarkers.length; i++) {
const marker = connectionMarkers[i];
const status = connectionState(i, blockedIndex);
const color =
status === "linked"
? 0x4d9b7d
: status === "blocked"
? 0xd65e4b
: 0x9b9d94;
marker.material.color.setHex(color);
marker.material.emissive.setHex(
status === "blocked" ? 0x7a1d12 : status === "linked" ? 0x173f34 : 0x343630
);
marker.material.emissiveIntensity =
status === "blocked" ? 0.55 : 0.24;
}
}
function renderRecord() {
const list = $("#recordList");
list.replaceChildren();
for (const entry of state.record) {
const part = PART_BY_ID[entry.id];
const item = document.createElement("li");
item.className = `record-item${
entry.status === "refitted" ? " refitted" : ""
}`;
const head = document.createElement("div");
head.className = "record-head";
const name = document.createElement("span");
name.className = "record-name";
name.textContent = `${String(entry.seq).padStart(2, "0")} · ${part.name}`;
const time = document.createElement("span");
time.className = "record-time";
time.textContent = entry.time;
head.append(name, time);
const note = document.createElement("div");
note.className = "record-note";
note.textContent = entry.note;
const status = document.createElement("span");
status.className = "record-state";
status.textContent =
entry.status === "refitted" ? "Refitted and verified" : "Awaiting refit";
item.append(head, note, status);
list.append(item);
}
}
function renderTestCard() {
const card = $("#testCard");
card.classList.remove("running", "pass", "fail");
const blockedIndex = firstBlockedIndex();
if (state.testRunning) {
card.classList.add("running");
$("#testState").textContent = "Motion test running";
$("#resultCode").textContent =
blockedIndex === -1 ? "C-01…" : CONNECTIONS[blockedIndex].code;
$("#resultTitle").textContent = "Watching the torque path";
$("#resultBody").textContent =
"The test rig is applying power and checking each coupling in sequence.";
$("#runTestBtn").textContent = "Testing…";
return;
}
$("#runTestBtn").textContent = "Run motion test";
if (state.testResult === "pass") {
card.classList.add("pass");
$("#testState").textContent = "Test passed";
$("#resultCode").textContent = "C-01–06";
$("#resultTitle").textContent = "Full motion confirmed";
$("#resultBody").textContent =
"All six couplings transfer torque. The winding key, spring, gear train, axle, and chassis are correctly seated.";
return;
}
if (state.testResult === "fail") {
card.classList.add("fail");
const connection = CONNECTIONS[blockedIndex];
const missing = connection.required.filter(
(id) => !state.installed.has(id)
);
$("#testState").textContent = "Motion blocked";
$("#resultCode").textContent = connection.code;
$("#resultTitle").textContent = connection.name;
$("#resultBody").textContent =
`Torque stops at this coupling. Refit ${missing
.map((id) => PART_BY_ID[id].name.toLowerCase())
.join(" and ")}, then run the motion test again.`;
return;
}
$("#testState").textContent = "Ready for test";
$("#resultCode").textContent =
blockedIndex === -1 ? "C-01–06" : CONNECTIONS[blockedIndex].code;
$("#resultTitle").textContent =
blockedIndex === -1
? "Torque path appears complete"
: "One coupling is open";
$("#resultBody").textContent =
blockedIndex === -1
? "All required components are mounted. Run the motion test to verify the complete mechanism."
: `The first remaining blocked connection is ${CONNECTIONS[
blockedIndex
].name.toLowerCase()}. Refit the staged component and verify it with a motion test.`;
}
function renderAll() {
renderParts();
renderConnections();
renderRecord();
renderTestCard();
}
function detachPart(id, force = false, note = "Detached in ordered teardown") {
if (id === "base" || state.detached.has(id)) return;
if (!force) {
const next = TEARDOWN_ORDER.find((partId) =>
state.installed.has(partId)
);
if (next !== id) {
showToast(
`Follow the teardown order: detach ${PART_BY_ID[next].name.toLowerCase()} first.`
);
return;
}
}
state.installed.delete(id);
state.detached.add(id);
state.record.push({
seq: state.record.length + 1,
id,
time: formatTime(performance.now() - state.sessionStart),
note,
status: "staged"
});
showToast(`${PART_BY_ID[id].name} moved to the parts tray.`);
renderAll();
}
function restorePart(id) {
if (!state.detached.has(id)) return;
state.detached.delete(id);
state.installed.add(id);
for (let i = state.record.length - 1; i >= 0; i--) {
if (state.record[i].id === id) {
state.record[i].status = "refitted";
state.record[i].note = "Refitted to its indexed position";
break;
}
}
showToast(`${PART_BY_ID[id].name} refitted.`);
renderAll();
}
function inspectPart(id) {
if (id === "base") {
showToast("The service base is a fixed alignment fixture.");
return;
}
if (state.detached.has(id)) {
restorePart(id);
} else {
detachPart(id);
}
}
function restoreNext() {
const latest = [...state.record]
.reverse()
.find((entry) => state.detached.has(entry.id));
if (latest) restorePart(latest.id);
}
function restoreAll() {
const ordered = [...TEARDOWN_ORDER].reverse();
for (const id of ordered) {
if (state.detached.has(id)) restorePart(id);
}
showToast("All staged components have been refitted.");
}
async function autoTeardown() {
if (state.teardownRunning) return;
state.teardownRunning = true;
const token = ++state.teardownToken;
$("#teardownBtn").disabled = true;
$("#teardownBtn").textContent = "Teardown in progress…";
for (const id of TEARDOWN_ORDER) {
if (token !== state.teardownToken) return;
if (state.installed.has(id)) {
detachPart(id, true, "Removed by indexed teardown sequence");
await new Promise((resolve) => setTimeout(resolve, 480));
}
}
state.teardownRunning = false;
$("#teardownBtn").disabled = false;
$("#teardownBtn").textContent = "Continue teardown";
showToast("Ordered teardown complete. The record is ready for review.");
}
async function runMotionTest() {
if (state.testRunning) return;
state.testRunning = true;
state.testResult = null;
state.testStart = performance.now();
state.testBlocked = firstBlockedIndex();
const token = ++state.testToken;
const blocked = state.testBlocked;
const duration = blocked === -1 ? 4200 : 2800;
$("#runTestBtn").disabled = true;
renderTestCard();
await new Promise((resolve) => setTimeout(resolve, duration));
if (token !== state.testToken) return;
state.testRunning = false;
state.testResult = blocked === -1 ? "pass" : "fail";
state.testBlocked = firstBlockedIndex();
$("#runTestBtn").disabled = false;
renderAll();
showToast(
blocked === -1
? "Motion test passed: full torque path confirmed."
: `Motion blocked at ${CONNECTIONS[blocked].code}.`
);
}
$("#runTestBtn").addEventListener("click", runMotionTest);
$("#restoreNextBtn").addEventListener("click", restoreNext);
$("#restoreAllBtn").addEventListener("click", restoreAll);
$("#teardownBtn").addEventListener("click", autoTeardown);
$("#resetBtn").addEventListener("click", () => {
state.testToken++;
state.teardownToken++;
initialState();
renderAll();
showToast("Repair ticket reset to the intake condition.");
});
renderAll();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerDown = new THREE.Vector2();
let pointerIsDown = false;
let pointerMoved = false;
let activePointerId = null;
function setPointer(event) {
pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
}
function pickComponent(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(interactiveMeshes, false);
for (const intersection of intersections) {
if (intersection.object.userData.component) {
return intersection.object.userData.component;
}
}
return null;
}
canvas.addEventListener("pointerdown", (event) => {
pointerIsDown = true;
pointerMoved = false;
activePointerId = event.pointerId;
pointerDown.set(event.clientX, event.clientY);
canvas.setPointerCapture(event.pointerId);
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", (event) => {
if (pointerIsDown && event.pointerId === activePointerId) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.0045,
0.12,
0.92
);
pointerDown.set(event.clientX, event.clientY);
updateCamera();
return;
}
const id = pickComponent(event);
if (id) {
const part = PART_BY_ID[id];
const action =
id === "base"
? "Fixed fixture"
: state.detached.has(id)
? "Click to refit"
: "Click to detach";
tooltip.textContent = `${part.name} · ${action}`;
tooltip.style.left = `${event.clientX + 13}px`;
tooltip.style.top = `${event.clientY + 14}px`;
tooltip.style.display = "block";
canvas.style.cursor = "pointer";
} else {
tooltip.style.display = "none";
canvas.style.cursor = "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
if (!pointerMoved && pointerIsDown) {
const id = pickComponent(event);
if (id) inspectPart(id);
}
pointerIsDown = false;
activePointerId = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerIsDown = false;
activePointerId = null;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
4.7,
10
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraYaw = 0.58;
cameraPitch = 0.39;
cameraRadius = 7.4;
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
let driveAngle = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
for (const component of Object.values(components)) {
const mounted =
component.id === "base" || state.installed.has(component.id);
const targetPosition = mounted ? component.home : component.park;
const targetQuaternion = mounted
? component.homeQuaternion
: component.parkQuaternion;
const blend = 1 - Math.exp(-dt * 6.5);
component.group.position.lerp(targetPosition, blend);
component.group.quaternion.slerp(targetQuaternion, blend);
}
const blockedIndex = firstBlockedIndex();
const allLinked = blockedIndex === -1;
const testElapsed = (now - state.testStart) / 1000;
if (allLinked && (state.testRunning || state.testResult === "pass")) {
const speed = state.testResult === "pass" ? 1.4 : 3.2;
driveAngle += dt * speed;
} else if (state.testRunning && blockedIndex !== -1) {
driveAngle += Math.sin(testElapsed * 16) * dt * 0.65;
} else {
driveAngle += dt * 0.06;
}
components.drive.visual.rotation.y = driveAngle;
components.output.visual.rotation.y = -driveAngle * 1.38;
components.axle.visual.rotation.y = driveAngle * 0.8;
components.barrel.visual.rotation.x = driveAngle * 0.28;
components.key.visual.rotation.x = driveAngle * 2.1;
const activeMotion =
state.testRunning &&
state.testBlocked === -1 &&
state.installed.has("chassis");
const bob = activeMotion ? Math.sin(testElapsed * 7.5) * 0.035 : 0;
chassisBody.position.y = bob;
leftArm.rotation.z =
(activeMotion ? Math.sin(testElapsed * 5.4) * 0.15 : 0) - 0.04;
rightArm.rotation.z =
(activeMotion ? -Math.sin(testElapsed * 5.4) * 0.15 : 0) + 0.04;
headPivot.rotation.y = activeMotion
? Math.sin(testElapsed * 2.5) * 0.12
: 0;
for (let i = 0; i < connectionMarkers.length; i++) {
const marker = connectionMarkers[i];
const status = connectionState(i, blockedIndex);
const baseScale = status === "blocked" ? 1 : 0.86;
if (
status === "blocked" &&
state.testRunning &&
blockedIndex === i
) {
const pulse = 1 + Math.sin(testElapsed * 10) * 0.12;
marker.mesh.scale.setScalar(pulse);
marker.material.emissiveIntensity = 0.7;
} else {
marker.mesh.scale.lerp(
new THREE.Vector3(baseScale, baseScale, baseScale),
1 - Math.exp(-dt * 8)
);
}
}
renderer.render(scene, camera);
}
animate();
setTimeout(() => {
$("#loading").classList.add("hidden");
setTimeout(() => $("#loading").remove(), 300);
}, 250);
</script>
</body>
</html>
```