Prompt specification
Build or customize the Three.js 3D scene "Workshop Flat-Pack Assembly 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: Workshop Flat-Pack Assembly Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/workshop-flat-pack-assembly-table-x2075
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing sheet-metal folds and assembly clearances. Build a small workbench where several folded panels assemble into an original storage box. Preserve tabs, slots, and face orientations through the sequence. Voxel style.
Working Three.js Starter (workshop-flat-pack-assembly-table-x2075):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Foldline — Voxel Storage Box Assembly</title>
<style>
:root {
--bg: #0b111b;
--panel: rgba(15, 23, 36, 0.92);
--panel-2: rgba(24, 35, 52, 0.92);
--line: rgba(180, 207, 226, 0.16);
--text: #eaf3f7;
--muted: #91a5b5;
--cyan: #69e4df;
--amber: #ffad48;
--coral: #ff6f61;
--navy: #18304a;
--shadow: 0 14px 45px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active { cursor: grabbing; }
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
position: fixed;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 15px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
background: var(--cyan);
box-shadow: 0 0 14px rgba(105, 228, 223, 0.55);
}
h1 {
margin: 8px 0 3px;
font-size: clamp(23px, 3vw, 35px);
line-height: 1;
letter-spacing: -0.055em;
}
.subtitle {
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.badge-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
.mini-badge {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 5px;
color: #c9d8e1;
background: rgba(255, 255, 255, 0.035);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
#stages {
position: fixed;
top: 22px;
right: 22px;
width: 278px;
padding: 14px;
border-radius: 15px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: #aabccc;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#stage-list {
display: grid;
gap: 4px;
}
.stage {
display: grid;
grid-template-columns: 30px 1fr;
align-items: center;
gap: 9px;
width: 100%;
padding: 8px 9px;
border: 1px solid transparent;
border-radius: 8px;
color: #8398a9;
background: transparent;
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.stage:hover {
color: #dce9f0;
background: rgba(255, 255, 255, 0.035);
}
.stage.active {
color: var(--text);
border-color: rgba(105, 228, 223, 0.25);
background: rgba(105, 228, 223, 0.08);
}
.stage-number {
color: #60788c;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.stage.active .stage-number { color: var(--cyan); }
.stage-name {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 9px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #9db0bf;
font-size: 9px;
letter-spacing: 0.04em;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.tag {
position: absolute;
left: 0;
top: 0;
padding: 5px 7px;
border: 1px solid rgba(105, 228, 223, 0.25);
border-radius: 5px;
color: #dffbf9;
background: rgba(7, 15, 23, 0.88);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.28);
font: 700 8px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
white-space: nowrap;
opacity: 0;
transition: opacity 140ms ease;
}
.tag::before {
content: "";
display: inline-block;
width: 5px;
height: 5px;
margin-right: 5px;
vertical-align: 1px;
border-radius: 1px;
background: var(--cyan);
}
.tag.amber { border-color: rgba(255, 173, 72, 0.28); }
.tag.amber::before { background: var(--amber); }
.tag.coral { border-color: rgba(255, 111, 97, 0.3); }
.tag.coral::before { background: var(--coral); }
.controls {
position: fixed;
left: 22px;
right: 22px;
bottom: 22px;
padding: 13px 15px;
border-radius: 15px;
}
.transport {
display: flex;
align-items: center;
gap: 9px;
}
button {
border: 1px solid var(--line);
border-radius: 8px;
color: #dce9f0;
background: rgba(255, 255, 255, 0.045);
cursor: pointer;
transition: 140ms ease;
}
button:hover {
color: white;
border-color: rgba(105, 228, 223, 0.38);
background: rgba(105, 228, 223, 0.09);
}
.icon-button {
width: 36px;
height: 36px;
font-size: 15px;
}
#play {
min-width: 92px;
height: 36px;
padding: 0 15px;
border-color: rgba(105, 228, 223, 0.34);
color: #071319;
background: var(--cyan);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
}
#play:hover {
color: #071319;
background: #8af4ef;
}
#scrub {
flex: 1;
min-width: 100px;
height: 4px;
appearance: none;
border-radius: 4px;
outline: none;
background: linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--progress, 0%),
rgba(255, 255, 255, 0.12) var(--progress, 0%),
rgba(255, 255, 255, 0.12) 100%
);
cursor: pointer;
}
#scrub::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 3px solid #132434;
border-radius: 3px;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(105, 228, 223, 0.4);
}
#scrub::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #132434;
border-radius: 3px;
background: var(--cyan);
}
#progress-value {
width: 43px;
color: #9fb3c2;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
.control-divider {
width: 1px;
height: 22px;
background: var(--line);
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
color: #a7bbc9;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
white-space: nowrap;
cursor: pointer;
user-select: none;
}
.toggle input {
width: 14px;
height: 14px;
margin: 0;
accent-color: var(--cyan);
}
#speed {
height: 32px;
padding: 0 10px;
color: #b9cad6;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.readout {
position: fixed;
left: 22px;
bottom: 104px;
max-width: 330px;
padding: 11px 13px;
border-radius: 10px;
pointer-events: none;
}
#stage-title {
color: var(--cyan);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
}
#stage-detail {
margin-top: 4px;
color: #a1b4c2;
font-size: 10px;
line-height: 1.45;
}
.hint {
position: fixed;
right: 22px;
bottom: 104px;
padding: 8px 10px;
border-radius: 8px;
color: #8096a7;
font: 700 8px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
text-align: right;
pointer-events: none;
}
@media (max-width: 900px) {
#stages {
top: auto;
right: 14px;
bottom: 102px;
width: 230px;
max-height: 39vh;
overflow: auto;
}
.legend { display: none; }
.brand { top: 14px; left: 14px; width: calc(100vw - 28px); }
.controls { left: 14px; right: 14px; bottom: 14px; }
.readout { display: none; }
.hint { display: none; }
}
@media (max-width: 620px) {
#stages { display: none; }
.brand { padding: 13px 15px; }
.subtitle { font-size: 10px; }
.badge-row { display: none; }
.controls { padding: 10px; }
.control-divider, .toggle, #speed { display: none; }
#play { min-width: 72px; padding: 0 9px; }
.icon-button { width: 32px; height: 32px; }
#progress-value { width: 34px; font-size: 8px; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels"></div>
<header class="brand glass">
<div class="eyebrow">Foldline / Assembly study 04</div>
<h1>Stackbox 12</h1>
<div class="subtitle">
A folded-sheet storage crate with registered corner tongues, recessed
sockets, and a reversible hinged lid.
</div>
<div class="badge-row">
<span class="mini-badge">7 FOLD STAGES</span>
<span class="mini-badge">5 VOXEL PANELS</span>
<span class="mini-badge">TAB + SLOT LOCKS</span>
</div>
</header>
<aside id="stages" class="glass">
<div class="section-title">
<span>Assembly sequence</span>
<span>08 steps</span>
</div>
<div id="stage-list"></div>
<div class="legend">
<div class="legend-item">
<span class="swatch" style="background:#ffad48"></span>
EXTERIOR FACE
</div>
<div class="legend-item">
<span class="swatch" style="background:#237b85"></span>
INTERIOR FACE
</div>
<div class="legend-item">
<span class="swatch" style="background:#ff6f61"></span>
TAB / TONGUE
</div>
<div class="legend-item">
<span class="swatch" style="background:#091521"></span>
SLOT / SOCKET
</div>
</div>
</aside>
<div class="readout glass">
<div id="stage-title">00 / BASE DATUM</div>
<div id="stage-detail">
The floor panel establishes the origin. Exterior faces remain amber;
interior faces remain teal.
</div>
</div>
<div class="hint glass">
DRAG TO ORBIT · WHEEL TO ZOOM<br />
SPACE: PLAY · ← →: STEP
</div>
<footer class="controls glass">
<div class="transport">
<button id="reset" class="icon-button" title="Reset" aria-label="Reset">↺</button>
<button id="prev" class="icon-button" title="Previous stage" aria-label="Previous stage">‹</button>
<button id="play" title="Play or pause">▶ PLAY</button>
<button id="next" class="icon-button" title="Next stage" aria-label="Next stage">›</button>
<input
id="scrub"
type="range"
min="0"
max="1000"
value="0"
aria-label="Assembly progress"
/>
<div id="progress-value">000%</div>
<div class="control-divider"></div>
<label class="toggle">
<input id="clearance-toggle" type="checkbox" checked />
CLEARANCE
</label>
<label class="toggle">
<input id="labels-toggle" type="checkbox" checked />
LABELS
</label>
<div class="control-divider"></div>
<button id="speed" title="Change playback speed">1.0×</button>
</div>
</footer>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b111b);
scene.fog = new THREE.Fog(0x0b111b, 19, 38);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 4, -4, 0.1, 80);
const cameraTarget = new THREE.Vector3(0, 0.8, 0);
const orbit = {
theta: 0.69,
phi: 0.92,
radius: 18,
zoom: 1.08
};
const hemi = new THREE.HemisphereLight(0xb9e5ff, 0x25303b, 2.0);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffead0, 4.0);
key.position.set(5.5, 10, 7.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -9;
key.shadow.camera.right = 9;
key.shadow.camera.top = 9;
key.shadow.camera.bottom = -9;
key.shadow.camera.near = 1;
key.shadow.camera.far = 28;
key.shadow.bias = -0.0004;
scene.add(key);
const rim = new THREE.DirectionalLight(0x54d9e7, 2.2);
rim.position.set(-7, 5, -6);
scene.add(rim);
const fill = new THREE.PointLight(0xff9f54, 16, 15, 2);
fill.position.set(-4, 4, 5);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and voxel helpers
// -------------------------------------------------------------------------
const MAT = {
outside: new THREE.MeshStandardMaterial({
color: 0xe88932,
roughness: 0.68,
metalness: 0.08,
flatShading: true
}),
outsideLight: new THREE.MeshStandardMaterial({
color: 0xffad48,
roughness: 0.64,
metalness: 0.06,
flatShading: true
}),
outsideDark: new THREE.MeshStandardMaterial({
color: 0xa94e24,
roughness: 0.72,
metalness: 0.08,
flatShading: true
}),
inside: new THREE.MeshStandardMaterial({
color: 0x237b85,
roughness: 0.72,
metalness: 0.04,
flatShading: true
}),
insideLight: new THREE.MeshStandardMaterial({
color: 0x43a3a4,
roughness: 0.68,
flatShading: true
}),
insideDark: new THREE.MeshStandardMaterial({
color: 0x174f5b,
roughness: 0.76,
flatShading: true
}),
slot: new THREE.MeshStandardMaterial({
color: 0x07131d,
roughness: 0.95,
metalness: 0.0
}),
tab: new THREE.MeshStandardMaterial({
color: 0xff6f61,
emissive: 0x3d0a06,
emissiveIntensity: 0.18,
roughness: 0.56,
metalness: 0.08,
flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xffe4b0,
roughness: 0.8,
flatShading: true
}),
bench: new THREE.MeshStandardMaterial({
color: 0x38414a,
roughness: 0.95,
flatShading: true
}),
benchEdge: new THREE.MeshStandardMaterial({
color: 0x222b34,
roughness: 0.96,
flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0x8fa7b4,
roughness: 0.55,
metalness: 0.32,
flatShading: true
}),
cyan: new THREE.MeshBasicMaterial({
color: 0x69e4df,
transparent: true,
opacity: 0.8,
depthWrite: false
}),
cyanSoft: new THREE.MeshBasicMaterial({
color: 0x69e4df,
transparent: true,
opacity: 0.18,
depthWrite: false
})
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x111820,
transparent: true,
opacity: 0.55
});
function addBox(
parent,
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
withEdges = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (withEdges) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterial
);
edges.position.copy(mesh.position);
parent.add(edges);
}
return mesh;
}
function addLine(parent, points, color = 0x69e4df, opacity = 0.65) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
parent.add(line);
return line;
}
function addOrientationPixels(parent, x, y, z, normal = "z") {
const light = MAT.cream;
const dark = MAT.insideDark;
if (normal === "z") {
addBox(parent, 0.10, 0.10, 0.025, light, x, y + 0.11, z, false);
addBox(parent, 0.10, 0.10, 0.025, light, x, y, z, false);
addBox(parent, 0.10, 0.10, 0.025, light, x, y - 0.11, z, false);
addBox(parent, 0.10, 0.10, 0.025, dark, x + 0.12, y - 0.11, z, false);
} else if (normal === "x") {
addBox(parent, 0.025, 0.10, 0.10, light, x, y + 0.11, z, false);
addBox(parent, 0.025, 0.10, 0.10, light, x, y, z, false);
addBox(parent, 0.025, 0.10, 0.10, light, x, y - 0.11, z, false);
addBox(parent, 0.025, 0.10, 0.10, dark, x, y - 0.11, z + 0.12, false);
} else {
addBox(parent, 0.10, 0.025, 0.10, light, x, y, z + 0.11, false);
addBox(parent, 0.10, 0.025, 0.10, light, x, y, z, false);
addBox(parent, 0.10, 0.025, 0.10, light, x, y, z - 0.11, false);
addBox(parent, 0.10, 0.025, 0.10, dark, x + 0.12, y, z - 0.11, false);
}
}
// -------------------------------------------------------------------------
// Workbench
// -------------------------------------------------------------------------
const bench = new THREE.Group();
scene.add(bench);
for (let i = 0; i < 6; i++) {
const z = -4.15 + i * 1.66;
addBox(
bench,
10.8,
0.28,
1.58,
i % 2 === 0 ? MAT.bench : MAT.benchEdge,
0,
-0.18,
z
);
}
for (const x of [-4.6, 4.6]) {
for (const z of [-3.75, 3.75]) {
addBox(bench, 0.42, 1.55, 0.42, MAT.benchEdge, x, -1.06, z);
}
}
addBox(bench, 9.5, 0.22, 0.26, MAT.benchEdge, 0, -0.72, -3.75);
addBox(bench, 9.5, 0.22, 0.26, MAT.benchEdge, 0, -0.72, 3.75);
const grid = new THREE.GridHelper(10.4, 20, 0x6c8798, 0x52616d);
grid.position.y = -0.032;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
// -------------------------------------------------------------------------
// Storage-box dimensions
// -------------------------------------------------------------------------
const W = 4.8;
const D = 3.4;
const H = 2.15;
const T = 0.16;
const assembly = new THREE.Group();
scene.add(assembly);
// Floor panel: +Y is the interior face, -Y is the exterior face.
const base = new THREE.Group();
assembly.add(base);
addBox(
base,
W,
T,
D,
[
MAT.outsideDark,
MAT.outsideDark,
MAT.inside,
MAT.outside,
MAT.outsideDark,
MAT.outsideDark
],
0,
T / 2,
0
);
addOrientationPixels(base, -1.95, T + 0.018, -1.25, "y");
// Rear panel: hinged around its bottom rear edge.
const rear = new THREE.Group();
rear.position.set(0, T, -D / 2);
rear.rotation.x = -Math.PI / 2;
assembly.add(rear);
addBox(
rear,
W,
H,
T,
[
MAT.outsideDark,
MAT.outsideDark,
MAT.outsideDark,
MAT.outsideDark,
MAT.inside,
MAT.outside
],
0,
H / 2,
0
);
// Interior stiffening ribs.
for (const y of [0.34, 0.96, 1.58]) {
addBox(
rear,
W - 0.36,
0.055,
0.045,
MAT.insideLight,
0,
y,
T / 2 + 0.024,
false
);
}
addOrientationPixels(rear, -1.96, 1.62, T / 2 + 0.035, "z");
addOrientationPixels(rear, 1.96, 1.62, -T / 2 - 0.035, "z");
// Hinged lid remains a child of the rear panel throughout the sequence.
const lid = new THREE.Group();
lid.position.set(0, H, 0);
rear.add(lid);
addBox(
lid,
W + 0.12,
T,
D + 0.10,
[
MAT.outsideDark,
MAT.outsideDark,
MAT.outside,
MAT.inside,
MAT.outsideDark,
MAT.outsideDark
],
0,
T / 2,
D / 2
);
// Underside ribs.
for (const x of [-1.48, 0, 1.48]) {
addBox(
lid,
0.11,
0.07,
D - 0.46,
MAT.insideDark,
x,
-0.035,
D / 2
);
}
// Lid sockets: their local Z follows the lid through every hinge movement.
const lidSlots = [];
for (const x of [-1.35, 1.35]) {
const socket = addBox(
lid,
0.58,
0.026,
0.40,
MAT.slot,
x,
T + 0.014,
D - 0.32,
false
);
lidSlots.push(socket);
addBox(
lid,
0.66,
0.014,
0.045,
MAT.cyanSoft,
x,
T + 0.025,
D - 0.57,
false
);
addBox(
lid,
0.66,
0.014,
0.045,
MAT.cyanSoft,
x,
T + 0.025,
D - 0.07,
false
);
}
addOrientationPixels(lid, -2.02, T + 0.02, D - 0.58, "y");
// Left and right panels.
const sidePanels = [];
const sideSlotAnchors = [];
for (const side of [-1, 1]) {
const sideGroup = new THREE.Group();
sideGroup.position.set(side * W / 2, T, 0);
sideGroup.rotation.z = side === -1 ? Math.PI / 2 : -Math.PI / 2;
assembly.add(sideGroup);
const innerMaterial = side === -1 ? MAT.inside : MAT.inside;
const outerMaterial = side === -1 ? MAT.outside : MAT.outside;
addBox(
sideGroup,
T,
H,
D,
side === 1
? [outerMaterial, innerMaterial, outerMaterial, outerMaterial, outerMaterial, outerMaterial]
: [innerMaterial, outerMaterial, outerMaterial, outerMaterial, outerMaterial, outerMaterial],
0,
H / 2,
0
);
// Interior ribs on the inward-facing X surface.
for (const y of [0.34, 0.96, 1.58]) {
addBox(
sideGroup,
0.045,
0.055,
D - 0.36,
MAT.insideLight,
-side * (T / 2 + 0.024),
y,
0,
false
);
}
// Matching recessed slot near the front edge.
const slotZ = D / 2 - T / 2 - 0.36;
addBox(
sideGroup,
0.028,
0.34,
0.76,
MAT.slot,
-side * (T / 2 + 0.015),
0.92,
slotZ,
false
);
// Cyan clearance frame around the slot.
for (const dy of [-0.21, 0.21]) {
addBox(
sideGroup,
0.022,
0.035,
0.82,
MAT.cyanSoft,
-side * (T / 2 + 0.028),
0.92 + dy,
slotZ,
false
);
}
for (const dz of [-0.39, 0.39]) {
addBox(
sideGroup,
0.022,
0.40,
0.035,
MAT.cyanSoft,
-side * (T / 2 + 0.028),
0.92,
slotZ + dz,
false
);
}
const anchor = new THREE.Object3D();
anchor.position.set(-side * (T / 2 + 0.05), 0.92, slotZ);
sideGroup.add(anchor);
sideSlotAnchors.push(anchor);
addOrientationPixels(
sideGroup,
side * (T / 2 + 0.025),
1.63,
-0.62,
"x"
);
sidePanels.push(sideGroup);
}
// Front panel: hinged around its bottom front edge.
const front = new THREE.Group();
front.position.set(0, T, D / 2);
front.rotation.x = Math.PI / 2;
assembly.add(front);
addBox(
front,
W,
H,
T,
[
MAT.outsideDark,
MAT.outsideDark,
MAT.outsideDark,
MAT.outsideDark,
MAT.outside,
MAT.inside
],
0,
H / 2,
0
);
// Recessed-looking handle on the exterior face.
addBox(
front,
1.02,
0.31,
0.035,
MAT.slot,
0,
H * 0.55,
T / 2 + 0.017,
false
);
addBox(
front,
1.16,
0.055,
0.065,
MAT.outsideLight,
0,
H * 0.55 + 0.18,
T / 2 + 0.035
);
addBox(
front,
1.16,
0.055,
0.065,
MAT.outsideLight,
0,
H * 0.55 - 0.18,
T / 2 + 0.035
);
addOrientationPixels(front, -2.03, 1.64, T / 2 + 0.03, "z");
addOrientationPixels(front, 2.03, 1.64, -T / 2 - 0.03, "z");
// Corner tongues: children of the front panel, rotating into side-wall slots.
const cornerTabs = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * W / 2, 0.92, -T / 2);
front.add(pivot);
addBox(
pivot,
0.16,
0.32,
0.18,
MAT.outsideDark,
0,
0,
0,
false
);
const tongue = addBox(
pivot,
0.72,
0.28,
0.16,
MAT.tab,
-side * 0.36,
0,
0
);
cornerTabs.push({ pivot, tongue, side });
}
// Lid latch tongues: children of the front, folding onto the lid sockets.
const latchTabs = [];
for (const x of [-1.35, 1.35]) {
const pivot = new THREE.Group();
pivot.position.set(x, H + T, T / 2 + 0.06);
front.add(pivot);
addBox(
pivot,
0.57,
0.16,
0.15,
MAT.outsideDark,
0,
0,
0
);
const tongue = addBox(
pivot,
0.48,
0.70,
0.12,
MAT.tab,
0,
0.35,
0
);
latchTabs.push({ pivot, tongue });
}
// -------------------------------------------------------------------------
// Original internal organizer
// -------------------------------------------------------------------------
const organizer = new THREE.Group();
assembly.add(organizer);
addBox(
organizer,
W - 0.56,
0.08,
D - 0.56,
MAT.insideDark,
0,
T + 0.04,
0
);
for (const x of [-0.67, 0.67]) {
addBox(
organizer,
0.08,
0.25,
D - 0.92,
MAT.inside,
x,
T + 0.16,
-0.06
);
}
addBox(
organizer,
W - 0.98,
0.25,
0.08,
MAT.inside,
0,
T + 0.16,
-0.47
);
// Small stored voxel objects.
addBox(organizer, 0.32, 0.28, 0.32, MAT.outsideLight, -1.37, T + 0.22, 0.40);
addBox(organizer, 0.25, 0.38, 0.25, MAT.cream, -0.30, T + 0.27, 0.39);
addBox(organizer, 0.35, 0.22, 0.28, MAT.tab, 1.34, T + 0.19, -0.92);
addBox(organizer, 0.27, 0.27, 0.27, MAT.insideLight, 0.31, T + 0.22, -0.94);
// -------------------------------------------------------------------------
// Clearance envelope and dimensions
// -------------------------------------------------------------------------
const clearanceGroup = new THREE.Group();
scene.add(clearanceGroup);
const envelopeGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(W + 0.30, H + T + 0.16, D + 0.24)
);
const envelope = new THREE.LineSegments(
envelopeGeometry,
new THREE.LineBasicMaterial({
color: 0x69e4df,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
envelope.position.set(0, T + (H + T) / 2, 0);
clearanceGroup.add(envelope);
const dimColor = 0x69e4df;
// Width.
addLine(
clearanceGroup,
[[-W / 2, 0.18, D / 2 + 1.0], [W / 2, 0.18, D / 2 + 1.0]],
dimColor,
0.55
);
for (const x of [-W / 2, W / 2]) {
addLine(
clearanceGroup,
[[x, 0.18, D / 2 + 0.86], [x, 0.18, D / 2 + 1.14]],
dimColor,
0.55
);
}
// Depth.
addLine(
clearanceGroup,
[[W / 2 + 1.0, 0.18, -D / 2], [W / 2 + 1.0, 0.18, D / 2]],
dimColor,
0.55
);
for (const z of [-D / 2, D / 2]) {
addLine(
clearanceGroup,
[[W / 2 + 0.86, 0.18, z], [W / 2 + 1.14, 0.18, z]],
dimColor,
0.55
);
}
// Height.
addLine(
clearanceGroup,
[[-W / 2 - 0.82, T, D / 2], [-W / 2 - 0.82, T + H, D / 2]],
dimColor,
0.55
);
for (const y of [T, T + H]) {
addLine(
clearanceGroup,
[[-W / 2 - 0.96, y, D / 2], [-W / 2 - 0.68, y, D / 2]],
dimColor,
0.55
);
}
const dimensionAnchors = {
width: new THREE.Object3D(),
depth: new THREE.Object3D(),
height: new THREE.Object3D()
};
dimensionAnchors.width.position.set(0, 0.20, D / 2 + 1.08);
dimensionAnchors.depth.position.set(W / 2 + 1.10, 0.20, 0);
dimensionAnchors.height.position.set(-W / 2 - 0.90, T + H / 2, D / 2);
scene.add(
dimensionAnchors.width,
dimensionAnchors.depth,
dimensionAnchors.height
);
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labels = [];
function addLabel(text, anchor, className = "") {
const element = document.createElement("div");
element.className = `tag ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
const label = { element, anchor };
labels.push(label);
return label;
}
addLabel("EXTERIOR +Z", dimensionAnchors.width, "amber");
addLabel("480 mm / 0.48", dimensionAnchors.width);
addLabel("340 mm / 0.34", dimensionAnchors.depth);
addLabel("215 mm / 0.215", dimensionAnchors.height);
addLabel("CORNER TONGUE", cornerTabs[1].pivot, "coral");
addLabel("SIDE SLOT", sideSlotAnchors[1]);
addLabel("LID SOCKET", lidSlots[1], "amber");
addLabel("FOLD AXIS / X", lid);
addLabel("INSIDE FACE", organizer, "amber");
// -------------------------------------------------------------------------
// Timeline
// -------------------------------------------------------------------------
const stages = [
{
short: "BASE DATUM",
title: "00 / BASE DATUM",
detail:
"The floor panel establishes the origin. Exterior faces remain amber; interior faces remain teal.",
start: 0.00,
end: 0.08
},
{
short: "REAR + LID",
title: "01 / REAR PANEL + LID HINGE",
detail:
"The rear panel folds 90° from the bench. Its lid remains rigidly attached to the same hinge axis.",
start: 0.08,
end: 0.26
},
{
short: "SIDE WALLS",
title: "02 / SIDE WALLS",
detail:
"Both side panels fold upward in parallel. Their interior slots remain fixed to each side face.",
start: 0.26,
end: 0.44
},
{
short: "FRONT WALL",
title: "03 / FRONT PANEL",
detail:
"The front wall rotates into position. Corner tongues travel with the front rather than floating independently.",
start: 0.44,
end: 0.61
},
{
short: "LOCK TABS",
title: "04 / CORNER LOCK TABS",
detail:
"The coral tongues rotate 90° and register with the recessed side-wall slots, preserving face orientation.",
start: 0.61,
end: 0.73
},
{
short: "OPEN LID",
title: "05 / LID REVEAL",
detail:
"The hinged lid opens to expose the modular organizer. The lid socket positions follow the lid hinge exactly.",
start: 0.73,
end: 0.82
},
{
short: "CLOSE LID",
title: "06 / LID CLOSE",
detail:
"The lid rotates back along the rear hinge. Its exterior face remains uppermost throughout the travel.",
start: 0.82,
end: 0.93
},
{
short: "LID LATCHES",
title: "07 / LID LATCHES",
detail:
"The front latch tongues fold over the lid edge and align with the two top sockets. Assembly is complete.",
start: 0.93,
end: 1.00
}
];
const stageList = document.getElementById("stage-list");
const stageButtons = [];
stages.forEach((stage, index) => {
const button = document.createElement("button");
button.className = "stage";
button.innerHTML = `
<span class="stage-number">${String(index).padStart(2, "0")}</span>
<span class="stage-name">${stage.short}</span>
`;
button.addEventListener("click", () => {
setPlaying(false);
progress = stage.start + 0.0001;
updateScene(progress);
updateUI();
});
stageList.appendChild(button);
stageButtons.push(button);
});
const scrub = document.getElementById("scrub");
const progressValue = document.getElementById("progress-value");
const playButton = document.getElementById("play");
const stageTitle = document.getElementById("stage-title");
const stageDetail = document.getElementById("stage-detail");
const clearanceToggle = document.getElementById("clearance-toggle");
const labelsToggle = document.getElementById("labels-toggle");
const speedButton = document.getElementById("speed");
let progress = 0;
let playing = false;
let speed = 1;
const speeds = [0.5, 1, 1.5, 2];
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function smoothRange(value, start, end) {
const t = clamp01((value - start) / (end - start));
return t * t * (3 - 2 * t);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function updateScene(value) {
const p = clamp01(value);
// Each fold remains a hierarchy transform, preserving tabs, slots, and faces.
rear.rotation.x = lerp(
-Math.PI / 2,
0,
smoothRange(p, stages[1].start, stages[1].end)
);
const sideFold = smoothRange(p, stages[2].start, stages[2].end);
sidePanels[0].rotation.z = lerp(Math.PI / 2, 0, sideFold);
sidePanels[1].rotation.z = lerp(-Math.PI / 2, 0, sideFold);
front.rotation.x = lerp(
Math.PI / 2,
0,
smoothRange(p, stages[3].start, stages[3].end)
);
const cornerLock = smoothRange(p, stages[4].start, stages[4].end);
for (const tab of cornerTabs) {
tab.pivot.rotation.y = -tab.side * Math.PI / 2 * cornerLock;
}
const lidOpen = smoothRange(p, stages[5].start, stages[5].end);
const lidClosed = smoothRange(p, stages[6].start, stages[6].end);
lid.rotation.x = lerp(0, -Math.PI * 0.62, lidOpen);
lid.rotation.x = lerp(lid.rotation.x, 0, lidClosed);
const latchLock = smoothRange(p, stages[7].start, stages[7].end);
for (const tab of latchTabs) {
tab.pivot.rotation.x = -Math.PI / 2 * latchLock;
}
const activeCorner = Math.max(
0,
1 - Math.abs(p - (stages[4].start + stages[4].end) / 2) / 0.12
);
const activeLatch = Math.max(
0,
1 - Math.abs(p - (stages[7].start + stages[7].end) / 2) / 0.09
);
MAT.tab.emissiveIntensity =
0.16 + activeCorner * 0.62 + activeLatch * 0.48;
clearanceGroup.visible = clearanceToggle.checked;
}
function currentStageIndex(value) {
for (let i = stages.length - 1; i >= 0; i--) {
if (value >= stages[i].start - 0.00001) return i;
}
return 0;
}
function updateUI() {
const percent = Math.round(progress * 100);
scrub.value = String(Math.round(progress * 1000));
scrub.style.setProperty("--progress", `${percent}%`);
progressValue.textContent = `${String(percent).padStart(3, "0")}%`;
const index = currentStageIndex(progress);
stageButtons.forEach((button, i) => {
button.classList.toggle("active", i === index);
});
stageTitle.textContent = stages[index].title;
stageDetail.textContent = stages[index].detail;
playButton.textContent = playing ? "❚❚ PAUSE" : "▶ PLAY";
}
function setPlaying(value) {
playing = value;
updateUI();
}
playButton.addEventListener("click", () => {
if (progress >= 0.9999) {
progress = 0;
updateScene(progress);
}
setPlaying(!playing);
});
document.getElementById("reset").addEventListener("click", () => {
setPlaying(false);
progress = 0;
updateScene(progress);
updateUI();
});
document.getElementById("prev").addEventListener("click", () => {
setPlaying(false);
const index = currentStageIndex(progress);
const targetIndex = progress > stages[index].start + 0.015
? index
: Math.max(0, index - 1);
progress = stages[targetIndex].start + 0.0001;
updateScene(progress);
updateUI();
});
document.getElementById("next").addEventListener("click", () => {
setPlaying(false);
const index = currentStageIndex(progress);
const targetIndex = Math.min(stages.length - 1, index + 1);
progress = stages[targetIndex].end;
updateScene(progress);
updateUI();
});
scrub.addEventListener("input", () => {
const requestedProgress = Number(scrub.value) / 1000;
setPlaying(false);
progress = requestedProgress;
updateScene(progress);
updateUI();
});
clearanceToggle.addEventListener("change", () => {
clearanceGroup.visible = clearanceToggle.checked;
});
labelsToggle.addEventListener("change", () => {
labelLayer.style.display = labelsToggle.checked ? "block" : "none";
});
speedButton.addEventListener("click", () => {
const index = speeds.indexOf(speed);
speed = speeds[(index + 1) % speeds.length];
speedButton.textContent = `${speed.toFixed(1)}×`;
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
} else if (event.code === "ArrowRight") {
event.preventDefault();
document.getElementById("next").click();
} else if (event.code === "ArrowLeft") {
event.preventDefault();
document.getElementById("prev").click();
} else if (event.code === "Home") {
document.getElementById("reset").click();
}
});
// -------------------------------------------------------------------------
// Direct camera controls: no addon imports
// -------------------------------------------------------------------------
let dragging = false;
let previousPointer = { x: 0, y: 0 };
let activePointer = null;
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
activePointer = event.pointerId;
dragging = true;
previousPointer = { x: event.clientX, y: event.clientY };
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0) {
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * (distance / pinchDistance),
0.62,
2.3
);
}
pinchDistance = distance;
return;
}
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer = { x: event.clientX, y: event.clientY };
if (event.button === 2 || event.shiftKey) {
const worldPerPixel =
(camera.top - camera.bottom) / camera.zoom / window.innerHeight;
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
cameraTarget.addScaledVector(right, -dx * worldPerPixel);
cameraTarget.addScaledVector(up, dy * worldPerPixel);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.006,
0.34,
1.38
);
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) {
dragging = false;
activePointer = null;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.3
);
},
{ passive: false }
);
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
// -------------------------------------------------------------------------
// Resize and projected label placement
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
const desiredWidth = aspect < 1 ? 10.4 : 12.8;
const viewHeight = desiredWidth / aspect;
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const projected = new THREE.Vector3();
function updateLabels() {
if (!labelsToggle.checked) return;
for (const label of labels) {
label.anchor.getWorldPosition(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
if (!visible) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
label.element.style.opacity = "0.88";
}
}
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
progress = clamp01(progress + delta * 0.115 * speed);
if (progress >= 1) setPlaying(false);
updateScene(progress);
updateUI();
}
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
updateScene(progress);
updateUI();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```