Prompt specification
Build or customize the Three.js 3D scene "Repair intake tag and object" 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: Repair intake tag and object
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/repair-intake-tag-and-object-x0529
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a repair intake tag and matching spare parts. Display a broken toy, repair tag, and small parts tray sharing one symbol; show the missing wheel's position clearly so the reported fault matches the object. Voxel style.
Working Three.js Starter (repair-intake-tag-and-object-x0529):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Repair Intake — Matching Spare Parts</title>
<style>
:root {
--ink: #172934;
--muted: #66737a;
--paper: #f5f0e4;
--orange: #ef6b3a;
--orange-light: #ff9b67;
--red: #d83c35;
--green: #278b73;
--line: rgba(23, 41, 52, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7e1d6;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
display: flex;
align-items: center;
gap: 14px;
padding: 15px 18px 15px 14px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 16px;
background: rgba(250, 247, 239, 0.9);
box-shadow: 0 12px 35px rgba(31, 43, 49, 0.12);
backdrop-filter: blur(12px);
}
.symbol {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 38px;
border-radius: 9px;
background: var(--orange);
box-shadow: inset 0 -4px 0 rgba(112, 40, 19, 0.15);
}
.symbol::before,
.symbol::after {
content: "";
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff8e9;
border-radius: 1px;
}
.symbol::before {
width: 22px;
height: 7px;
}
.symbol::after {
width: 7px;
height: 22px;
}
.eyebrow {
margin: 0 0 3px;
color: var(--orange);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(16px, 2vw, 22px);
line-height: 1.05;
letter-spacing: -0.03em;
}
.status-card {
position: absolute;
top: 24px;
right: 24px;
width: min(330px, calc(100vw - 48px));
padding: 16px 18px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 16px;
background: rgba(22, 39, 49, 0.91);
color: #f8f3e8;
box-shadow: 0 15px 40px rgba(22, 39, 49, 0.18);
backdrop-filter: blur(12px);
}
.status-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.status-id {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
}
.status-badge {
padding: 5px 8px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.11);
color: #ffc2a4;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-row {
display: grid;
grid-template-columns: 98px 1fr;
gap: 10px;
padding: 7px 0;
border-top: 1px solid rgba(255, 255, 255, 0.1);
font-size: 12px;
}
.status-row span:first-child {
color: #aebbc1;
}
.status-row strong {
font-weight: 700;
}
.fault {
color: #ff9a8f;
}
.matched {
color: #80ddc3;
}
.scene-label {
position: absolute;
width: max-content;
max-width: 220px;
padding: 10px 12px;
border-radius: 11px;
color: white;
font-size: 11px;
line-height: 1.35;
letter-spacing: 0.015em;
box-shadow: 0 8px 24px rgba(23, 41, 52, 0.18);
transform: translate(-50%, calc(-100% - 35px));
will-change: left, top;
}
.scene-label strong {
display: block;
margin-bottom: 2px;
font-size: 11px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -25px;
width: 2px;
height: 25px;
transform: translateX(-50%);
background: currentColor;
opacity: 0.85;
}
.scene-label::before {
content: "";
position: absolute;
left: 50%;
bottom: -29px;
width: 8px;
height: 8px;
transform: translateX(-50%) rotate(45deg);
background: currentColor;
}
#missingCallout {
background: var(--red);
}
#spareCallout {
background: var(--green);
transform: translate(-50%, 32px);
}
#spareCallout::after {
top: -25px;
bottom: auto;
}
#spareCallout::before {
top: -29px;
bottom: auto;
}
.hint {
position: absolute;
left: 24px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 10px;
background: rgba(250, 247, 239, 0.82);
color: #526069;
font-size: 11px;
font-weight: 650;
box-shadow: 0 8px 24px rgba(31, 43, 49, 0.08);
backdrop-filter: blur(10px);
}
.hint b {
color: var(--ink);
}
@media (max-width: 720px) {
.title-card {
top: 14px;
left: 14px;
padding: 11px 13px 11px 10px;
}
.status-card {
top: auto;
right: 14px;
bottom: 14px;
width: 245px;
padding: 12px 14px;
}
.status-row {
grid-template-columns: 76px 1fr;
font-size: 10px;
}
.hint {
display: none;
}
.scene-label {
max-width: 160px;
padding: 8px 9px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="title-card">
<div class="symbol" aria-hidden="true"></div>
<div>
<p class="eyebrow">Workshop intake · PX symbol</p>
<h1>Repair intake & matching spares</h1>
</div>
</header>
<aside class="status-card">
<div class="status-head">
<span class="status-id">INTAKE PX-204</span>
<span class="status-badge">Matched</span>
</div>
<div class="status-row">
<span>Reported</span>
<strong class="fault">Front wheel missing</strong>
</div>
<div class="status-row">
<span>Object</span>
<strong>Voxel utility truck</strong>
</div>
<div class="status-row">
<span>Spares</span>
<strong class="matched">1 wheel + 4 bolts</strong>
</div>
<div class="status-row">
<span>Shared ID</span>
<strong>Orange PX cross</strong>
</div>
</aside>
<div id="missingCallout" class="scene-label">
<strong>Missing wheel</strong>
Front-right position · 48 mm
</div>
<div id="spareCallout" class="scene-label">
<strong>Matched spare</strong>
Identical 48 mm voxel wheel
</div>
<div class="hint"><b>Drag</b> to orbit · <b>Scroll</b> to zoom · <b>Double-click</b> to reset</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 container = document.getElementById("scene");
const missingCallout = document.getElementById("missingCallout");
const spareCallout = document.getElementById("spareCallout");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7e1d6);
scene.fog = new THREE.Fog(0xe7e1d6, 17, 31);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
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;
container.appendChild(renderer.domElement);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xd8d1c4,
roughness: 0.95
}),
groundEdge: new THREE.MeshStandardMaterial({
color: 0xa9a297,
roughness: 0.9
}),
wall: new THREE.MeshStandardMaterial({
color: 0xded8cc,
roughness: 0.95
}),
shelf: new THREE.MeshStandardMaterial({
color: 0x8e9998,
roughness: 0.85
}),
bin: new THREE.MeshStandardMaterial({
color: 0xb6b3a9,
roughness: 0.9
}),
navy: new THREE.MeshStandardMaterial({
color: 0x193744,
roughness: 0.72
}),
teal: new THREE.MeshStandardMaterial({
color: 0x287f80,
roughness: 0.66
}),
tealLight: new THREE.MeshStandardMaterial({
color: 0x58a4a1,
roughness: 0.72
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xe8b83f,
roughness: 0.65
}),
yellowLight: new THREE.MeshStandardMaterial({
color: 0xf4ca58,
roughness: 0.62
}),
orange: new THREE.MeshStandardMaterial({
color: 0xef6b3a,
roughness: 0.58,
emissive: 0x401207,
emissiveIntensity: 0.08
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf2ead8,
roughness: 0.86
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x20282c,
roughness: 0.9
}),
rubberLight: new THREE.MeshStandardMaterial({
color: 0x364044,
roughness: 0.88
}),
metal: new THREE.MeshStandardMaterial({
color: 0xbcc3c0,
metalness: 0.55,
roughness: 0.43
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x566368,
metalness: 0.42,
roughness: 0.55
}),
glass: new THREE.MeshStandardMaterial({
color: 0x214958,
metalness: 0.08,
roughness: 0.25
})
};
const ghostMaterial = new THREE.MeshStandardMaterial({
color: 0xff4b42,
emissive: 0xff2f27,
emissiveIntensity: 0.7,
transparent: true,
opacity: 0.22,
depthWrite: false,
roughness: 0.55
});
const ghostAccentMaterial = new THREE.MeshStandardMaterial({
color: 0xff5b4f,
emissive: 0xff241d,
emissiveIntensity: 0.8,
transparent: true,
opacity: 0.72,
depthWrite: false
});
function box(
width,
height,
depth,
material,
x,
y,
z,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCanvasTexture(width, height, paint) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
paint(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function drawPlus(context, x, y, size, color) {
context.fillStyle = color;
context.fillRect(x, y + size * 0.34, size, size * 0.32);
context.fillRect(x + size * 0.34, y, size * 0.32, size);
}
function addPlusXY(parent, x, y, z, size, depth, material) {
box(
size,
size * 0.32,
depth,
material,
x,
y,
z,
parent
);
box(
size * 0.32,
size,
depth,
material,
x,
y,
z,
parent
);
}
function addPlusXZ(parent, x, y, z, size, height, material) {
box(
size,
height,
size * 0.32,
material,
x,
y,
z,
parent
);
box(
size * 0.32,
height,
size,
material,
x,
y,
z,
parent
);
}
// Lighting
scene.add(new THREE.HemisphereLight(0xfff8e9, 0x6b7472, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff2d8, 3.6);
keyLight.position.set(5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xaed6df, 1.4);
rimLight.position.set(-8, 6, -6);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xff9b65, 22, 18, 2);
warmFill.position.set(5, 4, -1);
scene.add(warmFill);
// Voxel workshop table and background
box(18, 0.5, 12, materials.ground, 0, -0.28, 0);
box(18.2, 0.26, 0.38, materials.groundEdge, 0, -0.13, 5.8);
box(18.2, 0.26, 0.38, materials.groundEdge, 0, -0.13, -5.8);
box(18, 8, 0.4, materials.wall, 0, 3.5, -5.7);
box(14.5, 0.18, 1.1, materials.shelf, -0.6, 2.3, -5.2);
box(14.5, 0.18, 1.1, materials.shelf, -0.6, 4.35, -5.2);
for (let i = 0; i < 7; i++) {
const x = -5.4 + i * 1.65;
const height = 0.55 + (i % 3) * 0.17;
box(
1.25,
height,
0.85,
i % 2 === 0 ? materials.bin : materials.shelf,
x,
2.42 + height / 2,
-5.15
);
}
for (let i = 0; i < 5; i++) {
const x = -4.9 + i * 2.1;
box(
1.4,
0.8 + (i % 2) * 0.35,
0.9,
i % 2 ? materials.bin : materials.tealLight,
x,
4.78 + (i % 2) * 0.175,
-5.1
);
}
// Shared PX cross tag
const tag = new THREE.Group();
tag.position.set(-5.0, 0, -1.35);
tag.rotation.y = 0.13;
scene.add(tag);
box(2.82, 3.55, 0.18, materials.orange, 0, 2.15, 0, tag);
const tagTexture = makeCanvasTexture(768, 1024, (ctx, w, h) => {
ctx.fillStyle = "#f5efdf";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#d9cfb9";
ctx.lineWidth = 8;
ctx.strokeRect(22, 22, w - 44, h - 44);
drawPlus(ctx, 58, 54, 76, "#ef6b3a");
ctx.textAlign = "left";
ctx.fillStyle = "#ef6b3a";
ctx.font = "800 24px Arial";
ctx.fillText("WORKSHOP / INTAKE", 165, 88);
ctx.fillStyle = "#172934";
ctx.font = "900 54px Arial";
ctx.fillText("REPAIR", 58, 186);
ctx.fillText("INTAKE", 58, 242);
ctx.fillStyle = "#ef6b3a";
ctx.font = "800 28px Arial";
ctx.fillText("PX-204", 58, 299);
ctx.fillStyle = "#172934";
ctx.font = "700 21px Arial";
ctx.fillText("SHARED SYMBOL", 58, 380);
drawPlus(ctx, 58, 406, 52, "#ef6b3a");
ctx.fillStyle = "#778087";
ctx.font = "600 19px Arial";
ctx.fillText("ISSUE REPORTED", 58, 515);
ctx.fillStyle = "#172934";
ctx.font = "900 37px Arial";
ctx.fillText("FRONT WHEEL", 58, 570);
ctx.fillStyle = "#d83c35";
ctx.fillRect(52, 605, 360, 66);
ctx.fillStyle = "#ffffff";
ctx.font = "900 35px Arial";
ctx.fillText("MISSING", 82, 650);
ctx.fillStyle = "#778087";
ctx.font = "600 19px Arial";
ctx.fillText("MATCHED SPARES", 58, 747);
ctx.fillStyle = "#278b73";
ctx.font = "800 24px Arial";
ctx.fillText("1 WHEEL + 4 BOLTS", 58, 787);
ctx.fillStyle = "#172934";
for (let i = 0; i < 46; i++) {
const width = i % 4 === 0 ? 8 : i % 3 === 0 ? 5 : 3;
ctx.fillRect(58 + i * 13, 882, width, 70);
}
ctx.fillStyle = "#778087";
ctx.font = "600 17px Arial";
ctx.fillText("FRONT RIGHT AXLE / 48 MM", 58, 988);
});
const tagFace = new THREE.Mesh(
new THREE.PlaneGeometry(2.58, 3.43),
new THREE.MeshStandardMaterial({
map: tagTexture,
roughness: 0.9
})
);
tagFace.position.set(0, 2.15, 0.096);
tagFace.receiveShadow = true;
tag.add(tagFace);
box(0.72, 0.16, 0.25, materials.darkMetal, 0, 3.91, 0.02, tag);
box(0.38, 0.28, 0.14, materials.metal, 0, 3.84, 0.17, tag);
box(0.12, 0.66, 0.14, materials.darkMetal, -0.83, 0.35, 0, tag);
box(0.12, 0.66, 0.14, materials.darkMetal, 0.83, 0.35, 0, tag);
box(2.05, 0.12, 0.75, materials.navy, 0, 0.08, 0.04, tag);
// Toy utility truck
const truck = new THREE.Group();
truck.position.set(-2.35, 0, 0);
scene.add(truck);
box(3.95, 0.28, 1.92, materials.navy, 0, 0.54, 0, truck);
box(3.72, 0.54, 1.78, materials.yellow, 0, 0.91, 0, truck);
box(3.88, 0.12, 1.9, materials.yellowLight, 0, 1.19, 0, truck);
// Rear utility bed
box(1.25, 0.18, 1.56, materials.teal, -1.18, 1.28, 0, truck);
box(0.14, 0.55, 1.58, materials.teal, -1.75, 1.53, 0, truck);
box(1.2, 0.46, 0.13, materials.teal, -1.18, 1.49, -0.74, truck);
box(1.2, 0.46, 0.13, materials.teal, -1.18, 1.49, 0.74, truck);
// Cab
box(1.62, 1.22, 1.64, materials.yellow, -0.48, 1.78, 0, truck);
box(1.82, 0.18, 1.78, materials.teal, -0.48, 2.45, 0, truck);
// Windows
box(0.92, 0.55, 0.055, materials.glass, -0.62, 1.92, 0.832, truck);
box(0.92, 0.55, 0.055, materials.glass, -0.62, 1.92, -0.832, truck);
box(0.055, 0.55, 1.28, materials.glass, 0.345, 1.92, 0, truck);
// Near-side door and shared orange PX cross
box(0.94, 0.64, 0.065, materials.teal, -0.55, 1.43, 0.86, truck);
addPlusXY(truck, -0.55, 1.43, 0.91, 0.36, 0.055, materials.orange);
// Hood and front details
box(1.42, 0.34, 1.66, materials.yellowLight, 1.18, 1.32, 0, truck);
box(0.18, 0.48, 1.78, materials.navy, 1.92, 0.88, 0, truck);
box(0.18, 0.24, 1.18, materials.metal, 2.03, 1.1, 0, truck);
for (const side of [-1, 1]) {
box(
0.28,
0.24,
0.06,
materials.cream,
1.78,
1.27,
side * 0.59,
truck
);
}
// Voxel wheel builder
function createVoxelWheel(ghost = false) {
const wheel = new THREE.Group();
const cell = 0.255;
const step = 0.275;
for (let ix = -2; ix <= 2; ix++) {
for (let iy = -2; iy <= 2; iy++) {
const distanceSquared = ix * ix + iy * iy;
if (distanceSquared > 5 || distanceSquared < 2) continue;
const outerMaterial = ghost
? (Math.abs(ix) + Math.abs(iy)) % 2 === 0
? ghostAccentMaterial
: ghostMaterial
: (Math.abs(ix) + Math.abs(iy)) % 3 === 0
? materials.rubberLight
: materials.rubber;
box(
cell,
cell,
ghost ? 0.3 : 0.36,
outerMaterial,
ix * step,
iy * step,
0,
wheel,
!ghost
);
}
}
const hubMaterial = ghost ? ghostAccentMaterial : materials.metal;
box(
0.34,
0.34,
ghost ? 0.28 : 0.39,
hubMaterial,
0,
0,
0,
wheel,
!ghost
);
if (!ghost) {
addPlusXY(wheel, 0, 0, 0.215, 0.3, 0.055, materials.orange);
}
return wheel;
}
// Three mounted wheels
const rearNear = createVoxelWheel();
rearNear.position.set(-1.27, 0.72, 1.03);
truck.add(rearNear);
const rearFar = createVoxelWheel();
rearFar.position.set(-1.27, 0.72, -1.03);
truck.add(rearFar);
const frontFar = createVoxelWheel();
frontFar.position.set(1.25, 0.72, -1.03);
truck.add(frontFar);
// Empty front-right wheel location
const missingWheel = createVoxelWheel(true);
missingWheel.position.set(1.25, 0.72, 1.03);
truck.add(missingWheel);
// Visible axle stub where the wheel is absent
box(
0.19,
0.19,
0.38,
materials.metal,
1.25,
0.72,
0.9,
truck
);
// Four red corner brackets around the missing wheel
const bracketMaterial = new THREE.MeshStandardMaterial({
color: 0xff4139,
emissive: 0xff251e,
emissiveIntensity: 0.8,
roughness: 0.5
});
function addCornerBracket(x, y) {
box(
0.28,
0.065,
0.07,
bracketMaterial,
x - Math.sign(x) * 0.105,
y,
1.245,
truck
);
box(
0.065,
0.28,
0.07,
bracketMaterial,
x,
y - Math.sign(y) * 0.105,
1.245,
truck
);
}
addCornerBracket(1.25 - 0.73, 0.72 + 0.73);
addCornerBracket(1.25 + 0.73, 0.72 + 0.73);
addCornerBracket(1.25 - 0.73, 0.72 - 0.73);
addCornerBracket(1.25 + 0.73, 0.72 - 0.73);
// Parts tray
const tray = new THREE.Group();
tray.position.set(3.55, 0, 0.35);
scene.add(tray);
box(3.8, 0.3, 3.0, materials.navy, 0, 0.24, 0, tray);
box(3.58, 0.08, 2.78, materials.tealLight, 0, 0.42, 0, tray);
// Outer walls
box(3.8, 0.48, 0.16, materials.teal, 0, 0.57, -1.43, tray);
box(3.8, 0.48, 0.16, materials.teal, 0, 0.57, 1.43, tray);
box(0.16, 0.48, 2.84, materials.teal, -1.82, 0.57, 0, tray);
box(0.16, 0.48, 2.84, materials.teal, 1.82, 0.57, 0, tray);
// Internal divider
box(0.14, 0.38, 2.68, materials.teal, -0.28, 0.54, 0, tray);
// Shared symbol embossed in the tray
addPlusXZ(tray, -1.08, 0.51, -0.52, 0.62, 0.08, materials.orange);
// Four small axle bolts
const boltPositions = [
[-1.37, 0.55],
[-0.92, 0.55],
[-1.37, 0.95],
[-0.92, 0.95]
];
for (const [x, z] of boltPositions) {
box(0.16, 0.12, 0.16, materials.metal, x, 0.54, z, tray);
box(0.09, 0.12, 0.09, materials.darkMetal, x, 0.64, z, tray);
}
// Matching spare wheel, lying flat in the larger compartment
const spareWheel = createVoxelWheel(false);
spareWheel.rotation.x = -Math.PI / 2;
spareWheel.position.set(0.73, 0.69, -0.03);
tray.add(spareWheel);
// Tray front label
const trayTexture = makeCanvasTexture(1024, 160, (ctx, w, h) => {
ctx.fillStyle = "#193744";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#ef6b3a";
ctx.fillRect(0, 0, 155, h);
drawPlus(ctx, 43, 38, 68, "#fff4df");
ctx.fillStyle = "#f7f1e4";
ctx.font = "900 46px Arial";
ctx.fillText("MATCHED SPARES", 205, 70);
ctx.fillStyle = "#9fc7c4";
ctx.font = "700 27px Arial";
ctx.fillText("PX-204 / 1 WHEEL + 4 BOLTS", 207, 119);
});
const trayLabel = new THREE.Mesh(
new THREE.PlaneGeometry(2.95, 0.46),
new THREE.MeshStandardMaterial({
map: trayTexture,
roughness: 0.78
})
);
trayLabel.position.set(0, 0.57, 1.516);
tray.add(trayLabel);
// Small voxel blocks along the table rear for scene depth
box(1.1, 0.55, 0.8, materials.bin, 5.5, 0.3, -2.6);
box(0.75, 0.42, 0.7, materials.shelf, 6.15, 0.23, -2.1);
box(0.85, 0.68, 0.8, materials.bin, -7.0, 0.35, 1.7);
// Custom camera controls implemented directly in this file
const cameraTarget = new THREE.Vector3(-0.35, 1.25, 0);
let desiredTheta = 0.52;
let desiredPhi = 1.02;
let desiredRadius = 14.8;
let currentTheta = desiredTheta;
let currentPhi = desiredPhi;
let currentRadius = desiredRadius;
function resetCamera() {
desiredTheta = 0.52;
desiredPhi = 1.02;
desiredRadius = window.innerWidth < 720 ? 17.2 : 14.8;
}
function updateCamera() {
currentTheta += (desiredTheta - currentTheta) * 0.12;
currentPhi += (desiredPhi - currentPhi) * 0.12;
currentRadius += (desiredRadius - currentRadius) * 0.12;
const horizontal = Math.sin(currentPhi) * currentRadius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(currentTheta),
cameraTarget.y + Math.cos(currentPhi) * currentRadius,
cameraTarget.z + horizontal * Math.cos(currentTheta)
);
camera.lookAt(cameraTarget);
}
let pointerDown = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
desiredTheta -= dx * 0.006;
desiredPhi = THREE.MathUtils.clamp(
desiredPhi - dy * 0.005,
0.58,
1.34
);
previousX = event.clientX;
previousY = event.clientY;
});
function releasePointer(event) {
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
8.5,
22
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
// Project the two in-scene labels onto their exact 3D positions
const missingAnchor = new THREE.Vector3(-1.1, 1.48, 1.03);
const spareAnchor = new THREE.Vector3(4.28, 0.82, 0.32);
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
element.style.visibility = visible ? "visible" : "hidden";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
// Gentle pulse makes the absent part unmistakable without moving it.
ghostMaterial.opacity = 0.16 + Math.sin(elapsed * 2.8) * 0.055;
ghostAccentMaterial.opacity =
0.58 + Math.sin(elapsed * 2.8 + 0.8) * 0.14;
placeLabel(missingCallout, missingAnchor);
placeLabel(spareCallout, spareAnchor);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```