Prompt specification
Build or customize the Three.js 3D scene "Public water-point placement game" 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: Public water-point placement game
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/public-water-point-placement-game-x0428
Scene Description Prompt:
Public water-point placement game. Create a small recreation map with busy paths and limited fountains; users place water points and compare route distances while maintaining clear approach areas at every station. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (public-water-point-placement-game-x0428):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pocket Park Water Point Planner</title>
<style>
:root {
--ink: #173a3b;
--muted: #617574;
--panel: rgba(251, 250, 244, 0.94);
--line: rgba(23, 58, 59, 0.12);
--teal: #167b78;
--teal-light: #d9eee8;
--orange: #db7049;
--purple: #7667a8;
--green: #2d8a56;
--shadow: 0 18px 45px rgba(34, 67, 61, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 16px;
left: 18px;
right: 18px;
height: 66px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 10px 12px 10px 18px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 18px;
background: rgba(252, 251, 246, 0.93);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.brand {
display: flex;
align-items: center;
min-width: 0;
gap: 12px;
}
.brand-mark {
width: 40px;
height: 40px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 13px;
color: white;
background: var(--teal);
box-shadow: 0 8px 18px rgba(22, 123, 120, 0.24);
}
.brand-mark svg {
width: 23px;
height: 23px;
}
.brand-copy {
min-width: 0;
}
.brand-copy h1 {
margin: 0;
font-size: 17px;
line-height: 1.2;
letter-spacing: -0.02em;
white-space: nowrap;
}
.brand-copy p {
margin: 3px 0 0;
color: var(--muted);
font-size: 12px;
white-space: nowrap;
}
.top-actions {
display: flex;
align-items: center;
gap: 8px;
}
.status-pill {
display: flex;
align-items: center;
gap: 8px;
min-height: 38px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.66);
font-size: 12px;
font-weight: 700;
white-space: nowrap;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #e49b41;
box-shadow: 0 0 0 4px rgba(228, 155, 65, 0.13);
}
.status-dot.complete {
background: var(--green);
box-shadow: 0 0 0 4px rgba(45, 138, 86, 0.13);
}
.icon-button,
.button {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.76);
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
.icon-button:hover,
.button:hover {
transform: translateY(-1px);
background: white;
border-color: rgba(23, 58, 59, 0.24);
}
.icon-button {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 11px;
}
.icon-button svg {
width: 17px;
height: 17px;
}
.panel {
position: fixed;
z-index: 9;
top: 96px;
left: 18px;
bottom: 16px;
width: 326px;
padding: 16px;
overflow: auto;
overscroll-behavior: contain;
border: 1px solid rgba(255, 255, 255, 0.86);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
scrollbar-width: thin;
scrollbar-color: rgba(23, 58, 59, 0.2) transparent;
}
.section + .section {
margin-top: 17px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 10px;
}
.section-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.section-heading span,
.microcopy {
color: var(--muted);
font-size: 11px;
}
.inventory-card {
display: flex;
align-items: center;
justify-content: space-between;
padding: 13px;
border: 1px solid rgba(22, 123, 120, 0.12);
border-radius: 14px;
background: var(--teal-light);
}
.inventory-card strong {
display: block;
margin-bottom: 3px;
font-size: 13px;
}
.inventory-card small {
color: var(--muted);
font-size: 11px;
}
.fountain-pips {
display: flex;
gap: 5px;
}
.fountain-pip {
width: 17px;
height: 23px;
position: relative;
border: 2px solid var(--teal);
border-radius: 4px 4px 7px 7px;
background: white;
transition: 180ms ease;
}
.fountain-pip::before {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 7px;
height: 4px;
border-radius: 50%;
background: #75c9d1;
}
.fountain-pip.used {
opacity: 0.25;
background: var(--teal);
transform: translateY(2px);
}
.zone-list {
display: grid;
gap: 7px;
}
.zone-row {
width: 100%;
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.65);
text-align: left;
cursor: default;
}
.zone-row.served {
cursor: pointer;
}
.zone-color {
width: 9px;
height: 28px;
border-radius: 5px;
}
.zone-name {
display: block;
margin-bottom: 2px;
font-size: 12px;
font-weight: 750;
}
.zone-detail {
display: block;
color: var(--muted);
font-size: 10px;
}
.zone-badge {
padding: 4px 7px;
border-radius: 999px;
color: var(--muted);
background: rgba(23, 58, 59, 0.06);
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.zone-row.served .zone-badge {
color: var(--green);
background: rgba(45, 138, 86, 0.11);
}
.route-header,
.route-row {
display: grid;
grid-template-columns: minmax(0, 1fr) 76px 76px;
gap: 7px;
align-items: center;
}
.route-header {
margin-bottom: 7px;
padding: 0 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
text-align: center;
text-transform: uppercase;
}
.route-header span:first-child {
text-align: left;
}
.route-list {
display: grid;
gap: 8px;
}
.route-row {
padding: 10px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.66);
}
.route-row.selected {
border-color: rgba(22, 123, 120, 0.45);
box-shadow: 0 5px 15px rgba(22, 123, 120, 0.08);
}
.route-station {
min-width: 0;
}
.route-station strong {
display: block;
overflow: hidden;
margin-bottom: 3px;
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
.route-station small {
display: block;
color: var(--green);
font-size: 9px;
}
.route-cell {
min-height: 39px;
padding: 5px;
border: 1px solid rgba(23, 58, 59, 0.08);
border-radius: 9px;
background: rgba(23, 58, 59, 0.04);
cursor: pointer;
}
.route-cell:hover,
.route-cell.active {
color: white;
background: var(--teal);
border-color: var(--teal);
}
.route-cell b,
.route-cell small {
display: block;
}
.route-cell b {
font-size: 11px;
}
.route-cell small {
margin-top: 2px;
opacity: 0.68;
font-size: 8px;
}
.empty-routes {
padding: 18px 12px;
border: 1px dashed rgba(23, 58, 59, 0.18);
border-radius: 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
text-align: center;
}
.totals {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.total-card {
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.64);
text-align: center;
}
.total-card.best {
border-color: rgba(45, 138, 86, 0.3);
background: rgba(45, 138, 86, 0.08);
}
.total-card span,
.total-card strong {
display: block;
}
.total-card span {
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.04em;
}
.total-card strong {
font-size: 15px;
}
.total-card small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
color: var(--muted);
font-size: 11px;
}
.toggle-row input {
accent-color: var(--teal);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.button {
min-height: 39px;
padding: 9px 11px;
border-radius: 11px;
font-size: 11px;
font-weight: 750;
}
.button.primary {
color: white;
border-color: var(--teal);
background: var(--teal);
}
.button.primary:hover {
background: #126c69;
}
.button.danger {
color: #a34b3a;
}
.hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
max-width: calc(100vw - 410px);
padding: 10px 14px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 999px;
color: white;
background: rgba(23, 58, 59, 0.86);
box-shadow: 0 9px 25px rgba(23, 58, 59, 0.18);
backdrop-filter: blur(10px);
font-size: 11px;
pointer-events: none;
}
.hint-icon {
width: 22px;
height: 22px;
display: grid;
place-items: center;
border-radius: 50%;
color: var(--teal);
background: white;
font-size: 12px;
font-weight: 900;
}
.map-controls {
position: fixed;
z-index: 8;
right: 18px;
bottom: 18px;
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 15px;
background: rgba(252, 251, 246, 0.92);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.map-controls .icon-button {
border-color: transparent;
background: transparent;
}
.control-divider {
width: 1px;
height: 24px;
margin: 0 2px;
background: var(--line);
}
.legend {
position: fixed;
z-index: 7;
top: 98px;
right: 18px;
display: flex;
gap: 12px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-radius: 12px;
color: var(--muted);
background: rgba(252, 251, 246, 0.82);
box-shadow: 0 9px 24px rgba(34, 67, 61, 0.1);
backdrop-filter: blur(10px);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
white-space: nowrap;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 50%;
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
top: 96px;
max-width: min(460px, calc(100vw - 30px));
transform: translate(-50%, -15px);
padding: 11px 16px;
border-radius: 12px;
color: white;
background: rgba(23, 58, 59, 0.94);
box-shadow: var(--shadow);
font-size: 12px;
font-weight: 650;
text-align: center;
opacity: 0;
pointer-events: none;
transition: 180ms ease;
}
#toast.show {
transform: translate(-50%, 0);
opacity: 1;
}
#toast.error {
background: rgba(166, 75, 55, 0.96);
}
#success {
position: fixed;
z-index: 20;
top: 98px;
left: 50%;
width: min(440px, calc(100vw - 390px));
transform: translate(-50%, -16px);
padding: 15px 18px;
border: 1px solid rgba(45, 138, 86, 0.25);
border-radius: 16px;
background: rgba(246, 253, 247, 0.95);
box-shadow: var(--shadow);
opacity: 0;
pointer-events: none;
transition: 220ms ease;
}
#success.show {
transform: translate(-50%, 0);
opacity: 1;
pointer-events: auto;
}
.success-inner {
display: flex;
align-items: center;
gap: 12px;
}
.success-check {
width: 36px;
height: 36px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 50%;
color: white;
background: var(--green);
font-weight: 900;
}
#success h3 {
margin: 0 0 3px;
font-size: 13px;
}
#success p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.modal-backdrop {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(19, 44, 43, 0.45);
backdrop-filter: blur(7px);
}
.modal-backdrop.hidden {
display: none;
}
.modal {
width: min(470px, 100%);
padding: 25px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 22px;
background: #fbfaf4;
box-shadow: 0 28px 80px rgba(16, 42, 40, 0.3);
}
.modal h2 {
margin: 0 0 8px;
font-size: 22px;
letter-spacing: -0.03em;
}
.modal > p {
margin: 0 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.help-list {
display: grid;
gap: 10px;
margin-bottom: 20px;
}
.help-item {
display: grid;
grid-template-columns: 28px 1fr;
gap: 10px;
align-items: start;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: white;
}
.help-number {
width: 27px;
height: 27px;
display: grid;
place-items: center;
border-radius: 9px;
color: white;
background: var(--teal);
font-size: 11px;
font-weight: 850;
}
.help-item strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
}
.help-item span {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.modal .button {
width: 100%;
}
@media (max-width: 900px) {
.brand-copy p,
.status-pill,
.legend {
display: none;
}
.panel {
width: 294px;
}
.hint {
max-width: calc(100vw - 350px);
}
#success {
width: min(410px, calc(100vw - 340px));
}
}
@media (max-width: 680px) {
.topbar {
top: 9px;
left: 9px;
right: 9px;
height: 58px;
padding-left: 10px;
}
.brand-copy h1 {
max-width: 170px;
overflow: hidden;
font-size: 14px;
text-overflow: ellipsis;
}
.top-actions {
gap: 4px;
}
.panel {
top: auto;
left: 9px;
right: 9px;
bottom: 9px;
width: auto;
max-height: 43vh;
padding: 13px;
border-radius: 17px;
}
.hint {
display: none;
}
.map-controls {
top: 77px;
right: 9px;
bottom: auto;
}
#success {
top: 77px;
left: 9px;
width: calc(100vw - 95px);
transform: translateY(-12px);
}
#success.show {
transform: translateY(0);
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M12 2.5S5.5 9.4 5.5 14.2a6.5 6.5 0 0 0 13 0C18.5 9.4 12 2.5 12 2.5Z"
fill="currentColor"/>
<path d="M9 15.1c.3 1.5 1.4 2.4 3 2.7"
stroke="#167b78" stroke-width="1.8" stroke-linecap="round"/>
</svg>
</div>
<div class="brand-copy">
<h1>Pocket Park Water Planner</h1>
<p>Place accessible fountains and compare visitor routes</p>
</div>
</div>
<div class="top-actions">
<div class="status-pill">
<span id="statusDot" class="status-dot"></span>
<span id="placedStat">0 / 3 fountains placed</span>
</div>
<button id="helpButton" class="icon-button" title="How to play" aria-label="How to play">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="9"/>
<path d="M9.8 9a2.4 2.4 0 1 1 3.4 2.2c-.8.4-1.2.9-1.2 1.8"/>
<path d="M12 17h.01" stroke-linecap="round"/>
</svg>
</button>
<button id="resetButton" class="icon-button" title="Reset plan" aria-label="Reset plan">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M4 4v6h6"/>
<path d="M5.4 15a8 8 0 1 0 .3-7.2L4 10"/>
</svg>
</button>
</div>
</header>
<aside class="panel" aria-label="Water point planning controls">
<section class="section">
<div class="section-heading">
<h2>Water point kit</h2>
<span>Public supply</span>
</div>
<div class="inventory-card">
<div>
<strong>Limited fountain inventory</strong>
<small>One station per activity zone</small>
</div>
<div id="fountainPips" class="fountain-pips"></div>
</div>
</section>
<section class="section">
<div class="section-heading">
<h2>Activity zones</h2>
<span id="zoneProgress">0 / 3 served</span>
</div>
<div id="zoneList" class="zone-list"></div>
</section>
<section class="section">
<div class="section-heading">
<h2>Route comparison</h2>
<span>Walk distance</span>
</div>
<div class="route-header">
<span>Station</span>
<span>West gate</span>
<span>South gate</span>
</div>
<div id="routeRows" class="route-list"></div>
<div class="totals" style="margin-top: 12px;">
<div id="westTotal" class="total-card">
<span>West total</span>
<strong>—</strong>
<small>all stations</small>
</div>
<div id="southTotal" class="total-card">
<span>South total</span>
<strong>—</strong>
<small>all stations</small>
</div>
<div id="bestTotal" class="total-card best">
<span>Best mixed</span>
<strong>—</strong>
<small>shortest per stop</small>
</div>
</div>
<label class="toggle-row">
<span>Show 1.5 m approach zones</span>
<input id="approachToggle" type="checkbox" checked />
</label>
<div class="button-row">
<button id="removeButton" class="button danger" disabled>Remove selected</button>
<button id="suggestButton" class="button">Suggest shortest</button>
</div>
</section>
<section class="section">
<div class="section-heading">
<h2>Planner notes</h2>
</div>
<div class="microcopy" style="line-height: 1.55;">
Approach circles must remain free of trees, buildings, furniture, and other stations.
Adjacent paths provide the station’s access connection.
</div>
</section>
</aside>
<div class="hint">
<span class="hint-icon">i</span>
<span>Click a glowing build pad · drag to orbit · scroll to zoom</span>
</div>
<div class="legend" aria-label="Map legend">
<span class="legend-item"><span class="legend-swatch" style="background:#2d8a56"></span>Clear approach</span>
<span class="legend-item"><span class="legend-swatch" style="background:#167b78"></span>West route</span>
<span class="legend-item"><span class="legend-swatch" style="background:#db7049"></span>South route</span>
</div>
<nav class="map-controls" aria-label="Map camera controls">
<button id="rotateLeft" class="icon-button" title="Rotate left" aria-label="Rotate left">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 7 4 12l5 5"/>
<path d="M5 12h8a6 6 0 0 1 6 6"/>
</svg>
</button>
<button id="zoomOut" class="icon-button" title="Zoom out" aria-label="Zoom out">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M5 12h14"/>
</svg>
</button>
<button id="zoomIn" class="icon-button" title="Zoom in" aria-label="Zoom in">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 5v14M5 12h14"/>
</svg>
</button>
<span class="control-divider"></span>
<button id="resetView" class="icon-button" title="Reset camera" aria-label="Reset camera">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M4 9V4h5M20 15v5h-5"/>
<path d="M5.2 17.8A8 8 0 0 0 19 7M18.8 6.2A8 8 0 0 0 5 17"/>
</svg>
</button>
</nav>
<div id="toast" role="status" aria-live="polite"></div>
<div id="success" role="status">
<div class="success-inner">
<div class="success-check">✓</div>
<div>
<h3>Plan complete</h3>
<p id="successText"></p>
</div>
</div>
</div>
<div id="helpModal" class="modal-backdrop hidden">
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="helpTitle">
<h2 id="helpTitle">Plan the park’s water access</h2>
<p>
You have three public fountains for three busy activity zones.
Choose the best connected pads while keeping every approach usable.
</p>
<div class="help-list">
<div class="help-item">
<span class="help-number">1</span>
<div>
<strong>Place one station per zone</strong>
<span>Click a glowing pad. Meadow, Play Lawn, and Ridge Trail each need one fountain.</span>
</div>
</div>
<div class="help-item">
<span class="help-number">2</span>
<div>
<strong>Compare the two entrances</strong>
<span>Route buttons compare walking distance from West Gate and South Gate. Click one to trace it.</span>
</div>
</div>
<div class="help-item">
<span class="help-number">3</span>
<div>
<strong>Protect the approach area</strong>
<span>Each station needs a clear 1.5 m circle with an open connection to a path.</span>
</div>
</div>
<div class="help-item">
<span class="help-number">4</span>
<div>
<strong>Explore the map</strong>
<span>Drag to orbit, scroll or use the buttons to zoom, and use Reset view to return home.</span>
</div>
</div>
</div>
<button id="closeHelp" class="button primary">Start planning</button>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9df);
scene.fog = new THREE.Fog(0xdce9df, 65, 115);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive recreation park map");
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-25, 25, 20, -20, 0.1, 180);
const cameraTarget = new THREE.Vector3(0, 0, 0);
let cameraYaw = 0.66;
let cameraPitch = 0.82;
const cameraRadius = 56;
const ambientLight = new THREE.HemisphereLight(0xf7fff5, 0x66826c, 2.15);
scene.add(ambientLight);
const sun = new THREE.DirectionalLight(0xfff4d8, 2.55);
sun.position.set(-18, 34, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00035;
scene.add(sun);
const palette = {
grass: 0x91b987,
grassDark: 0x79a874,
path: 0xe6cfa8,
pathEdge: 0xd3b98e,
soil: 0xa98262,
water: 0x69b8c4,
waterDark: 0x438e9d,
trunk: 0x80563d,
leaf: 0x4e8c5d,
leafLight: 0x70a965,
teal: 0x167b78,
orange: 0xdb7049,
purple: 0x7667a8,
green: 0x2d8a56,
cream: 0xf4edda
};
const obstacles = [];
const pickables = [];
const padMeshes = new Map();
const approachVisuals = [];
const walkers = [];
const placedStations = [];
let selectedStationId = null;
let selectedRoute = null;
let routeGroup = null;
let toastTimer = null;
let hoveredPad = null;
const APPROACH_RADIUS = 1.5;
const INVENTORY = 3;
const zones = [
{
id: "meadow",
name: "Meadow Rest",
short: "Meadow",
color: palette.teal,
pads: [
{ id: "A", x: -7, z: -2.8, segment: "main" },
{ id: "B", x: 8, z: 2.8, segment: "main" }
]
},
{
id: "play",
name: "Play Lawn",
short: "Play",
color: palette.orange,
pads: [
{ id: "C", x: -2.8, z: 8, segment: "bottom" },
{ id: "E", x: -12, z: 8, segment: "bottom" }
]
},
{
id: "ridge",
name: "Ridge Trail",
short: "Ridge",
color: palette.purple,
pads: [
{ id: "D", x: 12, z: -8, segment: "top" },
{ id: "F", x: 2, z: -8, segment: "top" }
]
}
];
const allPads = zones.flatMap(zone =>
zone.pads.map(pad => ({ ...pad, zoneId: zone.id }))
);
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
function addMesh(parent, geometry, material, x = 0, y = 0, z = 0, cast = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, width, height, depth, color, x = 0, y = 0, z = 0) {
return addMesh(
parent,
new THREE.BoxGeometry(width, height, depth),
makeMaterial(color),
x,
y,
z
);
}
function makeLabel(text, options = {}) {
const {
color = "#173a3b",
background = "rgba(252,251,246,0.93)",
border = "rgba(23,58,59,0.12)",
scale = 3.7,
height = 0.9
} = options;
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = background;
ctx.strokeStyle = border;
ctx.lineWidth = 4;
const x = 8;
const y = 8;
const w = 496;
const h = 112;
const r = 26;
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "700 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 64);
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(scale, height, 1);
sprite.renderOrder = 20;
return sprite;
}
// Park base and lawn.
addBox(scene, 49, 0.9, 37, 0x6f9270, 0, -0.54, 0);
addBox(scene, 48, 0.24, 36, palette.grass, 0, -0.12, 0);
// Low-poly grass color patches.
const patchMaterialA = makeMaterial(0x9fc28d, { transparent: true, opacity: 0.62 });
const patchMaterialB = makeMaterial(0x83ad7b, { transparent: true, opacity: 0.5 });
[
[-18, -12, 4.5, 3.2],
[17, 11, 5.2, 3.8],
[-16, 13, 4.3, 2.4],
[8, 13, 4.8, 2.8],
[16, -13, 4.7, 2.6]
].forEach(([x, z, sx, sz], index) => {
const patch = addMesh(
scene,
new THREE.CircleGeometry(1, 11),
index % 2 ? patchMaterialA : patchMaterialB,
x,
0.015,
z,
false
);
patch.rotation.x = -Math.PI / 2;
patch.rotation.z = index * 0.73;
patch.scale.set(sx, sz, 1);
});
const segments = [
{ id: "main", a: [-22, 0], b: [22, 0], width: 3.2 },
{ id: "center", a: [0, -15], b: [0, 17], width: 3.0 },
{ id: "top", a: [-15, -10], b: [15, -10], width: 2.4 },
{ id: "bottom", a: [-15, 10], b: [15, 10], width: 2.4 },
{ id: "west", a: [-15, -10], b: [-15, 10], width: 2.2 },
{ id: "east", a: [15, -10], b: [15, 10], width: 2.2 }
];
function addPathSegment(segment) {
const dx = segment.b[0] - segment.a[0];
const dz = segment.b[1] - segment.a[1];
const length = Math.hypot(dx, dz);
const horizontal = Math.abs(dx) > Math.abs(dz);
const path = addBox(
scene,
horizontal ? length + segment.width : segment.width,
0.09,
horizontal ? segment.width : length + segment.width,
palette.path,
(segment.a[0] + segment.b[0]) / 2,
0.065,
(segment.a[1] + segment.b[1]) / 2
);
path.receiveShadow = true;
const ends = [segment.a, segment.b];
ends.forEach(([x, z]) => {
const joint = addMesh(
scene,
new THREE.CylinderGeometry(segment.width / 2, segment.width / 2, 0.095, 18),
makeMaterial(palette.path),
x,
0.065,
z,
false
);
joint.receiveShadow = true;
});
}
segments.forEach(addPathSegment);
// Entrance aprons and gates.
function addGate(x, z, rotation, label, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
addBox(group, 0.28, 2.3, 0.28, 0x745a43, -1.25, 1.15, 0);
addBox(group, 0.28, 2.3, 0.28, 0x745a43, 1.25, 1.15, 0);
addBox(group, 2.9, 0.32, 0.38, color, 0, 2.18, 0);
addBox(group, 1.25, 0.12, 0.4, palette.cream, 0, 1.8, 0);
scene.add(group);
const sprite = makeLabel(label, {
color: "#ffffff",
background: color === palette.orange ? "rgba(219,112,73,0.95)" : "rgba(22,123,120,0.95)",
border: "rgba(255,255,255,0.25)",
scale: 4.4
});
sprite.position.set(x, 3.05, z);
scene.add(sprite);
}
addGate(-22, 0, Math.PI / 2, "West Gate", palette.teal);
addGate(0, 17, 0, "South Gate", palette.orange);
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = Math.random() * Math.PI * 2;
const trunk = addMesh(
group,
new THREE.CylinderGeometry(0.16 * scale, 0.23 * scale, 1.25 * scale, 6),
makeMaterial(palette.trunk),
0,
0.62 * scale,
0
);
const lower = addMesh(
group,
new THREE.IcosahedronGeometry(0.95 * scale, 0),
makeMaterial(palette.leaf),
0,
1.65 * scale,
0
);
lower.scale.set(1, 1.14, 1);
const upper = addMesh(
group,
new THREE.IcosahedronGeometry(0.72 * scale, 0),
makeMaterial(palette.leafLight),
0.15 * scale,
2.35 * scale,
-0.05 * scale
);
upper.scale.y = 1.12;
scene.add(group);
obstacles.push({ x, z, r: 0.38 * scale, label: "tree" });
}
[
[-19, -6, 1.05], [-19, 7, 1.15], [-12, -7, 1], [-9, -7, 0.92],
[-6, 13.8, 1.05], [6, 13.8, 1.1], [10, 8, 1.1], [18, 7, 1.12],
[18, -6, 1.1], [11, -13, 1], [4, -14, 0.95], [-3, -14, 1],
[-19, -12, 1], [18, -12, 1], [-17, 3, 0.9], [-8, 4, 0.88],
[14, 13.5, 0.95], [-20, -2, 0.9]
].forEach(([x, z, s]) => createTree(x, z, s));
function createBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
addBox(group, 1.9, 0.15, 0.48, 0x9b6847, 0, 0.48, 0);
addBox(group, 1.9, 0.5, 0.13, 0x9b6847, 0, 0.78, -0.23);
addBox(group, 0.14, 0.45, 0.4, 0x4e5550, -0.65, 0.23, 0);
addBox(group, 0.14, 0.45, 0.4, 0x4e5550, 0.65, 0.23, 0);
scene.add(group);
obstacles.push({ x, z, r: 0.85, label: "bench" });
}
createBench(-9.5, 3.8, 0.2);
createBench(6.2, 4.5, Math.PI);
createBench(12.8, -5.9, Math.PI / 2);
createBench(-2.2, -8.2, 0);
createBench(-13.1, 5.6, Math.PI / 2);
function createPicnicTable(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
addBox(group, 2.4, 0.16, 1.15, 0xc18a59, 0, 0.72, 0);
addBox(group, 2.4, 0.14, 0.4, 0xc18a59, 0, 1.25, -0.68);
addBox(group, 0.18, 0.7, 0.8, 0x6f7168, -0.8, 0.35, 0);
addBox(group, 0.18, 0.7, 0.8, 0x6f7168, 0.8, 0.35, 0);
scene.add(group);
obstacles.push({ x, z, r: 1.05, label: "picnic table" });
}
createPicnicTable(-9.5, 5.7, 0.15);
createPicnicTable(8.6, 5.4, -0.25);
// Small playground with low-poly play equipment.
const playGroup = new THREE.Group();
playGroup.position.set(7.6, 0, 8.5);
addBox(playGroup, 3.8, 0.12, 2.6, 0xe5c889, 0, 0.08, 0);
addBox(playGroup, 0.18, 1.8, 0.18, 0x5f8690, -1.1, 0.95, -0.6);
addBox(playGroup, 0.18, 1.8, 0.18, 0x5f8690, -1.1, 0.95, 0.6);
addBox(playGroup, 2.5, 0.18, 0.18, 0xd56f4c, -1.1, 1.85, -0.6);
addBox(playGroup, 2.5, 0.18, 0.18, 0xd56f4c, -1.1, 1.85, 0.6);
const slide = addBox(playGroup, 0.9, 0.14, 2.4, 0xf0b44d, 0.2, 0.62, 0);
slide.rotation.x = -0.35;
addMesh(playGroup, new THREE.ConeGeometry(0.55, 1.2, 5), makeMaterial(0x7667a8), 0.5, 1.0, 0);
scene.add(playGroup);
obstacles.push({ x: 7.6, z: 8.5, r: 1.75, label: "playground" });
// Pond in the north-east corner.
const pond = new THREE.Group();
pond.position.set(7, 0.025, -5.3);
const shore = addMesh(
pond,
new THREE.CircleGeometry(3.85, 13),
makeMaterial(0xd5c58f),
0,
0,
0,
false
);
shore.rotation.x = -Math.PI / 2;
shore.scale.set(1.18, 0.86, 1);
const water = addMesh(
pond,
new THREE.CircleGeometry(3.28, 13),
makeMaterial(palette.water, { roughness: 0.28, metalness: 0.05 }),
0,
0.035,
0,
false
);
water.rotation.x = -Math.PI / 2;
water.scale.set(1.18, 0.86, 1);
const island = addMesh(
pond,
new THREE.IcosahedronGeometry(0.8, 0),
makeMaterial(0x7da66b),
0.65,
0.22,
0.15
);
island.scale.y = 0.38;
scene.add(pond);
obstacles.push({ x: 7, z: -5.3, r: 3.5, label: "pond" });
// Park buildings.
function createBuilding(x, z, width, depth, height, roofColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
addBox(group, width, height, depth, 0xe8d9bc, 0, height / 2, 0);
const roof = addMesh(
group,
new THREE.ConeGeometry(Math.max(width, depth) * 0.72, height * 0.48, 4),
makeMaterial(roofColor),
0,
height + height * 0.24,
0
);
roof.rotation.y = Math.PI / 4;
roof.scale.z = depth / width;
scene.add(group);
obstacles.push({ x, z, r: Math.max(width, depth) * 0.65, label: "building" });
}
createBuilding(-20.3, 11.6, 3.4, 2.8, 2.0, 0x6c8177);
createBuilding(20.2, 11.5, 3.8, 3.0, 2.1, 0xb56b4f);
// Small rocks.
[
[-19.5, -10.2], [18.6, -8.8], [13.4, 12.8], [-11.5, 14.8]
].forEach(([x, z], index) => {
const rock = addMesh(
scene,
new THREE.IcosahedronGeometry(0.5 + index * 0.06, 0),
makeMaterial(index % 2 ? 0xa5aaa0 : 0x858f86),
x,
0.28,
z
);
rock.scale.set(1.3, 0.7, 0.9);
rock.rotation.y = index;
obstacles.push({ x, z, r: 0.5, label: "rock" });
});
// Build pads and their protected approach circles.
allPads.forEach(pad => {
const zone = zones.find(z => z.id === pad.zoneId);
const group = new THREE.Group();
group.position.set(pad.x, 0, pad.z);
const clearDisc = addMesh(
group,
new THREE.CircleGeometry(APPROACH_RADIUS, 48),
new THREE.MeshBasicMaterial({
color: palette.green,
transparent: true,
opacity: 0.1,
depthWrite: false,
side: THREE.DoubleSide
}),
0,
0.13,
0,
false
);
clearDisc.rotation.x = -Math.PI / 2;
const approachRing = addMesh(
group,
new THREE.RingGeometry(APPROACH_RADIUS - 0.08, APPROACH_RADIUS, 48),
new THREE.MeshBasicMaterial({
color: palette.green,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide,
depthWrite: false
}),
0,
0.145,
0,
false
);
approachRing.rotation.x = -Math.PI / 2;
const disk = addMesh(
group,
new THREE.CircleGeometry(0.67, 24),
makeMaterial(zone.color, {
emissive: zone.color,
emissiveIntensity: 0.13,
transparent: true,
opacity: 0.9
}),
0,
0.16,
0,
false
);
disk.rotation.x = -Math.PI / 2;
disk.userData = { pickType: "pad", padId: pad.id };
pickables.push(disk);
padMeshes.set(pad.id, disk);
const label = makeLabel(`${zone.short} ${pad.id}`, {
color: "#ffffff",
background: `#${new THREE.Color(zone.color).getHexString()}`,
border: "rgba(255,255,255,0.45)",
scale: 3.2,
height: 0.78
});
label.position.set(0, 2.1, 0);
group.add(label);
pad.label = label;
approachVisuals.push({ clearDisc, approachRing, group });
scene.add(group);
});
// Walking network graph.
const graph = {
nodes: [],
adjacency: []
};
function nodeKey(x, z) {
return `${x.toFixed(3)},${z.toFixed(3)}`;
}
function addNode(x, z) {
const key = nodeKey(x, z);
const existing = graph.nodes.findIndex(node => node.key === key);
if (existing !== -1) return existing;
graph.nodes.push({ x, z, key });
graph.adjacency.push([]);
return graph.nodes.length - 1;
}
function addEdge(a, b, segment) {
if (a === b) return;
const length = Math.hypot(
graph.nodes[a].x - graph.nodes[b].x,
graph.nodes[a].z - graph.nodes[b].z
);
graph.adjacency[a].push({ to: b, length, segment });
graph.adjacency[b].push({ to: a, length, segment });
}
function isHorizontal(segment) {
return segment.a[1] === segment.b[1];
}
function pointOnSegment(x, z, segment) {
if (isHorizontal(segment)) {
const minX = Math.min(segment.a[0], segment.b[0]) - 0.0001;
const maxX = Math.max(segment.a[0], segment.b[0]) + 0.0001;
return Math.abs(z - segment.a[1]) < 0.0001 && x >= minX && x <= maxX;
}
const minZ = Math.min(segment.a[1], segment.b[1]) - 0.0001;
const maxZ = Math.max(segment.a[1], segment.b[1]) + 0.0001;
return Math.abs(x - segment.a[0]) < 0.0001 && z >= minZ && z <= maxZ;
}
function segmentIntersection(s1, s2) {
if (isHorizontal(s1) && !isHorizontal(s2)) {
const x = s2.a[0];
const z = s1.a[1];
if (
x >= Math.min(s1.a[0], s1.b[0]) - 0.0001 &&
x <= Math.max(s1.a[0], s1.b[0]) + 0.0001 &&
z >= Math.min(s2.a[1], s2.b[1]) - 0.0001 &&
z <= Math.max(s2.a[1], s2.b[1]) + 0.0001
) return [x, z];
}
if (!isHorizontal(s1) && isHorizontal(s2)) {
const x = s1.a[0];
const z = s2.a[1];
if (
z >= Math.min(s1.a[1], s1.b[1]) - 0.0001 &&
z <= Math.max(s1.a[1], s1.b[1]) + 0.0001 &&
x >= Math.min(s2.a[0], s2.b[0]) - 0.0001 &&
x <= Math.max(s2.a[0], s2.b[0]) + 0.0001
) return [x, z];
}
return null;
}
function projectToSegment(x, z, segment) {
if (isHorizontal(segment)) {
return {
x: Math.max(Math.min(x, segment.b[0]), segment.a[0]),
z: segment.a[1]
};
}
return {
x: segment.a[0],
z: Math.max(Math.min(z, segment.b[1]), segment.a[1])
};
}
segments.forEach(segment => {
addNode(...segment.a);
addNode(...segment.b);
});
for (let i = 0; i < segments.length; i++) {
for (let j = i + 1; j < segments.length; j++) {
const intersection = segmentIntersection(segments[i], segments[j]);
if (intersection) addNode(...intersection);
}
}
const padNodeIds = new Map();
const padConnectorIds = new Map();
allPads.forEach(pad => {
const segment = segments.find(s => s.id === pad.segment);
const projection = projectToSegment(pad.x, pad.z, segment);
const connectorId = addNode(projection.x, projection.z);
const padId = addNode(pad.x, pad.z);
padNodeIds.set(pad.id, padId);
padConnectorIds.set(pad.id, connectorId);
});
segments.forEach(segment => {
const ids = graph.nodes
.map((node, index) => ({ node, index }))
.filter(({ node }) => pointOnSegment(node.x, node.z, segment))
.map(({ index }) => index);
const uniqueIds = [...new Set(ids)];
const horizontal = isHorizontal(segment);
uniqueIds.sort((a, b) => {
const av = horizontal ? graph.nodes[a].x : graph.nodes[a].z;
const bv = horizontal ? graph.nodes[b].x : graph.nodes[b].z;
return av - bv;
});
for (let i = 1; i < uniqueIds.length; i++) {
addEdge(uniqueIds[i - 1], uniqueIds[i], segment.id);
}
});
allPads.forEach(pad => {
addEdge(padConnectorIds.get(pad.id), padNodeIds.get(pad.id), `spur-${pad.id}`);
});
const westGateNode = addNode(-22, 0);
const southGateNode = addNode(0, 17);
function shortestPath(fromNode, toNode) {
const count = graph.nodes.length;
const distances = Array(count).fill(Infinity);
const previous = Array(count).fill(-1);
const previousEdges = Array(count).fill(null);
const visited = Array(count).fill(false);
distances[fromNode] = 0;
for (let iteration = 0; iteration < count; iteration++) {
let current = -1;
let bestDistance = Infinity;
for (let i = 0; i < count; i++) {
if (!visited[i] && distances[i] < bestDistance) {
current = i;
bestDistance = distances[i];
}
}
if (current === -1 || current === toNode) break;
visited[current] = true;
for (const edge of graph.adjacency[current]) {
const nextDistance = distances[current] + edge.length;
if (nextDistance < distances[edge.to]) {
distances[edge.to] = nextDistance;
previous[edge.to] = current;
previousEdges[edge.to] = edge;
}
}
}
if (!Number.isFinite(distances[toNode])) {
return { distance: Infinity, points: [], edges: [] };
}
const points = [];
const edges = [];
let current = toNode;
while (current !== -1) {
points.push({ x: graph.nodes[current].x, z: graph.nodes[current].z });
if (previous[current] !== -1) {
edges.push(previousEdges[current]);
}
current = previous[current];
}
points.reverse();
edges.reverse();
return { distance: distances[toNode], points, edges };
}
const traffic = {
main: 8,
center: 7,
bottom: 5,
top: 4,
west: 3,
east: 3
};
function estimateRouteTime(route) {
const walkingTime = route.distance / 1.25;
const crowding = route.edges.reduce((sum, edge) => {
const base = traffic[edge.segment] || 1;
return sum + (edge.length * base) / 24;
}, 0);
return walkingTime + crowding;
}
function validatePlacement(pad) {
const zoneStation = placedStations.find(station => station.zoneId === pad.zoneId);
if (zoneStation) {
return { valid: false, reason: "This activity zone already has a fountain." };
}
const occupied = placedStations.find(station => station.padId === pad.id);
if (occupied) {
return { valid: false, reason: "That build pad is already occupied." };
}
for (const obstacle of obstacles) {
const distance = Math.hypot(pad.x - obstacle.x, pad.z - obstacle.z);
if (distance < obstacle.r + APPROACH_RADIUS) {
return {
valid: false,
reason: `The approach would be blocked by the nearby ${obstacle.label}.`
};
}
}
for (const station of placedStations) {
const distance = Math.hypot(pad.x - station.x, pad.z - station.z);
if (distance < 3) {
return { valid: false, reason: "Fountains need more space between stations." };
}
}
return { valid: true, reason: "Approach area is clear." };
}
function createFountain(station) {
const group = new THREE.Group();
group.position.set(station.x, 0.1, station.z);
group.userData = { pickType: "station", stationId: station.id };
addMesh(
group,
new THREE.CylinderGeometry(0.43, 0.56, 0.42, 8),
makeMaterial(0xded7c6),
0,
0.21,
0
);
addMesh(
group,
new THREE.CylinderGeometry(0.7, 0.59, 0.25, 12),
makeMaterial(0xe9e1cf),
0,
0.53,
0
);
addMesh(
group,
new THREE.CylinderGeometry(0.57, 0.57, 0.055, 18),
makeMaterial(palette.water, { roughness: 0.25, metalness: 0.05 }),
0,
0.69,
0
);
addBox(group, 0.15, 0.46, 0.15, 0x87938e, 0.48, 0.82, 0);
addBox(group, 0.42, 0.11, 0.13, 0x87938e, 0.32, 1.02, 0);
const marker = addMesh(
group,
new THREE.CylinderGeometry(0.82, 0.82, 0.035, 32),
new THREE.MeshBasicMaterial({
color: palette.green,
transparent: true,
opacity: 0.24,
depthWrite: false
}),
0,
0.02,
0,
false
);
marker.userData.ignoreHighlight = true;
scene.add(group);
group.traverse(object => {
if (object.isMesh) {
object.userData.stationRoot = group;
pickables.push(object);
}
});
return group;
}
function clearRouteGeometry() {
if (!routeGroup) return;
routeGroup.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) object.material.dispose();
});
scene.remove(routeGroup);
routeGroup = null;
}
function drawRoute(station, gate) {
clearRouteGeometry();
if (!station) return;
const fromNode = gate === "west" ? westGateNode : southGateNode;
const toNode = padNodeIds.get(station.padId);
const route = shortestPath(fromNode, toNode);
routeGroup = new THREE.Group();
const color = gate === "west" ? palette.teal : palette.orange;
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthWrite: false
});
for (let i = 1; i < route.points.length; i++) {
const a = route.points[i - 1];
const b = route.points[i];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
if (length < 0.05) continue;
const mesh = addMesh(
routeGroup,
new THREE.CylinderGeometry(0.075, 0.075, length, 7),
material,
(a.x + b.x) / 2,
0.25,
(a.z + b.z) / 2,
false
);
const direction = new THREE.Vector3(dx, 0, dz).normalize();
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction);
mesh.renderOrder = 6;
}
scene.add(routeGroup);
}
function routeForStation(station, gate) {
const fromNode = gate === "west" ? westGateNode : southGateNode;
const toNode = padNodeIds.get(station.padId);
return shortestPath(fromNode, toNode);
}
function getStationRoutes() {
const result = new Map();
placedStations.forEach(station => {
const west = routeForStation(station, "west");
const south = routeForStation(station, "south");
result.set(station.id, {
west,
south,
bestGate: west.distance <= south.distance ? "west" : "south"
});
});
return result;
}
function selectStation(stationId, gate = null) {
const station = placedStations.find(item => item.id === stationId);
if (!station) return;
selectedStationId = stationId;
const routes = getStationRoutes();
const stationRoutes = routes.get(stationId);
selectedRoute = {
stationId,
gate: gate || stationRoutes.bestGate
};
drawRoute(station, selectedRoute.gate);
updateUI();
}
function placeFountain(pad) {
const validation = validatePlacement(pad);
if (!validation.valid) {
showToast(validation.reason, true);
return;
}
if (placedStations.length >= INVENTORY) {
showToast("All three fountains have been placed.", true);
return;
}
const zone = zones.find(item => item.id === pad.zoneId);
const station = {
id: `station-${Date.now()}-${pad.id}`,
padId: pad.id,
zoneId: pad.zoneId,
x: pad.x,
z: pad.z,
group: null
};
station.group = createFountain(station);
placedStations.push(station);
const padMesh = padMeshes.get(pad.id);
padMesh.material.color.set(palette.green);
padMesh.material.emissive.set(palette.green);
padMesh.material.emissiveIntensity = 0.22;
pad.label.visible = false;
const visual = approachVisuals.find(item => item.group.position.x === pad.x && item.group.position.z === pad.z);
if (visual) {
visual.approachRing.material.color.set(palette.green);
visual.approachRing.material.opacity = 0.95;
visual.clearDisc.material.opacity = 0.16;
}
selectStation(station.id);
showToast(`${zone.name} station placed. Approach area is clear.`);
if (placedStations.length === INVENTORY) {
const routes = getStationRoutes();
let combined = 0;
routes.forEach(item => {
combined += Math.min(item.west.distance, item.south.distance);
});
document.getElementById("successText").textContent =
`All three zones are served with clear approaches. Best mixed walking total: ${combined.toFixed(1)} m.`;
document.getElementById("success").classList.add("show");
}
}
function removeSelectedStation() {
if (!selectedStationId) return;
const index = placedStations.findIndex(item => item.id === selectedStationId);
if (index === -1) return;
const station = placedStations[index];
const zone = zones.find(item => item.id === station.zoneId);
const pad = allPads.find(item => item.id === station.padId);
station.group.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) object.material.dispose();
});
scene.remove(station.group);
placedStations.splice(index, 1);
selectedStationId = null;
selectedRoute = null;
clearRouteGeometry();
const padMesh = padMeshes.get(station.padId);
padMesh.material.color.set(zone.color);
padMesh.material.emissive.set(zone.color);
padMesh.material.emissiveIntensity = 0.13;
pad.label.visible = true;
const visual = approachVisuals.find(item => item.group.position.x === station.x && item.group.position.z === station.z);
if (visual) {
visual.approachRing.material.color.set(palette.green);
visual.approachRing.material.opacity = 0.72;
visual.clearDisc.material.opacity = 0.1;
}
document.getElementById("success").classList.remove("show");
showToast(`${zone.name} station removed.`);
updateUI();
}
function resetPlan() {
[...placedStations].forEach(station => {
station.group.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) object.material.dispose();
});
scene.remove(station.group);
const zone = zones.find(item => item.id === station.zoneId);
const padMesh = padMeshes.get(station.padId);
padMesh.material.color.set(zone.color);
padMesh.material.emissive.set(zone.color);
padMesh.material.emissiveIntensity = 0.13;
pad.label.visible = true;
});
placedStations.length = 0;
selectedStationId = null;
selectedRoute = null;
clearRouteGeometry();
document.getElementById("success").classList.remove("show");
showToast("The planning board has been reset.");
updateUI();
}
function updateUI() {
const routes = getStationRoutes();
document.getElementById("fountainPips").innerHTML = Array.from(
{ length: INVENTORY },
(_, index) => `<span class="fountain-pip ${index < placedStations.length ? "used" : ""}"></span>`
).join("");
document.getElementById("placedStat").textContent =
`${placedStations.length} / ${INVENTORY} fountains placed`;
document.getElementById("statusDot").classList.toggle("complete", placedStations.length === INVENTORY);
const zoneRows = zones.map(zone => {
const station = placedStations.find(item => item.zoneId === zone.id);
const detail = station
? `Pad ${station.padId} · approach clear`
: `Choose pad ${zone.pads.map(pad => pad.id).join(" or ")}`;
return `
<div class="zone-row ${station ? "served" : ""}" data-zone="${zone.id}">
<span class="zone-color" style="background:#${new THREE.Color(zone.color).getHexString()}"></span>
<span>
<span class="zone-name">${zone.name}</span>
<span class="zone-detail">${detail}</span>
</span>
<span class="zone-badge">${station ? "Served" : "Open"}</span>
</div>
`;
}).join("");
document.getElementById("zoneList").innerHTML = zoneRows;
document.getElementById("zoneProgress").textContent = `${placedStations.length} / 3 served`;
const routeRows = placedStations.map(station => {
const zone = zones.find(item => item.id === station.zoneId);
const item = routes.get(station.id);
const activeWest = selectedRoute?.stationId === station.id && selectedRoute.gate === "west";
const activeSouth = selectedRoute?.stationId === station.id && selectedRoute.gate === "south";
return `
<div class="route-row ${selectedStationId === station.id ? "selected" : ""}" data-station="${station.id}">
<div class="route-station">
<strong>${zone.name} ${station.padId}</strong>
<small>✓ 1.5 m clear</small>
</div>
<button class="route-cell ${activeWest ? "active" : ""}" data-gate="west" aria-label="Show west gate route">
<b>${item.west.distance.toFixed(1)} m</b>
<small>${Math.round(estimateRouteTime(item.west))} sec</small>
</button>
<button class="route-cell ${activeSouth ? "active" : ""}" data-gate="south" aria-label="Show south gate route">
<b>${item.south.distance.toFixed(1)} m</b>
<small>${Math.round(estimateRouteTime(item.south))} sec</small>
</button>
</div>
`;
}).join("");
document.getElementById("routeRows").innerHTML = routeRows.length
? routeRows
: `<div class="empty-routes">Place a fountain to compare its walking distance from West Gate and South Gate.</div>`;
let westTotal = 0;
let southTotal = 0;
let mixedTotal = 0;
routes.forEach(item => {
westTotal += item.west.distance;
southTotal += item.south.distance;
mixedTotal += Math.min(item.west.distance, item.south.distance);
});
function setTotal(id, value, best = false) {
const element = document.getElementById(id);
element.querySelector("strong").textContent = placedStations.length ? `${value.toFixed(1)} m` : "—";
element.classList.toggle("best", best);
}
const lowerWest = westTotal <= southTotal;
setTotal("westTotal", westTotal, placedStations.length > 0 && lowerWest);
setTotal("southTotal", southTotal, placedStations.length > 0 && !lowerWest);
setTotal("bestTotal", mixedTotal, true);
document.getElementById("removeButton").disabled = !selectedStationId;
}
function showToast(message, error = false) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.toggle("error", error);
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 3100);
}
// Animated visitors make the main circulation paths visibly busy.
function samplePath(points, t) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
lengths.push(length);
total += length;
}
let distance = ((t % 1) + 1) % 1 * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i]) {
const a = points[i];
const b = points[(i + 1) % points.length];
const ratio = lengths[i] === 0 ? 0 : distance / lengths[i];
return {
x: THREE.MathUtils.lerp(a[0], b[0], ratio),
z: THREE.MathUtils.lerp(a[1], b[1], ratio),
angle: Math.atan2(b[0] - a[0], b[1] - a[1])
};
}
distance -= lengths[i];
}
return { x: points[0][0], z: points[0][1], angle: 0 };
}
function createWalker(path, speed, color) {
const group = new THREE.Group();
const body = addMesh(
group,
new THREE.CylinderGeometry(0.11, 0.15, 0.42, 6),
makeMaterial(color),
0,
0.37,
0
);
const head = addMesh(
group,
new THREE.IcosahedronGeometry(0.13, 0),
makeMaterial(0xd6a77c),
0,
0.69,
0
);
addBox(group, 0.07, 0.23, 0.08, 0x44555a, -0.07, 0.13, 0);
addBox(group, 0.07, 0.23, 0.08, 0x44555a, 0.07, 0.13, 0);
scene.add(group);
walkers.push({ group, path, speed, offset: Math.random() });
}
const visitorPaths = [
{ path: [[-22, 0], [22, 0]], count: 10, speed: 0.022 },
{ path: [[0, -15], [0, 17]], count: 7, speed: 0.020 },
{ path: [[-15, -10], [15, -10]], count: 4, speed: 0.018 },
{ path: [[-15, 10], [15, 10]], count: 5, speed: 0.018 },
{ path: [[-15, -10], [-15, 10]], count: 2, speed: 0.016 },
{ path: [[15, -10], [15, 10]], count: 2, speed: 0.016 }
];
const visitorColors = [0xd16f4f, 0x497e8b, 0xe0aa42, 0x6c6ba1, 0x3c8c72, 0xb96169];
visitorPaths.forEach((route, routeIndex) => {
for (let i = 0; i < route.count; i++) {
createWalker(
route.path,
route.speed * (0.85 + Math.random() * 0.3),
visitorColors[(i + routeIndex) % visitorColors.length]
);
}
});
// Camera controls implemented directly without external controls modules.
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(31, 52 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
let startPointerX = 0;
let startPointerY = 0;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickAtPointer() {
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
for (const hit of hits) {
let object = hit.object;
while (object) {
if (object.userData.pickType === "pad") {
return { type: "pad", id: object.userData.padId, object };
}
if (object.userData.pickType === "station") {
return { type: "station", id: object.userData.stationId, object };
}
object = object.parent;
}
}
return null;
}
function setHoveredPad(padId) {
if (hoveredPad === padId) return;
if (hoveredPad) {
const previous = padMeshes.get(hoveredPad);
previous.scale.setScalar(1);
}
hoveredPad = padId;
renderer.domElement.style.cursor = padId ? "pointer" : "grab";
if (hoveredPad) {
const current = padMeshes.get(hoveredPad);
current.scale.setScalar(1.16);
}
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
pointerDown = true;
pointerMoved = false;
lastPointerX = startPointerX = event.clientX;
lastPointerY = startPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
updatePointer(event);
if (pointerDown) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.hypot(event.clientX - startPointerX, event.clientY - startPointerY) > 5) {
pointerMoved = true;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.0045, 0.34, 1.22);
updateCamera();
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else {
const hit = pickAtPointer();
setHoveredPad(hit?.type === "pad" ? hit.id : null);
}
});
renderer.domElement.addEventListener("pointerup", event => {
updatePointer(event);
pointerDown = false;
renderer.domElement.style.cursor = hoveredPad ? "pointer" : "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (pointerMoved) return;
const hit = pickAtPointer();
if (!hit) return;
if (hit.type === "pad") {
const pad = allPads.find(item => item.id === hit.id);
const station = placedStations.find(item => item.padId === hit.id);
if (station) {
selectStation(station.id);
} else {
placeFountain(pad);
}
} else if (hit.type === "station") {
selectStation(hit.id);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(camera.zoom * (event.deltaY > 0 ? 0.9 : 1.1), 0.65, 1.85);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
document.getElementById("routeRows").addEventListener("click", event => {
const cell = event.target.closest("[data-gate]");
const row = event.target.closest("[data-station]");
if (cell && row) {
selectStation(row.dataset.station, cell.dataset.gate);
} else if (row) {
selectStation(row.dataset.station);
}
});
document.getElementById("zoneList").addEventListener("click", event => {
const row = event.target.closest("[data-zone]");
if (!row) return;
const station = placedStations.find(item => item.zoneId === row.dataset.zone);
if (station) selectStation(station.id);
});
document.getElementById("removeButton").addEventListener("click", removeSelectedStation);
document.getElementById("resetButton").addEventListener("click", resetPlan);
document.getElementById("suggestButton").addEventListener("click", () => {
const suggestions = [];
zones.forEach(zone => {
const options = zone.pads.map(pad => {
const nodeId = padNodeIds.get(pad.id);
const west = shortestPath(westGateNode, nodeId).distance;
const south = shortestPath(southGateNode, nodeId).distance;
return { pad, score: Math.min(west, south), west, south };
});
options.sort((a, b) => a.score - b.score);
suggestions.push(options[0].pad);
});
const occupiedZones = new Set(placedStations.map(station => station.zoneId));
const available = suggestions.filter(pad => !occupiedZones.has(pad.zoneId));
if (!available.length) {
showToast("Every suggested pad is already in use.");
return;
}
placeFountain(available[0]);
});
document.getElementById("approachToggle").addEventListener("change", event => {
approachVisuals.forEach(visual => {
visual.clearDisc.visible = event.target.checked;
visual.approachRing.visible = event.target.checked;
});
});
document.getElementById("rotateLeft").addEventListener("click", () => {
cameraYaw -= 0.28;
updateCamera();
});
document.getElementById("zoomIn").addEventListener("click", () => {
camera.zoom = THREE.MathUtils.clamp(camera.zoom * 1.13, 0.65, 1.85);
updateCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
camera.zoom = THREE.MathUtils.clamp(camera.zoom / 1.13, 0.65, 1.85);
updateCamera();
});
document.getElementById("resetView").addEventListener("click", () => {
cameraYaw = 0.66;
cameraPitch = 0.82;
camera.zoom = 1;
cameraTarget.set(0, 0, 0);
updateCamera();
});
const helpModal = document.getElementById("helpModal");
document.getElementById("helpButton").addEventListener("click", () => {
helpModal.classList.remove("hidden");
});
document.getElementById("closeHelp").addEventListener("click", () => {
helpModal.classList.add("hidden");
});
helpModal.addEventListener("click", event => {
if (event.target === helpModal) helpModal.classList.add("hidden");
});
updateUI();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.04);
walkers.forEach((walker, index) => {
walker.offset += walker.speed * delta;
const position = samplePath(walker.path, walker.offset);
walker.group.position.set(position.x, 0.1, position.z);
walker.group.rotation.y = position.angle + (index % 2 === 0 ? 0 : Math.PI);
walker.group.children.forEach(child => {
if (child.geometry?.type === "BoxGeometry") {
child.rotation.x = Math.sin(elapsed * 9 + index) * 0.22;
}
});
});
approachVisuals.forEach((visual, index) => {
visual.approachRing.material.opacity =
0.62 + Math.sin(elapsed * 2.2 + index * 0.9) * 0.14;
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```