Prompt specification
Build or customize the Three.js 3D scene "Craft corner tool grouping" 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: Craft corner tool grouping
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/craft-corner-tool-grouping-x0211
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring pegboard storage. Compose a small craft station with board, scissors, brushes, tape, and shallow bins; arrange tools by activity and keep each outline visible after hanging. Voxel style.
Working Three.js Starter (craft-corner-tool-grouping-x0211):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Craft Station</title>
<style>
:root {
--ink: #41382f;
--paper: #f7f0e4;
--cut: #e77755;
--paint: #4c9c8b;
--fix: #e5ad42;
--draw: #d9657b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ece5d9;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
z-index: 10;
pointer-events: none;
user-select: none;
}
.title-card {
top: 24px;
left: 24px;
max-width: min(430px, calc(100vw - 48px));
padding: 17px 20px 16px;
border: 2px solid rgba(65, 56, 47, 0.78);
background: rgba(247, 240, 228, 0.91);
box-shadow: 5px 5px 0 rgba(65, 56, 47, 0.12);
backdrop-filter: blur(6px);
}
.eyebrow {
margin-bottom: 5px;
color: #776b60;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 4vw, 38px);
line-height: 0.95;
letter-spacing: -0.08em;
text-transform: uppercase;
}
.subtitle {
margin-top: 10px;
color: #665b50;
font-size: 11px;
line-height: 1.5;
}
.legend {
bottom: 24px;
left: 24px;
display: flex;
flex-wrap: wrap;
gap: 7px;
max-width: calc(100vw - 48px);
}
.chip {
display: flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
border: 1px solid rgba(65, 56, 47, 0.35);
background: rgba(247, 240, 228, 0.88);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
box-shadow: 2px 2px 0 rgba(65, 56, 47, 0.09);
}
.swatch {
width: 9px;
height: 9px;
box-shadow: 1px 1px 0 rgba(65, 56, 47, 0.22);
}
.swatch.cut { background: var(--cut); }
.swatch.paint { background: var(--paint); }
.swatch.fix { background: var(--fix); }
.swatch.draw { background: var(--draw); }
.controls {
right: 24px;
bottom: 24px;
padding: 10px 12px;
border: 1px solid rgba(65, 56, 47, 0.32);
background: rgba(247, 240, 228, 0.88);
color: #665b50;
font-size: 10px;
line-height: 1.6;
text-align: right;
box-shadow: 3px 3px 0 rgba(65, 56, 47, 0.09);
}
.controls strong {
color: var(--ink);
}
#reset {
position: fixed;
right: 24px;
top: 24px;
z-index: 20;
padding: 9px 11px;
border: 2px solid var(--ink);
background: var(--paper);
color: var(--ink);
font: 800 10px ui-monospace, monospace;
letter-spacing: 0.08em;
cursor: pointer;
box-shadow: 3px 3px 0 rgba(65, 56, 47, 0.2);
}
#reset:hover {
background: #fffaf1;
transform: translate(-1px, -1px);
box-shadow: 4px 4px 0 rgba(65, 56, 47, 0.2);
}
#reset:active {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 rgba(65, 56, 47, 0.2);
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
padding: 13px 15px;
}
.subtitle {
display: none;
}
.legend {
bottom: 14px;
left: 14px;
max-width: calc(100vw - 28px);
}
.chip {
padding: 6px 7px;
font-size: 8px;
}
.controls {
display: none;
}
#reset {
top: 14px;
right: 14px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="ui title-card">
<div class="eyebrow">Voxel workshop / 01</div>
<h1>Pegboard</h1>
<div class="subtitle">
A task-sorted craft station. Tools stay separated by activity,
with dark voxel edges preserving each hanging silhouette.
</div>
</header>
<div class="ui legend" aria-label="Activity zones">
<div class="chip"><span class="swatch cut"></span>CUT</div>
<div class="chip"><span class="swatch paint"></span>PAINT</div>
<div class="chip"><span class="swatch fix"></span>TAPE / FIX</div>
<div class="chip"><span class="swatch draw"></span>DRAW</div>
</div>
<div class="ui controls">
<strong>DRAG</strong> orbit · <strong>SHIFT + DRAG</strong> pan<br>
<strong>SCROLL</strong> zoom · <strong>R / DOUBLE-CLICK</strong> reset
</div>
<button id="reset" type="button">RESET VIEW</button>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("scene");
const resetButton = document.getElementById("reset");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xece5d9);
scene.fog = new THREE.Fog(0xece5d9, 20, 34);
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel pegboard craft station"
);
host.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const hemi = new THREE.HemisphereLight(0xfff4dc, 0x776b61, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedce, 3.2);
sun.position.set(-7, 12, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7dded, 1.25);
fill.position.set(9, 6, -5);
scene.add(fill);
const materialCache = new Map();
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x3f352d,
transparent: true,
opacity: 0.58,
toneMapped: false
});
function getMaterial(color, metalness = 0) {
const key = `${color}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: metalness > 0 ? 0.46 : 0.84,
metalness,
flatShading: true
})
);
}
return materialCache.get(key);
}
function block(
parent,
size,
position,
color,
outlined = false,
metalness = 0,
castShadow = true
) {
const geometry = new THREE.BoxGeometry(...size);
const mesh = new THREE.Mesh(
geometry,
getMaterial(color, metalness)
);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
if (outlined) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
edgeMaterial
);
mesh.add(edges);
}
parent.add(mesh);
return mesh;
}
function squareRing(
parent,
outer,
inner,
thickness,
depth,
position,
color,
outlined = true,
metalness = 0
) {
const group = new THREE.Group();
group.position.set(...position);
const horizontalY = (outer - thickness) / 2;
const verticalHeight = outer - thickness * 2;
block(
group,
[outer, thickness, depth],
[0, horizontalY, 0],
color,
outlined,
metalness
);
block(
group,
[outer, thickness, depth],
[0, -horizontalY, 0],
color,
outlined,
metalness
);
block(
group,
[thickness, verticalHeight, depth],
[(outer - thickness) / 2, 0, 0],
color,
outlined,
metalness
);
block(
group,
[thickness, verticalHeight, depth],
[-(outer - thickness) / 2, 0, 0],
color,
outlined,
metalness
);
parent.add(group);
return group;
}
function makePlaque(
text,
accent,
width,
height,
position,
parent = scene
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = Math.max(96, Math.round(512 * height / width));
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f8f0e4";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "#51443a";
ctx.lineWidth = 8;
ctx.strokeRect(4, 4, canvas.width - 8, canvas.height - 8);
ctx.fillStyle = accent;
ctx.fillRect(13, 13, 28, canvas.height - 26);
ctx.fillStyle = "#3f352e";
ctx.font = `800 ${Math.floor(canvas.height * 0.43)}px monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2 + 13, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
mesh.position.set(...position);
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Floor and workbench
// ------------------------------------------------------------
block(
scene,
[32, 0.34, 32],
[0, -1.12, 0],
0xddd3c3,
false,
0,
false
);
const wood = 0xb88757;
const darkWood = 0x8f603c;
const paleWood = 0xd2a66d;
block(
scene,
[10.8, 0.35, 3.3],
[0, 0.86, 1.25],
paleWood,
true
);
block(
scene,
[10.45, 0.54, 0.22],
[0, 0.52, 2.78],
wood,
true
);
block(
scene,
[6.65, 0.68, 2.12],
[0, 0.33, 1.28],
darkWood,
true
);
block(
scene,
[2.25, 0.12, 0.12],
[0, 0.35, 2.38],
0xe5c18a,
true,
0.15
);
const legPositions = [
[-4.75, 0.65],
[-4.75, 2.2],
[4.75, 0.65],
[4.75, 2.2]
];
for (const [x, z] of legPositions) {
block(
scene,
[0.42, 1.72, 0.42],
[x, -0.08, z],
darkWood,
true
);
}
// ------------------------------------------------------------
// Pegboard
// ------------------------------------------------------------
block(
scene,
[10.7, 6.8, 0.34],
[0, 4.35, 0],
wood,
true
);
block(
scene,
[10.04, 6.15, 0.12],
[0, 4.35, 0.22],
0xd7b27d,
false
);
// Frame rails.
block(scene, [10.7, 0.28, 0.46], [0, 7.75, 0.17], paleWood, true);
block(scene, [10.7, 0.28, 0.46], [0, 0.95, 0.17], paleWood, true);
block(scene, [0.28, 6.52, 0.46], [-5.21, 4.35, 0.17], paleWood, true);
block(scene, [0.28, 6.52, 0.46], [5.21, 4.35, 0.17], paleWood, true);
// Square perforations, kept as instanced voxel details.
const columns = 21;
const rows = 13;
const holeGeometry = new THREE.BoxGeometry(0.065, 0.065, 0.025);
const holeMaterial = new THREE.MeshStandardMaterial({
color: 0x896747,
roughness: 1
});
const holes = new THREE.InstancedMesh(
holeGeometry,
holeMaterial,
columns * rows
);
const dummy = new THREE.Object3D();
let holeIndex = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
dummy.position.set(
-4.6 + column * 0.46,
1.53 + row * 0.46,
0.307
);
dummy.updateMatrix();
holes.setMatrixAt(holeIndex++, dummy.matrix);
}
}
holes.instanceMatrix.needsUpdate = true;
holes.receiveShadow = true;
scene.add(holes);
// Fine separators reinforce the activity-based organization.
block(scene, [0.035, 4.45, 0.025], [-2.43, 4.68, 0.305], 0xb48b62);
block(scene, [0.035, 4.45, 0.025], [0.58, 4.68, 0.305], 0xb48b62);
block(scene, [0.035, 4.45, 0.025], [3.02, 4.68, 0.305], 0xb48b62);
makePlaque("CUT", "#e77755", 1.45, 0.38, [-3.62, 7.16, 0.31]);
makePlaque("PAINT", "#4c9c8b", 1.65, 0.38, [-0.85, 7.16, 0.31]);
makePlaque("TAPE / FIX", "#e5ad42", 2.15, 0.38, [1.82, 7.16, 0.31]);
makePlaque("DRAW", "#d9657b", 1.55, 0.38, [4.05, 7.16, 0.31]);
function pegHook(x, y) {
block(
scene,
[0.085, 0.34, 0.13],
[x, y - 0.09, 0.39],
0x50463d,
true
);
block(
scene,
[0.27, 0.085, 0.18],
[x, y - 0.25, 0.48],
0xaaa49b,
true,
0.65
);
}
// ------------------------------------------------------------
// CUT: voxel scissors
// ------------------------------------------------------------
const scissors = new THREE.Group();
scissors.position.set(-3.62, 5.14, 0.57);
scissors.rotation.z = -0.045;
scene.add(scissors);
const steel = 0xc4ced1;
const leftBlade = block(
scissors,
[0.17, 1.38, 0.13],
[-0.12, 0.61, 0.03],
steel,
true,
0.48
);
leftBlade.rotation.z = 0.145;
const rightBlade = block(
scissors,
[0.17, 1.38, 0.13],
[0.12, 0.61, 0.03],
steel,
true,
0.48
);
rightBlade.rotation.z = -0.145;
block(
scissors,
[0.24, 0.24, 0.18],
[0, 0.03, 0.12],
0xf2b84b,
true,
0.25
);
const handlePositions = [-0.43, 0.43];
const handleColors = [0xe77755, 0xd85f49];
handlePositions.forEach((x, index) => {
const connector = block(
scissors,
[0.14, 0.52, 0.12],
[x * 0.53, -0.25, 0.04],
handleColors[index],
true
);
connector.rotation.z = x < 0 ? -0.18 : 0.18;
const ring = new THREE.Group();
ring.position.set(x, -0.63, 0.05);
scissors.add(ring);
const outer = 0.68;
const thickness = 0.13;
block(ring, [outer, thickness, 0.14], [0, 0.275, 0], handleColors[index], true);
block(ring, [outer, thickness, 0.14], [0, -0.275, 0], handleColors[index], true);
block(ring, [thickness, 0.42, 0.14], [0.275, 0, 0], handleColors[index], true);
block(ring, [thickness, 0.42, 0.14], [-0.275, 0, 0], handleColors[index], true);
});
pegHook(-3.62, 6.58);
// ------------------------------------------------------------
// PAINT: three brushes
// ------------------------------------------------------------
function makeBrush(x, handleColor, bristleColor, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 5.65, 0.59);
group.scale.setScalar(scale);
scene.add(group);
block(
group,
[0.22, 0.96, 0.18],
[0, 0.25, 0],
handleColor,
true
);
block(
group,
[0.38, 0.25, 0.23],
[0, -0.33, 0.01],
0xbfc3bd,
true,
0.55
);
block(
group,
[0.49, 0.46, 0.25],
[0, -0.69, 0.02],
bristleColor,
true
);
block(
group,
[0.51, 0.12, 0.27],
[0, -0.9, 0.03],
0x927151,
true
);
pegHook(x, 6.53);
}
makeBrush(-1.55, 0xe77755, 0x9f6542, 1.02);
makeBrush(-0.78, 0x4c9c8b, 0xd4a34f, 0.92);
makeBrush(0.02, 0xd7b34e, 0x76533e, 1.08);
// ------------------------------------------------------------
// TAPE / FIX: tape roll and utility knife
// ------------------------------------------------------------
const tapeGroup = new THREE.Group();
tapeGroup.position.set(1.18, 5.53, 0.61);
scene.add(tapeGroup);
squareRing(
tapeGroup,
1.06,
0.50,
0.20,
0.25,
[0, 0, 0],
0xe7a73d,
true
);
const tapeTail = block(
tapeGroup,
[0.20, 0.65, 0.12],
[0.52, -0.39, 0.01],
0xf0b650,
true
);
tapeTail.rotation.z = -0.18;
pegHook(1.18, 6.20);
const knife = new THREE.Group();
knife.position.set(2.35, 5.35, 0.59);
scene.add(knife);
block(
knife,
[0.43, 1.10, 0.24],
[0, -0.13, 0],
0x557d9d,
true
);
block(
knife,
[0.48, 0.22, 0.29],
[0, 0.16, 0.02],
0xe8ad3e,
true
);
const knifeBlade = block(
knife,
[0.19, 0.66, 0.13],
[0, 0.75, -0.01],
steel,
true,
0.65
);
knifeBlade.rotation.z = 0.035;
pegHook(2.35, 6.42);
// ------------------------------------------------------------
// DRAW: ruler and pencil
// ------------------------------------------------------------
const ruler = new THREE.Group();
ruler.position.set(3.48, 5.33, 0.58);
scene.add(ruler);
block(
ruler,
[0.39, 2.62, 0.17],
[0, 0, 0],
0xf0d39c,
true
);
for (let i = 0; i < 11; i++) {
const longTick = i % 2 === 0;
block(
ruler,
[longTick ? 0.23 : 0.14, 0.027, 0.025],
[0.055, 1.05 - i * 0.21, 0.10],
0x55483c,
false,
0,
false
);
}
pegHook(3.48, 6.76);
const pencil = new THREE.Group();
pencil.position.set(4.42, 5.35, 0.59);
scene.add(pencil);
block(
pencil,
[0.25, 2.12, 0.18],
[0, 0, 0],
0xe7bd47,
true
);
block(
pencil,
[0.27, 0.28, 0.20],
[0, 1.12, 0.01],
0xd9657b,
true
);
block(
pencil,
[0.27, 0.22, 0.20],
[0, 0.93, 0.01],
0xb5a79b,
true
);
const pencilTip = block(
pencil,
[0.18, 0.28, 0.15],
[0, -1.14, 0],
0xd7b78a,
true
);
pencilTip.rotation.z = 0.02;
block(
pencil,
[0.13, 0.13, 0.13],
[0, -1.31, 0],
0x403a34,
true
);
pegHook(4.42, 6.70);
// ------------------------------------------------------------
// Shallow task bins
// ------------------------------------------------------------
function makeBin(x, color, label, variant) {
const group = new THREE.Group();
group.position.set(x, 1.78, 0.47);
scene.add(group);
const width = 1.56;
const height = 0.86;
const depth = 0.78;
block(group, [width, height, 0.08], [0, 0, 0.02], color, true);
block(group, [width, height, 0.08], [0, 0, depth], color, true);
block(group, [0.08, height, depth], [-width / 2, 0, depth / 2], color, true);
block(group, [0.08, height, depth], [width / 2, 0, depth / 2], color, true);
block(group, [width, 0.08, depth], [0, -height / 2, depth / 2], color, true);
block(
group,
[width + 0.08, 0.09, 0.14],
[0, height / 2, depth],
color,
true
);
makePlaque(
label,
color,
1.06,
0.24,
[0, -0.02, depth + 0.047],
group
);
if (variant === 0) {
// Paper clips.
for (let i = 0; i < 3; i++) {
const clip = new THREE.Group();
clip.position.set(-0.37 + i * 0.37, 0.34 + i * 0.055, 0.35);
clip.rotation.z = -0.18 + i * 0.16;
group.add(clip);
block(clip, [0.34, 0.055, 0.08], [0, 0.12, 0], 0x69655f, true);
block(clip, [0.34, 0.055, 0.08], [0, -0.12, 0], 0x69655f, true);
block(clip, [0.055, 0.23, 0.08], [-0.14, 0, 0], 0x69655f, true);
block(clip, [0.055, 0.23, 0.08], [0.14, 0, 0], 0x69655f, true);
}
} else if (variant === 1) {
// Push pins.
for (let i = 0; i < 6; i++) {
const pinX = -0.5 + (i % 3) * 0.45;
const pinY = 0.33 + Math.floor(i / 3) * 0.24;
block(group, [0.055, 0.50, 0.055], [pinX, pinY, 0.35], 0xa99c87, true);
block(
group,
[0.22, 0.19, 0.18],
[pinX, pinY + 0.28, 0.37],
[0xe77755, 0x4c9c8b, 0xd9657b][i % 3],
true
);
}
} else if (variant === 2) {
// Small tape rolls.
squareRing(group, 0.38, 0.18, 0.075, 0.14, [-0.34, 0.38, 0.36], 0xe7a73d);
squareRing(group, 0.32, 0.15, 0.065, 0.13, [0.28, 0.43, 0.39], 0x65a8a0);
squareRing(group, 0.27, 0.12, 0.055, 0.12, [0.05, 0.62, 0.33], 0xd9657b);
} else if (variant === 3) {
// Paper pads.
block(group, [0.63, 0.12, 0.46], [-0.28, 0.36, 0.35], 0xf1e4c7, true);
block(group, [0.59, 0.10, 0.42], [-0.28, 0.49, 0.34], 0xe9b9b6, true);
block(group, [0.51, 0.09, 0.39], [0.39, 0.37, 0.37], 0xa8c9b4, true);
} else {
// Beads and buttons.
const beadColors = [
0xe77755,
0x4c9c8b,
0xe5ad42,
0xd9657b,
0x6589b0,
0xf0e5cc
];
for (let i = 0; i < 9; i++) {
const beadX = -0.48 + (i % 3) * 0.47;
const beadY = 0.34 + Math.floor(i / 3) * 0.23;
block(
group,
[0.18, 0.18, 0.18],
[beadX, beadY, 0.36 + (i % 2) * 0.12],
beadColors[i % beadColors.length],
true
);
}
}
return group;
}
makeBin(-4.05, 0x5b8fa0, "CLIPS", 0);
makeBin(-2.02, 0xd66b59, "PINS", 1);
makeBin(0.02, 0xd6a33e, "TAPE", 2);
makeBin(2.06, 0x65987d, "PADS", 3);
makeBin(4.08, 0x8b7195, "BEADS", 4);
// ------------------------------------------------------------
// Desktop work-in-progress
// ------------------------------------------------------------
block(
scene,
[3.25, 0.035, 1.76],
[-0.65, 1.066, 1.62],
0xf4ead3,
true
);
// Color swatches on the paper.
block(scene, [0.65, 0.035, 0.36], [-1.35, 1.10, 1.46], 0xe77755, true);
block(scene, [0.48, 0.035, 0.32], [-0.59, 1.10, 1.50], 0x4c9c8b, true);
block(scene, [0.72, 0.035, 0.28], [0.18, 1.10, 1.44], 0xe5ad42, true);
// Pencil lying diagonally across the work.
const deskPencil = new THREE.Group();
deskPencil.position.set(0.58, 1.15, 2.02);
deskPencil.rotation.y = -0.38;
scene.add(deskPencil);
block(deskPencil, [0.14, 0.14, 1.82], [0, 0, 0], 0xe7bd47, true);
block(deskPencil, [0.16, 0.16, 0.24], [0, 0, 0.94], 0xd9657b, true);
block(deskPencil, [0.12, 0.12, 0.24], [0, 0, -1.02], 0xd7b78a, true);
// Brush cup.
const cup = new THREE.Group();
cup.position.set(-4.12, 1.06, 1.64);
scene.add(cup);
block(cup, [0.86, 0.08, 0.86], [0, 0, 0], 0x6c9ba4, true);
block(cup, [0.86, 0.62, 0.08], [0, 0.31, -0.39], 0x6c9ba4, true);
block(cup, [0.86, 0.62, 0.08], [0, 0.31, 0.39], 0x6c9ba4, true);
block(cup, [0.08, 0.62, 0.78], [-0.39, 0.31, 0], 0x6c9ba4, true);
block(cup, [0.08, 0.62, 0.78], [0.39, 0.31, 0], 0x6c9ba4, true);
const cupBrushes = [
[-0.19, 0.0, 0xe77755, 0x9f6542],
[0.08, 0.08, 0xe5ad42, 0xd6a866],
[0.23, -0.12, 0x4c9c8b, 0x76533e]
];
cupBrushes.forEach(([x, z, handle, bristles], index) => {
const brush = new THREE.Group();
brush.position.set(x, 0.35, z);
brush.rotation.z = [-0.12, 0.09, 0.16][index];
cup.add(brush);
block(brush, [0.12, 1.22, 0.12], [0, 0, 0], handle, true);
block(brush, [0.21, 0.18, 0.20], [0, -0.68, 0], 0xc7c8bf, true, 0.45);
block(brush, [0.27, 0.30, 0.22], [0, -0.91, 0], bristles, true);
});
// A spare tape roll on the tabletop.
const deskTape = squareRing(
scene,
0.86,
0.40,
0.17,
0.20,
[3.82, 1.14, 1.62],
0xe7a73d,
true
);
deskTape.rotation.x = -Math.PI / 2;
// Small paper stack.
block(scene, [1.25, 0.10, 0.88], [3.44, 1.10, 2.36], 0xeee1c5, true);
block(scene, [1.18, 0.08, 0.82], [3.46, 1.18, 2.35], 0xf8eed8, true);
// ------------------------------------------------------------
// Custom camera controls
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 3.38, 0.55);
const initial = {
yaw: 0.48,
pitch: 0.34,
radius: 16,
zoom: 1,
target: target.clone()
};
let yaw = initial.yaw;
let pitch = initial.pitch;
let radius = initial.radius;
let zoom = initial.zoom;
const cameraRight = new THREE.Vector3();
const cameraUp = new THREE.Vector3();
function updateCamera() {
const horizontal = radius * Math.cos(pitch);
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
cameraRight.setFromMatrixColumn(camera.matrixWorld, 0);
cameraUp.setFromMatrixColumn(camera.matrixWorld, 1);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve the full station even on narrow screens.
const verticalSpan = Math.max(9.8, 12.4 / aspect);
camera.left = (-verticalSpan * aspect) / 2;
camera.right = (verticalSpan * aspect) / 2;
camera.top = verticalSpan / 2;
camera.bottom = -verticalSpan / 2;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
updateCamera();
}
function resetView() {
yaw = initial.yaw;
pitch = initial.pitch;
radius = initial.radius;
zoom = initial.zoom;
target.copy(initial.target);
updateCamera();
}
const pointers = new Map();
let dragMode = "orbit";
let lastX = 0;
let lastY = 0;
let previousPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
const dx = values[0].x - values[1].x;
const dy = values[0].y - values[1].y;
return Math.hypot(dx, dy);
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragMode =
event.button === 2 || event.shiftKey || event.ctrlKey
? "pan"
: "orbit";
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.classList.add("dragging");
} else if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
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 distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
zoom *= distance / previousPinchDistance;
zoom = THREE.MathUtils.clamp(zoom, 0.62, 2.25);
updateCamera();
}
previousPinchDistance = distance;
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragMode === "orbit") {
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.0045, 0.10, 1.15);
} else {
const unitsPerPixel =
(camera.top - camera.bottom) / camera.zoom / window.innerHeight;
target.addScaledVector(cameraRight, -dx * unitsPerPixel);
target.addScaledVector(cameraUp, dy * unitsPerPixel);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
renderer.domElement.classList.remove("dragging");
previousPinchDistance = 0;
} else if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
previousPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
zoom *= Math.exp(-event.deltaY * 0.001);
zoom = THREE.MathUtils.clamp(zoom, 0.62, 2.25);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetView();
});
window.addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```