Prompt specification
Build or customize the Three.js 3D scene "Mobile clinic supply layout" 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: Mobile clinic supply layout
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mobile-clinic-supply-layout-x0200
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing locking caster wheels. Build a nonclinical room-planning exhibit with carts, cabinets, and visitor paths; users park and lock equipment so all selected storage faces remain accessible. Low-poly.
Working Three.js Starter (mobile-clinic-supply-layout-x0200):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Caster / Access Study</title>
<style>
:root {
--ink: #173b3a;
--muted: #667775;
--paper: rgba(250, 249, 243, 0.92);
--paper-solid: #f8f7f0;
--line: rgba(23, 59, 58, 0.14);
--teal: #278c7e;
--teal-light: #d9eee7;
--coral: #d86650;
--coral-light: #f8ded6;
--amber: #e5a34e;
--shadow: 0 16px 50px rgba(33, 54, 52, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #e9e8df;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#viewport canvas {
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
right: 20px;
display: flex;
justify-content: space-between;
align-items: flex-start;
pointer-events: none;
}
.brand,
.view-tools {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.66);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 320px;
padding: 12px 16px 12px 12px;
border-radius: 16px;
}
.brand-mark {
width: 42px;
height: 42px;
border-radius: 12px;
display: grid;
place-items: center;
color: white;
background: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
}
.brand h1 {
margin: 0;
font-size: 16px;
line-height: 1.15;
font-weight: 750;
letter-spacing: -0.02em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.view-tools {
display: flex;
gap: 5px;
padding: 6px;
border-radius: 14px;
}
.tool-button {
border: 0;
border-radius: 9px;
padding: 9px 11px;
color: var(--ink);
background: transparent;
cursor: pointer;
font-size: 12px;
font-weight: 700;
transition: background 160ms ease, color 160ms ease;
}
.tool-button:hover {
background: var(--teal-light);
}
.panel {
position: fixed;
z-index: 9;
top: 102px;
width: 286px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 20px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.left-panel {
left: 20px;
}
.right-panel {
right: 20px;
width: 306px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 19px;
letter-spacing: -0.035em;
}
.panel-copy {
margin: 7px 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section-label {
display: flex;
justify-content: space-between;
align-items: center;
margin: 17px 0 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--muted);
}
.section-label span:last-child {
letter-spacing: 0;
text-transform: none;
font-weight: 600;
}
.face-list {
display: grid;
gap: 7px;
}
.face-option {
width: 100%;
display: grid;
grid-template-columns: 35px 1fr auto;
align-items: center;
gap: 9px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--ink);
background: rgba(255, 255, 255, 0.45);
text-align: left;
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease;
}
.face-option:hover {
border-color: rgba(39, 140, 126, 0.46);
}
.face-option.selected {
border-color: rgba(39, 140, 126, 0.54);
background: rgba(217, 238, 231, 0.62);
}
.face-option.blocked {
border-color: rgba(216, 102, 80, 0.58);
background: rgba(248, 222, 214, 0.68);
}
.face-code {
width: 33px;
height: 33px;
display: grid;
place-items: center;
border-radius: 9px;
background: rgba(23, 59, 58, 0.08);
font-size: 11px;
font-weight: 850;
}
.face-name {
display: block;
font-size: 12px;
font-weight: 750;
}
.face-sub {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.face-state {
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--teal);
}
.face-option.blocked .face-state {
color: var(--coral);
}
.checks {
display: grid;
gap: 7px;
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.check-row {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 11px;
}
.check-name {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
}
.check-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 3px rgba(229, 163, 78, 0.14);
}
.check-dot.good {
background: var(--teal);
box-shadow: 0 0 0 3px rgba(39, 140, 126, 0.14);
}
.check-dot.bad {
background: var(--coral);
box-shadow: 0 0 0 3px rgba(216, 102, 80, 0.14);
}
.check-value {
font-weight: 800;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
}
.legend-swatch {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--teal);
}
.legend-swatch.blocked {
background: var(--coral);
}
.legend-swatch.parking {
border: 1px solid var(--amber);
background: rgba(229, 163, 78, 0.18);
}
.hint {
margin: 14px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.cart-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin: 15px 0;
}
.cart-tab {
min-width: 0;
padding: 9px 6px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.44);
color: var(--muted);
cursor: pointer;
}
.cart-tab strong,
.cart-tab span {
display: block;
}
.cart-tab strong {
color: var(--ink);
font-size: 11px;
}
.cart-tab span {
margin-top: 2px;
font-size: 9px;
}
.cart-tab.active {
color: white;
border-color: var(--ink);
background: var(--ink);
}
.cart-tab.active strong {
color: white;
}
.inspector-title {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
}
.inspector-title h3 {
margin: 0;
font-size: 17px;
letter-spacing: -0.03em;
}
.status-pill {
flex: 0 0 auto;
padding: 5px 7px;
border-radius: 999px;
background: rgba(229, 163, 78, 0.14);
color: #9b6326;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-pill.good {
color: var(--teal);
background: var(--teal-light);
}
.status-pill.bad {
color: var(--coral);
background: var(--coral-light);
}
.meta-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin: 14px 0;
}
.meta-cell {
padding: 9px;
border-radius: 10px;
background: rgba(23, 59, 58, 0.055);
}
.meta-cell span,
.meta-cell strong {
display: block;
}
.meta-cell span {
color: var(--muted);
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.meta-cell strong {
margin-top: 3px;
font-size: 12px;
}
.action-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.action-button {
min-height: 42px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.6);
color: var(--ink);
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
.action-button:hover {
transform: translateY(-1px);
background: white;
}
.action-button.primary {
border-color: var(--teal);
color: white;
background: var(--teal);
}
.action-button.primary:hover {
background: #20796d;
}
.action-button.wide {
grid-column: 1 / -1;
min-height: 36px;
background: transparent;
}
.wheel-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.wheel-button {
display: grid;
grid-template-columns: 28px 1fr;
grid-template-rows: 1fr 1fr;
column-gap: 7px;
align-items: center;
padding: 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.42);
color: var(--ink);
text-align: left;
cursor: pointer;
}
.wheel-icon {
grid-row: 1 / 3;
width: 28px;
height: 28px;
display: grid;
place-items: center;
border-radius: 8px;
background: var(--coral-light);
color: var(--coral);
font-size: 12px;
font-weight: 900;
}
.wheel-button.locked .wheel-icon {
color: var(--teal);
background: var(--teal-light);
}
.wheel-button strong {
align-self: end;
font-size: 10px;
}
.wheel-button em {
align-self: start;
color: var(--muted);
font-size: 9px;
font-style: normal;
}
.goal-bar {
position: fixed;
z-index: 10;
left: 50%;
bottom: 20px;
width: min(560px, calc(100vw - 660px));
min-width: 410px;
transform: translateX(-50%);
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 17px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
pointer-events: none;
}
.goal-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
.goal-copy strong,
.goal-copy span {
display: block;
}
.goal-copy strong {
font-size: 12px;
}
.goal-copy span {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.goal-badge {
flex: 0 0 auto;
padding: 7px 9px;
border-radius: 999px;
background: rgba(229, 163, 78, 0.15);
color: #9b6326;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
body.complete .goal-badge {
color: var(--teal);
background: var(--teal-light);
}
.progress-track {
height: 4px;
margin-top: 10px;
overflow: hidden;
border-radius: 99px;
background: rgba(23, 59, 58, 0.09);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--teal);
transition: width 250ms ease;
}
.toast {
position: fixed;
z-index: 30;
left: 50%;
top: 92px;
max-width: min(420px, calc(100vw - 40px));
padding: 11px 15px;
transform: translate(-50%, -15px);
border-radius: 12px;
color: white;
background: var(--ink);
box-shadow: 0 10px 35px rgba(23, 59, 58, 0.24);
font-size: 11px;
font-weight: 700;
text-align: center;
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #e9e8df;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loading.hide {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1100px) {
.panel {
width: 250px;
}
.right-panel {
width: 270px;
}
.goal-bar {
left: 285px;
right: 305px;
width: auto;
min-width: 0;
transform: none;
}
}
@media (max-width: 820px) {
.brand {
min-width: 0;
}
.brand p {
display: none;
}
.left-panel {
top: 88px;
width: 225px;
max-height: calc(100vh - 180px);
overflow: auto;
}
.right-panel {
top: auto;
bottom: 106px;
width: 245px;
max-height: 48vh;
overflow: auto;
}
.goal-bar {
left: 12px;
right: 12px;
bottom: 12px;
}
.tool-button {
padding: 8px;
font-size: 10px;
}
}
@media (max-width: 580px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand {
padding: 9px;
}
.brand-mark {
width: 35px;
height: 35px;
}
.brand h1 {
font-size: 13px;
}
.view-tools .tool-button:nth-child(2) {
display: none;
}
.left-panel {
top: 70px;
left: 10px;
width: 190px;
max-height: 43vh;
padding: 13px;
}
.left-panel .panel-copy,
.left-panel .legend,
.left-panel .hint {
display: none;
}
.right-panel {
right: 10px;
bottom: 98px;
width: 210px;
max-height: 43vh;
padding: 13px;
}
.right-panel .meta-grid,
.right-panel .action-row .wide {
display: none;
}
.wheel-grid {
grid-template-columns: 1fr;
}
.wheel-button:nth-child(n + 3) {
display: none;
}
.goal-copy span {
display: none;
}
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive room planning exhibit"></main>
<header class="topbar">
<div class="brand">
<div class="brand-mark">04</div>
<div>
<h1>Caster / Access Study</h1>
<p>Nonclinical room-planning exhibit</p>
</div>
</div>
<nav class="view-tools" aria-label="View controls">
<button class="tool-button" id="isoView" type="button">Isometric</button>
<button class="tool-button" id="topView" type="button">Plan view</button>
<button class="tool-button" id="resetPlan" type="button">Reset</button>
</nav>
</header>
<aside class="panel left-panel">
<p class="eyebrow">Access plan</p>
<h2>Selected storage faces</h2>
<p class="panel-copy">
Choose the cabinet faces that must remain usable. Equipment should stay
inside its assigned parking bay, with every caster brake engaged.
</p>
<div class="section-label">
<span>Storage faces</span>
<span id="faceCount">3 checked</span>
</div>
<div class="face-list" id="faceList"></div>
<div class="checks">
<div class="check-row">
<span class="check-name"><i class="check-dot" id="facesDot"></i>Faces accessible</span>
<span class="check-value" id="facesValue">3 / 3</span>
</div>
<div class="check-row">
<span class="check-name"><i class="check-dot" id="parkedDot"></i>Carts parked</span>
<span class="check-value" id="parkedValue">0 / 3</span>
</div>
<div class="check-row">
<span class="check-name"><i class="check-dot" id="lockedDot"></i>Brakes engaged</span>
<span class="check-value" id="lockedValue">0 / 3</span>
</div>
</div>
<div class="legend">
<div class="legend-item"><i class="legend-swatch"></i>Clear face</div>
<div class="legend-item"><i class="legend-swatch blocked"></i>Blocked face</div>
<div class="legend-item"><i class="legend-swatch parking"></i>Parking bay</div>
<div class="legend-item"><i class="legend-swatch" style="background:#9aa5a1"></i>Visitor path</div>
</div>
<p class="hint">
Drag a cart to move it. Click a caster to toggle its individual brake.
Drag empty floor to orbit; scroll to zoom.
</p>
</aside>
<aside class="panel right-panel">
<p class="eyebrow">Equipment inspector</p>
<div class="cart-tabs" id="cartTabs"></div>
<div class="inspector-title">
<div>
<h3 id="cartName">Linen utility cart</h3>
</div>
<span class="status-pill" id="cartStatus">Unparked</span>
</div>
<div class="meta-grid">
<div class="meta-cell">
<span>Position</span>
<strong id="cartPosition">X −5.0 / Z 2.6</strong>
</div>
<div class="meta-cell">
<span>Bay</span>
<strong id="cartBay">P-01</strong>
</div>
</div>
<div class="action-row">
<button class="action-button primary" id="parkCart" type="button">Park in P-01</button>
<button class="action-button" id="lockCart" type="button">Lock 4 casters</button>
<button class="action-button wide" id="focusCart" type="button">Inspect caster detail</button>
</div>
<div class="section-label">
<span>Caster brakes</span>
<span id="wheelCount">0 / 4 locked</span>
</div>
<div class="wheel-grid" id="wheelList"></div>
<p class="hint">
An orange pedal is released. A lowered green pedal is locked.
Parking and braking are both evaluated live.
</p>
</aside>
<section class="goal-bar" aria-live="polite">
<div class="goal-row">
<div class="goal-copy">
<strong id="goalTitle">Keep the selected storage faces accessible</strong>
<span id="goalDetail">3 / 3 faces open · 0 / 3 carts parked · 0 / 3 brakes locked</span>
</div>
<div class="goal-badge" id="goalBadge">In progress</div>
</div>
<div class="progress-track"><div class="progress-fill" id="progressFill"></div></div>
</section>
<div class="toast" id="toast" role="status"></div>
<div class="loading" id="loading">Building room exhibit…</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 loading = document.getElementById("loading");
const toastElement = document.getElementById("toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e8df);
scene.fog = new THREE.Fog(0xe9e8df, 24, 48);
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.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",
"Low-poly room with cabinets, carts, locking caster wheels, parking bays and visitor paths."
);
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const orbit = {
theta: 0.72,
phi: 0.72,
zoom: 1,
target: new THREE.Vector3(0.15, 0.55, -0.25)
};
function updateCamera() {
const radius = 20;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + radius * Math.cos(orbit.phi),
orbit.target.z + radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight = Math.max(6.8, 8.2 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x7d8c83, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4dc, 3.25);
keyLight.position.set(-5, 12, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8d9db, 1.0);
fillLight.position.set(8, 6, -7);
scene.add(fillLight);
const colors = {
ink: 0x173b3a,
cream: 0xe7e3d7,
paper: 0xf4f1e8,
teal: 0x278c7e,
tealLight: 0xc8dfd6,
coral: 0xd86650,
coralLight: 0xeeb9aa,
amber: 0xe5a34e,
metal: 0x8f9c99,
tire: 0x27302f,
floor: 0xd9d8ce
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
floor: standard(colors.floor, { roughness: 0.96 }),
plinth: standard(0xb9beb5),
wall: standard(colors.cream),
wallTrim: standard(0xc5c9bd),
ink: standard(colors.ink),
teal: standard(colors.teal),
tealLight: standard(colors.tealLight),
coral: standard(colors.coral),
coralLight: standard(colors.coralLight),
amber: standard(colors.amber),
metal: standard(colors.metal, { metalness: 0.22, roughness: 0.58 }),
tire: standard(colors.tire, { roughness: 0.9 }),
white: standard(0xf8f6ee),
wood: standard(0xcba97b),
paper: standard(0xe8e2d2)
};
function box(width, height, depth, material, parent, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
segments,
material,
parent,
x = 0,
y = 0,
z = 0
) {
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 addEdges(mesh, color = 0x425c59, opacity = 0.35) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 28),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return edges;
}
function makeTextTexture(text, background = "#173b3a", foreground = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = background;
context.beginPath();
context.roundRect(4, 4, 504, 120, 24);
context.fill();
context.fillStyle = foreground;
context.font = "800 54px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makeLabel(
text,
width,
height,
parent,
x,
y,
z,
options = {}
) {
const texture = makeTextTexture(
text,
options.background || "#173b3a",
options.foreground || "#ffffff"
);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function makeLine(points, material, parent = scene) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, material);
parent.add(line);
return line;
}
// Room shell.
const room = new THREE.Group();
scene.add(room);
box(14.4, 0.34, 10.4, materials.plinth, room, 0, -0.29, 0);
box(14, 0.16, 10, materials.floor, room, 0, -0.08, 0);
const tilePoints = [];
for (let x = -7; x <= 7; x += 1) {
tilePoints.push(new THREE.Vector3(x, 0.012, -5));
tilePoints.push(new THREE.Vector3(x, 0.012, 5));
}
for (let z = -5; z <= 5; z += 1) {
tilePoints.push(new THREE.Vector3(-7, 0.012, z));
tilePoints.push(new THREE.Vector3(7, 0.012, z));
}
const tileGeometry = new THREE.BufferGeometry().setFromPoints(tilePoints);
room.add(
new THREE.LineSegments(
tileGeometry,
new THREE.LineBasicMaterial({
color: 0xaeb5ad,
transparent: true,
opacity: 0.28
})
)
);
const backWall = box(14, 3.55, 0.18, materials.wall, room, 0, 1.775, -5);
addEdges(backWall, 0x8f9b91, 0.2);
const leftWall = box(0.18, 3.55, 10, materials.wall, room, -7, 1.775, 0);
addEdges(leftWall, 0x8f9b91, 0.2);
box(14, 0.12, 0.08, materials.wallTrim, room, 0, 0.15, -4.87);
box(0.08, 0.12, 10, materials.wallTrim, room, -6.87, 0.15, 0);
const wallSign = makeLabel(
"STORAGE / ACCESS 04",
3.15,
0.72,
room,
-4.5,
2.92,
-4.895,
{ background: "#173b3a" }
);
wallSign.renderOrder = 2;
// A small graphic wall panel.
const graphic = new THREE.Group();
graphic.position.set(5.2, 2.75, -4.88);
room.add(graphic);
for (let i = 0; i < 5; i++) {
const bar = box(
0.15,
0.62 + (i % 2) * 0.18,
0.025,
i % 2 ? materials.teal : materials.amber,
graphic,
(i - 2) * 0.28,
0,
0
);
bar.castShadow = false;
}
// Visitor paths.
const routeMaterial = new THREE.LineDashedMaterial({
color: colors.teal,
dashSize: 0.28,
gapSize: 0.15,
transparent: true,
opacity: 0.62
});
const mainRoute = makeLine(
[
new THREE.Vector3(0.05, 0.025, 4.45),
new THREE.Vector3(0.05, 0.025, -1.45)
],
routeMaterial
);
mainRoute.computeLineDistances();
const cabinetXs = [-4.45, -1.55, 1.35];
cabinetXs.forEach((x) => {
const branch = makeLine(
[
new THREE.Vector3(0.05, 0.026, -1.45),
new THREE.Vector3(x, 0.026, -1.45),
new THREE.Vector3(x, 0.026, -2.7)
],
routeMaterial
);
branch.computeLineDistances();
});
function makeFloorArrow(z) {
const arrow = new THREE.Group();
arrow.position.set(0.05, 0.035, z);
const material = new THREE.MeshBasicMaterial({ color: colors.teal });
const left = box(0.12, 0.015, 0.42, material, arrow, -0.13, 0, 0);
const right = box(0.12, 0.015, 0.42, material, arrow, 0.13, 0, 0);
left.rotation.y = -0.62;
right.rotation.y = 0.62;
left.castShadow = right.castShadow = false;
scene.add(arrow);
}
makeFloorArrow(3.55);
makeFloorArrow(-0.35);
// Low-poly visitors establish scale without becoming planning obstacles.
function createVisitor(x, z, color, rotation = 0) {
const visitor = new THREE.Group();
visitor.position.set(x, 0, z);
visitor.rotation.y = rotation;
const shirt = standard(color);
const skin = standard(0xd7aa83);
const trousers = standard(0x405b5b);
cylinder(0.14, 0.19, 0.5, 6, shirt, visitor, 0, 0.83, 0);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.14, 0),
skin
);
head.position.y = 1.24;
head.castShadow = true;
visitor.add(head);
box(0.09, 0.55, 0.1, trousers, visitor, -0.1, 0.34, 0);
box(0.09, 0.55, 0.1, trousers, visitor, 0.1, 0.34, 0);
box(0.07, 0.42, 0.08, shirt, visitor, -0.23, 0.82, 0);
box(0.07, 0.42, 0.08, shirt, visitor, 0.23, 0.82, 0);
scene.add(visitor);
}
createVisitor(0.35, 1.15, 0x3b8f88, -0.12);
createVisitor(-0.25, -0.62, 0xd17b62, 0.18);
// Parking bays.
const bays = [];
const bayXs = 4.65;
const bayZs = [-2.4, 0, 2.4];
bayZs.forEach((z, index) => {
const bayGroup = new THREE.Group();
bayGroup.position.set(bayXs, 0, z);
bayGroup.userData.kind = "bay";
bayGroup.userData.bayIndex = index;
scene.add(bayGroup);
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(1.85, 1.85),
new THREE.MeshBasicMaterial({
color: colors.amber,
transparent: true,
opacity: 0.11,
depthWrite: false,
side: THREE.DoubleSide
})
);
plane.rotation.x = -Math.PI / 2;
plane.position.y = 0.018;
plane.userData.kind = "bay";
plane.userData.bayIndex = index;
bayGroup.add(plane);
const points = [
new THREE.Vector3(-0.925, 0.03, -0.925),
new THREE.Vector3(0.925, 0.03, -0.925),
new THREE.Vector3(0.925, 0.03, 0.925),
new THREE.Vector3(-0.925, 0.03, 0.925)
];
const border = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: colors.amber,
transparent: true,
opacity: 0.82
})
);
bayGroup.add(border);
const label = makeLabel(
`P-0${index + 1}`,
0.86,
0.24,
bayGroup,
0,
0.032,
0.68
);
label.rotation.x = -Math.PI / 2;
bays.push({
index,
id: `P-0${index + 1}`,
x: bayXs,
z,
group: bayGroup
});
});
// Storage cabinets and selectable access envelopes.
const faces = [];
const faceNames = ["West cabinet", "Center cabinet", "East cabinet"];
function createCabinet(x, index) {
const group = new THREE.Group();
group.position.set(x, 0, -4.23);
scene.add(group);
const body = box(2.15, 2.35, 0.9, materials.paper, group, 0, 1.175, 0);
addEdges(body);
box(2.23, 0.13, 1.0, materials.ink, group, 0, 2.4, 0);
box(2.02, 0.12, 0.78, materials.wallTrim, group, 0, 0.08, 0);
for (let drawer = 0; drawer < 2; drawer++) {
const drawerMesh = box(
1.88,
0.22,
0.06,
materials.wallTrim,
group,
0,
0.34 + drawer * 0.27,
0.48
);
addEdges(drawerMesh, 0x768781, 0.28);
box(
0.45,
0.035,
0.045,
materials.ink,
group,
0,
0.34 + drawer * 0.27,
0.53
);
}
const panelMaterial = standard(colors.tealLight);
const panel = box(1.88, 1.53, 0.065, panelMaterial, group, 0, 1.42, 0.48);
const outline = addEdges(panel, colors.teal, 0.85);
box(0.08, 0.38, 0.09, materials.ink, group, 0.68, 1.39, 0.56);
const id = `A${index + 1}`;
const plaque = makeLabel(
id,
0.48,
0.18,
group,
-0.64,
2.12,
0.525,
{ background: "#173b3a" }
);
plaque.renderOrder = 2;
const zoneWidth = 1.98;
const zMin = -3.67;
const zMax = -1.78;
const zoneLength = zMax - zMin;
const zone = new THREE.Mesh(
new THREE.PlaneGeometry(zoneWidth, zoneLength),
new THREE.MeshBasicMaterial({
color: colors.teal,
transparent: true,
opacity: 0.12,
depthWrite: false,
side: THREE.DoubleSide
})
);
zone.rotation.x = -Math.PI / 2;
zone.position.set(x, 0.025, (zMin + zMax) / 2);
scene.add(zone);
const zonePoints = [
new THREE.Vector3(x - zoneWidth / 2, 0.038, zMin),
new THREE.Vector3(x + zoneWidth / 2, 0.038, zMin),
new THREE.Vector3(x + zoneWidth / 2, 0.038, zMax),
new THREE.Vector3(x - zoneWidth / 2, 0.038, zMax)
];
const zoneBorder = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(zonePoints),
new THREE.LineBasicMaterial({
color: colors.teal,
transparent: true,
opacity: 0.78
})
);
scene.add(zoneBorder);
const face = {
id,
index,
name: faceNames[index],
x,
halfWidth: zoneWidth / 2,
zMin,
zMax,
panel,
outline,
zone,
zoneBorder,
selected: true
};
panel.userData.kind = "face";
panel.userData.face = face;
faces.push(face);
}
cabinetXs.forEach(createCabinet);
// Carts and detailed locking casters.
const carts = [];
const wheelNames = ["Front left", "Front right", "Rear right", "Rear left"];
function makeCaster(cart, wheelIndex, x, z) {
const caster = new THREE.Group();
caster.position.set(x, 0, z);
caster.userData.kind = "wheel";
caster.userData.cart = cart;
caster.userData.wheelIndex = wheelIndex;
cart.group.add(caster);
const tire = cylinder(
0.165,
0.165,
0.115,
10,
materials.tire,
caster,
0,
0.165,
0
);
tire.rotation.z = Math.PI / 2;
const hub = cylinder(
0.073,
0.073,
0.122,
8,
materials.metal,
caster,
0,
0.165,
0
);
hub.rotation.z = Math.PI / 2;
box(0.035, 0.27, 0.19, materials.metal, caster, -0.082, 0.29, 0);
box(0.035, 0.27, 0.19, materials.metal, caster, 0.082, 0.29, 0);
cylinder(0.045, 0.05, 0.18, 8, materials.metal, caster, 0, 0.46, 0);
cylinder(0.075, 0.075, 0.035, 8, materials.ink, caster, 0, 0.56, 0);
const pedalPivot = new THREE.Group();
pedalPivot.position.set(0.12, 0.34, 0.015);
caster.add(pedalPivot);
const pedalMaterial = standard(colors.coral);
const pedal = box(
0.045,
0.045,
0.23,
pedalMaterial,
pedalPivot,
0,
0,
0.075
);
pedal.rotation.x = -0.65;
const wheel = {
index: wheelIndex,
name: wheelNames[wheelIndex],
caster,
pedalPivot,
pedalMaterial,
locked: false
};
cart.wheels.push(wheel);
}
function createCart(definition) {
const cart = {
...definition,
wheels: [],
group: new THREE.Group(),
motion: null
};
cart.group.position.set(cart.x, 0, cart.z);
cart.group.rotation.y = cart.rot;
cart.group.userData.kind = "cart";
cart.group.userData.cart = cart;
scene.add(cart.group);
const accent =
cart.type === "tall"
? materials.coral
: cart.type === "low"
? materials.teal
: materials.amber;
const accentLight =
cart.type === "tall"
? materials.coralLight
: cart.type === "low"
? materials.tealLight
: materials.paper;
if (cart.type === "tall") {
for (const px of [-cart.w / 2 + 0.08, cart.w / 2 - 0.08]) {
for (const pz of [-cart.d / 2 + 0.07, cart.d / 2 - 0.07]) {
box(0.065, 1.35, 0.065, materials.metal, cart.group, px, 1.1, pz);
}
}
[0.48, 1.02, 1.57].forEach((y, index) => {
const shelf = box(
cart.w,
0.075,
cart.d,
index === 2 ? accent : materials.white,
cart.group,
0,
y,
0
);
addEdges(shelf, 0x536864, 0.26);
});
box(cart.w * 0.72, 0.38, cart.d * 0.78, accentLight, cart.group, 0, 1.78, 0);
box(cart.w, 0.07, 0.07, materials.ink, cart.group, 0, 1.94, -cart.d / 2 + 0.08);
box(0.07, 0.4, 0.07, materials.ink, cart.group, -cart.w / 2 + 0.08, 1.75, -cart.d / 2 + 0.08);
box(0.07, 0.4, 0.07, materials.ink, cart.group, cart.w / 2 - 0.08, 1.75, -cart.d / 2 + 0.08);
} else if (cart.type === "low") {
const deck = box(
cart.w,
0.16,
cart.d,
accent,
cart.group,
0,
0.51,
0
);
addEdges(deck);
for (const px of [-cart.w / 2 + 0.06, cart.w / 2 - 0.06]) {
for (const pz of [-cart.d / 2 + 0.06, cart.d / 2 - 0.06]) {
box(0.065, 0.3, 0.065, materials.metal, cart.group, px, 0.69, pz);
}
}
box(cart.w - 0.12, 0.06, 0.06, materials.ink, cart.group, 0, 0.84, -cart.d / 2 + 0.06);
box(cart.w * 0.64, 0.12, cart.d * 0.7, accentLight, cart.group, -0.08, 0.65, 0);
} else {
const base = box(cart.w, 0.09, cart.d, materials.ink, cart.group, 0, 0.43, 0);
addEdges(base);
const bin = box(cart.w - 0.08, 0.78, cart.d - 0.07, accentLight, cart.group, 0, 0.87, 0);
addEdges(bin);
const lid = box(cart.w + 0.06, 0.09, cart.d + 0.04, accent, cart.group, 0, 1.3, 0);
addEdges(lid);
box(0.48, 0.05, 0.07, materials.ink, cart.group, 0, 1.37, 0);
box(0.065, 0.28, 0.065, materials.ink, cart.group, -0.42, 1.5, -0.18);
box(0.065, 0.28, 0.065, materials.ink, cart.group, 0.42, 1.5, -0.18);
box(0.9, 0.06, 0.06, materials.ink, cart.group, 0, 1.64, -0.18);
}
const positions = [
[-cart.w / 2 + 0.13, cart.d / 2 - 0.12],
[cart.w / 2 - 0.13, cart.d / 2 - 0.12],
[cart.w / 2 - 0.13, -cart.d / 2 + 0.12],
[-cart.w / 2 + 0.13, -cart.d / 2 + 0.12]
];
positions.forEach(([x, z], index) => makeCaster(cart, index, x, z));
carts.push(cart);
return cart;
}
createCart({
id: "C-01",
name: "Linen utility cart",
short: "Linen",
type: "tall",
x: -5.0,
z: 2.65,
rot: 0.1,
bay: 0,
w: 1.18,
d: 0.72
});
createCart({
id: "C-02",
name: "Low platform trolley",
short: "Platform",
type: "low",
x: -2.7,
z: 2.85,
rot: -0.12,
bay: 1,
w: 1.52,
d: 0.84
});
createCart({
id: "C-03",
name: "Material bin cart",
short: "Material",
type: "bin",
x: 2.75,
z: 2.75,
rot: 0.16,
bay: 2,
w: 1.03,
d: 0.7
});
// Selection outline around the active cart.
const selectionHelper = new THREE.BoxHelper(carts[0].group, colors.teal);
selectionHelper.material.transparent = true;
selectionHelper.material.opacity = 0.72;
selectionHelper.material.depthTest = false;
selectionHelper.renderOrder = 10;
scene.add(selectionHelper);
let selectedCart = carts[0];
let wheelListCartId = null;
let wasComplete = false;
let toastTimer;
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastElement.classList.remove("visible");
}, 2400);
}
// UI construction.
const faceListElement = document.getElementById("faceList");
const cartTabsElement = document.getElementById("cartTabs");
const wheelListElement = document.getElementById("wheelList");
faces.forEach((face) => {
const button = document.createElement("button");
button.className = "face-option selected";
button.type = "button";
button.innerHTML = `
<span class="face-code">${face.id}</span>
<span>
<span class="face-name">${face.name}</span>
<span class="face-sub">Storage face ${face.id}</span>
</span>
<span class="face-state">Open</span>
`;
button.addEventListener("click", () => toggleFace(face));
face.button = button;
faceListElement.appendChild(button);
});
carts.forEach((cart) => {
const button = document.createElement("button");
button.className = "cart-tab";
button.type = "button";
button.innerHTML = `
<strong>${cart.id}</strong>
<span>${cart.short}</span>
`;
button.addEventListener("click", () => selectCart(cart));
cart.tab = button;
cartTabsElement.appendChild(button);
});
function toggleFace(face) {
face.selected = !face.selected;
updateUI();
showToast(
`${face.id} ${face.selected ? "included in" : "removed from"} the access plan.`
);
}
function selectCart(cart) {
selectedCart = cart;
updateUI();
}
function cartFootprint(cart) {
const halfX = cart.w / 2;
const halfZ = cart.d / 2;
const angle = cart.group.rotation.y;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const centerX = cart.group.position.x;
const centerZ = cart.group.position.z;
return [
[-halfX, -halfZ],
[halfX, -halfZ],
[halfX, halfZ],
[-halfX, halfZ]
].map(([x, z]) => ({
x: centerX + x * cos + z * sin,
z: centerZ - x * sin + z * cos
}));
}
function faceRectangle(face) {
return [
{ x: face.x - face.halfWidth, z: face.zMin },
{ x: face.x + face.halfWidth, z: face.zMin },
{ x: face.x + face.halfWidth, z: face.zMax },
{ x: face.x - face.halfWidth, z: face.zMax }
];
}
function polygonsOverlap(polygonA, polygonB) {
function overlapsOnAxis(axis, a, b) {
let minA = Infinity;
let maxA = -Infinity;
let minB = Infinity;
let maxB = -Infinity;
a.forEach((point) => {
const projection = point.x * axis.x + point.z * axis.z;
minA = Math.min(minA, projection);
maxA = Math.max(maxA, projection);
});
b.forEach((point) => {
const projection = point.x * axis.x + point.z * axis.z;
minB = Math.min(minB, projection);
maxB = Math.max(maxB, projection);
});
return !(maxA <= minB + 0.0001 || maxB <= minA + 0.0001);
}
for (const polygon of [polygonA, polygonB]) {
for (let i = 0; i < polygon.length; i++) {
const p1 = polygon[i];
const p2 = polygon[(i + 1) % polygon.length];
const edgeX = p2.x - p1.x;
const edgeZ = p2.z - p1.z;
const length = Math.hypot(edgeX, edgeZ) || 1;
const axis = { x: -edgeZ / length, z: edgeX / length };
if (!overlapsOnAxis(axis, polygonA, polygonB)) {
return false;
}
}
}
return true;
}
function faceIsClear(face) {
const rectangle = faceRectangle(face);
return !carts.some((cart) =>
polygonsOverlap(cartFootprint(cart), rectangle)
);
}
function cartIsParked(cart) {
const bay = bays[cart.bay];
return (
Math.abs(cart.group.position.x - bay.x) < 0.52 &&
Math.abs(cart.group.position.z - bay.z) < 0.52
);
}
function lockedCount(cart) {
return cart.wheels.filter((wheel) => wheel.locked).length;
}
function evaluatePlan() {
const selectedFaces = faces.filter((face) => face.selected);
const clearFaces = selectedFaces.filter(faceIsClear);
const parkedCarts = carts.filter(cartIsParked);
const lockedCarts = carts.filter((cart) => lockedCount(cart) === 4);
const complete =
selectedFaces.length > 0 &&
clearFaces.length === selectedFaces.length &&
parkedCarts.length === carts.length &&
lockedCarts.length === carts.length;
return {
selectedFaces,
clearFaces,
parkedCarts,
lockedCarts,
complete
};
}
function setDot(element, state) {
element.classList.remove("good", "bad");
if (state === "good") element.classList.add("good");
if (state === "bad") element.classList.add("bad");
}
function renderWheelButtons() {
if (wheelListCartId === selectedCart.id) return;
wheelListCartId = selectedCart.id;
wheelListElement.innerHTML = "";
selectedCart.wheels.forEach((wheel) => {
const button = document.createElement("button");
button.className = "wheel-button";
button.type = "button";
button.dataset.wheelIndex = String(wheel.index);
button.innerHTML = `
<span class="wheel-icon">◉</span>
<strong>${wheel.name}</strong>
<em>Released</em>
`;
button.addEventListener("click", () => {
wheel.locked = !wheel.locked;
updateUI();
});
wheel.button = button;
wheelListElement.appendChild(button);
});
}
function updateUI() {
const result = evaluatePlan();
const selectedCount = result.selectedFaces.length;
const clearCount = result.clearFaces.length;
const parkedCount = result.parkedCarts.length;
const fullyLockedCount = result.lockedCarts.length;
faces.forEach((face) => {
const clear = faceIsClear(face);
face.zone.visible = face.selected;
face.zoneBorder.visible = face.selected;
const color = clear ? colors.teal : colors.coral;
face.zone.material.color.setHex(color);
face.zoneBorder.material.color.setHex(color);
face.panel.material.color.setHex(
face.selected ? (clear ? colors.tealLight : colors.coralLight) : 0xd9ddd4
);
face.outline.material.color.setHex(
face.selected ? color : 0x84918b
);
face.outline.material.opacity = face.selected ? 0.9 : 0.3;
face.button.classList.toggle("selected", face.selected);
face.button.classList.toggle("blocked", face.selected && !clear);
face.button.querySelector(".face-state").textContent = !face.selected
? "Not checked"
: clear
? "Open"
: "Blocked";
});
document.getElementById("faceCount").textContent =
`${selectedCount} checked`;
document.getElementById("facesValue").textContent =
`${clearCount} / ${selectedCount}`;
document.getElementById("parkedValue").textContent =
`${parkedCount} / ${carts.length}`;
document.getElementById("lockedValue").textContent =
`${fullyLockedCount} / ${carts.length}`;
setDot(
document.getElementById("facesDot"),
clearCount === selectedCount && selectedCount > 0 ? "good" : "bad"
);
setDot(
document.getElementById("parkedDot"),
parkedCount === carts.length ? "good" : "bad"
);
setDot(
document.getElementById("lockedDot"),
fullyLockedCount === carts.length ? "good" : "bad"
);
carts.forEach((cart) => {
cart.tab.classList.toggle("active", cart.id === selectedCart.id);
});
const selectedLocked = lockedCount(selectedCart);
const selectedParked = cartIsParked(selectedCart);
const status = document.getElementById("cartStatus");
status.classList.remove("good", "bad");
if (selectedParked && selectedLocked === 4) {
status.textContent = "Ready";
status.classList.add("good");
} else if (!selectedParked) {
status.textContent = "Unparked";
status.classList.add("bad");
} else {
status.textContent = "Not secured";
}
document.getElementById("cartName").textContent = selectedCart.name;
document.getElementById("cartPosition").textContent =
`X ${selectedCart.group.position.x.toFixed(1)} / Z ${selectedCart.group.position.z.toFixed(1)}`;
document.getElementById("cartBay").textContent =
bays[selectedCart.bay].id;
document.getElementById("parkCart").textContent =
`Park in ${bays[selectedCart.bay].id}`;
document.getElementById("lockCart").textContent =
selectedLocked === 4 ? "Release 4 brakes" : "Lock 4 casters";
document.getElementById("wheelCount").textContent =
`${selectedLocked} / 4 locked`;
renderWheelButtons();
selectedCart.wheels.forEach((wheel) => {
wheel.button.classList.toggle("locked", wheel.locked);
wheel.button.querySelector("em").textContent = wheel.locked
? "Engaged"
: "Released";
wheel.button.querySelector(".wheel-icon").textContent = wheel.locked
? "✓"
: "◉";
});
document.getElementById("goalDetail").textContent =
`${clearCount} / ${selectedCount} faces open · ` +
`${parkedCount} / ${carts.length} carts parked · ` +
`${fullyLockedCount} / ${carts.length} brakes locked`;
const totalTasks = selectedCount + carts.length * 2;
const completedTasks = clearCount + parkedCount + fullyLockedCount;
const progress = totalTasks ? (completedTasks / totalTasks) * 100 : 0;
document.getElementById("progressFill").style.width = `${progress}%`;
document.body.classList.toggle("complete", result.complete);
const badge = document.getElementById("goalBadge");
badge.textContent = result.complete ? "Plan complete" : "In progress";
document.getElementById("goalTitle").textContent = result.complete
? "All selected storage faces remain accessible"
: "Keep the selected storage faces accessible";
if (result.complete && !wasComplete) {
showToast("Plan complete — every selected face is accessible.");
}
wasComplete = result.complete;
}
function moveCartToBay(cart) {
const bay = bays[cart.bay];
cart.motion = {
start: performance.now(),
duration: 680,
fromX: cart.group.position.x,
fromZ: cart.group.position.z,
fromRotation: cart.group.rotation.y,
toX: bay.x,
toZ: bay.z,
toRotation: 0
};
showToast(`${cart.id} moving to ${bay.id}.`);
}
function toggleCartLocks(cart) {
const shouldLock = lockedCount(cart) !== 4;
cart.wheels.forEach((wheel) => {
wheel.locked = shouldLock;
});
updateUI();
showToast(
shouldLock
? `${cart.id}: all four caster brakes engaged.`
: `${cart.id}: all caster brakes released.`
);
}
document.getElementById("parkCart").addEventListener("click", () => {
moveCartToBay(selectedCart);
});
document.getElementById("lockCart").addEventListener("click", () => {
toggleCartLocks(selectedCart);
});
document.getElementById("focusCart").addEventListener("click", () => {
orbit.target.set(
selectedCart.group.position.x,
0.48,
selectedCart.group.position.z
);
orbit.theta = 0.76;
orbit.phi = 0.78;
orbit.zoom = 1.75;
updateCamera();
showToast("Caster detail view — click a wheel to toggle its brake.");
});
document.getElementById("isoView").addEventListener("click", () => {
orbit.target.set(0.15, 0.55, -0.25);
orbit.theta = 0.72;
orbit.phi = 0.72;
orbit.zoom = 1;
updateCamera();
});
document.getElementById("topView").addEventListener("click", () => {
orbit.target.set(0.15, 0.25, -0.25);
orbit.theta = 0.02;
orbit.phi = 0.14;
orbit.zoom = 1;
updateCamera();
});
document.getElementById("resetPlan").addEventListener("click", () => {
faces.forEach((face) => {
face.selected = true;
});
const initial = [
[-5.0, 2.65, 0.1],
[-2.7, 2.85, -0.12],
[2.75, 2.75, 0.16]
];
carts.forEach((cart, index) => {
cart.motion = null;
cart.group.position.set(initial[index][0], 0, initial[index][1]);
cart.group.rotation.y = initial[index][2];
cart.wheels.forEach((wheel) => {
wheel.locked = false;
});
});
selectedCart = carts[0];
orbit.target.set(0.15, 0.55, -0.25);
orbit.theta = 0.72;
orbit.phi = 0.72;
orbit.zoom = 1;
updateCamera();
updateUI();
showToast("Exhibit reset. Park and lock all three carts.");
});
// Direct pointer interaction and camera controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const groundPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const groundPoint = new THREE.Vector3();
let pointerMode = null;
let pointerStart = null;
let lastPointer = null;
let dragData = null;
function updatePointer(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;
raycaster.setFromCamera(pointer, camera);
}
function findInteractive(object) {
let current = object;
while (current) {
if (
current.userData.kind === "face" ||
current.userData.kind === "cart" ||
current.userData.kind === "wheel" ||
current.userData.kind === "bay"
) {
return current;
}
current = current.parent;
}
return null;
}
function pickInteractive(event) {
updatePointer(event);
const intersections = raycaster.intersectObjects(scene.children, true);
for (const intersection of intersections) {
const interactive = findInteractive(intersection.object);
if (interactive) return interactive;
}
return null;
}
function rayToGround(event) {
updatePointer(event);
return raycaster.ray.intersectPlane(groundPlane, groundPoint)
? groundPoint
: null;
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 1 && event.button !== 2) return;
renderer.domElement.setPointerCapture(event.pointerId);
pointerStart = { x: event.clientX, y: event.clientY };
lastPointer = { x: event.clientX, y: event.clientY };
dragData = null;
const hit = event.button === 0 ? pickInteractive(event) : null;
if (event.button === 0 && hit?.userData.kind === "cart") {
const cart = hit.userData.cart;
selectCart(cart);
const point = rayToGround(event);
if (point) {
pointerMode = "cart";
dragData = {
cart,
offsetX: cart.group.position.x - point.x,
offsetZ: cart.group.position.z - point.z
};
cart.motion = null;
}
} else if (
event.button === 0 &&
(hit?.userData.kind === "face" ||
hit?.userData.kind === "wheel" ||
hit?.userData.kind === "bay")
) {
pointerMode = hit.userData.kind;
} else {
pointerMode = "orbit";
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerMode === "orbit" && lastPointer) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.12, 1.28);
updateCamera();
} else if (pointerMode === "cart" && dragData) {
const point = rayToGround(event);
if (!point) return;
const cart = dragData.cart;
cart.group.position.x = THREE.MathUtils.clamp(
point.x + dragData.offsetX,
-6.15,
6.15
);
cart.group.position.z = THREE.MathUtils.clamp(
point.z + dragData.offsetZ,
-4.25,
4.25
);
updateUI();
} else if (!pointerMode) {
const hit = pickInteractive(event);
renderer.domElement.style.cursor = hit
? hit.userData.kind === "cart"
? "grab"
: "pointer"
: "default";
}
lastPointer = { x: event.clientX, y: event.clientY };
});
renderer.domElement.addEventListener("pointerup", (event) => {
const moved =
pointerStart &&
Math.hypot(
event.clientX - pointerStart.x,
event.clientY - pointerStart.y
) > 6;
if (!moved) {
if (pointerMode === "face") {
const hit = pickInteractive(event);
if (hit?.userData.kind === "face") toggleFace(hit.userData.face);
} else if (pointerMode === "wheel") {
const hit = pickInteractive(event);
if (hit?.userData.kind === "wheel") {
const wheel = hit.userData.cart.wheels[hit.userData.wheelIndex];
wheel.locked = !wheel.locked;
selectCart(hit.userData.cart);
updateUI();
showToast(
`${hit.userData.cart.id} · ${wheel.name}: ${
wheel.locked ? "brake engaged" : "brake released"
}.`
);
}
} else if (pointerMode === "bay") {
const hit = pickInteractive(event);
if (hit?.userData.kind === "bay") {
const bay = bays[hit.userData.bayIndex];
const assignedCart = carts.find((cart) => cart.bay === bay.index);
if (assignedCart) {
selectCart(assignedCart);
showToast(`${bay.id} is assigned to ${assignedCart.id}.`);
}
}
}
}
if (pointerMode === "cart" && dragData && !moved) {
const bay = bays[dragData.cart.bay];
const distance = Math.hypot(
dragData.cart.group.position.x - bay.x,
dragData.cart.group.position.z - bay.z
);
if (distance < 0.68) {
dragData.cart.group.position.set(bay.x, 0, bay.z);
dragData.cart.group.rotation.y = 0;
showToast(`${dragData.cart.id} snapped into ${bay.id}.`);
}
}
pointerMode = null;
pointerStart = null;
lastPointer = null;
dragData = null;
renderer.domElement.style.cursor = "default";
updateUI();
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerMode = null;
pointerStart = null;
lastPointer = null;
dragData = null;
updateUI();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.25
);
updateCamera();
},
{ passive: false }
);
// Animation.
function animate(time) {
let planChanged = false;
carts.forEach((cart) => {
if (cart.motion) {
const t = Math.min((time - cart.motion.start) / cart.motion.duration, 1);
const eased = 1 - Math.pow(1 - t, 3);
cart.group.position.x =
cart.motion.fromX +
(cart.motion.toX - cart.motion.fromX) * eased;
cart.group.position.z =
cart.motion.fromZ +
(cart.motion.toZ - cart.motion.fromZ) * eased;
cart.group.rotation.y =
cart.motion.fromRotation +
(cart.motion.toRotation - cart.motion.fromRotation) * eased;
if (t >= 1) {
cart.group.position.set(cart.motion.toX, 0, cart.motion.toZ);
cart.group.rotation.y = cart.motion.toRotation;
cart.motion = null;
}
planChanged = true;
}
cart.wheels.forEach((wheel) => {
const target = wheel.locked ? 0.78 : -0.65;
wheel.pedalPivot.rotation.x +=
(target - wheel.pedalPivot.rotation.x) * 0.16;
const targetColor = wheel.locked ? colors.teal : colors.coral;
wheel.pedalMaterial.color.lerp(
new THREE.Color(targetColor),
0.16
);
});
});
if (planChanged) updateUI();
selectionHelper.setFromObject(selectedCart.group);
renderer.render(scene, camera);
}
updateUI();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hide");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```