Prompt specification
Build or customize the Three.js 3D scene "Neighborhood Repair Cafe Diorama" 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: Neighborhood Repair Cafe Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-repair-cafe-diorama-x3959
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Build an original repair cafe with intake, workbenches, spare parts, and returned objects. Show several simple repair pathways without instructions for hazardous electrical or mechanical work.
Working Three.js Starter (neighborhood-repair-cafe-diorama-x3959):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#163c3b">
<title>Mend Commons — Voxel Repair Café</title>
<style>
:root {
--ink: #173a38;
--paper: #fffaf0;
--paper-soft: rgba(255, 250, 240, 0.92);
--teal: #24766f;
--coral: #e76f51;
--blue: #4d8fac;
--gold: #d9a441;
--purple: #8e6bb3;
--shadow: 0 14px 40px rgba(23, 58, 56, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfe5df;
color: var(--ink);
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;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #cfe5df;
transition: opacity 0.45s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-card {
padding: 18px 24px;
border: 3px solid var(--ink);
background: var(--paper);
box-shadow: 7px 7px 0 rgba(23, 58, 56, 0.18);
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
max-width: 440px;
padding: 19px 22px 18px;
border: 2px solid rgba(23, 58, 56, 0.18);
border-radius: 18px;
background: var(--paper-soft);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--coral);
content: "";
transform: rotate(15deg);
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 52px);
line-height: 0.95;
letter-spacing: -0.055em;
}
.brand p {
max-width: 370px;
margin: 11px 0 0;
color: #496664;
font-size: 13px;
line-height: 1.45;
}
.pathways {
position: absolute;
top: 24px;
right: 24px;
width: 245px;
padding: 15px;
border: 2px solid rgba(23, 58, 56, 0.17);
border-radius: 18px;
background: var(--paper-soft);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 2px 11px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.count {
padding: 4px 7px;
border-radius: 999px;
background: rgba(36, 118, 111, 0.12);
color: var(--teal);
font-size: 10px;
}
.path-list {
display: grid;
gap: 7px;
}
.path-button {
display: grid;
grid-template-columns: 11px 1fr auto;
align-items: center;
gap: 9px;
width: 100%;
min-height: 38px;
padding: 9px 10px;
border: 1px solid rgba(23, 58, 56, 0.12);
border-radius: 11px;
background: rgba(255, 255, 255, 0.6);
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
transform 0.16s ease,
background 0.16s ease,
border-color 0.16s ease;
}
.path-button:hover {
transform: translateX(-2px);
border-color: rgba(23, 58, 56, 0.3);
background: white;
}
.path-button.active {
border-color: var(--ink);
background: white;
box-shadow: 3px 3px 0 rgba(23, 58, 56, 0.13);
transform: translateX(-2px);
}
.path-dot {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--dot);
transform: rotate(15deg);
}
.path-name {
font-size: 12px;
font-weight: 760;
}
.path-number {
color: #78908d;
font-size: 10px;
font-weight: 800;
}
.detail {
position: absolute;
right: 24px;
bottom: 24px;
width: min(375px, calc(100vw - 48px));
padding: 20px;
border: 2px solid rgba(23, 58, 56, 0.17);
border-radius: 20px;
background: var(--paper-soft);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.detail-top {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.detail-kicker {
color: var(--accent, var(--teal));
font-size: 10px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent, var(--teal));
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent, var(--teal)) 14%, transparent);
}
.detail h2 {
margin: 0;
font-size: 25px;
letter-spacing: -0.035em;
}
.detail p {
margin: 9px 0 13px;
color: #526e6b;
font-size: 13px;
line-height: 1.5;
}
.stages {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 13px;
}
.stage {
padding: 6px 9px;
border: 1px solid rgba(23, 58, 56, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.7);
color: #385956;
font-size: 10px;
font-weight: 780;
}
.safety {
padding: 10px 11px;
border-left: 4px solid var(--coral);
border-radius: 5px 10px 10px 5px;
background: rgba(231, 111, 81, 0.08);
color: #6b4a42;
font-size: 11px;
line-height: 1.45;
}
.controls {
position: absolute;
bottom: 24px;
left: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: 330px;
}
.control {
padding: 9px 12px;
border: 1px solid rgba(23, 58, 56, 0.15);
border-radius: 999px;
background: var(--paper-soft);
box-shadow: 0 8px 24px rgba(23, 58, 56, 0.12);
color: #496664;
font-size: 10px;
font-weight: 780;
backdrop-filter: blur(10px);
}
.control strong {
color: var(--ink);
}
.scene-note {
position: absolute;
right: 28px;
bottom: 25px;
display: none;
}
@media (max-width: 850px) {
.brand {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 13px 15px;
}
.brand p {
display: none;
}
.pathways {
top: 112px;
right: 12px;
width: 185px;
padding: 10px;
}
.path-button {
min-height: 32px;
padding: 7px 8px;
}
.path-number {
display: none;
}
.detail {
right: 12px;
bottom: 12px;
width: min(340px, calc(100vw - 24px));
padding: 15px;
}
.detail h2 {
font-size: 21px;
}
.detail p {
font-size: 12px;
}
.controls {
bottom: auto;
top: 112px;
left: 12px;
max-width: 145px;
}
.control {
padding: 7px 9px;
}
}
@media (max-width: 560px) {
h1 {
font-size: 29px;
}
.eyebrow {
font-size: 9px;
}
.pathways {
top: auto;
right: 8px;
bottom: 8px;
left: 8px;
width: auto;
}
.path-list {
grid-template-columns: repeat(5, 1fr);
gap: 4px;
}
.path-button {
display: flex;
justify-content: center;
min-height: 28px;
padding: 7px 4px;
}
.path-name,
.panel-title {
display: none;
}
.detail {
right: 8px;
bottom: 72px;
width: calc(100vw - 16px);
}
.controls {
display: none;
}
.detail p {
margin: 6px 0 9px;
}
.safety {
padding: 7px 9px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="loading">
<div class="loading-card">Opening the repair café</div>
</div>
<main class="hud">
<header class="brand">
<div class="eyebrow">Neighborhood repair café</div>
<h1>Mend Commons</h1>
<p>
A welcoming voxel workshop for sharing skills, tracing repair pathways,
and returning useful objects to their owners.
</p>
</header>
<nav class="pathways" aria-label="Repair pathways">
<div class="panel-title">
Repair pathways
<span class="count">4 safe routes</span>
</div>
<div class="path-list">
<button class="path-button active" data-path="all" style="--dot:#24766f">
<span class="path-dot"></span>
<span class="path-name">All routes</span>
<span class="path-number">00</span>
</button>
<button class="path-button" data-path="textile" style="--dot:#e76f51">
<span class="path-dot"></span>
<span class="path-name">Textile mend</span>
<span class="path-number">01</span>
</button>
<button class="path-button" data-path="appliance" style="--dot:#4d8fac">
<span class="path-dot"></span>
<span class="path-name">Enclosed items</span>
<span class="path-number">02</span>
</button>
<button class="path-button" data-path="furniture" style="--dot:#d9a441">
<span class="path-dot"></span>
<span class="path-name">Light furniture</span>
<span class="path-number">03</span>
</button>
<button class="path-button" data-path="toys" style="--dot:#8e6bb3">
<span class="path-dot"></span>
<span class="path-name">Toys & games</span>
<span class="path-number">04</span>
</button>
</div>
</nav>
<article class="detail" id="detail" aria-live="polite">
<div class="detail-top">
<span class="status-dot"></span>
<span class="detail-kicker" id="detail-kicker">Start here</span>
</div>
<h2 id="detail-title">Intake & triage</h2>
<p id="detail-copy">
Every object begins with a friendly check-in, a short description of its
history, and a safe pathway recommendation.
</p>
<div class="stages" id="stages"></div>
<div class="safety">
Low-risk scope only. Powered, heated, sharp, moving, structural, or
unknown items are referred—not opened or repaired here.
</div>
</article>
<div class="controls" aria-hidden="true">
<div class="control"><strong>Drag</strong> orbit</div>
<div class="control"><strong>Scroll</strong> zoom</div>
<div class="control"><strong>Click</strong> a station</div>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const container = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfe5df);
scene.fog = new THREE.Fog(0xcfe5df, 31, 57);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel repair café. Drag to orbit, scroll to zoom, and click stations."
);
container.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf0fbff, 0x718263, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d1, 3.25);
sun.position.set(-9, 16, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9dce7, 0.7);
fill.position.set(10, 8, -9);
scene.add(fill);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
const M = {
grass: material(0x8fb77a),
grassDark: material(0x719864),
cream: material(0xf5ead5),
creamLight: material(0xfff8e9),
teal: material(0x24766f),
tealDark: material(0x185a57),
tealLight: material(0x64aaa0),
coral: material(0xe76f51),
coralLight: material(0xf2a17f),
blue: material(0x4d8fac),
blueLight: material(0x91bed0),
gold: material(0xd9a441),
goldLight: material(0xf1c96e),
purple: material(0x8e6bb3),
purpleLight: material(0xb69bd0),
wood: material(0xb77b4a),
woodDark: material(0x805032),
woodLight: material(0xd6a36a),
ink: material(0x173a38),
charcoal: material(0x31413f),
white: material(0xfffaf0),
pink: material(0xeaa6a1),
skin: material(0xc98768),
skinLight: material(0xe4b08c),
brick: material(0xb96f54),
plant: material(0x4d8b55),
plantLight: material(0x75a85f),
soil: material(0x554338),
lamp: material(0xfff1a8, {
emissive: 0xffd56a,
emissiveIntensity: 1.1
})
};
function box(
parent,
x,
y,
z,
width,
height,
depth,
mat,
options = {}
) {
const mesh = new THREE.Mesh(cubeGeometry, mat);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function group(parent, x = 0, y = 0, z = 0) {
const result = new THREE.Group();
result.position.set(x, y, z);
parent.add(result);
return result;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.needsUpdate = true;
return texture;
}
function stationLabel(text, accent) {
const texture = makeTexture(640, 150, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
roundedRect(ctx, 4, 4, w - 8, h - 8, 24);
ctx.fillStyle = "rgba(255,250,240,0.96)";
ctx.fill();
ctx.strokeStyle = "#173a38";
ctx.lineWidth = 7;
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 24, 27, 18, h - 54, 6);
ctx.fill();
ctx.fillStyle = "#173a38";
ctx.font = "800 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text.toUpperCase(), w / 2 + 8, h / 2 + 1);
});
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.65, 0.86, 1);
sprite.renderOrder = 10;
return sprite;
}
function frontLabel(parent, text, x, y, z, width, height, accent = "#24766f") {
const texture = makeTexture(512, 128, (ctx, w, h) => {
roundedRect(ctx, 3, 3, w - 6, h - 6, 18);
ctx.fillStyle = "#fffaf0";
ctx.fill();
ctx.strokeStyle = "#173a38";
ctx.lineWidth = 7;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(18, 19, 14, h - 38);
ctx.fillStyle = "#173a38";
ctx.font = "800 34px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text.toUpperCase(), w / 2 + 7, h / 2);
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true
})
);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function largeWallSign() {
const texture = makeTexture(1200, 300, (ctx, w, h) => {
ctx.fillStyle = "#fff8e9";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#24766f";
ctx.fillRect(0, 0, 30, h);
ctx.fillRect(w - 30, 0, 30, h);
ctx.fillStyle = "#e76f51";
ctx.fillRect(55, 47, 55, 55);
ctx.fillStyle = "#d9a441";
ctx.fillRect(126, 47, 55, 55);
ctx.fillStyle = "#4d8fac";
ctx.fillRect(197, 47, 55, 55);
ctx.fillStyle = "#173a38";
ctx.font = "900 88px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("MEND COMMONS", w / 2, 132);
ctx.fillStyle = "#4d6f6b";
ctx.font = "700 29px system-ui, sans-serif";
ctx.fillText(
"REPAIR CAFÉ • SHARE SKILLS • KEEP THINGS IN USE",
w / 2,
225
);
});
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(9.7, 2.42),
new THREE.MeshBasicMaterial({ map: texture })
);
sign.position.set(0, 4.38, -8.27);
scene.add(sign);
}
// ------------------------------------------------------------
// Ground, workshop shell, and decorations
// ------------------------------------------------------------
box(scene, 0, -0.62, 0, 28, 1.2, 22, M.grass, {
castShadow: false
});
const tileMaterials = [
material(0xd8d1bc),
material(0xcfc8b3),
material(0xe1dac7),
material(0xc9c4b3)
];
const tileSize = 1.22;
const cols = 18;
const rows = 12;
for (let ix = 0; ix < cols; ix++) {
for (let iz = 0; iz < rows; iz++) {
const x = (ix - (cols - 1) / 2) * tileSize;
const z = (iz - (rows - 1) / 2) * tileSize - 0.15;
const mat = tileMaterials[(ix * 3 + iz * 5) % tileMaterials.length];
box(scene, x, 0.06, z, 1.16, 0.12, 1.16, mat, {
castShadow: false
});
}
}
// Back wall and open timber frame.
box(scene, 0, 2.78, -8.55, 22.5, 5.35, 0.42, M.creamLight);
box(scene, 0, 0.87, -8.28, 22.3, 1.55, 0.12, M.teal);
box(scene, 0, 5.55, -8.18, 23, 0.28, 0.65, M.tealDark);
for (const x of [-11.05, -7.35, 7.35, 11.05]) {
box(scene, x, 3.05, -8.02, 0.38, 5.9, 0.62, M.woodDark);
}
for (const x of [-11.05, 11.05]) {
box(scene, x, 3.05, 7.45, 0.42, 5.85, 0.42, M.woodDark);
box(scene, x, 6.02, -0.25, 0.5, 0.5, 15.8, M.woodDark);
}
box(scene, 0, 6.02, -8.05, 22.5, 0.5, 0.55, M.woodDark);
box(scene, 0, 6.02, 7.45, 22.5, 0.5, 0.55, M.woodDark);
largeWallSign();
// Voxel bunting.
const flagColors = [M.coral, M.gold, M.blue, M.purple, M.tealLight];
for (let i = 0; i < 18; i++) {
const x = -9.8 + i * 1.15;
const y = 5.05 - Math.abs(i - 8.5) * 0.035;
box(scene, x, y, -8.18, 0.34, 0.42, 0.12, flagColors[i % flagColors.length]);
}
// Small hanging bulbs around the open front.
for (let i = 0; i < 12; i++) {
const x = -7.8 + i * 1.42;
const y = 5.35 - Math.sin((i / 11) * Math.PI) * 0.55;
box(scene, x, y, 7.12, 0.12, 0.12, 0.12, M.lamp, {
castShadow: false
});
}
function createPlanter(parent, x, z, size = 1) {
const planter = group(parent, x, 0, z);
box(planter, 0, 0.42, 0, 0.72 * size, 0.72 * size, 0.72 * size, M.coral);
box(planter, 0, 0.8 * size, 0, 0.78 * size, 0.12 * size, 0.78 * size, M.woodDark);
box(planter, 0, 0.87 * size, 0, 0.62 * size, 0.08 * size, 0.62 * size, M.soil);
box(
planter,
-0.18 * size,
1.15 * size,
0,
0.34 * size,
0.65 * size,
0.34 * size,
M.plant
);
box(
planter,
0.18 * size,
1.08 * size,
0.04 * size,
0.36 * size,
0.5 * size,
0.35 * size,
M.plantLight
);
box(
planter,
0,
1.43 * size,
-0.03 * size,
0.28 * size,
0.4 * size,
0.3 * size,
M.plant
);
return planter;
}
function createTree(x, z, scale = 1) {
const tree = group(scene, x, 0, z);
box(tree, 0, 1.15 * scale, 0, 0.55 * scale, 2.3 * scale, 0.55 * scale, M.woodDark);
box(tree, 0, 2.65 * scale, 0, 1.8 * scale, 1.25 * scale, 1.55 * scale, M.plant);
box(tree, -0.6 * scale, 3.2 * scale, 0.1 * scale, 1.15 * scale, 1.05 * scale, 1.2 * scale, M.plantLight);
box(tree, 0.7 * scale, 2.75 * scale, -0.15 * scale, 1.05 * scale, 1.2 * scale, 1.15 * scale, M.grassDark);
}
createTree(-12.3, -7.8, 1.2);
createTree(12.3, -7.7, 1.35);
createTree(-12.5, 6.9, 1.05);
createTree(12.5, 7.2, 1.1);
createPlanter(scene, -10.2, 6.8, 1.15);
createPlanter(scene, 10.1, 6.9, 1.05);
// Front stepping stones.
for (let i = 0; i < 5; i++) {
box(
scene,
-0.8 + i * 0.1,
0.07,
10.1 + i * 1.05,
1.25,
0.14,
0.74,
tileMaterials[(i + 1) % tileMaterials.length],
{ castShadow: false }
);
}
// ------------------------------------------------------------
// People and furnishing helpers
// ------------------------------------------------------------
function createPerson(parent, x, z, shirt, skin = M.skin, hair = M.ink) {
const person = group(parent, x, 0, z);
box(person, -0.18, 0.48, 0, 0.3, 0.9, 0.35, M.charcoal);
box(person, 0.18, 0.48, 0, 0.3, 0.9, 0.35, M.charcoal);
box(person, 0, 1.15, 0, 0.82, 0.82, 0.48, shirt);
box(person, 0, 1.88, 0, 0.65, 0.65, 0.62, skin);
box(person, 0, 2.13, -0.02, 0.7, 0.2, 0.66, hair);
box(person, -0.54, 1.15, 0, 0.25, 0.72, 0.3, shirt);
box(person, 0.54, 1.15, 0, 0.25, 0.72, 0.3, shirt);
box(person, -0.54, 0.72, 0.02, 0.23, 0.2, 0.27, skin);
box(person, 0.54, 0.72, 0.02, 0.23, 0.2, 0.27, skin);
return person;
}
function createTable(parent, width = 4, depth = 2, topMaterial = M.woodLight) {
const table = group(parent);
box(table, 0, 1.37, 0, width, 0.2, depth, topMaterial);
box(table, 0, 0.69, -depth / 2 + 0.22, width - 0.5, 1.25, 0.18, M.woodDark);
box(table, 0, 0.69, depth / 2 - 0.22, width - 0.5, 1.25, 0.18, M.woodDark);
box(table, -width / 2 + 0.25, 0.69, 0, 0.18, 1.25, depth - 0.5, M.woodDark);
box(table, width / 2 - 0.25, 0.69, 0, 0.18, 1.25, depth - 0.5, M.woodDark);
box(table, 0, 0.7, 0, width - 0.75, 0.16, depth - 0.65, M.wood);
return table;
}
function createShelf(parent, width, levels = 4) {
const shelf = group(parent);
const side = width / 2 - 0.12;
box(shelf, -side, 1.95, 0, 0.22, 3.9, 1.35, M.woodDark);
box(shelf, side, 1.95, 0, 0.22, 3.9, 1.35, M.woodDark);
box(shelf, 0, 3.88, 0, width, 0.2, 1.35, M.wood);
for (let i = 0; i < levels; i++) {
const y = 0.42 + i * 1.02;
box(shelf, 0, y, 0, width, 0.16, 1.35, M.woodLight);
}
box(shelf, 0, 1.95, -0.62, width - 0.35, 3.8, 0.12, M.cream);
return shelf;
}
function createMug(parent, x, y, z, color = M.coral) {
box(parent, x, y + 0.19, z, 0.32, 0.38, 0.32, color);
box(parent, x + 0.23, y + 0.2, z, 0.12, 0.22, 0.12, color);
box(parent, x, y + 0.39, z, 0.25, 0.035, 0.25, M.woodDark);
}
// ------------------------------------------------------------
// Station registry and UI information
// ------------------------------------------------------------
const stationRoots = [];
const stationInfo = {};
const halos = {};
function registerStation({
id,
root,
label,
accent,
x,
z,
size,
kicker,
title,
copy,
stages
}) {
root.userData.station = id;
stationRoots.push(root);
stationInfo[id] = {
id,
accent,
x,
z,
kicker,
title,
copy,
stages
};
const text = stationLabel(label, accent);
text.position.set(0, root.userData.labelHeight ?? 3.25, 0);
root.add(text);
const haloMaterial = new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.85,
depthWrite: false
});
const halo = group(scene, x, 0.18, z);
const [w, d] = size;
box(halo, 0, 0, -d / 2, w, 0.035, 0.075, haloMaterial, {
castShadow: false,
receiveShadow: false
});
box(halo, 0, 0, d / 2, w, 0.035, 0.075, haloMaterial, {
castShadow: false,
receiveShadow: false
});
box(halo, -w / 2, 0, 0, 0.075, 0.035, d, haloMaterial, {
castShadow: false,
receiveShadow: false
});
box(halo, w / 2, 0, 0, 0.075, 0.035, d, haloMaterial, {
castShadow: false,
receiveShadow: false
});
halo.visible = false;
halos[id] = halo;
}
// ------------------------------------------------------------
// Intake station
// ------------------------------------------------------------
const intake = group(scene, -8.1, 0, 3.7);
box(intake, 0, 0.82, 0, 3.6, 1.5, 1.45, M.teal);
box(intake, 0, 1.62, 0, 3.95, 0.18, 1.75, M.woodLight);
box(intake, 0, 0.75, 0.74, 3.2, 0.18, 0.08, M.tealDark);
box(intake, -1.15, 1.88, 0.1, 0.65, 0.35, 0.48, M.charcoal);
box(intake, -1.15, 1.9, 0.36, 0.5, 0.21, 0.04, M.blueLight);
box(intake, 0.65, 1.81, 0.05, 0.72, 0.08, 0.95, M.coralLight);
box(intake, 0.65, 1.86, 0.05, 0.56, 0.025, 0.76, M.white);
createMug(intake, 1.35, 1.72, -0.25, M.gold);
createPlanter(intake, -1.38, -0.05, 0.52);
createPerson(intake, -0.1, -1.12, M.coral, M.skinLight, M.woodDark);
intake.userData.labelHeight = 3.45;
registerStation({
id: "intake",
root: intake,
label: "01 / Intake",
accent: "#24766f",
x: -8.1,
z: 3.7,
size: [4.4, 2.5],
kicker: "Start here",
title: "Intake & triage",
copy:
"Every object begins with a friendly check-in, a short description of its history, and a safe pathway recommendation.",
stages: ["Check-in", "Item story", "Safe pathway"]
});
// ------------------------------------------------------------
// Textile mend station
// ------------------------------------------------------------
const textile = group(scene, -4.25, 0, 0.55);
const textileTable = createTable(textile, 4.25, 2.15, M.woodLight);
// Fabric pile.
box(textileTable, -1.35, 1.56, -0.35, 1.1, 0.16, 0.85, M.coral);
box(textileTable, -1.28, 1.69, -0.31, 0.92, 0.13, 0.7, M.pink);
box(textileTable, -1.4, 1.81, -0.29, 0.78, 0.1, 0.6, M.purpleLight);
// Closed, simple sewing-machine silhouette.
box(textileTable, 0.35, 1.64, -0.12, 1.3, 0.25, 0.78, M.charcoal);
box(textileTable, 0.88, 1.97, -0.12, 0.28, 0.7, 0.42, M.charcoal);
box(textileTable, 0.38, 2.25, -0.12, 1.1, 0.22, 0.42, M.charcoal);
box(textileTable, -0.08, 2.02, -0.12, 0.08, 0.42, 0.08, M.white);
// Thread spools.
for (let i = 0; i < 3; i++) {
box(textileTable, 1.25 + i * 0.28, 1.73, 0.5, 0.2, 0.28, 0.2, [
M.coral,
M.gold,
M.blue
][i]);
box(textileTable, 1.25 + i * 0.28, 1.9, 0.5, 0.13, 0.06, 0.13, M.woodDark);
}
createPerson(textile, -0.4, -1.55, M.teal, M.skin, M.ink);
textile.userData.labelHeight = 3.5;
registerStation({
id: "textile",
root: textile,
label: "02 / Textile mend",
accent: "#e76f51",
x: -4.25,
z: 0.55,
size: [4.8, 2.8],
kicker: "Repair pathway 01",
title: "Textile mend",
copy:
"Visible fabric damage is assessed, patched, stitched, and finished with simple reusable materials.",
stages: ["Assess", "Patch", "Stitch & finish"]
});
// ------------------------------------------------------------
// Enclosed-item triage station
// ------------------------------------------------------------
const appliance = group(scene, 0.85, 0, 0.6);
const applianceTable = createTable(appliance, 4.3, 2.1, M.creamLight);
// Closed radio.
box(applianceTable, -1.25, 1.85, -0.05, 1.15, 0.72, 0.65, M.blue);
box(applianceTable, -1.25, 1.9, 0.3, 0.8, 0.3, 0.04, M.charcoal);
for (let i = 0; i < 4; i++) {
box(applianceTable, -1.54 + i * 0.19, 1.9, 0.34, 0.1, 0.1, 0.035, M.goldLight);
}
box(applianceTable, -0.89, 1.7, 0.34, 0.13, 0.13, 0.035, M.white);
// Closed table lamp.
box(applianceTable, 0.25, 1.55, -0.2, 0.65, 0.13, 0.65, M.teal);
box(applianceTable, 0.25, 1.87, -0.2, 0.13, 0.55, 0.13, M.teal);
box(applianceTable, 0.25, 2.15, -0.2, 0.85, 0.42, 0.65, M.gold);
// External check cards.
for (let i = 0; i < 3; i++) {
box(applianceTable, 1.25, 1.52 + i * 0.04, 0.05, 0.72, 0.03, 0.9, M.white);
}
box(applianceTable, 1.12, 1.62, 0.05, 0.42, 0.3, 0.03, M.purpleLight);
box(appliance, 1.85, 1.1, 0.25, 0.14, 2.05, 0.14, M.woodDark);
box(appliance, 1.85, 2.18, 0.25, 0.52, 0.38, 0.1, M.goldLight);
createPerson(appliance, 0.75, -1.48, M.gold, M.skinLight, M.woodDark);
appliance.userData.labelHeight = 3.65;
registerStation({
id: "appliance",
root: appliance,
label: "03 / Enclosed items",
accent: "#4d8fac",
x: 0.85,
z: 0.6,
size: [4.8, 2.8],
kicker: "Repair pathway 02",
title: "Enclosed-item triage",
copy:
"Powered or enclosed objects receive an unplugged, external condition check. Anything requiring opening is referred.",
stages: ["Unplugged", "External check", "Refer if needed"]
});
// ------------------------------------------------------------
// Light furniture care station
// ------------------------------------------------------------
const furniture = group(scene, 5.35, 0, 0.5);
const furnitureTable = createTable(furniture, 4.35, 2.1, M.woodLight);
// Simple chair sample.
box(furnitureTable, -1.05, 1.56, 0.05, 0.95, 0.18, 0.9, M.wood);
box(furnitureTable, -1.05, 2.02, -0.34, 0.95, 0.82, 0.17, M.wood);
box(furnitureTable, -1.42, 1.0, 0.38, 0.14, 0.92, 0.14, M.woodDark);
box(furnitureTable, -0.68, 1.0, 0.38, 0.14, 0.92, 0.14, M.woodDark);
// Cleaning cloths and small parts tray.
box(furnitureTable, 0.65, 1.53, -0.3, 0.85, 0.1, 0.7, M.blueLight);
box(furnitureTable, 0.73, 1.6, -0.26, 0.72, 0.08, 0.58, M.white);
box(furnitureTable, 1.48, 1.53, 0.38, 0.85, 0.15, 0.72, M.goldLight);
for (let i = 0; i < 4; i++) {
box(
furnitureTable,
1.2 + (i % 2) * 0.32,
1.64,
0.16 + Math.floor(i / 2) * 0.28,
0.18,
0.1,
0.18,
M.charcoal
);
}
createPerson(furniture, 0.45, -1.48, M.purple, M.skin, M.ink);
furniture.userData.labelHeight = 3.45;
registerStation({
id: "furniture",
root: furniture,
label: "04 / Furniture care",
accent: "#d9a441",
x: 5.35,
z: 0.5,
size: [4.9, 2.8],
kicker: "Repair pathway 03",
title: "Light furniture care",
copy:
"Surface condition, loose small fittings, and non-structural problems can be handled while load-bearing repairs are referred.",
stages: ["Surface check", "Simple care", "Non-structural only"]
});
// ------------------------------------------------------------
// Toys and games station
// ------------------------------------------------------------
const toys = group(scene, -3.05, 0, -3.85);
const toyTable = createTable(toys, 4.15, 2.05, M.creamLight);
// Block set.
box(toyTable, -1.25, 1.61, 0.28, 0.55, 0.52, 0.55, M.coral);
box(toyTable, -0.55, 1.53, 0.42, 0.38, 0.38, 0.38, M.blue);
box(toyTable, -0.95, 1.98, 0.25, 0.42, 0.42, 0.42, M.gold);
// Voxel bear.
box(toyTable, 0.65, 1.55, -0.25, 0.72, 0.48, 0.55, M.woodLight);
box(toyTable, 0.65, 1.97, -0.25, 0.62, 0.58, 0.56, M.woodLight);
box(toyTable, 0.42, 2.33, -0.25, 0.22, 0.22, 0.22, M.woodLight);
box(toyTable, 0.88, 2.33, -0.25, 0.22, 0.22, 0.22, M.woodLight);
box(toyTable, 0.65, 1.98, 0.045, 0.34, 0.18, 0.06, M.woodDark);
// Board-game box.
box(toyTable, 1.35, 1.54, 0.42, 0.85, 0.12, 0.85, M.purpleLight);
box(toyTable, 1.35, 1.62, 0.42, 0.67, 0.05, 0.65, M.white);
createPerson(toys, 0.65, -1.5, M.blue, M.skinLight, M.woodDark);
toys.userData.labelHeight = 3.35;
registerStation({
id: "toys",
root: toys,
label: "05 / Toys & games",
accent: "#8e6bb3",
x: -3.05,
z: -3.85,
size: [4.7, 2.7],
kicker: "Repair pathway 04",
title: "Toys & games",
copy:
"Toys and games are cleaned, sorted, and checked externally. Worn or broken parts are evaluated before any simple care.",
stages: ["Clean", "Sort", "External check"]
});
// ------------------------------------------------------------
// Spare-parts library
// ------------------------------------------------------------
const parts = group(scene, 8.75, 0, -4.45);
const partsShelf = createShelf(parts, 4.45, 4);
const binColors = [M.coral, M.blue, M.gold, M.purple];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 3; col++) {
const x = -1.35 + col * 1.35;
const y = 0.61 + row * 1.02;
const z = 0.05;
box(partsShelf, x, y + 0.26, z, 1.02, 0.48, 0.88, binColors[(row + col) % 4]);
box(partsShelf, x, y + 0.51, z, 1.08, 0.08, 0.94, M.creamLight);
if (row === 0) {
for (let i = 0; i < 4; i++) {
box(
partsShelf,
x - 0.32 + i * 0.21,
y + 0.57,
z,
0.13,
0.12,
0.13,
M.white
);
}
} else if (row === 1) {
box(partsShelf, x, y + 0.58, z, 0.75, 0.12, 0.64, M.pink);
box(partsShelf, x + 0.12, y + 0.67, z, 0.46, 0.1, 0.5, M.blueLight);
} else {
box(partsShelf, x - 0.24, y + 0.58, z, 0.24, 0.12, 0.5, M.charcoal);
box(partsShelf, x + 0.22, y + 0.58, z, 0.24, 0.12, 0.5, M.goldLight);
}
}
}
frontLabel(partsShelf, "Buttons · Fabric · Fittings", 0, 3.25, 0.69, 3.75, 0.58, "#5e9c76");
parts.userData.labelHeight = 4.65;
registerStation({
id: "parts",
root: parts,
label: "06 / Spare parts",
accent: "#5e9c76",
x: 8.75,
z: -4.45,
size: [5, 2],
kicker: "Community resource",
title: "Spare-parts library",
copy:
"Donated buttons, textiles, and common fittings are sorted in shared bins so volunteers can find reusable materials quickly.",
stages: ["Donated", "Sorted", "Reusable"]
});
// ------------------------------------------------------------
// Returned objects
// ------------------------------------------------------------
const returns = group(scene, -8.35, 0, -4.7);
const returnShelf = createShelf(returns, 5.25, 4);
// Returned radio.
box(returnShelf, -1.75, 1.08, 0.05, 1.05, 0.62, 0.6, M.blue);
box(returnShelf, -1.75, 1.12, 0.37, 0.72, 0.28, 0.04, M.charcoal);
box(returnShelf, -1.42, 0.94, 0.39, 0.13, 0.13, 0.04, M.goldLight);
// Returned lamp.
box(returnShelf, 0, 0.93, 0.02, 0.62, 0.13, 0.62, M.teal);
box(returnShelf, 0, 1.27, 0.02, 0.13, 0.55, 0.13, M.teal);
box(returnShelf, 0, 1.57, 0.02, 0.8, 0.4, 0.62, M.gold);
// Returned books.
box(returnShelf, 1.65, 0.88, 0.05, 0.75, 0.22, 0.72, M.coral);
box(returnShelf, 1.7, 1.08, 0.02, 0.68, 0.2, 0.66, M.purpleLight);
box(returnShelf, 1.62, 1.27, 0.05, 0.75, 0.18, 0.7, M.gold);
// Small chair on the upper shelf.
box(returnShelf, -1.65, 2.08, 0.05, 0.9, 0.16, 0.78, M.wood);
box(returnShelf, -1.65, 2.48, -0.28, 0.9, 0.7, 0.15, M.wood);
box(returnShelf, -1.98, 1.66, 0.34, 0.13, 0.72, 0.13, M.woodDark);
box(returnShelf, -1.32, 1.66, 0.34, 0.13, 0.72, 0.13, M.woodDark);
// Pickup labels.
for (let i = 0; i < 3; i++) {
box(returnShelf, -1.7 + i * 1.7, 1.42, 0.47, 0.48, 0.24, 0.04, M.white);
box(returnShelf, -1.7 + i * 1.7, 1.43, 0.5, 0.28, 0.04, 0.02, M.coral);
}
frontLabel(returnShelf, "Returned · Logged · Ready", 0, 3.26, 0.69, 4.15, 0.58, "#2a9d8f");
returns.userData.labelHeight = 4.6;
registerStation({
id: "returns",
root: returns,
label: "07 / Returned",
accent: "#2a9d8f",
x: -8.35,
z: -4.7,
size: [5.8, 2],
kicker: "Return shelf",
title: "Returned objects",
copy:
"Completed objects are logged, labeled, and placed on the return shelf until their owners collect them.",
stages: ["Logged", "Labeled", "Ready for pickup"]
});
// ------------------------------------------------------------
// Café seating corner
// ------------------------------------------------------------
const cafe = group(scene, 7.1, 0, 4.9);
box(cafe, 0, 1.25, 0, 2.65, 0.18, 1.6, M.woodLight);
box(cafe, -1.02, 0.64, 0, 0.18, 1.18, 0.18, M.woodDark);
box(cafe, 1.02, 0.64, 0, 0.18, 1.18, 0.18, M.woodDark);
box(cafe, 0, 0.64, 0, 2.2, 0.14, 0.16, M.woodDark);
for (const x of [-1.85, 1.85]) {
box(cafe, x, 0.55, 0, 0.82, 0.18, 0.82, M.teal);
box(cafe, x, 0.28, 0, 0.45, 0.48, 0.45, M.tealDark);
box(cafe, x, 0.95, -0.32, 0.82, 0.8, 0.14, M.teal);
}
createMug(cafe, -0.55, 1.35, 0.1, M.coral);
createMug(cafe, 0.5, 1.35, -0.25, M.blue);
box(cafe, 0, 1.39, 0.32, 0.82, 0.08, 0.62, M.white);
box(cafe, 0, 1.45, 0.32, 0.7, 0.025, 0.5, M.pink);
// ------------------------------------------------------------
// Floor pathway routes
// ------------------------------------------------------------
const routeMaterials = {};
function addRoute(id, color, points) {
const mat = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.22,
transparent: true,
opacity: 0.5,
depthWrite: false,
roughness: 1
});
routeMaterials[id] = mat;
for (let i = 0; i < points.length - 1; i++) {
const [x1, z1] = points[i];
const [x2, z2] = points[i + 1];
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const angle = Math.atan2(dx, dz);
const count = Math.max(1, Math.floor(length / 0.44));
for (let j = 0; j < count; j++) {
const t = (j + 0.5) / count;
const dash = group(scene, x1 + dx * t, 0.17, z1 + dz * t);
dash.rotation.y = angle;
box(
dash,
0,
0,
0,
0.13,
0.035,
0.3,
mat,
{ castShadow: false, receiveShadow: false }
);
}
}
// Voxel arrow at the route destination.
const [endX, endZ] = points[points.length - 1];
const [prevX, prevZ] = points[points.length - 2];
const angle = Math.atan2(endX - prevX, endZ - prevZ);
const arrow = group(scene, endX, 0.18, endZ);
arrow.rotation.y = angle;
box(arrow, 0, 0, 0, 0.12, 0.035, 0.56, mat, {
castShadow: false,
receiveShadow: false
});
box(arrow, -0.15, 0, -0.2, 0.12, 0.035, 0.42, mat, {
castShadow: false,
receiveShadow: false
});
box(arrow, 0.15, 0, -0.2, 0.12, 0.035, 0.42, mat, {
castShadow: false,
receiveShadow: false
});
}
addRoute("textile", 0xe76f51, [
[-6.75, 3.05],
[-4.25, 2.0]
]);
addRoute("appliance", 0x4d8fac, [
[-6.55, 3.12],
[-2.35, 3.12],
[0.85, 1.95]
]);
addRoute("furniture", 0xd9a441, [
[-6.4, 3.55],
[3.85, 3.55],
[5.35, 1.85]
]);
addRoute("toys", 0x8e6bb3, [
[-7.15, 2.65],
[-5.65, 1.75],
[-5.65, -2.35],
[-3.05, -2.65]
]);
// ------------------------------------------------------------
// Detail panel and pathway controls
// ------------------------------------------------------------
const detailElement = document.querySelector("#detail");
const detailKicker = document.querySelector("#detail-kicker");
const detailTitle = document.querySelector("#detail-title");
const detailCopy = document.querySelector("#detail-copy");
const stagesElement = document.querySelector("#stages");
const pathButtons = [...document.querySelectorAll(".path-button")];
const stationToPath = {
textile: "textile",
appliance: "appliance",
furniture: "furniture",
toys: "toys"
};
let selectedStation = "intake";
let activePath = "all";
function updateDetail(id) {
const info = stationInfo[id];
selectedStation = id;
detailElement.style.setProperty("--accent", info.accent);
detailKicker.textContent = info.kicker;
detailTitle.textContent = info.title;
detailCopy.textContent = info.copy;
stagesElement.replaceChildren();
for (const stage of info.stages) {
const chip = document.createElement("span");
chip.className = "stage";
chip.textContent = stage;
stagesElement.appendChild(chip);
}
for (const [stationId, halo] of Object.entries(halos)) {
halo.visible = stationId === id;
}
}
function updatePathButtons() {
for (const button of pathButtons) {
button.classList.toggle("active", button.dataset.path === activePath);
}
}
function setPath(path, selectRelated = true) {
activePath = path;
updatePathButtons();
for (const [id, mat] of Object.entries(routeMaterials)) {
mat.opacity = path === "all" ? 0.55 : id === path ? 1 : 0.09;
}
if (selectRelated) {
if (path === "all") {
updateDetail("intake");
} else {
updateDetail(path);
}
}
}
for (const button of pathButtons) {
button.addEventListener("click", () => {
setPath(button.dataset.path, true);
});
}
updateDetail("intake");
setPath("all", false);
// ------------------------------------------------------------
// Camera controls implemented without external addons
// ------------------------------------------------------------
const orbit = {
radius: 27,
theta: 0.72,
phi: 0.88,
target: new THREE.Vector3(0, 1.1, -0.1),
targetGoal: new THREE.Vector3(0, 1.1, -0.1)
};
const spherical = new THREE.Spherical();
function updateCamera() {
spherical.set(orbit.radius, orbit.phi, orbit.theta);
camera.position.setFromSpherical(spherical).add(orbit.target);
camera.lookAt(orbit.target);
}
updateCamera();
const pointer = {
down: false,
moved: false,
x: 0,
y: 0,
startX: 0,
startY: 0
};
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
function stationAtPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(stationRoots, true);
for (const hit of hits) {
let object = hit.object;
while (object) {
if (object.userData.station) {
return object.userData.station;
}
object = object.parent;
}
}
return null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.down = true;
pointer.moved = false;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointer.down) {
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
if (Math.hypot(event.clientX - pointer.startX, event.clientY - pointer.startY) > 5) {
pointer.moved = true;
}
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.35, 1.27);
pointer.x = event.clientX;
pointer.y = event.clientY;
} else {
const station = stationAtPointer(event);
renderer.domElement.style.cursor = station ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointer.down = false;
if (!pointer.moved) {
const station = stationAtPointer(event);
if (station) {
const relatedPath = stationToPath[station];
if (relatedPath) {
setPath(relatedPath, false);
updateDetail(station);
} else {
activePath = station === "intake" ? "all" : "";
updatePathButtons();
for (const [id, mat] of Object.entries(routeMaterials)) {
mat.opacity = station === "intake" ? 0.55 : 0.18;
}
updateDetail(station);
}
const info = stationInfo[station];
orbit.targetGoal.set(info.x * 0.25, 1.1, info.z * 0.25);
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.down = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
12,
35
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") orbit.theta += 0.12;
if (event.key === "ArrowRight") orbit.theta -= 0.12;
if (event.key === "ArrowUp") orbit.phi = Math.max(0.35, orbit.phi - 0.08);
if (event.key === "ArrowDown") orbit.phi = Math.min(1.27, orbit.phi + 0.08);
if (event.key === "+" || event.key === "=") orbit.radius = Math.max(12, orbit.radius - 1);
if (event.key === "-") orbit.radius = Math.min(35, orbit.radius + 1);
event.preventDefault();
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
const elapsed = clock.getElapsedTime();
orbit.target.lerp(orbit.targetGoal, 0.055);
updateCamera();
const pulse = 1 + Math.sin(elapsed * 3.1) * 0.025;
for (const halo of Object.values(halos)) {
if (halo.visible) {
halo.scale.set(pulse, 1, pulse);
halo.rotation.y = Math.sin(elapsed * 0.5) * 0.015;
}
}
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.querySelector("#loading").classList.add("hidden");
setTimeout(() => {
document.querySelector("#loading").remove();
}, 500);
}
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```