Prompt specification
Build or customize the Three.js 3D scene "Plan a delivery across boat and land segments" 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: Plan a delivery across boat and land segments
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/plan-a-delivery-across-boat-and-land-segments-x2936
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Lamu Old Town's waterfront and lanes. Let users choose a fictional cargo route from landing to courtyard. Show transfer requirements and narrow-passage constraints while preserving distinct boat, pedestrian, and animal paths. Voxel style.
Working Three.js Starter (plan-a-delivery-across-boat-and-land-segments-x2936):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Lamu Old Town — Waterfront Cargo Routes</title>
<style>
:root {
--ink: #17333a;
--muted: #64777a;
--paper: rgba(255, 250, 240, 0.92);
--paper-solid: #fffaf0;
--line: rgba(27, 61, 65, 0.13);
--sea: #169fc5;
--foot: #ef9d31;
--animal: #4e9c68;
--danger: #dc574f;
--shadow: 0 14px 42px rgba(22, 54, 60, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #b9dde4;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.7);
box-shadow: var(--shadow);
backdrop-filter: blur(14px) saturate(1.15);
-webkit-backdrop-filter: blur(14px) saturate(1.15);
}
.brand {
top: 18px;
left: 18px;
width: 330px;
padding: 15px 17px 14px;
border-radius: 17px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
color: #527075;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 3px;
border-radius: 4px;
background: var(--sea);
}
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 600;
line-height: 1.04;
letter-spacing: -0.025em;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.route-panel {
top: 145px;
left: 18px;
width: 330px;
padding: 15px;
border-radius: 17px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 10px;
}
.panel-heading h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.fiction-badge {
padding: 4px 7px;
border-radius: 999px;
background: #e7eee7;
color: #4f6e58;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.route-list {
display: grid;
gap: 8px;
}
.route-button {
position: relative;
display: grid;
grid-template-columns: 35px 1fr auto;
gap: 10px;
align-items: center;
width: 100%;
padding: 11px;
color: var(--ink);
text-align: left;
background: rgba(255, 255, 255, 0.56);
border: 1px solid rgba(32, 69, 73, 0.1);
border-radius: 12px;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.route-button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.92);
border-color: rgba(32, 69, 73, 0.22);
}
.route-button[aria-pressed="true"] {
background: #fffaf0;
border-color: rgba(22, 159, 197, 0.55);
box-shadow:
inset 3px 0 0 var(--sea),
0 7px 16px rgba(35, 74, 78, 0.09);
}
.route-number {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border-radius: 9px;
color: white;
background: #244c53;
font-family: Georgia, serif;
font-size: 18px;
}
.route-button[aria-pressed="true"] .route-number {
background: var(--sea);
}
.route-name {
display: block;
margin-bottom: 3px;
font-size: 13px;
font-weight: 800;
}
.route-sub {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.route-status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--animal);
box-shadow: 0 0 0 4px rgba(78, 156, 104, 0.11);
}
.route-status-dot.warn {
background: var(--danger);
box-shadow: 0 0 0 4px rgba(220, 87, 79, 0.11);
}
.route-hint {
margin: 10px 2px 0;
color: #6a7b7d;
font-size: 10px;
line-height: 1.4;
}
.details {
top: 18px;
right: 18px;
width: 365px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border-radius: 17px;
scrollbar-width: thin;
}
.details-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.details h2 {
margin: 2px 0 4px;
font-family: Georgia, serif;
font-size: 25px;
line-height: 1.05;
font-weight: 600;
}
.details .description {
margin: 10px 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status-chip {
flex: 0 0 auto;
padding: 6px 8px;
border-radius: 999px;
color: #2f7049;
background: #e5f2e8;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-chip.warn {
color: #9a403b;
background: #f9e4df;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 16px;
}
.stat {
padding: 9px 8px;
background: rgba(241, 237, 224, 0.76);
border-radius: 10px;
}
.stat span {
display: block;
margin-bottom: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.stat strong {
font-size: 12px;
}
.section-title {
display: flex;
align-items: center;
gap: 8px;
margin: 17px 0 9px;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title::after {
content: "";
flex: 1;
height: 1px;
background: var(--line);
}
.chain {
display: grid;
gap: 0;
margin-bottom: 6px;
}
.chain-step {
display: grid;
grid-template-columns: 25px 1fr;
gap: 9px;
min-height: 34px;
}
.chain-node {
position: relative;
display: flex;
justify-content: center;
}
.chain-node::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
width: 1px;
background: #d9ded7;
}
.chain-step:first-child .chain-node::before { top: 7px; }
.chain-step:last-child .chain-node::before { bottom: calc(100% - 8px); }
.chain-dot {
position: relative;
z-index: 1;
width: 11px;
height: 11px;
margin-top: 2px;
border: 2px solid var(--paper-solid);
border-radius: 50%;
background: var(--sea);
box-shadow: 0 0 0 1px #d4dedb;
}
.chain-dot.foot { background: var(--foot); }
.chain-dot.animal { background: var(--animal); }
.chain-dot.danger { background: var(--danger); }
.chain-copy {
padding-bottom: 9px;
font-size: 11px;
line-height: 1.35;
}
.chain-copy strong { display: block; font-size: 11px; }
.chain-copy span { color: var(--muted); }
.transfer-list {
display: grid;
gap: 7px;
}
.transfer-card {
display: grid;
grid-template-columns: 27px 1fr;
gap: 9px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.52);
}
.transfer-index {
display: grid;
place-items: center;
width: 26px;
height: 26px;
border-radius: 7px;
color: white;
background: #31545a;
font-size: 10px;
font-weight: 800;
}
.transfer-card strong {
display: block;
margin-bottom: 3px;
font-size: 10px;
}
.transfer-card p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.clearance-list {
display: grid;
gap: 10px;
}
.clearance-row {
padding: 9px 10px;
border-radius: 10px;
background: rgba(241, 237, 224, 0.63);
}
.clearance-label {
display: flex;
justify-content: space-between;
gap: 12px;
font-size: 10px;
}
.clearance-label strong { font-size: 11px; }
.mode-label {
display: inline-flex;
align-items: center;
gap: 6px;
font-weight: 800;
}
.mode-label::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--sea);
}
.mode-label.foot::before { background: var(--foot); }
.mode-label.animal::before { background: var(--animal); }
.mode-label.animal.bad::before { background: var(--danger); }
.gauge {
position: relative;
height: 7px;
margin: 8px 0 5px;
overflow: visible;
border-radius: 99px;
background: #dce2dc;
}
.gauge .fill {
position: absolute;
inset: 0 auto 0 0;
border-radius: inherit;
background: var(--sea);
}
.gauge .fill.foot { background: var(--foot); }
.gauge .fill.animal { background: var(--animal); }
.gauge .fill.bad { background: var(--danger); }
.gauge .threshold {
position: absolute;
top: -3px;
width: 2px;
height: 13px;
background: #324e53;
border-radius: 2px;
}
.clearance-note {
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.clearance-note.bad {
color: #a3423e;
font-weight: 700;
}
.planning-note {
margin-top: 14px;
padding: 10px;
border-left: 3px solid var(--sea);
border-radius: 0 8px 8px 0;
color: #5b7174;
background: rgba(22, 159, 197, 0.07);
font-size: 10px;
line-height: 1.45;
}
.legend {
left: 18px;
bottom: 18px;
display: flex;
gap: 16px;
align-items: center;
padding: 11px 14px;
border-radius: 13px;
color: #405b60;
font-size: 10px;
font-weight: 750;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.legend-line {
width: 26px;
height: 5px;
border-radius: 5px;
background: var(--sea);
}
.legend-line.foot {
height: 4px;
background: var(--foot);
}
.legend-line.animal {
height: 4px;
background: repeating-linear-gradient(
90deg,
var(--animal) 0 7px,
transparent 7px 10px
);
}
.legend-line.closed {
height: 4px;
background: repeating-linear-gradient(
90deg,
var(--danger) 0 7px,
transparent 7px 10px
);
}
.controls {
right: 18px;
bottom: 18px;
display: flex;
gap: 6px;
padding: 7px;
border-radius: 13px;
}
.control-button {
min-width: 34px;
height: 34px;
padding: 0 10px;
color: #294e54;
background: rgba(255, 255, 255, 0.72);
border: 1px solid rgba(35, 74, 78, 0.11);
border-radius: 8px;
cursor: pointer;
font-size: 11px;
font-weight: 800;
}
.control-button:hover {
color: white;
background: #315d64;
}
.control-help {
position: fixed;
z-index: 5;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 999px;
color: rgba(255, 255, 255, 0.92);
background: rgba(20, 49, 54, 0.55);
backdrop-filter: blur(8px);
font-size: 9px;
letter-spacing: 0.03em;
pointer-events: none;
white-space: nowrap;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: #264f55;
background: #b9dde4;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-card {
text-align: center;
}
.loading-card strong {
display: block;
margin-bottom: 8px;
font-family: Georgia, serif;
font-size: 28px;
font-weight: 500;
}
.loading-card span {
color: #5f7b80;
font-size: 11px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
@media (max-width: 980px) {
.brand { width: 285px; }
.route-panel { width: 285px; }
.details { width: 330px; }
.legend { gap: 10px; }
.control-help { display: none; }
}
@media (max-width: 760px) {
.brand {
top: 8px;
left: 8px;
right: 8px;
width: auto;
padding: 10px 12px;
}
.brand h1 { font-size: 21px; }
.brand p { display: none; }
.route-panel {
top: 88px;
left: 8px;
right: 8px;
width: auto;
padding: 10px;
}
.route-list {
display: flex;
overflow-x: auto;
scrollbar-width: none;
}
.route-list::-webkit-scrollbar { display: none; }
.route-button {
flex: 0 0 245px;
padding: 8px;
}
.route-hint { display: none; }
.details {
top: auto;
right: 8px;
bottom: 54px;
left: 8px;
width: auto;
max-height: 38vh;
padding: 14px;
}
.details h2 { font-size: 21px; }
.details .description { display: none; }
.legend { display: none; }
.controls {
right: 8px;
bottom: 8px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel model of Lamu Old Town"></main>
<header class="panel brand">
<div class="eyebrow">Lamu Old Town · Cargo Atlas</div>
<h1>Waterfront to courtyard</h1>
<p>
A fictional transfer-planning model for Lamu’s boat lanes, pedestrian
passages, and animal-assisted final mile.
</p>
</header>
<section class="panel route-panel" aria-labelledby="route-heading">
<div class="panel-heading">
<h2 id="route-heading">Choose a cargo route</h2>
<span class="fiction-badge">Fictional</span>
</div>
<div id="route-list" class="route-list"></div>
<p class="route-hint">
The three colored paths remain separate. Closed passages are marked in red.
</p>
</section>
<aside id="details" class="panel details" aria-live="polite"></aside>
<div class="panel legend" aria-label="Route legend">
<span class="legend-item">
<i class="legend-line"></i> Boat
</span>
<span class="legend-item">
<i class="legend-line foot"></i> Pedestrian
</span>
<span class="legend-item">
<i class="legend-line animal"></i> Animal
</span>
<span class="legend-item">
<i class="legend-line closed"></i> Closed
</span>
</div>
<nav class="panel controls" aria-label="Camera controls">
<button class="control-button" id="zoom-out" title="Zoom out">−</button>
<button class="control-button" id="zoom-in" title="Zoom in">+</button>
<button class="control-button" id="plan-view" title="Show a plan view">Plan</button>
<button class="control-button" id="reset-view" title="Reset camera">Reset</button>
</nav>
<div class="control-help">
Drag to orbit · wheel to zoom · shift-drag to pan · double-click to reset
</div>
<div id="loading">
<div class="loading-card">
<strong>Lamu Old Town</strong>
<span>Building the voxel waterfront…</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Route data: every route uses separate boat, pedestrian, and animal paths.
// Coordinates are [x, z] in the fictional town grid.
// -------------------------------------------------------------------------
const routes = [
{
id: "west-loop",
number: "01",
name: "West Jetty Loop",
subtitle: "Balanced · dhow, porters, donkey",
status: "Cleared",
warning: false,
duration: "38 min",
effort: "Moderate",
transfers: "2",
description:
"The balanced route: a short dhow crossing, a hand-trolley porter leg, and a carefully measured donkey lane into the courtyard.",
boat: [
[-48, 28],
[-37, 25],
[-27, 23],
[-16, 20]
],
walk: [
[-16, 20],
[-16, 7],
[-5, 7],
[-5, -4],
[10, -4]
],
animal: [
[10, -4],
[14, -4],
[14, -14],
[20, -14],
[20, -29]
],
animalStop: 1,
animalOK: true,
chain: [
["boat", "Dhow crossing", "Sea route from the landing pontoon."],
["transfer", "Quay transfer", "Stern ramp to west jetty; lash all crates."],
["foot", "Porter leg", "Hand trolley to the shaded donkey tie."],
["animal", "Animal final mile", "Saddle baskets through the narrow lane."]
],
transfersDetail: [
[
"Dhow → west quay",
"Lower the stern ramp and move four crate stacks in one trolley cycle. Keep the gangway centered."
],
[
"Porters → donkey tie",
"One trolley operator and one tie assistant. Total transfer weight must remain below 120 kg."
],
[
"Donkey → courtyard",
"Use two balanced side baskets, each below 45 kg. Unload at the shaded courtyard store."
]
],
widths: [
["Boat", "Gangway", 1.20, 1.05, "15 cm above the required minimum", false],
["foot", "Pedestrian arcade", 1.42, 1.20, "22 cm above the required minimum", false],
["animal", "Donkey lane", 1.08, 1.00, "8 cm of spare clearance", false]
],
gates: [
{ x: -16, z: 17, axis: "z", width: 1.20, mode: "boat", label: "1.20 m · gangway" },
{ x: -5, z: 3, axis: "z", width: 1.42, mode: "foot", label: "1.42 m · arcade" },
{ x: 14, z: -8, axis: "z", width: 1.08, mode: "animal", label: "1.08 m · donkey lane" }
],
markers: [
[-16, 20, "1"],
[10, -4, "2"],
[20, -29, "3"]
],
note:
"Recommended fictional route. The donkey lane is narrow, so the plan assumes balanced baskets and a spotter at the final corner."
},
{
id: "east-arcade",
number: "02",
name: "East Arcade Run",
subtitle: "Fast crossing · manual fallback",
status: "Donkey closed",
warning: true,
duration: "31 min",
effort: "Heavy",
transfers: "2",
description:
"The boat reaches the east arcade quickly, but the animal branch is too narrow. Porters carry the final crates instead.",
boat: [
[-48, 28],
[-34, 26],
[-12, 23],
[8, 21],
[28, 20]
],
walk: [
[28, 20],
[28, 6],
[16, 6],
[16, -6],
[25, -6],
[25, -17],
[20, -29]
],
animal: [
[16, -6],
[19, -6],
[19, -17],
[20, -29]
],
animalStop: 0.36,
animalOK: false,
chain: [
["boat", "Dhow crossing", "Longer crossing to the east jetty."],
["transfer", "East jetty transfer", "Stern ramp and porters meet at the canopy."],
["foot", "Arcade porter leg", "Continue on foot through the covered arcade."],
["danger", "Animal branch closed", "0.96 m arch is below the 1.00 m minimum."]
],
transfersDetail: [
[
"Dhow → east jetty",
"Transfer under the customs canopy. The quay ramp is narrow, so move one crate stack at a time."
],
[
"Arcade → porter team",
"Use two porters for the long pedestrian section. A second trolley waits at the arcade exit."
],
[
"Animal attempt → manual fallback",
"The donkey branch is closed. Continue the highlighted pedestrian path to the courtyard with two carriers."
]
],
widths: [
["Boat", "East ramp", 1.10, 1.05, "5 cm above the required minimum", false],
["foot", "Covered arcade", 1.38, 1.20, "18 cm above the required minimum", false],
["animal", "Animal arch", 0.96, 1.00, "4 cm below the required minimum", true]
],
gates: [
{ x: 28, z: 17, axis: "z", width: 1.10, mode: "boat", label: "1.10 m · ramp" },
{ x: 16, z: 1, axis: "z", width: 1.38, mode: "foot", label: "1.38 m · arcade" },
{ x: 19, z: -15.4, axis: "z", width: 0.96, mode: "animal", label: "0.96 m · CLOSED", blocked: true }
],
markers: [
[28, 20, "1"],
[16, -6, "2"],
[20, -29, "3"]
],
note:
"The route remains operational as a porter-only cargo run. The red animal branch identifies the closed arch rather than disguising it as a usable path."
},
{
id: "cistern-cut",
number: "03",
name: "Cistern Stair Cut",
subtitle: "Pedestrian only · compact load",
status: "Porters only",
warning: true,
duration: "46 min",
effort: "High",
transfers: "1",
description:
"A quieter cut through the cistern lanes. Footporters can negotiate the stair, but animals cannot use the low pump-house arch.",
boat: [
[-48, 28],
[-37, 25],
[-27, 23],
[-16, 20]
],
walk: [
[-16, 20],
[-16, 7],
[-27, 7],
[-27, -8],
[-36, -8],
[-36, -22],
[5, -22],
[20, -29]
],
animal: [
[5, -22],
[15, -22],
[15, -29],
[20, -29]
],
animalStop: 0.64,
animalOK: false,
chain: [
["boat", "Dhow crossing", "Short sea leg to the west jetty."],
["transfer", "Quay transfer", "One crate trolley to the cistern approach."],
["foot", "Cistern stair", "Footporters use the stepped lane and rear court."],
["danger", "Animal branch closed", "The pump-house arch is only 0.78 m wide."]
],
transfersDetail: [
[
"Dhow → west quay",
"Move one compact trolley at a time. Do not stage more than two crate stacks on the ramp."
],
[
"Quay → cistern stair",
"A rope-assisted porter changes hands at the stair head. Keep each hand load below 35 kg."
],
[
"Cistern → courtyard",
"Animal assistance is not permitted. The porter route continues through the rear courtyard entrance."
]
],
widths: [
["Boat", "West gangway", 1.20, 1.05, "15 cm above the required minimum", false],
["foot", "Cistern stair", 1.16, 1.05, "11 cm above the required minimum", false],
["animal", "Pump-house arch", 0.78, 1.00, "22 cm below the required minimum", true]
],
gates: [
{ x: -16, z: 17, axis: "z", width: 1.20, mode: "boat", label: "1.20 m · gangway" },
{ x: -27, z: -7, axis: "z", width: 1.16, mode: "foot", label: "1.16 m · cistern stair" },
{ x: 15, z: -26.1, axis: "z", width: 0.78, mode: "animal", label: "0.78 m · NO ANIMALS", blocked: true }
],
markers: [
[-16, 20, "1"],
[-27, -8, "2"],
[20, -29, "3"]
],
note:
"Choose this route for light, hand-carried cargo. The visualization keeps the blocked animal attempt visible in green and red while the pedestrian path remains fully operational."
}
];
const COLORS = {
boat: 0x169fc5,
foot: 0xef9d31,
animal: 0x4e9c68,
danger: 0xdc574f,
sand: 0xd9bf91,
stone: 0xb9a98b,
water: 0x2c9fbd,
coral: 0xc9775d,
cream: 0xe8cba2,
wood: 0x72503a,
darkWood: 0x493b32,
green: 0x4d7e52
};
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9dde4);
scene.fog = new THREE.Fog(0xb9dde4, 105, 210);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
400
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const canvas = renderer.domElement;
canvas.tabIndex = 0;
document.getElementById("scene").appendChild(canvas);
const ambient = new THREE.HemisphereLight(0xe9fbff, 0x967552, 2.0);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.1);
sun.position.set(-42, 78, 48);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -90;
sun.shadow.camera.right = 90;
sun.shadow.camera.top = 85;
sun.shadow.camera.bottom = -85;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 190;
sun.shadow.bias = -0.0004;
scene.add(sun);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = [
color,
options.emissive ?? "",
options.emissiveIntensity ?? "",
options.roughness ?? "",
options.metalness ?? "",
options.transparent ?? "",
options.opacity ?? ""
].join("|");
if (!materialCache.has(key)) {
const mat = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
materialCache.set(key, mat);
}
return materialCache.get(key);
}
function box(parent, w, h, d, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
getMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function makeTextSprite(
text,
{
background = "#fffaf0",
foreground = "#24494f",
worldWidth = 6,
worldHeight = 1.5,
border = null
} = {}
) {
const c = document.createElement("canvas");
c.width = 640;
c.height = 144;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
const x = 8;
const y = 8;
const w = c.width - 16;
const h = c.height - 16;
const r = 22;
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();
ctx.fillStyle = background;
ctx.fill();
if (border) {
ctx.lineWidth = 5;
ctx.strokeStyle = border;
ctx.stroke();
}
ctx.fillStyle = foreground;
ctx.font = "800 43px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 2);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Town construction
// -------------------------------------------------------------------------
let randomSeed = 87123;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function createBuilding(x, z, w, d, h, color) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, w + 0.25, 0.38, d + 0.25, 0, 0.19, 0, 0xa88e70);
box(g, w, h, d, 0, h / 2, 0, color);
box(g, w + 0.45, 0.28, d + 0.45, 0, h + 0.08, 0, 0xf0d8b5);
box(g, w, 0.75, 0.24, 0, h + 0.46, d / 2, color);
box(g, w, 0.75, 0.24, 0, h + 0.46, -d / 2, color);
box(g, 0.24, 0.75, d, w / 2, h + 0.46, 0, color);
box(g, 0.24, 0.75, d, -w / 2, h + 0.46, 0, color);
const front = d / 2 + 0.055;
const doorColor = random() > 0.5 ? 0x355e5e : 0x684635;
box(g, 1.35, 2.5, 0.14, 0, 1.25, front, doorColor);
const windowRows = h > 9 ? [3.2, 6.4] : [3.2];
const windowXs = [-w * 0.27, w * 0.27];
for (const wy of windowRows) {
for (const wx of windowXs) {
box(g, 1.18, 1.38, 0.13, wx, wy, front + 0.02, 0x294c51);
box(g, 0.08, 1.4, 0.18, wx, wy, front + 0.1, 0x78543d);
box(g, 1.2, 0.08, 0.18, wx, wy, front + 0.1, 0x78543d);
box(g, 1.65, 0.16, 0.28, wx, wy - 0.78, front + 0.03, 0xe3c298);
}
}
if (random() > 0.35) {
const balconyY = h > 9 ? 5.7 : 4.5;
box(g, w * 0.55, 0.2, 1.1, 0, balconyY, front + 0.48, 0x73523a);
box(g, w * 0.55, 0.12, 0.12, 0, balconyY + 0.75, front + 0.98, 0x60452f);
for (let i = -2; i <= 2; i++) {
box(
g,
0.09,
0.75,
0.09,
i * (w * 0.1),
balconyY + 0.4,
front + 0.98,
0x73523a
);
}
}
if (random() > 0.5) {
box(g, 1.8, 1.25, 1.8, w * 0.2, h + 0.83, -d * 0.15, 0x8c6748);
box(g, 2.0, 0.14, 2.0, w * 0.2, h + 1.49, -d * 0.15, 0x60452f);
}
if (random() > 0.68) {
box(g, 1.8, 0.12, 0.12, -w * 0.2, h + 1.3, d * 0.1, 0x72503a);
box(g, 0.55, 0.8, 0.06, -w * 0.2 + 0.25, h + 0.9, d * 0.1, 0x6ca1a2);
box(g, 0.5, 0.72, 0.06, -w * 0.2 - 0.2, h + 0.85, d * 0.1, 0xd9b276);
}
return g;
}
function createPalm(x, z, height = 9) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
for (let i = 0; i < height; i++) {
const sway = Math.sin(i * 0.33) * 0.18;
box(g, 0.52, 1.05, 0.52, sway, i * 0.92 + 0.5, 0, 0x896342);
}
const top = height * 0.92;
for (let i = 0; i < 7; i++) {
const a = (i / 7) * Math.PI * 2;
const frond = box(
g,
3.7,
0.22,
0.8,
Math.sin(a) * 1.65,
top + 0.25,
Math.cos(a) * 1.65,
i % 2 ? 0x4e8554 : 0x63975c
);
frond.rotation.y = a;
frond.rotation.z = i % 2 ? 0.08 : -0.08;
}
box(g, 0.8, 0.8, 0.8, 0, top - 0.15, 0, 0x5e7741);
}
function createVoxelTree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, 0.55 * scale, 3.1 * scale, 0.55 * scale, 0, 1.55 * scale, 0, 0x725039);
box(g, 2.7 * scale, 1.8 * scale, 2.5 * scale, 0, 3.65 * scale, 0, 0x4c7e50);
box(g, 1.8 * scale, 1.3 * scale, 2.0 * scale, 0.6 * scale, 4.65 * scale, -0.2 * scale, 0x60945c);
box(g, 1.7 * scale, 1.2 * scale, 1.8 * scale, -0.8 * scale, 4.35 * scale, 0.5 * scale, 0x3f7048);
}
function createDhow(scale = 1) {
const g = new THREE.Group();
box(g, 2.1 * scale, 0.55 * scale, 5.3 * scale, 0, 0.35 * scale, 0, 0x69442f);
box(g, 1.55 * scale, 0.4 * scale, 4.7 * scale, 0, 0.76 * scale, 0, 0xa77742);
box(g, 0.16 * scale, 5.7 * scale, 0.16 * scale, 0, 3.2 * scale, 0.6 * scale, 0x5c432f);
box(g, 0.12 * scale, 3.6 * scale, 2.8 * scale, 0.08 * scale, 3.2 * scale, 0.85 * scale, 0xe9d8b5);
box(g, 0.18 * scale, 3.9 * scale, 0.18 * scale, 0, 3.25 * scale, 1.95 * scale, 0x765239);
box(g, 0.7 * scale, 0.65 * scale, 0.7 * scale, -0.45 * scale, 1.15 * scale, -1.55 * scale, 0xa66e3d);
box(g, 0.7 * scale, 0.65 * scale, 0.7 * scale, 0.45 * scale, 1.15 * scale, -1.55 * scale, 0xc38a4b);
return g;
}
function createPerson() {
const g = new THREE.Group();
box(g, 0.42, 0.72, 0.3, 0, 1.12, 0, 0xd06c43);
box(g, 0.37, 0.37, 0.37, 0, 1.72, 0, 0x9b6847);
box(g, 0.52, 0.15, 0.42, 0, 1.94, 0, 0xe8d2a0);
box(g, 0.17, 0.72, 0.18, -0.13, 0.42, 0, 0x35585a);
box(g, 0.17, 0.72, 0.18, 0.13, 0.42, 0, 0x35585a);
box(g, 0.16, 0.65, 0.16, -0.31, 1.08, 0, 0x9b6847);
box(g, 0.16, 0.65, 0.16, 0.31, 1.08, 0, 0x9b6847);
box(g, 0.55, 0.48, 0.48, 0, 1.26, 0.43, 0x9d7344);
return g;
}
function createDonkey() {
const g = new THREE.Group();
box(g, 1.0, 0.78, 1.8, 0, 1.25, 0, 0x6f6b62);
box(g, 0.7, 0.7, 0.72, 0, 1.42, 1.02, 0x777168);
box(g, 0.42, 0.62, 0.4, 0, 1.92, 1.06, 0x777168);
box(g, 0.16, 0.48, 0.18, -0.23, 2.2, 1.0, 0x777168);
box(g, 0.16, 0.48, 0.18, 0.23, 2.2, 1.0, 0x777168);
box(g, 0.2, 0.9, 0.22, -0.32, 0.48, 0.58, 0x5e5b55);
box(g, 0.2, 0.9, 0.22, 0.32, 0.48, 0.58, 0x5e5b55);
box(g, 0.2, 0.9, 0.22, -0.32, 0.48, -0.58, 0x5e5b55);
box(g, 0.2, 0.9, 0.22, 0.32, 0.48, -0.58, 0x5e5b55);
box(g, 0.12, 0.85, 0.12, 0, 1.2, -0.98, 0x4d4944);
box(g, 0.9, 0.2, 1.2, 0, 1.7, 0, 0xa55e3c);
box(g, 0.72, 0.55, 0.72, -0.72, 1.4, 0.25, 0xb48748);
box(g, 0.72, 0.55, 0.72, 0.72, 1.4, 0.25, 0xc09250);
return g;
}
function createEnvironment() {
// Land and water.
box(scene, 142, 1.4, 88, 0, -0.7, -30, COLORS.sand, {
roughness: 0.96,
castShadow: false
});
box(scene, 142, 0.3, 100, 0, -0.52, 64, COLORS.water, {
roughness: 0.25,
metalness: 0.04,
castShadow: false
});
// Voxel shoreline blocks.
for (let x = -68; x <= 68; x += 4) {
box(scene, 3.85, 0.75, 1.1, x, 0.05, 14.15, 0xb9a98b);
}
// West and east jetties.
box(scene, 3.2, 0.55, 7.5, -16, 0.12, 17.2, 0xb8a98d);
box(scene, 3.2, 0.55, 7.5, 28, 0.12, 17.2, 0xb8a98d);
for (const x of [-17.3, -14.7, 26.7, 29.3]) {
for (const z of [14.3, 17.1, 19.9]) {
box(scene, 0.35, 1.7, 0.35, x, 0.78, z, 0x76543d);
}
}
// Offshore landing pontoon.
box(scene, 6.3, 0.5, 4.6, -51, -0.02, 28, 0x9c8566);
for (const x of [-53.5, -48.5]) {
for (const z of [26.3, 29.7]) {
box(scene, 0.35, 2.5, 0.35, x, 0.9, z, 0x654a36);
}
}
const buildingPalette = [
0xc9795f, 0xd28b68, 0xe0aa7f, 0xe7c39a,
0xca8268, 0xd49b76, 0xdcb087, 0xbc705b
];
const rows = [
{
z: 1,
buildings: [[-59, 8], [-44, 9], [-29, 8], [7, 9], [43, 9], [58, 8]]
},
{
z: -13,
buildings: [[-57, 8], [-42, 9], [-25, 8], [-9, 9], [7, 9], [39, 8], [55, 9]]
},
{
z: -29,
buildings: [[-58, 8], [-42, 9], [-25, 8], [-9, 9], [8, 9], [39, 8], [55, 9]]
},
{
z: -46,
buildings: [[-56, 9], [-40, 8], [-24, 9], [-8, 8], [8, 9], [38, 8], [54, 9]]
}
];
let buildingIndex = 0;
for (const row of rows) {
for (const [x, width] of row.buildings) {
const depth = 7 + Math.floor(random() * 3);
const height = 7 + Math.floor(random() * 7);
createBuilding(
x,
row.z,
width,
depth,
height,
buildingPalette[buildingIndex % buildingPalette.length]
);
buildingIndex++;
}
}
// Covered arcade on the east route.
const arcade = new THREE.Group();
scene.add(arcade);
for (const z of [14, 9, 4]) {
box(arcade, 0.55, 4.2, 0.55, 26.35, 2.1, z, COLORS.coral);
box(arcade, 0.55, 4.2, 0.55, 29.65, 2.1, z, COLORS.coral);
}
box(arcade, 4.4, 0.45, 13.5, 28, 4.35, 9, 0xe0aa7f);
box(arcade, 4.8, 0.18, 14, 28, 4.66, 9, 0xf0d8b5);
// Cistern stair-side architecture.
box(scene, 5.2, 2.1, 2.2, -29.4, 1.05, -7.2, 0xb89c7b);
box(scene, 4.4, 0.3, 1.3, -29.2, 2.25, -7.2, 0xd9bb91);
for (let i = 0; i < 4; i++) {
box(scene, 2.3, 0.23, 0.65, -27, 0.13 + i * 0.22, -5.4 - i * 0.58, 0xc3ad8a);
}
// Courtyard.
box(scene, 13, 0.12, 13, 20, 0.07, -34, 0xe0c596);
box(scene, 0.55, 2.6, 12, 13.6, 1.3, -34, 0xcb8264);
box(scene, 0.55, 2.6, 12, 26.4, 1.3, -34, 0xcb8264);
box(scene, 4.1, 2.6, 0.55, 15.75, 1.3, -40, 0xcb8264);
box(scene, 4.1, 2.6, 0.55, 24.25, 1.3, -40, 0xcb8264);
box(scene, 13, 2.6, 0.55, 20, 1.3, -40, 0xcb8264);
box(scene, 3.8, 2.6, 0.55, 17.9, 1.3, -28, 0xcb8264);
box(scene, 3.8, 2.6, 0.55, 22.1, 1.3, -28, 0xcb8264);
box(scene, 1.5, 1.15, 1.5, 20, 0.63, -35, 0x8b806b);
box(scene, 1.1, 0.22, 1.1, 20, 1.3, -35, 0x304e50);
// Crates and a small hand trolley.
for (let i = 0; i < 9; i++) {
box(
scene,
0.8,
0.8,
0.8,
23 + (i % 3) * 0.9,
0.48 + Math.floor(i / 6) * 0.82,
-32 - Math.floor((i % 6) / 3) * 0.9,
i % 2 ? 0xb17a42 : 0x9d6b3e
);
}
box(scene, 1.25, 0.2, 1.0, 7, 0.18, 9.3, 0x5d4937);
box(scene, 0.15, 0.65, 0.15, 7, 0.48, 9.3, 0x5d4937);
box(scene, 0.95, 0.7, 0.85, 7, 0.88, 9.3, 0xb27b43);
// Market stall.
const stall = new THREE.Group();
stall.position.set(-1.5, 0, 10);
scene.add(stall);
for (const x of [-2, 2]) {
for (const z of [-1.2, 1.2]) {
box(stall, 0.15, 2.7, 0.15, x, 1.35, z, 0x6d4d36);
}
}
for (let i = 0; i < 6; i++) {
box(
stall,
0.72,
0.14,
3.1,
-1.8 + i * 0.72,
2.8,
0,
i % 2 ? 0xe9d8b4 : 0xb75e4c
);
}
box(stall, 4.5, 0.85, 1.2, 0, 0.43, -0.4, 0x9c7044);
for (let i = 0; i < 5; i++) {
box(stall, 0.48, 0.48, 0.48, -1.5 + i * 0.75, 1.08, -0.4, i % 2 ? 0xd09b43 : 0x698148);
}
// Palms and trees.
createPalm(-65, 9, 9);
createPalm(-35, 11, 8);
createPalm(35, 10, 10);
createPalm(62, 8, 8);
createPalm(-63, -43, 10);
createPalm(-35, -51, 9);
createPalm(35, -50, 10);
createPalm(59, -40, 8);
createVoxelTree(16.3, -36.2, 0.85);
createVoxelTree(23.7, -37.2, 0.75);
// Static dhows.
const boatA = createDhow(0.9);
boatA.position.set(-7, -0.35, 31);
boatA.rotation.y = 0.72;
scene.add(boatA);
const boatB = createDhow(0.75);
boatB.position.set(-58, -0.35, 22);
boatB.rotation.y = -0.45;
scene.add(boatB);
const boatC = createDhow(0.66);
boatC.position.set(8, -0.35, 32);
boatC.rotation.y = 2.4;
scene.add(boatC);
// Static people and donkey.
const person = createPerson();
person.position.set(22, 0.08, 8.5);
person.rotation.y = -1.4;
scene.add(person);
const donkey = createDonkey();
donkey.position.set(25, 0.08, -35);
donkey.rotation.y = 0.4;
scene.add(donkey);
// Water ripples as pale voxel strips.
const ripples = [];
for (let i = 0; i < 65; i++) {
const x = -69 + random() * 138;
const z = 18 + random() * 78;
const w = 0.8 + random() * 2.8;
const ripple = box(
scene,
w,
0.035,
0.12,
x,
-0.325,
z,
0xbfe8e9,
{
transparent: true,
opacity: 0.28,
castShadow: false
}
);
ripples.push({ mesh: ripple, phase: random() * Math.PI * 2 });
}
// Voxel clouds.
const clouds = [
[-38, 31, 28],
[22, 37, 40],
[56, 29, 6]
];
for (const [x, y, z] of clouds) {
box(scene, 6, 1.2, 2.5, x, y, z, 0xf6f2df, { castShadow: false });
box(scene, 3, 1.7, 2.1, x - 1, y + 0.6, z, 0xf6f2df, { castShadow: false });
box(scene, 3.2, 1.5, 2.2, x + 1.8, y + 0.45, z, 0xf6f2df, { castShadow: false });
}
// Landmark labels.
const landingLabel = makeTextSprite("LANDING PONTOON", {
worldWidth: 10,
worldHeight: 2.1,
background: "#275965",
foreground: "#fffaf0"
});
landingLabel.position.set(-51, 7, 29);
scene.add(landingLabel);
const townLabel = makeTextSprite("OLD TOWN LANES", {
worldWidth: 11,
worldHeight: 2.2,
background: "#fffaf0",
foreground: "#31575b"
});
townLabel.position.set(-8, 17, -10);
scene.add(townLabel);
const courtyardLabel = makeTextSprite("CARGO COURTYARD", {
worldWidth: 10,
worldHeight: 2.1,
background: "#fffaf0",
foreground: "#31575b"
});
courtyardLabel.position.set(20, 6.5, -37);
scene.add(courtyardLabel);
return { ripples };
}
const environment = createEnvironment();
// -------------------------------------------------------------------------
// Route geometry
// -------------------------------------------------------------------------
function pathLength(points) {
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
total += Math.hypot(
points[i + 1][0] - points[i][0],
points[i + 1][1] - points[i][1]
);
}
return total;
}
function splitPathAtFraction(points, fraction) {
const total = pathLength(points);
let remaining = total * fraction;
for (let i = 0; i < points.length - 1; i++) {
const ax = points[i][0];
const az = points[i][1];
const bx = points[i + 1][0];
const bz = points[i + 1][1];
const length = Math.hypot(bx - ax, bz - az);
if (remaining <= length) {
const t = length === 0 ? 0 : remaining / length;
const cut = [ax + (bx - ax) * t, az + (bz - az) * t];
return [
points.slice(0, i + 1).concat([cut]),
[cut].concat(points.slice(i + 1))
];
}
remaining -= length;
}
return [points, []];
}
function createStrip(parent, points, y, width, color, dashed = false) {
const group = new THREE.Group();
parent.add(group);
const pathMat = getMaterial(color, {
roughness: 0.62,
emissive: color,
emissiveIntensity: 0.11
});
const addPiece = (length, x, z, axis) => {
const geometry = axis === "x"
? new THREE.BoxGeometry(length, 0.075, width)
: new THREE.BoxGeometry(width, 0.075, length);
const mesh = new THREE.Mesh(geometry, pathMat);
mesh.position.set(x, y, z);
mesh.receiveShadow = true;
group.add(mesh);
};
for (let i = 0; i < points.length - 1; i++) {
const ax = points[i][0];
const az = points[i][1];
const bx = points[i + 1][0];
const bz = points[i + 1][1];
const length = Math.hypot(bx - ax, bz - az);
if (length < 0.001) continue;
if (dashed) {
const dashLength = width > 1.4 ? 1.8 : 0.72;
const gap = width > 1.4 ? 1.0 : 0.48;
const step = dashLength + gap;
for (let d = 0; d < length; d += step) {
const pieceLength = Math.min(dashLength, length - d);
const t = (d + pieceLength / 2) / length;
const x = ax + (bx - ax) * t;
const z = az + (bz - az) * t;
addPiece(pieceLength, x, z, bx !== ax ? "x" : "z");
}
} else {
addPiece(
length,
(ax + bx) / 2,
(az + bz) / 2,
bx !== ax ? "x" : "z"
);
}
}
for (const [x, z] of points) {
const joint = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.075, width),
pathMat
);
joint.position.set(x, y, z);
group.add(joint);
}
return group;
}
function makeGate(parent, gate) {
const g = new THREE.Group();
g.position.set(gate.x, 0, gate.z);
parent.add(g);
const color = gate.blocked ? COLORS.danger : COLORS.animal;
const visualWidth = Math.max(gate.width, 0.75);
if (gate.axis === "z") {
box(g, 0.2, 2.4, 0.2, -visualWidth / 2, 1.2, 0, color);
box(g, 0.2, 2.4, 0.2, visualWidth / 2, 1.2, 0, color);
box(g, visualWidth + 0.35, 0.18, 0.2, 0, 2.42, 0, color);
} else {
box(g, 0.2, 2.4, 0.2, 0, 1.2, -visualWidth / 2, color);
box(g, 0.2, 2.4, 0.2, 0, 1.2, visualWidth / 2, color);
box(g, 0.2, 0.18, visualWidth + 0.35, 0, 2.42, 0, color);
}
if (gate.blocked) {
const xBar = box(g, 1.4, 0.16, 0.16, 0, 1.4, 0, 0x9f3936);
xBar.rotation.z = Math.PI / 4;
const zBar = box(g, 1.4, 0.16, 0.16, 0, 1.4, 0, 0x9f3936);
zBar.rotation.z = -Math.PI / 4;
}
const label = makeTextSprite(gate.label, {
worldWidth: gate.blocked ? 7.3 : 6.1,
worldHeight: 1.35,
background: gate.blocked ? "#9f3936" : "#fffaf0",
foreground: gate.blocked ? "#ffffff" : "#31575b",
border: gate.blocked ? "#7f2927" : null
});
label.position.set(0, 3.6, 0);
g.add(label);
return g;
}
function makeTransferMarker(parent, x, z, number) {
const marker = makeTextSprite(number, {
worldWidth: 2.2,
worldHeight: 2.2,
background: "#31575b",
foreground: "#fffaf0"
});
marker.position.set(x, 4.4, z);
parent.add(marker);
}
function buildRouteVisual(route) {
const group = new THREE.Group();
scene.add(group);
createStrip(group, route.boat, -0.30, 2.2, COLORS.boat, true);
createStrip(group, route.walk, 0.14, 0.9, COLORS.foot, false);
if (route.animalOK) {
createStrip(group, route.animal, 0.20, 0.72, COLORS.animal, true);
} else {
const [allowed, closed] = splitPathAtFraction(route.animal, route.animalStop);
createStrip(group, allowed, 0.20, 0.72, COLORS.animal, true);
createStrip(group, closed, 0.21, 0.72, COLORS.danger, true);
}
route.gates.forEach(gate => makeGate(group, gate));
route.markers.forEach(([x, z, number]) => makeTransferMarker(group, x, z, number));
group.visible = false;
route.visual = group;
}
routes.forEach(buildRouteVisual);
// Moving route actors.
const movingDhow = createDhow(0.82);
scene.add(movingDhow);
const movingPorter = createPerson();
scene.add(movingPorter);
const movingDonkey = createDonkey();
scene.add(movingDonkey);
function samplePath(points, t) {
const total = pathLength(points);
let distance = ((t % 1) + 1) % 1 * total;
for (let i = 0; i < points.length - 1; i++) {
const ax = points[i][0];
const az = points[i][1];
const bx = points[i + 1][0];
const bz = points[i + 1][1];
const length = Math.hypot(bx - ax, bz - az);
if (distance <= length || i === points.length - 2) {
const localT = length === 0 ? 0 : Math.min(distance / length, 1);
return {
x: ax + (bx - ax) * localT,
z: az + (bz - az) * localT,
angle: Math.atan2(bx - ax, bz - az)
};
}
distance -= length;
}
return { x: points[0][0], z: points[0][1], angle: 0 };
}
// -------------------------------------------------------------------------
// Route selection and details panel
// -------------------------------------------------------------------------
let activeRoute = routes[0];
const routeList = document.getElementById("route-list");
const details = document.getElementById("details");
routes.forEach(route => {
const button = document.createElement("button");
button.className = "route-button";
button.type = "button";
button.setAttribute("aria-pressed", String(route.id === activeRoute.id));
button.dataset.route = route.id;
button.innerHTML = `
<span class="route-number">${route.number}</span>
<span>
<span class="route-name">${route.name}</span>
<span class="route-sub">${route.subtitle}</span>
</span>
<span class="route-status-dot ${route.warning ? "warn" : ""}"></span>
`;
button.addEventListener("click", () => selectRoute(route.id));
routeList.appendChild(button);
});
function widthRow(row) {
const [mode, label, value, minimum, note, bad] = row;
const maxScale = 1.6;
const fill = Math.min(100, value / maxScale * 100);
const threshold = Math.min(100, minimum / maxScale * 100);
const modeClass = mode === "animal" && bad ? " animal bad" : ` ${mode}`;
return `
<div class="clearance-row">
<div class="clearance-label">
<span class="mode-label${modeClass}">${label}</span>
<strong>${value.toFixed(2)} m</strong>
</div>
<div class="gauge">
<span class="fill ${mode === "foot" ? "foot" : mode}${bad ? " bad" : ""}" style="width:${fill}%"></span>
<span class="threshold" style="left:${threshold}%"></span>
</div>
<div class="clearance-note ${bad ? "bad" : ""}">
Minimum ${minimum.toFixed(2)} m · ${note}
</div>
</div>
`;
}
function renderDetails(route) {
const chain = route.chain.map(step => {
const dotClass = step[0] === "transfer"
? ""
: step[0] === "danger"
? " danger"
: ` ${step[0]}`;
return `
<div class="chain-step">
<div class="chain-node"><span class="chain-dot${dotClass}"></span></div>
<div class="chain-copy">
<strong>${step[1]}</strong>
<span>${step[2]}</span>
</div>
</div>
`;
}).join("");
const transfers = route.transfersDetail.map((transfer, index) => `
<div class="transfer-card">
<span class="transfer-index">${index + 1}</span>
<div>
<strong>${transfer[0]}</strong>
<p>${transfer[1]}</p>
</div>
</div>
`).join("");
details.innerHTML = `
<div class="details-top">
<div>
<div class="eyebrow">Route ${route.number}</div>
<h2>${route.name}</h2>
</div>
<span class="status-chip ${route.warning ? "warn" : ""}">${route.status}</span>
</div>
<p class="description">${route.description}</p>
<div class="stats">
<div class="stat"><span>Duration</span><strong>${route.duration}</strong></div>
<div class="stat"><span>Effort</span><strong>${route.effort}</strong></div>
<div class="stat"><span>Transfers</span><strong>${route.transfers}</strong></div>
</div>
<div class="section-title">Mode chain</div>
<div class="chain">${chain}</div>
<div class="section-title">Transfer requirements</div>
<div class="transfer-list">${transfers}</div>
<div class="section-title">Narrow-passage checks</div>
<div class="clearance-list">
${route.widths.map(widthRow).join("")}
</div>
<div class="planning-note">${route.note}</div>
`;
}
function selectRoute(id) {
activeRoute = routes.find(route => route.id === id);
routes.forEach(route => {
route.visual.visible = route.id === activeRoute.id;
});
document.querySelectorAll(".route-button").forEach(button => {
button.setAttribute(
"aria-pressed",
String(button.dataset.route === activeRoute.id)
);
});
renderDetails(activeRoute);
}
renderDetails(activeRoute);
routes[0].visual.visible = true;
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, touch pinch, and plan view.
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.62,
phi: 0.84,
radius: 119,
target: new THREE.Vector3(0, 2, -8)
};
const defaultCamera = {
theta: 0.62,
phi: 0.84,
radius: 119,
target: new THREE.Vector3(0, 2, -8)
};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
cameraState.phi = clamp(cameraState.phi, 0.12, 1.36);
cameraState.radius = clamp(cameraState.radius, 42, 170);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const pointers = new Map();
let previousPinchDistance = 0;
let panning = false;
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);
}
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
panning = event.shiftKey || event.button === 2;
if (pointers.size === 2) previousPinchDistance = pointerDistance();
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
if (panning) {
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.theta),
0,
-Math.cos(cameraState.theta)
);
const scale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi -= dy * 0.005;
}
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.radius *= previousPinchDistance / distance;
}
previousPinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
function resetCamera() {
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.radius = defaultCamera.radius;
cameraState.target.copy(defaultCamera.target);
updateCamera();
}
document.getElementById("zoom-in").addEventListener("click", () => {
cameraState.radius *= 0.84;
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
cameraState.radius *= 1.16;
updateCamera();
});
document.getElementById("plan-view").addEventListener("click", () => {
cameraState.theta = 0;
cameraState.phi = 0.16;
cameraState.radius = 112;
cameraState.target.set(0, 1, -8);
updateCamera();
});
document.getElementById("reset-view").addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") cameraState.theta -= 0.08;
if (event.key === "ArrowRight") cameraState.theta += 0.08;
if (event.key === "ArrowUp") cameraState.phi -= 0.06;
if (event.key === "ArrowDown") cameraState.phi += 0.06;
if (event.key === "+" || event.key === "=") cameraState.radius *= 0.9;
if (event.key === "-") cameraState.radius *= 1.1;
if (event.key === "r") resetCamera();
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
});
updateCamera();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let boatPhase = 0;
let porterPhase = 0;
let donkeyPhase = 0;
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (!reducedMotion) {
boatPhase = (boatPhase + delta * 0.028) % 1;
porterPhase = (porterPhase + delta * 0.055) % 1;
donkeyPhase = (donkeyPhase + delta * 0.035) % 1;
}
const boatSample = samplePath(activeRoute.boat, boatPhase);
movingDhow.position.set(
boatSample.x,
-0.37 + Math.sin(time * 2.1) * 0.035,
boatSample.z
);
movingDhow.rotation.y = boatSample.angle;
movingDhow.rotation.z = Math.sin(time * 1.2) * 0.012;
const porterSample = samplePath(activeRoute.walk, porterPhase);
movingPorter.position.set(
porterSample.x,
0.12 + Math.abs(Math.sin(time * 7)) * 0.025,
porterSample.z
);
movingPorter.rotation.y = porterSample.angle;
let donkeyT = donkeyPhase;
if (!activeRoute.animalOK) {
const pingPong = donkeyPhase < 0.5
? donkeyPhase * 2
: (1 - donkeyPhase) * 2;
donkeyT = pingPong * activeRoute.animalStop;
}
const donkeySample = samplePath(activeRoute.animal, donkeyT);
movingDonkey.position.set(
donkeySample.x,
0.12 + Math.abs(Math.sin(time * 6)) * 0.018,
donkeySample.z
);
movingDonkey.rotation.y = donkeySample.angle;
for (const ripple of environment.ripples) {
ripple.mesh.position.y = -0.325 + Math.sin(time * 1.4 + ripple.phase) * 0.012;
ripple.mesh.material.opacity = 0.22 + Math.sin(time + ripple.phase) * 0.06;
}
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```