Prompt specification
Build or customize the Three.js 3D scene "Jacket repair preparation table" 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: Jacket repair preparation table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/jacket-repair-preparation-table-x0639
Scene Description Prompt:
Use Three.js from cdnjs to compose a jacket, replacement zipper tape, clips, and sewing tools; compare the old and new closures by length and attachment edges before the repair sequence. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (jacket-repair-preparation-table-x0639):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Voxel Jacket Zipper Repair</title>
<style>
:root {
--ink: #17242a;
--muted: #64747b;
--paper: rgba(250, 252, 249, .94);
--line: rgba(23, 36, 42, .13);
--old: #d86843;
--new: #169f9a;
--gold: #d59d36;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8ece8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255,255,255,.8);
box-shadow: 0 18px 50px rgba(24, 38, 42, .13);
backdrop-filter: blur(14px);
}
header {
position: fixed;
top: 18px;
left: 20px;
right: 20px;
display: flex;
justify-content: space-between;
align-items: flex-start;
pointer-events: none;
gap: 16px;
}
.brand {
padding: 13px 16px 12px;
border-radius: 16px;
pointer-events: auto;
}
.eyebrow {
color: var(--new);
font-size: 10px;
font-weight: 800;
letter-spacing: .19em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 0;
font-size: clamp(18px, 2.2vw, 27px);
letter-spacing: -.035em;
line-height: 1.05;
}
.mode {
padding: 10px 13px;
border-radius: 999px;
font-size: 11px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
white-space: nowrap;
}
.mode.compare { color: #76510b; background: #fff1c9; }
.mode.repair { color: #0a6965; background: #d9f7f1; }
#comparison {
position: fixed;
top: 98px;
right: 20px;
width: min(340px, calc(100vw - 40px));
padding: 18px;
border-radius: 18px;
transition: width .3s ease, opacity .3s ease;
}
#comparison h2 {
margin: 5px 0 4px;
font-size: 20px;
letter-spacing: -.03em;
}
.sub {
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.measurement {
margin-top: 15px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255,255,255,.55);
}
.measurement.old { border-left: 4px solid var(--old); }
.measurement.new { border-left: 4px solid var(--new); }
.measure-head {
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 800;
font-size: 13px;
}
.chip {
padding: 4px 7px;
border-radius: 7px;
font-size: 10px;
letter-spacing: .08em;
text-transform: uppercase;
}
.chip.old { color: #8b351e; background: #ffe1d5; }
.chip.new { color: #086c68; background: #d9f7f1; }
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.metric {
padding: 8px;
background: rgba(23,36,42,.045);
border-radius: 9px;
}
.metric strong {
display: block;
font-size: 18px;
letter-spacing: -.04em;
}
.metric span {
color: var(--muted);
font-size: 10px;
}
.bar {
height: 6px;
margin-top: 10px;
overflow: hidden;
border-radius: 99px;
background: #e8ecea;
}
.bar > i {
display: block;
height: 100%;
border-radius: inherit;
}
.old .bar > i { width: 92%; background: var(--old); }
.new .bar > i { width: 100%; background: var(--new); }
.fit {
margin-top: 13px;
padding: 11px 12px;
color: #174b48;
background: #e6f7f3;
border: 1px solid #c7ebe4;
border-radius: 12px;
font-size: 12px;
line-height: 1.45;
}
.fit b { color: #08736e; }
.buttons {
display: flex;
gap: 8px;
margin-top: 14px;
}
button {
appearance: none;
border: 0;
border-radius: 10px;
padding: 10px 12px;
color: white;
background: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform .15s ease, opacity .15s ease, background .15s ease;
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: .38; cursor: not-allowed; }
button.secondary {
color: var(--ink);
background: #e9eeeb;
}
button.accent { background: var(--new); }
button.auto { flex: 1; background: #1d3036; }
button.next { flex: 1; }
#comparison.compact {
width: 260px;
}
#comparison.compact .measurement,
#comparison.compact .fit {
display: none;
}
#comparison.compact h2 {
font-size: 15px;
}
#stagePanel {
position: fixed;
left: 20px;
bottom: 20px;
width: min(440px, calc(100vw - 40px));
padding: 15px;
border-radius: 17px;
}
.stage-top {
display: flex;
align-items: flex-start;
gap: 12px;
}
.step-number {
flex: 0 0 37px;
height: 37px;
display: grid;
place-items: center;
border-radius: 10px;
color: #0d6f6a;
background: #d9f7f1;
font-size: 12px;
font-weight: 900;
}
#stageTitle {
margin: 0;
font-size: 15px;
letter-spacing: -.02em;
}
#stageCopy {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.steps {
display: flex;
gap: 5px;
margin: 13px 0 11px;
}
.step {
flex: 1;
height: 5px;
border-radius: 99px;
background: #dfe6e2;
transition: background .25s ease;
}
.step.done { background: #8ed7ce; }
.step.active { background: var(--new); }
.stage-actions {
display: flex;
gap: 8px;
}
#controls {
position: fixed;
right: 20px;
bottom: 22px;
color: rgba(23,36,42,.65);
font-size: 10px;
line-height: 1.5;
text-align: right;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 4;
transform: translate(-50%, -100%);
padding: 8px 10px;
border-radius: 10px;
color: white;
font-size: 11px;
font-weight: 800;
line-height: 1.25;
text-align: center;
pointer-events: none;
white-space: nowrap;
box-shadow: 0 8px 25px rgba(20,30,34,.18);
}
.world-label small {
display: block;
margin-top: 3px;
opacity: .8;
font-size: 9px;
font-weight: 650;
}
#oldLabel { background: #b95032; }
#newLabel { background: #087f7a; }
#jacketLabel { background: #25373e; }
#toast {
position: fixed;
left: 50%;
top: 22px;
z-index: 8;
transform: translate(-50%, -20px);
opacity: 0;
padding: 11px 16px;
border-radius: 12px;
color: white;
background: #168f88;
font-size: 12px;
font-weight: 800;
box-shadow: 0 15px 40px rgba(20,40,42,.2);
transition: opacity .25s ease, transform .25s ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 780px) {
header { top: 10px; left: 10px; right: 10px; }
.brand { padding: 10px 12px; }
.mode { display: none; }
#comparison {
top: auto;
right: 10px;
bottom: 153px;
width: calc(100vw - 20px);
padding: 12px;
}
#comparison.compact { width: calc(100vw - 20px); }
#stagePanel {
left: 10px;
bottom: 10px;
width: calc(100vw - 20px);
padding: 12px;
}
#controls { display: none; }
.measurement { margin-top: 9px; padding: 9px; }
.fit { margin-top: 8px; }
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<header>
<div class="brand panel">
<div class="eyebrow">Voxel Workbench / Repair Study</div>
<h1>Jacket Zipper Replacement</h1>
</div>
<div id="mode" class="mode compare panel">Compare before repair</div>
</header>
<section id="comparison" class="panel">
<div class="eyebrow">Closure inspection</div>
<h2>Old vs. replacement</h2>
<div class="sub">
The old closure is removed for bench inspection. Compare total length and usable
sewn attachment edge before installation.
</div>
<div class="measurement old">
<div class="measure-head">
<span>Old closure</span>
<span class="chip old">Worn</span>
</div>
<div class="metrics">
<div class="metric"><strong>48 cm</strong><span>total length</span></div>
<div class="metric"><strong>46 cm</strong><span>attachment edge</span></div>
</div>
<div class="bar"><i></i></div>
</div>
<div class="measurement new">
<div class="measure-head">
<span>Replacement zipper</span>
<span class="chip new">New</span>
</div>
<div class="metrics">
<div class="metric"><strong>52 cm</strong><span>total length</span></div>
<div class="metric"><strong>50 cm</strong><span>attachment edge</span></div>
</div>
<div class="bar"><i></i></div>
</div>
<div class="fit">
<b>Fit result:</b> the new tape is 4 cm longer than the old edge and exactly
matches the jacket’s 50 cm placket requirement. Align the lower stop first.
</div>
<div class="buttons">
<button id="beginBtn" class="accent" style="flex:1">Confirm fit & begin</button>
<button id="resetBtn" class="secondary">Reset</button>
</div>
</section>
<section id="stagePanel" class="panel">
<div class="stage-top">
<div id="stepNumber" class="step-number">0</div>
<div>
<h3 id="stageTitle">Inspect both closures</h3>
<p id="stageCopy">
Compare the 48 cm old closure with the 52 cm replacement and verify both
attachment edges against the jacket placket.
</p>
</div>
</div>
<div class="steps" id="steps">
<i class="step active"></i><i class="step"></i><i class="step"></i><i class="step"></i>
<i class="step"></i><i class="step"></i><i class="step"></i><i class="step"></i>
</div>
<div class="stage-actions">
<button id="autoBtn" class="auto">▶ Play repair</button>
<button id="nextBtn" class="next secondary" disabled>Start repair</button>
</div>
</section>
<div id="controls">
Drag to orbit · Shift/right-drag to pan · Wheel to zoom<br>
All garment, zipper, clip, and tool forms are assembled from visible blocks.
</div>
<div id="oldLabel" class="world-label">OLD CLOSURE<small>48 cm total · 46 cm edge</small></div>
<div id="newLabel" class="world-label">REPLACEMENT<small>52 cm total · 50 cm edge</small></div>
<div id="jacketLabel" class="world-label">JACKET PLACKET<small>50 cm required attachment edge</small></div>
<div id="toast">Repair complete — zipper closed and tested</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ece8);
scene.fog = new THREE.Fog(0xe8ece8, 20, 34);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 100);
const cameraState = {
azimuth: 0.57,
polar: 1.02,
distance: 16.2,
target: new THREE.Vector3(0, 1.9, 0.45)
};
const desiredCamera = {
azimuth: cameraState.azimuth,
polar: cameraState.polar,
distance: cameraState.distance,
target: cameraState.target.clone()
};
scene.add(new THREE.HemisphereLight(0xf9fff9, 0x7f8e8b, 2.0));
const key = new THREE.DirectionalLight(0xfff8e8, 3.1);
key.position.set(7, 11, 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.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xc8f3ef, 1.25);
fill.position.set(-8, 6, 4);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const mats = {
bench: new THREE.MeshStandardMaterial({ color: 0xc8bda8, roughness: 0.88 }),
benchEdge: new THREE.MeshStandardMaterial({ color: 0x8e806b, roughness: 0.9 }),
lining: new THREE.MeshStandardMaterial({ color: 0x41565d, roughness: 0.9 }),
navy0: new THREE.MeshStandardMaterial({ color: 0x203d4b, roughness: 0.83 }),
navy1: new THREE.MeshStandardMaterial({ color: 0x294956, roughness: 0.82 }),
navy2: new THREE.MeshStandardMaterial({ color: 0x19323f, roughness: 0.86 }),
tan: new THREE.MeshStandardMaterial({ color: 0xa98258, roughness: 0.85 }),
cream: new THREE.MeshStandardMaterial({ color: 0xf0dfb4, roughness: 0.76 }),
dark: new THREE.MeshStandardMaterial({ color: 0x17262d, roughness: 0.72 }),
metal: new THREE.MeshStandardMaterial({ color: 0xaab8ba, metalness: 0.72, roughness: 0.29 }),
darkMetal: new THREE.MeshStandardMaterial({ color: 0x4f5c60, metalness: 0.65, roughness: 0.36 }),
oldTape: new THREE.MeshStandardMaterial({ color: 0xc96342, roughness: 0.77 }),
oldEdge: new THREE.MeshStandardMaterial({ color: 0xf0b36e, roughness: 0.7 }),
newTape: new THREE.MeshStandardMaterial({ color: 0x169d98, roughness: 0.73 }),
newEdge: new THREE.MeshStandardMaterial({ color: 0xc8fff0, roughness: 0.68 }),
yellow: new THREE.MeshStandardMaterial({ color: 0xf0bb3d, roughness: 0.68 }),
blue: new THREE.MeshStandardMaterial({ color: 0x55a9d7, roughness: 0.65 }),
red: new THREE.MeshStandardMaterial({ color: 0xdb4b3f, roughness: 0.7 }),
thread: new THREE.MeshStandardMaterial({ color: 0xf7e7b8, roughness: 0.8 }),
wood: new THREE.MeshStandardMaterial({ color: 0xa96f3f, roughness: 0.82 }),
edge: new THREE.MeshStandardMaterial({
color: 0xd6a64c, roughness: 0.65, emissive: 0x3c2700, emissiveIntensity: 0
})
};
function block(parent, size, position, material, shadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(...size);
mesh.position.set(...position);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function instances(parent, cells, material) {
if (!cells.length) return null;
const mesh = new THREE.InstancedMesh(unitBox, material, cells.length);
cells.forEach((cell, i) => {
dummy.position.set(...cell.p);
dummy.scale.set(...cell.s);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
/* Workbench */
block(scene, [14.6, .38, 11.2], [0, -.25, .65], mats.bench);
block(scene, [14.8, .18, .18], [0, -.13, 6.25], mats.benchEdge);
block(scene, [.18, .18, 11.2], [-7.4, -.13, .65], mats.benchEdge);
block(scene, [.18, .18, 11.2], [7.4, -.13, .65], mats.benchEdge);
const gridMat = new THREE.MeshStandardMaterial({ color: 0x9e917c, roughness: 1 });
for (let x = -6; x <= 6; x += 1) {
block(scene, [.012, .008, 10.6], [x, -.052, .65], gridMat, false);
}
for (let z = -4; z <= 6; z += 1) {
block(scene, [13.8, .008, .012], [0, -.051, z], gridMat, false);
}
/* Jacket: visibly separated voxel blocks */
const jacket = new THREE.Group();
scene.add(jacket);
const jacketCells = [[], [], []];
const sleeveCells = [[], [], []];
const tanCells = [];
for (let row = 0; row < 14; row++) {
const y = .43 + row * .28;
for (let col = 0; col < 11; col++) {
const x = -1.4 + col * .28;
const k = (row * 7 + col * 3) % 3;
jacketCells[k].push({ p: [x, y, -.88], s: [.265, .265, .19] });
}
}
for (let row = 0; row < 14; row++) {
const y = .43 + row * .28;
for (let side of [-1, 1]) {
for (let col = 0; col < 5; col++) {
const x = side * (.28 + col * .28);
const k = (row * 5 + col * 2 + (side > 0 ? 1 : 0)) % 3;
jacketCells[k].push({ p: [x, y, -.51], s: [.265, .265, .22] });
}
}
}
for (let row = 0; row < 9; row++) {
const y = 1.18 + row * .28;
for (let col = 0; col < 3; col++) {
const k = (row + col) % 3;
sleeveCells[k].push({
p: [-1.68 - col * .25 - (row > 6 ? .12 : 0), y, -.48],
s: [.235, .265, .24]
});
sleeveCells[k].push({
p: [1.68 + col * .25 + (row > 6 ? .12 : 0), y, -.48],
s: [.235, .265, .24]
});
}
}
for (let row = 0; row < 9; row++) {
const y = 1.18 + row * .28;
tanCells.push({ p: [-2.39, y, -.48], s: [.25, .27, .25] });
tanCells.push({ p: [2.39, y, -.48], s: [.25, .27, .25] });
}
instances(jacket, jacketCells[0], mats.navy0);
instances(jacket, jacketCells[1], mats.navy1);
instances(jacket, jacketCells[2], mats.navy2);
instances(jacket, sleeveCells[0], mats.navy1);
instances(jacket, sleeveCells[1], mats.navy2);
instances(jacket, sleeveCells[2], mats.navy0);
instances(jacket, tanCells, mats.tan);
for (let x = -1.4; x <= 1.4; x += .28) {
if (Math.abs(x) < .45) continue;
block(jacket, [.26, .25, .31], [x, 4.27, -.42], mats.navy1);
}
for (let side of [-1, 1]) {
for (let i = 0; i < 5; i++) {
block(jacket, [.28, .25, .32], [side * (.25 + i * .28), 4.27, -.42], mats.tan);
}
}
block(jacket, [.54, .23, .32], [-.14, 4.43, -.4], mats.navy2);
block(jacket, [.54, .23, .32], [.14, 4.43, -.4], mats.navy2);
const jacketEdges = new THREE.Group();
jacket.add(jacketEdges);
for (let side of [-1, 1]) {
for (let i = 0; i < 14; i++) {
block(
jacketEdges,
[.085, .145, .055],
[side * .225, .53 + i * .28, -.365],
mats.edge,
false
);
}
}
/* Zipper construction */
function makeZipper(totalLength, tapeLength, tapeMaterial, edgeMaterial, worn = false) {
const root = new THREE.Group();
const halves = {};
const count = Math.round(tapeLength / .18);
for (const side of [-1, 1]) {
const half = new THREE.Group();
half.position.x = side * .12;
root.add(half);
halves[side < 0 ? "left" : "right"] = half;
for (let i = 0; i < count; i++) {
const z = -tapeLength / 2 + (i + .5) * tapeLength / count;
block(half, [.19, .065, .162], [0, .025, z], tapeMaterial);
if (i % 2 === 0) {
block(
half,
[.045, .072, .115],
[side * .143, .029, z],
edgeMaterial,
false
);
}
}
const toothCount = Math.floor((tapeLength - .25) / .105);
for (let i = 0; i < toothCount; i++) {
const z = -(tapeLength - .4) / 2 + i * .105;
block(
half,
[.067, .078, .066],
[-side * .055, .083, z],
worn ? mats.darkMetal : mats.metal,
false
);
}
block(half, [.15, .09, .12], [0, .08, -tapeLength / 2 + .05], mats.darkMetal);
}
const slider = new THREE.Group();
slider.position.set(0, .14, tapeLength / 2 - .24);
root.add(slider);
block(slider, [.24, .11, .24], [0, 0, 0], worn ? mats.darkMetal : mats.metal);
block(slider, [.13, .09, .12], [0, .08, -.05], worn ? mats.oldTape : mats.metal);
block(slider, [.085, .07, .33], [0, .07, .24], mats.darkMetal);
block(slider, [.13, .075, .105], [0, .07, .41], worn ? mats.oldTape : mats.metal);
for (const z of [-totalLength / 2, totalLength / 2]) {
block(root, [.16, .09, .12], [0, .075, z], mats.darkMetal);
}
return { root, halves, slider };
}
const oldZip = makeZipper(4.8, 4.6, mats.oldTape, mats.oldEdge, true);
oldZip.root.position.set(-4.05, .045, .95);
scene.add(oldZip.root);
const newZip = makeZipper(5.2, 5.0, mats.newTape, mats.newEdge, false);
newZip.root.position.set(4.05, .045, .95);
scene.add(newZip.root);
/* Physical block rulers */
function makeRuler(length, x) {
const g = new THREE.Group();
g.position.set(x, .025, .95);
block(g, [.025, .025, length], [0, 0, 0], mats.dark, false);
for (let z = -length / 2; z <= length / 2 + .001; z += .5) {
const major = Math.abs(z % 1) < .01;
block(g, [major ? .18 : .11, .026, .025], [0, .002, z], mats.dark, false);
}
scene.add(g);
return g;
}
const oldRuler = makeRuler(4.8, -4.62);
const newRuler = makeRuler(5.2, 4.62);
/* Tool tray */
block(scene, [5.6, .08, 1.45], [.05, .015, 4.25], mats.dark, false);
/* Thread spool made from stacked square blocks */
const spool = new THREE.Group();
spool.position.set(-1.75, .18, 4.18);
scene.add(spool);
for (let i = 0; i < 8; i++) {
block(spool, [.38, .052, .38], [0, i * .055, 0], i % 2 ? mats.cream : mats.newTape, false);
}
block(spool, [.46, .07, .46], [0, -.045, 0], mats.wood);
block(spool, [.46, .07, .46], [0, .49, 0], mats.wood);
/* Brush */
const brush = new THREE.Group();
brush.position.set(-.75, .2, 4.22);
brush.rotation.x = -Math.PI / 2;
scene.add(brush);
block(brush, [.12, .72, .12], [0, .08, 0], mats.wood);
block(brush, [.34, .17, .2], [0, -.36, 0], mats.tan);
for (let i = -2; i <= 2; i++) {
block(brush, [.045, .16, .045], [i * .055, -.49, 0], mats.cream, false);
}
/* Sewing needle tool */
const sewTool = new THREE.Group();
sewTool.position.set(.55, .21, 4.22);
sewTool.rotation.x = -Math.PI / 2;
scene.add(sewTool);
block(sewTool, [.11, .38, .11], [0, -.28, 0], mats.blue);
block(sewTool, [.07, .11, .07], [0, -.05, 0], mats.metal);
block(sewTool, [.026, .75, .026], [0, .37, 0], mats.metal);
block(sewTool, [.052, .11, .018], [0, .58, 0], mats.dark, false);
/* Box-built scissors */
const scissors = new THREE.Group();
scissors.position.set(1.72, .13, 4.15);
scene.add(scissors);
for (let side of [-1, 1]) {
const arm = new THREE.Group();
arm.rotation.y = side * .19;
scissors.add(arm);
block(arm, [.08, .07, .75], [side * .08, 0, .12], mats.metal);
block(arm, [.2, .075, .29], [side * .13, 0, -.42], mats.red);
block(arm, [.1, .075, .28], [side * .15, 0, -.57], mats.red);
}
block(scissors, [.09, .09, .12], [0, .03, -.13], mats.darkMetal);
/* Box-built awl and seam ripper */
const awl = new THREE.Group();
awl.position.set(2.55, .13, 4.22);
awl.rotation.y = -.22;
scene.add(awl);
block(awl, [.18, .12, .48], [0, 0, 0], mats.wood);
block(awl, [.035, .035, .52], [0, .055, -.42], mats.metal);
const ripper = new THREE.Group();
ripper.position.set(3.08, .13, 4.2);
ripper.rotation.y = .2;
scene.add(ripper);
block(ripper, [.16, .12, .48], [0, 0, .02], mats.red);
block(ripper, [.05, .05, .43], [0, .06, -.38], mats.metal);
block(ripper, [.09, .05, .1], [0, .11, -.58], mats.metal);
/* Six sewing clips */
const clips = [];
for (let i = 0; i < 6; i++) {
const clip = new THREE.Group();
clip.position.set(-1.1 + i * .43, .12, 4.0);
clip.rotation.x = -Math.PI / 2;
const cm = i % 2 ? mats.blue : mats.yellow;
block(clip, [.31, .075, .11], [0, .1, 0], cm);
block(clip, [.31, .075, .11], [0, -.1, 0], cm);
block(clip, [.075, .23, .11], [-.12, 0, 0], cm);
scene.add(clip);
clips.push(clip);
}
/* Stitch blocks hidden until sewn */
const leftStitches = [];
const rightStitches = [];
for (let i = 0; i < 19; i++) {
const y = .55 + i * .215;
const a = block(scene, [.13, .035, .035], [-.205, y, -.065], mats.thread, false);
const b = block(scene, [.13, .035, .035], [.205, y, -.065], mats.thread, false);
a.visible = false;
b.visible = false;
leftStitches.push(a);
rightStitches.push(b);
}
/* Camera controls implemented directly, without addons */
const pointer = new THREE.Vector2();
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", e => e.preventDefault());
canvas.addEventListener("pointerdown", e => {
dragging = true;
panning = e.button === 2 || e.shiftKey;
lastX = e.clientX;
lastY = e.clientY;
canvas.setPointerCapture(e.pointerId);
});
canvas.addEventListener("pointermove", e => {
if (!dragging) return;
const dx = e.clientX - lastX;
const dy = e.clientY - lastY;
lastX = e.clientX;
lastY = e.clientY;
if (panning) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
desiredCamera.target.addScaledVector(right, -dx * desiredCamera.distance * .0015);
desiredCamera.target.addScaledVector(up, dy * desiredCamera.distance * .0015);
} else {
desiredCamera.azimuth -= dx * .006;
desiredCamera.polar = THREE.MathUtils.clamp(desiredCamera.polar - dy * .005, .45, 1.42);
}
});
canvas.addEventListener("pointerup", e => {
dragging = false;
canvas.releasePointerCapture(e.pointerId);
});
canvas.addEventListener("wheel", e => {
e.preventDefault();
desiredCamera.distance = THREE.MathUtils.clamp(
desiredCamera.distance * Math.exp(e.deltaY * .001),
6.2,
22
);
}, { passive: false });
/* Tween system */
let tweens = [];
let autoTimer = 0;
function tween(duration, update, complete) {
tweens.push({ start: performance.now(), duration, update, complete });
}
function updateTweens(now) {
for (let i = tweens.length - 1; i >= 0; i--) {
const tw = tweens[i];
const p = THREE.MathUtils.clamp((now - tw.start) / tw.duration, 0, 1);
const eased = p * p * (3 - 2 * p);
tw.update(eased, p);
if (p >= 1) {
tweens.splice(i, 1);
if (tw.complete) tw.complete();
}
}
}
function moveCamera(distance, target, azimuth = cameraState.azimuth, polar = cameraState.polar) {
desiredCamera.distance = distance;
desiredCamera.target.copy(target);
desiredCamera.azimuth = azimuth;
desiredCamera.polar = polar;
}
/* Sequence state */
const stages = [
["Inspect both closures", "Compare the 48 cm old closure with the 52 cm replacement and verify both attachment edges against the jacket placket."],
["Prepare the attachment edges", "Brush both placket edges clean and mark the exact 50 cm sewing path."],
["Align the replacement zipper", "Move the new closure into position and align its lower stop with the jacket hem."],
["Clip the left zipper tape", "Place sewing clips along the left tape so the attachment edge cannot shift."],
["Clip the right zipper tape", "Secure the right tape opposite the first side and check that both edges are level."],
["Stitch the left attachment edge", "Use a straight stitch along the left tape, stopping before the slider."],
["Stitch the right attachment edge", "Repeat the stitch on the right edge and remove the temporary clips."],
["Close and test the closure", "Join the voxel teeth, slide the pull down, and test the finished zipper."]
];
let currentStep = 0;
let confirmed = false;
let busy = false;
let autoPlay = false;
const modeEl = document.querySelector("#mode");
const comparisonEl = document.querySelector("#comparison");
const stageTitle = document.querySelector("#stageTitle");
const stageCopy = document.querySelector("#stageCopy");
const stepNumber = document.querySelector("#stepNumber");
const nextBtn = document.querySelector("#nextBtn");
const autoBtn = document.querySelector("#autoBtn");
const beginBtn = document.querySelector("#beginBtn");
const resetBtn = document.querySelector("#resetBtn");
const toast = document.querySelector("#toast");
const stepEls = [...document.querySelectorAll(".step")];
function updateStageUI() {
stageTitle.textContent = stages[currentStep][0];
stageCopy.textContent = stages[currentStep][1];
stepNumber.textContent = currentStep;
nextBtn.disabled = busy || !confirmed || currentStep >= stages.length - 1;
nextBtn.textContent = currentStep === 0 ? "Start repair" :
currentStep >= stages.length - 1 ? "Repair complete" : "Next step";
stepEls.forEach((el, i) => {
el.classList.toggle("done", i < currentStep);
el.classList.toggle("active", i === currentStep);
});
}
function resetComparison() {
clearTimeout(autoTimer);
tweens.length = 0;
currentStep = 0;
confirmed = false;
busy = false;
autoPlay = false;
oldZip.root.position.set(-4.05, .045, .95);
oldZip.root.rotation.set(0, 0, 0);
oldZip.root.scale.setScalar(1);
newZip.root.position.set(4.05, .045, .95);
newZip.root.quaternion.identity();
newZip.root.scale.setScalar(1);
newZip.halves.left.position.x = -.12;
newZip.halves.right.position.x = .12;
newZip.slider.position.z = 2.26;
const clipStart = [
[-1.1, .12, 4.0], [-.67, .12, 4.0], [-.24, .12, 4.0],
[.19, .12, 4.0], [.62, .12, 4.0], [1.05, .12, 4.0]
];
clips.forEach((clip, i) => {
clip.position.set(...clipStart[i]);
clip.quaternion.setFromEuler(new THREE.Euler(-Math.PI / 2, 0, 0));
clip.scale.setScalar(1);
});
leftStitches.forEach(s => s.visible = false);
rightStitches.forEach(s => s.visible = false);
brush.position.set(-.75, .2, 4.22);
brush.quaternion.setFromEuler(new THREE.Euler(-Math.PI / 2, 0, 0));
sewTool.position.set(.55, .21, 4.22);
sewTool.quaternion.setFromEuler(new THREE.Euler(-Math.PI / 2, 0, 0));
mats.edge.emissiveIntensity = 0;
comparisonEl.classList.remove("compact");
modeEl.className = "mode compare panel";
modeEl.textContent = "Compare before repair";
document.querySelector("#oldLabel").style.display = "";
document.querySelector("#newLabel").style.display = "";
document.querySelector("#jacketLabel").style.display = "";
moveCamera(16.2, new THREE.Vector3(0, 1.9, .45));
toast.classList.remove("show");
updateStageUI();
}
function finishStage(n) {
currentStep = n;
busy = false;
updateStageUI();
if (n === stages.length - 1) {
autoPlay = false;
toast.classList.add("show");
setTimeout(() => toast.classList.remove("show"), 3500);
} else if (autoPlay) {
autoTimer = setTimeout(() => runStage(n + 1), 650);
}
}
function runStage(n) {
if (busy || n <= 0 || n >= stages.length) return;
if (!confirmed) return;
busy = true;
updateStageUI();
if (n === 1) {
moveCamera(12.2, new THREE.Vector3(0, 2.0, -.05));
const from = brush.position.clone();
const fromQ = brush.quaternion.clone();
const targetQ = new THREE.Quaternion();
tween(2400, (p) => {
if (p < .18) {
brush.position.lerpVectors(from, new THREE.Vector3(-.34, .68, -.13), p / .18);
} else {
const q = THREE.MathUtils.clamp((p - .18) / .82, 0, 1);
brush.position.set(-.34, .68 + q * 3.55, -.13);
}
brush.quaternion.slerpQuaternions(fromQ, targetQ, THREE.MathUtils.smoothstep(p, 0, .22));
mats.edge.emissiveIntensity = .8 * p;
}, () => finishStage(1));
}
if (n === 2) {
moveCamera(9.4, new THREE.Vector3(0, 2.15, -.05), .48, 1.03);
const from = newZip.root.position.clone();
const fromQ = newZip.root.quaternion.clone();
const target = new THREE.Vector3(0, 2.5, -.1);
const targetQ = new THREE.Quaternion().setFromEuler(new THREE.Euler(-Math.PI / 2, 0, 0));
const fromScale = newZip.root.scale.x;
tween(1700, (p) => {
newZip.root.position.lerpVectors(from, target, p);
newZip.root.quaternion.slerpQuaternions(fromQ, targetQ, p);
const s = THREE.MathUtils.lerp(fromScale, .84, p);
newZip.root.scale.setScalar(s);
}, () => finishStage(2));
}
if (n === 3 || n === 4) {
const isLeft = n === 3;
const list = isLeft ? clips.slice(0, 3) : clips.slice(3);
const ys = [1.03, 2.43, 3.82];
const identity = new THREE.Quaternion();
list.forEach((clip, i) => {
const from = clip.position.clone();
const fromQ = clip.quaternion.clone();
const to = new THREE.Vector3(isLeft ? -.235 : .235, ys[i], -.015);
tween(900 + i * 120, (p) => {
clip.position.lerpVectors(from, to, p);
clip.quaternion.slerpQuaternions(fromQ, identity, p);
});
});
setTimeout(() => finishStage(n), 900 + (list.length - 1) * 120 + 180);
}
if (n === 5 || n === 6) {
const isLeft = n === 5;
const stitches = isLeft ? leftStitches : rightStitches;
const x = isLeft ? -.29 : .29;
const from = sewTool.position.clone();
const fromQ = sewTool.quaternion.clone();
const targetQ = new THREE.Quaternion();
tween(2500, (p) => {
if (p < .18) {
sewTool.position.lerpVectors(from, new THREE.Vector3(x, .63, -.04), p / .18);
} else {
const q = THREE.MathUtils.clamp((p - .18) / .68, 0, 1);
sewTool.position.set(x, .63 + q * 3.55, -.04);
}
sewTool.quaternion.slerpQuaternions(fromQ, targetQ, THREE.MathUtils.smoothstep(p, 0, .2));
const reveal = THREE.MathUtils.clamp((p - .22) / .62, 0, 1);
stitches.forEach((stitch, i) => {
stitch.visible = reveal > i / stitches.length * .92;
});
}, () => {
stitches.forEach(s => s.visible = true);
finishStage(n);
});
}
if (n === 7) {
const leftFrom = newZip.halves.left.position.x;
const rightFrom = newZip.halves.right.position.x;
const sliderFrom = newZip.slider.position.z;
tween(2600, (p) => {
newZip.halves.left.position.x = THREE.MathUtils.lerp(leftFrom, -.057, p);
newZip.halves.right.position.x = THREE.MathUtils.lerp(rightFrom, .057, p);
const q = THREE.MathUtils.smoothstep(p, 0, .88);
newZip.slider.position.z = THREE.MathUtils.lerp(sliderFrom, -2.05, q);
if (p > .9) {
const bounce = Math.sin((p - .9) * Math.PI * 6) * (1 - p) * .13;
newZip.slider.position.z += bounce;
}
}, () => finishStage(7));
}
}
beginBtn.addEventListener("click", () => {
confirmed = true;
comparisonEl.classList.add("compact");
modeEl.className = "mode repair panel";
modeEl.textContent = "Repair in progress";
document.querySelector("#oldLabel").style.display = "none";
document.querySelector("#newLabel").style.display = "none";
document.querySelector("#jacketLabel").style.display = "none";
runStage(1);
});
resetBtn.addEventListener("click", resetComparison);
nextBtn.addEventListener("click", () => {
if (!confirmed) {
confirmed = true;
comparisonEl.classList.add("compact");
modeEl.className = "mode repair panel";
modeEl.textContent = "Repair in progress";
}
if (currentStep < stages.length - 1) runStage(currentStep + 1);
});
autoBtn.addEventListener("click", () => {
if (!confirmed) {
confirmed = true;
comparisonEl.classList.add("compact");
modeEl.className = "mode repair panel";
modeEl.textContent = "Repair in progress";
}
autoPlay = !autoPlay;
autoBtn.textContent = autoPlay ? "Ⅱ Pause sequence" : "▶ Play repair";
clearTimeout(autoTimer);
if (autoPlay && currentStep === 0) runStage(1);
else if (autoPlay && currentStep < stages.length - 1) {
autoTimer = setTimeout(() => runStage(currentStep + 1), 500);
}
});
/* Project HTML labels onto the Three.js scene */
const projected = new THREE.Vector3();
function placeLabel(element, world) {
projected.copy(world).project(camera);
const visible = projected.z > -1 && projected.z < 1 &&
Math.abs(projected.x) < 1.15 && Math.abs(projected.y) < 1.15;
element.style.visibility = visible ? "visible" : "hidden";
if (!visible) return;
const x = (projected.x * .5 + .5) * innerWidth;
const y = (-projected.y * .5 + .5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
placeLabel(document.querySelector("#oldLabel"), new THREE.Vector3(-4.05, .38, 3.43));
placeLabel(document.querySelector("#newLabel"), new THREE.Vector3(4.05, .38, 3.63));
placeLabel(document.querySelector("#jacketLabel"), new THREE.Vector3(0, 4.78, -.45));
}
/* Render loop */
function animate(now) {
requestAnimationFrame(animate);
updateTweens(now);
const cameraEase = .085;
cameraState.azimuth += (desiredCamera.azimuth - cameraState.azimuth) * cameraEase;
cameraState.polar += (desiredCamera.polar - cameraState.polar) * cameraEase;
cameraState.distance += (desiredCamera.distance - cameraState.distance) * cameraEase;
cameraState.target.lerp(desiredCamera.target, cameraEase);
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x + cameraState.distance * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.distance * Math.cos(cameraState.polar),
cameraState.target.z + cameraState.distance * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateStageUI();
requestAnimationFrame(animate);
</script>
</body>
</html>
```