Prompt specification
Build or customize the Three.js 3D scene "Repair restores the original 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 restores the original object
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/repair-restores-the-original-object-x3902
Scene Description Prompt:
A low-poly family member replaces a toy axle and reattaches its original wheel, preserving distinctive paint marks. One HTML file with Three.js from cdnjs.
Working Three.js Starter (repair-restores-the-original-object-x3902):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One More Turn — A Low-Poly Family Repair</title>
<style>
:root {
--ink: #283b3d;
--muted: #667674;
--paper: rgba(255, 250, 241, 0.88);
--accent: #c95f50;
--gold: #e6b84f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee4d6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.header {
position: fixed;
z-index: 10;
top: clamp(20px, 4vw, 42px);
left: clamp(20px, 4vw, 48px);
max-width: 440px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
padding: 7px 11px;
border: 1px solid rgba(40, 59, 61, 0.15);
border-radius: 999px;
background: rgba(255, 250, 241, 0.66);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
content: "";
box-shadow: 0 0 0 4px rgba(201, 95, 80, 0.12);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 70px);
font-weight: 500;
line-height: 0.94;
letter-spacing: -0.045em;
}
.intro {
max-width: 370px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.controls {
position: fixed;
z-index: 20;
top: clamp(18px, 3vw, 34px);
right: clamp(18px, 3vw, 34px);
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(40, 59, 61, 0.14);
border-radius: 12px;
padding: 10px 14px;
background: var(--paper);
box-shadow: 0 8px 24px rgba(48, 57, 53, 0.08);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
transform 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
button:hover {
transform: translateY(-2px);
background: rgba(255, 252, 247, 0.98);
box-shadow: 0 10px 28px rgba(48, 57, 53, 0.12);
}
button:focus-visible {
outline: 3px solid rgba(201, 95, 80, 0.35);
outline-offset: 3px;
}
button.active {
border-color: rgba(201, 95, 80, 0.35);
background: rgba(201, 95, 80, 0.12);
color: #8d3d34;
}
.caption {
position: fixed;
z-index: 10;
bottom: clamp(18px, 3vw, 34px);
left: clamp(20px, 4vw, 48px);
display: flex;
align-items: center;
gap: 12px;
padding: 11px 15px 11px 11px;
border: 1px solid rgba(40, 59, 61, 0.11);
border-radius: 15px;
background: rgba(255, 250, 241, 0.76);
box-shadow: 0 10px 30px rgba(48, 57, 53, 0.08);
backdrop-filter: blur(12px);
pointer-events: none;
}
.caption-icon {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border-radius: 10px;
background: var(--gold);
color: #4e3a13;
font-size: 18px;
}
.caption strong,
.caption small {
display: block;
}
.caption strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-weight: 500;
}
.caption small {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hint {
position: fixed;
z-index: 10;
right: clamp(18px, 3vw, 34px);
bottom: clamp(20px, 3vw, 34px);
color: rgba(40, 59, 61, 0.62);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.05em;
pointer-events: none;
}
.pin {
position: fixed;
z-index: 8;
left: 0;
top: 0;
width: 1px;
height: 1px;
pointer-events: none;
opacity: 0;
transition: opacity 180ms ease;
}
.pin.visible {
opacity: 1;
}
.pin-dot {
position: absolute;
left: -6px;
top: -6px;
width: 12px;
height: 12px;
border: 3px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 3px 12px rgba(70, 44, 35, 0.25);
}
.pin-line {
position: absolute;
left: -72px;
top: -29px;
width: 82px;
height: 2px;
border-radius: 2px;
background: rgba(40, 59, 61, 0.48);
transform: rotate(21deg);
transform-origin: right center;
}
.pin-card {
position: absolute;
left: -168px;
top: -67px;
min-width: 150px;
padding: 10px 13px;
border: 1px solid rgba(40, 59, 61, 0.13);
border-radius: 11px;
background: rgba(255, 250, 241, 0.9);
box-shadow: 0 8px 24px rgba(48, 57, 53, 0.12);
backdrop-filter: blur(10px);
font-size: 11px;
font-weight: 800;
line-height: 1.25;
}
.pin-card small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.04em;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #eee4d6;
color: var(--muted);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
body.ready #loading {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.header {
max-width: 270px;
}
.intro,
.hint,
.pin {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 78px;
flex-direction: column;
}
button {
padding: 9px 11px;
}
.caption {
right: 14px;
bottom: 14px;
left: 14px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly family repair scene"></div>
<header class="header">
<div class="eyebrow">A small family repair</div>
<h1>One More<br />Turn.</h1>
<p class="intro">
A fresh axle, a steady hand, and the same well-loved wheel—with every
red streak and blue scuff still right where the child left them.
</p>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="resetView" type="button">Reset view</button>
<button id="focusWheel" type="button">Inspect wheel</button>
<button id="toggleOrbit" type="button" aria-pressed="false">Auto orbit</button>
</nav>
<div class="caption">
<span class="caption-icon" aria-hidden="true">↻</span>
<span>
<strong>The original wheel, back in place</strong>
<small>Fresh silver axle · old paint preserved</small>
</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click the wheel</div>
<div id="pin" class="pin" aria-hidden="true">
<span class="pin-dot"></span>
<span class="pin-line"></span>
<span class="pin-card">
Original wheel
<small>red streak · blue scuff · tiny chip</small>
</span>
</div>
<div id="loading">Building the little scene…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const host = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee4d6);
scene.fog = new THREE.Fog(0xeee4d6, 11, 24);
const camera = new THREE.PerspectiveCamera(
37,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
host.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff4df, 0x71848a, 2.15);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1d7, 3.4);
key.position.set(-3.5, 7, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 20;
key.shadow.bias = -0.0008;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0x9ec9db, 1.25);
fill.position.set(5, 3, -4);
scene.add(fill);
const warmBounce = new THREE.PointLight(0xffb26b, 0.7, 9, 2);
warmBounce.position.set(1.7, 2.8, 2.5);
scene.add(warmBounce);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const material = (color, roughness = 0.8, metalness = 0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
const M = {
floor: material(0xe8ddcc),
platform: material(0xd6b98c),
platformEdge: material(0xb89267),
red: material(0xb94f43),
redDark: material(0x843a36),
cream: material(0xf0dca8),
wood: material(0xc89256),
woodDark: material(0x95613b),
gold: material(0xe2ae3e, 0.66),
wheel: material(0xe9bd4e, 0.76),
wheelFace: material(0xf1cb65, 0.78),
wheelEdge: material(0xc7892e, 0.78),
hub: material(0xb97a35),
skin: material(0xd79a72),
hair: material(0x382b29),
shirt: material(0xc75e50),
shirtDark: material(0xa8443d),
pants: material(0x314a5d),
shoes: material(0xf2eadb),
silver: material(0xaeb8b9, 0.3, 0.72),
oldMetal: material(0x795b47, 0.9, 0.15),
black: material(0x253033),
white: material(0xfff7e7)
};
function mesh(geometry, mat, position, parent = scene) {
const object = new THREE.Mesh(geometry, mat);
if (position) object.position.set(...position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(size, mat, position, parent = scene) {
return mesh(new THREE.BoxGeometry(...size), mat, position, parent);
}
const UP = new THREE.Vector3(0, 1, 0);
function cylinderBetween(a, b, radiusBottom, radiusTop, mat, segments = 8, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const object = mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, length, segments),
mat,
null,
parent
);
object.position.copy(start).add(end).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(UP, direction.normalize());
return object;
}
function polygonDecal(points, color, z, parent) {
const shape = new THREE.Shape();
points.forEach(([x, y], index) => {
if (index === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
});
shape.closePath();
const decal = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
new THREE.MeshBasicMaterial({
color,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -2
})
);
decal.position.z = z;
decal.renderOrder = 3;
parent.add(decal);
return decal;
}
// -------------------------------------------------------------------------
// Warm diorama platform
// -------------------------------------------------------------------------
const floor = mesh(
new THREE.PlaneGeometry(40, 40),
M.floor,
[0, -0.14, 0]
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const platform = mesh(
new THREE.CylinderGeometry(4.05, 4.12, 0.16, 48),
M.platform,
[0, -0.06, 0]
);
platform.castShadow = false;
const platformRim = mesh(
new THREE.TorusGeometry(4.04, 0.045, 6, 64),
M.platformEdge,
[0, -0.02, 0]
);
platformRim.rotation.x = Math.PI / 2;
platformRim.castShadow = false;
// -------------------------------------------------------------------------
// Toy wagon
// -------------------------------------------------------------------------
const wagon = new THREE.Group();
scene.add(wagon);
box([2.55, 0.18, 1.34], M.redDark, [0, 1.02, 0], wagon);
// Slatted interior floor.
for (let i = 0; i < 5; i++) {
box(
[2.38, 0.055, 0.21],
i % 2 ? M.wood : M.cream,
[0, 1.135, -0.49 + i * 0.245],
wagon
);
}
// Long side panels.
for (const z of [-0.66, 0.66]) {
box([2.5, 0.55, 0.12], M.cream, [0, 1.42, z], wagon);
box([2.62, 0.12, 0.16], M.red, [0, 1.72, z], wagon);
box([2.55, 0.09, 0.14], M.redDark, [0, 1.16, z], wagon);
// Simple wood-grain strips.
for (const x of [-0.72, 0.1, 0.75]) {
box(
[0.62, 0.025, 0.012],
M.wood,
[x, 1.43, z + Math.sign(z) * 0.066],
wagon
);
}
}
// End panels.
for (const x of [-1.26, 1.26]) {
box([0.12, 0.56, 1.3], M.red, [x, 1.42, 0], wagon);
box([0.17, 0.1, 1.38], M.cream, [x, 1.7, 0], wagon);
}
// A cheerful sun emblem on the visible side.
const sun = mesh(
new THREE.CircleGeometry(0.17, 12),
M.gold,
[-0.55, 1.43, 0.727],
wagon
);
sun.castShadow = false;
for (let i = 0; i < 8; i++) {
const a = (i / 8) * Math.PI * 2;
const ray = box(
[0.035, 0.105, 0.018],
M.gold,
[
-0.55 + Math.cos(a) * 0.235,
1.43 + Math.sin(a) * 0.235,
0.731
],
wagon
);
ray.rotation.z = a - Math.PI / 2;
ray.castShadow = false;
}
// Pull handle.
cylinderBetween(
[-1.28, 1.21, -0.43],
[-2.08, 1.12, -0.43],
0.055,
0.055,
M.redDark,
8,
wagon
);
cylinderBetween(
[-1.28, 1.21, 0.43],
[-2.08, 1.12, 0.43],
0.055,
0.055,
M.redDark,
8,
wagon
);
cylinderBetween(
[-2.08, 1.12, -0.46],
[-2.08, 1.12, 0.46],
0.06,
0.06,
M.red,
8,
wagon
);
// -------------------------------------------------------------------------
// Original wheel and replacement axle
// -------------------------------------------------------------------------
function makeWheel(x, z, original = false) {
const group = new THREE.Group();
group.position.set(x, 0.62, z);
group.rotation.z = original ? -0.16 : x * 0.1;
group.userData.wheel = true;
scene.add(group);
const rim = mesh(
new THREE.CylinderGeometry(0.56, 0.56, 0.22, 16),
M.wheel,
null,
group
);
rim.rotation.x = Math.PI / 2;
const face = mesh(
new THREE.CircleGeometry(0.49, 24),
M.wheelFace,
[0, 0, 0.116],
group
);
face.castShadow = false;
const outerRing = mesh(
new THREE.TorusGeometry(0.49, 0.035, 5, 20),
M.wheelEdge,
[0, 0, 0.139],
group
);
outerRing.castShadow = false;
const hub = mesh(
new THREE.CylinderGeometry(0.145, 0.145, 0.31, 10),
M.hub,
[0, 0, 0.015],
group
);
hub.rotation.x = Math.PI / 2;
// Small recessed dots around the old wheel.
for (let i = 0; i < 8; i++) {
const a = (i / 8) * Math.PI * 2 + 0.1;
const dot = new THREE.Mesh(
new THREE.CircleGeometry(0.026, 8),
new THREE.MeshBasicMaterial({ color: 0xa66f2c })
);
dot.position.set(
Math.cos(a) * 0.345,
Math.sin(a) * 0.345,
0.143
);
group.add(dot);
}
if (original) {
// The old red zigzag brush mark.
polygonDecal(
[
[-0.37, 0.19],
[-0.21, 0.27],
[-0.05, 0.12],
[0.12, 0.18],
[0.31, 0.02],
[0.36, 0.08],
[0.14, 0.27],
[-0.02, 0.2],
[-0.19, 0.34],
[-0.39, 0.25]
],
0xc94e42,
0.153,
group
);
// The faded blue scuff.
polygonDecal(
[
[0.04, -0.32],
[0.18, -0.27],
[0.33, -0.12],
[0.28, -0.07],
[0.13, -0.19],
[0.0, -0.23]
],
0x3d8fa3,
0.154,
group
);
// Tiny paint chips exposing the wood beneath.
polygonDecal(
[
[-0.36, -0.03],
[-0.29, 0.015],
[-0.31, 0.065],
[-0.37, 0.045]
],
0x9b6738,
0.157,
group
);
polygonDecal(
[
[0.39, 0.17],
[0.45, 0.13],
[0.43, 0.2],
[0.385, 0.22]
],
0xa66d3b,
0.157,
group
);
}
return group;
}
makeWheel(1.0, 0.79, true);
makeWheel(-0.66, 0.79, false);
makeWheel(1.0, -0.79, false);
makeWheel(-0.66, -0.79, false);
// New silver axle running through the repaired wheel.
cylinderBetween(
[1.0, 0.62, -0.86],
[1.0, 0.62, 1.075],
0.052,
0.052,
M.silver,
10
);
const axleCollar = mesh(
new THREE.CylinderGeometry(0.09, 0.09, 0.12, 8),
M.silver,
[1.0, 0.62, 0.99]
);
axleCollar.rotation.x = Math.PI / 2;
const nut = mesh(
new THREE.CylinderGeometry(0.085, 0.085, 0.07, 6),
M.silver,
[1.0, 0.62, 1.055]
);
nut.rotation.x = Math.PI / 2;
// -------------------------------------------------------------------------
// Family member kneeling beside the wagon
// -------------------------------------------------------------------------
const person = new THREE.Group();
scene.add(person);
const hips = [2.08, 0.87, 1.36];
const shoulders = [1.76, 1.52, 1.22];
// Torso, leaning toward the repaired wheel.
cylinderBetween(
hips,
shoulders,
0.43,
0.33,
M.shirt,
7,
person
);
const pelvis = mesh(
new THREE.DodecahedronGeometry(0.38, 0),
M.pants,
hips,
person
);
pelvis.scale.set(1, 0.75, 0.85);
// Kneeling legs.
cylinderBetween(
[2.03, 0.84, 1.37],
[2.57, 0.36, 1.62],
0.23,
0.18,
M.pants,
7,
person
);
cylinderBetween(
[2.57, 0.36, 1.62],
[2.82, 0.18, 1.96],
0.17,
0.13,
M.pants,
7,
person
);
const rightShoe = box(
[0.39, 0.16, 0.22],
M.shoes,
[2.91, 0.13, 2.01],
person
);
rightShoe.rotation.y = -0.38;
cylinderBetween(
[2.02, 0.84, 1.37],
[1.78, 0.36, 1.64],
0.22,
0.17,
M.pants,
7,
person
);
cylinderBetween(
[1.78, 0.36, 1.64],
[1.48, 0.19, 1.89],
0.16,
0.12,
M.pants,
7,
person
);
const leftShoe = box(
[0.36, 0.15, 0.21],
M.shoes,
[1.41, 0.13, 1.93],
person
);
leftShoe.rotation.y = 0.15;
// Neck.
cylinderBetween(
[1.7, 1.55, 1.2],
[1.62, 1.73, 1.19],
0.13,
0.13,
M.skin,
8,
person
);
// Head turned slightly toward the viewer while working.
const head = new THREE.Group();
head.position.set(1.59, 1.98, 1.18);
head.rotation.y = 0.82;
person.add(head);
const face = mesh(
new THREE.IcosahedronGeometry(0.31, 1),
M.skin,
[0, 0, 0],
head
);
face.scale.set(0.95, 1.08, 0.92);
// Low-poly hair cap.
const hairCap = mesh(
new THREE.SphereGeometry(0.322, 9, 5, 0, Math.PI * 2, 0, 1.45),
M.hair,
[0, 0.045, -0.025],
head
);
hairCap.scale.set(1, 0.95, 0.94);
// Ponytail and tie.
const tail = mesh(
new THREE.IcosahedronGeometry(0.18, 0),
M.hair,
[0.02, -0.19, -0.34],
head
);
tail.scale.set(0.72, 1.35, 0.72);
tail.rotation.z = -0.12;
const tie = mesh(
new THREE.TorusGeometry(0.09, 0.026, 5, 10),
M.gold,
[0.01, -0.08, -0.29],
head
);
tie.rotation.x = Math.PI / 2;
// Ears.
for (const x of [-0.29, 0.29]) {
const ear = mesh(
new THREE.IcosahedronGeometry(0.075, 0),
M.skin,
[x, -0.015, 0],
head
);
ear.scale.set(0.65, 1, 0.8);
}
// Eyes.
for (const x of [-0.095, 0.095]) {
const eye = mesh(
new THREE.SphereGeometry(0.026, 7, 5),
M.black,
[x, 0.035, 0.273],
head
);
eye.castShadow = false;
}
// Nose.
const nose = mesh(
new THREE.ConeGeometry(0.055, 0.13, 4),
M.skin,
[0, -0.025, 0.295],
head
);
nose.rotation.x = Math.PI / 2;
// Small smile.
const smile = box(
[0.11, 0.016, 0.018],
M.shirtDark,
[0, -0.115, 0.273],
head
);
smile.rotation.z = -0.08;
// Arms: coral sleeves, bare forearms, hands at the axle.
const armData = [
{
shoulder: [1.61, 1.49, 1.14],
elbow: [1.38, 1.15, 1.02],
hand: [1.08, 0.78, 0.91]
},
{
shoulder: [1.9, 1.48, 1.29],
elbow: [1.58, 1.08, 1.12],
hand: [1.035, 0.61, 1.015]
}
];
for (const arm of armData) {
cylinderBetween(
arm.shoulder,
arm.elbow,
0.145,
0.115,
M.shirt,
7,
person
);
cylinderBetween(
arm.elbow,
arm.hand,
0.105,
0.075,
M.skin,
7,
person
);
const hand = mesh(
new THREE.DodecahedronGeometry(0.12, 0),
M.skin,
arm.hand,
person
);
hand.scale.set(1, 0.8, 0.9);
}
// Collar detail.
const collar = mesh(
new THREE.TorusGeometry(0.17, 0.035, 5, 10),
M.shirtDark,
[1.72, 1.56, 1.22],
person
);
collar.rotation.x = Math.PI / 2;
collar.rotation.z = -0.25;
// -------------------------------------------------------------------------
// Small family/playroom props
// -------------------------------------------------------------------------
function toyBlock(position, size, colorMat) {
const group = new THREE.Group();
group.position.set(...position);
scene.add(group);
box([size, size, size], colorMat, [0, size / 2, 0], group);
for (const x of [-size * 0.24, size * 0.24]) {
for (const z of [-size * 0.24, size * 0.24]) {
const stud = mesh(
new THREE.CylinderGeometry(size * 0.105, size * 0.105, size * 0.12, 10),
colorMat,
[x, size + size * 0.055, z],
group
);
stud.castShadow = false;
}
}
return group;
}
toyBlock([-2.25, 0.02, 0.78], 0.39, material(0x5e91a2));
toyBlock([-2.68, 0.02, 1.2], 0.32, material(0xd77858));
toyBlock([-1.86, 0.02, 1.5], 0.3, material(0xe2b34d));
// The old rusty axle segment, set aside on the floor.
cylinderBetween(
[-0.32, 0.105, 1.48],
[0.42, 0.105, 1.58],
0.038,
0.038,
M.oldMetal,
7
);
// Small wrench beside the repair.
const wrench = new THREE.Group();
wrench.position.set(0.7, 0.075, 1.75);
wrench.rotation.y = -0.55;
scene.add(wrench);
box([0.48, 0.055, 0.12], M.silver, [0, 0, 0], wrench);
box([0.12, 0.055, 0.23], M.silver, [0.27, 0, -0.09], wrench);
box([0.12, 0.055, 0.23], M.silver, [0.27, 0, 0.09], wrench);
// A few floor flecks keep the setting tactile without becoming busy.
for (let i = 0; i < 16; i++) {
const a = (i / 16) * Math.PI * 2 + 0.3;
const r = 2.9 + (i % 3) * 0.2;
const fleck = box(
[0.045, 0.018, 0.045],
i % 2 ? M.wood : M.cream,
[Math.cos(a) * r, 0.035, Math.sin(a) * r]
);
fleck.rotation.y = a;
fleck.castShadow = false;
}
// -------------------------------------------------------------------------
// Camera controls — implemented directly, without camera-control addons
// -------------------------------------------------------------------------
const defaultTarget = new THREE.Vector3(0.18, 0.87, 0.18);
const cameraTarget = defaultTarget.clone();
let radius = innerWidth < 700 ? 8.8 : 7.45;
let theta = 0.62;
let phi = 1.14;
let autoOrbit = false;
let tween = null;
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
function applyCamera() {
spherical.set(radius, phi, theta);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
}
function moveCamera(target, newRadius, newTheta, newPhi, duration = 750) {
const delta = ((newTheta - theta + Math.PI) % (Math.PI * 2) + Math.PI * 2) %
(Math.PI * 2) - Math.PI;
tween = {
elapsed: 0,
duration,
fromTarget: cameraTarget.clone(),
toTarget: target.clone(),
fromRadius: radius,
toRadius: newRadius,
fromTheta: theta,
toTheta: theta + delta,
fromPhi: phi,
toPhi: newPhi
};
}
function resetView() {
moveCamera(
defaultTarget,
innerWidth < 700 ? 8.8 : 7.45,
0.62,
1.14
);
}
function focusWheel() {
moveCamera(
new THREE.Vector3(1.0, 0.64, 0.78),
2.75,
0.38,
1.22
);
}
const pointers = new Map();
let pinchDistance = 0;
const canvas = renderer.domElement;
canvas.tabIndex = 0;
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
tween = null;
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi - dy * 0.005, 0.38, 1.48);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
radius = THREE.MathUtils.clamp(
radius * (pinchDistance / distance),
2.25,
12
);
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
tween = null;
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
2.25,
12
);
},
{ passive: false }
);
// Double-click the original wheel to inspect its paint marks.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
canvas.addEventListener("dblclick", event => {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(scene.children, true);
const wheelHit = hits.find(hit => hit.object.userData.wheel);
if (wheelHit) focusWheel();
});
addEventListener("keydown", event => {
const step = 0.08;
let handled = true;
switch (event.key) {
case "ArrowLeft":
theta += step;
break;
case "ArrowRight":
theta -= step;
break;
case "ArrowUp":
phi = Math.max(0.38, phi - step * 0.7);
break;
case "ArrowDown":
phi = Math.min(1.48, phi + step * 0.7);
break;
case "+":
case "=":
radius = Math.max(2.25, radius - 0.35);
break;
case "-":
radius = Math.min(12, radius + 0.35);
break;
case "0":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
tween = null;
}
});
document.querySelector("#resetView").addEventListener("click", resetView);
document.querySelector("#focusWheel").addEventListener("click", focusWheel);
const orbitButton = document.querySelector("#toggleOrbit");
orbitButton.addEventListener("click", () => {
autoOrbit = !autoOrbit;
orbitButton.classList.toggle("active", autoOrbit);
orbitButton.setAttribute("aria-pressed", String(autoOrbit));
tween = null;
});
// -------------------------------------------------------------------------
// Screen-space wheel annotation
// -------------------------------------------------------------------------
const pin = document.querySelector("#pin");
const pinAnchor = new THREE.Vector3(1.0, 0.72, 0.93);
const projectedPin = new THREE.Vector3();
function updatePin() {
projectedPin.copy(pinAnchor).project(camera);
const visible =
projectedPin.z > -1 &&
projectedPin.z < 1 &&
Math.abs(projectedPin.x) < 1.2 &&
Math.abs(projectedPin.y) < 1.2;
pin.classList.toggle("visible", visible);
if (visible) {
pin.style.transform = `translate(
${(projectedPin.x * 0.5 + 0.5) * innerWidth}px,
${(-projectedPin.y * 0.5 + 0.5) * innerHeight}px
)`;
}
}
// -------------------------------------------------------------------------
// Animation and resize
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (tween) {
tween.elapsed += dt * 1000;
const raw = Math.min(tween.elapsed / tween.duration, 1);
const eased = raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
cameraTarget.lerpVectors(tween.fromTarget, tween.toTarget, eased);
radius = THREE.MathUtils.lerp(tween.fromRadius, tween.toRadius, eased);
theta = THREE.MathUtils.lerp(tween.fromTheta, tween.toTheta, eased);
phi = THREE.MathUtils.lerp(tween.fromPhi, tween.toPhi, eased);
if (raw >= 1) tween = null;
} else if (autoOrbit) {
theta += dt * 0.12;
}
applyCamera();
renderer.render(scene, camera);
updatePin();
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
applyCamera();
renderer.render(scene, camera);
document.body.classList.add("ready");
animate();
</script>
</body>
</html>
```