Prompt specification
Build or customize the Three.js 3D scene "Repair desk inventory drawer" 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: Repair desk inventory drawer
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/repair-desk-inventory-drawer-x0019
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing modular drawer dividers. Compose an open workbench with subdivided drawers containing screws, plugs, tape, and tools; selecting a drawer highlights its matching category on the pegboard above. Stylized solid forms.
Working Three.js Starter (repair-desk-inventory-drawer-x0019):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modular Workbench</title>
<style>
:root {
--ink: #172326;
--paper: #eee7dc;
--glass: rgba(245, 240, 231, 0.86);
--line: rgba(23, 35, 38, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded5c7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--glass);
box-shadow: 0 18px 50px rgba(41, 33, 24, 0.12);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #596466;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 3px;
border-radius: 999px;
background: #ff7657;
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 0.96;
letter-spacing: -0.055em;
}
.brand p {
margin: 12px 0 0;
max-width: 280px;
color: #596466;
font-size: 12px;
line-height: 1.5;
}
.selected-card {
position: absolute;
top: 24px;
right: 24px;
width: 220px;
padding: 16px 18px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--glass);
box-shadow: 0 18px 50px rgba(41, 33, 24, 0.1);
backdrop-filter: blur(12px);
}
.selected-card span {
display: block;
margin-bottom: 4px;
color: #687174;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.selected-card strong {
display: block;
font-size: 21px;
letter-spacing: -0.035em;
}
.selected-card p {
margin: 7px 0 0;
color: #626d70;
font-size: 11px;
line-height: 1.45;
}
.help {
position: absolute;
right: 25px;
bottom: 24px;
color: rgba(23, 35, 38, 0.65);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.category-nav {
position: fixed;
left: 50%;
bottom: 20px;
z-index: 5;
display: flex;
gap: 8px;
padding: 8px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(245, 240, 231, 0.91);
box-shadow: 0 18px 50px rgba(41, 33, 24, 0.14);
backdrop-filter: blur(12px);
}
.category-button {
min-width: 105px;
padding: 10px 13px;
border: 1px solid transparent;
border-radius: 11px;
background: transparent;
color: #536064;
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
transition:
color 180ms ease,
background 180ms ease,
transform 180ms ease,
box-shadow 180ms ease;
}
.category-button:hover {
color: var(--ink);
background: rgba(23, 35, 38, 0.06);
transform: translateY(-1px);
}
.category-button.active {
color: var(--ink);
background: white;
box-shadow:
0 5px 16px rgba(35, 28, 20, 0.09),
inset 0 -3px 0 var(--category-color);
}
.category-button .dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: var(--category-color);
vertical-align: 1px;
}
#reset-view {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 6;
padding: 10px 14px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(245, 240, 231, 0.88);
color: #536064;
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
#reset-view:hover {
color: var(--ink);
background: white;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #ded5c7;
color: #526064;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
width: 245px;
padding: 14px 16px;
}
.brand p,
.selected-card,
.help {
display: none;
}
.category-nav {
right: 10px;
bottom: 10px;
left: 10px;
justify-content: center;
gap: 3px;
padding: 6px;
transform: none;
}
.category-button {
min-width: 0;
flex: 1;
padding: 10px 6px;
font-size: 8px;
}
.category-button .dot {
display: block;
width: 6px;
height: 6px;
margin: 0 auto 5px;
}
#reset-view {
right: 14px;
bottom: 76px;
left: auto;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="hud">
<section class="brand">
<div class="eyebrow">Workshop storage / 04</div>
<h1>MODULAR<br>WORKBENCH</h1>
<p>
Click a drawer or pegboard category to connect the stored hardware
with its place in the workshop system.
</p>
</section>
<section class="selected-card">
<span>Selected category</span>
<strong id="selected-name">TOOLS</strong>
<p id="selected-description">Hand tools are ready at the bench.</p>
</section>
<div class="help">Drag to orbit · Scroll to zoom · Right-drag to pan</div>
</div>
<nav class="category-nav" aria-label="Drawer categories">
<button class="category-button" data-category="screws" style="--category-color:#ff7657">
<span class="dot"></span>Screws
</button>
<button class="category-button" data-category="plugs" style="--category-color:#32c5d2">
<span class="dot"></span>Plugs
</button>
<button class="category-button" data-category="tape" style="--category-color:#f3c44e">
<span class="dot"></span>Tape
</button>
<button class="category-button active" data-category="tools" style="--category-color:#70c989">
<span class="dot"></span>Tools
</button>
</nav>
<button id="reset-view">Reset view</button>
<div id="loading">Building workbench…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const selectedName = document.getElementById("selected-name");
const selectedDescription = document.getElementById("selected-description");
const categoryButtons = [...document.querySelectorAll(".category-button")];
const categories = {
screws: {
name: "SCREWS",
color: 0xff7657,
description: "Fasteners are sorted and ready for the next assembly."
},
plugs: {
name: "PLUGS",
color: 0x32c5d2,
description: "Electrical plugs and fittings are grouped together."
},
tape: {
name: "TAPE",
color: 0xf3c44e,
description: "Rolls of tape are kept within easy reach."
},
tools: {
name: "TOOLS",
color: 0x70c989,
description: "Hand tools are ready at the bench."
}
};
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
renderer.domElement.setAttribute("aria-label", "Interactive modular workbench");
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded5c7);
scene.fog = new THREE.Fog(0xded5c7, 15, 29);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const hemiLight = new THREE.HemisphereLight(0xfff6e9, 0x655c51, 2.2);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xfff1db, 3.4);
keyLight.position.set(-5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d9df, 1.2);
fillLight.position.set(7, 5, 2);
scene.add(fillLight);
// ---------------------------------------------------------------------
// Materials and geometry helpers
// ---------------------------------------------------------------------
const materials = {
wall: new THREE.MeshStandardMaterial({
color: 0xd8d0c3,
roughness: 0.96
}),
floor: new THREE.MeshStandardMaterial({
color: 0xb8ad9d,
roughness: 0.94
}),
wood: new THREE.MeshStandardMaterial({
color: 0xb98555,
roughness: 0.72
}),
woodEdge: new THREE.MeshStandardMaterial({
color: 0x805737,
roughness: 0.78
}),
frame: new THREE.MeshStandardMaterial({
color: 0x26383b,
roughness: 0.64,
metalness: 0.14
}),
frameLight: new THREE.MeshStandardMaterial({
color: 0x4a5c5e,
roughness: 0.66,
metalness: 0.1
}),
pegboard: new THREE.MeshStandardMaterial({
color: 0xc3915e,
roughness: 0.86
}),
metal: new THREE.MeshStandardMaterial({
color: 0xaeb8b8,
roughness: 0.32,
metalness: 0.78
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x4a5354,
roughness: 0.45,
metalness: 0.58
}),
dark: new THREE.MeshStandardMaterial({
color: 0x1e292c,
roughness: 0.65
}),
paper: new THREE.MeshStandardMaterial({
color: 0xeee7d7,
roughness: 0.88
}),
ceramic: new THREE.MeshStandardMaterial({
color: 0xe8e2d8,
roughness: 0.72
})
};
const categoryMaterials = {};
for (const [key, data] of Object.entries(categories)) {
categoryMaterials[key] = new THREE.MeshStandardMaterial({
color: data.color,
roughness: 0.52,
metalness: 0.05
});
}
function addBox(parent, width, height, depth, material, x = 0, y = 0, z = 0, 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 addCylinder(
parent,
radiusTop,
radiusBottom,
height,
material,
x = 0,
y = 0,
z = 0,
segments = 20
) {
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 addTorus(parent, radius, tube, material, x = 0, y = 0, z = 0, arc = Math.PI * 2) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 12, 32, arc),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabelTexture(text, accent) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
const css = `#${accent.toString(16).padStart(6, "0")}`;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(20, 30, 32, 0.94)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = css;
ctx.fillRect(0, 0, 14, canvas.height);
ctx.fillStyle = "#f4efe5";
ctx.font = "800 48px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2 + 4, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function addLabel(parent, text, accent, width, height, x, y, z) {
const material = new THREE.MeshBasicMaterial({
map: makeLabelTexture(text, accent),
transparent: true,
toneMapped: false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function makeHitBox(parent, width, height, depth, category, x = 0, y = 0, z = 0) {
const material = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const hitBox = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
hitBox.position.set(x, y, z);
hitBox.userData.category = category;
parent.add(hitBox);
interactionObjects.push(hitBox);
return hitBox;
}
// ---------------------------------------------------------------------
// Room, bench, and cabinet
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(new THREE.PlaneGeometry(40, 40), materials.floor);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.03;
floor.receiveShadow = true;
scene.add(floor);
const wall = new THREE.Mesh(new THREE.PlaneGeometry(30, 18), materials.wall);
wall.position.set(0, 7, -1.28);
wall.receiveShadow = true;
scene.add(wall);
addBox(scene, 30, 0.16, 0.12, materials.woodEdge, 0, 0.08, -1.18);
// Workbench legs and lower shelf.
for (const x of [-3.35, 3.35]) {
for (const z of [-0.88, 0.88]) {
addBox(scene, 0.28, 1.92, 0.28, materials.frame, x, 0.97, z);
addBox(scene, 0.38, 0.1, 0.38, materials.darkMetal, x, 0.08, z);
}
}
addBox(scene, 6.55, 0.13, 1.58, materials.frameLight, 0, 0.24, 0);
addBox(scene, 8.0, 0.28, 2.5, materials.wood, 0, 2.05, 0);
addBox(scene, 8.05, 0.12, 0.16, materials.woodEdge, 0, 1.96, 1.22);
// Open cabinet carcass.
addBox(scene, 7.15, 1.62, 0.12, materials.frame, 0, 1.02, -1.0);
addBox(scene, 0.14, 1.7, 2.05, materials.frame, -3.57, 1.0, 0);
addBox(scene, 0.14, 1.7, 2.05, materials.frame, 3.57, 1.0, 0);
addBox(scene, 7.15, 0.12, 2.05, materials.frame, 0, 0.22, 0);
addBox(scene, 7.15, 0.12, 2.05, materials.frame, 0, 0.96, 0);
addBox(scene, 0.12, 1.7, 2.05, materials.frameLight, 0, 1.0, 0);
// Pegboard.
addBox(scene, 8.05, 3.2, 0.18, materials.pegboard, 0, 4.15, -1.02);
addBox(scene, 8.16, 0.12, 0.22, materials.woodEdge, 0, 5.76, -1.02);
addBox(scene, 8.16, 0.12, 0.22, materials.woodEdge, 0, 2.55, -1.02);
// Instanced peg holes.
const holeColumns = 25;
const holeRows = 9;
const holeGeometry = new THREE.CircleGeometry(0.029, 12);
const holeMaterial = new THREE.MeshBasicMaterial({ color: 0x65442c });
const holes = new THREE.InstancedMesh(holeGeometry, holeMaterial, holeColumns * holeRows);
const holeTransform = new THREE.Object3D();
let holeIndex = 0;
for (let row = 0; row < holeRows; row++) {
for (let col = 0; col < holeColumns; col++) {
holeTransform.position.set(
-3.72 + col * 0.31,
2.78 + row * 0.34,
-0.921
);
holeTransform.updateMatrix();
holes.setMatrixAt(holeIndex++, holeTransform.matrix);
}
}
holes.instanceMatrix.needsUpdate = true;
scene.add(holes);
addLabel(scene, "MODULE / 04", 0xff7657, 1.72, 0.35, 0, 5.43, -0.89);
// ---------------------------------------------------------------------
// Pegboard category icons
// ---------------------------------------------------------------------
function createPegIcon(key, material) {
const group = new THREE.Group();
if (key === "screws") {
for (let i = -1; i <= 1; i++) {
const screw = new THREE.Group();
addCylinder(screw, 0.032, 0.025, 0.5, material, 0, 0.12, 0, 12);
const tip = new THREE.Mesh(
new THREE.ConeGeometry(0.034, 0.15, 12),
material
);
tip.rotation.z = Math.PI;
tip.position.y = -0.2;
screw.add(tip);
addCylinder(screw, 0.092, 0.092, 0.1, material, 0, 0.41, 0, 16);
screw.position.x = i * 0.29;
screw.rotation.z = i * 0.1;
group.add(screw);
}
}
if (key === "plugs") {
for (const x of [-0.25, 0.25]) {
addCylinder(group, 0.18, 0.21, 0.43, material, x, 0.12, 0, 18);
addBox(group, 0.045, 0.23, 0.045, materials.metal, x - 0.065, -0.21, 0);
addBox(group, 0.045, 0.23, 0.045, materials.metal, x + 0.065, -0.21, 0);
}
}
if (key === "tape") {
const tape = addTorus(group, 0.34, 0.09, material, 0, 0.13, 0.04);
tape.rotation.z = -0.15;
const inner = addTorus(group, 0.23, 0.025, materials.dark, 0, 0.13, 0.045);
inner.rotation.z = -0.15;
}
if (key === "tools") {
const screwdriver = new THREE.Group();
addBox(screwdriver, 0.18, 0.52, 0.13, material, 0, -0.04, 0);
addCylinder(screwdriver, 0.035, 0.035, 0.45, materials.metal, 0, 0.39, 0, 12);
screwdriver.rotation.z = -0.63;
group.add(screwdriver);
const wrench = new THREE.Group();
addBox(wrench, 0.12, 0.64, 0.12, material, 0, 0, 0);
addTorus(wrench, 0.16, 0.045, material, 0, 0.35, 0, Math.PI * 1.65);
wrench.rotation.z = 0.68;
group.add(wrench);
}
return group;
}
const interactionObjects = [];
const boardVisuals = {};
const boardPositions = {
screws: -2.85,
plugs: -0.95,
tape: 0.95,
tools: 2.85
};
for (const [key, data] of Object.entries(categories)) {
const group = new THREE.Group();
group.position.set(boardPositions[key], 4.28, -0.88);
scene.add(group);
const frameMaterial = new THREE.MeshStandardMaterial({
color: data.color,
emissive: data.color,
emissiveIntensity: 0.05,
roughness: 0.5
});
const backingMaterial = new THREE.MeshStandardMaterial({
color: 0x263438,
emissive: data.color,
emissiveIntensity: 0.015,
roughness: 0.74
});
const iconMaterial = new THREE.MeshStandardMaterial({
color: data.color,
emissive: data.color,
emissiveIntensity: 0.05,
roughness: 0.48,
metalness: 0.06
});
addBox(group, 1.73, 1.77, 0.05, frameMaterial, 0, 0, -0.045);
addBox(group, 1.64, 1.68, 0.08, backingMaterial, 0, 0, 0);
const icon = createPegIcon(key, iconMaterial);
icon.position.set(0, 0.22, 0.14);
group.add(icon);
addLabel(group, data.name, data.color, 1.43, 0.35, 0, -0.58, 0.055);
makeHitBox(group, 1.72, 1.78, 0.36, key, 0, 0, 0.06);
const light = new THREE.PointLight(data.color, 0.12, 2.5, 2);
light.position.set(0, 0, 0.6);
group.add(light);
boardVisuals[key] = {
group,
frameMaterial,
backingMaterial,
iconMaterial,
light,
targetColor: new THREE.Color(data.color),
darkColor: new THREE.Color(0x263438)
};
}
// ---------------------------------------------------------------------
// Hardware shapes used inside the drawers
// ---------------------------------------------------------------------
function createLooseScrew() {
const group = new THREE.Group();
const shaft = addCylinder(group, 0.032, 0.025, 0.57, materials.metal, 0, 0, 0, 12);
shaft.rotation.z = Math.PI / 2;
const head = addCylinder(group, 0.092, 0.092, 0.07, materials.metal, 0.31, 0, 0, 14);
head.rotation.z = Math.PI / 2;
const tip = new THREE.Mesh(
new THREE.ConeGeometry(0.034, 0.1, 12),
materials.metal
);
tip.rotation.z = -Math.PI / 2;
tip.position.x = -0.335;
group.add(tip);
return group;
}
function createLoosePlug() {
const group = new THREE.Group();
addCylinder(group, 0.15, 0.18, 0.27, categoryMaterials.plugs, 0, 0.02, 0, 16);
addCylinder(group, 0.125, 0.145, 0.055, materials.dark, 0, 0.18, 0, 16);
addBox(group, 0.04, 0.22, 0.04, materials.metal, -0.055, -0.22, 0);
addBox(group, 0.04, 0.22, 0.04, materials.metal, 0.055, -0.22, 0);
return group;
}
function createTapeRoll() {
const group = new THREE.Group();
const roll = addTorus(group, 0.24, 0.075, categoryMaterials.tape);
roll.rotation.x = Math.PI / 2;
const core = addCylinder(group, 0.105, 0.105, 0.13, materials.paper);
core.rotation.x = Math.PI / 2;
return group;
}
function createScrewdriver() {
const group = new THREE.Group();
const handle = addCylinder(group, 0.13, 0.16, 0.48, categoryMaterials.tools, 0, 0, -0.28, 16);
handle.rotation.x = Math.PI / 2;
const shaft = addCylinder(group, 0.035, 0.035, 0.57, materials.metal, 0, 0, 0.24, 12);
shaft.rotation.x = Math.PI / 2;
const tip = addBox(group, 0.09, 0.025, 0.18, materials.metal, 0, 0, 0.59);
tip.rotation.y = 0.3;
return group;
}
function createWrench() {
const group = new THREE.Group();
addBox(group, 0.14, 0.08, 0.78, materials.metal, 0, 0, 0);
const jaw = addTorus(group, 0.15, 0.045, materials.metal, 0, 0, 0.45, Math.PI * 1.65);
jaw.rotation.x = Math.PI / 2;
const end = addTorus(group, 0.115, 0.038, materials.metal, 0, 0, -0.45, Math.PI * 1.65);
end.rotation.x = Math.PI / 2;
return group;
}
function populateDrawer(category, drawer) {
const group = drawer.group;
if (category === "screws") {
const locations = [
[-1.12, -0.37, 0.08],
[-0.72, -0.31, -0.05],
[-0.34, -0.4, 0.12],
[0.34, -0.32, -0.08],
[0.78, -0.38, 0.09],
[1.15, -0.3, -0.12],
[-0.9, 0.31, -0.04],
[0.55, 0.3, 0.12]
];
locations.forEach(([x, z, rotation], index) => {
const screw = createLooseScrew();
screw.position.set(x, -0.115, z);
screw.rotation.y = rotation;
screw.scale.setScalar(index % 3 === 0 ? 0.88 : 1);
group.add(screw);
});
}
if (category === "plugs") {
const locations = [
[-1.08, -0.34],
[-0.7, -0.31],
[-0.34, -0.39],
[0.35, -0.32],
[0.78, -0.4],
[1.15, -0.3],
[-0.72, 0.31],
[0.74, 0.31]
];
locations.forEach(([x, z], index) => {
const plug = createLoosePlug();
plug.position.set(x, -0.025, z);
plug.rotation.y = index * 0.23;
group.add(plug);
});
}
if (category === "tape") {
const locations = [
[-1.08, -0.35],
[-0.36, -0.34],
[0.4, -0.35],
[1.08, -0.31],
[-0.7, 0.3],
[0.25, 0.31]
];
locations.forEach(([x, z], index) => {
const tape = createTapeRoll();
tape.position.set(x, -0.105, z);
tape.rotation.y = index * 0.5;
group.add(tape);
});
}
if (category === "tools") {
const screwdriver = createScrewdriver();
screwdriver.position.set(-0.92, -0.09, 0);
screwdriver.rotation.y = -0.18;
group.add(screwdriver);
const secondDriver = createScrewdriver();
secondDriver.position.set(-0.35, -0.09, 0.02);
secondDriver.rotation.y = 0.22;
secondDriver.scale.setScalar(0.88);
group.add(secondDriver);
const wrench = createWrench();
wrench.position.set(0.64, -0.08, 0.05);
wrench.rotation.y = -0.08;
group.add(wrench);
const secondWrench = createWrench();
secondWrench.position.set(1.15, -0.08, -0.05);
secondWrench.rotation.y = 0.18;
secondWrench.scale.setScalar(0.9);
group.add(secondWrench);
}
}
// ---------------------------------------------------------------------
// Drawers
// ---------------------------------------------------------------------
const drawers = {};
function createDrawer(category, x, y) {
const data = categories[category];
const group = new THREE.Group();
group.position.set(x, y, 0.48);
scene.add(group);
const width = 3.15;
const depth = 1.5;
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x35474b,
roughness: 0.65,
metalness: 0.13,
emissive: data.color,
emissiveIntensity: 0.01
});
const frontMaterial = new THREE.MeshStandardMaterial({
color: 0x26383c,
roughness: 0.6,
metalness: 0.14,
emissive: data.color,
emissiveIntensity: 0.01
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: data.color,
emissive: data.color,
emissiveIntensity: 0.05,
roughness: 0.48
});
addBox(group, width, 0.09, depth, bodyMaterial, 0, -0.24, 0);
addBox(group, 0.09, 0.4, depth, bodyMaterial, -width / 2, -0.02, 0);
addBox(group, 0.09, 0.4, depth, bodyMaterial, width / 2, -0.02, 0);
addBox(group, width, 0.4, 0.08, bodyMaterial, 0, -0.02, -depth / 2);
addBox(group, width + 0.09, 0.5, 0.12, frontMaterial, 0, -0.02, depth / 2);
addBox(group, width - 0.12, 0.055, 0.025, accentMaterial, 0, 0.175, depth / 2 + 0.073);
const handle = addBox(group, 0.78, 0.11, 0.13, materials.metal, 0, -0.015, depth / 2 + 0.13);
handle.rotation.z = Math.PI / 2;
// Internal modular dividers.
addBox(group, 0.055, 0.23, depth - 0.1, materials.frameLight, -0.53, -0.1, 0);
addBox(group, 0.055, 0.23, depth - 0.1, materials.frameLight, 0.53, -0.1, 0);
const outlineGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(width + 0.11, 0.58, depth + 0.05)
);
const outlineMaterial = new THREE.LineBasicMaterial({
color: data.color,
transparent: true,
opacity: 0.95
});
const outline = new THREE.LineSegments(outlineGeometry, outlineMaterial);
outline.position.set(0, -0.015, 0.02);
outline.visible = false;
group.add(outline);
makeHitBox(group, width + 0.12, 0.64, depth + 0.1, category, 0, -0.01, 0.02);
const drawer = {
category,
group,
frontMaterial,
accentMaterial,
outline,
currentOpen: 0.48,
targetOpen: 0.48
};
drawers[category] = drawer;
populateDrawer(category, drawer);
return drawer;
}
createDrawer("screws", -1.72, 0.58);
createDrawer("plugs", 1.72, 0.58);
createDrawer("tape", -1.72, 1.32);
createDrawer("tools", 1.72, 1.32);
// ---------------------------------------------------------------------
// Bench-top props
// ---------------------------------------------------------------------
// Cutting mat and notebook.
addBox(scene, 2.15, 0.025, 1.08, categoryMaterials.plugs, 0.35, 2.205, 0.1);
addBox(scene, 0.85, 0.055, 0.66, materials.paper, 0.26, 2.245, 0.13);
addBox(scene, 0.11, 0.065, 0.68, categoryMaterials.tape, 0.0, 2.25, 0.13);
// Bench vise.
addBox(scene, 0.92, 0.12, 0.62, materials.darkMetal, 2.72, 2.26, -0.18);
addBox(scene, 0.22, 0.44, 0.56, materials.frame, 2.58, 2.48, -0.18);
addBox(scene, 0.22, 0.44, 0.56, materials.frame, 3.08, 2.48, -0.18);
const viseShaft = addCylinder(scene, 0.055, 0.055, 0.86, materials.metal, 2.83, 2.43, -0.18, 16);
viseShaft.rotation.z = Math.PI / 2;
const viseHandle = addBox(scene, 0.1, 0.45, 0.1, materials.darkMetal, 3.27, 2.43, -0.18);
viseHandle.rotation.x = Math.PI / 2;
// Mug.
addCylinder(scene, 0.29, 0.25, 0.48, materials.ceramic, -2.45, 2.44, 0.42, 24);
addCylinder(scene, 0.235, 0.235, 0.025, materials.dark, -2.45, 2.69, 0.42, 24);
const mugHandle = addTorus(scene, 0.18, 0.045, materials.ceramic, -2.14, 2.46, 0.42);
mugHandle.rotation.y = Math.PI / 2;
// Small pencil cup.
addCylinder(scene, 0.22, 0.19, 0.36, materials.frameLight, -3.1, 2.39, 0.48, 18);
addBox(scene, 0.055, 0.52, 0.055, categoryMaterials.tape, -3.16, 2.75, 0.47);
addBox(scene, 0.055, 0.47, 0.055, materials.metal, -3.05, 2.7, 0.49);
addBox(scene, 0.055, 0.55, 0.055, categoryMaterials.screws, -3.05, 2.76, 0.43);
// ---------------------------------------------------------------------
// Selection state
// ---------------------------------------------------------------------
let selectedCategory = "tools";
let hoveredCategory = null;
function selectCategory(category) {
if (!categories[category]) return;
selectedCategory = category;
const data = categories[category];
selectedName.textContent = data.name;
selectedDescription.textContent = data.description;
categoryButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.category === category);
});
for (const [key, drawer] of Object.entries(drawers)) {
drawer.targetOpen = key === category ? 0.78 : 0.48;
}
}
categoryButtons.forEach((button) => {
button.addEventListener("click", () => selectCategory(button.dataset.category));
});
// ---------------------------------------------------------------------
// Custom orbit, pan, zoom, and picking controls
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.75, 0.15),
spherical: new THREE.Spherical(11.6, 1.34, 0.52)
};
function applyCamera() {
camera.position.setFromSpherical(cameraState.spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const drag = {
active: false,
pointerId: null,
button: 0,
lastX: 0,
lastY: 0,
startX: 0,
startY: 0,
moved: false
};
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pick(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactionObjects, false);
if (hits.length) {
selectCategory(hits[0].object.userData.category);
}
}
function hoverTest(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactionObjects, false);
hoveredCategory = hits.length ? hits[0].object.userData.category : null;
renderer.domElement.style.cursor = hoveredCategory ? "pointer" : "grab";
}
renderer.domElement.addEventListener("pointerdown", (event) => {
drag.active = true;
drag.pointerId = event.pointerId;
drag.button = event.button;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
drag.startX = event.clientX;
drag.startY = event.clientY;
drag.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!drag.active || event.pointerId !== drag.pointerId) {
hoverTest(event);
return;
}
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
if (
Math.abs(event.clientX - drag.startX) +
Math.abs(event.clientY - drag.startY) >
5
) {
drag.moved = true;
}
if (drag.button === 2) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = cameraState.spherical.radius * 0.00125;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -3.5, 3.5);
cameraState.target.y = THREE.MathUtils.clamp(cameraState.target.y, 1.1, 5.2);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -1, 2);
} else {
cameraState.spherical.theta -= dx * 0.005;
cameraState.spherical.phi = THREE.MathUtils.clamp(
cameraState.spherical.phi - dy * 0.005,
0.72,
1.52
);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (
drag.active &&
drag.pointerId === event.pointerId &&
!drag.moved &&
drag.button === 0
) {
pick(event);
}
drag.active = false;
drag.pointerId = null;
renderer.domElement.style.cursor = hoveredCategory ? "pointer" : "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
drag.active = false;
drag.pointerId = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.spherical.radius = THREE.MathUtils.clamp(
cameraState.spherical.radius * Math.exp(event.deltaY * 0.001),
6.8,
18
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
document.getElementById("reset-view").addEventListener("click", () => {
cameraState.target.set(0, 2.75, 0.15);
cameraState.spherical.set(11.6, 1.34, 0.52);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function damp(current, target, speed, delta) {
return THREE.MathUtils.lerp(current, target, 1 - Math.exp(-speed * delta));
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
for (const [key, drawer] of Object.entries(drawers)) {
const isSelected = key === selectedCategory;
const isHovered = key === hoveredCategory;
drawer.currentOpen = damp(
drawer.currentOpen,
drawer.targetOpen,
7,
delta
);
drawer.group.position.z = drawer.currentOpen;
drawer.frontMaterial.emissiveIntensity = damp(
drawer.frontMaterial.emissiveIntensity,
isSelected ? 0.38 : isHovered ? 0.16 : 0.015,
9,
delta
);
drawer.accentMaterial.emissiveIntensity = damp(
drawer.accentMaterial.emissiveIntensity,
isSelected ? 0.42 : 0.05,
9,
delta
);
drawer.outline.visible = isSelected;
}
for (const [key, visual] of Object.entries(boardVisuals)) {
const isSelected = key === selectedCategory;
const isHovered = key === hoveredCategory;
const targetScale = isSelected ? 1.075 : isHovered ? 1.035 : 1;
const currentScale = visual.group.scale.x;
const nextScale = damp(currentScale, targetScale, 9, delta);
visual.group.scale.setScalar(nextScale);
visual.group.position.y = damp(
visual.group.position.y,
isSelected ? 4.36 : 4.28,
8,
delta
);
visual.frameMaterial.emissiveIntensity = damp(
visual.frameMaterial.emissiveIntensity,
isSelected ? 0.48 : isHovered ? 0.2 : 0.04,
9,
delta
);
visual.iconMaterial.emissiveIntensity = damp(
visual.iconMaterial.emissiveIntensity,
isSelected ? 0.56 : isHovered ? 0.24 : 0.05,
9,
delta
);
visual.backingMaterial.emissiveIntensity = damp(
visual.backingMaterial.emissiveIntensity,
isSelected ? 0.2 : isHovered ? 0.08 : 0.015,
9,
delta
);
visual.backingMaterial.color.lerp(
isSelected ? visual.targetColor : visual.darkColor,
1 - Math.exp(-7 * delta)
);
visual.backingMaterial.color.multiplyScalar(isSelected ? 0.34 : 1);
visual.light.intensity = damp(
visual.light.intensity,
isSelected ? 2.4 : isHovered ? 0.8 : 0.12,
8,
delta
);
}
applyCamera();
renderer.render(scene, camera);
}
selectCategory("tools");
applyCamera();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```