Prompt specification
Build or customize the Three.js 3D scene "Table activity boundary markers" 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: Table activity boundary markers
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/table-activity-boundary-markers-x0221
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing shared table space. Place removable dividers and colored mats on a plain table with art and puzzle objects; show separate work regions while the tabletop remains physically continuous. Stylized solid forms.
Working Three.js Starter (table-activity-boundary-markers-x0221):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shared Table Studio</title>
<style>
:root {
--ink: #252a2d;
--muted: #687174;
--paper: rgba(255, 255, 255, 0.86);
--line: rgba(37, 42, 45, 0.12);
--accent: #ed765d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ebe7de;
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;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.glass {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.78);
box-shadow:
0 16px 45px rgba(57, 50, 40, 0.12),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
header {
position: fixed;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #55a79c;
box-shadow: 0 0 0 4px rgba(85, 167, 156, 0.15);
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 38px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 790;
}
header p {
max-width: 330px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
width: min(330px, calc(100vw - 44px));
padding: 16px;
border-radius: 20px;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.control-label {
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.selection {
margin-top: 3px;
font-size: 13px;
font-weight: 720;
}
button {
appearance: none;
border: 0;
border-radius: 12px;
padding: 10px 12px;
background: #283034;
color: white;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
box-shadow 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #171c1f;
box-shadow: 0 7px 18px rgba(20, 25, 28, 0.16);
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 3px solid rgba(237, 118, 93, 0.36);
outline-offset: 2px;
}
.button-row {
display: flex;
gap: 8px;
}
.button-row button {
flex: 1;
}
.button-row .secondary {
background: rgba(40, 48, 52, 0.09);
color: var(--ink);
}
.button-row .secondary:hover {
background: rgba(40, 48, 52, 0.15);
}
.palette {
display: flex;
align-items: center;
gap: 9px;
margin: 15px 0 12px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.swatch {
position: relative;
width: 30px;
height: 30px;
padding: 0;
border: 3px solid rgba(255, 255, 255, 0.95);
border-radius: 50%;
background: var(--swatch);
box-shadow: 0 0 0 1px rgba(30, 35, 38, 0.14);
}
.swatch:hover {
transform: translateY(-2px) scale(1.06);
background: var(--swatch);
}
.swatch.active::after {
content: "";
position: absolute;
inset: -6px;
border: 2px solid var(--ink);
border-radius: 50%;
opacity: 0.65;
}
.hint {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.hint strong {
color: var(--ink);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #ebe7de;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
color: var(--muted);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.loader::before {
content: "";
width: 22px;
height: 22px;
border: 3px solid rgba(37, 42, 45, 0.14);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 720px) {
header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
header p {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
}
</style>
</</head>
<body>
<canvas id="scene" aria-label="Interactive 3D shared table scene"></canvas>
<header class="glass">
<div class="eyebrow">
<span class="live-dot"></span>
Shared workspace
</div>
<h1>One table.<br />Three ways to make.</h1>
<p>
Colored mats create distinct work zones while the tabletop remains one
continuous shared surface.
</p>
</header>
<aside class="controls glass">
<div class="control-row">
<div>
<div class="control-label">Selected zone</div>
<div class="selection" id="selectionText">MAKE · Shared build</div>
</div>
<button id="dividerButton" type="button">Park dividers</button>
</div>
<div class="palette" id="palette" aria-label="Mat color palette">
<button
class="swatch"
type="button"
style="--swatch:#e97b68"
data-color="#e97b68"
aria-label="Coral"
></button>
<button
class="swatch"
type="button"
style="--swatch:#e8ba55"
data-color="#e8ba55"
aria-label="Marigold"
></button>
<button
class="swatch"
type="button"
style="--swatch:#58aaa3"
data-color="#58aaa3"
aria-label="Teal"
></button>
<button
class="swatch"
type="button"
style="--swatch:#6d91c8"
data-color="#6d91c8"
aria-label="Blue"
></button>
<button
class="swatch"
type="button"
style="--swatch:#a48ac5"
data-color="#a48ac5"
aria-label="Lilac"
></button>
</div>
<div class="button-row">
<button class="secondary" id="resetButton" type="button">Reset layout</button>
<button class="secondary" id="viewButton" type="button">Reset view</button>
</div>
<p class="hint">
<strong>Drag</strong> to orbit · <strong>Scroll / pinch</strong> to zoom ·
Click a divider or mat to interact.
</p>
</aside>
<div id="loading">
<div class="loader">Preparing shared table</div>
</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 loading = document.querySelector("#loading");
const selectionText = document.querySelector("#selectionText");
const dividerButton = document.querySelector("#dividerButton");
const resetButton = document.querySelector("#resetButton");
const viewButton = document.querySelector("#viewButton");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#ebe7de");
scene.fog = new THREE.Fog("#ebe7de", 19, 36);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
100
);
const SURFACE = 2.05;
const WORK_Y = SURFACE + 0.07;
const palette = {
ink: new THREE.MeshStandardMaterial({
color: 0x293034,
roughness: 0.82
}),
frame: new THREE.MeshStandardMaterial({
color: 0xc89462,
roughness: 0.78
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf7f1e5,
roughness: 0.9
}),
paper: new THREE.MeshStandardMaterial({
color: 0xfffaf0,
roughness: 0.95
}),
wood: new THREE.MeshStandardMaterial({
color: 0xcfa36c,
roughness: 0.82
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0xa9784d,
roughness: 0.86
}),
coral: new THREE.MeshStandardMaterial({
color: 0xe97b68,
roughness: 0.77
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xe8ba55,
roughness: 0.77
}),
teal: new THREE.MeshStandardMaterial({
color: 0x58aaa3,
roughness: 0.77
}),
blue: new THREE.MeshStandardMaterial({
color: 0x6d91c8,
roughness: 0.77
}),
lilac: new THREE.MeshStandardMaterial({
color: 0xa48ac5,
roughness: 0.77
}),
mint: new THREE.MeshStandardMaterial({
color: 0x9dc69f,
roughness: 0.8
})
};
function addBox(
parent,
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0
) {
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);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
material,
x = 0,
y = 0,
z = 0,
segments = 24
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, start, end, radius, material) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const mesh = addCylinder(
parent,
radius,
radius,
direction.length(),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
return mesh;
}
function roundedRectShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(
x,
y + height,
x,
y + height - r
);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function roundedSlab(
width,
depth,
height,
radius,
material,
bottomY = 0
) {
const bevel = Math.min(0.035, height * 0.2);
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, depth, radius),
{
depth: Math.max(0.005, height - bevel * 2),
bevelEnabled: true,
bevelSegments: 2,
bevelSize: bevel * 0.8,
bevelThickness: bevel,
curveSegments: 8,
steps: 1
}
);
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = bottomY + bevel;
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeLabel(text, width, height, x, z, color = "#293034") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 160;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 640, 160);
context.fillStyle = "rgba(255,255,255,0.88)";
context.beginPath();
context.roundRect(8, 8, 624, 144, 34);
context.fill();
context.strokeStyle = "rgba(35,40,43,0.10)";
context.lineWidth = 4;
context.stroke();
context.fillStyle = color;
context.font = "800 48px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 320, 82);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, WORK_Y + 0.012, z);
mesh.renderOrder = 2;
scene.add(mesh);
return mesh;
}
// Lighting
scene.add(new THREE.HemisphereLight(0xfff8e9, 0x8d9698, 2.05));
const keyLight = new THREE.DirectionalLight(0xfff1d8, 3.35);
keyLight.position.set(5.5, 12, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9e5ef, 1.1);
fillLight.position.set(-8, 7, -7);
scene.add(fillLight);
// Ground and continuous table
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xe7e0d5,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.04;
ground.receiveShadow = true;
scene.add(ground);
const stage = new THREE.Mesh(
new THREE.CylinderGeometry(8.5, 8.7, 0.08, 96),
new THREE.MeshStandardMaterial({
color: 0xded6c9,
roughness: 1
})
);
stage.position.y = -0.01;
stage.receiveShadow = true;
scene.add(stage);
const table = new THREE.Group();
scene.add(table);
const tabletop = roundedSlab(
12,
7.2,
0.3,
0.28,
new THREE.MeshStandardMaterial({
color: 0xe8c997,
roughness: 0.83
}),
SURFACE - 0.3
);
table.add(tabletop);
const apron = addBox(
table,
10.9,
0.42,
6.15,
palette.woodDark,
0,
SURFACE - 0.48,
0
);
apron.castShadow = true;
const legPositions = [
[-5.1, -2.62],
[5.1, -2.62],
[-5.1, 2.62],
[5.1, 2.62]
];
for (const [x, z] of legPositions) {
addCylinder(
table,
0.23,
0.31,
1.65,
palette.wood,
x,
0.84,
z,
20
);
}
addBox(table, 9.7, 0.18, 0.22, palette.woodDark, 0, 0.62, -2.62);
addBox(table, 9.7, 0.18, 0.22, palette.woodDark, 0, 0.62, 2.62);
// Colored mats
const mats = [];
const clickTargets = [];
function addMat(name, subtitle, x, width, color) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.96,
emissive: 0x000000,
emissiveIntensity: 0
});
const mat = roundedSlab(
width,
4.5,
0.055,
0.22,
material,
SURFACE + 0.006
);
mat.userData.matRecord = {
name,
subtitle,
material,
originalColor: new THREE.Color(color)
};
mats.push(mat);
clickTargets.push(mat);
scene.add(mat);
makeLabel(`${name} · ${subtitle}`, 2.15, 0.54, x, 1.86);
return mat;
}
const artMat = addMat("ART", "Make & sketch", -3.65, 4.2, "#e97b68");
const buildMat = addMat("MAKE", "Shared build", 0, 3.0, "#e8ba55");
const puzzleMat = addMat("PUZZLE", "Fit & solve", 3.65, 4.2, "#58aaa3");
let selectedMat = buildMat;
function selectMat(mat) {
selectedMat = mat;
for (const item of mats) {
item.userData.matRecord.material.emissive.set(0x000000);
item.userData.matRecord.material.emissiveIntensity = 0;
}
selectedMat.userData.matRecord.material.emissive.set(0x332f28);
selectedMat.userData.matRecord.material.emissiveIntensity = 0.12;
const record = selectedMat.userData.matRecord;
selectionText.textContent = `${record.name} · ${record.subtitle}`;
const color = `#${record.material.color.getHexString()}`;
document.querySelectorAll(".swatch").forEach((button) => {
button.classList.toggle("active", button.dataset.color === color);
});
}
selectMat(buildMat);
// Art zone: framed artwork, easel, palette, brushes, and sketchbook
const artGroup = new THREE.Group();
artGroup.position.set(-3.65, WORK_Y, -1.38);
scene.add(artGroup);
const canvasFrame = addBox(
artGroup,
1.92,
1.38,
0.12,
palette.frame,
0,
0.82,
0
);
canvasFrame.castShadow = true;
const canvasSurface = new THREE.Mesh(
new THREE.PlaneGeometry(1.68, 1.14),
palette.paper
);
canvasSurface.position.set(0, 0.82, 0.067);
canvasSurface.receiveShadow = true;
artGroup.add(canvasSurface);
const sun = new THREE.Mesh(
new THREE.CircleGeometry(0.2, 32),
palette.yellow
);
sun.position.set(0.48, 1.08, 0.075);
artGroup.add(sun);
const mountainShape = new THREE.Shape();
mountainShape.moveTo(-0.8, 0.28);
mountainShape.lineTo(-0.28, 1.0);
mountainShape.lineTo(0.13, 0.52);
mountainShape.lineTo(0.44, 0.82);
mountainShape.lineTo(0.8, 0.28);
mountainShape.closePath();
const mountain = new THREE.Mesh(
new THREE.ShapeGeometry(mountainShape),
palette.blue
);
mountain.position.z = 0.077;
artGroup.add(mountain);
const foreground = new THREE.Mesh(
new THREE.PlaneGeometry(1.66, 0.38),
palette.teal
);
foreground.position.set(0, 0.46, 0.08);
artGroup.add(foreground);
addBox(artGroup, 0.12, 1.42, 0.16, palette.frame, -0.91, 0.82, 0.04);
addBox(artGroup, 0.12, 1.42, 0.16, palette.frame, 0.91, 0.82, 0.04);
addBox(artGroup, 1.92, 0.12, 0.16, palette.frame, 0, 0.16, 0.04);
addBox(artGroup, 1.92, 0.12, 0.16, palette.frame, 0, 1.48, 0.04);
cylinderBetween(
artGroup,
[-0.67, 0, 0.08],
[-0.4, 1.55, -0.02],
0.045,
palette.woodDark
);
cylinderBetween(
artGroup,
[0.67, 0, 0.08],
[0.4, 1.55, -0.02],
0.045,
palette.woodDark
);
const paletteGroup = new THREE.Group();
paletteGroup.position.set(-4.85, WORK_Y + 0.055, 0.62);
paletteGroup.rotation.y = -0.25;
scene.add(paletteGroup);
const artistPalette = addCylinder(
paletteGroup,
0.48,
0.48,
0.09,
palette.frame,
0,
0,
0,
48
);
artistPalette.scale.set(1.18, 1, 0.82);
const paintDots = [
[-0.25, 0.11, palette.coral],
[0.04, 0.22, palette.blue],
[0.27, 0.06, palette.yellow],
[0.04, -0.13, palette.teal],
[-0.23, -0.13, palette.lilac]
];
for (const [x, z, material] of paintDots) {
addCylinder(
paletteGroup,
0.075,
0.075,
0.025,
material,
x,
0.059,
z,
20
);
}
const brushColors = [palette.coral, palette.blue, palette.teal];
brushColors.forEach((material, index) => {
const z = 1.16 + index * 0.16;
cylinderBetween(
scene,
[-4.55, WORK_Y + 0.075, z],
[-3.36, WORK_Y + 0.075, z + 0.05],
0.025,
material
);
});
const sketchbook = new THREE.Group();
sketchbook.position.set(-2.55, WORK_Y + 0.045, 0.92);
sketchbook.rotation.y = -0.16;
scene.add(sketchbook);
addBox(sketchbook, 0.92, 0.09, 1.18, palette.ink);
addBox(sketchbook, 0.84, 0.025, 1.08, palette.paper, 0, 0.057, 0);
addBox(sketchbook, 0.055, 0.032, 1.08, palette.coral, -0.36, 0.08, 0);
// Shared build zone
const buildGroup = new THREE.Group();
scene.add(buildGroup);
roundedSlab(
2.12,
1.42,
0.075,
0.16,
new THREE.MeshStandardMaterial({
color: 0xf4e4c3,
roughness: 0.9
}),
WORK_Y
).position.x = 0;
const buildBlocks = [
[-0.62, 0.27, -0.25, 0.5, 0.5, 0.5, palette.coral],
[-0.62, 0.77, -0.25, 0.5, 0.5, 0.5, palette.blue],
[-0.08, 0.24, -0.12, 0.46, 0.46, 0.46, palette.teal],
[0.42, 0.23, -0.24, 0.5, 0.46, 0.5, palette.lilac]
];
for (const [x, y, z, w, h, d, material] of buildBlocks) {
addBox(buildGroup, w, h, d, material, x, WORK_Y + y, z);
}
addCylinder(
buildGroup,
0.24,
0.24,
0.46,
palette.yellow,
0.44,
WORK_Y + 0.58,
-0.22,
28
);
const buildSphere = new THREE.Mesh(
new THREE.SphereGeometry(0.29, 32, 20),
palette.mint
);
buildSphere.position.set(-0.18, WORK_Y + 0.45, 0.47);
buildSphere.castShadow = true;
buildGroup.add(buildSphere);
// Puzzle zone
const puzzleGroup = new THREE.Group();
puzzleGroup.position.set(3.65, 0, -0.12);
scene.add(puzzleGroup);
addBox(
puzzleGroup,
3.42,
0.1,
2.94,
palette.ink,
0,
WORK_Y + 0.05,
0
);
addBox(
puzzleGroup,
3.08,
0.055,
2.6,
new THREE.MeshStandardMaterial({
color: 0x536e78,
roughness: 0.88
}),
0,
WORK_Y + 0.126,
0
);
const puzzleMaterials = [
palette.coral,
palette.yellow,
palette.blue,
palette.lilac,
palette.mint,
palette.teal,
palette.coral,
palette.yellow,
palette.blue
];
function makePuzzlePiece(material) {
const a = 0.31;
const shape = new THREE.Shape();
shape.moveTo(-a, -a);
shape.lineTo(-a, -0.12);
shape.bezierCurveTo(
-0.49,
-0.12,
-0.49,
0.12,
-a,
0.12
);
shape.lineTo(-a, a);
shape.lineTo(0.1, a);
shape.bezierCurveTo(
0.1,
0.47,
-0.14,
0.47,
-0.14,
a
);
shape.lineTo(a, a);
shape.lineTo(a, 0.1);
shape.bezierCurveTo(
0.47,
0.1,
0.47,
-0.14,
a,
-0.14
);
shape.lineTo(a, -a);
shape.lineTo(0.1, -a);
shape.bezierCurveTo(
0.1,
-0.46,
-0.14,
-0.46,
-0.14,
-a
);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.115,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.018,
bevelThickness: 0.018,
curveSegments: 10
});
geometry.rotateX(-Math.PI / 2);
const piece = new THREE.Mesh(geometry, material);
piece.castShadow = true;
piece.receiveShadow = true;
return piece;
}
const piecePositions = [
[-0.92, -0.91],
[0, -0.91],
[0.92, -0.91],
[-0.92, 0],
[0, 0],
[0.92, 0],
[-0.92, 0.91],
[0, 0.91],
[0.92, 0.91]
];
const omittedPieces = new Set([4, 7]);
piecePositions.forEach(([x, z], index) => {
if (omittedPieces.has(index)) return;
const piece = makePuzzlePiece(puzzleMaterials[index]);
piece.position.set(x, WORK_Y + 0.155, z);
piece.rotation.z = (index % 3 - 1) * 0.018;
puzzleGroup.add(piece);
});
const loosePiece = makePuzzlePiece(palette.coral);
loosePiece.position.set(-1.03, WORK_Y + 0.13, 1.7);
loosePiece.rotation.set(-Math.PI / 2, 0, 0.32);
puzzleGroup.add(loosePiece);
// Removable dividers
const dividers = [];
const installedQuaternion = new THREE.Quaternion();
const parkedQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(Math.PI / 2, Math.PI / 2, 0, "XYZ")
);
function createDivider(x, parkedBackZ, accentMaterial) {
const group = new THREE.Group();
group.position.set(x, SURFACE + 0.015, 0);
scene.add(group);
const divider = {
group,
x,
parkedBackZ,
removed: false,
targetPosition: group.position.clone(),
targetQuaternion: installedQuaternion.clone()
};
const children = [];
children.push(
addBox(
group,
0.11,
0.78,
3.45,
new THREE.MeshStandardMaterial({
color: 0xf5f0e6,
roughness: 0.86
}),
0,
0.48,
0
)
);
children.push(
addBox(
group,
0.125,
0.075,
3.38,
accentMaterial,
0,
0.82,
0
)
);
children.push(
addBox(group, 0.46, 0.08, 0.34, palette.ink, 0, 0.04, -1.32)
);
children.push(
addBox(group, 0.46, 0.08, 0.34, palette.ink, 0, 0.04, 1.32)
);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.032, 10, 28),
palette.ink
);
handle.position.set(0, 0.88, -0.15);
handle.rotation.y = Math.PI / 2;
handle.castShadow = true;
group.add(handle);
children.push(handle);
const badge = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 18, 12),
accentMaterial
);
badge.position.set(0, 0.55, 1.42);
badge.castShadow = true;
group.add(badge);
children.push(badge);
for (const child of children) {
child.userData.divider = divider;
clickTargets.push(child);
}
dividers.push(divider);
return divider;
}
createDivider(-1.62, 2.34, palette.coral);
createDivider(1.62, 2.67, palette.teal);
function setDividerRemoved(divider, removed) {
divider.removed = removed;
if (removed) {
divider.targetPosition.set(
divider.x,
SURFACE + 0.1,
divider.parkedBackZ
);
divider.targetQuaternion.copy(parkedQuaternion);
} else {
divider.targetPosition.set(divider.x, SURFACE + 0.015, 0);
divider.targetQuaternion.copy(installedQuaternion);
}
updateDividerButton();
}
function toggleDivider(divider) {
setDividerRemoved(divider, !divider.removed);
}
function updateDividerButton() {
const anyInstalled = dividers.some((divider) => !divider.removed);
dividerButton.textContent = anyInstalled
? "Park dividers"
: "Return dividers";
}
dividerButton.addEventListener("click", () => {
const anyInstalled = dividers.some((divider) => !divider.removed);
for (const divider of dividers) {
setDividerRemoved(divider, anyInstalled);
}
});
// Palette buttons recolor the selected mat.
const swatchButtons = [
...document.querySelectorAll(".swatch")
];
swatchButtons.forEach((button) => {
button.addEventListener("click", () => {
selectedMat.userData.matRecord.material.color.set(button.dataset.color);
selectedMat.userData.matRecord.material.emissive.set(0x332f28);
selectedMat.userData.matRecord.material.emissiveIntensity = 0.12;
swatchButtons.forEach((item) =>
item.classList.toggle(
"active",
item.dataset.color === button.dataset.color
)
);
});
});
resetButton.addEventListener("click", () => {
for (const divider of dividers) {
setDividerRemoved(divider, false);
}
for (const mat of mats) {
const record = mat.userData.matRecord;
record.material.color.copy(record.originalColor);
}
selectMat(buildMat);
resetCamera();
});
// Direct camera controls: orbit, wheel zoom, and pinch zoom.
const target = new THREE.Vector3(0, 1.65, 0);
let theta = 0.72;
let polar = 0.94;
let radius = 15.6;
function resetCamera() {
theta = 0.72;
polar = 0.94;
radius = window.innerWidth < 700 ? 18.2 : 15.6;
updateCamera();
}
function updateCamera() {
camera.position.set(
target.x + radius * Math.sin(polar) * Math.sin(theta),
target.y + radius * Math.cos(polar),
target.z + radius * Math.sin(polar) * Math.cos(theta)
);
camera.lookAt(target);
}
resetCamera();
const pointers = new Map();
let dragStart = null;
let lastPinchDistance = 0;
let dragged = false;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragStart = {
x: event.clientX,
y: event.clientY,
theta,
polar
};
dragged = false;
} else if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
radius = THREE.MathUtils.clamp(
radius * (lastPinchDistance / distance),
10,
24
);
updateCamera();
}
lastPinchDistance = distance;
dragged = true;
return;
}
if (!dragStart) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
if (
Math.abs(event.clientX - dragStart.x) +
Math.abs(event.clientY - dragStart.y) >
4
) {
dragged = true;
}
theta = dragStart.theta - dx * 0.005;
polar = THREE.MathUtils.clamp(
dragStart.polar - dy * 0.005,
0.42,
1.28
);
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
lastPinchDistance = 0;
}
if (pointers.size === 0) {
dragStart = null;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
10,
24
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
viewButton.addEventListener("click", resetCamera);
// Click interaction using raycasting.
const raycaster = new THREE.Raycaster();
const normalizedPointer = new THREE.Vector2();
canvas.addEventListener("pointerup", (event) => {
if (dragged) return;
normalizedPointer.set(
(event.clientX / window.innerWidth) * 2 - 1,
-(event.clientY / window.innerHeight) * 2 + 1
);
raycaster.setFromCamera(normalizedPointer, camera);
const intersections = raycaster.intersectObjects(
clickTargets,
false
);
if (!intersections.length) return;
const hit = intersections[0].object;
if (hit.userData.divider) {
toggleDivider(hit.userData.divider);
} else if (hit.userData.matRecord) {
selectMat(hit);
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.fov = width < 700 ? 46 : 35;
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// Animation
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const positionAlpha = 1 - Math.exp(-delta * 8);
const rotationAlpha = 1 - Math.exp(-delta * 8);
for (const divider of dividers) {
divider.group.position.lerp(
divider.targetPosition,
positionAlpha
);
divider.group.quaternion.slerp(
divider.targetQuaternion,
rotationAlpha
);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 550);
});
</script>
</body>
</html>
```