Prompt specification
Build or customize the Three.js 3D scene "Broken picture-frame repair" 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: Broken picture-frame repair
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/broken-picture-frame-repair-x0267
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Build a repair bench with separated frame corner, alignment jig, clamps, and glue marker; restoration follows cleaning, alignment, holding, and release as distinct visible stages.
Working Three.js Starter (broken-picture-frame-repair-x0267):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Frame Restoration</title>
<style>
:root {
--ink: #f6f1e7;
--muted: #aeb7c2;
--cyan: #58e0d2;
--orange: #ffad5c;
--red: #ff7568;
--green: #7be495;
--panel: rgba(20, 25, 34, 0.84);
--line: rgba(255, 255, 255, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #111720;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
user-select: none;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.intro {
position: absolute;
top: 24px;
left: 24px;
width: min(370px, calc(100vw - 48px));
padding: 20px 22px 19px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.led {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
h1 {
margin: 10px 0 7px;
font-size: clamp(27px, 3vw, 39px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.steps {
position: absolute;
top: 248px;
left: 24px;
width: 286px;
padding: 9px;
border-radius: 17px;
pointer-events: auto;
}
.step {
width: 100%;
border: 0;
border-radius: 12px;
padding: 11px 12px;
display: grid;
grid-template-columns: 34px 1fr 12px;
align-items: center;
gap: 10px;
color: var(--muted);
background: transparent;
text-align: left;
cursor: pointer;
transition: 180ms ease;
}
.step:hover {
color: var(--ink);
background: rgba(255, 255, 255, 0.045);
}
.step.active {
color: var(--ink);
background: rgba(88, 224, 210, 0.1);
}
.step-index {
font-size: 11px;
font-weight: 900;
letter-spacing: 0.08em;
color: #727e8b;
}
.step.active .step-index {
color: var(--cyan);
}
.step b,
.step small {
display: block;
}
.step b {
font-size: 13px;
margin-bottom: 2px;
}
.step small {
font-size: 10px;
color: #7f8995;
}
.step-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #434b56;
transition: 180ms ease;
}
.step.active .step-dot {
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
.step.done .step-dot {
background: var(--green);
}
.status {
position: absolute;
top: 24px;
right: 24px;
width: min(320px, calc(100vw - 48px));
padding: 17px 18px;
border-radius: 18px;
}
.status-top {
display: flex;
justify-content: space-between;
align-items: center;
color: #7f8995;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#state {
color: var(--cyan);
}
#current-title {
margin: 12px 0 6px;
font-size: 19px;
letter-spacing: -0.02em;
}
#current-copy {
min-height: 42px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.dock {
position: absolute;
left: 50%;
bottom: 23px;
transform: translateX(-50%);
width: min(710px, calc(100vw - 32px));
padding: 12px;
border-radius: 18px;
pointer-events: auto;
display: grid;
grid-template-columns: auto auto 1fr auto;
align-items: center;
gap: 10px;
}
.control {
height: 42px;
min-width: 42px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.055);
color: var(--ink);
cursor: pointer;
transition: 150ms ease;
}
.control:hover {
background: rgba(255, 255, 255, 0.11);
border-color: rgba(255, 255, 255, 0.22);
}
#play {
width: 49px;
border-color: rgba(88, 224, 210, 0.38);
color: var(--cyan);
background: rgba(88, 224, 210, 0.12);
font-size: 17px;
}
.timeline-wrap {
min-width: 0;
padding: 0 6px;
}
.timeline-meta {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: #7f8995;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.track {
position: relative;
height: 6px;
border-radius: 8px;
background: #303743;
cursor: pointer;
}
#fill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), #a5f5d0);
box-shadow: 0 0 12px rgba(88, 224, 210, 0.32);
}
.tick {
position: absolute;
top: -3px;
width: 2px;
height: 12px;
border-radius: 2px;
background: #66717d;
transform: translateX(-1px);
}
.camera-hint {
position: absolute;
right: 25px;
bottom: 97px;
padding: 8px 11px;
border-radius: 10px;
color: rgba(255, 255, 255, 0.62);
background: rgba(12, 16, 23, 0.58);
border: 1px solid rgba(255, 255, 255, 0.09);
font-size: 10px;
letter-spacing: 0.05em;
}
.annotation {
position: absolute;
z-index: 3;
display: flex;
align-items: center;
gap: 7px;
transform: translate(-50%, -100%);
transition: opacity 160ms ease;
filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45));
}
.annotation::after {
content: "";
position: absolute;
left: 7px;
top: 100%;
width: 1px;
height: 22px;
background: linear-gradient(rgba(255, 255, 255, 0.65), transparent);
}
.annotation i {
width: 7px;
height: 7px;
border-radius: 2px;
background: #b9c4cc;
box-shadow: 0 0 0 3px rgba(185, 196, 204, 0.13);
}
.annotation span {
padding: 5px 8px;
border-radius: 6px;
background: rgba(14, 18, 25, 0.78);
border: 1px solid rgba(255, 255, 255, 0.13);
color: #dbe2e8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
}
.annotation.active i {
background: var(--cyan);
box-shadow: 0 0 0 3px rgba(88, 224, 210, 0.16), 0 0 13px var(--cyan);
}
.annotation.active span {
color: var(--cyan);
border-color: rgba(88, 224, 210, 0.34);
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.intro p {
display: none;
}
.steps {
top: auto;
bottom: 99px;
left: 12px;
width: calc(100vw - 24px);
display: grid;
grid-template-columns: repeat(4, 1fr);
padding: 6px;
}
.step {
display: block;
padding: 9px 6px;
text-align: center;
}
.step-index,
.step small,
.step-dot {
display: none;
}
.step b {
font-size: 10px;
}
.status {
top: 116px;
right: 12px;
width: 220px;
padding: 12px 14px;
}
#current-copy {
display: none;
}
.dock {
bottom: 12px;
grid-template-columns: auto auto 1fr;
}
#home {
display: none;
}
.camera-hint {
display: none;
}
.annotation span {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel repair bench"></canvas>
<div class="ui">
<section class="intro glass">
<div class="eyebrow"><span class="led"></span> Voxel workshop / Bay 04</div>
<h1>Frame corner<br />restoration</h1>
<p>A four-stage repair sequence on a voxel workbench. Drag to orbit, scroll to zoom, or use the stage controls.</p>
</section>
<nav class="steps glass" id="steps" aria-label="Restoration stages">
<button class="step active" data-stage="0">
<span class="step-index">01</span>
<span><b>Clean</b><small>Lift loose grime</small></span>
<span class="step-dot"></span>
</button>
<button class="step" data-stage="1">
<span class="step-index">02</span>
<span><b>Align</b><small>Seat in the jig</small></span>
<span class="step-dot"></span>
</button>
<button class="step" data-stage="2">
<span class="step-index">03</span>
<span><b>Hold</b><small>Clamp and glue</small></span>
<span class="step-dot"></span>
</button>
<button class="step" data-stage="3">
<span class="step-index">04</span>
<span><b>Release</b><small>Set the repair</small></span>
<span class="step-dot"></span>
</button>
</nav>
<section class="status glass">
<div class="status-top">
<span>Current operation</span>
<span id="state">01 / 04</span>
</div>
<h2 id="current-title">Surface cleaning</h2>
<p id="current-copy">A block brush lifts the loose grime from the separated wooden corner.</p>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
<section class="dock glass">
<button class="control" id="play" title="Play or pause">Ⅱ</button>
<button class="control" id="reset" title="Restart">↺</button>
<div class="timeline-wrap">
<div class="timeline-meta">
<span>Restoration sequence</span>
<span id="time">00:00 / 00:16</span>
</div>
<div class="track" id="track">
<div id="fill"></div>
</div>
</div>
<button class="control" id="home" title="Reset camera">⌂</button>
</section>
<div class="annotation active" id="label-frame"><i></i><span>Detached corner</span></div>
<div class="annotation" id="label-jig"><i></i><span>Alignment jig</span></div>
<div class="annotation" id="label-clamps"><i></i><span>Pressure clamps</span></div>
<div class="annotation" id="label-marker"><i></i><span>Glue marker</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";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
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 scene = new THREE.Scene();
scene.background = new THREE.Color(0x141a24);
scene.fog = new THREE.Fog(0x141a24, 18, 34);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
70
);
const hemi = new THREE.HemisphereLight(0xbad9ee, 0x3b2a20, 2.15);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffe0b5, 3.8);
key.position.set(6, 12, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -10;
key.shadow.camera.right = 10;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -10;
key.shadow.camera.near = 1;
key.shadow.camera.far = 30;
key.shadow.bias = -0.0005;
scene.add(key);
const fill = new THREE.DirectionalLight(0x6bc5dc, 1.45);
fill.position.set(-7, 6, 4);
scene.add(fill);
const stageLight = new THREE.PointLight(0xffbd6a, 12, 9, 2);
stageLight.position.set(0, 6, 1);
scene.add(stageLight);
// ------------------------------------------------------------
// Materials and box helper
// ------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.05,
...options
});
}
const M = {
floor: standard(0x27313a),
floorA: standard(0x2c3741),
floorB: standard(0x222b34),
wall: standard(0x252d37),
board: standard(0x574235),
boardEdge: standard(0x2d211c),
bench: standard(0x76503a),
benchDark: standard(0x3c2a22),
benchEdge: standard(0x241b18),
steel: standard(0x52616b, { metalness: 0.62, roughness: 0.36 }),
steelDark: standard(0x303b44, { metalness: 0.66, roughness: 0.4 }),
silver: standard(0xa8b5ba, { metalness: 0.76, roughness: 0.25 }),
cyan: standard(0x50d9cd, {
emissive: 0x1b776e,
emissiveIntensity: 0.45,
metalness: 0.2,
roughness: 0.32
}),
red: standard(0xc94f47, { metalness: 0.16, roughness: 0.48 }),
redDark: standard(0x71312f),
orange: standard(0xf5a33f),
orangeDark: standard(0x9b5e24),
blue: standard(0x4b90c4),
navy: standard(0x233c57),
cream: standard(0xeee4ca),
green: standard(0x65d987, {
emissive: 0x23793b,
emissiveIntensity: 0.65
}),
black: standard(0x15191e),
glue: standard(0xffb33c, {
emissive: 0x9b4c08,
emissiveIntensity: 0.4,
roughness: 0.28
})
};
function box(w, h, d, x, y, z, material, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(x = 0, y = 0, z = 0, parent = scene) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
let seed = 9047;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
// ------------------------------------------------------------
// Workshop
// ------------------------------------------------------------
box(19, 0.3, 15, 0, -0.2, 0, M.floor);
for (let x = -8; x <= 8; x += 2) {
for (let z = -6; z <= 6; z += 2) {
const tileMaterial = random() > 0.5 ? M.floorA : M.floorB;
box(1.96, 0.055, 1.96, x, -0.02, z, tileMaterial);
}
}
box(15.5, 7.2, 0.32, 0, 3.5, -5.8, M.wall);
box(11.5, 4.7, 0.14, 0, 4.25, -5.56, M.board);
box(11.7, 0.16, 0.2, 0, 6.66, -5.48, M.boardEdge);
box(11.7, 0.16, 0.2, 0, 1.84, -5.48, M.boardEdge);
const holeGeometry = new THREE.BoxGeometry(0.075, 0.075, 0.045);
const holeMaterial = standard(0x241c19);
const holes = new THREE.InstancedMesh(holeGeometry, holeMaterial, 112);
const holeMatrix = new THREE.Matrix4();
let holeIndex = 0;
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 16; col++) {
holeMatrix.makeTranslation(
-4.875 + col * 0.65,
2.5 + row * 0.5,
-5.455
);
holes.setMatrixAt(holeIndex++, holeMatrix);
}
}
holes.receiveShadow = true;
scene.add(holes);
// Pegboard tools.
box(0.16, 1.55, 0.16, -3.65, 4.6, -5.28, M.orangeDark);
box(0.85, 0.28, 0.3, -3.65, 5.45, -5.25, M.steel);
box(0.58, 0.18, 0.16, -2.35, 4.55, -5.3, M.silver);
box(0.22, 0.62, 0.16, -2.48, 4.85, -5.3, M.silver);
box(0.22, 0.62, 0.16, -2.2, 4.85, -5.3, M.silver);
box(2.7, 0.18, 0.75, 2.9, 3.05, -5.25, M.benchDark);
for (let i = 0; i < 3; i++) {
const x = 2.15 + i * 0.75;
box(0.52, 0.62, 0.48, x, 3.43, -5.23, i === 1 ? M.cyan : M.cream);
box(0.56, 0.08, 0.52, x, 3.77, -5.23, M.steelDark);
}
function makeWallSign(text) {
const c = document.createElement("canvas");
c.width = 768;
c.height = 160;
const ctx = c.getContext("2d");
ctx.fillStyle = "#1b252c";
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = "#55d8cd";
ctx.lineWidth = 8;
ctx.strokeRect(9, 9, c.width - 18, c.height - 18);
ctx.fillStyle = "#f5edda";
ctx.font = "900 64px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 3);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(3.15, 0.66),
new THREE.MeshBasicMaterial({ map: texture })
);
sign.position.set(1.65, 5.55, -5.35);
scene.add(sign);
}
makeWallSign("FRAME LAB");
// ------------------------------------------------------------
// Repair bench
// ------------------------------------------------------------
box(10.2, 0.42, 5.45, 0, 2.67, 0, M.bench);
box(10.25, 0.18, 0.2, 0, 2.77, 2.72, M.benchEdge);
box(10.25, 0.18, 0.2, 0, 2.77, -2.72, M.benchEdge);
for (let z = -2; z <= 2; z += 1) {
box(10.05, 0.025, 0.035, 0, 2.895, z, M.benchDark);
}
for (const x of [-4.35, 4.35]) {
for (const z of [-2.05, 2.05]) {
box(0.46, 2.55, 0.46, x, 1.22, z, M.benchDark);
box(0.58, 0.18, 0.58, x, 0.08, z, M.benchEdge);
}
}
box(8.5, 0.35, 0.24, 0, 2.33, 2.14, M.benchDark);
box(8.5, 0.35, 0.24, 0, 2.33, -2.14, M.benchDark);
// Drawer cabinet.
box(1.75, 2.15, 3.75, -3.25, 1.37, 0.05, M.benchDark);
for (let i = 0; i < 3; i++) {
const y = 0.6 + i * 0.68;
box(1.53, 0.54, 0.12, -3.25, y, 1.98, M.bench);
box(0.42, 0.08, 0.11, -3.25, y + 0.03, 2.08, M.silver);
}
// Lower shelf and storage.
box(4.65, 0.18, 3.75, 1.55, 0.52, 0.05, M.benchDark);
box(1.2, 0.85, 1.15, 0.85, 1.02, -0.25, M.cream);
box(0.9, 0.7, 0.9, 2.35, 0.95, 0.35, M.navy);
box(1.05, 0.58, 1.0, 3.35, 0.88, -0.35, M.orangeDark);
// Small parts tray.
box(1.55, 0.1, 0.8, 3.55, 2.98, 1.75, M.steelDark);
box(0.12, 0.28, 0.72, 2.8, 3.1, 1.75, M.steel);
box(0.12, 0.28, 0.72, 4.3, 3.1, 1.75, M.steel);
box(1.45, 0.28, 0.1, 3.55, 3.1, 2.12, M.steel);
box(1.45, 0.28, 0.1, 3.55, 3.1, 1.38, M.steel);
// ------------------------------------------------------------
// Alignment jig
// ------------------------------------------------------------
const jig = group();
box(3.85, 0.18, 3.85, 0.3, 2.99, 0.3, M.steelDark, jig);
box(3.55, 0.045, 3.55, 0.3, 3.105, 0.3, M.steel, jig);
// Square locator at the final frame origin.
box(0.7, 0.075, 0.7, -1.05, 3.155, -1.05, M.steelDark, jig);
box(0.5, 0.045, 0.5, -1.05, 3.205, -1.05, M.cyan, jig);
// Right-angle guide rails.
box(0.12, 0.16, 3.35, 1.91, 3.2, 0.33, M.cyan, jig);
box(3.35, 0.16, 0.12, 0.33, 3.2, 1.91, M.cyan, jig);
// Locator pins.
for (const p of [
[-1.45, -1.45],
[1.72, -1.45],
[-1.45, 1.72]
]) {
box(0.18, 0.28, 0.18, p[0], 3.25, p[1], M.silver, jig);
box(0.09, 0.09, 0.09, p[0], 3.43, p[1], M.cyan, jig);
}
// Small alignment squares on the jig plate.
for (let x = 0; x < 4; x++) {
for (let z = 0; z < 4; z++) {
if ((x + z) % 2 === 0) {
box(0.23, 0.025, 0.23, -0.92 + x * 0.48, 3.14, -0.72 + z * 0.48, M.steelDark, jig);
}
}
}
const jigGlowMaterial = M.cyan.clone();
jigGlowMaterial.emissiveIntensity = 0.35;
const alignmentLights = [];
for (const p of [[1.91, 3.34, 0.33], [0.33, 3.34, 1.91]]) {
const lightCube = box(0.17, 0.16, 0.17, p[0], p[1], p[2], jigGlowMaterial, jig);
alignmentLights.push(lightCube);
}
// ------------------------------------------------------------
// Separated frame corner
// ------------------------------------------------------------
const frameWoodMaterial = standard(0xc58a4d, {
emissive: 0x5f2e0e,
emissiveIntensity: 0.05,
roughness: 0.7
});
const frameInsetMaterial = standard(0x6f4226);
const frame = group(2.35, 3.13, 0.55);
frame.rotation.y = -0.24;
// Six modular blocks form each arm.
for (let i = 0; i < 6; i++) {
const x = 0.225 + i * 0.45;
box(0.445, 0.42, 0.43, x, 0, 0, frameWoodMaterial, frame);
box(0.31, 0.035, 0.25, x, 0.226, 0, frameInsetMaterial, frame);
const z = 0.225 + i * 0.45;
box(0.43, 0.42, 0.445, 0, 0, z, frameWoodMaterial, frame);
box(0.25, 0.035, 0.31, 0, 0.226, z, frameInsetMaterial, frame);
}
box(0.52, 0.46, 0.52, 0, 0, 0, frameWoodMaterial, frame);
box(0.25, 0.04, 0.25, 0, 0.252, 0, frameInsetMaterial, frame);
const dirtMaterial = standard(0x3d3329, { roughness: 1 });
const dirtPieces = [];
for (let i = 0; i < 22; i++) {
const onHorizontal = i % 3 !== 0;
const p = onHorizontal
? [0.18 + random() * 2.35, 0.245, (random() - 0.5) * 0.28]
: [(random() - 0.5) * 0.28, 0.245, 0.18 + random() * 2.35];
const size = 0.07 + random() * 0.08;
const dirt = box(size, size * 0.65, size, p[0], p[1], p[2], dirtMaterial, frame);
dirt.userData.threshold = (i / 22) * 0.82;
dirtPieces.push(dirt);
}
// ------------------------------------------------------------
// Two voxel clamps
// ------------------------------------------------------------
const clampIndicatorMaterial = standard(0x7be495, {
emissive: 0x226b36,
emissiveIntensity: 0.6
});
// Clamp A grips the vertical arm.
const clampA = group();
box(0.88, 0.18, 0.88, -2.05, 3.02, 0.02, M.redDark, clampA);
box(0.26, 1.18, 0.26, -1.85, 3.63, 0.02, M.red, clampA);
box(1.25, 0.23, 0.32, -1.34, 4.18, 0.02, M.red, clampA);
box(0.2, 0.2, 0.68, -0.79, 4.18, 0.02, M.redDark, clampA);
box(0.18, 0.12, 0.18, -1.85, 4.35, 0.02, M.silver, clampA);
box(0.44, 0.06, 0.44, -1.85, 4.43, 0.02, M.black, clampA);
box(0.16, 0.09, 0.16, -2.27, 3.16, 0.34, clampIndicatorMaterial, clampA);
const jawA = group();
box(0.55, 0.2, 0.66, -1.05, 4.03, 0.02, M.red, jawA);
box(0.5, 0.065, 0.61, -1.05, 3.91, 0.02, M.black, jawA);
scene.add(jawA);
const screwA = box(0.09, 0.12, 0.09, -1.05, 4.02, 0.02, M.silver);
// Clamp B grips the horizontal arm.
const clampB = group();
box(0.88, 0.18, 0.88, 0.08, 3.02, -2.05, M.redDark, clampB);
box(0.26, 1.18, 0.26, 0.08, 3.63, -1.85, M.red, clampB);
box(0.32, 0.23, 1.25, 0.08, 4.18, -1.34, M.red, clampB);
box(0.68, 0.2, 0.2, 0.08, 4.18, -0.79, M.redDark, clampB);
box(0.18, 0.12, 0.18, 0.4, 4.35, -1.85, M.silver, clampB);
box(0.44, 0.06, 0.44, 0.4, 4.43, -1.85, M.black, clampB);
box(0.16, 0.09, 0.16, 0.4, 3.16, -2.27, clampIndicatorMaterial, clampB);
const jawB = group();
box(0.66, 0.2, 0.55, 0.08, 4.03, -1.05, M.red, jawB);
box(0.61, 0.065, 0.5, 0.08, 3.91, -1.05, M.black, jawB);
scene.add(jawB);
const screwB = box(0.09, 0.12, 0.09, 0.08, 4.02, -1.05, M.silver);
// ------------------------------------------------------------
// Glue marker
// ------------------------------------------------------------
const marker = group(2.72, 2.92, -1.68);
box(0.29, 0.73, 0.29, 0, 0.39, 0, M.orange, marker);
box(0.31, 0.18, 0.31, 0, 0.62, 0, M.cream, marker);
box(0.32, 0.16, 0.32, 0, 0.86, 0, M.black, marker);
box(0.18, 0.15, 0.18, 0, 0.055, 0, M.cream, marker);
box(0.1, 0.07, 0.1, 0, -0.035, 0, M.orangeDark, marker);
box(0.055, 0.25, 0.305, 0, 0.39, 0, M.cyan, marker);
marker.rotation.z = -0.05;
const markerRest = marker.position.clone();
// ------------------------------------------------------------
// Cleaning brush
// ------------------------------------------------------------
const brush = group(2.35, 3.73, 0.55);
box(0.17, 0.83, 0.17, 0, 0.68, 0, M.orangeDark, brush);
box(0.82, 0.18, 0.28, 0, 0.22, 0, M.blue, brush);
for (let i = 0; i < 7; i++) {
box(0.055, 0.18, 0.29, -0.31 + i * 0.105, 0.035, 0, M.navy, brush);
}
scene.add(brush);
const dustMaterial = standard(0x9a856d, {
transparent: true,
opacity: 0.65,
roughness: 1
});
const dust = [];
for (let i = 0; i < 18; i++) {
const particle = box(
0.045 + random() * 0.035,
0.045 + random() * 0.035,
0.045 + random() * 0.035,
0,
0,
0,
dustMaterial
);
particle.userData.phase = random();
particle.userData.offset = new THREE.Vector3(
(random() - 0.5) * 0.8,
random() * 0.45,
(random() - 0.5) * 0.6
);
dust.push(particle);
}
// ------------------------------------------------------------
// Glue beads and release beacon
// ------------------------------------------------------------
const glueBeads = [];
const gluePositions = [];
for (let i = 0; i < 8; i++) {
gluePositions.push(new THREE.Vector3(-0.58 + i * 0.27, 3.555, -0.79));
}
for (let i = 0; i < 8; i++) {
gluePositions.push(new THREE.Vector3(-0.79, 3.555, -0.54 + i * 0.27));
}
gluePositions.forEach((p, i) => {
const bead = box(0.105, 0.07, 0.105, p.x, p.y, p.z, M.glue);
bead.scale.setScalar(0.001);
bead.userData.threshold = 0.16 + (i / (gluePositions.length - 1)) * 0.58;
glueBeads.push(bead);
});
const beaconMaterial = standard(0x7be495, {
emissive: 0x3de364,
emissiveIntensity: 1.2
});
const beacon = box(0.25, 0.25, 0.25, 1.93, 3.28, 1.93, beaconMaterial);
beacon.scale.setScalar(0.001);
const beaconLight = new THREE.PointLight(0x6cf18c, 0, 4, 2);
beaconLight.position.set(1.9, 3.6, 1.9);
scene.add(beaconLight);
// ------------------------------------------------------------
// Custom orbit controls (no addons)
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 2.45, 0);
let yaw = 0.72;
let pitch = 0.93;
let radius = 14.3;
let desiredYaw = yaw;
let desiredPitch = pitch;
let desiredRadius = radius;
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
desiredYaw -= dx * 0.006;
desiredPitch = THREE.MathUtils.clamp(desiredPitch - dy * 0.005, 0.48, 1.38);
});
function stopDragging() {
dragging = false;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius + event.deltaY * 0.012,
8.5,
21
);
},
{ passive: false }
);
function homeCamera() {
desiredYaw = 0.72;
desiredPitch = 0.93;
desiredRadius = 14.3;
cameraTarget.set(0, 2.45, 0);
}
canvas.addEventListener("dblclick", homeCamera);
function updateCamera() {
yaw += (desiredYaw - yaw) * 0.12;
pitch += (desiredPitch - pitch) * 0.12;
radius += (desiredRadius - radius) * 0.12;
camera.position.set(
cameraTarget.x + radius * Math.sin(pitch) * Math.sin(yaw),
cameraTarget.y + radius * Math.cos(pitch),
cameraTarget.z + radius * Math.sin(pitch) * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
// ------------------------------------------------------------
// Restoration timeline
// ------------------------------------------------------------
const stages = [
{
start: 0,
duration: 4.2,
title: "Surface cleaning",
copy: "A block brush lifts the loose grime from the separated wooden corner."
},
{
start: 4.2,
duration: 4.0,
title: "Corner alignment",
copy: "The cleaned corner is lifted, rotated, and seated against the right-angle locator."
},
{
start: 8.2,
duration: 4.2,
title: "Clamped adhesive bond",
copy: "Two clamps lock the joint while the glue marker lays a continuous orange bead."
},
{
start: 12.4,
duration: 3.6,
title: "Pressure release",
copy: "The clamps open, the repaired corner remains seated, and the new bond is left to set."
}
];
const totalDuration = stages[stages.length - 1].start + stages[stages.length - 1].duration;
let timeline = 0.15;
let playing = true;
let previousStage = -1;
const clamp01 = (v) => THREE.MathUtils.clamp(v, 0, 1);
const ease = (v) => {
const x = clamp01(v);
return x * x * (3 - 2 * x);
};
const range = (a, b, v) => ease((v - a) / (b - a));
const initPosition = new THREE.Vector3(2.35, 3.13, 0.55);
const finalPosition = new THREE.Vector3(-1.05, 3.31, -1.05);
const markerStart = new THREE.Vector3(0.05, 3.57, -0.79);
const markerCorner = new THREE.Vector3(-0.79, 3.57, -0.79);
const markerEnd = new THREE.Vector3(-0.79, 3.57, 1.35);
function currentStageIndex(t) {
for (let i = stages.length - 1; i >= 0; i--) {
if (t >= stages[i].start) return i;
}
return 0;
}
function setTimeline(value, pause = true) {
timeline = THREE.MathUtils.clamp(value, 0, totalDuration);
if (pause) playing = false;
}
function animateScene(t) {
const cleanP = clamp01(t / stages[0].duration);
const alignP = clamp01((t - stages[1].start) / stages[1].duration);
const holdP = clamp01((t - stages[2].start) / stages[2].duration);
const releaseP = clamp01((t - stages[3].start) / stages[3].duration);
// Cleaning: brush motion and progressive grime removal.
for (let i = 0; i < dirtPieces.length; i++) {
const dirt = dirtPieces[i];
const threshold = dirt.userData.threshold;
const scale = 1 - range(threshold, threshold + 0.14, cleanP);
dirt.scale.setScalar(Math.max(0.001, scale));
}
const cleaningVisible = t < stages[1].start + 0.82;
brush.visible = cleaningVisible;
if (t < stages[1].start) {
brush.position.set(
initPosition.x + Math.sin(t * 5.2) * 0.6,
3.75 + Math.sin(t * 10) * 0.045,
initPosition.z + Math.sin(t * 3.1) * 0.22
);
brush.rotation.z = Math.sin(t * 7) * 0.1;
} else {
const returnP = clamp01((t - stages[1].start) / 0.82);
brush.position.lerpVectors(
new THREE.Vector3(initPosition.x, 3.75, initPosition.z),
new THREE.Vector3(3.25, 3.08, 1.75),
ease(returnP)
);
brush.rotation.z = THREE.MathUtils.lerp(0, -1.25, ease(returnP));
}
for (let i = 0; i < dust.length; i++) {
const particle = dust[i];
const phase = (t * 1.8 + particle.userData.phase) % 1;
const visible = t < stages[1].start;
particle.visible = visible;
if (visible) {
particle.position.set(
brush.position.x + particle.userData.offset.x + phase * 0.25,
3.72 + particle.userData.offset.y + phase * 0.4,
brush.position.z + particle.userData.offset.z + Math.sin(phase * Math.PI) * 0.18
);
particle.scale.setScalar(Math.max(0.001, Math.sin(phase * Math.PI) * 0.9));
}
}
// Alignment: lift, arc, rotate, and seat the corner.
if (t < stages[1].start) {
frame.position.copy(initPosition);
frame.rotation.y = -0.24;
} else {
const u = ease(alignP);
frame.position.lerpVectors(initPosition, finalPosition, u);
frame.position.y += Math.sin(u * Math.PI) * 1.35;
frame.rotation.y = THREE.MathUtils.lerp(-0.24, 0, u);
// Tiny seating settle at the end of alignment.
if (alignP > 0.82) {
frame.position.y -= Math.sin((alignP - 0.82) / 0.18 * Math.PI) * 0.035;
}
}
// Clamps: close during holding, then open during release.
const closeAmount = range(0, 0.29, holdP) * (1 - range(0, 0.65, releaseP));
const jawY = THREE.MathUtils.lerp(4.03, 3.66, closeAmount);
jawA.position.y = jawY;
jawB.position.y = jawY;
const beamBottom = 4.065;
const jawTop = jawY + 0.1;
const screwHeight = Math.max(0.08, beamBottom - jawTop);
screwA.scale.y = screwHeight / 0.12;
screwA.position.y = (beamBottom + jawTop) * 0.5;
screwB.scale.y = screwHeight / 0.12;
screwB.position.y = (beamBottom + jawTop) * 0.5;
// Clamp indicators turn from cyan to green after release.
const indicatorColor = new THREE.Color(0x54dce0).lerp(
new THREE.Color(0x7be495),
releaseP
);
clampIndicatorMaterial.color.copy(indicatorColor);
clampIndicatorMaterial.emissive.copy(indicatorColor);
clampIndicatorMaterial.emissiveIntensity = 0.45 + Math.sin(t * 4) * 0.16;
// Glue marker path and glue bead deposition.
if (t < stages[2].start) {
marker.position.copy(markerRest);
} else if (t < stages[3].start) {
const u = holdP;
if (u < 0.16) {
marker.position.lerpVectors(markerRest, markerStart, ease(u / 0.16));
} else if (u < 0.47) {
marker.position.lerpVectors(markerStart, markerCorner, ease((u - 0.16) / 0.31));
} else if (u < 0.78) {
marker.position.lerpVectors(markerCorner, markerEnd, ease((u - 0.47) / 0.31));
} else {
marker.position.lerpVectors(markerEnd, markerRest, ease((u - 0.78) / 0.22));
}
} else {
marker.position.copy(markerRest);
}
marker.rotation.z = -0.05 + Math.sin(t * 5) * 0.025;
for (let i = 0; i < glueBeads.length; i++) {
const bead = glueBeads[i];
const reveal = range(
bead.userData.threshold,
bead.userData.threshold + 0.045,
holdP
);
bead.scale.setScalar(Math.max(0.001, reveal));
}
// Jig illumination emphasizes alignment.
const alignmentPulse = stageIndex === 1 ? 0.85 + Math.sin(t * 6) * 0.3 : 0.3;
jigGlowMaterial.emissiveIntensity = alignmentPulse;
// Release beacon confirms the restored bond.
const beaconScale = range(0.02, 0.25, releaseP);
beacon.scale.setScalar(Math.max(0.001, beaconScale));
beaconLight.intensity = releaseP * 7 * (0.85 + Math.sin(t * 5) * 0.15);
// The frame gains a subtle warm set as the bond releases.
frameWoodMaterial.emissiveIntensity = 0.05 + releaseP * 0.16;
// Stage light and annotation emphasis.
const stageColors = [0xffbd6a, 0x58e0d2, 0xff765e, 0x75e58f];
stageLight.color.setHex(stageColors[stageIndex]);
stageLight.intensity = 10 + Math.sin(t * 3) * 1.5;
}
// The stage index is calculated before animateScene so the same value
// can be reused by the light and UI.
let stageIndex = 0;
// ------------------------------------------------------------
// UI
// ------------------------------------------------------------
const playButton = document.querySelector("#play");
const resetButton = document.querySelector("#reset");
const homeButton = document.querySelector("#home");
const track = document.querySelector("#track");
const progressFill = document.querySelector("#fill");
const timeLabel = document.querySelector("#time");
const stateLabel = document.querySelector("#state");
const currentTitle = document.querySelector("#current-title");
const currentCopy = document.querySelector("#current-copy");
const stepButtons = [...document.querySelectorAll(".step")];
const annotationElements = {
frame: document.querySelector("#label-frame"),
jig: document.querySelector("#label-jig"),
clamps: document.querySelector("#label-clamps"),
marker: document.querySelector("#label-marker")
};
stages.forEach((stage, index) => {
const tick = document.createElement("div");
tick.className = "tick";
tick.style.left = `${(stage.start / totalDuration) * 100}%`;
track.appendChild(tick);
});
stepButtons.forEach((button) => {
button.addEventListener("click", () => {
const index = Number(button.dataset.stage);
setTimeline(stages[index].start + 0.015, true);
});
});
playButton.addEventListener("click", () => {
if (timeline >= totalDuration - 0.02) timeline = 0;
playing = !playing;
});
resetButton.addEventListener("click", () => {
timeline = 0;
playing = false;
});
homeButton.addEventListener("click", homeCamera);
track.addEventListener("pointerdown", (event) => {
const rect = track.getBoundingClientRect();
const ratio = THREE.MathUtils.clamp((event.clientX - rect.left) / rect.width, 0, 1);
setTimeline(ratio * totalDuration, true);
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
if (timeline >= totalDuration - 0.02) timeline = 0;
playing = !playing;
}
if (event.code === "ArrowRight") {
const next = Math.min(stages.length - 1, currentStageIndex(timeline) + 1);
setTimeline(stages[next].start + 0.015, true);
}
if (event.code === "ArrowLeft") {
const previous = Math.max(0, currentStageIndex(timeline) - 1);
setTimeline(stages[previous].start + 0.015, true);
}
if (event.code === "Home") homeCamera();
});
function formatTime(value) {
const seconds = Math.floor(value);
return `00:${String(seconds).padStart(2, "0")}`;
}
function updateUI() {
const index = currentStageIndex(timeline);
stageIndex = index;
progressFill.style.width = `${(timeline / totalDuration) * 100}%`;
timeLabel.textContent = `${formatTime(timeline)} / ${formatTime(totalDuration)}`;
playButton.textContent = playing ? "Ⅱ" : "▶";
if (index !== previousStage) {
previousStage = index;
stateLabel.textContent = `${String(index + 1).padStart(2, "0")} / 04`;
currentTitle.textContent = stages[index].title;
currentCopy.textContent = stages[index].copy;
stepButtons.forEach((button, i) => {
button.classList.toggle("active", i === index);
button.classList.toggle("done", i < index);
});
annotationElements.frame.classList.toggle(
"active",
index === 0 || index === 1 || index === 3
);
annotationElements.jig.classList.toggle("active", index === 1);
annotationElements.clamps.classList.toggle("active", index === 2);
annotationElements.marker.classList.toggle("active", index === 2);
}
}
function positionAnnotation(element, position) {
const projected = position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function updateAnnotations() {
positionAnnotation(
annotationElements.frame,
frame.localToWorld(new THREE.Vector3(0.95, 0.78, 0.35))
);
positionAnnotation(
annotationElements.jig,
new THREE.Vector3(0.55, 3.48, 0.55)
);
positionAnnotation(
annotationElements.clamps,
new THREE.Vector3(-1.9, 4.62, -0.75)
);
positionAnnotation(
annotationElements.marker,
marker.localToWorld(new THREE.Vector3(0, 1.08, 0))
);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Main loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
timeline += dt;
if (timeline >= totalDuration) {
timeline = totalDuration;
playing = false;
}
}
updateUI();
animateScene(timeline);
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```