Prompt specification
Build or customize the Three.js 3D scene "Diagnose before replacing a part" 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: Diagnose before replacing a part
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/diagnose-before-replacing-a-part-x0530
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring repair kiosks and parts matching. Animate an inspection of wheel, axle, and casing; highlight the actual disconnected joint before selecting a replacement, keeping unrelated components unchanged throughout the sequence. Low-poly.
Working Three.js Starter (diagnose-before-replacing-a-part-x0530):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Repair Bay — Inspection & Parts Matching</title>
<style>
:root {
color-scheme: dark;
--bg: #071016;
--panel: rgba(9, 20, 28, 0.88);
--line: rgba(146, 221, 226, 0.22);
--text: #e9f5f3;
--muted: #8ca8ae;
--cyan: #67e4e2;
--amber: #ffbc5c;
--red: #ff685e;
--green: #8ce89c;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
button { font: inherit; }
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
#brand {
position: absolute;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#brandMark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border: 1px solid var(--cyan);
color: var(--cyan);
transform: rotate(45deg);
box-shadow: 0 0 22px rgba(103, 228, 226, 0.15);
}
#brandMark span {
transform: rotate(-45deg);
font-size: 18px;
font-weight: 800;
}
#brand strong {
display: block;
font-size: 14px;
font-weight: 760;
}
#brand small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.2em;
}
#inspection {
position: absolute;
top: 24px;
right: 26px;
width: min(360px, calc(100vw - 52px));
padding: 18px;
border: 1px solid var(--line);
background: linear-gradient(145deg, rgba(15, 31, 40, 0.93), var(--panel));
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(15px);
}
#inspection::before {
content: "";
position: absolute;
top: -1px;
left: -1px;
width: 72px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
#stageTitle {
margin: 8px 0 7px;
font-size: 20px;
line-height: 1.15;
letter-spacing: -0.025em;
}
#stageDetail {
min-height: 44px;
color: #afc3c7;
font-size: 12px;
line-height: 1.55;
}
#checks {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 5px;
margin-top: 15px;
}
.check {
height: 5px;
background: rgba(255, 255, 255, 0.08);
transition: background 180ms ease, box-shadow 180ms ease;
}
.check.done {
background: var(--cyan);
box-shadow: 0 0 9px rgba(103, 228, 226, 0.5);
}
.check.current {
background: var(--amber);
box-shadow: 0 0 9px rgba(255, 188, 92, 0.55);
}
.check.critical {
background: var(--red);
box-shadow: 0 0 9px rgba(255, 104, 94, 0.55);
}
#readouts {
display: flex;
justify-content: space-between;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font: 10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
}
#readouts b { color: var(--text); font-weight: 600; }
#bottom {
position: absolute;
left: 26px;
right: 26px;
bottom: 22px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
}
#timeline {
width: min(620px, calc(100vw - 52px));
padding: 14px 16px 13px;
border: 1px solid var(--line);
background: rgba(8, 19, 26, 0.85);
backdrop-filter: blur(12px);
}
#timelineLabels {
display: flex;
justify-content: space-between;
margin-bottom: 9px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#timelineLabels .active { color: var(--cyan); }
#track {
height: 4px;
overflow: hidden;
background: rgba(255, 255, 255, 0.08);
}
#progress {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--cyan), var(--amber));
box-shadow: 0 0 12px rgba(103, 228, 226, 0.45);
}
#controls {
display: flex;
gap: 8px;
pointer-events: auto;
}
.control {
min-width: 42px;
height: 42px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 0;
background: rgba(8, 19, 26, 0.88);
color: var(--text);
cursor: pointer;
transition: border-color 150ms ease, color 150ms ease, transform 150ms ease;
}
.control:hover {
color: var(--cyan);
border-color: var(--cyan);
transform: translateY(-2px);
}
#hotspots {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.hotspot {
position: absolute;
display: none;
transform: translate(-50%, -100%);
min-width: 120px;
color: var(--text);
text-align: center;
filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.65));
}
.hotspot::after {
content: "";
display: block;
width: 1px;
height: 28px;
margin: 7px auto 0;
background: linear-gradient(var(--cyan), transparent);
}
.hotspot .tag {
padding: 6px 9px;
border: 1px solid rgba(103, 228, 226, 0.5);
background: rgba(6, 18, 24, 0.88);
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.hotspot .sub {
margin-top: 5px;
color: #c0d2d4;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.hotspot.critical .tag {
border-color: rgba(255, 104, 94, 0.8);
color: #ff9189;
box-shadow: 0 0 18px rgba(255, 104, 94, 0.2);
}
.hotspot.critical::after {
background: linear-gradient(var(--red), transparent);
}
.hotspot.match .tag {
border-color: rgba(140, 232, 156, 0.8);
color: var(--green);
box-shadow: 0 0 18px rgba(140, 232, 156, 0.18);
}
#legend {
position: absolute;
left: 26px;
bottom: 118px;
display: flex;
gap: 16px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#legend span::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
background: var(--cyan);
box-shadow: 0 0 8px currentColor;
}
#legend .fault::before { background: var(--red); }
#legend .match::before { background: var(--green); }
@media (max-width: 720px) {
#brand { top: 15px; left: 15px; }
#brand small { display: none; }
#inspection {
top: 68px;
right: 15px;
width: min(320px, calc(100vw - 30px));
padding: 13px;
}
#stageTitle { font-size: 16px; }
#stageDetail { font-size: 11px; }
#bottom { left: 15px; right: 15px; bottom: 14px; }
#timeline { width: calc(100vw - 30px); }
#legend { display: none; }
.control { height: 38px; min-width: 38px; padding: 0 10px; }
}
</style>
</head>
<body>
<div id="ui">
<div id="brand">
<div id="brandMark"><span>R</span></div>
<div>
<strong>Field Repair / Bay 04</strong>
<small>Inspection + automated parts matching</small>
</div>
</div>
<section id="inspection" aria-live="polite">
<div class="eyebrow" id="stageKicker">System ready</div>
<h1 id="stageTitle">Preparing component inspection</h1>
<div id="stageDetail">The drive assembly is staged. Components will be inspected individually before a replacement is selected.</div>
<div id="checks">
<span class="check"></span>
<span class="check"></span>
<span class="check"></span>
<span class="check"></span>
<span class="check"></span>
</div>
<div id="readouts">
<span>MODE <b>AUTO</b></span>
<span>T <b id="timecode">00:00.0</b></span>
<span>DRAG <b>ORBIT</b></span>
</div>
</section>
<div id="hotspots">
<div class="hotspot" id="spotWheel">
<div class="tag">Wheel / W-24</div>
<div class="sub">6-BOLT PATTERN · NOMINAL</div>
</div>
<div class="hotspot" id="spotAxle">
<div class="tag">Axle / A-18</div>
<div class="sub">KEYED SPLINE · CHECK</div>
</div>
<div class="hotspot" id="spotCasing">
<div class="tag">Casing / C-42</div>
<div class="sub">INPUT PORT · CHECK</div>
</div>
<div class="hotspot critical" id="spotJoint">
<div class="tag">Joint J-04 disconnected</div>
<div class="sub">AXLE INPUT ↔ CASING PORT</div>
</div>
<div class="hotspot match" id="spotMatch">
<div class="tag">Replacement matched</div>
<div class="sub">AXLE A-18 · 100% COMPATIBLE</div>
</div>
</div>
<div id="legend">
<span>Inspection field</span>
<span class="fault">Disconnected joint</span>
<span class="match">Matched part</span>
</div>
<div id="bottom">
<div id="timeline">
<div id="timelineLabels">
<span>Overview</span>
<span>Wheel</span>
<span>Axle</span>
<span>Casing</span>
<span>Fault</span>
<span>Match</span>
</div>
<div id="track"><div id="progress"></div></div>
</div>
<div id="controls">
<button class="control" id="pause" aria-label="Pause sequence">Ⅱ</button>
<button class="control" id="replay" aria-label="Replay sequence">↻</button>
<button class="control" id="view" aria-label="Reset camera">⌂</button>
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071016);
scene.fog = new THREE.Fog(0x071016, 18, 34);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
document.body.prepend(renderer.domElement);
const orbit = {
target: new THREE.Vector3(0, 1.05, -0.35),
radius: 15.6,
theta: 0.62,
phi: 1.08
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
applyCamera();
// Direct camera controls: no examples/addons are used.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
orbit.theta -= (event.clientX - pointerX) * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - (event.clientY - pointerY) * 0.005,
0.42,
1.42
);
pointerX = event.clientX;
pointerY = event.clientY;
});
function stopDragging() { dragging = false; }
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
8.5,
24
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
orbit.target.set(0, 1.05, -0.35);
orbit.radius = 15.6;
orbit.theta = 0.62;
orbit.phi = 1.08;
});
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa9dce3, 0x14252b, 1.65));
const keyLight = new THREE.DirectionalLight(0xffefd9, 3.0);
keyLight.position.set(-6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4bc7dc, 1.25);
rimLight.position.set(8, 5, -8);
scene.add(rimLight);
const inspectorLight = new THREE.SpotLight(
0x67e4e2,
0,
12,
Math.PI / 8,
0.65,
1.25
);
inspectorLight.position.set(3, 6, 4);
scene.add(inspectorLight);
scene.add(inspectorLight.target);
const jointLight = new THREE.PointLight(0xff4c43, 0, 4, 2);
jointLight.position.set(-0.25, 1.35, 0.25);
scene.add(jointLight);
// A translucent scanning beam, aligned manually every frame.
const beamMaterial = new THREE.MeshBasicMaterial({
color: 0x67e4e2,
transparent: true,
opacity: 0.07,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending
});
const scanBeam = new THREE.Mesh(
new THREE.CylinderGeometry(0.06, 0.7, 1, 12, 1, true),
beamMaterial
);
scene.add(scanBeam);
// -------------------------------------------------------------------------
// Materials and low-poly helpers
// -------------------------------------------------------------------------
const mat = {
floor: new THREE.MeshStandardMaterial({
color: 0x101d22, roughness: 0.92, metalness: 0.08, flatShading: true
}),
platform: new THREE.MeshStandardMaterial({
color: 0x172a30, roughness: 0.78, metalness: 0.18, flatShading: true
}),
casing: new THREE.MeshStandardMaterial({
color: 0x3f9b94, roughness: 0.55, metalness: 0.36, flatShading: true
}),
casingDark: new THREE.MeshStandardMaterial({
color: 0x214f51, roughness: 0.58, metalness: 0.42, flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0x9fb4b5, roughness: 0.31, metalness: 0.82, flatShading: true
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x26383d, roughness: 0.42, metalness: 0.74, flatShading: true
}),
tire: new THREE.MeshStandardMaterial({
color: 0x151b1d, roughness: 0.93, metalness: 0.02, flatShading: true
}),
orange: new THREE.MeshStandardMaterial({
color: 0xf28b3a, roughness: 0.48, metalness: 0.25, flatShading: true
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xe5b84e, roughness: 0.5, metalness: 0.34, flatShading: true
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x4cd8d4,
emissive: 0x1b8f8d,
emissiveIntensity: 0.4,
roughness: 0.4,
metalness: 0.25,
flatShading: true
}),
red: new THREE.MeshStandardMaterial({
color: 0xff5e53,
emissive: 0xff241a,
emissiveIntensity: 1.2,
roughness: 0.4,
metalness: 0.2,
flatShading: true
}),
white: new THREE.MeshStandardMaterial({
color: 0xcbd9d8, roughness: 0.72, metalness: 0.08, flatShading: true
})
};
function mesh(geometry, material, parent = scene) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, material, parent, x = 0, y = 0, z = 0) {
const object = mesh(new THREE.BoxGeometry(w, h, d), material, parent);
object.position.set(x, y, z);
return object;
}
function cylinderX(radius, length, material, parent, x = 0, y = 0, z = 0, segments = 12) {
const object = mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material,
parent
);
object.rotation.z = Math.PI / 2;
object.position.set(x, y, z);
return object;
}
function cylinderZ(radius, length, material, parent, x = 0, y = 0, z = 0, segments = 12) {
const object = mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material,
parent
);
object.rotation.x = Math.PI / 2;
object.position.set(x, y, z);
return object;
}
// -------------------------------------------------------------------------
// Environment
// -------------------------------------------------------------------------
const floor = mesh(new THREE.PlaneGeometry(40, 40), mat.floor);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const grid = new THREE.GridHelper(36, 36, 0x315057, 0x1a3037);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.35;
scene.add(grid);
const platform = mesh(
new THREE.CylinderGeometry(6.3, 6.65, 0.22, 12),
mat.platform
);
platform.position.set(0, 0.12, -0.3);
platform.receiveShadow = true;
const serviceMat = box(
6.7, 0.045, 3.2,
new THREE.MeshStandardMaterial({
color: 0x20353a,
roughness: 0.92,
metalness: 0.03
}),
scene, 0, 0.255, 0.35
);
serviceMat.receiveShadow = true;
// Painted service markings.
for (let i = 0; i < 6; i++) {
const stripe = box(
0.34, 0.012, 0.1,
new THREE.MeshBasicMaterial({ color: 0xc7a34c }),
scene, -2.85 + i * 1.12, 0.285, 1.78
);
stripe.castShadow = false;
}
// Back-wall blocks and pipes provide depth without distracting from the job.
for (let i = 0; i < 7; i++) {
const column = box(
0.35, 4.5, 0.35,
mat.casingDark,
scene, -7 + i * 2.35, 2.25, -6.2
);
column.castShadow = false;
}
box(15.4, 0.22, 0.25, mat.darkSteel, scene, 0, 3.5, -5.95);
box(15.4, 0.16, 0.22, mat.casingDark, scene, 0, 1.8, -6.02);
// -------------------------------------------------------------------------
// Main casing
// -------------------------------------------------------------------------
const casing = new THREE.Group();
casing.position.set(-1.75, 1.32, 0.25);
scene.add(casing);
const casingBody = mesh(
new THREE.DodecahedronGeometry(1.14, 0),
mat.casing,
casing
);
casingBody.scale.set(1.06, 0.78, 0.78);
box(2.05, 0.28, 1.55, mat.casingDark, casing, 0, -0.75, 0);
box(1.42, 0.16, 1.18, mat.darkSteel, casing, -0.05, 0.67, 0);
// Faceted side cover and fasteners.
const cover = cylinderZ(
0.64, 0.12, mat.casingDark, casing,
0, 0.02, 0.78, 10
);
cover.rotation.x = Math.PI / 2;
const coverCenter = cylinderZ(
0.29, 0.15, mat.steel, casing,
0, 0.02, 0.86, 10
);
coverCenter.rotation.x = Math.PI / 2;
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const bolt = cylinderZ(
0.045, 0.06, mat.steel, casing,
Math.cos(angle) * 0.47,
0.02 + Math.sin(angle) * 0.47,
0.87,
6
);
bolt.rotation.x = Math.PI / 2;
}
// Vent slats.
for (let i = 0; i < 4; i++) {
box(
0.08, 0.38, 0.08,
mat.darkSteel, casing,
-0.57 + i * 0.19, -0.22, 0.87
);
}
// Right-side input socket. Its outer edge is x=-0.37.
const socket = cylinderX(
0.35, 0.30, mat.darkSteel, casing,
1.23, 0.03, 0
);
const socketInner = cylinderX(
0.23, 0.33, mat.black || new THREE.MeshBasicMaterial({ color: 0x071015 }),
casing, 1.24, 0.03, 0
);
socketInner.castShadow = false;
// Spline teeth around the socket.
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const tooth = box(
0.06, 0.055, 0.075,
mat.steel, casing,
1.4,
0.03 + Math.sin(angle) * 0.255,
Math.cos(angle) * 0.255
);
tooth.rotation.x = angle;
}
// Supports hold the exploded assembly in an inspection fixture.
box(0.18, 0.7, 0.18, mat.darkSteel, scene, -2.28, 0.59, 0.02);
box(0.18, 0.7, 0.18, mat.darkSteel, scene, 1.32, 0.59, 0.02);
box(0.6, 0.12, 0.44, mat.casingDark, scene, -2.28, 0.32, 0.02);
box(0.6, 0.12, 0.44, mat.casingDark, scene, 1.32, 0.32, 0.02);
// -------------------------------------------------------------------------
// Detached axle and wheel
// -------------------------------------------------------------------------
const axle = new THREE.Group();
axle.position.set(0.62, 1.35, 0.25);
scene.add(axle);
cylinderX(0.14, 1.48, mat.steel, axle, 0, 0, 0, 10);
cylinderX(0.24, 0.18, mat.darkSteel, axle, -0.55, 0, 0, 10);
cylinderX(0.22, 0.15, mat.yellow, axle, 0.28, 0, 0, 10);
cylinderX(0.19, 0.16, mat.darkSteel, axle, 0.66, 0, 0, 10);
// Keyed spline at the disconnected end.
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const key = box(
0.15, 0.045, 0.055,
mat.yellow, axle,
-0.78,
Math.sin(angle) * 0.16,
Math.cos(angle) * 0.16
);
key.rotation.x = angle;
}
const wheelRotor = new THREE.Group();
wheelRotor.position.set(1.75, 1.35, 0.25);
scene.add(wheelRotor);
const tire = mesh(
new THREE.TorusGeometry(0.76, 0.18, 6, 12),
mat.tire,
wheelRotor
);
tire.rotation.y = Math.PI / 2;
const rim = cylinderX(0.64, 0.28, mat.orange, wheelRotor, 0, 0, 0, 12);
const rimInner = cylinderX(0.43, 0.32, mat.darkSteel, wheelRotor, 0, 0, 0, 12);
const hub = cylinderX(0.21, 0.52, mat.steel, wheelRotor, 0.02, 0, 0, 10);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const bolt = cylinderX(
0.055, 0.08, mat.white, wheelRotor,
0.20,
Math.sin(angle) * 0.34,
Math.cos(angle) * 0.34,
6
);
bolt.rotation.z = Math.PI / 2;
}
// A thin index mark makes the wheel's inspection rotation visible.
box(
0.07, 0.48, 0.08,
mat.cyan, wheelRotor,
0.19, 0.27, 0
);
// -------------------------------------------------------------------------
// Inspection highlights
// -------------------------------------------------------------------------
const wheelFocusMaterial = new THREE.MeshBasicMaterial({
color: 0x67e4e2,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const wheelFocus = mesh(
new THREE.TorusGeometry(1.02, 0.025, 6, 32),
wheelFocusMaterial,
scene
);
wheelFocus.position.copy(wheelRotor.position);
wheelFocus.rotation.y = Math.PI / 2;
wheelFocus.castShadow = false;
const axleFocusMaterial = new THREE.MeshBasicMaterial({
color: 0x67e4e2,
wireframe: true,
transparent: true,
opacity: 0,
depthWrite: false
});
const axleFocus = mesh(
new THREE.CylinderGeometry(0.31, 0.31, 1.62, 8, 1, true),
axleFocusMaterial,
scene
);
axleFocus.rotation.z = Math.PI / 2;
axleFocus.position.copy(axle.position);
axleFocus.castShadow = false;
const casingFocusMaterial = new THREE.MeshBasicMaterial({
color: 0x67e4e2,
wireframe: true,
transparent: true,
opacity: 0,
depthWrite: false
});
const casingFocus = mesh(
new THREE.DodecahedronGeometry(1.17, 0),
casingFocusMaterial,
scene
);
casingFocus.scale.set(1.07, 0.79, 0.79);
casingFocus.position.copy(casing.position);
casingFocus.castShadow = false;
// The fault is placed exactly between the casing socket and detached axle.
const jointGroup = new THREE.Group();
jointGroup.position.set(-0.245, 1.38, 0.25);
scene.add(jointGroup);
const jointRingMaterial = new THREE.MeshBasicMaterial({
color: 0xff554b,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const jointRing = mesh(
new THREE.TorusGeometry(0.31, 0.035, 6, 24),
jointRingMaterial,
jointGroup
);
jointRing.rotation.y = Math.PI / 2;
jointRing.castShadow = false;
const jointBracketMaterial = new THREE.MeshBasicMaterial({
color: 0xff554b,
transparent: true,
opacity: 0,
depthWrite: false
});
const jointBracket = mesh(
new THREE.TorusGeometry(0.39, 0.015, 4, 4),
jointBracketMaterial,
jointGroup
);
jointBracket.rotation.y = Math.PI / 2;
jointBracket.castShadow = false;
const faultLineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.49, 1.38, 0.25),
new THREE.Vector3(-0.04, 1.38, 0.25)
]);
const faultLineMaterial = new THREE.LineDashedMaterial({
color: 0xff554b,
dashSize: 0.07,
gapSize: 0.05,
transparent: true,
opacity: 0
});
const faultLine = new THREE.Line(faultLineGeometry, faultLineMaterial);
faultLine.computeLineDistances();
scene.add(faultLine);
// -------------------------------------------------------------------------
// Repair kiosks
// -------------------------------------------------------------------------
function makeCanvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return { canvas, context, texture };
}
function createKiosk(x, number, title, code, color) {
const group = new THREE.Group();
group.position.set(x, 0, -4.05);
scene.add(group);
box(2.2, 0.25, 1.18, mat.darkSteel, group, 0, 0.13, 0);
box(1.65, 2.0, 0.68, mat.casingDark, group, 0, 1.18, 0);
box(1.94, 0.18, 0.88, mat.casing, group, 0, 2.3, 0);
const frame = box(
1.78, 1.08, 0.12,
mat.darkSteel, group,
0, 1.66, 0.37
);
frame.castShadow = true;
const screenData = makeCanvasTexture(512, 320, (ctx, w, h) => {
ctx.fillStyle = "#07161d";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = color;
ctx.fillRect(0, 0, w, 9);
ctx.fillStyle = "#d9eeed";
ctx.font = "bold 34px sans-serif";
ctx.fillText(`0${number} ${title}`, 34, 69);
ctx.fillStyle = "#78999f";
ctx.font = "24px monospace";
ctx.fillText(`PART CODE ${code}`, 34, 111);
ctx.strokeStyle = "#28434a";
ctx.beginPath();
ctx.moveTo(34, 137);
ctx.lineTo(478, 137);
ctx.stroke();
ctx.fillStyle = "#67e4e2";
ctx.font = "bold 28px monospace";
ctx.fillText("INVENTORY READY", 34, 196);
ctx.fillStyle = "#91abb0";
ctx.font = "20px monospace";
ctx.fillText("6-BOLT / KEYED", 34, 242);
ctx.fillText("COMPATIBILITY SYSTEM", 34, 278);
});
const screen = mesh(
new THREE.PlaneGeometry(1.61, 0.91),
new THREE.MeshBasicMaterial({ map: screenData.texture }),
group
);
screen.position.set(0, 1.66, 0.438);
screen.castShadow = false;
const stripMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.18,
roughness: 0.4,
metalness: 0.25,
flatShading: true
});
const strip = box(1.7, 0.06, 0.08, stripMaterial, group, 0, 1.04, 0.38);
strip.castShadow = false;
// Bin and shelf.
box(1.85, 0.14, 1.03, mat.darkSteel, group, 0, 0.73, 0.04);
box(1.68, 0.55, 0.09, mat.casingDark, group, 0, 0.38, 0.47);
const light = new THREE.PointLight(color, 0.3, 4, 2);
light.position.set(0, 1.65, 0.8);
group.add(light);
return {
group,
screenData,
stripMaterial,
light,
color,
title,
code,
number,
lastState: ""
};
}
const kioskWheel = createKiosk(-3.65, 1, "WHEEL", "W-24", "#f2a14a");
const kioskAxle = createKiosk(0, 2, "AXLE", "A-18", "#67e4e2");
const kioskCasing = createKiosk(3.65, 3, "CASING", "C-42", "#83a6ff");
const kiosks = [kioskWheel, kioskAxle, kioskCasing];
function drawKioskState(kiosk, state) {
if (kiosk.lastState === state) return;
kiosk.lastState = state;
const { context: ctx, texture } = kiosk.screenData;
const selected = state === "selected";
const matched = state === "match";
ctx.fillStyle = "#07161d";
ctx.fillRect(0, 0, 512, 320);
ctx.fillStyle = matched ? "#8ce89c" : kiosk.color;
ctx.fillRect(0, 0, 512, 9);
ctx.fillStyle = "#d9eeed";
ctx.font = "bold 34px sans-serif";
ctx.fillText(`0${kiosk.number} ${kiosk.title}`, 34, 69);
ctx.fillStyle = "#78999f";
ctx.font = "24px monospace";
ctx.fillText(`PART CODE ${kiosk.code}`, 34, 111);
ctx.strokeStyle = "#28434a";
ctx.beginPath();
ctx.moveTo(34, 137);
ctx.lineTo(478, 137);
ctx.stroke();
if (selected || matched) {
ctx.fillStyle = "#8ce89c";
ctx.font = "bold 30px monospace";
ctx.fillText(selected ? "SELECTED" : "MATCH 100%", 34, 197);
ctx.fillStyle = "#c4d8d9";
ctx.font = "22px monospace";
ctx.fillText("SPLINE A-18", 34, 239);
ctx.fillText("LENGTH 1.48 / 6-BOLT", 34, 276);
} else {
ctx.fillStyle = kiosk.color;
ctx.font = "bold 28px monospace";
ctx.fillText("INVENTORY READY", 34, 196);
ctx.fillStyle = "#91abb0";
ctx.font = "20px monospace";
ctx.fillText("6-BOLT / KEYED", 34, 242);
ctx.fillText("COMPATIBILITY SYSTEM", 34, 278);
}
texture.needsUpdate = true;
}
// Non-selected replacement parts remain stationary in their matching kiosks.
const replacementWheel = new THREE.Group();
replacementWheel.position.set(-3.65, 1.03, -3.72);
scene.add(replacementWheel);
const spareTire = mesh(
new THREE.TorusGeometry(0.31, 0.075, 6, 12),
mat.tire,
replacementWheel
);
spareTire.rotation.y = Math.PI / 2;
cylinderX(0.24, 0.12, mat.orange, replacementWheel, 0, 0, 0, 12);
const replacementCasing = new THREE.Group();
replacementCasing.position.set(3.65, 1.08, -3.75);
scene.add(replacementCasing);
const spareCasing = mesh(
new THREE.DodecahedronGeometry(0.42, 0),
mat.casing,
replacementCasing
);
spareCasing.scale.set(1.05, 0.75, 0.72);
// The axle candidate is the only staged part that moves during selection.
const replacementAxle = new THREE.Group();
replacementAxle.position.set(0, 1.04, -3.72);
scene.add(replacementAxle);
cylinderX(0.115, 1.28, mat.steel, replacementAxle, 0, 0, 0, 10);
cylinderX(0.18, 0.12, mat.darkSteel, replacementAxle, -0.47, 0, 0, 10);
cylinderX(0.16, 0.11, mat.yellow, replacementAxle, 0.18, 0, 0, 10);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const key = box(
0.13, 0.04, 0.05,
mat.yellow, replacementAxle,
-0.67,
Math.sin(angle) * 0.125,
Math.cos(angle) * 0.125
);
key.rotation.x = angle;
}
const matchRingMaterial = new THREE.MeshBasicMaterial({
color: 0x8ce89c,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const matchRing = mesh(
new THREE.TorusGeometry(0.46, 0.025, 6, 24),
matchRingMaterial,
replacementAxle
);
matchRing.rotation.y = Math.PI / 2;
matchRing.castShadow = false;
// Staging tray for the selected replacement.
const stagingTray = new THREE.Group();
stagingTray.position.set(3.85, 0, 1.8);
scene.add(stagingTray);
box(2.0, 0.12, 1.05, mat.darkSteel, stagingTray, 0, 0.33, 0);
box(1.75, 0.08, 0.82, mat.casingDark, stagingTray, 0, 0.42, 0);
box(0.1, 0.46, 0.1, mat.casingDark, stagingTray, -0.78, 0.58, -0.35);
box(0.1, 0.46, 0.1, mat.casingDark, stagingTray, 0.78, 0.58, -0.35);
// -------------------------------------------------------------------------
// Timeline and UI state
// -------------------------------------------------------------------------
const stages = [
{
end: 1.7,
kicker: "System ready",
title: "Preparing component inspection",
detail: "The drive assembly is staged. Components will be inspected individually before a replacement is selected."
},
{
end: 4.7,
kicker: "Inspection 01 / Wheel",
title: "Wheel W-24 inspected",
detail: "The six-bolt pattern and hub index are intact. No wheel damage is detected, so the wheel remains unchanged."
},
{
end: 7.7,
kicker: "Inspection 02 / Axle",
title: "Axle A-18 inspected",
detail: "The keyed spline is visible on the detached shaft. Its connector is being compared against the casing input port."
},
{
end: 10.7,
kicker: "Inspection 03 / Casing",
title: "Casing C-42 inspected",
detail: "The casing input port is clean and undamaged. The actual separation is confirmed at joint J-04, not at the wheel."
},
{
end: 13.7,
kicker: "Fault isolated",
title: "Disconnected joint highlighted",
detail: "Joint J-04 is open between the axle spline and casing input. Replacement selection is locked until this fault is identified."
},
{
end: 20,
kicker: "Parts matching / AXLE",
title: "Compatible replacement selected",
detail: "The AXLE A-18 candidate matches joint J-04 by spline, length, and six-bolt interface. The wheel and casing remain untouched."
}
];
const duration = 20;
let elapsed = 0;
let playing = true;
let lastStage = -1;
const stageKicker = document.getElementById("stageKicker");
const stageTitle = document.getElementById("stageTitle");
const stageDetail = document.getElementById("stageDetail");
const progress = document.getElementById("progress");
const timecode = document.getElementById("timecode");
const checks = [...document.querySelectorAll(".check")];
const timelineLabels = [...document.querySelectorAll("#timelineLabels span")];
function stageIndexAt(time) {
for (let i = 0; i < stages.length; i++) {
if (time < stages[i].end) return i;
}
return stages.length - 1;
}
function updateUI(index) {
if (index === lastStage) return;
lastStage = index;
const stage = stages[index];
stageKicker.textContent = stage.kicker;
stageTitle.textContent = stage.title;
stageDetail.textContent = stage.detail;
checks.forEach((element, i) => {
element.className = "check";
if (i < index) element.classList.add("done");
if (i === index) {
element.classList.add(index === 4 ? "critical" : "current");
}
});
timelineLabels.forEach((element, i) => {
element.classList.toggle("active", i === index);
});
kioskAxle.lastState = "";
if (index === 5) {
drawKioskState(kioskAxle, "selected");
} else if (index === 4) {
drawKioskState(kioskAxle, "match");
} else {
drawKioskState(kioskAxle, "ready");
}
}
// -------------------------------------------------------------------------
// DOM hotspots projected from 3D positions
// -------------------------------------------------------------------------
const hotspotElements = {
wheel: document.getElementById("spotWheel"),
axle: document.getElementById("spotAxle"),
casing: document.getElementById("spotCasing"),
joint: document.getElementById("spotJoint"),
match: document.getElementById("spotMatch")
};
function projectHotspot(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.style.display = "none";
return;
}
element.style.display = "block";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
function updateHotspots(index) {
hotspotElements.wheel.style.display = "none";
hotspotElements.axle.style.display = "none";
hotspotElements.casing.style.display = "none";
hotspotElements.joint.style.display = "none";
hotspotElements.match.style.display = "none";
if (index === 1) {
projectHotspot(hotspotElements.wheel, wheelRotor.position.clone().add(new THREE.Vector3(0, 1.0, 0)));
}
if (index === 2) {
projectHotspot(hotspotElements.axle, axle.position.clone().add(new THREE.Vector3(0, 0.54, 0)));
}
if (index === 3) {
projectHotspot(hotspotElements.casing, casing.position.clone().add(new THREE.Vector3(-0.1, 1.05, 0)));
}
if (index === 4 || index === 5) {
projectHotspot(hotspotElements.joint, jointGroup.position.clone().add(new THREE.Vector3(0, 0.58, 0)));
}
if (index === 5) {
projectHotspot(hotspotElements.match, replacementAxle.position.clone().add(new THREE.Vector3(0, 0.55, 0)));
}
}
// -------------------------------------------------------------------------
// Controls
// -------------------------------------------------------------------------
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
playing = !playing;
pauseButton.textContent = playing ? "Ⅱ" : "▶";
pauseButton.setAttribute("aria-label", playing ? "Pause sequence" : "Play sequence");
});
document.getElementById("replay").addEventListener("click", () => {
elapsed = 0;
lastStage = -1;
playing = true;
pauseButton.textContent = "Ⅱ";
});
document.getElementById("view").addEventListener("click", () => {
orbit.target.set(0, 1.05, -0.35);
orbit.radius = 15.6;
orbit.theta = 0.62;
orbit.phi = 1.08;
});
addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
elapsed = 0;
lastStage = -1;
playing = true;
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const inspectionTarget = new THREE.Vector3();
const desiredTarget = new THREE.Vector3();
const desiredLightPosition = new THREE.Vector3();
const beamDirection = new THREE.Vector3();
const beamMidpoint = new THREE.Vector3();
const selectionStart = new THREE.Vector3(0, 1.72, -3.72);
const selectionEnd = new THREE.Vector3(3.85, 1.03, 1.8);
const selectionControl = new THREE.Vector3(1.25, 4.4, -0.25);
function quadraticBezier(out, a, b, c, t) {
const inv = 1 - t;
out.set(
inv * inv * a.x + 2 * inv * t * b.x + t * t * c.x,
inv * inv * a.y + 2 * inv * t * b.y + t * t * c.y,
inv * inv * a.z + 2 * inv * t * b.z + t * t * c.z
);
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (playing && elapsed < duration) {
elapsed = Math.min(duration, elapsed + dt);
}
const index = stageIndexAt(elapsed);
updateUI(index);
progress.style.width = `${(elapsed / duration) * 100}%`;
timecode.textContent = `00:${elapsed.toFixed(1).padStart(4, "0")}`;
// Only the inspected wheel is physically animated.
if (index === 1) {
wheelRotor.rotation.x += dt * 1.15;
}
// Component inspection fields.
const pulse = 0.5 + 0.5 * Math.sin(elapsed * 4.2);
wheelFocusMaterial.opacity = index === 1 ? 0.35 + pulse * 0.4 : 0;
wheelFocus.visible = index === 1;
const wheelScale = 1 + pulse * 0.045;
wheelFocus.scale.setScalar(wheelScale);
axleFocusMaterial.opacity = index === 2 ? 0.25 + pulse * 0.48 : 0;
axleFocus.visible = index === 2;
casingFocusMaterial.opacity = index === 3 ? 0.12 + pulse * 0.28 : 0;
casingFocus.visible = index === 3;
// The joint is isolated only after all three inspections are complete.
const jointVisible = index >= 4;
const jointPulse = 0.5 + 0.5 * Math.sin(elapsed * 6.2);
jointRingMaterial.opacity = jointVisible ? 0.48 + jointPulse * 0.5 : 0;
jointBracketMaterial.opacity = jointVisible ? 0.18 + (1 - jointPulse) * 0.35 : 0;
faultLineMaterial.opacity = jointVisible ? 0.45 + jointPulse * 0.5 : 0;
jointRing.scale.setScalar(1 + jointPulse * 0.12);
jointBracket.rotation.x += dt * 0.65;
jointLight.intensity = jointVisible ? 1.4 + jointPulse * 2.0 : 0;
// Selection begins strictly after the disconnected joint has been shown.
const selectionTime = THREE.MathUtils.clamp((elapsed - 13.7) / 5.7, 0, 1);
if (selectionTime < 0.22) {
const t = selectionTime / 0.22;
replacementAxle.position.set(
0,
THREE.MathUtils.lerp(1.04, selectionStart.y, t),
selectionStart.z
);
replacementAxle.rotation.set(0, 0, 0);
} else if (selectionTime < 0.84) {
const t = (selectionTime - 0.22) / 0.62;
quadraticBezier(
replacementAxle.position,
selectionStart,
selectionControl,
selectionEnd,
t
);
replacementAxle.rotation.z = Math.sin(t * Math.PI * 2) * 0.12;
replacementAxle.rotation.y = t * Math.PI * 0.65;
} else {
const t = (selectionTime - 0.84) / 0.16;
replacementAxle.position.copy(selectionEnd);
replacementAxle.rotation.set(0, Math.PI * 0.65, 0);
replacementAxle.position.y += Math.sin(t * Math.PI) * 0.05;
}
matchRingMaterial.opacity = index === 5 ? 0.3 + pulse * 0.55 : 0;
matchRing.visible = index === 5;
matchRing.scale.setScalar(1 + pulse * 0.08);
// Kiosk lighting communicates the exact matching bay.
for (const kiosk of kiosks) {
const isAxle = kiosk === kioskAxle;
const selected = isAxle && index === 5;
const hinted = isAxle && index === 4;
kiosk.stripMaterial.emissiveIntensity = selected
? 1.6 + pulse * 0.8
: hinted
? 0.65 + pulse * 0.55
: 0.18;
kiosk.light.intensity = selected ? 2.2 : hinted ? 0.9 : 0.3;
kiosk.light.color.set(selected ? 0x8ce89c : kiosk.color);
}
// Move the inspection light only; component transforms stay isolated.
if (index === 1) {
desiredTarget.copy(wheelRotor.position);
desiredLightPosition.set(4.4, 4.1, 3.0);
} else if (index === 2) {
desiredTarget.copy(axle.position);
desiredLightPosition.set(2.2, 4.8, 3.3);
} else if (index === 3) {
desiredTarget.copy(casing.position);
desiredLightPosition.set(0.5, 5.6, 4.2);
} else if (index === 4) {
desiredTarget.copy(jointGroup.position);
desiredLightPosition.set(1.8, 3.6, 3.2);
} else if (index === 5) {
desiredTarget.copy(replacementAxle.position);
desiredLightPosition.set(replacementAxle.position.x + 1.4, 4.1, 4.0);
} else {
desiredTarget.set(0, 1.1, 0);
desiredLightPosition.set(3, 6, 4);
}
inspectionTarget.lerp(desiredTarget, 1 - Math.exp(-dt * 5));
inspectorLight.target.position.copy(inspectionTarget);
inspectorLight.position.lerp(desiredLightPosition, 1 - Math.exp(-dt * 4));
inspectorLight.intensity = index === 0 ? 0.35 : index === 4 ? 2.4 : 3.2;
inspectorLight.color.set(index === 4 ? 0xff6b60 : index === 5 ? 0x8ce89c : 0x67e4e2);
beamDirection.subVectors(inspectionTarget, inspectorLight.position);
const beamLength = beamDirection.length();
beamMidpoint.copy(inspectorLight.position).add(inspectionTarget).multiplyScalar(0.5);
scanBeam.position.copy(beamMidpoint);
scanBeam.scale.set(1, beamLength, 1);
scanBeam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
beamDirection.clone().normalize()
);
beamMaterial.color.copy(inspectorLight.color);
beamMaterial.opacity = index === 0 ? 0.025 : 0.055;
applyCamera();
updateHotspots(index);
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
animate();
</script>
</body>
</html>
```