Prompt specification
Build or customize the Three.js 3D scene "Shelf-fitting 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: Shelf-fitting preparation table
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shelf-fitting-preparation-table-x0283
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Compose a wall alcove, measuring tape, cardboard template, and proposed shelf; transfer the opening's measured width to the template before checking its fit in place.
Working Three.js Starter (shelf-fitting-preparation-table-x0283):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Alcove Shelf — Measure, Transfer, Test</title>
<style>
:root {
--ink: #203331;
--muted: #667875;
--paper: rgba(250, 248, 241, 0.92);
--line: rgba(32, 51, 49, 0.13);
--teal: #246f68;
--teal-dark: #18544f;
--orange: #d9784c;
--green: #2d8b68;
--shadow: 0 24px 70px rgba(38, 53, 49, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e4da;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#scene canvas {
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 48% 43%, transparent 44%, rgba(54, 60, 55, 0.09) 100%),
linear-gradient(180deg, rgba(255,255,255,0.12), transparent 28%);
}
.title-block {
position: fixed;
top: 30px;
left: 34px;
width: min(430px, calc(100vw - 430px));
pointer-events: none;
z-index: 3;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
padding: 7px 10px;
border: 1px solid rgba(32, 51, 49, 0.13);
border-radius: 999px;
background: rgba(249, 247, 240, 0.76);
backdrop-filter: blur(12px);
color: var(--teal-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(217, 120, 76, 0.14);
}
h1 {
max-width: 420px;
margin: 0;
font-size: clamp(34px, 4vw, 58px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 780;
}
.title-block p {
max-width: 370px;
margin: 15px 0 0;
color: #566864;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 5;
top: 26px;
right: 26px;
width: 342px;
max-height: calc(100vh - 52px);
overflow: auto;
padding: 22px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 25px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(22px) saturate(1.15);
}
.panel-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.panel-kicker {
margin: 0 0 5px;
color: var(--orange);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 20px;
letter-spacing: -0.025em;
}
.sequence-number {
flex: 0 0 auto;
min-width: 49px;
padding: 8px 9px;
border-radius: 13px;
background: #e5eee9;
color: var(--teal-dark);
text-align: center;
font-size: 11px;
font-weight: 800;
}
#instruction {
min-height: 64px;
margin: 16px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.progress-track {
height: 4px;
overflow: hidden;
border-radius: 999px;
background: #dde3de;
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--orange), var(--teal));
transition: width 500ms cubic-bezier(.2,.8,.2,1);
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 13px 0 19px;
}
.step {
color: #82908d;
font-size: 10px;
font-weight: 750;
line-height: 1.25;
}
.step span {
display: grid;
place-items: center;
width: 23px;
height: 23px;
margin-bottom: 6px;
border: 1px solid #ccd5d0;
border-radius: 50%;
background: rgba(255,255,255,0.55);
font-size: 10px;
}
.step.active {
color: var(--orange);
}
.step.active span {
border-color: var(--orange);
background: #fff5ef;
box-shadow: 0 0 0 4px rgba(217, 120, 76, 0.09);
}
.step.done {
color: var(--teal);
}
.step.done span {
border-color: var(--teal);
background: var(--teal);
color: white;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
overflow: hidden;
margin: 0 0 17px;
border: 1px solid var(--line);
border-radius: 17px;
background: rgba(255,255,255,0.52);
}
.metric {
min-width: 0;
padding: 13px 14px;
}
.metric:nth-child(odd) {
border-right: 1px solid var(--line);
}
.metric:nth-child(-n+2) {
border-bottom: 1px solid var(--line);
}
.metric dt {
margin: 0 0 4px;
color: #7c8986;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.metric dd {
overflow: hidden;
margin: 0;
color: var(--ink);
font-size: 15px;
font-weight: 760;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric.full {
grid-column: 1 / -1;
border-right: 0;
}
.metric.success dd {
color: var(--green);
}
.actions {
display: grid;
gap: 9px;
}
.action {
display: flex;
align-items: center;
width: 100%;
min-height: 48px;
padding: 10px 12px;
border: 1px solid transparent;
border-radius: 14px;
background: var(--teal);
color: white;
cursor: pointer;
text-align: left;
transition:
transform 160ms ease,
background 160ms ease,
opacity 160ms ease,
box-shadow 160ms ease;
}
.action:hover:not(:disabled) {
transform: translateY(-1px);
background: var(--teal-dark);
box-shadow: 0 9px 22px rgba(36, 111, 104, 0.22);
}
.action:active:not(:disabled) {
transform: translateY(1px);
}
.action:disabled {
cursor: not-allowed;
opacity: 0.42;
}
.action.secondary {
border-color: var(--line);
background: rgba(255,255,255,0.62);
color: var(--ink);
}
.action.secondary:hover:not(:disabled) {
background: white;
box-shadow: 0 8px 18px rgba(38,53,49,0.08);
}
.action.complete {
border-color: rgba(36, 111, 104, 0.2);
background: #e5eee9;
color: var(--teal-dark);
opacity: 0.75;
}
.button-number {
display: grid;
flex: 0 0 auto;
place-items: center;
width: 25px;
height: 25px;
margin-right: 10px;
border-radius: 8px;
background: rgba(255,255,255,0.18);
font-size: 11px;
font-weight: 850;
}
.button-copy {
display: flex;
flex: 1;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.button-copy strong {
font-size: 13px;
font-weight: 760;
}
.button-copy small {
opacity: 0.73;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.panel-footer p {
margin: 0;
color: #7a8885;
font-size: 10px;
line-height: 1.45;
}
.text-button {
flex: 0 0 auto;
padding: 7px 9px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--teal);
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.text-button:hover {
background: #e8efeb;
}
.scene-caption {
position: fixed;
z-index: 3;
left: 34px;
bottom: 27px;
display: flex;
align-items: center;
gap: 11px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,0.56);
border-radius: 13px;
background: rgba(249,247,240,0.72);
backdrop-filter: blur(14px);
color: #596b67;
pointer-events: none;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
}
.scene-caption::before {
content: "";
width: 8px;
height: 8px;
border-radius: 3px;
background: var(--teal);
}
@media (max-width: 760px) {
.title-block {
top: 16px;
left: 16px;
width: calc(100vw - 32px);
}
.title-block p {
display: none;
}
h1 {
max-width: 290px;
font-size: 34px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 48vh;
padding: 17px;
border-radius: 21px;
}
.panel h2 {
font-size: 17px;
}
#instruction {
min-height: 0;
margin: 10px 0 12px;
}
.steps {
margin-bottom: 12px;
}
.metrics {
margin-bottom: 12px;
}
.metric {
padding: 9px 11px;
}
.action {
min-height: 43px;
}
.scene-caption {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="title-block">
<div class="eyebrow">Workshop / Fit Study 04</div>
<h1>Measure it.<br />Transfer it. Test it.</h1>
<p>
A guided shelf-planning scene: measure the alcove, carry the width onto
the cardboard template, then place the proposed shelf in the opening.
</p>
</header>
<aside class="panel" aria-label="Shelf fitting controls">
<div class="panel-top">
<div>
<p class="panel-kicker">Guided workflow</p>
<h2>Alcove shelf preparation</h2>
</div>
<div class="sequence-number" id="sequenceNumber">1 / 3</div>
</div>
<p id="instruction" aria-live="polite">
Start by measuring the opening. The template remains locked until the
measurement has been copied.
</p>
<div class="progress-track" aria-hidden="true">
<div id="progressFill"></div>
</div>
<div class="steps" aria-label="Progress">
<div class="step active"><span>1</span>Measure</div>
<div class="step"><span>2</span>Transfer</div>
<div class="step"><span>3</span>Test fit</div>
</div>
<dl class="metrics">
<div class="metric">
<dt>Opening width</dt>
<dd id="openingValue">—</dd>
</div>
<div class="metric">
<dt>Template width</dt>
<dd id="templateValue">—</dd>
</div>
<div class="metric full" id="fitMetric">
<dt>Fit result</dt>
<dd id="fitValue">Not checked</dd>
</div>
</dl>
<div class="actions">
<button class="action" id="measureButton">
<span class="button-number">1</span>
<span class="button-copy">
<strong>Measure opening</strong>
<small>Read</small>
</span>
</button>
<button class="action secondary" id="transferButton" disabled>
<span class="button-number">2</span>
<span class="button-copy">
<strong>Transfer to template</strong>
<small>Copy</small>
</span>
</button>
<button class="action secondary" id="fitButton" disabled>
<span class="button-number">3</span>
<span class="button-copy">
<strong>Check in place</strong>
<small>Fit</small>
</span>
</button>
<button class="action secondary" id="resetButton">
<span class="button-number">↺</span>
<span class="button-copy">
<strong>Reset workflow</strong>
<small>Again</small>
</span>
</button>
</div>
<div class="panel-footer">
<p>
Drag to orbit · Scroll to zoom<br />
Right-drag to pan · Click objects to use them
</p>
<button class="text-button" id="cameraButton">Recenter</button>
</div>
</aside>
<div class="scene-caption">
Finished opening: 2160 × 1800 mm · Proposed shelf: 2120 mm
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and lighting
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e4da);
scene.fog = new THREE.Fog(0xe8e4da, 13, 25);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
60
);
const hemi = new THREE.HemisphereLight(0xfffbef, 0x667d78, 2.15);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff2d5, 3.1);
keyLight.position.set(4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9ec8c1, 1.05);
fillLight.position.set(-5, 4, 3);
scene.add(fillLight);
const alcoveLight = new THREE.PointLight(0xffd8a0, 3.2, 4.2, 2);
alcoveLight.position.set(-1.2, 2.15, -0.1);
scene.add(alcoveLight);
const motionFactor = window.matchMedia("(prefers-reduced-motion: reduce)").matches
? 0.18
: 1;
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
}
const wallMaterial = standardMaterial(0xd8d5cb);
const wallEdgeMaterial = standardMaterial(0xc9c6bc);
const interiorMaterial = standardMaterial(0x334b52);
const interiorPanelMaterial = standardMaterial(0x405a60);
const floorMaterial = standardMaterial(0xaebbb4);
const woodMaterial = standardMaterial(0x9e7751);
const darkMetalMaterial = standardMaterial(0x263b3d, { metalness: 0.35 });
const cardboardMaterial = standardMaterial(0xffffff);
const yellowMaterial = standardMaterial(0xf2c748, { roughness: 0.54 });
const orangeMaterial = standardMaterial(0xd9784c);
const tealMaterial = standardMaterial(0x4d9f96, {
roughness: 0.5,
transparent: true,
opacity: 0.58,
depthWrite: false
});
function addBox(parent, width, height, depth, material, x, y, z, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x304743, opacity = 0.3) {
const edges = new THREE.EdgesGeometry(mesh.geometry, 25);
const lines = new THREE.LineSegments(
edges,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(lines);
return lines;
}
function makeCanvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function roundedRectPath(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeLabel(initialText, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const height = options.height ?? 0.26;
const aspect = canvas.width / canvas.height;
sprite.scale.set(height * aspect, height, 1);
sprite.renderOrder = 30;
function setText(text, accent = options.accent ?? "#f2c748") {
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRectPath(context, 8, 8, 752, 144, 28);
context.fillStyle = options.background ?? "rgba(29, 48, 46, 0.94)";
context.fill();
context.strokeStyle = accent;
context.lineWidth = 5;
context.stroke();
context.fillStyle = accent;
context.fillRect(28, 28, 8, 104);
let fontSize = options.fontSize ?? 49;
context.font = `800 ${fontSize}px Inter, system-ui, sans-serif`;
while (context.measureText(text).width > 655 && fontSize > 22) {
fontSize -= 2;
context.font = `800 ${fontSize}px Inter, system-ui, sans-serif`;
}
context.fillStyle = "#fffdf6";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 395, 82);
texture.needsUpdate = true;
}
setText(initialText);
sprite.userData.setText = setText;
return sprite;
}
function makeHorizontalDimension(color) {
const group = new THREE.Group();
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([-1, 0, 0, 1, 0, 0], 3)
);
const lineMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95
});
const line = new THREE.Line(geometry, lineMaterial);
line.frustumCulled = false;
group.add(line);
const arrowGeometry = new THREE.ConeGeometry(0.026, 0.09, 12);
const leftArrow = new THREE.Mesh(arrowGeometry, lineMaterial);
const rightArrow = new THREE.Mesh(arrowGeometry, lineMaterial);
leftArrow.rotation.z = -Math.PI / 2;
rightArrow.rotation.z = Math.PI / 2;
group.add(leftArrow, rightArrow);
return { group, line, leftArrow, rightArrow, material: lineMaterial };
}
function resizeDimension(dimension, width) {
const half = width / 2;
const positions = dimension.line.geometry.attributes.position;
positions.setXYZ(0, -half, 0, 0);
positions.setXYZ(1, half, 0, 0);
positions.needsUpdate = true;
dimension.leftArrow.position.x = -half;
dimension.rightArrow.position.x = half;
}
function colorDimension(dimension, color) {
dimension.material.color.set(color);
}
// -------------------------------------------------------------------------
// Dimensions used by the complete workflow
// -------------------------------------------------------------------------
const OPENING_WIDTH = 2.16;
const OPENING_HEIGHT = 1.80;
const OPENING_BOTTOM = 0.62;
const OPENING_TOP = OPENING_BOTTOM + OPENING_HEIGHT;
const OPENING_CENTER_X = -1.20;
const OPENING_LEFT = OPENING_CENTER_X - OPENING_WIDTH / 2;
const OPENING_RIGHT = OPENING_CENTER_X + OPENING_WIDTH / 2;
const OPENING_WIDTH_MM = 2160;
const SHELF_WIDTH = 2.12;
const SHELF_CLEARANCE = (OPENING_WIDTH - SHELF_WIDTH) / 2;
const SHELF_CLEARANCE_MM = Math.round(SHELF_CLEARANCE * 1000);
const TEMPLATE_BASE_WIDTH = 1.94;
// -------------------------------------------------------------------------
// Floor, wall, and recessed alcove
// -------------------------------------------------------------------------
const floor = addBox(
scene,
16,
0.16,
13,
floorMaterial,
0,
-0.08,
1.5,
false
);
floor.receiveShadow = true;
const grid = new THREE.GridHelper(16, 40, 0x80928b, 0x99aaa2);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.19;
scene.add(grid);
const WALL_LEFT = -4.50;
const WALL_RIGHT = 1.55;
const WALL_HEIGHT = 4.20;
const WALL_DEPTH = 0.18;
function addWallBlock(width, height, x, y) {
const block = addBox(
scene,
width,
height,
WALL_DEPTH,
wallMaterial,
x,
y,
0
);
addEdges(block, 0x747d76, 0.12);
return block;
}
addWallBlock(
OPENING_LEFT - WALL_LEFT,
WALL_HEIGHT,
(WALL_LEFT + OPENING_LEFT) / 2,
WALL_HEIGHT / 2
);
addWallBlock(
WALL_RIGHT - OPENING_RIGHT,
WALL_HEIGHT,
(WALL_RIGHT + OPENING_RIGHT) / 2,
WALL_HEIGHT / 2
);
addWallBlock(
OPENING_WIDTH,
WALL_HEIGHT - OPENING_TOP,
OPENING_CENTER_X,
(WALL_HEIGHT + OPENING_TOP) / 2
);
addWallBlock(
OPENING_WIDTH,
OPENING_BOTTOM,
OPENING_CENTER_X,
OPENING_BOTTOM / 2
);
const alcoveDepth = 0.40;
const backPanel = addBox(
scene,
OPENING_WIDTH,
OPENING_HEIGHT,
0.05,
interiorMaterial,
OPENING_CENTER_X,
OPENING_BOTTOM + OPENING_HEIGHT / 2,
-alcoveDepth
);
addEdges(backPanel, 0x8da4a0, 0.16);
addBox(
scene,
0.07,
OPENING_HEIGHT,
alcoveDepth,
wallEdgeMaterial,
OPENING_LEFT - 0.035,
OPENING_BOTTOM + OPENING_HEIGHT / 2,
-alcoveDepth / 2
);
addBox(
scene,
0.07,
OPENING_HEIGHT,
alcoveDepth,
wallEdgeMaterial,
OPENING_RIGHT + 0.035,
OPENING_BOTTOM + OPENING_HEIGHT / 2,
-alcoveDepth / 2
);
addBox(
scene,
OPENING_WIDTH + 0.14,
0.07,
alcoveDepth,
wallEdgeMaterial,
OPENING_CENTER_X,
OPENING_TOP + 0.035,
-alcoveDepth / 2
);
addBox(
scene,
OPENING_WIDTH + 0.14,
0.07,
alcoveDepth,
wallEdgeMaterial,
OPENING_CENTER_X,
OPENING_BOTTOM - 0.035,
-alcoveDepth / 2
);
for (let i = 0; i < 7; i++) {
addBox(
scene,
0.018,
OPENING_HEIGHT - 0.18,
0.012,
interiorPanelMaterial,
OPENING_LEFT + 0.25 + i * 0.27,
OPENING_BOTTOM + OPENING_HEIGHT / 2,
-0.365,
false
);
}
addBox(
scene,
WALL_RIGHT - WALL_LEFT,
0.12,
0.08,
wallEdgeMaterial,
(WALL_LEFT + WALL_RIGHT) / 2,
0.06,
0.11
);
// -------------------------------------------------------------------------
// Workbench and cardboard template
// -------------------------------------------------------------------------
const bench = new THREE.Group();
scene.add(bench);
addBox(bench, 3.05, 0.12, 1.08, woodMaterial, 2.80, 0.28, 1.28);
for (const x of [1.55, 4.05]) {
for (const z of [0.92, 1.64]) {
addBox(bench, 0.10, 0.30, 0.10, darkMetalMaterial, x, 0.10, z);
}
}
addBox(bench, 2.76, 0.08, 0.06, darkMetalMaterial, 2.80, 0.16, 1.27);
const cardboardTexture = makeCanvasTexture(512, 512, (context, width, height) => {
context.fillStyle = "#bd8858";
context.fillRect(0, 0, width, height);
let seed = 12345;
const random = () => {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
};
for (let i = 0; i < 2100; i++) {
const x = random() * width;
const y = random() * height;
const alpha = 0.025 + random() * 0.06;
context.fillStyle = random() > 0.52
? `rgba(85,52,31,${alpha})`
: `rgba(255,235,196,${alpha})`;
context.fillRect(x, y, 1 + random() * 3, 1);
}
context.strokeStyle = "rgba(87,57,34,0.16)";
context.lineWidth = 1;
for (let y = 0; y < height; y += 32) {
context.beginPath();
context.moveTo(0, y);
context.lineTo(width, y + 6);
context.stroke();
}
});
cardboardMaterial.map = cardboardTexture;
cardboardMaterial.color.set(0xffffff);
cardboardMaterial.roughness = 0.95;
const templateGroup = new THREE.Group();
templateGroup.position.set(2.76, 1.16, 1.40);
templateGroup.rotation.set(-0.035, -0.30, 0);
templateGroup.userData.action = "transfer";
scene.add(templateGroup);
const templateBoard = addBox(
templateGroup,
1,
1.55,
0.055,
cardboardMaterial,
0,
0,
0
);
templateBoard.scale.x = TEMPLATE_BASE_WIDTH;
addEdges(templateBoard, 0x795537, 0.4);
const printedOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.43, -0.56, 0.032),
new THREE.Vector3(0.43, -0.56, 0.032),
new THREE.Vector3(0.43, 0.43, 0.032),
new THREE.Vector3(-0.43, 0.43, 0.032)
]),
new THREE.LineBasicMaterial({
color: 0x66462f,
transparent: true,
opacity: 0.62
})
);
templateBoard.add(printedOutline);
const pencilLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.49, -0.63, 0.033),
new THREE.Vector3(0.49, -0.63, 0.033)
]),
new THREE.LineBasicMaterial({
color: 0x805c3c,
transparent: true,
opacity: 0.4
})
);
templateBoard.add(pencilLine);
const templateDimension = makeHorizontalDimension(0xd9784c);
templateDimension.group.position.set(0, 0.54, 0.09);
templateGroup.add(templateDimension.group);
function updateTemplateDimension(width) {
resizeDimension(templateDimension, width);
}
updateTemplateDimension(TEMPLATE_BASE_WIDTH);
const templateMeasureLabel = makeLabel("COPY WIDTH HERE", {
height: 0.25,
accent: "#e59663"
});
templateMeasureLabel.position.set(0, 0.78, 0.13);
templateGroup.add(templateMeasureLabel);
const templateNameLabel = makeLabel("CARDBOARD TEMPLATE", {
height: 0.18,
accent: "#d9784c",
fontSize: 40
});
templateNameLabel.position.set(0, 0.94, 0.11);
templateGroup.add(templateNameLabel);
const pencil = addBox(
scene,
0.72,
0.055,
0.055,
orangeMaterial,
2.13,
0.385,
1.60
);
pencil.rotation.y = -0.20;
addBox(scene, 0.12, 0.06, 0.055, darkMetalMaterial, 1.77, 0.385, 1.67);
// -------------------------------------------------------------------------
// Measuring tape case and animated tape across the opening
// -------------------------------------------------------------------------
const tapeCase = new THREE.Group();
tapeCase.position.set(3.72, 0.43, 1.25);
tapeCase.rotation.y = -0.18;
tapeCase.userData.action = "measure";
scene.add(tapeCase);
addBox(tapeCase, 0.36, 0.23, 0.18, yellowMaterial, 0, 0, 0);
addBox(tapeCase, 0.23, 0.07, 0.19, darkMetalMaterial, 0, 0.09, 0);
addBox(tapeCase, 0.12, 0.04, 0.20, standardMaterial(0xbcc4c0), 0.10, 0.13, 0);
const tapeCaseLabel = makeLabel("TAPE", {
height: 0.16,
accent: "#f2c748",
fontSize: 40
});
tapeCaseLabel.position.set(0, 0.33, 0.02);
tapeCase.add(tapeCaseLabel);
const tapeGroup = new THREE.Group();
tapeGroup.position.set(OPENING_CENTER_X, 2.79, 0.22);
tapeGroup.scale.x = 0.015;
tapeGroup.visible = false;
scene.add(tapeGroup);
addBox(tapeGroup, 1, 0.082, 0.038, yellowMaterial, 0, 0, 0);
const tickMaterial = standardMaterial(0x253130);
for (let i = 0; i <= 40; i++) {
const tickHeight = i % 5 === 0 ? 0.055 : 0.034;
addBox(
tapeGroup,
0.007,
tickHeight,
0.006,
tickMaterial,
-0.5 + i / 40,
-0.012,
0.022,
false
);
}
addBox(tapeGroup, 0.045, 0.11, 0.05, standardMaterial(0xb5c0bc), -0.515, -0.01, 0);
addBox(tapeGroup, 0.045, 0.11, 0.05, standardMaterial(0xb5c0bc), 0.515, -0.01, 0);
const tapeMeasureLabel = makeLabel("0 mm", {
height: 0.28,
accent: "#f2c748"
});
tapeMeasureLabel.position.set(OPENING_CENTER_X, 3.05, 0.32);
tapeMeasureLabel.visible = false;
scene.add(tapeMeasureLabel);
const openingDimension = makeHorizontalDimension(0xf2c748);
openingDimension.group.position.set(OPENING_CENTER_X, 2.78, 0.25);
openingDimension.group.visible = false;
scene.add(openingDimension.group);
resizeDimension(openingDimension, OPENING_WIDTH);
// -------------------------------------------------------------------------
// Proposed shelf, initially ghosted on the floor
// -------------------------------------------------------------------------
const shelfGroup = new THREE.Group();
const shelfStartPosition = new THREE.Vector3(2.58, 0.17, 2.70);
const shelfTargetPosition = new THREE.Vector3(
OPENING_CENTER_X,
1.16,
-0.075
);
shelfGroup.position.copy(shelfStartPosition);
shelfGroup.rotation.y = -0.27;
shelfGroup.userData.action = "fit";
scene.add(shelfGroup);
const shelfBoard = addBox(
shelfGroup,
SHELF_WIDTH,
0.08,
0.34,
tealMaterial,
0,
0,
0
);
addEdges(shelfBoard, 0x1c5c58, 0.72);
addBox(
shelfGroup,
SHELF_WIDTH,
0.045,
0.018,
orangeMaterial,
0,
-0.014,
0.173
);
addBox(
shelfGroup,
0.13,
0.14,
0.28,
darkMetalMaterial,
-0.73,
-0.09,
-0.005
);
addBox(
shelfGroup,
0.13,
0.14,
0.28,
darkMetalMaterial,
0.73,
-0.09,
-0.005
);
const shelfLabel = makeLabel("PROPOSED SHELF", {
height: 0.18,
accent: "#68b7ad",
fontSize: 40
});
shelfLabel.position.set(0, 0.36, 0.03);
shelfGroup.add(shelfLabel);
const copyMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 20, 16),
new THREE.MeshStandardMaterial({
color: 0x65c5b8,
emissive: 0x286f69,
emissiveIntensity: 0.8,
roughness: 0.35
})
);
copyMarker.castShadow = true;
copyMarker.visible = false;
scene.add(copyMarker);
const fitCallout = makeLabel(
`FITS · ${SHELF_CLEARANCE_MM} mm / SIDE`,
{
height: 0.25,
accent: "#63c68c",
fontSize: 43
}
);
fitCallout.position.set(OPENING_CENTER_X, 1.94, 0.32);
fitCallout.visible = false;
scene.add(fitCallout);
const fitLeader = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(OPENING_RIGHT, 1.18, 0.22),
new THREE.Vector3(0.20, 1.82, 0.30)
]),
new THREE.LineBasicMaterial({
color: 0x4aa474,
transparent: true,
opacity: 0.9
})
);
fitLeader.visible = false;
scene.add(fitLeader);
// -------------------------------------------------------------------------
// Custom camera controls — no external controls addon
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(-0.10, 1.28, 0.25),
radius: 9.65,
theta: 0.57,
phi: 1.12
};
function resetCamera() {
controls.target.set(-0.10, 1.28, 0.25);
controls.radius = window.innerWidth < 760 ? 11.8 : 9.65;
controls.theta = 0.57;
controls.phi = 1.12;
camera.fov = window.innerWidth < 760 ? 51 : 43;
camera.updateProjectionMatrix();
updateCamera();
}
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const interactiveRoots = [tapeCase, templateGroup, shelfGroup];
let dragState = null;
function findAction(object) {
let current = object;
while (current) {
if (current.userData && current.userData.action) {
return current.userData.action;
}
current = current.parent;
}
return null;
}
function pickAction(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactiveRoots, true);
for (const hit of hits) {
const action = findAction(hit.object);
if (action) return action;
}
return null;
}
function actionIsAvailable(action) {
return (
(action === "measure" && stage === 0) ||
(action === "transfer" && stage === 1) ||
(action === "fit" && stage === 2)
);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 1 && event.button !== 2) return;
dragState = {
pointerId: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false,
button: event.button
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragState) {
const action = pickAction(event.clientX, event.clientY);
renderer.domElement.style.cursor = actionIsAvailable(action)
? "pointer"
: "grab";
return;
}
const dx = event.clientX - dragState.lastX;
const dy = event.clientY - dragState.lastY;
const totalDistance = Math.hypot(
event.clientX - dragState.startX,
event.clientY - dragState.startY
);
if (totalDistance > 4) dragState.moved = true;
if (dragState.button === 0 && !event.shiftKey) {
controls.theta -= dx * 0.0055;
controls.phi -= dy * 0.0045;
controls.phi = THREE.MathUtils.clamp(controls.phi, 0.43, 1.43);
} else {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
const panScale = controls.radius * 0.0013;
controls.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -4, 4);
controls.target.y = THREE.MathUtils.clamp(controls.target.y, 0.45, 3.3);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -1.5, 3.5);
}
dragState.lastX = event.clientX;
dragState.lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragState) return;
const wasClick = !dragState.moved && dragState.button === 0;
const action = wasClick
? pickAction(event.clientX, event.clientY)
: null;
renderer.domElement.releasePointerCapture(event.pointerId);
renderer.domElement.classList.remove("dragging");
dragState = null;
if (action) requestAction(action);
});
renderer.domElement.addEventListener("pointercancel", () => {
dragState = null;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
4.7,
15
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI and workflow state
// -------------------------------------------------------------------------
const ui = {
instruction: document.getElementById("instruction"),
sequenceNumber: document.getElementById("sequenceNumber"),
progressFill: document.getElementById("progressFill"),
openingValue: document.getElementById("openingValue"),
templateValue: document.getElementById("templateValue"),
fitValue: document.getElementById("fitValue"),
fitMetric: document.getElementById("fitMetric"),
measureButton: document.getElementById("measureButton"),
transferButton: document.getElementById("transferButton"),
fitButton: document.getElementById("fitButton"),
resetButton: document.getElementById("resetButton"),
cameraButton: document.getElementById("cameraButton"),
steps: [...document.querySelectorAll(".step")]
};
let stage = 0;
let currentTemplateWidth = TEMPLATE_BASE_WIDTH;
let instructionTimer = null;
function setStage(nextStage) {
stage = nextStage;
ui.sequenceNumber.textContent = `${Math.min(stage + 1, 3)} / 3`;
ui.progressFill.style.width = `${(stage / 3) * 100}%`;
ui.steps.forEach((step, index) => {
step.classList.toggle("done", index < stage);
step.classList.toggle("active", index === stage);
});
ui.measureButton.disabled = stage !== 0;
ui.transferButton.disabled = stage !== 1;
ui.fitButton.disabled = stage !== 2;
ui.measureButton.classList.toggle("complete", stage > 0);
ui.transferButton.classList.toggle("complete", stage > 1);
ui.fitButton.classList.toggle("complete", stage > 2);
if (stage === 0) {
ui.instruction.textContent =
"Start by measuring the opening. The template remains locked until the measurement has been copied.";
} else if (stage === 1) {
ui.instruction.textContent =
"Opening measured at 2160 mm. Transfer this exact width to the cardboard template before placing the shelf.";
} else if (stage === 2) {
ui.instruction.textContent =
"The template now carries the 2160 mm opening width. Place the proposed shelf and check its side clearance.";
} else {
ui.instruction.textContent =
"The proposed shelf fits inside the opening with 20 mm clearance on each side. The measurement has been completed and transferred.";
}
}
function temporaryInstruction(message) {
ui.instruction.textContent = message;
clearTimeout(instructionTimer);
instructionTimer = setTimeout(() => {
if (stage === 0) {
ui.instruction.textContent =
"Start by measuring the opening. The template remains locked until the measurement has been copied.";
} else if (stage === 1) {
ui.instruction.textContent =
"Opening measured at 2160 mm. Transfer this exact width to the cardboard template before placing the shelf.";
} else if (stage === 2) {
ui.instruction.textContent =
"The template now carries the 2160 mm opening width. Place the proposed shelf and check its side clearance.";
}
}, 2300);
}
function requestAction(action) {
if (action === "measure") {
if (stage === 0) startMeasure();
else temporaryInstruction("The opening has already been measured.");
} else if (action === "transfer") {
if (stage === 1) startTransfer();
else if (stage === 0) {
temporaryInstruction("Measure the opening first. The template stays locked until then.");
} else {
temporaryInstruction("The measured width has already been transferred.");
}
} else if (action === "fit") {
if (stage === 2) startFitCheck();
else if (stage < 2) {
temporaryInstruction("Transfer the measured width to the template before checking the fit.");
} else {
temporaryInstruction("The shelf is already in place and the fit is confirmed.");
}
}
}
ui.measureButton.addEventListener("click", () => requestAction("measure"));
ui.transferButton.addEventListener("click", () => requestAction("transfer"));
ui.fitButton.addEventListener("click", () => requestAction("fit"));
ui.cameraButton.addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Minimal tween system
// -------------------------------------------------------------------------
const tweens = [];
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function easeOutCubic(value) {
return 1 - Math.pow(1 - value, 3);
}
function addTween(duration, onUpdate, onComplete, easing = easeInOutCubic) {
tweens.push({
start: performance.now(),
duration: Math.max(1, duration * motionFactor),
onUpdate,
onComplete,
easing
});
}
// -------------------------------------------------------------------------
// Step 1: measure the finished opening
// -------------------------------------------------------------------------
function startMeasure() {
ui.measureButton.disabled = true;
ui.instruction.textContent =
"Extending the tape between the finished inside faces of the alcove…";
tapeGroup.visible = true;
tapeGroup.scale.x = 0.015;
tapeGroup.position.y = 2.86;
tapeMeasureLabel.visible = true;
tapeMeasureLabel.userData.setText("0 mm");
addTween(
1500,
(eased, raw) => {
tapeGroup.scale.x = THREE.MathUtils.lerp(0.015, 1, eased);
tapeGroup.position.y = THREE.MathUtils.lerp(2.86, 2.56, eased);
const displayed = Math.round(
(OPENING_WIDTH_MM * raw) / 10
) * 10;
tapeMeasureLabel.userData.setText(`${displayed} mm`);
ui.openingValue.textContent = `${displayed} mm`;
},
() => {
tapeGroup.scale.x = 1;
tapeGroup.position.y = 2.56;
tapeMeasureLabel.userData.setText("2160 mm");
ui.openingValue.textContent = "2160 mm";
openingDimension.group.visible = true;
setStage(1);
},
easeOutCubic
);
}
// -------------------------------------------------------------------------
// Step 2: copy the opening width onto the cardboard template
// -------------------------------------------------------------------------
function startTransfer() {
ui.transferButton.disabled = true;
ui.instruction.textContent =
"Carrying the measured 2160 mm from the tape to the cardboard template…";
copyMarker.visible = true;
const start = new THREE.Vector3(
OPENING_CENTER_X,
2.88,
0.36
);
scene.updateMatrixWorld(true);
const end = templateGroup.localToWorld(
new THREE.Vector3(0, 0.78, 0.14)
);
const control = new THREE.Vector3(
0.65,
3.45,
1.65
);
const transferCurve = new THREE.QuadraticBezierCurve3(
start,
control,
end
);
addTween(
1650,
(eased) => {
currentTemplateWidth = THREE.MathUtils.lerp(
TEMPLATE_BASE_WIDTH,
OPENING_WIDTH,
eased
);
templateBoard.scale.x = currentTemplateWidth;
updateTemplateDimension(currentTemplateWidth);
copyMarker.position.copy(transferCurve.getPoint(eased));
if (eased < 0.56) {
templateMeasureLabel.userData.setText("COPYING…");
} else {
const widthMM = Math.round(
(OPENING_WIDTH_MM * eased) / 10
) * 10;
templateMeasureLabel.userData.setText(`${widthMM} mm`);
ui.templateValue.textContent = `${widthMM} mm`;
}
},
() => {
currentTemplateWidth = OPENING_WIDTH;
templateBoard.scale.x = currentTemplateWidth;
updateTemplateDimension(currentTemplateWidth);
templateMeasureLabel.userData.setText("2160 mm");
ui.templateValue.textContent = "2160 mm";
colorDimension(templateDimension, 0x3f9d91);
copyMarker.visible = false;
setStage(2);
}
);
}
// -------------------------------------------------------------------------
// Step 3: place the proposed shelf and confirm fit
// -------------------------------------------------------------------------
function startFitCheck() {
ui.fitButton.disabled = true;
ui.instruction.textContent =
"Placing the 2120 mm proposed shelf against the measured 2160 mm opening…";
const startPosition = shelfGroup.position.clone();
const startRotation = shelfGroup.rotation.y;
addTween(
1750,
(eased) => {
shelfGroup.position.lerpVectors(
startPosition,
shelfTargetPosition,
eased
);
shelfGroup.position.y += Math.sin(eased * Math.PI) * 0.24;
shelfGroup.rotation.y = THREE.MathUtils.lerp(
startRotation,
0,
eased
);
tealMaterial.opacity = THREE.MathUtils.lerp(0.58, 1, eased);
if (eased < 0.82) {
shelfLabel.userData.setText("CHECKING…");
} else {
shelfLabel.userData.setText("PROPOSED SHELF");
}
},
() => {
shelfGroup.position.copy(shelfTargetPosition);
shelfGroup.rotation.y = 0;
tealMaterial.opacity = 1;
tealMaterial.depthWrite = true;
tealMaterial.needsUpdate = true;
shelfLabel.userData.setText("SHELF / FITTED");
fitCallout.visible = true;
fitLeader.visible = true;
ui.fitValue.textContent = `Fits · ${SHELF_CLEARANCE_MM} mm / side`;
ui.fitMetric.classList.add("success");
setStage(3);
}
);
}
// -------------------------------------------------------------------------
// Reset workflow
// -------------------------------------------------------------------------
function resetWorkflow() {
tweens.length = 0;
clearTimeout(instructionTimer);
currentTemplateWidth = TEMPLATE_BASE_WIDTH;
templateBoard.scale.x = currentTemplateWidth;
updateTemplateDimension(currentTemplateWidth);
colorDimension(templateDimension, 0xd9784c);
templateMeasureLabel.userData.setText("COPY WIDTH HERE");
tapeGroup.visible = false;
tapeGroup.scale.x = 0.015;
tapeGroup.position.y = 2.79;
tapeMeasureLabel.visible = false;
openingDimension.group.visible = false;
copyMarker.visible = false;
shelfGroup.position.copy(shelfStartPosition);
shelfGroup.rotation.set(0, -0.27, 0);
tealMaterial.opacity = 0.58;
tealMaterial.depthWrite = false;
tealMaterial.needsUpdate = true;
shelfLabel.userData.setText("PROPOSED SHELF");
fitCallout.visible = false;
fitLeader.visible = false;
ui.openingValue.textContent = "—";
ui.templateValue.textContent = "—";
ui.fitValue.textContent = "Not checked";
ui.fitMetric.classList.remove("success");
setStage(0);
}
ui.resetButton.addEventListener("click", resetWorkflow);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 760 ? 51 : 43;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
resetCamera();
renderer.setAnimationLoop((now) => {
for (let i = tweens.length - 1; i >= 0; i--) {
const tween = tweens[i];
const raw = THREE.MathUtils.clamp(
(now - tween.start) / tween.duration,
0,
1
);
tween.onUpdate(tween.easing(raw), raw);
if (raw >= 1) {
tweens.splice(i, 1);
if (tween.onComplete) tween.onComplete();
}
}
if (copyMarker.visible) {
const pulse = 1 + Math.sin(now * 0.012) * 0.12;
copyMarker.scale.setScalar(pulse);
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```