Prompt specification
Build or customize the Three.js 3D scene "Plan quiet and busy boat routes through canals" 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 quiet and busy boat routes through canals
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/plan-quiet-and-busy-boat-routes-through-canals-x2756
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Xochimilco's canals and chinampas in Mexico City. Let users choose fictional boat paths with speed and access constraints. Highlight conflicts near cultivation landings while separating the exercise from actual local navigation regulations. Voxel style.
Working Three.js Starter (plan-quiet-and-busy-boat-routes-through-canals-x2756):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Xochimilco — Chinampa Route Lab</title>
<style>
:root {
--ink: #132b32;
--panel: rgba(246, 242, 222, 0.96);
--panel-soft: rgba(255, 255, 255, 0.55);
--line: rgba(19, 43, 50, 0.15);
--green: #2c7a5a;
--green-dark: #15513f;
--yellow: #f2c85b;
--coral: #ee684d;
--blue: #347d96;
--muted: #63777a;
--shadow: 0 18px 50px rgba(11, 39, 45, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #91c1bd;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(15, 44, 50, 0.16), transparent 22%),
radial-gradient(circle at center, transparent 48%, rgba(12, 38, 43, 0.2));
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
right: 398px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.brand {
min-width: 280px;
padding: 14px 17px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 16px;
background: rgba(246, 242, 222, 0.92);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 5px;
color: var(--green);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: 21px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.brand p {
margin: 6px 0 0;
color: var(--muted);
font-size: 12px;
}
.exercise-badge {
max-width: 280px;
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 14px;
background: rgba(19, 43, 50, 0.9);
color: #f6f2de;
box-shadow: var(--shadow);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
line-height: 1.45;
text-align: right;
text-transform: uppercase;
}
.exercise-badge strong {
display: block;
margin-top: 3px;
color: var(--yellow);
font-size: 11px;
}
.panel {
position: fixed;
z-index: 20;
top: 18px;
right: 18px;
bottom: 18px;
width: 360px;
padding: 17px;
overflow-y: auto;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
scrollbar-width: thin;
scrollbar-color: rgba(19, 43, 50, 0.25) transparent;
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-bottom: 13px;
border-bottom: 1px solid var(--line);
}
.panel-header h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.025em;
}
.live-pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border-radius: 999px;
background: #dce9d9;
color: var(--green-dark);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live-pill::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
content: "";
box-shadow: 0 0 0 4px rgba(44, 122, 90, 0.13);
}
.section {
padding: 15px 0;
border-bottom: 1px solid var(--line);
}
.section:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.route-list {
display: grid;
gap: 8px;
}
.route-card {
position: relative;
width: 100%;
padding: 11px 12px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.5);
cursor: pointer;
text-align: left;
transition:
transform 150ms ease,
border-color 150ms ease,
background 150ms ease;
}
.route-card:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.76);
}
.route-card.selected {
border-color: var(--route-color);
background: rgba(255, 255, 255, 0.9);
box-shadow: inset 4px 0 0 var(--route-color);
}
.route-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.route-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
font-weight: 850;
}
.route-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--route-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--route-color), transparent 75%);
}
.route-number {
color: var(--muted);
font-size: 10px;
font-weight: 800;
}
.route-description {
margin: 5px 0 8px 17px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.tags {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-left: 17px;
}
.tag {
padding: 4px 6px;
border-radius: 5px;
background: #e8eee4;
color: #365b54;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.control-row {
margin-top: 12px;
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
font-size: 11px;
font-weight: 750;
}
.control-value {
color: var(--green);
font-variant-numeric: tabular-nums;
font-weight: 900;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 7px 0 4px;
border-radius: 99px;
outline: none;
background: linear-gradient(
to right,
var(--green) 0%,
var(--green) var(--range-fill, 40%),
#d5ddd3 var(--range-fill, 40%),
#d5ddd3 100%
);
appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid var(--panel);
border-radius: 50%;
background: var(--green);
box-shadow: 0 1px 6px rgba(19, 43, 50, 0.25);
cursor: pointer;
appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid var(--panel);
border-radius: 50%;
background: var(--green);
box-shadow: 0 1px 6px rgba(19, 43, 50, 0.25);
cursor: pointer;
}
select {
width: 100%;
padding: 9px 31px 9px 10px;
border: 1px solid var(--line);
border-radius: 9px;
outline: none;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
font-size: 11px;
font-weight: 700;
}
.status-box {
padding: 11px;
border: 1px solid rgba(44, 122, 90, 0.25);
border-radius: 11px;
background: #e0ebdc;
}
.status-box.warning {
border-color: rgba(238, 104, 77, 0.35);
background: #f5dfd4;
}
.status-title {
display: flex;
align-items: center;
gap: 7px;
font-size: 11px;
font-weight: 900;
}
.status-icon {
display: grid;
width: 18px;
height: 18px;
place-items: center;
border-radius: 50%;
background: var(--green);
color: white;
font-size: 11px;
}
.warning .status-icon {
background: var(--coral);
}
.status-detail {
margin: 5px 0 0 25px;
color: #526a69;
font-size: 10px;
line-height: 1.45;
}
.small-button {
width: 100%;
margin-top: 8px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.6);
cursor: pointer;
font-size: 10px;
font-weight: 850;
}
.small-button:hover {
background: white;
}
.metric-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.metric {
padding: 9px 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.48);
}
.metric-label {
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
margin-top: 4px;
font-size: 14px;
font-weight: 900;
font-variant-numeric: tabular-nums;
}
.event-line {
display: flex;
align-items: center;
gap: 9px;
margin-top: 10px;
padding: 9px 10px;
border-radius: 9px;
background: #e6eee8;
color: #31564f;
font-size: 10px;
font-weight: 750;
}
.event-line.alert {
background: #f6ddd3;
color: #9e3f2d;
}
.event-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--green);
}
.alert .event-dot {
background: var(--coral);
animation: blink 600ms steps(2, end) infinite;
}
@keyframes blink {
50% {
opacity: 0.3;
}
}
.notice {
margin-top: 13px;
padding: 11px;
border-left: 3px solid var(--coral);
border-radius: 7px;
background: rgba(238, 104, 77, 0.1);
color: #6b5049;
font-size: 9px;
line-height: 1.5;
}
.notice strong {
color: #923f2f;
}
.view-controls {
position: fixed;
z-index: 11;
left: 18px;
bottom: 72px;
display: flex;
gap: 7px;
}
.view-button {
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 10px;
background: rgba(246, 242, 222, 0.91);
box-shadow: 0 8px 25px rgba(11, 39, 45, 0.18);
cursor: pointer;
font-size: 10px;
font-weight: 850;
}
.view-button:hover {
background: white;
}
.legend {
position: fixed;
z-index: 10;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 11px;
max-width: calc(100vw - 410px);
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 11px;
background: rgba(246, 242, 222, 0.88);
box-shadow: 0 8px 25px rgba(11, 39, 45, 0.16);
color: #38565a;
font-size: 9px;
font-weight: 750;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
background: #4f9468;
}
.swatch.route {
background: var(--yellow);
}
.swatch.conflict {
background: var(--coral);
}
.swatch.landing {
background: #6d513a;
}
.camera-help {
position: fixed;
z-index: 9;
left: 50%;
bottom: 23px;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 99px;
background: rgba(19, 43, 50, 0.72);
color: rgba(255, 255, 255, 0.84);
font-size: 9px;
font-weight: 700;
pointer-events: none;
}
@media (max-width: 760px) {
.topbar {
right: 12px;
left: 12px;
top: 12px;
}
.brand {
min-width: 0;
padding: 11px 13px;
}
.brand h1 {
font-size: 17px;
}
.brand p {
display: none;
}
.exercise-badge {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
padding: 14px;
border-radius: 17px;
}
.view-controls {
top: 80px;
bottom: auto;
left: 12px;
}
.legend,
.camera-help {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel model of Xochimilco canals and chinampas"></div>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Mexico City · Voxel Planning Study</div>
<h1>Xochimilco Chinampa Route Lab</h1>
<p>Fictional canal paths, access profiles, and landing conflicts.</p>
</div>
<div class="exercise-badge">
Fictional exercise only
<strong>Not for actual navigation</strong>
</div>
</header>
<aside class="panel" aria-label="Route planning controls">
<div class="panel-header">
<div>
<div class="eyebrow">Scenario Builder</div>
<h2>Choose a training route</h2>
</div>
<div class="live-pill" id="livePill">Running</div>
</div>
<section class="section">
<div class="section-title">
<span>01 · Fictional paths</span>
<span>Select one</span>
</div>
<div class="route-list" id="routeList"></div>
</section>
<section class="section">
<div class="section-title">
<span>02 · Operating profile</span>
<span id="clockLabel">00:00</span>
</div>
<div class="control-row">
<div class="control-label">
<span>Traffic speed</span>
<span class="control-value" id="speedValue">2.6 kn</span>
</div>
<input
id="speed"
type="range"
min="1"
max="6"
step="0.1"
value="2.6"
aria-label="Traffic speed in knots"
/>
</div>
<div class="control-row">
<div class="control-label">
<label for="beam">Training vessel beam</label>
<span class="control-value" id="beamValue">1.6 m</span>
</div>
<select id="beam">
<option value="1.6">1.6 m · narrow skiff</option>
<option value="2.0">2.0 m · standard barge</option>
<option value="2.4">2.4 m · wide workboat</option>
<option value="2.8">2.8 m · wide training hull</option>
</select>
</div>
<div class="control-row">
<div class="control-label">
<label for="access">Access profile</label>
</div>
<select id="access">
<option value="standard">Standard public access</option>
<option value="reservation">Reserved landing window</option>
<option value="low">Low-water channel</option>
</select>
</div>
</section>
<section class="section">
<div class="section-title">
<span>03 · Constraint check</span>
<span id="selectedRouteLabel">Canal Calabaza</span>
</div>
<div class="status-box" id="statusBox">
<div class="status-title">
<span class="status-icon" id="statusIcon">✓</span>
<span id="statusTitle">Compatible simulation</span>
</div>
<div class="status-detail" id="statusDetail">
The selected fictional profile satisfies this route’s assumed limits.
</div>
</div>
<button class="small-button" id="matchButton" type="button">
Find a compatible fictional route
</button>
</section>
<section class="section">
<div class="section-title">
<span>Live scenario</span>
<button
id="playButton"
class="small-button"
type="button"
style="width: auto; margin: 0; padding: 5px 9px"
>
Pause
</button>
</div>
<div class="metric-grid">
<div class="metric">
<div class="metric-label">Conflicts</div>
<div class="metric-value" id="conflictCount">0</div>
</div>
<div class="metric">
<div class="metric-label">Traffic</div>
<div class="metric-value">3</div>
</div>
<div class="metric">
<div class="metric-label">Cycle</div>
<div class="metric-value" id="cycleValue">28s</div>
</div>
</div>
<div class="event-line" id="eventLine">
<span class="event-dot"></span>
<span id="eventText">Landing corridors currently clear</span>
</div>
</section>
<div class="notice">
<strong>Separate from real navigation rules.</strong>
All route names, limits, access profiles, landing names, and traffic events
are fictional teaching devices. This model does not represent current
local regulations, water levels, permissions, or safe navigation advice.
Consult local authorities and posted guidance for real travel.
</div>
</aside>
<div class="view-controls" aria-label="Camera controls">
<button class="view-button" id="isoButton" type="button">Isometric</button>
<button class="view-button" id="topButton" type="button">Top view</button>
<button class="view-button" id="resetButton" type="button">Reset</button>
<button class="view-button" id="zoomIn" type="button">+</button>
<button class="view-button" id="zoomOut" type="button">−</button>
</div>
<div class="legend">
<div class="legend-item"><span class="swatch"></span> Chinampa plots</div>
<div class="legend-item"><span class="swatch route"></span> Fictional route</div>
<div class="legend-item"><span class="swatch landing"></span> Landing</div>
<div class="legend-item"><span class="swatch conflict"></span> Simulated conflict</div>
</div>
<div class="camera-help">Drag to orbit · Right-drag to pan · Scroll to zoom · 1–3 routes</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Data and UI
// ------------------------------------------------------------
const routeList = document.querySelector("#routeList");
const speedInput = document.querySelector("#speed");
const speedValue = document.querySelector("#speedValue");
const beamSelect = document.querySelector("#beam");
const beamValue = document.querySelector("#beamValue");
const accessSelect = document.querySelector("#access");
const statusBox = document.querySelector("#statusBox");
const statusIcon = document.querySelector("#statusIcon");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
const selectedRouteLabel = document.querySelector("#selectedRouteLabel");
const conflictCount = document.querySelector("#conflictCount");
const cycleValue = document.querySelector("#cycleValue");
const eventLine = document.querySelector("#eventLine");
const eventText = document.querySelector("#eventText");
const clockLabel = document.querySelector("#clockLabel");
const playButton = document.querySelector("#playButton");
const livePill = document.querySelector("#livePill");
const accessNames = {
standard: "Standard public",
reservation: "Reserved landing",
low: "Low-water channel"
};
const routes = [
{
id: "calabaza",
number: "01",
name: "Canal Calabaza",
color: 0xf2c85b,
css: "#f2c85b",
description: "Long east–west loop through the outer chinampa fields.",
maxSpeed: 4.5,
maxBeam: 2.4,
access: ["standard", "reservation", "low"],
points: [
[-60, -16], [-49, -16], [-38, -16], [-38, 6],
[-17, 6], [-6, 6], [4, 6], [4, 31],
[25, 31], [36, 31], [47, 31], [57, 22], [58, -16]
]
},
{
id: "caballito",
number: "02",
name: "Pasaje del Caballito",
color: 0x49b7a6,
css: "#49b7a6",
description: "Narrow inner passage with a lower assumed access limit.",
maxSpeed: 3.2,
maxBeam: 1.8,
access: ["standard"],
points: [
[-60, 6], [-50, 6], [-38, 6], [-27, 6],
[-17, 6], [-6, 6], [4, 31], [15, 31],
[25, 31], [36, 14], [47, 14], [58, 6], [58, -16]
]
},
{
id: "chopos",
number: "03",
name: "Travesía de los Chopos",
color: 0xf07b57,
css: "#f07b57",
description: "Long perimeter route using wider assumed canal access.",
maxSpeed: 5.0,
maxBeam: 2.8,
access: ["standard", "low"],
points: [
[-60, 31], [-50, 31], [-38, 31], [-17, 31],
[-17, 6], [-6, 6], [4, 6], [4, -39],
[25, -39], [47, -16], [58, -16], [58, 31], [25, 31]
]
}
];
let selectedRouteId = routes[0].id;
let simulationTime = 0;
let simulationPlaying = true;
function getSelectedRoute() {
return routes.find((route) => route.id === selectedRouteId);
}
routes.forEach((route) => {
const button = document.createElement("button");
button.type = "button";
button.className = "route-card";
button.dataset.route = route.id;
button.style.setProperty("--route-color", route.css);
button.innerHTML = `
<div class="route-top">
<div class="route-name">
<span class="route-dot"></span>
${route.name}
</div>
<span class="route-number">${route.number}</span>
</div>
<div class="route-description">${route.description}</div>
<div class="tags">
<span class="tag">≤ ${route.maxSpeed.toFixed(1)} kn</span>
<span class="tag">≤ ${route.maxBeam.toFixed(1)} m beam</span>
${route.access.map((a) => `<span class="tag">${accessNames[a]}</span>`).join("")}
</div>
`;
button.addEventListener("click", () => selectRoute(route.id));
routeList.appendChild(button);
});
function selectRoute(id) {
selectedRouteId = id;
updateRouteSelection();
updateConstraintStatus();
}
function updateRouteSelection() {
document.querySelectorAll(".route-card").forEach((card) => {
card.classList.toggle("selected", card.dataset.route === selectedRouteId);
});
selectedRouteLabel.textContent = getSelectedRoute().name;
routes.forEach((route) => {
const selected = route.id === selectedRouteId;
route.pathMaterial.opacity = selected ? 0.95 : 0.28;
route.pathMaterial.color.setHex(selected ? route.color : 0x789796);
route.segments.forEach((segment) => {
segment.scale.z = selected ? 1.65 : 0.8;
});
route.label.material.opacity = selected ? 1 : 0.42;
route.boat.scale.setScalar(selected ? 1.16 : 0.9);
});
}
function updateConstraintStatus() {
const route = getSelectedRoute();
const speed = Number(speedInput.value);
const beam = Number(beamSelect.value);
const access = accessSelect.value;
const issues = [];
if (speed > route.maxSpeed) {
issues.push(`speed is above the fictional ${route.maxSpeed.toFixed(1)} kn route cap`);
}
if (beam > route.maxBeam) {
issues.push(`the ${beam.toFixed(1)} m beam exceeds the fictional ${route.maxBeam.toFixed(1)} m limit`);
}
if (!route.access.includes(access)) {
issues.push(`${accessNames[access].toLowerCase()} access is not assumed on this route`);
}
if (issues.length === 0) {
statusBox.classList.remove("warning");
statusIcon.textContent = "✓";
statusTitle.textContent = "Compatible simulation";
statusDetail.textContent =
"The selected fictional profile satisfies this route’s assumed limits.";
} else {
statusBox.classList.add("warning");
statusIcon.textContent = "!";
statusTitle.textContent = "Constraint mismatch";
statusDetail.textContent =
issues.join("; ") + ". The scene continues for comparison only.";
}
}
speedInput.addEventListener("input", () => {
speedValue.textContent = `${Number(speedInput.value).toFixed(1)} kn`;
const percent =
((Number(speedInput.value) - Number(speedInput.min)) /
(Number(speedInput.max) - Number(speedInput.min))) *
100;
speedInput.style.setProperty("--range-fill", `${percent}%`);
cycleValue.textContent = `${Math.round(72 / Number(speedInput.value))}s`;
updateConstraintStatus();
});
beamSelect.addEventListener("change", () => {
beamValue.textContent = `${Number(beamSelect.value).toFixed(1)} m`;
updateConstraintStatus();
});
accessSelect.addEventListener("change", updateConstraintStatus);
document.querySelector("#matchButton").addEventListener("click", () => {
const speed = Number(speedInput.value);
const beam = Number(beamSelect.value);
const access = accessSelect.value;
const match = routes.find(
(route) =>
speed <= route.maxSpeed &&
beam <= route.maxBeam &&
route.access.includes(access)
);
if (match) {
selectRoute(match.id);
} else {
statusBox.classList.add("warning");
statusIcon.textContent = "!";
statusTitle.textContent = "No compatible fictional route";
statusDetail.textContent =
"No assumed route satisfies all three settings. Reduce the speed or beam, or choose standard public access.";
}
});
playButton.addEventListener("click", () => {
simulationPlaying = !simulationPlaying;
playButton.textContent = simulationPlaying ? "Pause" : "Play";
livePill.textContent = simulationPlaying ? "Running" : "Paused";
});
// ------------------------------------------------------------
// Three.js setup
// ------------------------------------------------------------
const container = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9ccbc3);
scene.fog = new THREE.Fog(0x9ccbc3, 95, 205);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
350
);
const ambient = new THREE.HemisphereLight(0xe9f5e7, 0x315b62, 2.1);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xfff0c3, 3.0);
sun.position.set(-45, 85, 35);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -90;
sun.shadow.camera.right = 90;
sun.shadow.camera.top = 80;
sun.shadow.camera.bottom = -80;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 220;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8cc8df, 0.65);
fill.position.set(60, 30, -60);
scene.add(fill);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshLambertMaterial({ color, ...options })
);
}
return materialCache.get(key);
}
function box(width, height, depth, color, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
typeof color === "number" ? material(color) : color
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
const random = seededRandom(20250308);
function makeLabel(text, options = {}) {
const {
width = 512,
height = 128,
background = "rgba(19,43,50,0.86)",
color = "#fff8df",
fontSize = 42,
worldWidth = 13
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
context.fillStyle = background;
context.fillRect(0, 0, width, height);
context.strokeStyle = "rgba(255,255,255,0.18)";
context.lineWidth = 4;
context.strokeRect(2, 2, width - 4, height - 4);
context.fillStyle = color;
context.font = `800 ${fontSize}px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height / 2, width - 32);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(worldWidth, worldWidth * (height / width), 1);
sprite.renderOrder = 20;
return sprite;
}
// ------------------------------------------------------------
// Water, banks, chinampas
// ------------------------------------------------------------
const waterMaterial = new THREE.MeshLambertMaterial({
color: 0x287f8b
});
const water = new THREE.Mesh(
new THREE.BoxGeometry(148, 0.8, 112),
waterMaterial
);
water.position.y = -0.45;
water.receiveShadow = true;
scene.add(water);
// Block-like surface glints.
const glintGeometry = new THREE.BoxGeometry(1.15, 0.025, 0.16);
const glintMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.23
});
const glints = new THREE.InstancedMesh(
glintGeometry,
glintMaterial,
180
);
const dummy = new THREE.Object3D();
for (let i = 0; i < 180; i++) {
dummy.position.set(
-69 + random() * 138,
0.015,
-51 + random() * 102
);
dummy.rotation.y = random() > 0.5 ? 0 : Math.PI / 2;
dummy.scale.set(0.55 + random() * 1.6, 1, 1);
dummy.updateMatrix();
glints.setMatrixAt(i, dummy.matrix);
glints.setColorAt(
i,
new THREE.Color().setHSL(0.48 + random() * 0.05, 0.45, 0.45 + random() * 0.25)
);
}
scene.add(glints);
// Land around the modeled water area.
box(14, 2.5, 112, 0x5f6d45, -67, 0.55, 0);
box(14, 2.5, 112, 0x5f6d45, 67, 0.55, 0);
box(120, 2.5, 14, 0x617349, 0, 0.55, -49);
box(120, 2.5, 14, 0x617349, 0, 0.55, 49);
const cropPositions = [];
function createChinampa(x, z, index) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const width = 10.2;
const depth = 8.1;
box(width, 0.9, depth, 0x68472f, 0, 0.42, 0, group);
box(width + 0.25, 0.18, depth + 0.25, 0x568a48, 0, 0.95, 0, group);
box(width + 0.5, 0.25, 0.45, 0x80603d, 0, 0.8, depth / 2 + 0.12, group);
box(width + 0.5, 0.25, 0.45, 0x80603d, 0, 0.8, -depth / 2 - 0.12, group);
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 6; column++) {
cropPositions.push({
x: x - width / 2 + 1.15 + column * 1.55,
z: z - 2.45 + row * 2.45,
variation: random()
});
}
}
if (index % 3 === 0) {
const sign = makeLabel(`CHINAMPA ${String(index + 1).padStart(2, "0")}`, {
worldWidth: 8.5,
fontSize: 34,
background: "rgba(29,77,59,0.86)"
});
sign.position.set(x, 3.8, z);
scene.add(sign);
}
}
const plotX = [-48, -27, -6, 15, 36];
const plotZ = [-28, -5, 18];
let plotIndex = 0;
plotX.forEach((x) => {
plotZ.forEach((z) => {
createChinampa(x, z, plotIndex++);
});
});
const cropGeometry = new THREE.BoxGeometry(0.62, 0.48, 0.62);
const cropMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
const crops = new THREE.InstancedMesh(
cropGeometry,
cropMaterial,
cropPositions.length
);
cropPositions.forEach((crop, index) => {
dummy.position.set(crop.x, 1.24, crop.z);
dummy.rotation.set(0, Math.floor(crop.variation * 4) * Math.PI / 2, 0);
dummy.scale.set(
0.8 + crop.variation * 0.25,
0.75 + crop.variation * 0.5,
0.8 + crop.variation * 0.25
);
dummy.updateMatrix();
crops.setMatrixAt(index, dummy.matrix);
crops.setColorAt(
index,
new THREE.Color().setHSL(
0.24 + crop.variation * 0.06,
0.45 + crop.variation * 0.18,
0.36 + crop.variation * 0.18
)
);
});
crops.castShadow = true;
crops.receiveShadow = true;
scene.add(crops);
// A quiet canal-edge village.
const buildingColors = [0xc86f53, 0xe3b75e, 0x6d9a84, 0x9a6958, 0xd7c49b];
for (let i = 0; i < 13; i++) {
const x = -65 + (i % 4) * 3.4;
const z = -38 + Math.floor(i / 4) * 14 + (i % 2) * 1.4;
const width = 3 + random() * 1.3;
const depth = 3 + random() * 1.2;
const height = 3 + random() * 3.5;
box(width, height, depth, buildingColors[i % buildingColors.length], x, 2 + height / 2, z);
box(width + 0.3, 0.38, depth + 0.3, 0x4f3e35, x, 2 + height + 0.2, z);
box(0.65, 1.0, 0.08, 0x284c58, x, 2.5, z + depth / 2 + 0.05);
}
// Voxel trees.
function createTree(x, z, size = 1) {
box(0.7 * size, 3 * size, 0.7 * size, 0x6f5035, x, 2.2 * size, z);
box(2.8 * size, 2.1 * size, 2.8 * size, 0x3f784b, x, 4.2 * size, z);
box(2.0 * size, 1.5 * size, 2.0 * size, 0x5c914d, x + 0.65 * size, 4.8 * size, z - 0.2);
}
[
[-60, -42], [-53, -42], [-45, -44], [-39, -42], [48, -43],
[58, -42], [63, -30], [63, 18], [62, 36], [-61, 30],
[-61, 42], [-47, 42], [39, 43], [50, 43]
].forEach(([x, z], index) => createTree(x, z, 0.85 + (index % 3) * 0.12));
// ------------------------------------------------------------
// Landing docks
// ------------------------------------------------------------
function createLanding(position, name, conflictPhase, routeIds) {
const group = new THREE.Group();
group.position.set(position[0], 0, position[1]);
scene.add(group);
box(6.5, 0.38, 4.2, 0x75523a, 0, 0.8, 0, group);
box(6.8, 0.12, 0.35, 0x9b744e, 0, 1.03, -1.8, group);
box(6.8, 0.12, 0.35, 0x9b744e, 0, 1.03, 1.8, group);
for (const x of [-2.5, 2.5]) {
for (const z of [-1.6, 1.6]) {
box(0.38, 2.1, 0.38, 0x563d2d, x, 1.55, z, group);
}
}
box(3.3, 2.2, 3.0, 0xd28b56, 0, 2.2, -2.9, group);
box(3.8, 0.35, 3.5, 0x704331, 0, 3.45, -2.9, group);
const label = makeLabel(name.toUpperCase(), {
worldWidth: 11,
fontSize: 31,
background: "rgba(80,54,39,0.9)",
color: "#fff1c9"
});
label.position.set(0, 6.2, -2.8);
group.add(label);
const conflict = {
group,
name,
phase: conflictPhase,
routeIds,
lastSeen: -999,
active: false
};
const conflictGroup = new THREE.Group();
conflictGroup.visible = false;
group.add(conflictGroup);
const conflictMaterial = new THREE.MeshBasicMaterial({
color: 0xee684d,
transparent: true,
opacity: 0.8,
depthWrite: false
});
conflict.material = conflictMaterial;
const size = 11;
box(size, 0.12, 0.45, conflictMaterial, 0, 0.55, -size / 2, conflictGroup);
box(size, 0.12, 0.45, conflictMaterial, 0, 0.55, size / 2, conflictGroup);
box(0.45, 0.12, size, conflictMaterial, -size / 2, 0.55, 0, conflictGroup);
box(0.45, 0.12, size, conflictMaterial, size / 2, 0.55, 0, conflictGroup);
const beaconMaterial = new THREE.MeshBasicMaterial({
color: 0xff8065,
transparent: true,
opacity: 0.8
});
conflict.beaconMaterial = beaconMaterial;
for (let i = 0; i < 3; i++) {
const beacon = box(
1.25,
1.25,
1.25,
beaconMaterial,
(i - 1) * 2.2,
2.2 + i * 0.65,
-1.5,
conflictGroup
);
beacon.rotation.y = Math.PI / 4;
}
const warning = makeLabel("LANDING CONFLICT", {
worldWidth: 11,
fontSize: 31,
background: "rgba(190,55,35,0.94)",
color: "#fff4df"
});
warning.position.set(0, 8.5, 0);
conflictGroup.add(warning);
conflict.visual = conflictGroup;
return conflict;
}
const landings = [
createLanding([-17, 6], "Marigold Landing", 4 / 12, routes.map((r) => r.id)),
createLanding([25, 31], "Reed Landing", 8 / 12, ["calabaza", "caballito"])
];
// ------------------------------------------------------------
// Routes and boats
// ------------------------------------------------------------
function createBoat(route, selected = false) {
const group = new THREE.Group();
const hullMaterial = new THREE.MeshLambertMaterial({
color: selected ? 0xf8f0cf : route.color
});
const darkMaterial = new THREE.MeshLambertMaterial({ color: 0x244b55 });
const roofMaterial = new THREE.MeshLambertMaterial({ color: route.color });
box(3.3, 0.65, 1.45, hullMaterial, 0, 0.35, 0, group);
box(1.0, 0.55, 1.05, darkMaterial, 0.8, 0.92, 0, group);
box(1.25, 0.18, 1.3, roofMaterial, 0.8, 1.3, 0, group);
box(0.9, 0.25, 1.3, hullMaterial, -1.95, 0.43, 0, group);
const wakeMaterial = new THREE.MeshBasicMaterial({
color: 0xc8ece4,
transparent: true,
opacity: 0.28,
depthWrite: false
});
box(1.4, 0.03, 0.18, wakeMaterial, -2.6, 0.02, 0, group);
box(1.9, 0.03, 0.12, wakeMaterial, -3.5, 0.02, 0, group);
scene.add(group);
return group;
}
routes.forEach((route) => {
const group = new THREE.Group();
scene.add(group);
route.pathMaterial = new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.95,
depthWrite: false
});
route.segments = [];
for (let i = 0; i < route.points.length - 1; i++) {
const a = route.points[i];
const b = route.points[i + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const segment = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.09, 0.25),
route.pathMaterial
);
segment.position.set((a[0] + b[0]) / 2, 0.38, (a[1] + b[1]) / 2);
segment.rotation.y = -Math.atan2(dz, dx);
segment.renderOrder = 4;
group.add(segment);
route.segments.push(segment);
}
const start = route.points[0];
const end = route.points[route.points.length - 1];
box(1.1, 1.1, 1.1, route.pathMaterial, start[0], 0.7, start[1], group);
box(1.1, 1.1, 1.1, route.pathMaterial, end[0], 0.7, end[1], group);
route.label = makeLabel(route.name.toUpperCase(), {
worldWidth: 13,
fontSize: 29,
background: "rgba(19,43,50,0.78)",
color: route.css
});
const labelPoint = route.points[10];
route.label.position.set(labelPoint[0], 5.2, labelPoint[1]);
group.add(route.label);
route.boat = createBoat(route);
});
function sampleRoute(route, progress) {
const segmentCount = route.points.length - 1;
const scaled = ((progress % 1) + 1) % 1 * segmentCount;
const index = Math.min(Math.floor(scaled), segmentCount - 1);
const local = scaled - index;
const a = route.points[index];
const b = route.points[index + 1];
return {
x: THREE.MathUtils.lerp(a[0], b[0], local),
z: THREE.MathUtils.lerp(a[1], b[1], local),
dx: b[0] - a[0],
dz: b[1] - a[1]
};
}
// ------------------------------------------------------------
// Direct camera controls — no external controls module
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0, 1),
radius: 116,
theta: 0.72,
phi: 0.73
};
const pointer = {
active: false,
id: null,
button: 0,
x: 0,
y: 0
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * s * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * s * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.button = event.button;
pointer.x = event.clientX;
pointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.button === 2 || event.shiftKey) {
const panScale = cameraState.radius / renderer.domElement.clientHeight;
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)
);
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(forward, -dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -75, 75);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -60, 60);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.2,
1.35
);
}
});
function endPointer(event) {
if (event.pointerId === pointer.id) {
pointer.active = false;
pointer.id = null;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
42,
175
);
},
{ passive: false }
);
document.querySelector("#isoButton").addEventListener("click", () => {
cameraState.theta = 0.72;
cameraState.phi = 0.73;
cameraState.radius = 116;
cameraState.target.set(0, 0, 1);
});
document.querySelector("#topButton").addEventListener("click", () => {
cameraState.theta = 0;
cameraState.phi = 0.12;
cameraState.radius = 125;
cameraState.target.set(0, 0, 1);
});
document.querySelector("#resetButton").addEventListener("click", () => {
cameraState.theta = 0.72;
cameraState.phi = 0.73;
cameraState.radius = 116;
cameraState.target.set(0, 0, 1);
simulationTime = 0;
simulationPlaying = true;
playButton.textContent = "Pause";
livePill.textContent = "Running";
});
document.querySelector("#zoomIn").addEventListener("click", () => {
cameraState.radius = Math.max(42, cameraState.radius * 0.88);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
cameraState.radius = Math.min(175, cameraState.radius * 1.12);
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") selectRoute(routes[0].id);
if (event.key === "2") selectRoute(routes[1].id);
if (event.key === "3") selectRoute(routes[2].id);
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Simulation and conflict detection
// ------------------------------------------------------------
function phaseDistance(a, b) {
const d = Math.abs(a - b);
return Math.min(d, 1 - d);
}
function formatClock(seconds) {
const minutes = Math.floor(seconds / 60);
const remainder = Math.floor(seconds % 60);
return `${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
}
let lastUiUpdate = 0;
function updateSimulation(delta) {
if (simulationPlaying) {
simulationTime += delta;
}
const speed = Number(speedInput.value);
const progress = (simulationTime * speed / 72) % 1;
routes.forEach((route) => {
const sample = sampleRoute(route, progress);
route.boat.position.set(sample.x, 0.25, sample.z);
route.boat.rotation.y = -Math.atan2(sample.dz, sample.dx);
});
let activeCount = 0;
let mostRecentConflict = null;
let mostRecentTime = -Infinity;
landings.forEach((landing) => {
const nearPhase = phaseDistance(progress, landing.phase) < 0.035;
if (nearPhase && simulationPlaying) {
landing.lastSeen = simulationTime;
}
landing.active = simulationTime - landing.lastSeen < 1.8;
if (landing.active) {
activeCount++;
if (landing.lastSeen > mostRecentTime) {
mostRecentTime = landing.lastSeen;
mostRecentConflict = landing;
}
}
landing.visual.visible = landing.active;
if (landing.active) {
const pulse = 1 + Math.sin(simulationTime * 7) * 0.09;
landing.visual.scale.set(pulse, 1, pulse);
landing.material.opacity = 0.62 + Math.sin(simulationTime * 6) * 0.18;
landing.beaconMaterial.opacity = 0.68 + Math.sin(simulationTime * 8) * 0.2;
}
});
if (performance.now() - lastUiUpdate > 120) {
lastUiUpdate = performance.now();
conflictCount.textContent = String(activeCount);
clockLabel.textContent = formatClock(simulationTime);
if (activeCount > 0) {
eventLine.classList.add("alert");
const count = mostRecentConflict.routeIds.length;
eventText.textContent =
`${mostRecentConflict.name} · ${count} vessels sharing the corridor`;
} else {
eventLine.classList.remove("alert");
eventText.textContent = "Landing corridors currently clear";
}
}
}
// Initial UI state.
speedInput.dispatchEvent(new Event("input"));
beamSelect.dispatchEvent(new Event("change"));
updateRouteSelection();
updateConstraintStatus();
updateCamera();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
updateSimulation(delta);
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```