Prompt specification
Build or customize the Three.js 3D scene "Choose delivery access by street or canal" 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: Choose delivery access by street or canal
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/choose-delivery-access-by-street-or-canal-x2804
Scene Description Prompt:
Compare fictional low-poly delivery routes to one shop by street or canal, including transfers and carrying distances. One HTML file, Three.js from cdnjs.
Working Three.js Starter (choose-delivery-access-by-street-or-canal-x2804):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Little Lantern Delivery — Route Comparison</title>
<style>
:root {
--ink: #183331;
--muted: #637875;
--panel: rgba(250, 252, 246, 0.93);
--line: rgba(24, 51, 49, 0.12);
--street: #f06b3c;
--canal: #12a89d;
--relay: #7857d8;
--carry: #f4c84a;
--shadow: 0 18px 48px rgba(24, 51, 49, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
background: #dce8e4;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.map-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
padding: 5px 9px;
border-radius: 999px;
border: 1px solid rgba(255, 255, 255, 0.8);
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 5px 16px rgba(24, 51, 49, 0.12);
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.map-label.shop {
background: #fff1d8;
border-color: rgba(240, 107, 60, 0.35);
}
.map-label.water {
color: #087c75;
background: rgba(225, 250, 247, 0.88);
letter-spacing: 0.13em;
}
.map-label.transfer {
min-width: 25px;
padding: 4px 7px;
color: #4a3a00;
background: #ffe47d;
border-color: rgba(126, 91, 0, 0.2);
font-size: 9px;
text-align: center;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.72);
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.15);
}
.brand {
top: 18px;
left: 18px;
width: 326px;
padding: 18px 18px 16px;
border-radius: 20px;
}
.eyebrow {
margin: 0 0 7px;
color: #598078;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 280px;
font-family: Georgia, "Times New Roman", serif;
font-size: 29px;
font-weight: 600;
line-height: 1.03;
letter-spacing: -0.035em;
}
.brand-copy {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.brand-copy strong {
color: var(--ink);
}
.actions {
position: fixed;
z-index: 15;
top: 18px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 7px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 14px;
background: rgba(250, 252, 246, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.action-button {
min-height: 34px;
padding: 0 12px;
border: 0;
border-radius: 10px;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: background 150ms ease, transform 150ms ease;
}
.action-button:hover {
background: rgba(24, 51, 49, 0.07);
}
.action-button:active {
transform: translateY(1px);
}
.compare {
top: 18px;
right: 18px;
width: 370px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 16px;
border-radius: 20px;
scrollbar-width: thin;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 600;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.text-button {
flex: 0 0 auto;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.62);
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.text-button:hover {
background: white;
}
.route-list {
display: grid;
gap: 8px;
}
.route-card {
position: relative;
padding: 11px 11px 10px 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.58);
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease,
box-shadow 150ms ease, transform 150ms ease;
}
.route-card::before {
content: "";
position: absolute;
left: 0;
top: 11px;
bottom: 11px;
width: 4px;
border-radius: 0 4px 4px 0;
background: var(--route-color);
}
.route-card:hover {
transform: translateY(-1px);
border-color: rgba(24, 51, 49, 0.25);
}
.route-card.selected {
border-color: var(--route-color);
background: rgba(255, 255, 255, 0.92);
box-shadow: 0 8px 20px color-mix(
in srgb,
var(--route-color) 14%,
transparent
);
}
.route-top {
display: flex;
align-items: center;
gap: 8px;
}
.route-title {
min-width: 0;
flex: 1;
}
.route-title strong {
display: block;
font-size: 12px;
line-height: 1.2;
}
.route-title small {
display: block;
margin-top: 3px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
text-overflow: ellipsis;
white-space: nowrap;
}
.time-pill {
padding: 5px 7px;
border-radius: 999px;
background: color-mix(
in srgb,
var(--route-color) 12%,
white
);
color: var(--route-color);
font-size: 10px;
font-weight: 900;
white-space: nowrap;
}
.route-metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 10px;
}
.route-metric {
padding-top: 7px;
border-top: 1px solid var(--line);
}
.route-metric span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.route-metric b {
display: block;
margin-top: 2px;
font-size: 12px;
}
.route-toggle {
position: absolute;
right: 8px;
bottom: 8px;
width: 15px;
height: 15px;
margin: 0;
cursor: pointer;
accent-color: var(--route-color);
opacity: 0.72;
}
.compare-table-wrap {
margin-top: 13px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.52);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 9px;
}
th,
td {
padding: 8px 7px;
border-bottom: 1px solid var(--line);
text-align: right;
white-space: nowrap;
}
th {
color: var(--muted);
font-size: 8px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
th:first-child,
td:first-child {
text-align: left;
}
tbody tr:last-child td {
border-bottom: 0;
}
td:first-child {
font-weight: 800;
}
.table-dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 50%;
vertical-align: 1px;
}
.carry-bar {
position: relative;
height: 4px;
margin-top: 5px;
overflow: hidden;
border-radius: 99px;
background: rgba(24, 51, 49, 0.08);
}
.carry-bar i {
display: block;
height: 100%;
border-radius: inherit;
background: var(--carry);
}
.fictional-note {
margin: 10px 2px 0;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.legend {
left: 18px;
bottom: 18px;
width: 326px;
padding: 13px 15px;
border-radius: 17px;
}
.legend-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
font-size: 9px;
font-weight: 700;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-line {
width: 22px;
height: 4px;
border-radius: 99px;
background: var(--legend-color);
}
.legend-dots {
width: 22px;
height: 5px;
background-image: radial-gradient(circle, var(--carry) 0 2px, transparent 2.5px);
background-size: 7px 5px;
}
.transfer-icon {
display: grid;
width: 22px;
height: 13px;
place-items: center;
border: 2px solid var(--carry);
border-radius: 99px;
color: #816500;
font-size: 7px;
font-weight: 900;
}
.camera-help {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
kbd {
padding: 1px 4px;
border: 1px solid rgba(24, 51, 49, 0.16);
border-bottom-width: 2px;
border-radius: 4px;
background: white;
color: var(--ink);
font: inherit;
font-size: 8px;
font-weight: 800;
}
.details {
left: 362px;
right: 406px;
bottom: 18px;
min-width: 330px;
padding: 14px 15px;
border-radius: 17px;
}
.details-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.details-title {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
.details-title i {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--selected-color);
}
.details-title strong {
overflow: hidden;
font-size: 12px;
text-overflow: ellipsis;
white-space: nowrap;
}
.details-summary {
margin: 5px 0 10px;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.segments {
display: flex;
gap: 6px;
min-width: 0;
}
.segment {
position: relative;
min-width: 0;
flex: 1;
padding: 7px 7px 6px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
}
.segment::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 3px;
background: var(--segment-color);
}
.segment span {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 7px;
font-weight: 800;
letter-spacing: 0.04em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.segment b {
display: block;
margin-top: 3px;
font-size: 10px;
}
.segment.carrying b::after {
content: " carry";
color: #9a7900;
font-size: 7px;
font-weight: 900;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #dce8e4;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1100px) {
.details {
left: 362px;
right: 18px;
}
.compare {
width: 340px;
}
}
@media (max-width: 850px) {
.brand {
width: 270px;
padding: 14px;
}
h1 {
font-size: 23px;
}
.brand-copy {
display: none;
}
.actions {
top: 108px;
}
.compare {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 45vh;
padding: 12px;
border-radius: 16px;
}
.compare-table-wrap,
.fictional-note {
display: none;
}
.route-list {
grid-template-columns: repeat(3, 1fr);
}
.route-card {
padding: 9px 8px 9px 11px;
}
.route-title small,
.route-metric:nth-child(1) {
display: none;
}
.route-metrics {
grid-template-columns: 1fr 1fr;
}
.legend {
right: 10px;
bottom: calc(45vh + 20px);
left: auto;
width: 250px;
}
.details {
display: none;
}
}
@media (max-width: 560px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
}
.brand .eyebrow {
margin-bottom: 4px;
}
h1 {
font-size: 21px;
}
.actions {
top: 91px;
}
.route-list {
display: flex;
overflow-x: auto;
}
.route-card {
min-width: 205px;
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels"></div>
<header class="panel brand">
<p class="eyebrow">Moss District · Fictional logistics map</p>
<h1>One shop.<br />Three ways there.</h1>
<p class="brand-copy">
Compare a direct street walk with two canal-first deliveries.
<strong>Yellow beads</strong> show parcel-carrying distance.
</p>
</header>
<nav class="actions" aria-label="Map controls">
<button class="action-button" id="reset-view">Reset 3D</button>
<button class="action-button" id="top-view">Top view</button>
<button class="action-button" id="toggle-labels">Labels on</button>
</nav>
<aside class="panel compare" aria-label="Route comparison">
<div class="panel-heading">
<div>
<h2>Route comparison</h2>
<p>Click a card or a route line to select it.</p>
</div>
<button class="text-button" id="show-all">Show all</button>
</div>
<div class="route-list" id="route-list"></div>
<div class="compare-table-wrap">
<table>
<thead>
<tr>
<th>Route</th>
<th>Distance</th>
<th>Carry</th>
<th>Transfer</th>
<th>Est.</th>
</tr>
</thead>
<tbody id="comparison-body"></tbody>
</table>
</div>
<p class="fictional-note">
Fictional routes and estimates. “Carry” means package distance moved on
foot; boat and bicycle legs are not counted as carrying.
</p>
</aside>
<section class="panel legend" aria-label="Map legend">
<div class="legend-grid">
<div class="legend-item">
<span class="legend-line" style="--legend-color: var(--street)"></span>
Street direct
</div>
<div class="legend-item">
<span class="legend-line" style="--legend-color: var(--canal)"></span>
Canal hybrid
</div>
<div class="legend-item">
<span class="legend-line" style="--legend-color: var(--relay)"></span>
Canal relay
</div>
<div class="legend-item">
<span class="legend-dots"></span>
Carrying on foot
</div>
<div class="legend-item">
<span class="transfer-icon">T</span>
Transfer point
</div>
</div>
<div class="camera-help">
Drag to orbit · Right-drag to pan · Scroll to zoom ·
<kbd>1</kbd> <kbd>2</kbd> <kbd>3</kbd> select routes
</div>
</section>
<section class="panel details" id="details" aria-live="polite">
<div class="details-header">
<div class="details-title">
<i></i>
<strong id="details-name"></strong>
</div>
<button class="text-button" id="focus-route">Frame route</button>
</div>
<p class="details-summary" id="details-summary"></p>
<div class="segments" id="segments"></div>
</section>
<div id="loading">Building Moss District…</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 labelsRoot = document.getElementById("labels");
const routeData = {
street: {
id: "street",
name: "Street direct",
short: "Street",
description: "One continuous walk along the road grid",
color: 0xf06b3c,
css: "#f06b3c",
distance: 1.18,
carry: 1.18,
transfers: 0,
minutes: 32,
summary:
"Simplest handover, but the parcel travels the full distance on foot.",
segments: [
{
mode: "Street walk",
distance: 0.24,
carrying: true,
color: "#f06b3c"
},
{
mode: "Street walk",
distance: 0.94,
carrying: true,
color: "#f06b3c"
}
]
},
canal: {
id: "canal",
name: "Canal hybrid",
short: "Hybrid",
description: "Walk to a dock, boat south, walk to the shop",
color: 0x12a89d,
css: "#12a89d",
distance: 1.04,
carry: 0.61,
transfers: 2,
minutes: 27,
summary:
"The boat shortens the trip, with two handovers and a moderate carry.",
segments: [
{
mode: "Walk to dock",
distance: 0.31,
carrying: true,
color: "#12a89d"
},
{
mode: "Canal boat",
distance: 0.43,
carrying: false,
color: "#087c75"
},
{
mode: "Walk to shop",
distance: 0.30,
carrying: true,
color: "#12a89d"
}
]
},
relay: {
id: "relay",
name: "Canal relay",
short: "Relay",
description: "Canal boat, bicycle relay, final doorstep walk",
color: 0x7857d8,
css: "#7857d8",
distance: 0.98,
carry: 0.38,
transfers: 3,
minutes: 24,
summary:
"Fastest estimate, but the extra relay adds a third handover.",
segments: [
{
mode: "Walk to dock",
distance: 0.31,
carrying: true,
color: "#7857d8"
},
{
mode: "Canal boat",
distance: 0.43,
carrying: false,
color: "#5f43bc"
},
{
mode: "Bicycle relay",
distance: 0.17,
carrying: false,
color: "#9579ec"
},
{
mode: "Final walk",
distance: 0.07,
carrying: true,
color: "#7857d8"
}
]
}
};
const routeOrder = ["street", "canal", "relay"];
const state = {
selected: "canal",
visible: {
street: true,
canal: true,
relay: true
},
labelsVisible: true
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e4);
scene.fog = new THREE.Fog(0xdce8e4, 108, 185);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
250
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.12;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly map comparing three delivery routes"
);
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf8fff8, 0x6e8171, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4d5, 3.4);
sun.position.set(-38, 58, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -65;
sun.shadow.camera.right = 65;
sun.shadow.camera.top = 60;
sun.shadow.camera.bottom = -60;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 140;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaedbe3, 1.0);
fill.position.set(35, 22, -40);
scene.add(fill);
const mat = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.88,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
depthWrite: options.depthWrite ?? true
});
const materials = {
base: mat(0xc9d7bd),
grass: mat(0xb9cda6),
water: mat(0x52b9bd, { roughness: 0.38, metalness: 0.05 }),
bank: mat(0xd8cda7),
road: mat(0x7f8d89),
roadEdge: mat(0x6e7d79),
marking: mat(0xe9e6ce),
wood: mat(0xa8794b),
dock: mat(0x8a633d),
white: mat(0xf8f6e8),
dark: mat(0x28433f),
shop: mat(0xd65e3e),
shopRoof: mat(0x673a2e),
depot: mat(0xe0c36d),
depotRoof: mat(0x51615d),
yellow: mat(0xf4c84a, {
emissive: 0x7b5c00,
emissiveIntensity: 0.15
})
};
function addBox(
width,
height,
depth,
x,
y,
z,
material,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(start, end, radius, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let seed = 3817;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
// Diorama base and canal.
addBox(100, 1.1, 86, 0, -0.6, -2, materials.base);
addBox(98, 0.08, 84, 0, -0.01, -2, materials.grass, scene, false);
addBox(10, 0.13, 76, 8, 0.04, -2, materials.water, scene, false);
addBox(1.3, 0.48, 76, 2.0, 0.16, -2, materials.bank);
addBox(1.3, 0.48, 76, 14.0, 0.16, -2, materials.bank);
// Main street grid.
const horizontalRoads = [-22, 0, 15];
for (const z of horizontalRoads) {
addBox(96, 0.12, 5.6, 0, 0.14, z, materials.road, scene, false);
for (let x = -45; x <= 45; x += 5.5) {
addBox(2.2, 0.025, 0.14, x, 0.215, z, materials.marking, scene, false);
}
}
const verticalRoads = [-31, 0, 28];
for (const x of verticalRoads) {
addBox(5.4, 0.13, 70, x, 0.145, -3, materials.road, scene, false);
for (let z = -35; z <= 30; z += 5.5) {
addBox(0.14, 0.025, 2.1, x, 0.22, z, materials.marking, scene, false);
}
}
// Small roads to the docks and canal towpath.
addBox(17, 0.12, 4.1, 22.5, 0.15, -10, materials.road, scene, false);
addBox(42, 0.11, 2.8, -12, 0.15, 13, materials.road, scene, false);
// Bridge rails and decks over the canal.
for (const z of horizontalRoads) {
for (const x of [2.3, 13.7]) {
addBox(0.18, 1.0, 5.8, x, 0.7, z, materials.roadEdge);
}
addBox(11.8, 0.32, 0.18, 8, 0.85, z - 2.6, materials.wood);
addBox(11.8, 0.32, 0.18, 8, 0.85, z + 2.6, materials.wood);
}
const buildingPalette = [
0xe9d6b5,
0xc8d5bd,
0xd9b7a0,
0xaebfc4,
0xe4c985,
0xc9b6d5,
0xb8c9af,
0xd98f78
];
const roofPalette = [
0x795449,
0x536c68,
0x8d6954,
0x687780,
0x77606f
];
const plots = [
[-42, -31], [-42, -12], [-42, 6], [-42, 27],
[-24, -31], [-24, -12], [-24, 7], [-24, 27],
[-10, -31], [-10, -12], [-10, 7],
[21, -31], [21, -12], [21, 7], [21, 27],
[39, -31], [39, -12], [39, 7], [39, 27]
];
function addBuilding(x, z, index, special = false) {
const width = special ? 8 : 5.8 + random() * 3.2;
const depth = special ? 6 : 5.4 + random() * 3.0;
const height = special ? 5.2 : 4 + random() * 6.2;
const wall = mat(
special
? index === 0
? 0xd65e3e
: 0xe0c36d
: buildingPalette[index % buildingPalette.length]
);
const roof = mat(
special
? index === 0
? 0x673a2e
: 0x51615d
: roofPalette[index % roofPalette.length]
);
addBox(width, height, depth, x, height / 2 + 0.2, z, wall);
const roofMesh = new THREE.Mesh(
new THREE.ConeGeometry(Math.max(width, depth) * 0.76, 1.8, 4),
roof
);
roofMesh.rotation.y = Math.PI / 4;
roofMesh.position.set(x, height + 1.05, z);
roofMesh.castShadow = true;
roofMesh.receiveShadow = true;
scene.add(roofMesh);
if (index === 0) {
// Shop awning and front counter.
addBox(7.8, 0.28, 2.0, x, 3.25, z - depth / 2 - 0.7, materials.white);
for (let i = -3; i <= 3; i++) {
addBox(
0.45,
0.35,
2.05,
x + i,
3.28,
z - depth / 2 - 0.7,
mat(i % 2 === 0 ? 0xf4c84a : 0xd65e3e)
);
}
}
if (index === 1) {
// Depot loading bay.
addBox(5.0, 3.0, 0.18, x, 1.9, z - depth / 2 - 0.1, materials.dark);
addBox(4.4, 0.35, 1.3, x, 3.45, z - depth / 2 - 0.6, materials.depotRoof);
}
// A few simple windows.
const windowCount = Math.max(1, Math.floor(width / 2.5));
for (let i = 0; i < windowCount; i++) {
const wx = x - width / 2 + 1.2 + i * ((width - 2.4) / Math.max(1, windowCount - 1));
addBox(
0.7,
0.8,
0.08,
wx,
Math.min(height - 0.8, 2.6),
z - depth / 2 - 0.05,
mat(0xf4d98a, {
emissive: 0x6e4c08,
emissiveIntensity: 0.12
}),
scene,
false
);
}
}
plots.forEach(([x, z], index) => {
addBuilding(x, z, index);
});
addBuilding(-37, 25, 0, true);
addBuilding(36, -28, 1, true);
function addTree(x, z, scale = 1) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.24 * scale, 0.32 * scale, 2.2 * scale, 6),
materials.wood
);
trunk.position.set(x, 1.05 * scale, z);
trunk.castShadow = true;
scene.add(trunk);
const foliageMaterial = mat(
random() > 0.5 ? 0x668e5f : 0x7fa36a
);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(1.45 * scale, 2.8 * scale, 6),
foliageMaterial
);
lower.position.set(x, 3.15 * scale, z);
lower.castShadow = true;
scene.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(1.05 * scale, 2.2 * scale, 6),
foliageMaterial
);
upper.position.set(x, 4.25 * scale, z);
upper.castShadow = true;
scene.add(upper);
}
[
[-46, -36], [-46, -18], [-46, 1], [-46, 20],
[-36, -35], [-17, -35], [-3, -35], [19, -35],
[31, -35], [45, -35], [45, -18], [45, 0],
[45, 18], [31, 31], [19, 31], [-3, 31],
[-17, 31], [-45, 31], [-46, 12], [19, 17],
[30, 17], [31, -17], [-17, -17]
].forEach(([x, z]) => addTree(x, z, 0.72 + random() * 0.34));
// Canal docks.
addBox(5.0, 0.45, 1.3, 16.0, 0.42, -10, materials.dock);
addBox(4.2, 0.42, 1.1, 0.0, 0.40, -10, materials.dock);
addBox(3.2, 0.42, 1.0, 0.0, 0.40, 15, materials.dock);
function createBoat(x, z, rotation = 0, color = 0x2f7772) {
const group = new THREE.Group();
group.position.set(x, 0.44, z);
group.rotation.y = rotation;
const hullMaterial = mat(color);
addBox(1.8, 0.72, 4.0, 0, 0, 0, hullMaterial, group);
const bow = new THREE.Mesh(
new THREE.ConeGeometry(1.25, 1.6, 4),
hullMaterial
);
bow.rotation.x = Math.PI / 2;
bow.rotation.y = Math.PI / 4;
bow.position.set(0, 0, 2.65);
bow.castShadow = true;
group.add(bow);
addBox(1.3, 1.15, 1.35, 0, 0.92, -0.35, materials.white, group);
addBox(1.36, 0.2, 1.4, 0, 1.58, -0.35, materials.dark, group);
addBox(1.05, 0.42, 0.05, 0, 1.05, -1.04, materials.water, group, false);
scene.add(group);
return group;
}
const movingBoat = createBoat(8, -1, 0.12, 0x2f7772);
createBoat(16, -10, Math.PI / 2, 0xb85b43);
createBoat(0, 15, Math.PI / 2, 0x66589c);
// A tiny bicycle on the relay route.
function createBicycle(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.52, z);
group.rotation.y = Math.PI / 2;
const bikeMaterial = mat(0x684fc2);
for (const wheelX of [-0.72, 0.72]) {
const wheel = new THREE.Mesh(
new THREE.TorusGeometry(0.52, 0.08, 5, 10),
materials.dark
);
wheel.position.set(wheelX, 0, 0);
wheel.rotation.y = Math.PI / 2;
group.add(wheel);
}
addCylinderBetween(
new THREE.Vector3(-0.7, 0, 0),
new THREE.Vector3(0.15, 0, 0),
0.055,
bikeMaterial,
group
);
addCylinderBetween(
new THREE.Vector3(0.15, 0, 0),
new THREE.Vector3(0.7, 0, 0),
0.055,
bikeMaterial,
group
);
addCylinderBetween(
new THREE.Vector3(0.15, 0, 0),
new THREE.Vector3(0.15, 0.65, 0),
0.055,
bikeMaterial,
group
);
addBox(0.42, 0.12, 0.22, 0.15, 0.68, 0, materials.dark, group);
scene.add(group);
}
createBicycle(-10, 13);
// Destination and origin markers.
function addEndpoint(x, z, color, symbol = "diamond") {
const group = new THREE.Group();
group.position.set(x, 0.3, z);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.17, 3.2, 8),
materials.dark
);
pole.position.y = 1.5;
pole.castShadow = true;
group.add(pole);
let marker;
if (symbol === "diamond") {
marker = new THREE.Mesh(
new THREE.OctahedronGeometry(1.15, 0),
mat(color, { emissive: color, emissiveIntensity: 0.14 })
);
} else {
marker = new THREE.Mesh(
new THREE.BoxGeometry(1.7, 1.7, 1.7),
mat(color, { emissive: color, emissiveIntensity: 0.12 })
);
}
marker.position.y = 3.55;
marker.castShadow = true;
group.add(marker);
scene.add(group);
return group;
}
addEndpoint(-31, 22, 0xd65e3e, "diamond");
addEndpoint(28, -22, 0xe0b93e, "box");
// Route construction.
const routePickables = [];
const routeObjects = {};
const labelRecords = [];
function createRoundedCurve(points, radius = 1.5) {
const path = new THREE.CurvePath();
let last = points[0].clone();
for (let i = 1; i < points.length - 1; i++) {
const previous = points[i - 1];
const current = points[i];
const next = points[i + 1];
const incomingLength = current.distanceTo(previous);
const outgoingLength = next.distanceTo(current);
const amount = Math.min(radius, incomingLength * 0.28, outgoingLength * 0.28);
const incoming = new THREE.Vector3()
.subVectors(current, previous)
.normalize();
const outgoing = new THREE.Vector3()
.subVectors(next, current)
.normalize();
const before = current.clone().addScaledVector(incoming, -amount);
const after = current.clone().addScaledVector(outgoing, amount);
path.add(new THREE.LineCurve3(last, before));
path.add(new THREE.QuadraticBezierCurve3(before, current, after));
last = after;
}
path.add(new THREE.LineCurve3(last, points[points.length - 1]));
return path;
}
function addMapLabel(text, position, className = "", routeId = null) {
const element = document.createElement("div");
element.className = `map-label ${className}`.trim();
element.textContent = text;
labelsRoot.appendChild(element);
const record = {
element,
position: position.clone(),
routeId,
baseOpacity: routeId ? 0 : 1
};
labelRecords.push(record);
return record;
}
function addTransferMarker(parent, position, routeId, number) {
const group = new THREE.Group();
group.position.copy(position);
group.position.y += 0.42;
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.95, 0.25, 6, 14),
materials.yellow
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.52;
ring.castShadow = true;
group.add(ring);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.14, 2.6, 7),
materials.yellow
);
pole.position.y = 1.25;
group.add(pole);
parent.add(group);
addMapLabel(
`T${number}`,
new THREE.Vector3(position.x, position.y + 2.7, position.z),
"transfer",
routeId
);
}
function addCarryBeads(parent, from, to, routeId, height) {
const start = new THREE.Vector3(from.x, height + 0.28, from.z);
const end = new THREE.Vector3(to.x, height + 0.28, to.z);
const distance = start.distanceTo(end);
const count = Math.max(1, Math.floor(distance / 4.2));
const beadGeometry = new THREE.SphereGeometry(0.27, 6, 4);
for (let i = 0; i < count; i++) {
const t = (i + 0.65) / count;
const bead = new THREE.Mesh(beadGeometry, materials.yellow);
bead.position.lerpVectors(start, end, t);
bead.castShadow = true;
bead.userData.routeId = routeId;
parent.add(bead);
routePickables.push(bead);
}
}
function buildRoute(id, pointData, height, transfers, carryRanges) {
const data = routeData[id];
const group = new THREE.Group();
scene.add(group);
const points = pointData.map(
([x, z]) => new THREE.Vector3(x, height, z)
);
const curve = createRoundedCurve(points, 1.65);
const routeMaterial = mat(data.color, {
roughness: 0.48,
emissive: data.color,
emissiveIntensity: 0.13
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 180, 0.48, 6, false),
routeMaterial
);
tube.castShadow = true;
tube.receiveShadow = true;
tube.userData.routeId = id;
group.add(tube);
routePickables.push(tube);
const haloMaterial = mat(data.color, {
transparent: true,
opacity: 0.15,
depthWrite: false,
emissive: data.color,
emissiveIntensity: 0.18
});
const halo = new THREE.Mesh(
new THREE.TubeGeometry(curve, 180, 0.83, 6, false),
haloMaterial
);
group.add(halo);
for (const [a, b] of carryRanges) {
addCarryBeads(group, points[a], points[b], id, height);
}
transfers.forEach((transfer, index) => {
addTransferMarker(
group,
new THREE.Vector3(transfer[0], height, transfer[1]),
id,
index + 1
);
});
routeObjects[id] = {
group,
tube,
routeMaterial,
haloMaterial
};
}
buildRoute(
"street",
[
[28, -22],
[28, 0],
[-31, 0],
[-31, 22]
],
0.57,
[],
[[0, 3]]
);
buildRoute(
"canal",
[
[28, -22],
[28, -10],
[16, -10],
[0, -10],
[0, 15],
[-31, 15],
[-31, 22]
],
0.68,
[[16, -10], [0, 15]],
[[0, 2], [4, 6]]
);
buildRoute(
"relay",
[
[28, -22],
[28, -10],
[16, -10],
[8, -10],
[8, 13],
[-31, 13],
[-31, 22]
],
0.79,
[[16, -10], [8, 13], [-31, 13]],
[[0, 2], [5, 6]]
);
addMapLabel(
"MOSS CANAL",
new THREE.Vector3(8, 0.5, 28),
"water"
);
addMapLabel(
"LITTLE LANTERN · SHOP",
new THREE.Vector3(-36, 6.2, 25),
"shop"
);
addMapLabel(
"NORTH DEPOT",
new THREE.Vector3(36, 6.2, -28)
);
// Comparison UI.
const routeList = document.getElementById("route-list");
const comparisonBody = document.getElementById("comparison-body");
const details = document.getElementById("details");
const detailsName = document.getElementById("details-name");
const detailsSummary = document.getElementById("details-summary");
const segmentsRoot = document.getElementById("segments");
routeList.innerHTML = routeOrder
.map((id) => {
const route = routeData[id];
return `
<div
class="route-card"
data-route="${id}"
role="button"
tabindex="0"
aria-label="Select ${route.name}"
style="--route-color:${route.css}"
>
<div class="route-top">
<div class="route-title">
<strong>${route.name}</strong>
<small>${route.description}</small>
</div>
<span class="time-pill">${route.minutes} min</span>
</div>
<div class="route-metrics">
<div class="route-metric">
<span>Distance</span>
<b>${route.distance.toFixed(2)} km</b>
</div>
<div class="route-metric">
<span>Carry</span>
<b>${route.carry.toFixed(2)} km</b>
</div>
<div class="route-metric">
<span>Transfers</span>
<b>${route.transfers}</b>
</div>
</div>
<input
class="route-toggle"
type="checkbox"
checked
aria-label="Show ${route.name}"
data-toggle="${id}"
/>
</div>
`;
})
.join("");
comparisonBody.innerHTML = routeOrder
.map((id) => {
const route = routeData[id];
const carryPercent = Math.round((route.carry / route.distance) * 100);
return `
<tr>
<td>
<span class="table-dot" style="background:${route.css}"></span>
${route.short}
</td>
<td>${route.distance.toFixed(2)} km</td>
<td>
${route.carry.toFixed(2)} km
<div class="carry-bar" title="${carryPercent}% carried on foot">
<i style="width:${carryPercent}%"></i>
</div>
</td>
<td>${route.transfers}</td>
<td>${route.minutes}m</td>
</tr>
`;
})
.join("");
function updateSelectionUI() {
document.querySelectorAll(".route-card").forEach((card) => {
card.classList.toggle(
"selected",
card.dataset.route === state.selected
);
});
const route = routeData[state.selected];
details.style.setProperty("--selected-color", route.css);
detailsName.textContent = route.name;
detailsSummary.textContent = route.summary;
segmentsRoot.innerHTML = route.segments
.map(
(segment) => `
<div
class="segment ${segment.carrying ? "carrying" : ""}"
style="--segment-color:${segment.color}"
title="${segment.mode}: ${segment.distance.toFixed(2)} km"
>
<span>${segment.mode}</span>
<b>${segment.distance.toFixed(2)} km</b>
</div>
`
)
.join("");
}
function selectRoute(id) {
state.selected = id;
state.visible[id] = true;
routeObjects[id].group.visible = true;
document
.querySelector(`[data-toggle="${id}"]`)
.setAttribute("checked", "checked");
updateSelectionUI();
}
document.querySelectorAll(".route-card").forEach((card) => {
card.addEventListener("click", (event) => {
if (event.target.classList.contains("route-toggle")) return;
selectRoute(card.dataset.route);
});
card.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
selectRoute(card.dataset.route);
}
});
});
document.querySelectorAll("[data-toggle]").forEach((checkbox) => {
checkbox.addEventListener("click", (event) => {
event.stopPropagation();
});
checkbox.addEventListener("change", (event) => {
const id = event.target.dataset.toggle;
state.visible[id] = event.target.checked;
routeObjects[id].group.visible = event.target.checked;
});
});
document.getElementById("show-all").addEventListener("click", () => {
for (const id of routeOrder) {
state.visible[id] = true;
routeObjects[id].group.visible = true;
document
.querySelector(`[data-toggle="${id}"]`)
.setAttribute("checked", "checked");
}
});
updateSelectionUI();
// Custom orbit/pan/zoom camera controller.
const initialCamera = {
target: new THREE.Vector3(-3, 0, -1),
radius: 80,
phi: 0.86,
theta: 0.74
};
const cameraGoal = { ...initialCamera };
const cameraCurrent = {
target: initialCamera.target.clone(),
radius: initialCamera.radius,
phi: initialCamera.phi,
theta: initialCamera.theta
};
const pointer = {
down: false,
button: 0,
x: 0,
y: 0,
startX: 0,
startY: 0,
moved: false
};
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.down = true;
pointer.button = event.button;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
pointer.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.down) {
updatePointerNDC(event);
const hit = pickRoute();
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (Math.hypot(
event.clientX - pointer.startX,
event.clientY - pointer.startY
) > 4) {
pointer.moved = true;
}
if (pointer.button === 2) {
const right = new THREE.Vector3();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
right.crossVectors(forward, camera.up).normalize();
const amount = cameraCurrent.radius * 0.0015;
cameraGoal.target.addScaledVector(right, -dx * amount);
cameraGoal.target.addScaledVector(forward, dy * amount);
cameraGoal.target.x = THREE.MathUtils.clamp(
cameraGoal.target.x,
-48,
48
);
cameraGoal.target.z = THREE.MathUtils.clamp(
cameraGoal.target.z,
-43,
37
);
} else {
cameraGoal.theta -= dx * 0.005;
cameraGoal.phi = THREE.MathUtils.clamp(
cameraGoal.phi - dy * 0.005,
0.13,
1.43
);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointer.moved && pointer.button === 0) {
updatePointerNDC(event);
const hit = pickRoute();
if (hit) selectRoute(hit);
}
pointer.down = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.down = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius * Math.exp(event.deltaY * 0.001),
32,
132
);
},
{ passive: false }
);
function updatePointerNDC(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function isVisibleInHierarchy(object) {
let current = object;
while (current) {
if (!current.visible) return false;
current = current.parent;
}
return true;
}
function pickRoute() {
raycaster.setFromCamera(pointerNDC, camera);
const intersections = raycaster.intersectObjects(routePickables, false);
const hit = intersections.find((intersection) =>
isVisibleInHierarchy(intersection.object)
);
return hit ? hit.object.userData.routeId : null;
}
document.getElementById("reset-view").addEventListener("click", () => {
cameraGoal.target.copy(initialCamera.target);
cameraGoal.radius = initialCamera.radius;
cameraGoal.phi = initialCamera.phi;
cameraGoal.theta = initialCamera.theta;
});
document.getElementById("top-view").addEventListener("click", () => {
cameraGoal.target.set(-3, 0, -1);
cameraGoal.radius = 94;
cameraGoal.phi = 0.14;
cameraGoal.theta = 0;
});
document.getElementById("toggle-labels").addEventListener("click", (event) => {
state.labelsVisible = !state.labelsVisible;
event.currentTarget.textContent = state.labelsVisible
? "Labels on"
: "Labels off";
});
document.getElementById("focus-route").addEventListener("click", () => {
const group = routeObjects[state.selected].group;
const box = new THREE.Box3().setFromObject(group);
const center = box.getCenter(new THREE.Vector3());
cameraGoal.target.copy(center);
cameraGoal.radius = 62;
cameraGoal.phi = 0.78;
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") selectRoute("street");
if (event.key === "2") selectRoute("canal");
if (event.key === "3") selectRoute("relay");
if (event.key.toLowerCase() === "t") {
document.getElementById("top-view").click();
}
if (event.key.toLowerCase() === "r") {
document.getElementById("reset-view").click();
}
if (event.key.toLowerCase() === "l") {
document.getElementById("toggle-labels").click();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labelRecords) {
let visible = state.labelsVisible;
if (label.routeId) {
visible =
visible &&
state.visible[label.routeId] &&
state.selected === label.routeId;
}
if (!visible) {
label.element.style.display = "none";
continue;
}
projected.copy(label.position).project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
projected.x < -1.15 ||
projected.x > 1.15 ||
projected.y < -1.15 ||
projected.y > 1.15
) {
label.element.style.display = "none";
continue;
}
label.element.style.display = "block";
label.element.style.left =
`${((projected.x + 1) / 2) * window.innerWidth}px`;
label.element.style.top =
`${((-projected.y + 1) / 2) * window.innerHeight}px`;
}
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const damping = 1 - Math.exp(-9 * clock.getDelta());
cameraCurrent.radius = THREE.MathUtils.lerp(
cameraCurrent.radius,
cameraGoal.radius,
damping
);
cameraCurrent.phi = THREE.MathUtils.lerp(
cameraCurrent.phi,
cameraGoal.phi,
damping
);
cameraCurrent.theta = THREE.MathUtils.lerp(
cameraCurrent.theta,
cameraGoal.theta,
damping
);
cameraCurrent.target.lerp(cameraGoal.target, damping);
const spherical = new THREE.Spherical(
cameraCurrent.radius,
cameraCurrent.phi,
cameraCurrent.theta
);
camera.position.setFromSpherical(spherical).add(cameraCurrent.target);
camera.lookAt(cameraCurrent.target);
for (const id of routeOrder) {
const object = routeObjects[id];
const selected = state.selected === id;
object.routeMaterial.emissiveIntensity = selected
? 0.32
: 0.08;
object.haloMaterial.opacity = selected
? 0.19 + Math.sin(clock.elapsedTime * 2.2) * 0.035
: 0.075;
}
movingBoat.position.y =
0.44 + Math.sin(clock.elapsedTime * 1.4) * 0.045;
movingBoat.rotation.z =
Math.sin(clock.elapsedTime * 0.9) * 0.012;
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```