Prompt specification
Build or customize the Three.js 3D scene "Shared studio storage reconfiguration" 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: Shared studio storage reconfiguration
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shared-studio-storage-reconfiguration-x0212
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring pegboard storage. Create a workshop wall serving painting and repair sessions; users swap hook modules and trace retrieval routes to compare accessibility without duplicating the entire tool collection. Low-poly.
Working Three.js Starter (shared-studio-storage-reconfiguration-x0212):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pegboard Lab — Workshop Route Planner</title>
<style>
:root {
--ink: #252b28;
--muted: #69706a;
--paper: rgba(248, 245, 236, 0.91);
--line: rgba(45, 55, 49, 0.14);
--green: #2f7068;
--green-dark: #214f4a;
--orange: #d2734f;
--blue: #53678c;
--shadow: 0 14px 40px rgba(45, 43, 35, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #d8d0bf;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 5;
top: 20px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand,
.status-strip {
border: 1px solid rgba(255, 255, 255, 0.48);
background: rgba(248, 245, 236, 0.82);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.brand {
padding: 15px 18px 14px;
border-radius: 4px 18px 18px 18px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 2.1vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
}
.status-strip {
display: flex;
gap: 18px;
padding: 12px 16px;
border-radius: 16px 4px 16px 16px;
}
.status-item {
min-width: 62px;
}
.status-item strong {
display: block;
font-size: 17px;
line-height: 1;
}
.status-item span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 4;
top: 118px;
width: 286px;
max-height: calc(100vh - 150px);
overflow: auto;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 5px 22px 22px 22px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: rgba(47, 112, 104, 0.25) transparent;
}
.panel-left {
left: 24px;
}
.panel-right {
right: 24px;
width: 304px;
border-radius: 22px 5px 22px 22px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.panel h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.02em;
}
.panel-copy {
margin: 0 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.section-label {
margin: 15px 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.module-list,
.slot-list {
display: grid;
gap: 8px;
}
.module-card {
display: grid;
grid-template-columns: 38px 1fr auto;
align-items: center;
gap: 10px;
width: 100%;
padding: 10px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--ink);
text-align: left;
background: rgba(255, 255, 255, 0.55);
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.module-card:hover {
transform: translateY(-1px);
border-color: rgba(47, 112, 104, 0.45);
}
.module-card.active {
border-color: var(--green);
background: rgba(47, 112, 104, 0.09);
box-shadow: inset 3px 0 0 var(--green);
}
.module-swatch {
display: grid;
place-items: center;
width: 38px;
height: 38px;
border-radius: 9px;
color: white;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
}
.module-copy strong,
.module-copy small {
display: block;
}
.module-copy strong {
font-size: 12px;
}
.module-copy small {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.module-count {
color: var(--muted);
font-size: 9px;
font-weight: 800;
}
.slot-button {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 8px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
text-align: left;
background: rgba(255, 255, 255, 0.65);
cursor: pointer;
}
.slot-button:hover {
border-color: var(--green);
background: rgba(47, 112, 104, 0.08);
}
.slot-button span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.slot-button b {
font-size: 11px;
}
.utility-button,
.trace-button {
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
background: rgba(255, 255, 255, 0.65);
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.utility-button {
width: 100%;
padding: 10px 12px;
}
.utility-button:hover,
.trace-button:hover {
border-color: var(--green);
color: var(--green-dark);
}
.trace-button {
padding: 8px 10px;
white-space: nowrap;
}
.trace-button.active {
border-color: var(--green);
color: white;
background: var(--green);
}
.tool-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.tool-button {
position: relative;
min-width: 0;
padding: 9px 4px 8px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
background: rgba(255, 255, 255, 0.58);
cursor: pointer;
transition:
transform 140ms ease,
border-color 140ms ease,
background 140ms ease;
}
.tool-button:hover {
transform: translateY(-1px);
border-color: var(--tool-color);
}
.tool-button.active {
border-color: var(--tool-color);
background: color-mix(in srgb, var(--tool-color) 10%, white);
box-shadow: inset 0 -3px 0 var(--tool-color);
}
.tool-code {
display: block;
color: var(--tool-color);
font-size: 12px;
font-weight: 900;
letter-spacing: 0.08em;
}
.tool-name {
display: block;
margin-top: 4px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.tool-mount {
position: absolute;
top: 5px;
right: 6px;
color: var(--muted);
font-size: 8px;
font-weight: 900;
}
.route-summary {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.selected-tool {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.selected-tool strong {
display: block;
font-size: 13px;
}
.selected-tool small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.mount-badge {
padding: 5px 7px;
border-radius: 7px;
color: white;
background: var(--green);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
}
.score-row {
display: grid;
grid-template-columns: 74px 1fr 34px;
align-items: center;
gap: 8px;
margin: 8px 0;
}
.score-row label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.score-track {
height: 6px;
overflow: hidden;
border-radius: 20px;
background: rgba(40, 50, 44, 0.1);
}
.score-fill {
height: 100%;
width: 0;
border-radius: inherit;
background: var(--green);
transition: width 280ms ease;
}
.score-fill.reference {
background: var(--orange);
}
.score-number {
text-align: right;
font-size: 12px;
font-weight: 850;
}
.delta {
font-size: 10px;
font-weight: 900;
}
.delta.good {
color: var(--green);
}
.delta.bad {
color: var(--orange);
}
.metrics {
display: grid;
gap: 6px;
margin: 13px 0;
}
.metric-line {
display: grid;
grid-template-columns: 1fr 58px 58px;
gap: 5px;
padding-bottom: 5px;
border-bottom: 1px dashed var(--line);
font-size: 10px;
}
.metric-line span:first-child {
color: var(--muted);
}
.metric-line span:not(:first-child) {
text-align: right;
font-weight: 750;
}
.metric-head {
color: var(--muted);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.insight {
margin: 10px 0 12px;
padding: 9px 10px;
border-left: 3px solid var(--green);
border-radius: 0 8px 8px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
background: rgba(47, 112, 104, 0.07);
}
.legend {
position: fixed;
z-index: 3;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 16px;
padding: 10px 15px;
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 14px;
color: var(--muted);
background: rgba(248, 245, 236, 0.84);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
transform: translateX(-50%);
pointer-events: none;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.legend-line {
width: 21px;
height: 3px;
border-radius: 3px;
background: var(--green);
}
.legend-line.reference {
height: 0;
border-top: 2px dashed var(--orange);
background: transparent;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
}
.camera-button {
position: fixed;
z-index: 5;
right: 24px;
bottom: 22px;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 50%;
color: var(--ink);
background: rgba(248, 245, 236, 0.88);
box-shadow: var(--shadow);
cursor: pointer;
}
.toast {
position: fixed;
z-index: 10;
left: 50%;
bottom: 82px;
max-width: min(440px, calc(100vw - 40px));
padding: 11px 15px;
border-radius: 12px;
color: white;
background: rgba(37, 43, 40, 0.92);
box-shadow: var(--shadow);
opacity: 0;
transform: translate(-50%, 12px);
transition:
opacity 180ms ease,
transform 180ms ease;
pointer-events: none;
text-align: center;
font-size: 11px;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: var(--green-dark);
background: #e6dfd1;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1050px) {
.panel {
width: 250px;
}
.panel-right {
width: 270px;
}
.status-strip {
gap: 10px;
}
}
@media (max-width: 760px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand {
padding: 11px 13px;
}
.subtitle,
.status-strip {
display: none;
}
.panel {
top: auto;
bottom: 10px;
width: calc(50vw - 15px);
max-height: 43vh;
padding: 12px;
border-radius: 14px;
}
.panel-left {
left: 10px;
}
.panel-right {
right: 10px;
border-radius: 14px;
}
.panel-copy,
.section-label,
.module-copy small,
.legend {
display: none;
}
.module-card {
grid-template-columns: 30px 1fr;
padding: 7px;
}
.module-swatch {
width: 30px;
height: 30px;
}
.module-count {
display: none;
}
.tool-grid {
grid-template-columns: repeat(3, 1fr);
}
.camera-button {
right: 10px;
bottom: calc(43vh + 18px);
width: 32px;
height: 32px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Workshop systems lab</div>
<h1>Pegboard Lab</h1>
<p class="subtitle">Rearrange modules. Trace retrieval. Compare the reach.</p>
</div>
<div class="status-strip" aria-label="Collection status">
<div class="status-item">
<strong>9</strong>
<span>Tracked tools</span>
</div>
<div class="status-item">
<strong>3</strong>
<span>Hook modules</span>
</div>
<div class="status-item">
<strong>0</strong>
<span>Duplicates</span>
</div>
</div>
</header>
<aside class="panel panel-left">
<div class="panel-title">
<h2>Hook modules</h2>
</div>
<p class="panel-copy">
Select a module, then choose a mount to swap it into. The same three tools
travel with each module—no copies are created.
</p>
<div id="moduleList" class="module-list"></div>
<div class="section-label">Swap into mount</div>
<div class="slot-list">
<button class="slot-button" data-slot="0">
<span>Mount A · high left</span>
<b id="slotName0"></b>
</button>
<button class="slot-button" data-slot="1">
<span>Mount B · center</span>
<b id="slotName1"></b>
</button>
<button class="slot-button" data-slot="2">
<span>Mount C · low right</span>
<b id="slotName2"></b>
</button>
</div>
<div class="section-label">Layout</div>
<button id="resetLayout" class="utility-button">Reset original layout</button>
</aside>
<aside class="panel panel-right">
<div class="panel-title">
<h2>Route inspector</h2>
<button id="traceAll" class="trace-button">Trace all</button>
</div>
<p class="panel-copy">
Select a tool to trace its retrieval path. The orange reference is the
original position, or your last pinned comparison.
</p>
<div id="toolList" class="tool-grid"></div>
<div class="route-summary">
<div class="selected-tool">
<div>
<strong id="selectedToolName"></strong>
<small id="selectedToolMeta"></small>
</div>
<span id="selectedMount" class="mount-badge"></span>
</div>
<div class="score-row">
<label>Current</label>
<div class="score-track">
<div id="currentScoreBar" class="score-fill"></div>
</div>
<span id="currentScore" class="score-number"></span>
</div>
<div class="score-row">
<label id="referenceLabel">Baseline</label>
<div class="score-track">
<div id="referenceScoreBar" class="score-fill reference"></div>
</div>
<span id="referenceScore" class="score-number"></span>
</div>
<div class="metrics">
<div class="metric-line metric-head">
<span>Measure</span>
<span>Current</span>
<span>Reference</span>
</div>
<div class="metric-line">
<span>Travel path</span>
<span id="currentTravel"></span>
<span id="referenceTravel"></span>
</div>
<div class="metric-line">
<span>Direct reach</span>
<span id="currentReach"></span>
<span id="referenceReach"></span>
</div>
<div class="metric-line">
<span>Peak height</span>
<span id="currentHeight"></span>
<span id="referenceHeight"></span>
</div>
</div>
<div id="routeInsight" class="insight"></div>
<button id="pinReference" class="utility-button">Pin current positions as reference</button>
</div>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="legend-line"></span>Current route</div>
<div class="legend-item"><span class="legend-line reference"></span>Reference route</div>
<div class="legend-item"><span class="legend-dot"></span>Worker start</div>
</div>
<button id="cameraReset" class="camera-button" title="Reset camera" aria-label="Reset camera">
↺
</button>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<div id="loading">Building workshop…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and renderer
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
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.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly workshop pegboard. Drag to orbit, scroll to zoom."
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d0bf);
scene.fog = new THREE.Fog(0xd8d0bf, 19, 37);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
target: new THREE.Vector3(0, 4.35, 0),
radius: 15.2,
theta: 0.285,
phi: 1.315
};
function applyCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.radius = 15.2;
cameraState.theta = 0.285;
cameraState.phi = 1.315;
applyCamera();
}
applyCamera();
const hemi = new THREE.HemisphereLight(0xf7f1df, 0x736b5e, 2.05);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff3d7, 3.15);
key.position.set(-7, 13, 10);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -13;
key.shadow.camera.right = 13;
key.shadow.camera.top = 13;
key.shadow.camera.bottom = -8;
key.shadow.camera.near = 1;
key.shadow.camera.far = 35;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xaac8c3, 1.0);
fill.position.set(9, 7, 8);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared materials and geometry helpers
// -------------------------------------------------------------------------
const materials = {
wall: new THREE.MeshStandardMaterial({
color: 0xc9c1b0,
roughness: 0.96,
flatShading: true
}),
floor: new THREE.MeshStandardMaterial({
color: 0xb8ad99,
roughness: 1,
flatShading: true
}),
board: new THREE.MeshStandardMaterial({
color: 0xb77d4f,
roughness: 0.88,
flatShading: true
}),
frame: new THREE.MeshStandardMaterial({
color: 0x604435,
roughness: 0.86,
flatShading: true
}),
bench: new THREE.MeshStandardMaterial({
color: 0x876249,
roughness: 0.9,
flatShading: true
}),
benchTop: new THREE.MeshStandardMaterial({
color: 0xa97950,
roughness: 0.84,
flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x303633,
roughness: 0.76,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0xaab0aa,
roughness: 0.42,
metalness: 0.72,
flatShading: true
}),
brass: new THREE.MeshStandardMaterial({
color: 0xc9a25c,
roughness: 0.45,
metalness: 0.62,
flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xe9dfc8,
roughness: 0.78,
flatShading: true
}),
red: new THREE.MeshStandardMaterial({
color: 0xb55042,
roughness: 0.7,
flatShading: true
}),
teal: new THREE.MeshStandardMaterial({
color: 0x3f7770,
roughness: 0.72,
flatShading: true
}),
blue: new THREE.MeshStandardMaterial({
color: 0x4f6387,
roughness: 0.74,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0xb98154,
roughness: 0.86,
flatShading: true
})
};
function addMesh(parent, geometry, material, position = [0, 0, 0], rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, size, material, position, rotation) {
return addMesh(
parent,
new THREE.BoxGeometry(...size),
material,
position,
rotation
);
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
material,
position,
rotation = [0, 0, 0],
segments = 8
) {
return addMesh(
parent,
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material,
position,
rotation
);
}
function makeTextSprite(text, background = "#2f7068", foreground = "#ffffff", width = 512) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = 112;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "800 38px system-ui, sans-serif";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(2.55, 0.56, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Workshop room, pegboard and bench
// -------------------------------------------------------------------------
const workshop = new THREE.Group();
scene.add(workshop);
addBox(workshop, [22, 12, 0.45], materials.wall, [0, 5.9, -0.65]);
addBox(workshop, [24, 0.22, 18], materials.floor, [0, -0.12, 4.2]);
// Pegboard face and frame.
addBox(workshop, [11.55, 6.25, 0.2], materials.board, [0, 5.38, 0.12]);
addBox(workshop, [12.0, 0.22, 0.32], materials.frame, [0, 8.56, 0.15]);
addBox(workshop, [12.0, 0.22, 0.32], materials.frame, [0, 2.2, 0.15]);
addBox(workshop, [0.22, 6.45, 0.32], materials.frame, [-5.89, 5.38, 0.15]);
addBox(workshop, [0.22, 6.45, 0.32], materials.frame, [5.89, 5.38, 0.15]);
// Peg holes as one instanced low-poly mesh.
const holeGeometry = new THREE.CylinderGeometry(0.038, 0.038, 0.022, 8);
holeGeometry.rotateX(Math.PI / 2);
const holeMaterial = new THREE.MeshStandardMaterial({
color: 0x5f4030,
roughness: 1,
flatShading: true
});
const holeCountX = 30;
const holeCountY = 16;
const holes = new THREE.InstancedMesh(
holeGeometry,
holeMaterial,
holeCountX * holeCountY
);
const holeDummy = new THREE.Object3D();
let holeIndex = 0;
for (let row = 0; row < holeCountY; row++) {
for (let column = 0; column < holeCountX; column++) {
holeDummy.position.set(
-5.45 + column * 0.374,
2.52 + row * 0.365,
0.235
);
holeDummy.updateMatrix();
holes.setMatrixAt(holeIndex++, holeDummy.matrix);
}
}
holes.instanceMatrix.needsUpdate = true;
workshop.add(holes);
const workshopSign = makeTextSprite("PAINT + REPAIR", "#363c39", "#f2ead9", 768);
workshopSign.position.set(0, 9.03, 0.02);
workshopSign.scale.set(4.4, 0.64, 1);
workshop.add(workshopSign);
// Workbench.
const bench = new THREE.Group();
workshop.add(bench);
addBox(bench, [10.2, 0.25, 2.2], materials.benchTop, [0, 1.38, 1.65]);
addBox(bench, [9.55, 0.16, 1.65], materials.bench, [0, 0.52, 1.68]);
for (const x of [-4.48, 4.48]) {
for (const z of [0.84, 2.46]) {
addBox(bench, [0.26, 1.45, 0.26], materials.frame, [x, 0.65, z]);
}
}
// Toolbox and task props.
addBox(bench, [1.7, 0.52, 0.85], materials.teal, [-3.6, 1.77, 1.65]);
addBox(bench, [1.72, 0.12, 0.87], materials.dark, [-3.6, 2.08, 1.65]);
addBox(bench, [0.55, 0.09, 0.1], materials.brass, [-3.6, 1.98, 2.1]);
const paintColors = [0xd26a4f, 0x567f86, 0xe1bc58];
paintColors.forEach((color, index) => {
const paintMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
flatShading: true
});
addCylinder(
bench,
0.31,
0.29,
0.54,
paintMaterial,
[2.6 + index * 0.72, 1.78, 1.48],
[0, 0, 0],
10
);
addCylinder(
bench,
0.32,
0.32,
0.045,
materials.cream,
[2.6 + index * 0.72, 2.07, 1.48],
[0, 0, 0],
10
);
});
// Low-poly folded rag.
addBox(bench, [0.75, 0.12, 0.55], materials.cream, [1.25, 1.57, 2.12], [0, 0.25, 0]);
addBox(bench, [0.65, 0.1, 0.42], materials.red, [1.34, 1.65, 2.08], [0, -0.12, 0]);
// -------------------------------------------------------------------------
// Data: one unique tracked tool per entry
// -------------------------------------------------------------------------
const moduleDefinitions = {
repair: {
id: "repair",
name: "Repair Rail",
short: "REPAIR",
description: "Heavy-grip hooks",
color: 0x3f7068,
css: "#3f7068",
friction: 1.08
},
brush: {
id: "brush",
name: "Brush Rail",
short: "BRUSH",
description: "Soft retaining clips",
color: 0xc66d4e,
css: "#c66d4e",
friction: 0.94
},
precision: {
id: "precision",
name: "Precision Rail",
short: "PRECISION",
description: "Narrow open hooks",
color: 0x53678c,
css: "#53678c",
friction: 1.0
}
};
const toolDefinitions = [
{ id: "hammer", name: "Hammer", code: "HAM", module: "repair", x: -0.9 },
{ id: "pliers", name: "Pliers", code: "PLR", module: "repair", x: 0 },
{ id: "screwdriver", name: "Driver", code: "SCR", module: "repair", x: 0.9 },
{ id: "brush", name: "Brush", code: "BRS", module: "brush", x: -0.9 },
{ id: "roller", name: "Roller", code: "ROL", module: "brush", x: 0 },
{ id: "knife", name: "Palette knife", code: "KNF", module: "brush", x: 0.9 },
{ id: "tape", name: "Tape measure", code: "TPE", module: "precision", x: -0.9 },
{ id: "ruler", name: "Ruler", code: "RUL", module: "precision", x: 0 },
{ id: "pencil", name: "Pencil", code: "PEN", module: "precision", x: 0.9 }
];
const slotDefinitions = [
{ id: "A", label: "Mount A · high left", position: new THREE.Vector3(-3.55, 6.8, 0.4) },
{ id: "B", label: "Mount B · center", position: new THREE.Vector3(0, 5.82, 0.4) },
{ id: "C", label: "Mount C · low right", position: new THREE.Vector3(3.55, 4.86, 0.4) }
];
const state = {
slots: ["repair", "brush", "precision"],
selectedModule: "repair",
selectedTool: "hammer",
traceAll: false,
referencePinned: false
};
const modules = new Map();
const tools = new Map();
const interactiveMeshes = [];
// -------------------------------------------------------------------------
// Tool geometry
// -------------------------------------------------------------------------
function createTool(definition) {
const group = new THREE.Group();
group.name = definition.name;
group.userData.toolId = definition.id;
const handleMaterial = definition.module === "precision"
? materials.blue
: definition.module === "brush"
? materials.wood
: materials.teal;
switch (definition.id) {
case "hammer": {
addBox(group, [0.13, 0.84, 0.13], materials.wood, [0, -0.53, 0]);
addBox(group, [0.16, 0.38, 0.16], materials.dark, [0, -0.79, 0]);
addBox(group, [0.62, 0.22, 0.22], materials.metal, [0.03, -0.08, 0]);
addBox(group, [0.22, 0.15, 0.22], materials.metal, [0.31, -0.14, 0], [0, 0, 0.28]);
break;
}
case "pliers": {
addBox(group, [0.11, 0.72, 0.12], handleMaterial, [-0.09, -0.47, 0], [0, 0, -0.16]);
addBox(group, [0.11, 0.72, 0.12], handleMaterial, [0.09, -0.47, 0], [0, 0, 0.16]);
addBox(group, [0.1, 0.34, 0.13], materials.metal, [-0.055, -0.08, 0], [0, 0, -0.12]);
addBox(group, [0.1, 0.34, 0.13], materials.metal, [0.055, -0.08, 0], [0, 0, 0.12]);
addCylinder(group, 0.09, 0.09, 0.15, materials.brass, [0, -0.25, 0.03], [Math.PI / 2, 0, 0], 8);
break;
}
case "screwdriver": {
addBox(group, [0.09, 0.58, 0.09], materials.metal, [0, -0.26, 0]);
addCylinder(group, 0.13, 0.15, 0.48, handleMaterial, [0, -0.69, 0], [0, 0, 0], 8);
break;
}
case "brush": {
addBox(group, [0.12, 0.57, 0.12], handleMaterial, [0, -0.31, 0]);
addBox(group, [0.26, 0.16, 0.18], materials.metal, [0, -0.64, 0]);
addBox(group, [0.31, 0.32, 0.2], materials.cream, [0, -0.86, 0]);
addBox(group, [0.31, 0.08, 0.2], materials.red, [0, -1.02, 0]);
break;
}
case "roller": {
addBox(group, [0.1, 0.62, 0.1], handleMaterial, [0, -0.31, 0]);
addBox(group, [0.1, 0.28, 0.1], materials.metal, [0, -0.65, 0], [0, 0, 0.38]);
addCylinder(group, 0.18, 0.18, 0.62, materials.cream, [0.08, -0.77, 0], [0, 0, Math.PI / 2], 10);
addCylinder(group, 0.1, 0.1, 0.66, materials.metal, [0.08, -0.77, 0], [0, 0, Math.PI / 2], 8);
break;
}
case "knife": {
addBox(group, [0.14, 0.48, 0.14], handleMaterial, [0, -0.28, 0]);
addBox(group, [0.22, 0.46, 0.06], materials.metal, [0, 0.02, 0], [0, 0, 0.03]);
addBox(group, [0.24, 0.12, 0.07], materials.metal, [0, -0.16, 0]);
break;
}
case "tape": {
addBox(group, [0.58, 0.56, 0.22], handleMaterial, [0, -0.36, 0]);
addCylinder(group, 0.14, 0.14, 0.24, materials.cream, [0, -0.36, 0], [Math.PI / 2, 0, 0], 10);
addBox(group, [0.18, 0.09, 0.09], materials.metal, [0.19, -0.25, 0.12]);
break;
}
case "ruler": {
addBox(group, [0.22, 1.15, 0.1], materials.cream, [0, -0.65, 0]);
for (let index = 0; index < 6; index++) {
addBox(
group,
[0.13, 0.025, 0.015],
materials.dark,
[0.025, -0.23 - index * 0.16, 0.058]
);
}
break;
}
case "pencil": {
addCylinder(group, 0.075, 0.075, 0.95, materials.red, [0, -0.52, 0], [0, 0, 0], 6);
addCylinder(group, 0.08, 0.08, 0.18, materials.cream, [0, -0.08, 0], [0, 0, 0], 6);
addMesh(
group,
new THREE.ConeGeometry(0.075, 0.18, 6),
materials.wood,
[0, -1.08, 0],
[Math.PI, 0, 0]
);
break;
}
}
group.traverse((object) => {
if (object.isMesh) {
object.userData.toolId = definition.id;
interactiveMeshes.push(object);
}
});
return group;
}
// -------------------------------------------------------------------------
// Hook modules
// -------------------------------------------------------------------------
function createModule(definition) {
const group = new THREE.Group();
group.userData.moduleId = definition.id;
scene.add(group);
const railMaterial = new THREE.MeshStandardMaterial({
color: definition.color,
roughness: 0.72,
metalness: 0.08,
flatShading: true,
emissive: 0x000000,
emissiveIntensity: 0
});
const rail = addBox(group, [2.86, 0.22, 0.18], railMaterial, [0, 0, 0]);
rail.userData.moduleId = definition.id;
interactiveMeshes.push(rail);
addBox(group, [2.72, 0.08, 0.11], materials.dark, [0, 0.12, -0.04]);
const label = makeTextSprite(
`${definition.short} · 3 TOOLS`,
`#${definition.color.toString(16).padStart(6, "0")}`,
"#ffffff",
640
);
label.position.set(0, 0.57, 0.02);
label.scale.set(2.26, 0.48, 1);
group.add(label);
for (const x of [-0.9, 0, 0.9]) {
// L-shaped hook.
addBox(group, [0.08, 0.08, 0.31], materials.brass, [x, -0.16, 0.17]);
addBox(group, [0.08, 0.19, 0.08], materials.brass, [x, -0.08, 0.32]);
}
for (const toolDefinition of toolDefinitions.filter(
(tool) => tool.module === definition.id
)) {
const toolGroup = createTool(toolDefinition);
toolGroup.position.set(toolDefinition.x, -0.18, 0.36);
group.add(toolGroup);
tools.set(toolDefinition.id, {
...toolDefinition,
group: toolGroup,
anchorLocal: new THREE.Vector3(toolDefinition.x, -0.2, 0.68),
moduleId: definition.id
});
}
modules.set(definition.id, {
...definition,
group,
rail,
railMaterial
});
return modules.get(definition.id);
}
Object.values(moduleDefinitions).forEach(createModule);
function updateModulePositions() {
state.slots.forEach((moduleId, slotIndex) => {
modules.get(moduleId).group.position.copy(slotDefinitions[slotIndex].position);
});
scene.updateMatrixWorld(true);
}
updateModulePositions();
// -------------------------------------------------------------------------
// Worker and route origin
// -------------------------------------------------------------------------
const worker = new THREE.Group();
worker.position.set(-6.05, 0, 3.08);
workshop.add(worker);
const workerShirt = new THREE.MeshStandardMaterial({
color: 0x567b76,
roughness: 0.92,
flatShading: true
});
const workerPants = new THREE.MeshStandardMaterial({
color: 0x46505a,
roughness: 0.95,
flatShading: true
});
const skin = new THREE.MeshStandardMaterial({
color: 0xc88f68,
roughness: 0.9,
flatShading: true
});
addBox(worker, [0.27, 0.85, 0.3], workerPants, [-0.2, 0.5, 0]);
addBox(worker, [0.27, 0.85, 0.3], workerPants, [0.2, 0.5, 0]);
addBox(worker, [0.36, 0.16, 0.55], materials.dark, [-0.2, 0.08, -0.06]);
addBox(worker, [0.36, 0.16, 0.55], materials.dark, [0.2, 0.08, -0.06]);
addBox(worker, [0.78, 0.84, 0.42], workerShirt, [0, 1.27, 0]);
addBox(worker, [0.18, 0.66, 0.2], workerShirt, [-0.5, 1.33, 0], [0, 0, 0.12]);
addBox(worker, [0.18, 0.66, 0.2], workerShirt, [0.5, 1.48, -0.03], [0, 0, -0.28]);
addBox(worker, [0.17, 0.16, 0.17], skin, [0.58, 1.17, -0.03]);
addMesh(worker, new THREE.IcosahedronGeometry(0.27, 1), skin, [0, 1.94, 0]);
addCylinder(worker, 0.28, 0.3, 0.16, materials.red, [0, 2.13, 0], [0, 0, 0], 8);
addBox(worker, [0.42, 0.06, 0.28], materials.red, [0, 2.09, -0.22]);
const routeOrigin = new THREE.Vector3(-5.47, 1.17, 3.03);
const originMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.025, 5, 18),
new THREE.MeshBasicMaterial({ color: 0xd2734f })
);
originMarker.position.copy(routeOrigin);
workshop.add(originMarker);
const startLabel = makeTextSprite("START", "#d2734f", "#ffffff", 320);
startLabel.position.set(routeOrigin.x, routeOrigin.y + 0.42, routeOrigin.z);
startLabel.scale.set(0.88, 0.3, 1);
workshop.add(startLabel);
// -------------------------------------------------------------------------
// Routes and accessibility calculations
// -------------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
let selectedCurve = null;
let pulseMesh = null;
const baselineAnchors = new Map();
const referenceAnchors = new Map();
function getToolAnchor(tool) {
const module = modules.get(tool.moduleId);
return module.group.localToWorld(tool.anchorLocal.clone());
}
function captureBaseline() {
baselineAnchors.clear();
referenceAnchors.clear();
for (const tool of tools.values()) {
const anchor = getToolAnchor(tool);
baselineAnchors.set(tool.id, anchor.clone());
referenceAnchors.set(tool.id, anchor.clone());
}
state.referencePinned = false;
}
function routePoints(anchor) {
const target = anchor.clone();
const points = [routeOrigin.clone()];
// A waypoint keeps the path around the bench's left edge before it rises
// into the board aisle. This makes travel distance visibly meaningful.
if (target.x > -5.1) {
points.push(new THREE.Vector3(-5.28, routeOrigin.y, 2.35));
points.push(new THREE.Vector3(-5.28, target.y, 1.12));
points.push(new THREE.Vector3(target.x, target.y, 1.08));
} else {
points.push(new THREE.Vector3(target.x, routeOrigin.y, 1.12));
}
points.push(target);
return points;
}
function pathLength(points) {
let length = 0;
for (let index = 1; index < points.length; index++) {
length += points[index].distanceTo(points[index - 1]);
}
return length;
}
function computeMetrics(anchor, moduleId) {
const points = routePoints(anchor);
const travel = pathLength(points);
const reach = routeOrigin.distanceTo(anchor);
const peak = Math.max(...points.map((point) => point.y));
const module = modules.get(moduleId);
let score = 100;
score -= Math.max(0, travel - 4.5) * 3.5;
score -= Math.max(0, anchor.y - 7.0) * 6;
score -= Math.max(0, 3.65 - anchor.y) * 3;
score -= Math.max(0, Math.abs(anchor.x) - 4.0) * 2.4;
score -= (module.friction - 1) * 8;
return {
travel,
reach,
peak,
score: THREE.MathUtils.clamp(Math.round(score), 0, 100)
};
}
function disposeGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material.dispose();
}
}
});
}
}
function makeCurve(points) {
return new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.06);
}
function addCurrentRoute(anchor, strong = true) {
const points = routePoints(anchor);
const curve = makeCurve(points);
const color = new THREE.Color(0x28796e);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(
curve,
Math.max(32, points.length * 10),
strong ? 0.035 : 0.018,
5,
false
),
new THREE.MeshBasicMaterial({
color,
transparent: !strong,
opacity: strong ? 1 : 0.34
})
);
routeGroup.add(tube);
const endpoint = new THREE.Mesh(
new THREE.SphereGeometry(strong ? 0.075 : 0.045, 8, 6),
new THREE.MeshBasicMaterial({
color,
transparent: !strong,
opacity: strong ? 1 : 0.5
})
);
endpoint.position.copy(anchor);
routeGroup.add(endpoint);
return curve;
}
function addReferenceRoute(anchor) {
const offsetAnchor = anchor.clone();
offsetAnchor.z += 0.075;
const points = routePoints(offsetAnchor);
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color: 0xd2734f,
dashSize: 0.14,
gapSize: 0.09,
transparent: true,
opacity: 0.9
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
routeGroup.add(line);
const endpoint = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 8, 6),
new THREE.MeshBasicMaterial({ color: 0xd2734f })
);
endpoint.position.copy(offsetAnchor);
routeGroup.add(endpoint);
}
function drawSelectedRoute() {
disposeGroup(routeGroup);
selectedCurve = null;
pulseMesh = null;
if (state.traceAll) {
for (const tool of tools.values()) {
addCurrentRoute(getToolAnchor(tool), false);
}
}
const tool = tools.get(state.selectedTool);
const currentAnchor = getToolAnchor(tool);
const referenceAnchor = referenceAnchors.get(tool.id);
selectedCurve = addCurrentRoute(currentAnchor, true);
if (currentAnchor.distanceTo(referenceAnchor) > 0.035) {
addReferenceRoute(referenceAnchor);
}
const targetRing = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.018, 5, 22),
new THREE.MeshBasicMaterial({ color: 0x28796e })
);
targetRing.position.copy(currentAnchor);
routeGroup.add(targetRing);
pulseMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.085, 10, 8),
new THREE.MeshBasicMaterial({ color: 0xf6d46f })
);
routeGroup.add(pulseMesh);
updateRouteInspector();
}
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const moduleList = document.getElementById("moduleList");
const toolList = document.getElementById("toolList");
const toast = document.getElementById("toast");
let toastTimer = null;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2600);
}
for (const definition of Object.values(moduleDefinitions)) {
const button = document.createElement("button");
button.className = "module-card";
button.dataset.module = definition.id;
button.innerHTML = `
<span class="module-swatch" style="background:${definition.css}">
${definition.short.slice(0, 2)}
</span>
<span class="module-copy">
<strong>${definition.name}</strong>
<small>${definition.description}</small>
</span>
<span class="module-count">3 TOOLS</span>
`;
button.addEventListener("click", () => {
state.selectedModule = definition.id;
updateUI();
showToast(`${definition.name} selected. Choose a mount to swap it into.`);
});
moduleList.appendChild(button);
}
for (const definition of toolDefinitions) {
const button = document.createElement("button");
button.className = "tool-button";
button.dataset.tool = definition.id;
button.style.setProperty(
"--tool-color",
moduleDefinitions[definition.module].css
);
button.title = definition.name;
button.innerHTML = `
<span class="tool-mount"></span>
<span class="tool-code">${definition.code}</span>
<span class="tool-name">${definition.name}</span>
`;
button.addEventListener("click", () => {
state.selectedTool = definition.id;
drawSelectedRoute();
updateUI();
});
toolList.appendChild(button);
}
document.querySelectorAll(".slot-button").forEach((button) => {
button.addEventListener("click", () => {
swapSelectedModule(Number(button.dataset.slot));
});
});
document.getElementById("resetLayout").addEventListener("click", () => {
state.slots = ["repair", "brush", "precision"];
state.selectedModule = "repair";
state.selectedTool = "hammer";
state.traceAll = false;
updateModulePositions();
captureBaseline();
drawSelectedRoute();
updateUI();
showToast("Original layout restored. Baseline reference updated.");
});
document.getElementById("traceAll").addEventListener("click", () => {
state.traceAll = !state.traceAll;
drawSelectedRoute();
updateUI();
showToast(
state.traceAll
? "All nine retrieval routes are visible."
: "Showing the selected tool route only."
);
});
document.getElementById("pinReference").addEventListener("click", () => {
referenceAnchors.clear();
for (const tool of tools.values()) {
referenceAnchors.set(tool.id, getToolAnchor(tool));
}
state.referencePinned = true;
drawSelectedRoute();
updateUI();
showToast("Current positions pinned as the comparison reference.");
});
document.getElementById("cameraReset").addEventListener("click", resetCamera);
function swapSelectedModule(targetSlot) {
const sourceId = state.selectedModule;
const sourceSlot = state.slots.indexOf(sourceId);
if (sourceSlot === targetSlot) {
showToast(`${modules.get(sourceId).name} is already in ${slotDefinitions[targetSlot].id}.`);
return;
}
const targetId = state.slots[targetSlot];
state.slots[sourceSlot] = targetId;
state.slots[targetSlot] = sourceId;
updateModulePositions();
drawSelectedRoute();
updateUI();
showToast(
`${modules.get(sourceId).name} swapped with ${modules.get(targetId).name}. ` +
"All nine tools remain unique."
);
}
function updateRouteInspector() {
const tool = tools.get(state.selectedTool);
const currentAnchor = getToolAnchor(tool);
const referenceAnchor = referenceAnchors.get(tool.id);
const current = computeMetrics(currentAnchor, tool.moduleId);
const reference = computeMetrics(referenceAnchor, tool.moduleId);
const difference = current.score - reference.score;
document.getElementById("selectedToolName").textContent = tool.name;
document.getElementById("selectedToolMeta").textContent =
`${modules.get(tool.moduleId).name} · ${modules.get(tool.moduleId).description}`;
const currentSlot = state.slots.indexOf(tool.moduleId);
document.getElementById("selectedMount").textContent =
`MOUNT ${slotDefinitions[currentSlot].id}`;
document.getElementById("currentScore").textContent = current.score;
document.getElementById("referenceScore").textContent = reference.score;
document.getElementById("currentScoreBar").style.width = `${current.score}%`;
document.getElementById("referenceScoreBar").style.width = `${reference.score}%`;
document.getElementById("currentTravel").textContent = `${current.travel.toFixed(1)} m`;
document.getElementById("referenceTravel").textContent = `${reference.travel.toFixed(1)} m`;
document.getElementById("currentReach").textContent = `${current.reach.toFixed(1)} m`;
document.getElementById("referenceReach").textContent = `${reference.reach.toFixed(1)} m`;
document.getElementById("currentHeight").textContent = `${current.peak.toFixed(1)} m`;
document.getElementById("referenceHeight").textContent = `${reference.peak.toFixed(1)} m`;
document.getElementById("referenceLabel").textContent = state.referencePinned
? "Pinned"
: "Baseline";
let insight;
if (difference > 3) {
insight = `Improved by ${difference} points. This position shortens the retrieval path and reduces the lift.`;
} else if (difference < -3) {
insight = `Reduced by ${Math.abs(difference)} points. The new position adds travel or places the grip farther from the ideal working height.`;
} else {
insight = "Accessibility is effectively unchanged. Travel and working height remain close to the reference position.";
}
document.getElementById("routeInsight").textContent = insight;
}
function updateUI() {
document.querySelectorAll(".module-card").forEach((button) => {
button.classList.toggle("active", button.dataset.module === state.selectedModule);
});
state.slots.forEach((moduleId, slotIndex) => {
document.getElementById(`slotName${slotIndex}`).textContent =
modules.get(moduleId).name;
});
document.querySelectorAll(".tool-button").forEach((button) => {
const tool = tools.get(button.dataset.tool);
const slot = state.slots.indexOf(tool.moduleId);
button.classList.toggle("active", tool.id === state.selectedTool);
button.querySelector(".tool-mount").textContent = slotDefinitions[slot].id;
});
for (const module of modules.values()) {
const selected = module.id === state.selectedModule;
module.railMaterial.emissive.setHex(selected ? 0x234f49 : 0x000000);
module.railMaterial.emissiveIntensity = selected ? 0.34 : 0;
}
const traceButton = document.getElementById("traceAll");
traceButton.classList.toggle("active", state.traceAll);
traceButton.textContent = state.traceAll ? "Hide all" : "Trace all";
document.getElementById("pinReference").textContent = state.referencePinned
? "Re-pin current positions"
: "Pin current positions as reference";
}
// -------------------------------------------------------------------------
// Scene picking and direct camera controls
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let dragged = false;
function getAncestorValue(object, key) {
while (object) {
if (object.userData[key] !== undefined) {
return object.userData[key];
}
object = object.parent;
}
return undefined;
}
function pickScene(clientX, clientY) {
const bounds = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y = -((clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(interactiveMeshes, false);
for (const intersection of intersections) {
const toolId = getAncestorValue(intersection.object, "toolId");
if (toolId) {
state.selectedTool = toolId;
drawSelectedRoute();
updateUI();
return;
}
const moduleId = getAncestorValue(intersection.object, "moduleId");
if (moduleId) {
if (moduleId !== state.selectedModule) {
const targetSlot = state.slots.indexOf(moduleId);
swapSelectedModule(targetSlot);
} else {
updateUI();
}
return;
}
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = {
x: event.clientX,
y: event.clientY,
pointerId: event.pointerId
};
dragged = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) {
raycaster.setFromCamera(pointer, camera);
return;
}
const deltaX = event.clientX - pointerDown.x;
const deltaY = event.clientY - pointerDown.y;
if (Math.abs(deltaX) + Math.abs(deltaY) > 4) {
dragged = true;
}
if (dragged) {
cameraState.theta -= deltaX * 0.0055;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + deltaY * 0.0045,
0.98,
1.47
);
applyCamera();
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragged && pointerDown) {
pickScene(event.clientX, event.clientY);
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
pointerDown = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
dragged = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
10.5,
23
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") {
cameraState.theta -= 0.08;
applyCamera();
} else if (event.key === "ArrowRight") {
cameraState.theta += 0.08;
applyCamera();
} else if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.98, cameraState.phi - 0.06);
applyCamera();
} else if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.47, cameraState.phi + 0.06);
applyCamera();
} else if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(10.5, cameraState.radius - 0.7);
applyCamera();
} else if (event.key === "-") {
cameraState.radius = Math.min(23, cameraState.radius + 0.7);
applyCamera();
} else if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
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 and initialization
// -------------------------------------------------------------------------
captureBaseline();
drawSelectedRoute();
updateUI();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
if (pulseMesh && selectedCurve) {
const progress = (elapsed * 0.12) % 1;
pulseMesh.position.copy(selectedCurve.getPointAt(progress));
pulseMesh.scale.setScalar(0.9 + Math.sin(elapsed * 6) * 0.16);
}
originMarker.rotation.z = elapsed * 0.35;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
loading.classList.add("hidden");
</script>
</body>
</html>
```