Prompt specification
Build or customize the Three.js 3D scene "Color-independent route design" 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: Color-independent route design
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/color-independent-route-design-x0416
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a low-poly public-building map with routes identifiable without color. Build a small cutaway lobby connecting a reading room, service desk, courtyard, and lift, with distinct symbols repeated on signs and floor markers. Give each route both a color and a recognizable shape or pattern. A monochrome toggle should remove the color information while leaving the symbols, route continuity, and destination names readable. Let users trace a selected route from the entrance and see whether it can still be followed. Avoid making the monochrome mode change the geometry or simplify the task itself.
Working Three.js Starter (color-independent-route-design-x0416):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Civic Library — Accessible Route Map</title>
<style>
:root {
--ink: #202326;
--muted: #666b70;
--paper: #f4f1e8;
--panel: #fffdf7;
--line: #d7d2c7;
--focus: #222;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #e6e2d8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
#app {
display: grid;
grid-template-columns: 340px minmax(0, 1fr);
width: 100%;
height: 100%;
}
aside {
position: relative;
z-index: 2;
overflow-y: auto;
padding: 25px 22px 22px;
background: var(--panel);
border-right: 1px solid var(--line);
box-shadow: 5px 0 20px #0000000c;
}
.eyebrow {
margin: 0 0 8px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 28px;
line-height: 1.05;
letter-spacing: -.035em;
}
.intro {
margin: 12px 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section-title {
margin: 22px 0 9px;
font-size: 11px;
font-weight: 850;
letter-spacing: .12em;
text-transform: uppercase;
}
.routes {
display: grid;
gap: 8px;
}
.route-card {
display: grid;
grid-template-columns: 39px 12px 1fr;
align-items: center;
gap: 10px;
width: 100%;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: #fffefa;
color: var(--ink);
text-align: left;
cursor: pointer;
transition: border-color .15s, background .15s, transform .15s;
}
.route-card:hover {
transform: translateY(-1px);
border-color: #99958c;
}
.route-card:focus-visible,
button:focus-visible,
input:focus-visible {
outline: 3px solid #777;
outline-offset: 2px;
}
.route-card.active {
border-color: #34383b;
background: #f0eee7;
box-shadow: inset 3px 0 0 #34383b;
}
.route-card svg {
width: 34px;
height: 34px;
display: block;
}
.swatch {
width: 10px;
height: 32px;
border-radius: 5px;
background: var(--route-color);
border: 1px solid #00000025;
}
.route-name {
display: block;
font-size: 14px;
font-weight: 760;
}
.route-cue {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.trace-panel {
margin-top: 19px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: #f7f4ec;
}
.trace-actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
}
.primary,
.secondary {
min-height: 40px;
border-radius: 9px;
border: 1px solid #34383b;
cursor: pointer;
font-weight: 750;
font-size: 13px;
}
.primary {
padding: 0 15px;
background: #292d30;
color: white;
}
.secondary {
padding: 0 12px;
background: #fffefa;
color: #292d30;
}
.primary:hover { background: #44494d; }
.secondary:hover { background: #ece9e0; }
.progress {
height: 7px;
margin: 13px 0 8px;
overflow: hidden;
border-radius: 999px;
background: #d8d4ca;
}
#progressFill {
width: 0;
height: 100%;
background: #35393c;
border-radius: inherit;
transition: width .08s linear;
}
#traceStatus {
min-height: 36px;
margin: 0;
color: #45494c;
font-size: 12px;
line-height: 1.45;
}
.follow {
display: flex;
align-items: center;
gap: 8px;
margin-top: 10px;
color: #4b4f52;
font-size: 12px;
cursor: pointer;
}
.follow input {
width: 16px;
height: 16px;
accent-color: #34383b;
}
.note {
margin-top: 18px;
padding: 12px 13px;
border-left: 3px solid #44484b;
background: #eeece5;
color: #4d5154;
font-size: 12px;
line-height: 1.55;
}
.shortcuts {
margin: 17px 0 0;
color: #777b7e;
font-size: 10px;
line-height: 1.55;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e6e2d8;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.map-toolbar {
position: absolute;
z-index: 3;
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 9px;
padding: 8px;
border: 1px solid #c8c4ba;
border-radius: 12px;
background: #fffdf7ed;
box-shadow: 0 5px 22px #00000016;
backdrop-filter: blur(8px);
}
.mode-toggle {
display: flex;
align-items: center;
gap: 8px;
padding: 0 7px 0 4px;
font-size: 12px;
font-weight: 750;
cursor: pointer;
white-space: nowrap;
}
.mode-toggle input {
width: 17px;
height: 17px;
accent-color: #303437;
}
.tool-button {
height: 34px;
padding: 0 11px;
border: 1px solid #c7c3b9;
border-radius: 8px;
background: #fffefa;
color: #303437;
cursor: pointer;
font-size: 12px;
font-weight: 720;
}
.tool-button:hover { background: #ece9e0; }
.map-caption {
position: absolute;
z-index: 2;
left: 18px;
bottom: 17px;
max-width: min(390px, calc(100% - 36px));
padding: 10px 12px;
border: 1px solid #c8c4ba;
border-radius: 10px;
background: #fffdf7df;
color: #55595c;
font-size: 11px;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(7px);
}
#modeBadge {
position: absolute;
z-index: 2;
top: 20px;
left: 20px;
padding: 8px 11px;
border: 1px solid #c8c4ba;
border-radius: 9px;
background: #fffdf7e8;
color: #44484b;
font-size: 11px;
font-weight: 760;
letter-spacing: .03em;
pointer-events: none;
}
@media (max-width: 800px) {
html, body { overflow: auto; }
#app {
height: auto;
min-height: 100%;
grid-template-columns: 1fr;
grid-template-rows: 68vh auto;
}
#viewport { grid-row: 1; }
aside {
grid-row: 2;
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
}
.map-toolbar {
top: 10px;
right: 10px;
}
#modeBadge {
top: 12px;
left: 12px;
}
.map-caption {
left: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<main id="app">
<aside>
<p class="eyebrow">Public-building wayfinding</p>
<h1>Civic Library</h1>
<p class="intro">
Select a destination, then trace its route from the Entrance.
Every route uses both a color and a repeated symbol pattern.
</p>
<div class="section-title">Choose a destination</div>
<div class="routes" id="routeList">
<button class="route-card active" data-route="reading" aria-pressed="true">
<svg viewBox="0 0 48 48" aria-hidden="true">
<path d="M7 12c6-2 11-1 17 3v23c-6-4-11-5-17-3V12Z"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linejoin="round"/>
<path d="M41 12c-6-2-11-1-17 3v23c6-4 11-5 17-3V12Z"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linejoin="round"/>
<path d="M24 15v23" fill="none" stroke="currentColor" stroke-width="3"/>
</svg>
<span class="swatch"></span>
<span>
<span class="route-name">Reading Room</span>
<span class="route-cue">Open-book symbols</span>
</span>
</button>
<button class="route-card" data-route="service" aria-pressed="false">
<svg viewBox="0 0 48 48" aria-hidden="true">
<path d="M15 33h18c-2-2-3-5-3-9a6 6 0 0 0-12 0c0 4-1 7-3 9Z"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linejoin="round"/>
<path d="M20 38h8M24 12v-3M14 17l-2-2M34 17l2-2"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linecap="round"/>
</svg>
<span class="swatch"></span>
<span>
<span class="route-name">Service Desk</span>
<span class="route-cue">Bell symbols</span>
</span>
</button>
<button class="route-card" data-route="courtyard" aria-pressed="false">
<svg viewBox="0 0 48 48" aria-hidden="true">
<path d="M24 38V24" fill="none" stroke="currentColor"
stroke-width="3" stroke-linecap="round"/>
<path d="M25 28C13 27 10 18 12 10c10 0 17 7 13 18Z"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linejoin="round"/>
<path d="M24 23C25 11 32 6 39 7c1 9-5 16-15 16Z"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linejoin="round"/>
</svg>
<span class="swatch"></span>
<span>
<span class="route-name">Courtyard</span>
<span class="route-cue">Leaf symbols</span>
</span>
</button>
<button class="route-card" data-route="lift" aria-pressed="false">
<svg viewBox="0 0 48 48" aria-hidden="true">
<path d="m18 17 6-7 6 7M24 10v15"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linecap="round" stroke-linejoin="round"/>
<path d="m18 31 6 7 6-7M24 38V23"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span class="swatch"></span>
<span>
<span class="route-name">Lift</span>
<span class="route-cue">Up/down symbols</span>
</span>
</button>
</div>
<div class="trace-panel">
<div class="section-title" style="margin-top:0">Route trace</div>
<div class="trace-actions">
<button class="primary" id="traceButton">Trace route</button>
<button class="secondary" id="resetTraceButton">Reset</button>
</div>
<div class="progress" aria-hidden="true">
<div id="progressFill"></div>
</div>
<p id="traceStatus" aria-live="polite">
Ready — begin at the Entrance.
</p>
<label class="follow">
<input type="checkbox" id="followToggle" checked>
Camera follows the tracer
</label>
</div>
<div class="note">
<strong>Test without color:</strong> switch to Monochrome.
The building, routes, symbol sequence, and destination names remain unchanged.
Only the color cue is removed.
</div>
<p class="shortcuts">
Keyboard: <strong>1–4</strong> select a route ·
<strong>T</strong> trace/pause · <strong>M</strong> monochrome ·
<strong>R</strong> reset camera
</p>
</aside>
<section id="viewport" aria-label="Interactive three-dimensional building map">
<div id="modeBadge">Color cues on</div>
<div class="map-toolbar">
<label class="mode-toggle" title="Remove color information">
<input type="checkbox" id="monoToggle">
Monochrome
</label>
<button class="tool-button" id="topButton">Top</button>
<button class="tool-button" id="resetViewButton">Reset view</button>
</div>
<div class="map-caption">
Drag to orbit · Right-drag to pan · Scroll to zoom ·
Click a destination sign to select it
</div>
</section>
</main>
<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.querySelector("#viewport");
const modeBadge = document.querySelector("#modeBadge");
const monoToggle = document.querySelector("#monoToggle");
const followToggle = document.querySelector("#followToggle");
const traceButton = document.querySelector("#traceButton");
const resetTraceButton = document.querySelector("#resetTraceButton");
const traceStatus = document.querySelector("#traceStatus");
const progressFill = document.querySelector("#progressFill");
const routeButtons = [...document.querySelectorAll(".route-card")];
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e6e2d8");
scene.fog = new THREE.Fog("#e6e2d8", 48, 88);
const camera = new THREE.PerspectiveCamera(43, 1, 0.1, 150);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly cutaway map of a civic library with four symbol-coded routes"
);
viewport.prepend(renderer.domElement);
const ambient = new THREE.HemisphereLight("#ffffff", "#888888", 2.15);
scene.add(ambient);
const sun = new THREE.DirectionalLight("#ffffff", 3.0);
sun.position.set(14, 26, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00035;
scene.add(sun);
// Small custom orbit/pan/zoom controller. No addons are used.
const view = {
target: new THREE.Vector3(0, 0, -1.2),
radius: 39,
phi: 0.91,
theta: 0.61
};
function updateCamera(dt = 1) {
if (
followToggle.checked &&
(trace.running || trace.complete) &&
!drag.active
) {
const desired = trace.running
? new THREE.Vector3(tracer.position.x, 0, tracer.position.z)
: new THREE.Vector3(
selectedRoute.points.at(-1).x,
0,
selectedRoute.points.at(-1).z
);
view.target.lerp(desired, 1 - Math.exp(-dt * 4.5));
}
const sinPhi = Math.sin(view.phi);
const offset = new THREE.Vector3(
view.radius * sinPhi * Math.sin(view.theta),
view.radius * Math.cos(view.phi),
view.radius * sinPhi * Math.cos(view.theta)
);
camera.position.copy(view.target).add(offset);
camera.lookAt(view.target);
}
function resetCamera() {
view.target.set(0, 0, -1.2);
view.radius = 39;
view.phi = 0.91;
view.theta = 0.61;
updateCamera();
}
const drag = {
active: false,
pointerId: null,
button: 0,
x: 0,
y: 0,
moved: 0
};
renderer.domElement.addEventListener("contextmenu", e => e.preventDefault());
renderer.domElement.addEventListener("pointerdown", e => {
drag.active = true;
drag.pointerId = e.pointerId;
drag.button = e.button;
drag.x = e.clientX;
drag.y = e.clientY;
drag.moved = 0;
renderer.domElement.setPointerCapture(e.pointerId);
});
renderer.domElement.addEventListener("pointermove", e => {
if (!drag.active || e.pointerId !== drag.pointerId) return;
const dx = e.clientX - drag.x;
const dy = e.clientY - drag.y;
drag.x = e.clientX;
drag.y = e.clientY;
drag.moved += Math.abs(dx) + Math.abs(dy);
const panning = drag.button === 2 || drag.button === 1 || e.shiftKey;
if (panning) {
const right = new THREE.Vector3(
Math.cos(view.theta),
0,
-Math.sin(view.theta)
);
const forward = new THREE.Vector3(
-Math.sin(view.theta),
0,
-Math.cos(view.theta)
);
const amount = view.radius * 0.0014;
view.target.addScaledVector(right, -dx * amount);
view.target.addScaledVector(forward, -dy * amount);
} else {
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi + dy * 0.005,
0.08,
1.36
);
}
});
renderer.domElement.addEventListener("pointerup", e => {
const wasClick = drag.moved < 6 && drag.button === 0;
drag.active = false;
drag.pointerId = null;
if (wasClick) selectSignUnderPointer(e);
});
renderer.domElement.addEventListener("pointercancel", () => {
drag.active = false;
drag.pointerId = null;
});
renderer.domElement.addEventListener("wheel", e => {
e.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(e.deltaY * 0.001),
13,
70
);
}, { passive: false });
// ------------------------------------------------------------
// Color registry: monochrome changes pigment only
// ------------------------------------------------------------
const trackedMaterials = [];
const routeMaterials = [];
function trackedMaterial(color, options = {}, isRoute = false) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
...options
});
trackedMaterials.push({
material,
baseColor: material.color.clone(),
baseEmissive: material.emissive
? material.emissive.clone()
: new THREE.Color("#000000"),
isRoute
});
if (isRoute) routeMaterials.push(material);
return material;
}
let monochrome = false;
function applyAppearance() {
for (const record of trackedMaterials) {
const { material, baseColor, baseEmissive, isRoute } = record;
if (isRoute && monochrome) {
// Every route receives the same neutral gray.
// Route identity is then carried by the repeated symbols.
material.color.set("#686868");
material.emissive.set("#777777");
material.emissiveIntensity = 0.04;
} else {
if (monochrome) {
const luminance =
0.2126 * baseColor.r +
0.7152 * baseColor.g +
0.0722 * baseColor.b;
material.color.setRGB(
luminance,
luminance,
luminance
);
material.emissive.setScalar(luminance * 0.12);
material.emissiveIntensity = 0.12;
} else {
material.color.copy(baseColor);
material.emissive.copy(baseEmissive);
material.emissiveIntensity = 1;
}
}
}
updateRouteHighlight();
modeBadge.textContent = monochrome
? "Monochrome — symbols carry the route"
: "Color cues on";
for (const button of routeButtons) {
const route = routes.find(r => r.id === button.dataset.route);
button.querySelector(".swatch").style.background =
monochrome ? "#686868" : route.color;
}
}
function updateRouteHighlight() {
for (const route of routes) {
if (route.id === selectedRouteId) {
route.material.emissive.set(monochrome ? "#777777" : route.color);
route.material.emissiveIntensity = monochrome ? 0.12 : 0.22;
} else {
route.material.emissive.set("#000000");
route.material.emissiveIntensity = 0;
}
}
}
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function box(w, h, d, material, x, y, z, rotationY = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function cylinder(radius, height, material, x, y, z, sides = 10) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, sides),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addWallX(x, z1, z2, material, height = 1.18) {
return box(
0.22,
height,
z2 - z1,
material,
x,
height / 2,
(z1 + z2) / 2
);
}
function addWallZ(z, x1, x2, material, height = 1.18) {
return box(
x2 - x1,
height,
0.22,
material,
(x1 + x2) / 2,
height / 2,
z
);
}
const floorLobby = trackedMaterial("#d7c9a7");
const floorReading = trackedMaterial("#b7c9c3");
const floorService = trackedMaterial("#d9b5a5");
const floorCourtyard = trackedMaterial("#a8c892");
const floorLift = trackedMaterial("#c5c8d1");
const wallMaterial = trackedMaterial("#eee9dc");
const darkMaterial = trackedMaterial("#45494c");
const woodMaterial = trackedMaterial("#9b6b43");
const lightWoodMaterial = trackedMaterial("#c49c6c");
const metalMaterial = trackedMaterial("#8d9294", { metalness: 0.35 });
const greenMaterial = trackedMaterial("#6f965e");
const trunkMaterial = trackedMaterial("#79543d");
const blueMaterial = trackedMaterial("#6d9ead");
const fabricMaterial = trackedMaterial("#8b7770");
const whiteMaterial = trackedMaterial("#f5f0e6");
const waterMaterial = trackedMaterial("#6ca7af", { roughness: 0.3 });
// ------------------------------------------------------------
// Cutaway building
// ------------------------------------------------------------
// Site and room slabs.
box(31, 0.3, 26, trackedMaterial("#b9b3a6"), 0, -0.22, -0.5);
box(10, 0.08, 13, floorLobby, 0, 0.04, 2.5);
box(8, 0.08, 9, floorReading, -9, 0.04, -1.5);
box(7, 0.08, 7, floorService, 8.5, 0.04, 0.5);
box(10, 0.08, 7, floorCourtyard, 0, 0.04, -7.5);
box(4, 0.08, 7, floorLift, 8, 0.04, -6.5);
// Lobby: doorway gaps preserve visible route continuity.
addWallX(-5, -4, -2.2, wallMaterial);
addWallX(-5, 0, 9, wallMaterial);
addWallX(5, -4, -1.8, wallMaterial);
addWallX(5, 2.2, 9, wallMaterial);
addWallZ(-4, -5, -2.4, wallMaterial);
addWallZ(-4, -0.8, 4, wallMaterial);
addWallZ(9, -5, -1.2, wallMaterial);
addWallZ(9, 1.2, 5, wallMaterial);
// Reading room.
addWallZ(-6, -13, -5, wallMaterial);
addWallZ(3, -13, -5, wallMaterial);
addWallX(-13, -6, 3, wallMaterial);
// Service room.
addWallZ(-3, 5, 12, wallMaterial);
addWallZ(4, 5, 12, wallMaterial);
addWallX(12, -3, 4, wallMaterial);
// Courtyard.
addWallX(-5, -11, -4, wallMaterial, 0.9);
addWallX(5, -11, -6, wallMaterial, 0.9);
addWallX(5, -4.2, -4, wallMaterial, 0.9);
// Lift enclosure.
addWallX(6, -10, -3, wallMaterial, 1.65);
addWallX(10, -10, -3, wallMaterial, 1.65);
addWallZ(-10, 6, 10, wallMaterial, 1.65);
addWallZ(-3, 6, 7.2, wallMaterial, 1.65);
addWallZ(-3, 8.8, 10, wallMaterial, 1.65);
// Entrance arch and threshold.
box(3.5, 0.08, 1.8, darkMaterial, 0, 0.10, 9.9);
cylinder(0.13, 2.8, metalMaterial, -1.45, 1.45, 10.45, 8);
cylinder(0.13, 2.8, metalMaterial, 1.45, 1.45, 10.45, 8);
box(3.15, 0.22, 0.25, metalMaterial, 0, 2.84, 10.45);
// Lobby furniture.
function addBench(x, z, rotation = 0) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = rotation;
const seat = new THREE.Mesh(
new THREE.BoxGeometry(1.8, 0.16, 0.55),
woodMaterial
);
seat.position.y = 0.48;
seat.castShadow = true;
g.add(seat);
const back = new THREE.Mesh(
new THREE.BoxGeometry(1.8, 0.48, 0.12),
woodMaterial
);
back.position.set(0, 0.76, -0.23);
back.castShadow = true;
g.add(back);
for (const dx of [-0.65, 0.65]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.43, 0.42),
darkMaterial
);
leg.position.set(dx, 0.24, 0);
leg.castShadow = true;
g.add(leg);
}
scene.add(g);
}
addBench(-3.0, 2.2);
addBench(2.3, 2.2, Math.PI);
// Information kiosk, off the route centerlines.
box(0.85, 1.25, 0.48, darkMaterial, 2.4, 0.7, 4.1);
box(0.72, 0.48, 0.08, blueMaterial, 2.4, 1.08, 4.37);
// Reading shelves.
function addShelf(x, z, rotation = 0) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = rotation;
const frame = new THREE.Mesh(
new THREE.BoxGeometry(2.8, 1.75, 0.38),
woodMaterial
);
frame.position.y = 0.9;
frame.castShadow = true;
g.add(frame);
for (const y of [0.35, 0.85, 1.35]) {
const shelf = new THREE.Mesh(
new THREE.BoxGeometry(2.55, 0.08, 0.52),
lightWoodMaterial
);
shelf.position.set(0, y, 0.1);
shelf.castShadow = true;
g.add(shelf);
}
const bookColors = [
trackedMaterial("#6e879c"),
trackedMaterial("#a36f5c"),
trackedMaterial("#7c8b6a")
];
for (let row = 0; row < 3; row++) {
for (let i = 0; i < 8; i++) {
const book = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.28 + (i % 3) * 0.035, 0.28),
bookColors[(i + row) % bookColors.length]
);
book.position.set(-1.02 + i * 0.29, 0.53 + row * 0.5, 0.16);
book.castShadow = true;
g.add(book);
}
}
scene.add(g);
}
addShelf(-11.0, -4.65);
addShelf(-7.8, -4.65);
addShelf(-11.0, 1.7, Math.PI);
// Service counter.
box(3.1, 0.88, 0.75, woodMaterial, 9.6, 0.49, 0.4);
box(3.35, 0.12, 0.95, lightWoodMaterial, 9.6, 0.99, 0.4);
box(0.7, 0.42, 0.48, darkMaterial, 9.5, 1.25, 0.28);
box(0.56, 0.3, 0.05, blueMaterial, 9.5, 1.27, 0.55);
// Courtyard planters, tree, and water feature.
function addTree(x, z, scale = 1) {
cylinder(0.15 * scale, 1.2 * scale, trunkMaterial,
x, 0.65 * scale, z, 7);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.75 * scale, 0),
greenMaterial
);
crown.position.set(x, 1.65 * scale, z);
crown.scale.y = 1.25;
crown.castShadow = true;
scene.add(crown);
box(1.35 * scale, 0.28 * scale, 1.35 * scale,
trackedMaterial("#a59a83"), x, 0.15 * scale, z);
}
addTree(-3.4, -8.8, 0.95);
addTree(3.4, -8.7, 1.05);
box(2.1, 0.16, 1.25, waterMaterial, 1.9, 0.13, -6.6);
box(2.35, 0.18, 1.5, whiteMaterial, 1.9, 0.08, -6.6);
// Lift doors and call panel.
box(2.25, 1.45, 0.13, metalMaterial, 8, 0.76, -9.82);
box(0.035, 1.35, 0.06, darkMaterial, 8, 0.75, -9.72);
box(0.18, 0.42, 0.08, darkMaterial, 9.35, 1.2, -9.7);
// A few abstract low-poly visitors.
function addPerson(x, z, color) {
const mat = trackedMaterial(color);
cylinder(0.16, 0.65, mat, x, 0.43, z, 7);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.18, 8, 6),
trackedMaterial("#b98769")
);
head.position.set(x, 0.91, z);
head.castShadow = true;
scene.add(head);
}
addPerson(-1.0, 4.6, "#708b9b");
addPerson(1.3, -0.8, "#9b725d");
// ------------------------------------------------------------
// Symbol and sign drawing
// ------------------------------------------------------------
function roundedRectPath(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function symbolShapePath(ctx, type, cx, cy, radius) {
ctx.beginPath();
if (type === "reading") {
roundedRectPath(ctx, cx - radius, cy - radius,
radius * 2, radius * 2, radius * 0.18);
} else if (type === "service") {
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
} else if (type === "courtyard") {
for (let i = 0; i < 6; i++) {
const a = Math.PI / 3 * i - Math.PI / 2;
const x = cx + Math.cos(a) * radius;
const y = cy + Math.sin(a) * radius;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.closePath();
} else {
ctx.moveTo(cx, cy - radius);
ctx.lineTo(cx + radius, cy);
ctx.lineTo(cx, cy + radius);
ctx.lineTo(cx - radius, cy);
ctx.closePath();
}
}
function drawGlyph(ctx, type, cx, cy, size, color = "#222628", width = 0) {
ctx.save();
ctx.translate(cx, cy);
ctx.scale(size / 48, size / 48);
ctx.strokeStyle = color;
ctx.fillStyle = color;
ctx.lineWidth = width || 3;
ctx.lineCap = "round";
ctx.lineJoin = "round";
if (type === "reading") {
ctx.beginPath();
ctx.moveTo(7, 12);
ctx.bezierCurveTo(13, 10, 18, 11, 24, 15);
ctx.bezierCurveTo(30, 11, 35, 10, 41, 12);
ctx.lineTo(41, 35);
ctx.bezierCurveTo(35, 33, 30, 34, 24, 38);
ctx.bezierCurveTo(18, 34, 13, 33, 7, 35);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(24, 15);
ctx.lineTo(24, 38);
ctx.stroke();
} else if (type === "service") {
ctx.beginPath();
ctx.moveTo(15, 33);
ctx.bezierCurveTo(18, 29, 18, 26, 18, 23);
ctx.bezierCurveTo(18, 17, 21, 14, 24, 14);
ctx.bezierCurveTo(27, 14, 30, 17, 30, 23);
ctx.bezierCurveTo(30, 26, 30, 29, 33, 33);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(20, 38);
ctx.lineTo(28, 38);
ctx.moveTo(24, 10);
ctx.lineTo(24, 13);
ctx.moveTo(14, 17);
ctx.lineTo(12, 15);
ctx.moveTo(34, 17);
ctx.lineTo(36, 15);
ctx.stroke();
} else if (type === "courtyard") {
ctx.beginPath();
ctx.moveTo(24, 38);
ctx.lineTo(24, 24);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(25, 28);
ctx.bezierCurveTo(14, 27, 10, 19, 12, 10);
ctx.bezierCurveTo(22, 10, 28, 17, 25, 28);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(24, 23);
ctx.bezierCurveTo(25, 12, 32, 6, 39, 7);
ctx.bezierCurveTo(40, 16, 34, 23, 24, 23);
ctx.stroke();
} else if (type === "lift") {
ctx.beginPath();
ctx.moveTo(18, 17);
ctx.lineTo(24, 10);
ctx.lineTo(30, 17);
ctx.moveTo(24, 10);
ctx.lineTo(24, 25);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(18, 31);
ctx.lineTo(24, 38);
ctx.lineTo(30, 31);
ctx.moveTo(24, 38);
ctx.lineTo(24, 23);
ctx.stroke();
} else {
// Entrance arrow.
ctx.beginPath();
ctx.moveTo(24, 39);
ctx.lineTo(24, 11);
ctx.moveTo(14, 21);
ctx.lineTo(24, 10);
ctx.lineTo(34, 21);
ctx.stroke();
}
ctx.restore();
}
function makeFloorMarkerTexture(type) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 256);
symbolShapePath(ctx, type, 128, 128, 104);
ctx.fillStyle = "#fffefa";
ctx.fill();
ctx.strokeStyle = "#222628";
ctx.lineWidth = 10;
ctx.stroke();
drawGlyph(ctx, type, 128, 126, 126, "#222628", 2.8);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeSignTexture(type, name, subtitle) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fffdf7";
ctx.fillRect(0, 0, 1024, 256);
ctx.strokeStyle = "#25292c";
ctx.lineWidth = 10;
ctx.strokeRect(5, 5, 1014, 246);
symbolShapePath(ctx, type, 112, 128, 82);
ctx.fillStyle = "#f3f0e8";
ctx.fill();
ctx.strokeStyle = "#25292c";
ctx.lineWidth = 7;
ctx.stroke();
drawGlyph(ctx, type, 112, 126, 118, "#25292c", 2.5);
ctx.fillStyle = "#202326";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.font = "800 55px Arial, sans-serif";
ctx.fillText(name, 235, 101);
ctx.fillStyle = "#666b70";
ctx.font = "500 30px Arial, sans-serif";
ctx.fillText(subtitle, 237, 169);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const signMeshes = [];
function addSign(type, name, subtitle, x, y, z, routeId = null, width = 4.65) {
const group = new THREE.Group();
group.position.set(x, y, z);
const backing = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.12, 1.18, 0.14),
darkMaterial
);
backing.castShadow = true;
group.add(backing);
const texture = makeSignTexture(type, name, subtitle);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(width, 1.05),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false,
side: THREE.DoubleSide
})
);
face.position.z = 0.078;
group.add(face);
if (routeId) {
face.userData.routeId = routeId;
signMeshes.push(face);
}
scene.add(group);
return group;
}
// ------------------------------------------------------------
// Routes: continuous geometry + repeated symbol patterns
// ------------------------------------------------------------
const routes = [
{
id: "reading",
name: "Reading Room",
subtitle: "Books, study desks and quiet reading",
symbol: "reading",
color: "#2f78c4",
width: 0.29,
points: [
[-0.60, 9.0],
[-0.60, 6.8],
[-4.20, 6.8],
[-4.20, -1.0],
[-9.40, -1.0]
],
segments: [
"Entrance bay",
"South lobby",
"West lobby junction",
"Reading-room doorway",
"Reading Room"
]
},
{
id: "service",
name: "Service Desk",
subtitle: "Information, registration and assistance",
symbol: "service",
color: "#d66b2c",
width: 0.24,
points: [
[-0.20, 9.0],
[-0.20, 7.8],
[3.70, 7.8],
[3.70, 1.0],
[8.40, 1.0]
],
segments: [
"Entrance bay",
"South lobby",
"Service junction",
"Service-room approach",
"Service Desk"
]
},
{
id: "courtyard",
name: "Courtyard",
subtitle: "Garden, seating and natural light",
symbol: "courtyard",
color: "#25865b",
width: 0.36,
points: [
[0.20, 9.0],
[0.20, 6.3],
[-1.60, 6.3],
[-1.60, -7.2]
],
segments: [
"Entrance bay",
"Central lobby",
"Courtyard junction",
"Courtyard"
]
},
{
id: "lift",
name: "Lift",
subtitle: "Upper-floor public services",
symbol: "lift",
color: "#8d4ec4",
width: 0.18,
points: [
[0.60, 9.0],
[0.60, 8.2],
[4.70, 8.2],
[4.70, -5.2],
[7.70, -5.2],
[7.70, -7.0]
],
segments: [
"Entrance bay",
"East lobby",
"North lift corridor",
"Lift-room doorway",
"Lift"
]
}
];
const ROUTE_Y = 0.14;
function pathMetrics(points) {
const cumulative = [0];
let total = 0;
for (let i = 1; i < points.length; i++) {
total += points[i].distanceTo(points[i - 1]);
cumulative.push(total);
}
return { cumulative, total };
}
function samplePath(points, distance) {
const d = THREE.MathUtils.clamp(distance, 0, pathMetrics(points).total);
for (let i = 1; i < points.length; i++) {
if (d <= pathMetrics(points).cumulative[i]) {
const start = points[i - 1];
const end = points[i];
const segmentLength = start.distanceTo(end);
const t = (d - pathMetrics(points).cumulative[i - 1]) / segmentLength;
return {
position: start.clone().lerp(end, t),
tangent: end.clone().sub(start).normalize(),
segment: i - 1
};
}
}
return {
position: points.at(-1).clone(),
tangent: new THREE.Vector3(0, 0, -1),
segment: points.length - 2
};
}
for (const route of routes) {
route.material = trackedMaterial(
route.color,
{ roughness: 0.76 },
true
);
route.points = route.points.map(
p => new THREE.Vector3(p[0], ROUTE_Y, p[1])
);
route.metrics = pathMetrics(route.points);
route.markerTexture = makeFloorMarkerTexture(route.symbol);
// Continuous floor band. The corners are joined with discs.
for (let i = 1; i < route.points.length; i++) {
const start = route.points[i - 1];
const end = route.points[i];
const midpoint = start.clone().lerp(end, 0.5);
const dx = end.x - start.x;
const dz = end.z - start.z;
const length = Math.hypot(dx, dz);
const angle = Math.atan2(dx, dz);
const segment = new THREE.Mesh(
new THREE.BoxGeometry(route.width, 0.055, length + route.width * 0.25),
route.material
);
segment.position.set(midpoint.x, ROUTE_Y, midpoint.z);
segment.rotation.y = angle;
segment.receiveShadow = true;
scene.add(segment);
if (i < route.points.length - 1) {
const joint = new THREE.Mesh(
new THREE.CylinderGeometry(
route.width / 2,
route.width / 2,
0.055,
18
),
route.material
);
joint.position.set(end.x, ROUTE_Y, end.z);
joint.receiveShadow = true;
scene.add(joint);
}
}
// Repeated, destination-specific floor symbols.
const markerMaterial = new THREE.MeshBasicMaterial({
map: route.markerTexture,
transparent: true,
depthWrite: false,
toneMapped: false
});
const markerSize = route.id === "courtyard" ? 0.79 : 0.72;
for (
let distance = 0.35;
distance < route.metrics.total - 0.15;
distance += 1.06
) {
const sample = samplePath(route.points, distance);
const marker = new THREE.Mesh(
new THREE.PlaneGeometry(markerSize, markerSize),
markerMaterial
);
marker.position.set(
sample.position.x,
ROUTE_Y + 0.052,
sample.position.z
);
marker.rotation.x = -Math.PI / 2;
marker.rotation.z = -Math.atan2(
sample.tangent.x,
sample.tangent.z
);
marker.renderOrder = 3;
scene.add(marker);
}
// Larger endpoint medallion.
const endMarker = new THREE.Mesh(
new THREE.PlaneGeometry(1.28, 1.28),
markerMaterial
);
endMarker.position.copy(route.points.at(-1));
endMarker.position.y = ROUTE_Y + 0.055;
endMarker.rotation.x = -Math.PI / 2;
endMarker.renderOrder = 3;
scene.add(endMarker);
}
// Physical destination signs use the same symbols as the floor markers.
addSign(
"reading", "Reading Room", "Books & study",
-9.0, 2.25, -5.76, "reading"
);
addSign(
"service", "Service Desk", "Information & assistance",
8.65, 2.25, 3.74, "service"
);
addSign(
"courtyard", "Courtyard", "Garden & seating",
0, 2.35, -10.75, "courtyard"
);
addSign(
"lift", "Lift", "Upper-floor services",
8.0, 2.25, -9.75, "lift"
);
addSign(
"entrance", "ENTRANCE", "Start here · four marked route bays",
0, 3.22, 10.42, null, 4.8
);
// ------------------------------------------------------------
// Tracer
// ------------------------------------------------------------
const tracer = new THREE.Group();
const tracerBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.22, 0.62, 7),
new THREE.MeshBasicMaterial({ color: "#ffffff" })
);
tracerBody.position.y = 0.68;
tracer.add(tracerBody);
const tracerHead = new THREE.Mesh(
new THREE.SphereGeometry(0.18, 10, 7),
new THREE.MeshBasicMaterial({ color: "#ffffff" })
);
tracerHead.position.y = 1.16;
tracer.add(tracerHead);
const tracerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.38, 0.045, 6, 24),
new THREE.MeshBasicMaterial({ color: "#ffffff" })
);
tracerRing.rotation.x = Math.PI / 2;
tracerRing.position.y = 0.08;
tracer.add(tracerRing);
scene.add(tracer);
let selectedRouteId = "reading";
let selectedRoute = routes[0];
const trace = {
distance: 0,
running: false,
complete: false,
segment: 0
};
function updateTracerVisual() {
const sample = samplePath(selectedRoute.points, trace.distance);
tracer.position.copy(sample.position);
tracer.position.y = ROUTE_Y + 0.04;
trace.segment = sample.segment;
const pulse = 1 + Math.sin(performance.now() * 0.006) * 0.08;
tracerRing.scale.setScalar(pulse);
}
function updateTraceUI() {
const progress = trace.distance / selectedRoute.metrics.total;
progressFill.style.width = `${progress * 100}%`;
let status;
if (trace.complete) {
status =
`Arrived at ${selectedRoute.name}. ` +
`The symbol sequence is unchanged in ${monochrome ? "Monochrome" : "Color"} mode.`;
} else if (trace.running) {
status = `Tracing: ${selectedRoute.segments[trace.segment]} → ${selectedRoute.name}`;
} else if (trace.distance > 0) {
status = `Paused at ${selectedRoute.segments[trace.segment]}`;
} else {
status = `Ready — begin at the Entrance and follow the ${selectedRoute.name} symbols.`;
}
if (traceStatus.textContent !== status) traceStatus.textContent = status;
traceButton.textContent = trace.running
? "Pause"
: trace.complete
? "Trace again"
: trace.distance > 0
? "Continue"
: "Trace route";
}
function resetTrace() {
trace.distance = 0;
trace.running = false;
trace.complete = false;
trace.segment = 0;
updateTracerVisual();
updateTraceUI();
}
function selectRoute(id) {
selectedRouteId = id;
selectedRoute = routes.find(route => route.id === id);
for (const button of routeButtons) {
const active = button.dataset.route === id;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
updateRouteHighlight();
resetTrace();
}
function toggleTrace() {
if (trace.running) {
trace.running = false;
} else {
if (trace.complete || trace.distance >= selectedRoute.metrics.total) {
trace.distance = 0;
trace.complete = false;
}
trace.running = true;
if (followToggle.checked) {
view.radius = Math.min(view.radius, 30);
}
}
updateTraceUI();
}
traceButton.addEventListener("click", toggleTrace);
resetTraceButton.addEventListener("click", resetTrace);
for (const button of routeButtons) {
button.addEventListener("click", () => selectRoute(button.dataset.route));
}
// ------------------------------------------------------------
// Monochrome and camera controls
// ------------------------------------------------------------
function setMonochrome(value) {
monochrome = value;
monoToggle.checked = value;
applyAppearance();
}
monoToggle.addEventListener("change", () => setMonochrome(monoToggle.checked));
document.querySelector("#topButton").addEventListener("click", () => {
view.target.set(0, 0, -1.2);
view.radius = 38;
view.phi = 0.035;
view.theta = 0;
updateCamera();
});
document.querySelector("#resetViewButton").addEventListener("click", resetCamera);
window.addEventListener("keydown", e => {
if (e.target instanceof HTMLInputElement) return;
const key = e.key.toLowerCase();
const routeKeys = {
"1": "reading",
"2": "service",
"3": "courtyard",
"4": "lift"
};
if (routeKeys[key]) selectRoute(routeKeys[key]);
else if (key === "t") toggleTrace();
else if (key === "m") setMonochrome(!monochrome);
else if (key === "r") resetCamera();
});
// Click destination signs.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function selectSignUnderPointer(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);
const hits = raycaster.intersectObjects(signMeshes, false);
if (hits.length) {
const routeId = hits[0].object.userData.routeId;
if (routeId) selectRoute(routeId);
}
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(viewport);
resize();
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (trace.running) {
trace.distance = Math.min(
selectedRoute.metrics.total,
trace.distance + dt * 2.15
);
if (trace.distance >= selectedRoute.metrics.total - 0.001) {
trace.running = false;
trace.complete = true;
}
updateTracerVisual();
updateTraceUI();
}
updateCamera(dt);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
selectRoute("reading");
applyAppearance();
updateCamera();
animate();
</script>
</body>
</html>
```