Prompt specification
Build or customize the Three.js 3D scene "Inclusive Playground Planning Board" 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: Inclusive Playground Planning Board
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/inclusive-playground-planning-board-x3204
Scene Description Prompt:
Make a voxel playground planning board comparing paths, rest areas, and reachable equipment with several mobility proxies. Three.js from cdnjs, one HTML file.
Working Three.js Starter (inclusive-playground-planning-board-x3204):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Access Playground</title>
<style>
:root {
--ink: #24322f;
--muted: #6f7c77;
--panel: rgba(255, 255, 255, 0.9);
--line: rgba(44, 67, 60, 0.12);
--green: #147d68;
--green-soft: #e4f3ee;
--blue: #5688e8;
--coral: #ef8b64;
--teal: #27a99a;
--shadow: 0 16px 40px rgba(42, 57, 51, 0.13);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #edf1ec;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.glass {
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.85);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.brand {
position: fixed;
top: 18px;
left: 18px;
width: 410px;
padding: 18px 20px 16px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 3px;
background: var(--green);
box-shadow: 0 0 0 4px rgba(20, 125, 104, 0.12);
}
h1 {
margin: 8px 0 4px;
font-size: 28px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.summary {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 14px;
}
.summary-item {
min-width: 0;
padding: 9px 10px;
border-radius: 12px;
background: rgba(239, 245, 241, 0.82);
}
.summary-item span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.summary-item strong {
display: block;
overflow: hidden;
margin-top: 3px;
font-size: 16px;
text-overflow: ellipsis;
white-space: nowrap;
}
.panel {
position: fixed;
top: 18px;
right: 18px;
width: 350px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border-radius: 20px;
scrollbar-width: thin;
scrollbar-color: #bec9c4 transparent;
}
.section + .section {
margin-top: 18px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.section-title h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.01em;
}
.section-title small {
color: var(--muted);
font-size: 10px;
}
.proxy-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.proxy-button {
position: relative;
min-height: 62px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.proxy-button:hover {
transform: translateY(-1px);
border-color: rgba(20, 125, 104, 0.3);
}
.proxy-button.active {
border-color: var(--proxy-color);
background: color-mix(in srgb, var(--proxy-color) 11%, white);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--proxy-color) 18%, transparent);
}
.proxy-button strong {
display: block;
font-size: 12px;
}
.proxy-button span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.proxy-dot {
position: absolute;
top: 11px;
right: 11px;
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--proxy-color);
}
.budget-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.budget-row label {
font-size: 12px;
font-weight: 700;
}
.budget-value {
padding: 5px 9px;
border-radius: 9px;
background: var(--green-soft);
color: var(--green);
font-size: 11px;
font-weight: 800;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0;
appearance: none;
border-radius: 10px;
outline: none;
background: linear-gradient(90deg, var(--green) 0 var(--range-fill, 40%), #dfe6e2 var(--range-fill, 40%));
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid white;
border-radius: 6px;
background: var(--green);
box-shadow: 0 2px 7px rgba(31, 77, 65, 0.25);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid white;
border-radius: 6px;
background: var(--green);
box-shadow: 0 2px 7px rgba(31, 77, 65, 0.25);
cursor: pointer;
}
.scale {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #9aa49f;
font-size: 9px;
}
.route-list {
display: grid;
gap: 8px;
}
.route-row {
position: relative;
display: grid;
grid-template-columns: 11px 1fr auto;
align-items: center;
gap: 9px;
width: 100%;
padding: 11px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.66);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.route-row:hover { transform: translateX(2px); }
.route-row.active {
border-color: rgba(20, 125, 104, 0.34);
background: #f5faf7;
box-shadow: 0 0 0 2px rgba(20, 125, 104, 0.07);
}
.route-swatch {
width: 9px;
height: 28px;
border-radius: 4px;
background: var(--route-color);
}
.route-name {
font-size: 12px;
font-weight: 800;
}
.route-meta {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.route-result {
text-align: right;
}
.route-result strong {
display: block;
font-size: 13px;
}
.route-result span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
text-transform: uppercase;
}
.route-result .blocked {
color: #bd654e;
}
.layer-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.layer-button {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.6);
color: var(--muted);
font-size: 9px;
font-weight: 700;
cursor: pointer;
}
.layer-button input {
accent-color: var(--green);
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
color: var(--muted);
font-size: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-mark {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--mark);
}
.legend-mark.outline {
border: 2px solid var(--green);
background: transparent;
}
.proxy-strip {
position: fixed;
left: 18px;
bottom: 18px;
width: min(650px, calc(100vw - 396px));
padding: 13px;
border-radius: 18px;
}
.strip-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 2px 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.proxy-cards {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
}
.compare-card {
min-width: 0;
padding: 10px;
border: 1px solid transparent;
border-radius: 12px;
background: rgba(240, 244, 241, 0.86);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.compare-card:hover { background: #edf3f0; }
.compare-card.active {
border-color: var(--proxy-color);
background: color-mix(in srgb, var(--proxy-color) 9%, white);
}
.compare-card strong {
display: block;
overflow: hidden;
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
.compare-card span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
line-height: 1.35;
}
.selection {
position: fixed;
left: 18px;
bottom: 142px;
width: 330px;
padding: 14px 16px;
border-radius: 17px;
pointer-events: none;
}
.selection-kicker {
color: var(--green);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.selection h3 {
margin: 5px 0 4px;
font-size: 16px;
letter-spacing: -0.02em;
}
.selection p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.tag-row {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 9px;
}
.tag {
padding: 4px 7px;
border-radius: 7px;
background: #edf2ef;
color: #52635d;
font-size: 8px;
font-weight: 700;
}
.hint {
position: fixed;
right: 386px;
bottom: 20px;
padding: 8px 11px;
border-radius: 10px;
color: #718079;
font-size: 9px;
pointer-events: none;
}
.mobile-note { display: none; }
@media (max-width: 1050px) {
.brand { width: 350px; }
.panel { width: 320px; }
.proxy-strip { width: calc(100vw - 358px); }
.proxy-cards { grid-template-columns: repeat(2, 1fr); }
.selection { bottom: 225px; }
.hint { display: none; }
}
@media (max-width: 760px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 13px 15px;
}
h1 { font-size: 22px; }
.brand p { display: none; }
.summary { margin-top: 10px; }
.summary-item { padding: 6px 8px; }
.summary-item strong { font-size: 13px; }
.panel {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100% - 20px);
max-height: 43vh;
padding: 14px;
border-radius: 17px;
}
.proxy-strip {
left: 10px;
bottom: calc(43vh + 20px);
width: calc(100% - 20px);
padding: 10px;
}
.proxy-cards {
display: flex;
overflow-x: auto;
}
.compare-card {
min-width: 130px;
}
.selection { display: none; }
.mobile-note { display: inline; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D voxel playground planning board"></div>
<header class="brand glass">
<div class="eyebrow">Access atlas · playground 04</div>
<h1>Small routes. Big possibilities.</h1>
<p>Compare walking surfaces, recovery points, and play opportunities through four mobility proxies.</p>
<div class="summary" aria-live="polite">
<div class="summary-item">
<span>Route walk</span>
<strong id="summaryTime">—</strong>
</div>
<div class="summary-item">
<span>Reachable play</span>
<strong id="summaryStops">—</strong>
</div>
<div class="summary-item">
<span>Rest cues</span>
<strong id="summaryRests">—</strong>
</div>
</div>
</header>
<aside class="panel glass" aria-label="Planning controls">
<section class="section">
<div class="section-title">
<h2>Mobility proxy</h2>
<small>Switch perspective</small>
</div>
<div class="proxy-grid" id="proxyGrid"></div>
</section>
<section class="section">
<div class="section-title">
<h2>Visit budget</h2>
<small>Travel + play time</small>
</div>
<div class="budget-row">
<label for="budget">Time away from entry</label>
<output class="budget-value" id="budgetValue" for="budget">7 min</output>
</div>
<input id="budget" type="range" min="4" max="12" step="1" value="7">
<div class="scale"><span>4 min</span><span>8 min</span><span>12 min</span></div>
</section>
<section class="section">
<div class="section-title">
<h2>Path comparison</h2>
<small>Click to focus</small>
</div>
<div class="route-list" id="routeList"></div>
</section>
<section class="section">
<div class="section-title">
<h2>Board layers</h2>
<small>Toggle visibility</small>
</div>
<div class="layer-row">
<label class="layer-button"><input id="layerPaths" type="checkbox" checked> Paths</label>
<label class="layer-button"><input id="layerEquipment" type="checkbox" checked> Equipment</label>
<label class="layer-button"><input id="layerRest" type="checkbox" checked> Rest areas</label>
</div>
</section>
<section class="section">
<div class="section-title">
<h2>Map legend</h2>
</div>
<div class="legend">
<div class="legend-item"><i class="legend-mark" style="--mark:#5688e8"></i> Ribbon Run</div>
<div class="legend-item"><i class="legend-mark" style="--mark:#ef8b64"></i> Forest Trail</div>
<div class="legend-item"><i class="legend-mark" style="--mark:#27a99a"></i> Easy Circuit</div>
<div class="legend-item"><i class="legend-mark" style="--mark:#49c4b1"></i> Rest bench</div>
<div class="legend-item"><i class="legend-mark outline"></i> Reachable</div>
<div class="legend-item"><i class="legend-mark" style="--mark:#ef8b64"></i> Play feature</div>
</div>
</section>
</aside>
<section class="selection glass" id="selection" aria-live="polite"></section>
<section class="proxy-strip glass" aria-label="Mobility proxy comparison">
<div class="strip-heading">
<span>Proxy comparison</span>
<span id="stripCaption">Best fit at 7 min</span>
</div>
<div class="proxy-cards" id="proxyCards"></div>
</section>
<div class="hint glass">Drag to orbit · Shift-drag to pan · Scroll to zoom · Select a feature</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const GRID_X = 26;
const GRID_Z = 20;
const CELL = 1;
const METERS_PER_CELL = 2.5;
const REST_DURATION = 2.5;
const state = {
proxyId: "wheelchair",
activeRouteId: "ribbon",
budget: 7,
selected: null
};
const proxies = [
{
id: "walker",
name: "Walking",
short: "Walker",
color: "#efb547",
speed: 1.35,
maxSlope: 10,
minWidth: 1.2,
restEvery: 4,
comfort: 0.9,
note: "10% slope · rest every 4 min"
},
{
id: "rollator",
name: "Rollator",
short: "Rollator",
color: "#b47be8",
speed: 1.0,
maxSlope: 6.8,
minWidth: 1.5,
restEvery: 2,
comfort: 0.67,
note: "6.8% slope · rest every 2 min"
},
{
id: "wheelchair",
name: "Wheelchair",
short: "Wheelchair",
color: "#3d8ee8",
speed: 0.8,
maxSlope: 5.2,
minWidth: 1.8,
restEvery: 2.5,
comfort: 0.4,
note: "5.2% slope · firm surface"
},
{
id: "stroller",
name: "Stroller",
short: "Stroller",
color: "#ef806e",
speed: 1.1,
maxSlope: 5,
minWidth: 2,
restEvery: 1.5,
comfort: 0.55,
note: "5% slope · room to turn"
}
];
const routes = [
{
id: "ribbon",
name: "Ribbon Run",
color: "#5688e8",
surface: "Rubber",
width: 2.6,
slope: 2.4,
roughness: 0.06,
waypoints: [[2,16],[6,16],[6,5],[12,5],[12,13],[18,13],[18,6],[23,6]]
},
{
id: "forest",
name: "Forest Trail",
color: "#ef8b64",
surface: "Gravel",
width: 1.7,
slope: 6.4,
roughness: 0.36,
waypoints: [[2,16],[4,16],[4,2],[10,2],[10,17],[16,17],[16,3],[23,3]]
},
{
id: "easy",
name: "Easy Circuit",
color: "#27a99a",
surface: "Resin",
width: 2.8,
slope: 3.4,
roughness: 0.02,
waypoints: [[2,16],[7,16],[7,7],[11,7],[11,13],[17,13],[17,8],[23,8]]
}
];
const benches = [
{ id: "bench1", name: "Willow Rest", position: [5,12], seats: 3, detail: "Shaded bench beside the main ribbon." },
{ id: "bench2", name: "Moss Break", position: [13,9], seats: 2, detail: "Quiet reset point near the central play zone." },
{ id: "bench3", name: "Creek Rest", position: [19,11], seats: 3, detail: "Rest bench overlooking the eastern play area." },
{ id: "bench4", name: "Pine Pause", position: [3,8], seats: 2, detail: "Rest point along the wooded north-west leg." },
{ id: "bench5", name: "Ridge Rest", position: [9,12], seats: 3, detail: "Central bench with a clear view across the playground." },
{ id: "bench6", name: "Timber Rest", position: [17,9], seats: 2, detail: "Rest point close to the climbing and water zones." },
{ id: "bench7", name: "Garden Rest", position: [8,11], seats: 3, detail: "Sheltered seating near the sensory garden." },
{ id: "bench8", name: "Loop Rest", position: [10,12], seats: 2, detail: "Short-break bench on the accessible loop." },
{ id: "bench9", name: "East Rest", position: [18,10], seats: 3, detail: "Rest bench at the accessible circuit’s east turn." }
];
const features = [
{
id: "sensory", name: "Sensory Garden", type: "Calm play",
position: [8,12], dwell: 2.5,
detail: "Low tactile panels, quiet seating and a compact sensory garden.",
tags: ["Low stimulus", "Tactile", "Shaded"]
},
{
id: "slide", name: "Voxel Slide", type: "Active play",
position: [14,9], dwell: 3.5,
detail: "A broad platform slide with a gradual transfer route.",
tags: ["Platform", "Grade 1", "Social"]
},
{
id: "swings", name: "Swing Grove", type: "Active play",
position: [19,14], dwell: 3,
detail: "Two swing bays set on a firm, level landing.",
tags: ["Level landing", "Companion space"]
},
{
id: "climber", name: "Block Mountain", type: "Active play",
position: [17,6], dwell: 2.5,
detail: "Low climbing blocks with multiple heights and easy exits.",
tags: ["Low", "Multiple exits", "Open deck"]
},
{
id: "carousel", name: "Pixel Carousel", type: "Shared play",
position: [13,4], dwell: 2,
detail: "A slow carousel with a broad entry and level viewing deck.",
tags: ["Slow speed", "Level", "Shared"]
},
{
id: "water", name: "Water Cubes", type: "Sensory play",
position: [22,9], dwell: 3,
detail: "Drip paths and tactile water-play cubes with a nearby drain-off pad.",
tags: ["Tactile", "Drip pad", "Shade"]
},
{
id: "quiet", name: "Quiet Nook", type: "Calm play",
position: [7,3], dwell: 2,
detail: "An enclosed reading nook with soft seating and a clear approach.",
tags: ["Quiet", "Reading", "Seated"]
},
{
id: "basket", name: "Pixel Baskets", type: "Active play",
position: [3,15], dwell: 2,
detail: "Low, adjustable basketball hoops with a broad stopping zone.",
tags: ["Adjustable", "Low hoop", "Open space"]
},
{
id: "hoops", name: "Team Hoops", type: "Social play",
position: [19,14], dwell: 2.5,
detail: "Two compact goals positioned on a firm, open court.",
tags: ["Team play", "Level court", "Seating nearby"]
},
{
id: "tactile", name: "Tactile Trail", type: "Sensory play",
position: [13,14], dwell: 2,
detail: "A short raised-texture trail with frequent passing and resting points.",
tags: ["Tactile", "Short route", "Rest nearby"]
}
];
const $ = (selector) => document.querySelector(selector);
const gridToWorld = (gx, gz) => new THREE.Vector3(
(gx - (GRID_X - 1) / 2) * CELL,
0,
(gz - (GRID_Z - 1) / 2) * CELL
);
function expandWaypoints(points) {
const cells = [];
for (let i = 0; i < points.length - 1; i++) {
let [x, z] = points[i];
const [tx, tz] = points[i + 1];
while (x !== tx) {
x += Math.sign(tx - x);
cells.push([x, z]);
}
while (z !== tz) {
z += Math.sign(tz - z);
cells.push([x, z]);
}
}
return cells;
}
routes.forEach(route => {
route.cells = expandWaypoints(route.waypoints);
route.lengthMeters = (route.cells.length - 1) * METERS_PER_CELL;
});
const proxyMap = Object.fromEntries(proxies.map(p => [p.id, p]));
const routeMap = Object.fromEntries(routes.map(r => [r.id, r]));
const featureMap = Object.fromEntries(features.map(f => [f.id, f]));
const benchMap = Object.fromEntries(benches.map(b => [b.id, b]));
function nearestRouteCell(position, route) {
let best = { index: 0, distance: Infinity };
route.cells.forEach((cell, index) => {
const distance = Math.abs(cell[0] - position[0]) + Math.abs(cell[1] - position[1]);
if (distance < best.distance) best = { index, distance };
});
return best;
}
function routeCompatibility(route, proxy) {
const slopeReason = route.slope > proxy.maxSlope;
const widthReason = route.width < proxy.minWidth;
return {
suitable: !slopeReason && !widthReason,
reason: slopeReason
? `Slope ${route.slope}% over ${proxy.maxSlope}%`
: widthReason
? `${route.width}m width below ${proxy.minWidth}m`
: "Good fit"
};
}
function routeTravelMinutes(route, proxy) {
const surfacePenalty = 1 + route.roughness * (1 - proxy.comfort) * 2;
const slopeRatio = route.slope / proxy.maxSlope;
const slopePenalty = slopeRatio > 0.65 ? 1 + (slopeRatio - 0.65) * 0.8 : 1;
return METERS_PER_CELL / proxy.speed / 60 * surfacePenalty * slopePenalty;
}
function simulateRoute(route, proxy) {
const compatibility = routeCompatibility(route, proxy);
const perCell = routeTravelMinutes(route, proxy);
const times = [0];
const benchIndices = new Map();
benches.forEach(bench => {
const nearest = nearestRouteCell(bench.position, route);
if (nearest.distance <= 3 && !benchIndices.has(nearest.index)) {
benchIndices.set(nearest.index, bench.id);
}
});
let total = 0;
let continuous = 0;
let restCount = 0;
for (let i = 1; i < route.cells.length; i++) {
total += perCell;
continuous += perCell;
times[i] = total;
if (continuous >= proxy.restEvery && benchIndices.has(i)) {
total += REST_DURATION;
continuous = 0;
restCount++;
times[i] = total;
}
}
return { ...compatibility, times, total, restCount, perCell };
}
function calculateMetrics(proxy) {
const result = {};
routes.forEach(route => {
const simulation = simulateRoute(route, proxy);
const featureResults = {};
features.forEach(feature => {
const nearest = nearestRouteCell(feature.position, route);
const detourMeters = nearest.distance * METERS_PER_CELL * 2;
const detourMinutes = routeTravelMinutes(route, proxy) * nearest.distance * 2;
const arrival = simulation.times[nearest.index] + detourMinutes;
const total = arrival + feature.dwell;
const shortSpur = nearest.distance <= 4;
const reachable = simulation.suitable && shortSpur && total <= state.budget;
featureResults[feature.id] = {
nearest,
shortSpur,
arrival,
total,
reachable,
reason: !simulation.suitable
? simulation.reason
: !shortSpur
? "No short connection from this route"
: total > state.budget
? `Needs ${total.toFixed(1)} min`
: "Reachable"
};
});
const benchResults = {};
benches.forEach(bench => {
const nearest = nearestRouteCell(bench.position, route);
const arrival = simulation.times[nearest.index] +
routeTravelMinutes(route, proxy) * nearest.distance * 2;
benchResults[bench.id] = {
nearest,
arrival,
reachable: simulation.suitable && nearest.distance <= 3 && arrival <= state.budget
};
});
result[route.id] = {
...simulation,
features: featureResults,
benches: benchResults,
stops: Object.values(featureResults).filter(item => item.reachable).length
};
});
return result;
}
function createInterface() {
$("#proxyGrid").innerHTML = proxies.map(proxy => `
<button class="proxy-button ${proxy.id === state.proxyId ? "active" : ""}"
data-proxy="${proxy.id}" style="--proxy-color:${proxy.color}"
aria-pressed="${proxy.id === state.proxyId}">
<i class="proxy-dot"></i>
<strong>${proxy.name}</strong>
<span>${proxy.note}</span>
</button>
`).join("");
$("#routeList").innerHTML = routes.map(route => `
<button class="route-row ${route.id === state.activeRouteId ? "active" : ""}"
data-route="${route.id}" style="--route-color:${route.color}">
<i class="route-swatch"></i>
<span>
<span class="route-name">${route.name}</span>
<span class="route-meta" data-role="route-meta"></span>
</span>
<span class="route-result">
<strong data-role="route-time"></strong>
<span data-role="route-status"></span>
</span>
</button>
`).join("");
$("#proxyCards").innerHTML = proxies.map(proxy => `
<button class="compare-card ${proxy.id === state.proxyId ? "active" : ""}"
data-proxy="${proxy.id}" style="--proxy-color:${proxy.color}">
<strong>${proxy.name}</strong>
<span data-role="best-route"></span>
<span data-role="proxy-result"></span>
</button>
`).join("");
$("#proxyGrid").addEventListener("click", event => {
const button = event.target.closest("[data-proxy]");
if (!button) return;
state.proxyId = button.dataset.proxy;
updateAll();
});
$("#proxyCards").addEventListener("click", event => {
const button = event.target.closest("[data-proxy]");
if (!button) return;
state.proxyId = button.dataset.proxy;
updateAll();
});
$("#routeList").addEventListener("click", event => {
const button = event.target.closest("[data-route]");
if (!button) return;
state.activeRouteId = button.dataset.route;
updateAll();
});
$("#budget").addEventListener("input", event => {
state.budget = Number(event.target.value);
updateAll();
});
$("#layerPaths").addEventListener("change", event => {
routes.forEach(route => route.group.visible = event.target.checked);
});
$("#layerEquipment").addEventListener("change", event => {
equipmentGroup.visible = event.target.checked;
});
$("#layerRest").addEventListener("change", event => {
restGroup.visible = event.target.checked;
});
}
createInterface();
const scene = new THREE.Scene();
scene.background = new THREE.Color("#edf1ec");
scene.fog = new THREE.Fog("#edf1ec", 36, 65);
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.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
$("#scene").appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-18, 18, 12, -12, 0.1, 120);
const controls = {
theta: 0.62,
phi: 0.78,
radius: 38,
target: new THREE.Vector3(0, 0, 0)
};
const hemi = new THREE.HemisphereLight("#ffffff", "#7f9a88", 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff4dc", 3.1);
sun.position.set(-13, 21, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.0005;
scene.add(sun);
const boardGroup = new THREE.Group();
const equipmentGroup = new THREE.Group();
const restGroup = new THREE.Group();
const spurGroup = new THREE.Group();
scene.add(boardGroup, equipmentGroup, restGroup);
equipmentGroup.add(spurGroup);
const pickables = [];
const worldUp = new THREE.Vector3(0, 1, 0);
function addBox(parent, width, height, depth, x, y, z, color, options = {}) {
const material = options.material || new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0
});
if (options.tint) {
material.userData.baseColor = color;
parent.userData.tintMaterials ||= [];
parent.userData.tintMaterials.push(material);
}
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) mesh.rotation.set(...options.rotation);
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radiusTop, radiusBottom, height, x, y, z, color, options = {}) {
const material = new THREE.MeshStandardMaterial({ color, roughness: 0.78 });
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, options.segments || 12),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function registerPickable(group, data) {
group.traverse(child => {
if (child.isMesh) {
child.userData.pickData = data;
pickables.push(child);
}
});
}
function createBoard() {
addBox(boardGroup, GRID_X + 0.8, 0.6, GRID_Z + 0.8, 0, -0.36, 0, "#cbd5cc");
const tileGeometry = new THREE.BoxGeometry(0.975, 0.08, 0.975);
const tileMaterial = new THREE.MeshStandardMaterial({ color: "#ffffff", roughness: 1 });
const grass = new THREE.InstancedMesh(tileGeometry, tileMaterial, GRID_X * GRID_Z);
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
let instance = 0;
for (let z = 0; z < GRID_Z; z++) {
for (let x = 0; x < GRID_X; x++) {
matrix.makeTranslation(
x - (GRID_X - 1) / 2,
0,
z - (GRID_Z - 1) / 2
);
grass.setMatrixAt(instance, matrix);
const noise = ((x * 17 + z * 31 + x * z) % 7) / 30;
color.setHSL(0.29 + noise * 0.02, 0.22, 0.66 + noise);
grass.setColorAt(instance, color);
instance++;
}
}
grass.receiveShadow = true;
boardGroup.add(grass);
const curb = "#aebdb1";
addBox(boardGroup, GRID_X + 1.1, 0.28, 0.28, 0, 0.04, -GRID_Z / 2 - 0.45, curb);
addBox(boardGroup, GRID_X + 1.1, 0.28, 0.28, 0, 0.04, GRID_Z / 2 + 0.45, curb);
addBox(boardGroup, 0.28, 0.28, GRID_Z + 0.6, -GRID_X / 2 - 0.45, 0.04, 0, curb);
addBox(boardGroup, 0.28, 0.28, GRID_Z + 0.6, GRID_X / 2 + 0.45, 0.04, 0, curb);
const entry = new THREE.Group();
entry.position.copy(gridToWorld(2, 16));
addBox(entry, 0.18, 1.8, 0.18, -0.65, 0.9, 0, "#f4c54d");
addBox(entry, 0.18, 1.8, 0.18, 0.65, 0.9, 0, "#f4c54d");
addBox(entry, 1.55, 0.24, 0.24, 0, 1.75, 0, "#f4c54d");
boardGroup.add(entry);
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 72;
const context = labelCanvas.getContext("2d");
context.fillStyle = "rgba(255,255,255,0.94)";
context.fillRect(8, 8, 240, 56);
context.fillStyle = "#24322f";
context.font = "700 28px sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("ENTRY", 128, 37);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ map: texture, depthTest: false }));
sprite.position.copy(gridToWorld(2, 16)).add(new THREE.Vector3(0, 2.35, 0));
sprite.scale.set(2.2, 0.62, 1);
boardGroup.add(sprite);
}
function createRoutes() {
routes.forEach((route, routeIndex) => {
const group = new THREE.Group();
route.group = group;
boardGroup.add(group);
const material = new THREE.MeshStandardMaterial({
color: route.color,
roughness: 0.9,
transparent: true,
opacity: 1
});
route.material = material;
const tile = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.87, 0.13, 0.87),
material,
route.cells.length
);
const matrix = new THREE.Matrix4();
route.cells.forEach((cell, index) => {
const position = gridToWorld(cell[0], cell[1]);
matrix.makeTranslation(position.x, 0.12 + routeIndex * 0.015, position.z);
tile.setMatrixAt(index, matrix);
});
tile.receiveShadow = true;
tile.castShadow = false;
group.add(tile);
const guideMaterial = new THREE.MeshBasicMaterial({
color: "#ffffff",
transparent: true,
opacity: 0.38
});
route.cells.forEach((cell, index) => {
if (index % 5 !== 0) return;
const position = gridToWorld(cell[0], cell[1]);
const stud = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.025, 0.13),
guideMaterial
);
stud.position.set(position.x, 0.205 + routeIndex * 0.015, position.z);
group.add(stud);
});
});
}
function createHalo(parent, size = 2.25) {
const halo = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color: "#29aa83",
transparent: true,
opacity: 0.42,
depthWrite: false
});
const thickness = 0.07;
addBox(halo, size, 0.025, thickness, 0, 0.22, -size / 2, "#29aa83", { material, castShadow: false });
addBox(halo, size, 0.025, thickness, 0, 0.22, size / 2, "#29aa83", { material, castShadow: false });
addBox(halo, thickness, 0.025, size, -size / 2, 0.22, 0, "#29aa83", { material, castShadow: false });
addBox(halo, thickness, 0.025, size, size / 2, 0.22, 0, "#29aa83", { material, castShadow: false });
halo.visible = false;
parent.add(halo);
parent.userData.halo = halo;
return halo;
}
function buildSensory(group) {
addBox(group, 0.8, 0.35, 0.8, -0.55, 0.29, -0.45, "#8fc7dc", { tint: true });
addBox(group, 0.55, 0.52, 0.55, 0.35, 0.36, -0.5, "#f4c65f", { tint: true });
addBox(group, 0.6, 0.24, 0.6, -0.2, 0.22, 0.55, "#d99ac3", { tint: true });
addBox(group, 1.6, 0.12, 0.45, 0, 0.22, 0.25, "#7caea1", { tint: true });
}
function buildSlide(group) {
addBox(group, 0.75, 1.7, 0.75, -0.45, 0.95, -0.65, "#ef8b64", { tint: true });
addBox(group, 1.1, 0.18, 1.05, -0.45, 1.82, -0.65, "#f4c65f", { tint: true });
addBox(group, 0.78, 0.16, 3.25, -0.45, 0.82, 0.45, "#ef8b64", {
tint: true,
rotation: [0.54, 0, 0]
});
for (let i = 0; i < 4; i++) {
addBox(group, 0.9, 0.3, 0.48, 0.7, 0.22 + i * 0.32, -0.9 + i * 0.45,
i % 2 ? "#f4c65f" : "#7caea1", { tint: true });
}
}
function buildSwings(group) {
addBox(group, 0.16, 2.15, 0.16, -1, 1.15, 0, "#536c75");
addBox(group, 0.16, 2.15, 0.16, 1, 1.15, 0, "#536c75");
addBox(group, 2.3, 0.17, 0.18, 0, 2.15, 0, "#ef8b64", { tint: true });
addBox(group, 0.08, 1.0, 0.08, -0.5, 1.65, 0, "#596f75");
addBox(group, 0.08, 1.0, 0.08, 0.5, 1.65, 0, "#596f75");
addBox(group, 0.7, 0.12, 0.35, -0.5, 1.12, 0, "#f4c65f", { tint: true });
addBox(group, 0.7, 0.12, 0.35, 0.5, 1.12, 0, "#f4c65f", { tint: true });
}
function buildClimber(group) {
const blocks = [
[0, 0.35, 0, 1.05, 0.6, 1.05, "#ef8b64"],
[0.7, 0.55, -0.25, 0.8, 1.0, 0.8, "#f4c65f"],
[-0.65, 0.45, 0.45, 0.9, 0.8, 0.9, "#67b9aa"],
[0.2, 1.15, 0.05, 0.7, 0.55, 0.7, "#8e9ed0"]
];
blocks.forEach(block => {
addBox(group, block[3], block[4], block[5], block[0], block[1], block[2], block[6], { tint: true });
});
}
function buildCarousel(group) {
addBox(group, 2.25, 0.25, 2.25, 0, 0.28, 0, "#e9c86f", { tint: true });
addBox(group, 0.22, 1.55, 0.22, 0, 0.98, 0, "#58717a");
addBox(group, 2.5, 0.16, 0.18, 0, 1.55, 0, "#ef8b64", { tint: true });
addBox(group, 0.18, 0.16, 2.5, 0, 1.55, 0, "#ef8b64", { tint: true });
[[0.85,0],[0,0.85],[-0.85,0],[0,-0.85]].forEach(([x,z], index) => {
addBox(group, 0.45, 0.55, 0.45, x, 0.62, z,
index % 2 ? "#70b9ac" : "#7396d3", { tint: true });
});
}
function buildWater(group) {
addBox(group, 2.1, 0.12, 1.7, 0, 0.18, 0, "#6eb6cf", { tint: true });
addBox(group, 0.5, 0.5, 0.5, -0.55, 0.43, -0.35, "#9bd5df", { tint: true });
addBox(group, 0.38, 0.75, 0.38, 0.1, 0.5, -0.1, "#5da5c1", { tint: true });
addBox(group, 0.58, 0.28, 0.58, 0.65, 0.35, 0.45, "#f2cb6e", { tint: true });
}
function buildQuiet(group) {
addBox(group, 1.7, 0.16, 1.5, 0, 0.2, 0, "#79b8a8", { tint: true });
addBox(group, 1.7, 1.55, 0.2, 0, 0.9, -0.65, "#6aa596", { tint: true });
addBox(group, 0.2, 1.55, 1.3, -0.75, 0.9, 0, "#6aa596", { tint: true });
addBox(group, 0.2, 1.55, 1.3, 0.75, 0.9, 0, "#6aa596", { tint: true });
addBox(group, 0.75, 0.28, 0.7, 0, 0.42, 0.25, "#f2cb6e", { tint: true });
}
function buildBasket(group) {
addBox(group, 0.18, 1.5, 0.18, -0.75, 0.85, -0.35, "#ef8b64", { tint: true });
addBox(group, 0.18, 1.5, 0.18, 0.75, 0.85, -0.35, "#ef8b64", { tint: true });
addBox(group, 1.8, 0.18, 0.18, 0, 1.55, -0.35, "#ef8b64", { tint: true });
addBox(group, 0.72, 0.12, 0.18, 0, 1.18, -0.35, "#f4c65f", { tint: true });
}
function buildHoops(group) {
addBox(group, 0.16, 1.55, 0.16, -0.85, 0.85, 0, "#6f91d4", { tint: true });
addBox(group, 0.16, 1.55, 0.16, 0.85, 0.85, 0, "#6f91d4", { tint: true });
addBox(group, 1.95, 0.16, 0.16, 0, 1.55, 0, "#6f91d4", { tint: true });
addBox(group, 0.85, 0.12, 0.18, 0, 1.2, 0, "#f1cb70", { tint: true });
}
function buildTactile(group) {
const colors = ["#ef8b64", "#f2cb70", "#69b9a9", "#7897d3"];
for (let i = 0; i < 7; i++) {
const angle = i / 7 * Math.PI * 2;
addBox(group, 0.46, 0.28, 0.46,
Math.cos(angle) * 0.75,
0.28,
Math.sin(angle) * 0.75,
colors[i % colors.length], { tint: true });
}
addBox(group, 0.7, 0.12, 0.7, 0, 0.23, 0, "#f0e6cf", { tint: true });
}
function createEquipment() {
const builders = {
sensory: buildSensory,
slide: buildSlide,
swings: buildSwings,
climber: buildClimber,
carousel: buildCarousel,
water: buildWater,
quiet: buildQuiet,
basket: buildBasket,
hoops: buildHoops,
tactile: buildTactile
};
features.forEach(feature => {
const group = new THREE.Group();
group.position.copy(gridToWorld(feature.position[0], feature.position[1]));
group.userData.tintMaterials = [];
addBox(group, 2.25, 0.1, 2.25, 0, 0.11, 0, "#d9d2bd");
builders[feature.id](group);
createHalo(group);
feature.group = group;
equipmentGroup.add(group);
registerPickable(group, { type: "feature", id: feature.id });
});
}
function createBenches() {
benches.forEach(bench => {
const group = new THREE.Group();
group.position.copy(gridToWorld(bench.position[0], bench.position[1]));
group.userData.tintMaterials = [];
addBox(group, 1.75, 0.08, 1.15, 0, 0.12, 0, "#71c8b7");
addBox(group, 1.5, 0.17, 0.5, 0, 0.61, 0, "#a77650", { tint: true });
addBox(group, 1.5, 0.55, 0.14, 0, 0.9, 0.2, "#a77650", { tint: true });
addBox(group, 0.14, 0.45, 0.42, -0.55, 0.36, 0, "#536c65");
addBox(group, 0.14, 0.45, 0.42, 0.55, 0.36, 0, "#536c65");
bench.group = group;
restGroup.add(group);
registerPickable(group, { type: "bench", id: bench.id });
});
}
function seededRandom(seed) {
return function() {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
function createTrees() {
const random = seededRandom(418);
const colors = ["#6b9d70", "#83ad76", "#5e916c", "#91b77c"];
let count = 0;
let attempts = 0;
while (count < 24 && attempts < 900) {
attempts++;
const gx = 1 + Math.floor(random() * (GRID_X - 2));
const gz = 1 + Math.floor(random() * (GRID_Z - 2));
const nearRoute = routes.some(route => route.cells.some(cell =>
Math.abs(cell[0] - gx) + Math.abs(cell[1] - gz) <= 1
));
const nearFeature = features.some(feature =>
Math.abs(feature.position[0] - gx) + Math.abs(feature.position[1] - gz) <= 2
);
if (nearRoute || nearFeature) continue;
const tree = new THREE.Group();
tree.position.copy(gridToWorld(gx, gz));
addBox(tree, 0.32, 1.15, 0.32, 0, 0.62, 0, "#806345");
const size = 0.75 + random() * 0.38;
addBox(tree, size, size * 0.72, size, 0, 1.48, 0, colors[count % colors.length]);
addBox(tree, size * 0.68, size * 0.62, size * 0.72, -size * 0.36, 1.92, 0.05, colors[(count + 1) % colors.length]);
addBox(tree, size * 0.62, size * 0.58, size * 0.67, size * 0.34, 1.98, -0.06, colors[(count + 2) % colors.length]);
boardGroup.add(tree);
count++;
}
}
function createAgent() {
const agent = new THREE.Group();
addBox(agent, 0.38, 0.55, 0.3, 0, 0.55, 0, "#3d8ee8");
addBox(agent, 0.34, 0.34, 0.34, 0, 1.05, 0, "#efc7a1");
addBox(agent, 0.46, 0.12, 0.48, 0, 1.26, 0, "#3d8ee8");
scene.add(agent);
return agent;
}
const agent = createAgent();
createBoard();
createRoutes();
createEquipment();
createBenches();
createTrees();
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const verticalView = Math.max(21, 34 / aspect);
camera.left = -verticalView * aspect / 2;
camera.right = verticalView * aspect / 2;
camera.top = verticalView / 2;
camera.bottom = -verticalView / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
let pointerDown = null;
let hoverData = null;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = {
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
pan: event.shiftKey || event.button === 2,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - pointerDown.lastX;
const dy = event.clientY - pointerDown.lastY;
const totalDistance = Math.hypot(event.clientX - pointerDown.x, event.clientY - pointerDown.y);
if (totalDistance > 4) pointerDown.moved = true;
if (pointerDown.pan) {
const scale = 0.035;
const right = new THREE.Vector3(Math.cos(controls.theta), 0, -Math.sin(controls.theta));
controls.target.addScaledVector(right, -dx * scale);
controls.target.z += dy * scale;
controls.target.x += dx * scale * 0.15;
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.005, 0.48, 1.28);
}
pointerDown.lastX = event.clientX;
pointerDown.lastY = event.clientY;
updateCamera();
return;
}
const hit = pick(event.clientX, event.clientY);
hoverData = hit?.object.userData.pickData || null;
renderer.domElement.style.cursor = hoverData ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerDown && !pointerDown.moved && event.button === 0) {
const hit = pick(event.clientX, event.clientY);
if (hit) {
state.selected = hit.object.userData.pickData;
updateSelection(metrics);
}
}
pointerDown = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.025,
22,
52
);
updateCamera();
}, { passive: false });
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pick(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(pickables, false)[0];
}
function rebuildSpurs(metric) {
while (spurGroup.children.length) {
const child = spurGroup.children.pop();
child.parent = null;
}
const route = routeMap[state.activeRouteId];
const seen = new Set();
features.forEach(feature => {
const result = metric.features[feature.id];
if (!result.reachable) return;
const start = route.cells[result.nearest.index];
const end = feature.position;
const cells = [];
let x = start[0];
let z = start[1];
while (x !== end[0]) {
x += Math.sign(end[0] - x);
cells.push([x, z]);
}
while (z !== end[1]) {
z += Math.sign(end[1] - z);
cells.push([x, z]);
}
cells.forEach(cell => {
const key = cell.join(",");
if (seen.has(key)) return;
seen.add(key);
const position = gridToWorld(cell[0], cell[1]);
const material = new THREE.MeshStandardMaterial({
color: route.color,
roughness: 0.9,
transparent: true,
opacity: 0.48
});
const tile = new THREE.Mesh(new THREE.BoxGeometry(0.62, 0.09, 0.62), material);
tile.position.set(position.x, 0.13, position.z);
tile.receiveShadow = true;
spurGroup.add(tile);
});
});
}
function tintGroup(group, reachable, type) {
const materials = group.userData.tintMaterials || [];
materials.forEach(material => {
const base = material.userData.baseColor || "#ef8b64";
material.color.set(reachable ? base : "#aab3ae");
material.emissive.set(reachable ? (type === "bench" ? "#123f37" : "#0b332b") : "#000000");
material.emissiveIntensity = reachable ? 0.12 : 0;
});
if (group.userData.halo) group.userData.halo.visible = reachable;
}
function updateVisuals(metric) {
routes.forEach(route => {
const active = route.id === state.activeRouteId;
route.material.opacity = active ? 1 : 0.38;
route.material.color.set(route.color);
});
features.forEach(feature => {
const result = metric.features[feature.id];
tintGroup(feature.group, result.reachable, "feature");
});
benches.forEach(bench => {
const result = metric.benches[bench.id];
tintGroup(bench.group, result.reachable, "bench");
});
agent.traverse(child => {
if (child.isMesh && child.material.color) {
if (child === agent.children[0] || child === agent.children[2]) {
child.material.color.set(proxyMap[state.proxyId].color);
}
}
});
rebuildSpurs(metric);
}
function updateSelection(metric) {
if (!state.selected) return;
const route = routeMap[state.activeRouteId];
const proxy = proxyMap[state.proxyId];
const routeMetric = metric[route.id];
if (state.selected.type === "feature") {
const feature = featureMap[state.selected.id];
const result = routeMetric.features[feature.id];
let status = result.reachable
? `Reachable in ${result.total.toFixed(1)} min`
: result.reason;
let statusColor = result.reachable ? "#147d68" : "#a76550";
$("#selection").innerHTML = `
<div class="selection-kicker">Selected feature · ${feature.type}</div>
<h3>${feature.name}</h3>
<p>${feature.detail}</p>
<p style="margin-top:6px;color:${statusColor};font-weight:700">
${status} · ${route.name} · ${proxy.name}
</p>
<div class="tag-row">
${feature.tags.map(tag => `<span class="tag">${tag}</span>`).join("")}
<span class="tag">${feature.dwell} min activity</span>
</div>
`;
} else {
const bench = benchMap[state.selected.id];
const result = routeMetric.benches[bench.id];
$("#selection").innerHTML = `
<div class="selection-kicker">Selected rest area</div>
<h3>${bench.name}</h3>
<p>${bench.detail}</p>
<p style="margin-top:6px;color:${result.reachable ? "#147d68" : "#a76550"};font-weight:700">
${result.reachable ? `Available at ${result.arrival.toFixed(1)} min` : "Outside the selected route plan"}
· ${bench.seats} seats
</p>
<div class="tag-row">
<span class="tag">2.5 min recovery</span>
<span class="tag">${route.name}</span>
</div>
`;
}
}
let metrics = calculateMetrics(proxyMap[state.proxyId]);
function updateAll() {
const proxy = proxyMap[state.proxyId];
const route = routeMap[state.activeRouteId];
metrics = calculateMetrics(proxy);
const routeMetric = metrics[route.id];
document.querySelectorAll(".proxy-button").forEach(button => {
const active = button.dataset.proxy === state.proxyId;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", active);
});
document.querySelectorAll(".compare-card").forEach(button => {
button.classList.toggle("active", button.dataset.proxy === state.proxyId);
});
document.querySelectorAll(".route-row").forEach(button => {
button.classList.toggle("active", button.dataset.route === state.activeRouteId);
});
document.querySelectorAll("[data-role='route-time']").forEach(element => {
const routeId = element.closest(".route-row").dataset.route;
const result = metrics[routeId];
element.textContent = result.suitable ? `${result.total.toFixed(1)} min` : "—";
});
document.querySelectorAll("[data-role='route-status']").forEach(element => {
const routeId = element.closest(".route-row").dataset.route;
const result = metrics[routeId];
element.textContent = result.suitable
? `${result.stops} stops · ${result.restCount} rest`
: "Not eligible";
element.classList.toggle("blocked", !result.suitable);
});
document.querySelectorAll("[data-role='route-meta']").forEach(element => {
const routeId = element.closest(".route-row").dataset.route;
const routeData = routeMap[routeId];
const result = metrics[routeId];
element.textContent = `${routeData.surface} · ${routeData.width}m wide · ${routeData.slope}% slope` +
(result.suitable ? "" : ` · ${result.reason}`);
});
proxies.forEach(proxyItem => {
const proxyMetrics = calculateMetrics(proxyItem);
const eligible = routes
.map(routeData => ({ route: routeData, result: proxyMetrics[routeData.id] }))
.filter(item => item.result.suitable)
.sort((a, b) => b.result.stops - a.result.stops || a.result.total - b.result.total);
const card = document.querySelector(`.compare-card[data-proxy="${proxyItem.id}"]`);
if (!eligible.length) {
card.querySelector("[data-role='best-route']").textContent = "No eligible route";
card.querySelector("[data-role='proxy-result']").textContent = "Review slope or width";
return;
}
const best = eligible[0];
card.querySelector("[data-role='best-route']").textContent = best.route.name;
card.querySelector("[data-role='proxy-result']").textContent =
`${best.result.stops} stops · ${best.result.restCount} rest cues`;
});
$("#summaryTime").textContent = routeMetric.suitable
? `${routeMetric.total.toFixed(1)} min`
: "Excluded";
$("#summaryStops").textContent = `${routeMetric.stops} / ${features.length}`;
$("#summaryRests").textContent = `${routeMetric.restCount} cues`;
$("#budgetValue").textContent = `${state.budget} min`;
$("#budget").style.setProperty("--range-fill", `${((state.budget - 4) / 8) * 100}%`);
$("#stripCaption").textContent = `Best fit at ${state.budget} min`;
updateVisuals(routeMetric);
updateSelection(metrics);
}
state.selected = { type: "feature", id: features[0].id };
updateAll();
const clock = new THREE.Clock();
let agentProgress = 0;
function animate() {
const elapsed = clock.getElapsedTime();
const route = routeMap[state.activeRouteId];
agentProgress = (elapsed * 0.055) % 1;
const scaled = agentProgress * (route.cells.length - 1);
const index = Math.floor(scaled);
const fraction = scaled - index;
const from = gridToWorld(...route.cells[index]);
const to = gridToWorld(...route.cells[Math.min(index + 1, route.cells.length - 1)]);
agent.position.lerpVectors(from, to, fraction);
agent.position.y = 0.25;
agent.rotation.y = Math.atan2(to.x - from.x, to.z - from.z);
agent.visible = route.group.visible;
features.forEach(feature => {
const halo = feature.group.userData.halo;
if (halo?.visible) {
const pulse = 1 + Math.sin(elapsed * 2.4 + feature.position[0]) * 0.035;
halo.scale.set(pulse, 1, pulse);
halo.rotation.y = elapsed * 0.12;
}
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```