Prompt specification
Build or customize the Three.js 3D scene "Wayfinding through a clinic lobby" 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: Wayfinding through a clinic lobby
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wayfinding-through-a-clinic-lobby-x0415
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows high-contrast wayfinding signs. Build a nonclinical lobby model with distinct service zones, arrows, and floor bands; users follow a selected destination using redundant shape and text cues. Voxel style.
Working Three.js Starter (wayfinding-through-a-clinic-lobby-x0415):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#07131d">
<title>Community Commons — Voxel Wayfinding</title>
<style>
:root {
--bg: #07131d;
--panel: rgba(7, 19, 29, 0.92);
--panel-soft: rgba(12, 30, 43, 0.82);
--line: rgba(255, 255, 255, 0.16);
--text: #f7fbff;
--muted: #9db2c2;
--cyan: #43e4df;
--active: #ff7548;
--shadow: 0 18px 55px rgba(0, 0, 0, 0.36);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
#scene.pickable {
cursor: pointer;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.interactive {
pointer-events: auto;
}
.masthead {
position: absolute;
top: 22px;
left: 24px;
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
width: 43px;
height: 43px;
display: grid;
place-items: center;
border: 1px solid rgba(67, 228, 223, 0.55);
background: rgba(7, 19, 29, 0.82);
box-shadow: inset 0 0 22px rgba(67, 228, 223, 0.08);
color: var(--cyan);
font: 800 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.eyebrow {
margin: 0 0 4px;
color: var(--cyan);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.masthead h1 {
margin: 0;
font-size: clamp(17px, 2vw, 24px);
line-height: 1;
letter-spacing: -0.025em;
}
.status-pill {
position: absolute;
top: 24px;
right: 24px;
min-width: 245px;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 15px;
border: 1px solid var(--line);
border-left: 4px solid var(--active);
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
background: var(--active);
box-shadow: 0 0 0 5px color-mix(in srgb, var(--active) 18%, transparent);
}
.status-copy {
min-width: 0;
}
.status-copy small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.status-copy strong {
display: block;
overflow: hidden;
color: #fff;
font-size: 13px;
line-height: 1.2;
text-overflow: ellipsis;
white-space: nowrap;
}
.panel {
position: absolute;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.destination-panel {
left: 24px;
bottom: 24px;
width: 338px;
padding: 16px;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 15px;
margin-bottom: 13px;
}
.panel-heading h2,
.route-card h2 {
margin: 0;
font-size: 15px;
line-height: 1.2;
letter-spacing: -0.01em;
}
.panel-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.destination-count {
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
.destination-list {
display: grid;
gap: 7px;
}
.destination-button {
--accent: #ffffff;
width: 100%;
min-height: 51px;
display: grid;
grid-template-columns: 38px minmax(0, 1fr) auto;
align-items: center;
gap: 11px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.11);
background: rgba(255, 255, 255, 0.035);
color: var(--text);
text-align: left;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.destination-button:hover {
border-color: color-mix(in srgb, var(--accent) 65%, white 10%);
background: color-mix(in srgb, var(--accent) 9%, transparent);
transform: translateX(2px);
}
.destination-button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.destination-button.active {
border-color: var(--accent);
background: color-mix(in srgb, var(--accent) 13%, transparent);
box-shadow: inset 3px 0 0 var(--accent);
}
.glyph {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border: 1px solid color-mix(in srgb, var(--accent) 58%, transparent);
background: color-mix(in srgb, var(--accent) 10%, transparent);
color: var(--accent);
}
.glyph svg {
width: 23px;
height: 23px;
overflow: visible;
}
.destination-label {
min-width: 0;
}
.destination-label strong {
display: block;
overflow: hidden;
font-size: 12px;
line-height: 1.2;
text-overflow: ellipsis;
white-space: nowrap;
}
.destination-label small {
display: block;
margin-top: 3px;
overflow: hidden;
color: var(--muted);
font: 600 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
text-overflow: ellipsis;
white-space: nowrap;
}
.zone-code {
min-width: 28px;
color: var(--accent);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
.route-card {
right: 24px;
bottom: 24px;
width: 316px;
padding: 16px;
}
.route-header {
display: flex;
align-items: center;
gap: 13px;
margin-bottom: 13px;
}
.route-header .glyph {
width: 44px;
height: 44px;
flex: 0 0 auto;
}
.route-header .glyph svg {
width: 27px;
height: 27px;
}
.route-kicker {
margin: 0 0 4px;
color: var(--active);
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.route-meta {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
}
.route-steps {
display: grid;
gap: 5px;
margin: 0 0 13px;
padding: 0;
list-style: none;
}
.route-step {
display: grid;
grid-template-columns: 25px 24px minmax(0, 1fr);
align-items: center;
gap: 7px;
min-height: 31px;
padding: 5px 7px;
border: 1px solid rgba(255, 255, 255, 0.08);
background: rgba(255, 255, 255, 0.035);
color: #e7f0f6;
font-size: 10px;
}
.step-number {
color: #6f8798;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.step-arrow {
color: var(--active);
font-size: 18px;
font-weight: 900;
line-height: 1;
text-align: center;
}
.route-hint {
margin: 0;
padding: 10px 11px;
border-left: 3px solid var(--active);
background: rgba(255, 255, 255, 0.045);
color: #b8c8d3;
font-size: 10px;
line-height: 1.45;
}
.camera-tools {
position: absolute;
right: 24px;
top: 88px;
display: flex;
gap: 6px;
}
.tool-button {
width: 35px;
height: 35px;
border: 1px solid var(--line);
background: var(--panel-soft);
color: #dce9f1;
font: 800 16px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
backdrop-filter: blur(12px);
}
.tool-button:hover {
border-color: var(--cyan);
color: var(--cyan);
}
.tool-button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.cue-key {
position: absolute;
left: 50%;
bottom: 27px;
display: flex;
align-items: center;
gap: 15px;
transform: translateX(-50%);
padding: 9px 13px;
border: 1px solid var(--line);
background: rgba(7, 19, 29, 0.76);
color: #afc0cc;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
backdrop-filter: blur(12px);
}
.cue-key span {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.key-band {
width: 21px;
height: 7px;
background: var(--active);
}
.key-arrow {
color: #fff;
font-size: 16px;
line-height: 7px;
}
.key-shape {
width: 12px;
height: 12px;
border: 2px solid var(--active);
transform: rotate(45deg);
}
.controls-hint {
position: absolute;
left: 50%;
top: 24px;
transform: translateX(-50%);
color: rgba(212, 229, 239, 0.65);
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #07131d;
color: #dceaf2;
transition: opacity 350ms ease, visibility 350ms ease;
}
#loading.hidden {
visibility: hidden;
opacity: 0;
}
.loading-content {
text-align: center;
}
.loading-grid {
width: 66px;
height: 66px;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
margin: 0 auto 19px;
}
.loading-grid i {
background: #43e4df;
animation: loadPulse 900ms ease-in-out infinite alternate;
}
.loading-grid i:nth-child(2) { animation-delay: 120ms; }
.loading-grid i:nth-child(3) { animation-delay: 240ms; }
.loading-grid i:nth-child(4) { animation-delay: 360ms; }
.loading-grid i:nth-child(5) { animation-delay: 480ms; }
.loading-grid i:nth-child(6) { animation-delay: 600ms; }
.loading-content strong {
display: block;
font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
}
.loading-content small {
display: block;
margin-top: 8px;
color: #7790a1;
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
@keyframes loadPulse {
from { opacity: 0.18; transform: scale(0.8); }
to { opacity: 1; transform: scale(1); }
}
@media (max-width: 1120px) {
.cue-key,
.controls-hint {
display: none;
}
}
@media (max-width: 820px) {
.masthead {
top: 14px;
left: 14px;
}
.brand-mark {
width: 38px;
height: 38px;
}
.status-pill {
top: 14px;
right: 14px;
min-width: 0;
max-width: calc(100vw - 180px);
}
.status-copy strong {
max-width: 145px;
}
.camera-tools {
top: 68px;
right: 14px;
}
.route-card {
top: 111px;
right: 14px;
bottom: auto;
width: 244px;
padding: 12px;
}
.route-header {
margin-bottom: 9px;
}
.route-header .glyph {
width: 36px;
height: 36px;
}
.route-steps {
gap: 3px;
margin-bottom: 9px;
}
.route-step {
min-height: 27px;
padding: 4px 5px;
}
.destination-panel {
left: 14px;
right: 14px;
bottom: 14px;
width: auto;
padding: 11px;
}
.panel-heading {
margin-bottom: 8px;
}
.destination-list {
display: flex;
overflow-x: auto;
padding-bottom: 3px;
scrollbar-width: thin;
}
.destination-button {
min-width: 184px;
}
.destination-button:hover {
transform: none;
}
}
@media (max-width: 520px) {
.masthead h1 {
font-size: 16px;
}
.masthead .eyebrow {
font-size: 8px;
}
.status-pill {
padding: 9px 10px;
}
.status-copy small {
display: none;
}
.status-copy strong {
max-width: 110px;
font-size: 11px;
}
.route-card {
width: 214px;
}
.route-hint {
display: none;
}
.route-step {
grid-template-columns: 18px 20px minmax(0, 1fr);
gap: 4px;
font-size: 9px;
}
.panel-heading p {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive three-dimensional community lobby wayfinding map"
tabindex="0"
></canvas>
<div class="hud">
<header class="masthead">
<div class="brand-mark" aria-hidden="true">CC</div>
<div>
<p class="eyebrow">Community Commons</p>
<h1>Lobby Wayfinding</h1>
</div>
</header>
<div class="status-pill" id="statusPill" aria-live="polite">
<span class="status-dot" aria-hidden="true"></span>
<div class="status-copy">
<small>Selected destination</small>
<strong id="statusLabel">Welcome desk</strong>
</div>
</div>
<div class="controls-hint" aria-hidden="true">
Drag to orbit · Scroll to zoom · R to reset
</div>
<div class="camera-tools interactive" aria-label="Camera controls">
<button class="tool-button" id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button class="tool-button" id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button class="tool-button" id="resetView" type="button" aria-label="Reset camera">↺</button>
</div>
<section class="panel destination-panel interactive" aria-labelledby="destinationHeading">
<div class="panel-heading">
<div>
<h2 id="destinationHeading">Choose a destination</h2>
<p>Select a zone or click it directly in the lobby.</p>
</div>
<span class="destination-count">05 ZONES</span>
</div>
<div class="destination-list" id="destinationList"></div>
</section>
<section class="panel route-card interactive" aria-labelledby="routeName">
<div class="route-header">
<div class="glyph" id="routeGlyph" aria-hidden="true"></div>
<div>
<p class="route-kicker" id="routeKicker">Route to Zone A</p>
<h2 id="routeName">Welcome desk</h2>
<p class="route-meta" id="routeMeta"></p>
</div>
</div>
<ol class="route-steps" id="routeSteps"></ol>
<p class="route-hint" id="routeHint"></p>
</section>
<div class="cue-key" aria-hidden="true">
<span><i class="key-band"></i> COLOR BAND</span>
<span><i class="key-arrow">↑</i> DIRECTION</span>
<span><i class="key-shape"></i> SHAPE + TEXT</span>
</div>
</div>
<div id="loading">
<div class="loading-content">
<div class="loading-grid" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<strong>ASSEMBLING LOBBY</strong>
<small>LOADING VOXEL WAYFINDING</small>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Core scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.Fog(0x07131d, 46, 78);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.1, 0);
const cameraState = {
theta: 0.67,
phi: 0.92,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xeaf8ff, 0x263743, 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3dc, 3.1);
sun.position.set(-13, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.0007;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x59cfff, 1.1);
rimLight.position.set(15, 11, -16);
scene.add(rimLight);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function makeBox(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene,
castShadow = true,
receiveShadow = true
) {
const resolvedMaterial =
material && typeof material === "object"
? material
: getMaterial(material);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
resolvedMaterial
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => material.dispose());
}
});
}
}
// -------------------------------------------------------------------------
// Destination data
// -------------------------------------------------------------------------
const destinations = {
welcome: {
id: "welcome",
label: "WELCOME DESK",
title: "Welcome desk",
subtitle: "CIVIC SERVICES",
code: "A",
color: 0xff7548,
css: "#ff7548",
shape: "square",
center: [-9, -6],
sign: [-9, -3.45],
route: [
[0, 8],
[0, 0],
[-4, 0],
[-4, -4.2],
[-8, -4.2]
],
steps: [
{ arrow: "↑", text: "Continue to the central junction" },
{ arrow: "↰", text: "Turn left into Zone A" },
{ arrow: "↱", text: "Turn right toward the desk" },
{ arrow: "◆", text: "Welcome desk ahead" }
],
turns: 2
},
help: {
id: "help",
label: "VISITOR HELP",
title: "Visitor help",
subtitle: "INFORMATION",
code: "B",
color: 0xa977ff,
css: "#a977ff",
shape: "diamond",
center: [9, -6],
sign: [9, -3.45],
route: [
[0, 8],
[0, 0],
[4, 0],
[4, -4.2],
[8, -4.2]
],
steps: [
{ arrow: "↑", text: "Continue to the central junction" },
{ arrow: "↱", text: "Turn right into Zone B" },
{ arrow: "↰", text: "Turn left toward the desk" },
{ arrow: "◆", text: "Visitor help ahead" }
],
turns: 2
},
restrooms: {
id: "restrooms",
label: "RESTROOMS",
title: "Restrooms",
subtitle: "PUBLIC AMENITIES",
code: "C",
color: 0x38a8ff,
css: "#38a8ff",
shape: "circle",
center: [-9, 5],
sign: [-9, 7.25],
route: [
[0, 8],
[0, 0],
[-4, 0],
[-4, 3.8],
[-8, 3.8]
],
steps: [
{ arrow: "↑", text: "Continue to the central junction" },
{ arrow: "↰", text: "Turn left toward Zone C" },
{ arrow: "↰", text: "Turn left at the blue band" },
{ arrow: "●", text: "Restrooms are directly ahead" }
],
turns: 2
},
workspace: {
id: "workspace",
label: "CO-WORK STUDIO",
title: "Co-work studio",
subtitle: "SHARED WORKSPACE",
code: "D",
color: 0x58d977,
css: "#58d977",
shape: "triangle",
center: [9, 5],
sign: [9, 7.25],
route: [
[0, 8],
[0, 0],
[4, 0],
[4, 3.8],
[8, 3.8]
],
steps: [
{ arrow: "↑", text: "Continue to the central junction" },
{ arrow: "↱", text: "Turn right toward Zone D" },
{ arrow: "↱", text: "Turn right at the green band" },
{ arrow: "▲", text: "Co-work studio is directly ahead" }
],
turns: 2
},
cafe: {
id: "cafe",
label: "COMMONS CAFÉ",
title: "Commons café",
subtitle: "FOOD + DRINK",
code: "E",
color: 0xffca4b,
css: "#ffca4b",
shape: "hexagon",
center: [0, -7],
sign: [2.25, -6.5],
route: [
[0, 8],
[0, 0],
[0, -5.3]
],
steps: [
{ arrow: "↑", text: "Continue straight through the junction" },
{ arrow: "↑", text: "Follow the yellow floor band" },
{ arrow: "⬡", text: "Commons café ahead" }
],
turns: 0
}
};
const destinationOrder = [
"welcome",
"help",
"restrooms",
"workspace",
"cafe"
];
const pickables = [];
const zoneFrames = {};
const iconObjects = [];
// -------------------------------------------------------------------------
// Label textures
// -------------------------------------------------------------------------
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function drawShape(ctx, shape, x, y, radius) {
ctx.save();
ctx.fillStyle = "#07131d";
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = 6;
ctx.lineJoin = "miter";
if (shape === "square") {
ctx.fillRect(x - radius * 0.8, y - radius * 0.8, radius * 1.6, radius * 1.6);
ctx.strokeRect(x - radius * 0.8, y - radius * 0.8, radius * 1.6, radius * 1.6);
} else if (shape === "diamond") {
ctx.beginPath();
ctx.moveTo(x, y - radius);
ctx.lineTo(x + radius, y);
ctx.lineTo(x, y + radius);
ctx.lineTo(x - radius, y);
ctx.closePath();
ctx.fill();
ctx.stroke();
} else if (shape === "circle") {
ctx.beginPath();
ctx.arc(x, y, radius * 0.9, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
} else if (shape === "triangle") {
ctx.beginPath();
ctx.moveTo(x, y - radius);
ctx.lineTo(x + radius, y + radius * 0.8);
ctx.lineTo(x - radius, y + radius * 0.8);
ctx.closePath();
ctx.fill();
ctx.stroke();
} else if (shape === "hexagon") {
ctx.beginPath();
ctx.moveTo(x - radius * 0.45, y - radius);
ctx.lineTo(x + radius * 0.45, y - radius);
ctx.lineTo(x + radius, y);
ctx.lineTo(x + radius * 0.45, y + radius);
ctx.lineTo(x - radius * 0.45, y + radius);
ctx.lineTo(x - radius, y);
ctx.closePath();
ctx.fill();
ctx.stroke();
}
ctx.restore();
}
function createLabelTexture(destination) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
roundedRectPath(ctx, 8, 8, 1008, 240, 26);
ctx.fillStyle = "rgba(5, 15, 24, 0.96)";
ctx.fill();
ctx.strokeStyle = destination.css;
ctx.lineWidth = 9;
ctx.stroke();
roundedRectPath(ctx, 24, 24, 218, 208, 17);
ctx.fillStyle = destination.css;
ctx.fill();
drawShape(ctx, destination.shape, 133, 128, 58);
ctx.fillStyle = destination.css;
ctx.font = "800 24px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "right";
ctx.fillText(`ZONE ${destination.code}`, 980, 48);
ctx.textAlign = "left";
ctx.fillStyle = "#ffffff";
let fontSize = 58;
ctx.font = `800 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, monospace`;
while (ctx.measureText(destination.label).width > 700 && fontSize > 34) {
fontSize -= 2;
ctx.font = `800 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, monospace`;
}
ctx.fillText(destination.label, 285, 116);
ctx.fillStyle = "#a9bdca";
ctx.font = "700 25px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(destination.subtitle, 287, 172);
ctx.fillStyle = destination.css;
ctx.fillRect(285, 198, 170, 7);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = true;
return texture;
}
function createBadgeTexture(color) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
roundedRectPath(ctx, 5, 5, 502, 118, 20);
ctx.fillStyle = color;
ctx.fill();
ctx.strokeStyle = "#ffffff";
ctx.lineWidth = 8;
ctx.stroke();
ctx.fillStyle = "#07131d";
ctx.font = "900 52px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("SELECTED", 256, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function createGroundLabelTexture() {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
roundedRectPath(ctx, 8, 8, 752, 176, 25);
ctx.fillStyle = "rgba(7, 19, 29, 0.92)";
ctx.fill();
ctx.strokeStyle = "#43e4df";
ctx.lineWidth = 8;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#ffffff";
ctx.font = "900 49px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText("YOU ARE HERE", 384, 78);
ctx.fillStyle = "#43e4df";
ctx.font = "800 23px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText("ENTRANCE", 384, 132);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function createSprite(texture, width, height) {
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Voxel icons
// -------------------------------------------------------------------------
function createVoxelIcon(destination) {
const group = new THREE.Group();
const iconMaterial = new THREE.MeshStandardMaterial({
color: destination.color,
emissive: new THREE.Color(destination.color).multiplyScalar(0.22),
roughness: 0.48,
metalness: 0.08
});
const add = (x, y, width = 0.16, height = 0.16) => {
const mesh = makeBox(
width,
height,
0.2,
iconMaterial,
x,
y,
0,
group,
false,
false
);
return mesh;
};
if (destination.shape === "square") {
add(0, 0, 0.58, 0.58);
} else if (destination.shape === "diamond") {
const mesh = add(0, 0, 0.52, 0.52);
mesh.rotation.z = Math.PI / 4;
} else if (destination.shape === "circle") {
for (let index = 0; index < 8; index++) {
const angle = (index / 8) * Math.PI * 2;
add(
Math.cos(angle) * 0.31,
Math.sin(angle) * 0.31,
0.17,
0.17
);
}
} else if (destination.shape === "triangle") {
add(0, 0.29);
add(-0.18, 0);
add(0.18, 0);
add(-0.36, -0.29);
add(0, -0.29);
add(0.36, -0.29);
} else if (destination.shape === "hexagon") {
add(-0.18, 0.28);
add(0.18, 0.28);
add(-0.36, 0);
add(0, 0);
add(0.36, 0);
add(-0.18, -0.28);
add(0.18, -0.28);
}
return group;
}
// -------------------------------------------------------------------------
// Lobby architecture
// -------------------------------------------------------------------------
const lobby = new THREE.Group();
scene.add(lobby);
makeBox(
27.4,
0.8,
21.4,
0x182630,
0,
-0.42,
0,
lobby,
false,
true
);
const floorColors = [0xd7dad6, 0xcdd2cf, 0xe0e1dc, 0xcbd1cf];
for (let x = -12; x <= 12; x += 2) {
for (let z = -9; z <= 9; z += 2) {
const inCorridor = Math.abs(x) <= 2 || Math.abs(z) <= 2;
const color = inCorridor
? 0x4a5b65
: floorColors[Math.abs((x + z) / 2) % floorColors.length];
makeBox(
1.86,
0.08,
1.86,
color,
x,
0.04,
z,
lobby,
false,
true
);
}
}
// Main circulation spine.
makeBox(2.25, 0.055, 18.4, 0x31434e, 0, 0.12, 0.1, lobby, false, true);
makeBox(22.2, 0.055, 2.15, 0x31434e, 0, 0.125, 0, lobby, false, true);
// Rear cutaway wall.
for (let x = -12; x <= 12; x += 2) {
makeBox(
1.86,
3.1,
0.48,
x % 4 === 0 ? 0x223441 : 0x1a2b37,
x,
1.55,
-10.35,
lobby
);
}
// Low side walls preserve the cutaway view.
for (let z = -8; z <= 8; z += 2) {
makeBox(0.45, 0.95, 1.86, 0x1d303c, -13.25, 0.48, z, lobby);
makeBox(0.45, 0.65, 1.86, 0x20333f, 13.25, 0.33, z, lobby);
}
// Voxel columns and rear lintels.
[
[-12.8, -9.9],
[12.8, -9.9],
[-12.8, 9.7],
[12.8, 9.7]
].forEach(([x, z], index) => {
const height = index < 2 ? 3.7 : 1.4;
makeBox(0.72, height, 0.72, 0x28404e, x, height / 2, z, lobby);
makeBox(0.95, 0.22, 0.95, 0x43e4df, x, height + 0.05, z, lobby);
});
makeBox(25.2, 0.34, 0.56, 0x2b4655, 0, 3.05, -10.35, lobby);
// Decorative wall panels.
for (const x of [-8, -2, 4, 10]) {
makeBox(
2.1,
1.1,
0.08,
new THREE.MeshStandardMaterial({
color: 0x7cdce3,
emissive: 0x1e5c68,
emissiveIntensity: 0.55,
roughness: 0.35
}),
x,
1.55,
-10.08,
lobby,
false
);
}
function createBench(x, z, color = 0x324b58) {
const group = new THREE.Group();
group.position.set(x, 0, z);
lobby.add(group);
makeBox(2.15, 0.25, 0.72, color, 0, 0.56, 0, group);
makeBox(2.15, 0.62, 0.18, color, 0, 0.91, -0.28, group);
makeBox(0.18, 0.52, 0.55, 0x172832, -0.78, 0.28, 0, group);
makeBox(0.18, 0.52, 0.55, 0x172832, 0.78, 0.28, 0, group);
}
createBench(-3.4, 6.5);
createBench(3.4, 6.5);
function createPlanter(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
lobby.add(group);
makeBox(1.15, 0.65, 1.15, 0x334550, 0, 0.34, 0, group);
makeBox(0.75, 0.85, 0.75, 0x356d62, 0, 1.03, 0, group);
makeBox(0.48, 0.58, 0.48, 0x468d73, 0.18, 1.56, -0.12, group);
makeBox(0.36, 0.4, 0.36, 0x5aa27e, -0.2, 1.72, 0.15, group);
}
createPlanter(-11.5, 8.4);
createPlanter(11.5, 8.4);
createPlanter(-11.4, -9);
createPlanter(11.4, -9);
const groundLabelMaterial = new THREE.MeshBasicMaterial({
map: createGroundLabelTexture(),
transparent: true,
depthWrite: false
});
const groundLabel = new THREE.Mesh(
new THREE.PlaneGeometry(3.75, 0.94),
groundLabelMaterial
);
groundLabel.rotation.x = -Math.PI / 2;
groundLabel.position.set(0, 0.18, 9.1);
groundLabel.renderOrder = 4;
scene.add(groundLabel);
// -------------------------------------------------------------------------
// Service zones
// -------------------------------------------------------------------------
function buildZonePad(destination) {
const [x, z] = destination.center;
const width = 5.8;
const depth = 4.8;
const padColor = new THREE.Color(destination.color).lerp(
new THREE.Color(0x263640),
0.72
);
const padMaterial = new THREE.MeshStandardMaterial({
color: padColor,
roughness: 0.86
});
makeBox(
width,
0.11,
depth,
padMaterial,
x,
0.14,
z,
destination.group,
false,
true
);
const accentMaterial = new THREE.MeshBasicMaterial({
color: destination.color,
transparent: true,
opacity: 0.28
});
const inset = 0.32;
for (const dx of [-1, 1]) {
for (const dz of [-1, 1]) {
makeBox(
0.8,
0.035,
0.8,
accentMaterial,
x + dx * (width / 2 - inset),
0.215,
z + dz * (depth / 2 - inset),
destination.group,
false,
false
);
}
}
const frameMaterial = new THREE.MeshBasicMaterial({
color: destination.color
});
const frame = new THREE.Group();
destination.group.add(frame);
const horizontalLength = width + 0.35;
const verticalLength = depth + 0.35;
makeBox(
horizontalLength,
0.12,
0.12,
frameMaterial,
x,
0.29,
z - depth / 2 - 0.12,
frame,
false,
false
);
makeBox(
horizontalLength,
0.12,
0.12,
frameMaterial,
x,
0.29,
z + depth / 2 + 0.12,
frame,
false,
false
);
makeBox(
0.12,
0.12,
verticalLength,
frameMaterial,
x - width / 2 - 0.12,
0.29,
z,
frame,
false,
false
);
makeBox(
0.12,
0.12,
verticalLength,
frameMaterial,
x + width / 2 + 0.12,
0.29,
z,
frame,
false,
false
);
frame.visible = false;
zoneFrames[destination.id] = frame;
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const hitbox = new THREE.Mesh(
new THREE.BoxGeometry(width, 3.6, depth),
hitMaterial
);
hitbox.position.set(x, 1.75, z);
hitbox.userData.destination = destination.id;
destination.group.add(hitbox);
pickables.push(hitbox);
}
function buildZoneSign(destination) {
const [x, z] = destination.sign;
makeBox(
0.5,
0.18,
0.5,
0x172a35,
x,
0.2,
z,
destination.group
);
makeBox(
0.16,
3.5,
0.16,
0x172a35,
x,
1.92,
z,
destination.group
);
const label = createSprite(createLabelTexture(destination), 6.25, 1.56);
label.position.set(x, 4.05, z);
destination.group.add(label);
destination.labelSprite = label;
const icon = createVoxelIcon(destination);
icon.position.set(x, 5.34, z);
icon.userData.destination = destination.id;
destination.group.add(icon);
destination.icon = icon;
destination.iconBaseY = icon.position.y;
iconObjects.push(icon);
}
function buildWelcomeZone(destination) {
const group = destination.group;
makeBox(3.7, 1.08, 1.2, destination.color, -9, 0.66, -7.05, group);
makeBox(3.82, 0.15, 1.3, 0xffc5a7, -9, 1.27, -7.05, group);
makeBox(1.05, 1.05, 2.6, destination.color, -11.1, 0.65, -5.9, group);
makeBox(1.17, 0.15, 2.72, 0xffc5a7, -11.1, 1.25, -5.9, group);
makeBox(0.7, 0.48, 0.12, 0x122530, -9.1, 1.63, -6.78, group);
makeBox(0.18, 0.3, 0.18, 0x122530, -9.1, 1.35, -6.78, group);
makeBox(2.1, 0.25, 0.65, 0x4e6875, -9.9, 0.57, -4.45, group);
makeBox(0.18, 0.52, 0.5, 0x172a35, -10.65, 0.28, -4.45, group);
makeBox(0.18, 0.52, 0.5, 0x172a35, -9.15, 0.28, -4.45, group);
}
function buildHelpZone(destination) {
const group = destination.group;
makeBox(3.6, 1.08, 1.2, destination.color, 8.9, 0.66, -7.05, group);
makeBox(3.72, 0.15, 1.3, 0xd3bcff, 8.9, 1.27, -7.05, group);
makeBox(0.85, 0.55, 0.12, 0x172535, 8.8, 1.65, -6.78, group);
makeBox(0.2, 0.32, 0.2, 0x172535, 8.8, 1.34, -6.78, group);
makeBox(0.85, 0.38, 0.85, 0x253945, 10.6, 0.58, -5.2, group);
makeBox(0.85, 0.7, 0.16, 0x253945, 10.6, 0.94, -5.55, group);
}
function buildRestroomZone(destination) {
const group = destination.group;
makeBox(5.25, 2.5, 0.24, 0x29414e, -9, 1.32, 3.95, group);
makeBox(0.24, 2.5, 3.15, 0x29414e, -11.52, 1.32, 5.5, group);
makeBox(0.24, 2.5, 3.15, 0x29414e, -6.48, 1.32, 5.5, group);
makeBox(1.15, 2.05, 0.12, destination.color, -10.2, 1.1, 4.1, group);
makeBox(1.15, 2.05, 0.12, destination.color, -7.9, 1.1, 4.1, group);
makeBox(0.18, 0.18, 0.12, 0xffffff, -9.7, 1.15, 4.19, group);
makeBox(0.18, 0.18, 0.12, 0xffffff, -7.4, 1.15, 4.19, group);
}
function buildWorkspaceZone(destination) {
const group = destination.group;
[8.05, 10.2].forEach((x) => {
makeBox(1.55, 0.16, 0.82, 0xf0d3b5, x, 1.05, 5.3, group);
makeBox(0.16, 0.9, 0.16, 0x52636e, x - 0.58, 0.55, 5.3, group);
makeBox(0.16, 0.9, 0.16, 0x52636e, x + 0.58, 0.55, 5.3, group);
makeBox(0.58, 0.42, 0.1, 0x1a303a, x, 1.37, 5.12, group);
makeBox(0.16, 0.27, 0.16, 0x1a303a, x, 1.16, 5.12, group);
makeBox(0.62, 0.18, 0.62, destination.color, x, 0.63, 6.22, group);
makeBox(0.62, 0.72, 0.15, destination.color, x, 0.99, 6.5, group);
});
}
function buildCafeZone(destination) {
const group = destination.group;
makeBox(4.3, 1.02, 1.12, destination.color, -0.25, 0.62, -8.45, group);
makeBox(4.42, 0.15, 1.22, 0xffe49a, -0.25, 1.21, -8.45, group);
makeBox(0.72, 0.52, 0.12, 0x192b33, -0.65, 1.55, -8.2, group);
makeBox(0.45, 0.42, 0.45, 0x334b56, 0.85, 1.48, -8.15, group);
makeBox(1.1, 0.14, 1.1, 0xe8ddc8, -2.05, 0.98, -6.25, group);
makeBox(0.18, 0.85, 0.18, 0x405662, -2.05, 0.52, -6.25, group);
makeBox(0.6, 0.18, 0.6, 0x3c5963, -2.05, 0.58, -6.85, group);
}
for (const id of destinationOrder) {
const destination = destinations[id];
destination.group = new THREE.Group();
scene.add(destination.group);
buildZonePad(destination);
buildZoneSign(destination);
}
buildWelcomeZone(destinations.welcome);
buildHelpZone(destinations.help);
buildRestroomZone(destinations.restrooms);
buildWorkspaceZone(destinations.workspace);
buildCafeZone(destinations.cafe);
// -------------------------------------------------------------------------
// Floor bands and route geometry
// -------------------------------------------------------------------------
function createBandMaterial(color, opacity) {
return new THREE.MeshBasicMaterial({
color,
transparent: opacity < 1,
opacity,
depthWrite: false
});
}
function drawStaticBand(points, color) {
const material = createBandMaterial(color, 0.23);
for (let index = 0; index < points.length - 1; index++) {
const a = points[index];
const b = points[index + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
if (length < 0.001) continue;
const angle = Math.atan2(dx, dz);
const count = Math.max(1, Math.ceil(length / 0.55));
const step = length / count;
for (let tile = 0; tile < count; tile++) {
const t = (tile + 0.5) / count;
const mesh = makeBox(
0.52,
0.035,
step * 0.92,
material,
THREE.MathUtils.lerp(a.x, b.x, t),
0.17,
THREE.MathUtils.lerp(a.z, b.z, t),
scene,
false,
false
);
mesh.rotation.y = angle;
mesh.renderOrder = 1;
}
}
}
for (const id of destinationOrder) {
const destination = destinations[id];
const points = destination.route
.slice(1)
.map(([x, z]) => new THREE.Vector3(x, 0, z));
drawStaticBand(points, destination.color);
}
const routeGroup = new THREE.Group();
const flowGroup = new THREE.Group();
const markerGroup = new THREE.Group();
scene.add(routeGroup);
scene.add(flowGroup);
scene.add(markerGroup);
let selectedDestination = destinations.welcome;
let activeRouteData = null;
let routeArrows = [];
let flowCubes = [];
let markerPulse = null;
function createArrowMesh() {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color: 0xffffff,
depthTest: false,
depthWrite: false
});
makeBox(0.16, 0.07, 0.72, material, 0, 0, -0.16, group, false, false);
makeBox(0.18, 0.07, 0.18, material, 0, 0, 0.34, group, false, false);
makeBox(0.18, 0.07, 0.38, material, -0.21, 0, 0.13, group, false, false);
makeBox(0.18, 0.07, 0.38, material, 0.21, 0, 0.13, group, false, false);
group.renderOrder = 5;
return group;
}
function createPolylineData(points) {
const segments = [];
let totalLength = 0;
for (let index = 0; index < points.length - 1; index++) {
const start = points[index];
const end = points[index + 1];
const dx = end.x - start.x;
const dz = end.z - start.z;
const length = Math.hypot(dx, dz);
if (length < 0.001) continue;
segments.push({
start,
end,
dx,
dz,
length,
startDistance: totalLength
});
totalLength += length;
}
return { segments, totalLength };
}
function samplePolyline(data, normalizedTime) {
let distance = normalizedTime * data.totalLength;
for (const segment of data.segments) {
const localDistance = distance - segment.startDistance;
if (localDistance <= segment.length) {
const t = segment.length === 0 ? 0 : localDistance / segment.length;
return {
position: new THREE.Vector3(
segment.start.x + segment.dx * t,
0,
segment.start.z + segment.dz * t
),
direction: new THREE.Vector3(
segment.dx / segment.length,
0,
segment.dz / segment.length
)
};
}
distance -= segment.length;
}
const last = data.segments[data.segments.length - 1];
return {
position: last.end.clone(),
direction: new THREE.Vector3(last.dx / last.length, 0, last.dz / last.length)
};
}
function drawActiveRoute(destination) {
clearGroup(routeGroup);
clearGroup(flowGroup);
clearGroup(markerGroup);
routeArrows = [];
flowCubes = [];
markerPulse = null;
const points = destination.route.map(([x, z]) => new THREE.Vector3(x, 0, z));
const data = createPolylineData(points);
activeRouteData = data;
const routeMaterial = new THREE.MeshBasicMaterial({
color: destination.color,
depthWrite: false
});
// The selected route uses a bright tiled floor band.
for (let index = 0; index < points.length - 1; index++) {
const a = points[index];
const b = points[index + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
if (length < 0.001) continue;
const angle = Math.atan2(dx, dz);
const count = Math.max(1, Math.ceil(length / 0.72));
const step = length / count;
for (let tile = 0; tile < count; tile++) {
const t = (tile + 0.5) / count;
const mesh = makeBox(
0.74,
0.075,
step * 0.84,
routeMaterial,
THREE.MathUtils.lerp(a.x, b.x, t),
0.225,
THREE.MathUtils.lerp(a.z, b.z, t),
routeGroup,
false,
false
);
mesh.rotation.y = angle;
mesh.renderOrder = 2;
}
// White voxel arrows provide a direction cue independent of color.
let arrowDistance = 1.05;
while (arrowDistance < length - 0.55) {
const t = arrowDistance / length;
const arrow = createArrowMesh();
arrow.position.set(
THREE.MathUtils.lerp(a.x, b.x, t),
0.31,
THREE.MathUtils.lerp(a.z, b.z, t)
);
arrow.rotation.y = angle;
routeGroup.add(arrow);
routeArrows.push(arrow);
arrowDistance += 1.55;
}
}
// Square corner tiles visually join the orthogonal segments.
for (let index = 1; index < points.length - 1; index++) {
const point = points[index];
makeBox(
0.76,
0.075,
0.76,
routeMaterial,
point.x,
0.225,
point.z,
routeGroup,
false,
false
).renderOrder = 2;
}
// Moving cubes make the route direction explicit.
for (let index = 0; index < 3; index++) {
const material = new THREE.MeshBasicMaterial({
color: index === 0 ? 0xffffff : 0xdffaff,
transparent: true,
opacity: index === 0 ? 1 : 0.62 - index * 0.14,
depthTest: false,
depthWrite: false
});
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.25, 0.25),
material
);
cube.renderOrder = 7;
flowGroup.add(cube);
flowCubes.push(cube);
}
// Endpoint brackets and a floating voxel confirm the selected destination.
const endpoint = points[points.length - 1];
const markerMaterial = new THREE.MeshBasicMaterial({
color: destination.color,
depthTest: false,
depthWrite: false
});
const bracketOffsets = [
[-0.62, -0.62],
[0.62, -0.62],
[-0.62, 0.62],
[0.62, 0.62]
];
bracketOffsets.forEach(([dx, dz]) => {
makeBox(
0.34,
0.12,
0.13,
markerMaterial,
endpoint.x + dx,
0.35,
endpoint.z + dz,
markerGroup,
false,
false
);
makeBox(
0.13,
0.12,
0.34,
markerMaterial,
endpoint.x + dx,
0.35,
endpoint.z + dz,
markerGroup,
false,
false
);
});
markerPulse = new THREE.Mesh(
new THREE.BoxGeometry(0.3, 0.3, 0.3),
new THREE.MeshBasicMaterial({
color: 0xffffff,
depthTest: false,
depthWrite: false
})
);
markerPulse.position.set(endpoint.x, 1.05, endpoint.z);
markerPulse.renderOrder = 8;
markerGroup.add(markerPulse);
}
// -------------------------------------------------------------------------
// Destination UI
// -------------------------------------------------------------------------
function shapeSVG(shape) {
const shapes = {
square: '<rect x="9" y="9" width="22" height="22" rx="1"/>',
diamond: '<path d="M20 6 L34 20 L20 34 L6 20 Z"/>',
circle: '<circle cx="20" cy="20" r="13"/>',
triangle: '<path d="M20 6 L34 32 L6 32 Z"/>',
hexagon: '<path d="M14 7 L26 7 L34 20 L26 33 L14 33 L6 20 Z"/>'
};
return `
<svg viewBox="0 0 40 40" fill="none" stroke="currentColor"
stroke-width="2.7" stroke-linejoin="miter" aria-hidden="true">
${shapes[shape]}
</svg>
`;
}
const destinationList = document.querySelector("#destinationList");
const destinationButtons = {};
for (const id of destinationOrder) {
const destination = destinations[id];
const button = document.createElement("button");
button.type = "button";
button.className = "destination-button";
button.style.setProperty("--accent", destination.css);
button.setAttribute("aria-pressed", "false");
button.innerHTML = `
<span class="glyph" aria-hidden="true">${shapeSVG(destination.shape)}</span>
<span class="destination-label">
<strong>${destination.title}</strong>
<small>${destination.subtitle}</small>
</span>
<span class="zone-code">${destination.code}</span>
`;
button.addEventListener("click", () => selectDestination(id));
destinationList.appendChild(button);
destinationButtons[id] = button;
}
const selectionBadge = createSprite(createBadgeTexture("#ff7548"), 2.15, 0.54);
selectionBadge.position.set(
selectedDestination.sign[0],
6.22,
selectedDestination.sign[1]
);
scene.add(selectionBadge);
function selectDestination(id) {
const destination = destinations[id];
if (!destination) return;
selectedDestination = destination;
document.documentElement.style.setProperty("--active", destination.css);
document.querySelector("#statusLabel").textContent = destination.title;
document.querySelector("#routeGlyph").innerHTML = shapeSVG(destination.shape);
document.querySelector("#routeGlyph").style.color = destination.css;
document.querySelector("#routeGlyph").style.borderColor = `${destination.css}99`;
document.querySelector("#routeGlyph").style.background = `${destination.css}18`;
document.querySelector("#routeKicker").textContent = `Route to Zone ${destination.code}`;
document.querySelector("#routeName").textContent = destination.title;
for (const [buttonId, button] of Object.entries(destinationButtons)) {
const active = buttonId === id;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
for (const [frameId, frame] of Object.entries(zoneFrames)) {
frame.visible = frameId === id;
}
for (const destinationId of destinationOrder) {
const item = destinations[destinationId];
item.icon.scale.setScalar(destinationId === id ? 1.13 : 1);
item.labelSprite.material.opacity = destinationId === id ? 1 : 0.9;
}
drawActiveRoute(destination);
const distance = Math.round(activeRouteData.totalLength);
const turnText = destination.turns === 1
? "1 turn"
: `${destination.turns} turns`;
document.querySelector("#routeMeta").textContent =
`≈ ${distance} m • ${turnText} • Zone ${destination.code}`;
document.querySelector("#routeSteps").innerHTML = destination.steps
.map(
(step, index) => `
<li class="route-step">
<span class="step-number">${String(index + 1).padStart(2, "0")}</span>
<span class="step-arrow" aria-hidden="true">${step.arrow}</span>
<span>${step.text}</span>
</li>
`
)
.join("");
document.querySelector("#routeHint").textContent =
`Follow the ${destination.title.toLowerCase()} floor band and the white arrows. ` +
`The matching ${destination.shape} symbol confirms the zone.`;
if (selectionBadge.material.map) {
selectionBadge.material.map.dispose();
}
selectionBadge.material.map = createBadgeTexture(destination.css);
selectionBadge.material.needsUpdate = true;
selectionBadge.position.set(
destination.sign[0],
6.22,
destination.sign[1]
);
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, wheel zoom, pinch zoom, keyboard reset
// -------------------------------------------------------------------------
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const verticalSize = aspect < 1 ? 32 / aspect : 23.5;
camera.left = (-verticalSize * aspect) / 2;
camera.right = (verticalSize * aspect) / 2;
camera.top = verticalSize / 2;
camera.bottom = -verticalSize / 2;
camera.zoom = cameraState.zoom;
const radius = 38;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + radius * Math.cos(cameraState.phi),
cameraTarget.z + radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = 0.67;
cameraState.phi = 0.92;
cameraState.zoom = 1;
updateCamera();
}
function adjustZoom(amount) {
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom + amount,
0.68,
1.75
);
updateCamera();
}
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
updateCamera();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
adjustZoom(event.deltaY > 0 ? -0.08 : 0.08);
},
{ passive: false }
);
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
const pointers = new Map();
let activePointerId = null;
let lastPointerX = 0;
let lastPointerY = 0;
let downPointerX = 0;
let downPointerY = 0;
let dragged = false;
let singlePointerGesture = false;
let previousPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function setPointerNdc(event) {
const rect = canvas.getBoundingClientRect();
pointerNdc.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickDestination(event) {
setPointerNdc(event);
raycaster.setFromCamera(pointerNdc, camera);
const intersections = raycaster.intersectObjects(pickables, false);
if (!intersections.length) return;
const destinationId = intersections[0].object.userData.destination;
if (destinationId) selectDestination(destinationId);
}
function updateHover(event) {
setPointerNdc(event);
raycaster.setFromCamera(pointerNdc, camera);
const intersections = raycaster.intersectObjects(pickables, false);
canvas.classList.toggle("pickable", intersections.length > 0);
}
canvas.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
canvas.setPointerCapture(event.pointerId);
if (pointers.size === 1) {
activePointerId = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
downPointerX = event.clientX;
downPointerY = event.clientY;
dragged = false;
singlePointerGesture = true;
} else {
singlePointerGesture = false;
previousPinchDistance = pointerDistance();
}
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (pointers.has(event.pointerId)) {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
}
if (pointers.size >= 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (distance / previousPinchDistance),
0.68,
1.75
);
updateCamera();
}
previousPinchDistance = distance;
dragged = true;
return;
}
if (event.pointerId !== activePointerId) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (
Math.hypot(
event.clientX - downPointerX,
event.clientY - downPointerY
) > 5
) {
dragged = true;
}
cameraState.theta -= dx * 0.0065;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.0055,
0.48,
1.27
);
updateCamera();
});
function endPointer(event, cancelled = false) {
const shouldPick =
!cancelled &&
singlePointerGesture &&
!dragged &&
pointers.size === 1;
pointers.delete(event.pointerId);
if (shouldPick) {
pickDestination(event);
}
if (pointers.size === 1) {
const remaining = [...pointers.entries()][0];
activePointerId = remaining[0];
lastPointerX = remaining[1].x;
lastPointerY = remaining[1].y;
} else {
activePointerId = null;
}
previousPinchDistance = pointerDistance();
singlePointerGesture = false;
canvas.classList.remove("dragging");
updateHover(event);
}
canvas.addEventListener("pointerup", (event) => endPointer(event));
canvas.addEventListener("pointercancel", (event) => endPointer(event, true));
canvas.addEventListener("pointerleave", () => {
if (!pointers.size) canvas.classList.remove("pickable");
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (tag === "INPUT" || tag === "TEXTAREA") return;
if (event.key.toLowerCase() === "r") {
resetCamera();
} else if (event.key === "+" || event.key === "=") {
adjustZoom(0.1);
} else if (event.key === "-") {
adjustZoom(-0.1);
} else if (event.key === "ArrowLeft") {
cameraState.theta -= 0.09;
updateCamera();
} else if (event.key === "ArrowRight") {
cameraState.theta += 0.09;
updateCamera();
} else if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.48, cameraState.phi - 0.07);
updateCamera();
} else if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.27, cameraState.phi + 0.07);
updateCamera();
}
});
document.querySelector("#resetView").addEventListener("click", resetCamera);
document.querySelector("#zoomIn").addEventListener("click", () => adjustZoom(0.12));
document.querySelector("#zoomOut").addEventListener("click", () => adjustZoom(-0.12));
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
iconObjects.forEach((icon, index) => {
icon.position.y =
icon.userData.destination === selectedDestination.id
? icon.userData.baseY + Math.sin(time * 2.1) * 0.11
: icon.userData.baseY + Math.sin(time * 1.5 + index) * 0.055;
icon.rotation.y = Math.sin(time * 0.9 + index) * 0.13;
});
routeArrows.forEach((arrow, index) => {
const pulse = 1 + Math.sin(time * 4.2 - index * 0.55) * 0.045;
arrow.scale.set(pulse, 1, pulse);
});
if (activeRouteData) {
flowCubes.forEach((cube, index) => {
const t = (time * 0.075 + index / flowCubes.length) % 1;
const sample = samplePolyline(activeRouteData, t);
cube.position.set(
sample.position.x,
0.48 + Math.sin(time * 5 + index) * 0.04,
sample.position.z
);
cube.rotation.y = time * 1.6 + index;
});
}
if (markerPulse) {
markerPulse.position.y = 1.03 + Math.sin(time * 3.4) * 0.18;
markerPulse.rotation.y = time * 1.4;
markerPulse.rotation.z = Math.PI / 4;
}
selectionBadge.position.y =
6.22 + Math.sin(time * 2.7) * 0.07;
renderer.render(scene, camera);
}
// Initialize.
updateCamera();
selectDestination("welcome");
animate();
window.setTimeout(() => {
document.querySelector("#loading").classList.add("hidden");
}, 450);
</script>
</body>
</html>
```