Prompt specification
Build or customize the Three.js 3D scene "Rezone one parcel and compare access" 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: Rezone one parcel and compare access
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rezone-one-parcel-and-compare-access-x1312
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows land-use mosaics. Let users replace one fictional parcel's use while tracking walking distance, cultivated area, and connected green space. Report tradeoffs separately without declaring a universal optimal layout. Low-poly.
Working Three.js Starter (rezone-one-parcel-and-compare-access-x1312):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#f4f1e8">
<title>Common Ground — Land-use Mosaic</title>
<style>
:root {
--paper: #f4f1e8;
--panel: #fbf9f3;
--ink: #25332d;
--muted: #6f786f;
--line: #ddd8cb;
--orange: #d76c45;
--orange-soft: #f4ddd0;
--green: #3f7959;
--green-soft: #dce9dc;
--violet: #74639e;
--violet-soft: #e8e1f1;
--shadow: 0 12px 35px rgba(45, 51, 43, 0.12);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body { overflow: hidden; }
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
button:focus-visible,
summary:focus-visible {
outline: 3px solid rgba(116, 99, 158, 0.32);
outline-offset: 2px;
}
.app {
height: 100dvh;
display: grid;
grid-template-rows: 66px minmax(0, 1fr);
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
background: rgba(251, 249, 243, 0.96);
border-bottom: 1px solid var(--line);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
flex: 0 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 3px;
transform: rotate(-2deg);
}
.brand-mark span {
display: block;
border-radius: 3px;
background: var(--green);
}
.brand-mark span:nth-child(2) { background: var(--orange); }
.brand-mark span:nth-child(3) { background: #d5b95e; }
.brand-mark span:nth-child(4) { background: var(--violet); }
.brand-title {
font-weight: 780;
font-size: 16px;
letter-spacing: -0.02em;
white-space: nowrap;
}
.brand-subtitle {
color: var(--muted);
font-size: 12px;
margin-top: 2px;
white-space: nowrap;
}
.header-note {
color: var(--muted);
font-size: 12px;
padding: 7px 11px;
border: 1px solid var(--line);
border-radius: 999px;
white-space: nowrap;
}
main {
display: grid;
grid-template-columns: 365px minmax(0, 1fr);
min-height: 0;
}
aside {
min-height: 0;
overflow-y: auto;
padding: 23px 22px 30px;
background: var(--panel);
border-right: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #c8c2b5 transparent;
}
.eyebrow {
color: var(--orange);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
h1 {
font-family: Georgia, "Times New Roman", serif;
font-weight: 500;
font-size: 31px;
line-height: 1.06;
letter-spacing: -0.035em;
margin: 7px 0 10px;
}
.intro {
color: var(--muted);
font-size: 13px;
line-height: 1.55;
margin: 0 0 18px;
}
.current-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 11px;
margin-bottom: 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: #f7f4ec;
}
.current-copy {
min-width: 0;
font-size: 11px;
color: var(--muted);
}
.current-copy strong {
display: block;
color: var(--ink);
font-size: 13px;
margin-top: 2px;
}
.reset-button {
border: 0;
border-radius: 7px;
padding: 7px 9px;
background: white;
border: 1px solid var(--line);
font-size: 11px;
font-weight: 700;
white-space: nowrap;
}
.reset-button:hover { border-color: var(--orange); }
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 19px 0 9px;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.04em;
}
.section-label span {
color: var(--muted);
font-size: 10px;
font-weight: 600;
letter-spacing: 0;
}
.options {
display: grid;
gap: 8px;
}
.option {
width: 100%;
display: grid;
grid-template-columns: 28px minmax(0, 1fr) auto;
gap: 9px;
align-items: center;
padding: 11px 10px;
text-align: left;
border: 1px solid var(--line);
border-radius: 11px;
background: white;
transition: border-color 150ms, box-shadow 150ms, transform 150ms;
}
.option:hover {
transform: translateY(-1px);
border-color: #bdb5a6;
box-shadow: 0 5px 14px rgba(55, 59, 49, 0.07);
}
.option.active {
border-color: var(--orange);
box-shadow: 0 0 0 2px rgba(215, 108, 69, 0.11);
background: #fffaf4;
}
.option-number {
width: 25px;
height: 25px;
display: grid;
place-items: center;
border-radius: 7px;
background: #eef0e8;
color: #59635b;
font-size: 10px;
font-weight: 800;
}
.option.active .option-number {
background: var(--orange);
color: white;
}
.option-copy { min-width: 0; }
.option-copy strong {
display: block;
font-size: 13px;
line-height: 1.25;
}
.option-copy small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.option-numbers {
display: grid;
grid-template-columns: auto auto;
gap: 4px 9px;
text-align: right;
}
.option-numbers b {
font-size: 11px;
font-weight: 780;
}
.option-numbers small {
grid-row: 2;
color: var(--muted);
font-size: 8px;
white-space: nowrap;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric-card {
min-width: 0;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: white;
}
.metric-card.wide { grid-column: 1 / -1; }
.metric-card .metric-head {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.02em;
}
.metric-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--violet);
}
.metric-dot.green { background: var(--green); }
.metric-dot.orange { background: var(--orange); }
.metric-value {
display: block;
margin-top: 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
line-height: 1;
font-weight: 500;
letter-spacing: -0.04em;
}
.metric-value small {
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
color: var(--muted);
font-size: 11px;
font-weight: 600;
letter-spacing: 0;
}
.metric-detail {
margin: 7px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.comparison {
display: block;
margin-top: 5px;
color: #4f5d55;
font-size: 10px;
font-weight: 700;
}
.tradeoffs {
display: grid;
gap: 9px;
}
.tradeoff {
display: grid;
grid-template-columns: 9px minmax(0, 1fr);
gap: 9px;
align-items: start;
}
.tradeoff-marker {
width: 8px;
height: 8px;
margin-top: 4px;
border-radius: 2px;
background: var(--violet);
}
.tradeoff:nth-child(2) .tradeoff-marker { background: var(--orange); }
.tradeoff:nth-child(3) .tradeoff-marker { background: var(--green); }
.tradeoff:nth-child(4) .tradeoff-marker { background: #c4a850; }
.tradeoff strong {
display: block;
font-size: 11px;
margin-bottom: 2px;
}
.tradeoff p {
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.neutral-note {
margin-top: 16px;
padding: 12px;
border-left: 3px solid var(--violet);
background: var(--violet-soft);
border-radius: 0 8px 8px 0;
color: #504a62;
font-size: 10.5px;
line-height: 1.5;
}
details {
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
summary {
cursor: pointer;
color: #505b54;
font-size: 11px;
font-weight: 800;
}
details p {
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
details ul {
padding-left: 16px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e7e3d8;
isolation: isolate;
}
#viewport canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active { cursor: grabbing; }
.scene-card {
position: absolute;
z-index: 3;
top: 18px;
left: 18px;
max-width: min(310px, calc(100% - 140px));
padding: 12px 14px;
border: 1px solid rgba(255,255,255,0.72);
border-radius: 11px;
background: rgba(251, 249, 243, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
pointer-events: none;
}
.scene-card .eyebrow { font-size: 9px; }
.scene-card strong {
display: block;
margin-top: 4px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.scene-card small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.layer-controls {
position: absolute;
z-index: 4;
top: 18px;
right: 18px;
display: flex;
gap: 6px;
}
.layer-button {
display: flex;
align-items: center;
gap: 7px;
min-height: 34px;
padding: 7px 10px;
border: 1px solid rgba(255,255,255,0.72);
border-radius: 9px;
background: rgba(251, 249, 243, 0.91);
box-shadow: 0 5px 18px rgba(45, 51, 43, 0.09);
font-size: 10px;
font-weight: 750;
backdrop-filter: blur(9px);
}
.legend-line {
width: 18px;
height: 3px;
border-radius: 2px;
background: var(--violet);
}
.legend-line.green { background: var(--green); }
.legend {
position: absolute;
z-index: 3;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
max-width: 330px;
padding: 9px 11px;
border: 1px solid rgba(255,255,255,0.65);
border-radius: 9px;
background: rgba(251, 249, 243, 0.86);
color: #59635c;
font-size: 9px;
backdrop-filter: blur(8px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
background: #cf8d64;
}
.swatch.green { background: #72a376; }
.swatch.purple { background: #7c6aa4; }
.swatch.gold { background: #d5b95e; }
.camera-controls {
position: absolute;
z-index: 4;
right: 18px;
bottom: 18px;
display: flex;
align-items: center;
gap: 6px;
}
.camera-button {
min-width: 34px;
height: 34px;
display: grid;
place-items: center;
padding: 0 9px;
border: 1px solid rgba(255,255,255,0.72);
border-radius: 9px;
background: rgba(251, 249, 243, 0.92);
box-shadow: 0 5px 18px rgba(45, 51, 43, 0.09);
font-size: 11px;
font-weight: 800;
backdrop-filter: blur(9px);
}
.camera-button:hover { background: white; }
.camera-hint {
position: absolute;
z-index: 3;
right: 18px;
bottom: 60px;
padding: 5px 8px;
border-radius: 6px;
background: rgba(251, 249, 243, 0.72);
color: #687168;
font-size: 9px;
pointer-events: none;
}
#labels {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.map-label {
position: absolute;
transform: translate(-50%, -100%);
padding: 5px 7px;
border-radius: 6px;
border: 1px solid rgba(255,255,255,0.7);
background: rgba(250,248,241,0.9);
box-shadow: 0 3px 10px rgba(35,45,38,0.11);
color: #4f5b53;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.025em;
white-space: nowrap;
}
.map-label.parcel {
padding: 7px 10px;
background: var(--orange);
border-color: #f4c2ad;
color: white;
font-size: 10px;
}
@media (max-width: 860px) {
body { overflow: auto; }
.app {
height: auto;
min-height: 100dvh;
grid-template-rows: 60px auto;
}
header { padding: 0 15px; }
.brand-subtitle, .header-note { display: none; }
main {
display: flex;
flex-direction: column;
min-height: 0;
}
#viewport {
order: -1;
width: 100%;
height: 58vh;
min-height: 390px;
flex: 0 0 auto;
}
aside {
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
padding: 21px 17px 35px;
}
.scene-card {
top: 12px;
left: 12px;
max-width: calc(100% - 24px);
}
.layer-controls {
top: auto;
right: 12px;
bottom: 58px;
}
.camera-controls { right: 12px; bottom: 12px; }
.camera-hint { display: none; }
.legend { left: 12px; bottom: 12px; max-width: 235px; }
}
@media (max-width: 430px) {
h1 { font-size: 28px; }
.metric-value { font-size: 24px; }
.option { grid-template-columns: 25px minmax(0, 1fr); }
.option-numbers { display: none; }
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div>
<div class="brand-title">Common Ground</div>
<div class="brand-subtitle">A land-use mosaic sandbox</div>
</div>
</div>
<div class="header-note">Fictional district · Parcel P-07</div>
</header>
<main>
<aside aria-label="Land-use controls and tradeoffs">
<div class="eyebrow">One parcel, several futures</div>
<h1>What should Parcel P-07 become?</h1>
<p class="intro">
Replace the current maker court and inspect how walking, food growing,
and connected open space respond. The measures are reported separately.
</p>
<div class="current-row">
<div class="current-copy">
Existing use
<strong id="currentUse">Maker court</strong>
</div>
<button class="reset-button" id="resetButton" type="button">Reset</button>
</div>
<div class="section-label">
Try a replacement
<span>Select to preview</span>
</div>
<div class="options" id="options"></div>
<div class="section-label">
Scenario measures
<span>Compared with current use</span>
</div>
<div class="metric-grid" id="metrics"></div>
<div class="section-label">
Tradeoffs by priority
<span>No overall ranking</span>
</div>
<div class="tradeoffs" id="tradeoffs"></div>
<div class="neutral-note">
A stronger result in one measure can weaken another. This model does not
declare a universal optimal layout; it exposes the consequences of each choice.
</div>
<details>
<summary>How the model counts</summary>
<ul>
<li>
<strong>Walking:</strong> a shortest-path loop from P-07 to the market,
school, clinic, and station, returning to the parcel. Time assumes
75 meters per minute.
</li>
<li>
<strong>Cultivated area:</strong> modeled edible beds plus managed
orchard floor.
</li>
<li>
<strong>Connected green:</strong> public green space reachable through
the marked pedestrian-green links. In the food grove, green and
cultivated areas can overlap.
</li>
<li>The geometry is schematic and intended for comparison, not parcel-level design.</li>
</ul>
</details>
</aside>
<section id="viewport" aria-label="Interactive low-poly land-use mosaic">
<div class="scene-card">
<div class="eyebrow" id="sceneEyebrow">Existing parcel</div>
<strong id="sceneTitle">Maker court</strong>
<small id="sceneSubtitle">2,900 m² fictional parcel · 2.0 ha neighborhood</small>
</div>
<div class="layer-controls" aria-label="Map layers">
<button class="layer-button" id="routeToggle" type="button" aria-pressed="true">
<span class="legend-line"></span>
Daily loop
</button>
<button class="layer-button" id="greenToggle" type="button" aria-pressed="true">
<span class="legend-line green"></span>
Green links
</button>
</div>
<div id="labels" aria-hidden="true"></div>
<div class="legend" aria-hidden="true">
<span class="legend-item"><span class="swatch"></span>Built use</span>
<span class="legend-item"><span class="swatch green"></span>Open space</span>
<span class="legend-item"><span class="swatch purple"></span>Daily walking loop</span>
<span class="legend-item"><span class="swatch gold"></span>Community destination</span>
</div>
<div class="camera-hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div class="camera-controls" aria-label="Camera controls">
<button class="camera-button" id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button class="camera-button" id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button class="camera-button" id="planView" type="button">Plan</button>
<button class="camera-button" id="resetView" type="button">Reset</button>
</div>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scenario definitions
// -------------------------------------------------------------------------
const NEIGHBORHOOD_GREEN = 5020;
const OPTIONS = {
maker: {
title: "Maker court",
subtitle: "Workshops, small yards, shared beds",
cultivated: 320,
green: 540,
publicShare: 0.45,
access: { x: -29, z: 3 },
accessTo: "w",
trade: {
access: "The west threshold keeps the daily loop around {walk} m, with most travel following existing sidewalk links.",
food: "Small shared beds provide {cult} m² of cultivation while workshop floors retain much of the parcel.",
green: "About {greenParcel} m² of the parcel’s open ground joins the public green network; other yard areas remain shared but not publicly continuous.",
balance: "The parcel supports making and gathering, but housing, production, and public open space each receive only part of the ground."
}
},
homes: {
title: "Courtyard homes",
subtitle: "Compact homes around a semi-private court",
cultivated: 140,
green: 420,
publicShare: 0.25,
access: { x: -2, z: -24 },
accessTo: "n",
trade: {
access: "A north entrance shifts the route to {walk} m and places daily errands on the central north sidewalk.",
food: "A few shared beds retain {cult} m² of cultivation, but edible growing is secondary to housing.",
green: "The courtyard remains semi-private, so only about {greenParcel} m² is counted as publicly connected green.",
balance: "More residential floor area is possible, while public gathering space and food-growing capacity become more limited."
}
},
garden: {
title: "Community garden",
subtitle: "Public beds, tool shed, shared growing",
cultivated: 1380,
green: 680,
publicShare: 0.85,
access: { x: 27, z: 1 },
accessTo: "e",
trade: {
access: "The east threshold creates a {walk} m loop and short direct links to the market and station side of the district.",
food: "Thirty raised beds provide {cult} m² of clearly cultivated area, concentrating production in a public place.",
green: "Perimeter planting adds about {greenParcel} m² of connected green, but the active growing footprint is extensive.",
balance: "Food growing and public activity are prominent; indoor floor area and uninterrupted lawn are comparatively limited."
}
},
grove: {
title: "Food grove",
subtitle: "Managed orchard, shade, habitat planting",
cultivated: 1560,
green: 2100,
publicShare: 1,
access: { x: 4, z: 24 },
accessTo: "s",
trade: {
access: "A south threshold produces a {walk} m loop, with a longer northward leg to the market and school.",
food: "The managed orchard floor provides {cult} m² of food-growing area, with trees and understory sharing the same footprint.",
green: "A continuous planted interior contributes roughly {greenParcel} m² of connected green and substantial shade.",
balance: "Cultivation, habitat, and shade overlap, while built floor area and a simple, highly controlled bed layout are reduced."
}
},
commons: {
title: "Civic commons",
subtitle: "Open lawn, play, events, shade trees",
cultivated: 0,
green: 2560,
publicShare: 1,
access: { x: 0, z: 24 },
accessTo: "s",
trade: {
access: "The south entrance yields a {walk} m loop and a direct connection to the southern neighborhood path.",
food: "No cultivated beds are included in this scenario, so dedicated food production falls to zero.",
green: "About {greenParcel} m² of the parcel remains continuous public green and links the surrounding green spaces.",
balance: "The parcel becomes flexible public space for play and events, with less dedicated cultivation or enclosed floor area."
}
}
};
const OPTION_ORDER = ["homes", "garden", "grove", "commons"];
// -------------------------------------------------------------------------
// Pedestrian graph and shortest-path calculations
// -------------------------------------------------------------------------
const NODES = {
nw: { x: -42, z: -32 },
n: { x: 0, z: -32 },
ne: { x: 42, z: -32 },
w: { x: -42, z: 0 },
e: { x: 42, z: 0 },
sw: { x: -42, z: 32 },
s: { x: 0, z: 32 },
se: { x: 42, z: 32 },
school: { x: -54, z: -39 },
market: { x: 54, z: -39 },
clinic: { x: -54, z: 39 },
station: { x: 54, z: 39 }
};
const FIXED_EDGES = [
["nw", "n"], ["n", "ne"],
["nw", "w"], ["w", "sw"],
["ne", "e"], ["e", "se"],
["sw", "s"], ["s", "se"],
["nw", "school"], ["ne", "market"],
["sw", "clinic"], ["se", "station"]
];
const BASE_ROUTE_IDS = ["market", "school", "clinic", "station"];
function distanceBetween(a, b) {
return Math.hypot(a.x - b.x, a.z - b.z);
}
function buildAdjacency(option) {
const adjacency = new Map();
for (const id of Object.keys(NODES)) adjacency.set(id, []);
adjacency.set("access", []);
for (const [a, b] of FIXED_EDGES) {
const length = distanceBetween(NODES[a], NODES[b]);
adjacency.get(a).push({ id: b, length });
adjacency.get(b).push({ id: a, length });
}
const accessNode = { x: option.access.x, z: option.access.z };
const accessLength = distanceBetween(accessNode, NODES[option.accessTo]);
adjacency.get("access").push({ id: option.accessTo, length: accessLength });
return adjacency;
}
function shortestPath(adjacency, startId, endId) {
const distances = new Map();
const previous = new Map();
const unvisited = new Set();
for (const id of adjacency.keys()) {
distances.set(id, Infinity);
unvisited.add(id);
}
distances.set(startId, 0);
while (unvisited.size) {
let current = null;
let bestDistance = Infinity;
for (const id of unvisited) {
const d = distances.get(id);
if (d < bestDistance) {
bestDistance = d;
current = id;
}
}
if (current === null) break;
unvisited.delete(current);
if (current === endId) break;
for (const edge of adjacency.get(current)) {
if (!unvisited.has(edge.id)) continue;
const candidate = bestDistance + edge.length;
if (candidate < distances.get(edge.id)) {
distances.set(edge.id, candidate);
previous.set(edge.id, current);
}
}
}
if (!Number.isFinite(distances.get(endId))) return [];
const path = [endId];
let cursor = endId;
while (cursor !== startId) {
cursor = previous.get(cursor);
if (!cursor) return [];
path.unshift(cursor);
}
return path;
}
function calculateRoute(option) {
const adjacency = buildAdjacency(option);
const accessNode = { x: option.access.x, z: option.access.z };
const ids = ["access", ...BASE_ROUTE_IDS, "access"];
const paths = [];
let total = 0;
for (let i = 0; i < ids.length - 1; i++) {
const pathIds = shortestPath(adjacency, ids[i], ids[i + 1]);
const points = pathIds.map((id, pointIndex) => {
if (id === "access") return new THREE.Vector3(accessNode.x, 0.39, accessNode.z);
const node = NODES[id];
return new THREE.Vector3(node.x, 0.39, node.z);
});
for (let p = 1; p < points.length; p++) {
total += Math.hypot(points[p].x - points[p - 1].x, points[p].z - points[p - 1].z);
}
paths.push(points);
}
return { paths, total: Math.round(total) };
}
const METRICS = {};
for (const [id, option] of Object.entries(OPTIONS)) {
const route = calculateRoute(option);
METRICS[id] = {
walking: route.total,
minutes: Math.max(1, Math.round(route.total / 75)),
cultivated: option.cultivated,
connected: NEIGHBORHOOD_GREEN + Math.round(option.green * option.publicShare / 10) * 10,
greenParcel: Math.round(option.green * option.publicShare / 10) * 10
};
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7e3d8);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.domElement.setAttribute("role", "img");
renderer.domElement.setAttribute("aria-label", "Low-poly neighborhood with selectable parcel P-07");
viewport.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-100, 100, 100, -100, 0.1, 500);
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
theta: 0.76,
phi: 0.88,
radius: 165,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xfff9e8, 0x7d8b78, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d6, 2.5);
sun.position.set(-70, 105, 45);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -110;
sun.shadow.camera.right = 110;
sun.shadow.camera.top = 100;
sun.shadow.camera.bottom = -100;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 260;
sun.shadow.bias = -0.0005;
scene.add(sun);
const staticGroup = new THREE.Group();
const parcelGroup = new THREE.Group();
const greenNetworkGroup = new THREE.Group();
const routeGroup = new THREE.Group();
scene.add(staticGroup, parcelGroup, greenNetworkGroup, routeGroup);
const COLORS = {
ground: 0xd9d2c1,
road: 0x747a77,
sidewalk: 0xc9c5b9,
soil: 0x8b6746,
bed: 0x9a7049,
grass: 0x78a879,
grassLight: 0x8fb785,
grassDark: 0x5f8c68,
timber: 0xa9794f,
wall1: 0xd6b28d,
wall2: 0xc5c8b8,
wall3: 0xb9c7c3,
wall4: 0xc9b0a1,
roof1: 0x8d6a58,
roof2: 0x697a78,
roof3: 0xa26855,
window: 0x506363,
trunk: 0x75553e
};
function material(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true,
...extra
});
}
function basicMaterial(color, extra = {}) {
return new THREE.MeshBasicMaterial({ color, ...extra });
}
function box(parent, width, height, depth, x, z, color, y = height / 2) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
color?.isMaterial ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radiusTop, radiusBottom, height, sides, x, z, color, y = height / 2) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, sides),
color?.isMaterial ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roofGeometry(width, depth, rise) {
const x = width / 2;
const z = depth / 2;
const vertices = [
-x, 0, -z, x, 0, -z, 0, rise, 0,
x, 0, -z, x, 0, z, 0, rise, 0,
x, 0, z, -x, 0, z, 0, rise, 0,
-x, 0, z, -x, 0, -z, 0, rise, 0
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
geometry.computeVertexNormals();
return geometry;
}
function building(parent, x, z, width, depth, height, wallColor, roofColor, windowCount = 3) {
const group = new THREE.Group();
parent.add(group);
box(group, width, height, depth, x, z, wallColor, height / 2 + 0.12);
const roof = new THREE.Mesh(
roofGeometry(width + 1.2, depth + 1.2, 3.2),
material(roofColor)
);
roof.position.set(x, height + 0.12, z);
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
const windowWidth = Math.max(1, Math.min(2.2, width / (windowCount * 1.8)));
const spacing = width / (windowCount + 1);
for (let i = 0; i < windowCount; i++) {
box(
group,
windowWidth,
1.25,
0.12,
x - width / 2 + spacing * (i + 1),
z + depth / 2 + 0.03,
COLORS.window,
height * 0.57
);
}
box(
group,
Math.min(2.2, width * 0.18),
Math.min(3, height * 0.55),
0.14,
x,
z + depth / 2 + 0.05,
COLORS.roof2,
Math.min(3, height * 0.55) / 2
);
return group;
}
function tree(parent, x, z, scale = 1, crownColor = COLORS.grassDark) {
const group = new THREE.Group();
parent.add(group);
cylinder(group, 0.38 * scale, 0.5 * scale, 2.2 * scale, 6, x, z, COLORS.trunk, 1.1 * scale);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(2.25 * scale, 4.8 * scale, 6),
material(crownColor)
);
crown.position.set(x, 3.55 * scale, z);
crown.rotation.y = (x * 0.13 + z * 0.07) % Math.PI;
crown.castShadow = true;
crown.receiveShadow = true;
group.add(crown);
return group;
}
function fruitTree(parent, x, z, scale = 1) {
const group = tree(parent, x, z, scale, 0x65875f);
const fruitMaterial = material(0xc9804f);
for (let i = 0; i < 3; i++) {
const fruit = new THREE.Mesh(new THREE.IcosahedronGeometry(0.22 * scale, 0), fruitMaterial);
const angle = i * 2.1;
fruit.position.set(
x + Math.cos(angle) * 1.45 * scale,
2.9 * scale + i * 0.32 * scale,
z + Math.sin(angle) * 1.45 * scale
);
fruit.castShadow = true;
group.add(fruit);
}
return group;
}
function patchRect(parent, x, z, width, depth, color, y = 0.19) {
const patch = box(parent, width, 0.06, depth, x, z, color, y);
patch.castShadow = false;
return patch;
}
function patchCircle(parent, x, z, radius, color, y = 0.19, segments = 14) {
const patch = new THREE.Mesh(
new THREE.CircleGeometry(radius, segments),
material(color)
);
patch.rotation.x = -Math.PI / 2;
patch.position.set(x, y, z);
patch.receiveShadow = true;
parent.add(patch);
return patch;
}
function raisedBed(parent, x, z, width, depth) {
const group = new THREE.Group();
parent.add(group);
box(group, width, 0.28, depth, x, z, COLORS.soil, 0.31);
box(group, width + 0.45, 0.38, 0.28, x, z - depth / 2, COLORS.timber, 0.31);
box(group, width + 0.45, 0.38, 0.28, x, z + depth / 2, COLORS.timber, 0.31);
box(group, 0.28, 0.38, depth + 0.45, x - width / 2, z, COLORS.timber, 0.31);
box(group, 0.28, 0.38, depth + 0.45, x + width / 2, z, COLORS.timber, 0.31);
const rowCount = Math.max(1, Math.floor(depth / 2.4));
for (let i = 0; i < rowCount; i++) {
const row = box(
group,
Math.max(0.5, width - 1.3),
0.26,
0.48,
x,
z - depth / 2 + 1.4 + i * 2.1,
0x5f8c58,
0.58
);
row.castShadow = false;
}
}
function stripBetween(parent, a, b, width, color, y = 0.23, opacity = 1) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.045, length),
basicMaterial(color, { transparent: opacity < 1, opacity })
);
mesh.position.set((a.x + b.x) / 2, y, (a.z + b.z) / 2);
mesh.rotation.y = Math.atan2(dx, dz);
parent.add(mesh);
return mesh;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material) ? object.material : [object.material];
materials.forEach((mat) => mat.dispose());
}
});
}
}
// Static neighborhood
function buildStaticNeighborhood() {
box(staticGroup, 190, 1, 160, 0, 0, COLORS.ground, -0.5);
// Roads
box(staticGroup, 166, 0.12, 9, 0, -39, COLORS.road, 0.06);
box(staticGroup, 166, 0.12, 9, 0, 39, COLORS.road, 0.06);
box(staticGroup, 9, 0.12, 88, -47, 0, COLORS.road, 0.06);
box(staticGroup, 9, 0.12, 88, 47, 0, COLORS.road, 0.06);
// Sidewalks
for (const z of [-32.7, -45.3, 32.7, 45.3]) {
box(staticGroup, 164, 0.10, 2.2, 0, z, COLORS.sidewalk, 0.12);
}
for (const x of [-40.5, -53.5, 40.5, 53.5]) {
box(staticGroup, 2.2, 0.10, 85, x, 0, COLORS.sidewalk, 0.12);
}
// Road center dashes
for (let x = -74; x <= 74; x += 11) {
if (Math.abs(Math.abs(x) - 47) < 9) continue;
box(staticGroup, 3.5, 0.025, 0.22, x, -39, 0xd3b86b, 0.14);
box(staticGroup, 3.5, 0.025, 0.22, x, 39, 0xd3b86b, 0.14);
}
for (let z = -24; z <= 24; z += 11) {
if (Math.abs(Math.abs(z) - 39) < 9) continue;
box(staticGroup, 0.22, 0.025, 3.5, -47, z, 0xd3b86b, 0.14);
box(staticGroup, 0.22, 0.025, 3.5, 47, z, 0xd3b86b, 0.14);
}
// Crosswalks
for (const x of [-47, 47]) {
for (const z of [-39, 39]) {
for (let i = 0; i < 5; i++) {
box(staticGroup, 5.4, 0.035, 0.65, x, z - 3 + i * 1.45, 0xd9d6cb, 0.16);
}
}
}
// Parcel slab and highlighted boundary
box(staticGroup, 58, 0.18, 50, -3, 0, 0xc5b99f, 0.14);
const boundaryPoints = [
new THREE.Vector3(-32, 0.39, -25),
new THREE.Vector3(26, 0.39, -25),
new THREE.Vector3(26, 0.39, 25),
new THREE.Vector3(-32, 0.39, 25)
];
const boundary = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(boundaryPoints),
new THREE.LineBasicMaterial({ color: 0xd76c45 })
);
staticGroup.add(boundary);
for (const x of [-32, 26]) {
for (const z of [-25, 25]) {
cylinder(staticGroup, 0.32, 0.38, 1.1, 6, x, z, 0xd76c45, 0.72);
}
}
// Destination buildings
building(staticGroup, 61, -56, 24, 18, 8.5, 0xc8b180, 0x9a6e4e, 4);
building(staticGroup, -64, -55, 29, 18, 6.8, 0xb9c7c3, 0x718482, 5);
building(staticGroup, -61, 55, 22, 16, 8, 0xd3c4b8, 0x8e7d76, 3);
building(staticGroup, 62, 54, 26, 15, 7, 0xc4c9bc, 0x70807b, 4);
// Market canopy
box(staticGroup, 15, 0.35, 7, 60, -43, 0xd76c45, 4.4);
for (const x of [54, 60, 66]) {
cylinder(staticGroup, 0.25, 0.25, 4.2, 6, x, -43, 0x7c6a55, 2.1);
}
// Other neighborhood buildings
building(staticGroup, -71, -14, 17, 14, 6, COLORS.wall1, COLORS.roof1, 3);
building(staticGroup, -72, 15, 18, 15, 7, COLORS.wall4, COLORS.roof3, 3);
building(staticGroup, -20, -61, 18, 13, 6.5, COLORS.wall2, COLORS.roof2, 3);
building(staticGroup, 22, -62, 18, 13, 6, COLORS.wall1, COLORS.roof1, 3);
building(staticGroup, -22, 61, 17, 13, 6, COLORS.wall2, COLORS.roof2, 3);
building(staticGroup, 72, 0, 16, 20, 7, COLORS.wall4, COLORS.roof3, 3);
// Static connected green spaces
patchCircle(staticGroup, -61, 0, 9, COLORS.grass, 0.19);
patchRect(staticGroup, -65, -39, 22, 11, COLORS.grassLight, 0.19);
patchRect(staticGroup, 61, -39, 19, 10, COLORS.grassLight, 0.19);
patchRect(staticGroup, 10, 52, 29, 16, COLORS.grassDark, 0.19);
// Paths and green links
const green = 0x3f7959;
const corridors = [
[{ x: -3, z: 0 }, { x: -42, z: 0 }],
[{ x: -42, z: 0 }, { x: -61, z: 0 }],
[{ x: -3, z: 0 }, { x: 0, z: -32 }],
[{ x: 0, z: -32 }, { x: -64, z: -32 }],
[{ x: 0, z: -32 }, { x: 61, z: -32 }],
[{ x: -3, z: 0 }, { x: 0, z: 32 }],
[{ x: 0, z: 32 }, { x: 10, z: 52 }],
[{ x: 0, z: 32 }, { x: 61, z: 32 }]
];
for (const [a, b] of corridors) {
stripBetween(greenNetworkGroup, a, b, 3.2, green, 0.245, 0.42);
}
// Pocket park trees and benches
[
[-66, -5], [-66, 5], [-57, -5], [-56, 5],
[-62, 0], [-60, -9], [-69, 8]
].forEach(([x, z]) => tree(staticGroup, x, z, 0.9));
for (const [x, z] of [[-57, 0], [-65, 0]]) {
box(staticGroup, 3, 0.3, 0.8, x, z, 0x9a7049, 0.55);
box(staticGroup, 0.5, 1.1, 0.5, x - 1, z, 0x7c6a55, 0.55);
}
// South commons
tree(staticGroup, 0, 50, 1.1);
tree(staticGroup, 20, 55, 1.2);
tree(staticGroup, 17, 47, 0.9);
// Small street trees
const streetTrees = [
[-36, -27], [-20, -27], [17, -27], [33, -27],
[-36, 27], [-18, 27], [18, 27], [34, 27],
[-35, -18], [-35, 17], [35, -18], [35, 17]
];
streetTrees.forEach(([x, z]) => tree(staticGroup, x, z, 0.72, 0x6f956c));
// Distant texture: small plots
for (let i = 0; i < 16; i++) {
const x = -80 + (i % 4) * 7;
const z = 67 + Math.floor(i / 4) * 4;
patchRect(staticGroup, x, z, 4.5, 2.5, i % 2 ? 0x9ba579 : 0xb2a17f, 0.17);
}
}
buildStaticNeighborhood();
// Parcel option geometry
function buildParcel(optionId) {
clearGroup(parcelGroup);
const option = OPTIONS[optionId];
const group = new THREE.Group();
parcelGroup.add(group);
if (optionId === "maker") {
building(group, -18, -13, 20, 13, 5.8, 0xc5a47f, 0x876555, 4);
building(group, 8, -14, 18, 12, 5.2, 0xb7c1b6, 0x657775, 3);
building(group, -18, 12, 18, 11, 5, 0xc9b29e, 0x8b6957, 3);
patchRect(group, 10, 10, 25, 19, 0x7fa376, 0.23);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 5; col++) {
raisedBed(group, 3 + col * 5, 6 + row * 10, 4, 8);
}
}
tree(group, 22, -4, 0.7);
tree(group, 21, 19, 0.75);
}
if (optionId === "homes") {
building(group, -21, -14, 16, 12, 7.2, 0xd2b38f, 0x89695a, 3);
building(group, 12, -14, 16, 12, 6.7, 0xc7c9bc, 0x6c7d7a, 3);
building(group, -21, 13, 16, 12, 6.3, 0xc9b0a1, 0x9b6c57, 3);
building(group, 12, 13, 16, 12, 7, 0xd0c7b2, 0x7a6a61, 3);
patchRect(group, -3, 0, 36, 21, 0x82a87a, 0.23);
stripBetween(group, { x: -21, z: 0 }, { x: 15, z: 0 }, 2.1, 0xc9b99c, 0.27);
for (let i = 0; i < 7; i++) {
raisedBed(group, -15 + i * 4, 5, 4, 5);
}
tree(group, 19, 3, 0.75);
tree(group, -24, 2, 0.65);
}
if (optionId === "garden") {
patchRect(group, -3, 0, 55, 47, 0x78a171, 0.22);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 6; col++) {
raisedBed(group, -25 + col * 8.8, -18.4 + row * 9.2, 7.2, 6.4);
}
}
building(group, -22, -21, 10, 6, 3.8, 0xb18a64, 0x7e674f, 2);
// Tool table and water tank
box(group, 3.5, 0.35, 1.8, 21, 19, 0x9a7049, 0.9);
cylinder(group, 1.15, 1.15, 2.3, 8, 24, -17, 0x7e9b91, 1.3);
tree(group, 23, -19, 0.65);
tree(group, -26, 19, 0.65);
}
if (optionId === "grove") {
patchRect(group, -3, 0, 54, 44, 0x769d70, 0.22);
patchRect(group, -3, 0, 52, 30, 0x879264, 0.235);
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 5; col++) {
fruitTree(group, -23 + col * 10, -13.5 + row * 9, 0.95);
}
}
// Understory bands and a central gathering path
for (const z of [-19, -10, -1, 8]) {
patchRect(group, -3, z, 51, 1.3, 0x587d54, 0.28);
}
stripBetween(group, { x: -3, z: -24 }, { x: -3, z: 24 }, 2.2, 0xc3b291, 0.3);
box(group, 5, 0.35, 2, -3, 17, 0x9a7049, 0.75);
cylinder(group, 0.75, 0.75, 1.8, 8, -24, 20, 0x7e9b91, 1.05);
}
if (optionId === "commons") {
patchRect(group, -3, 0, 54, 46, 0x80aa76, 0.22);
// Crossing paths
stripBetween(group, { x: -30, z: 0 }, { x: 24, z: 0 }, 3, 0xc8b797, 0.26);
stripBetween(group, { x: -3, z: -24 }, { x: -3, z: 24 }, 3, 0xc8b797, 0.26);
// Play area
patchCircle(group, 14, -12, 8, 0xd8b968, 0.29, 10);
box(group, 6, 0.5, 2.5, 13, -12, 0x6f8e91, 0.65);
const slide = box(group, 3, 0.35, 7, 16, -10, 0xd76c45, 1.4);
slide.rotation.x = -0.38;
// Benches
for (const [x, z] of [[-15, 8], [-8, 8], [7, 10], [14, 10]]) {
box(group, 3, 0.3, 0.8, x, z, 0x9a7049, 0.58);
box(group, 0.45, 1, 0.45, x - 1, z, 0x7d6d59, 0.5);
box(group, 0.45, 1, 0.45, x + 1, z, 0x7d6d59, 0.5);
}
tree(group, -23, -17, 1.0);
tree(group, -23, 17, 1.0);
tree(group, 19, 18, 1.0);
tree(group, 19, -20, 0.85);
}
// Parcel threshold marker
const threshold = new THREE.Mesh(
new THREE.BoxGeometry(3.2, 0.24, 1.5),
material(0xd76c45)
);
threshold.position.set(option.access.x, 0.45, option.access.z);
threshold.castShadow = true;
group.add(threshold);
}
function updateRoute(optionId) {
clearGroup(routeGroup);
const option = OPTIONS[optionId];
const route = calculateRoute(option);
const allPoints = [];
for (const path of route.paths) {
for (const point of path) {
const last = allPoints[allPoints.length - 1];
if (!last || last.distanceToSquared(point) > 0.01) allPoints.push(point);
}
}
if (allPoints.length > 1) {
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(allPoints),
new THREE.LineDashedMaterial({
color: 0x74639e,
dashSize: 2.6,
gapSize: 1.25,
transparent: true,
opacity: 0.92
})
);
line.computeLineDistances();
line.renderOrder = 5;
routeGroup.add(line);
}
const marker = new THREE.Mesh(
new THREE.TorusGeometry(1.25, 0.22, 5, 12),
material(0x74639e)
);
marker.rotation.x = Math.PI / 2;
marker.position.set(option.access.x, 0.55, option.access.z);
marker.castShadow = true;
routeGroup.add(marker);
}
// -------------------------------------------------------------------------
// Labels
// -------------------------------------------------------------------------
const labelDefinitions = [
{ id: "parcel", text: "P-07 · SCENARIO", position: new THREE.Vector3(-3, 7, 23), parcel: true },
{ id: "market", text: "MARKET", position: new THREE.Vector3(61, 12, -56) },
{ id: "school", text: "SCHOOL", position: new THREE.Vector3(-64, 10, -55) },
{ id: "clinic", text: "CLINIC", position: new THREE.Vector3(-61, 11, 55) },
{ id: "station", text: "STATION", position: new THREE.Vector3(62, 10, 54) }
];
const labels = labelDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = `map-label${definition.parcel ? " parcel" : ""}`;
element.textContent = definition.text;
document.getElementById("labels").appendChild(element);
return { ...definition, element };
});
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
const optionsElement = document.getElementById("options");
const metricsElement = document.getElementById("metrics");
const tradeoffsElement = document.getElementById("tradeoffs");
const currentUseElement = document.getElementById("currentUse");
const sceneEyebrowElement = document.getElementById("sceneEyebrow");
const sceneTitleElement = document.getElementById("sceneTitle");
const parcelLabel = labels.find((label) => label.parcel);
let selectedOption = "maker";
function number(value) {
return new Intl.NumberFormat("en-US").format(value);
}
function comparison(value, baseline, unit) {
const difference = value - baseline;
if (difference === 0) return `Same as current use`;
const amount = number(Math.abs(difference));
return difference < 0
? `${amount} ${unit} less than current use`
: `${amount} ${unit} more than current use`;
}
OPTION_ORDER.forEach((id, index) => {
const option = OPTIONS[id];
const metrics = METRICS[id];
const button = document.createElement("button");
button.type = "button";
button.className = "option";
button.dataset.option = id;
button.setAttribute("aria-pressed", "false");
button.innerHTML = `
<span class="option-number">${String(index + 1).padStart(2, "0")}</span>
<span class="option-copy">
<strong>${option.title}</strong>
<small>${option.subtitle}</small>
</span>
<span class="option-numbers">
<b>${number(metrics.cultivated)}</b>
<small>m² grown</small>
<b>${number(metrics.connected)}</b>
<small>m² green</small>
</span>
`;
button.addEventListener("click", () => selectOption(id));
optionsElement.appendChild(button);
});
function renderMetrics(optionId) {
const metrics = METRICS[optionId];
const base = METRICS.maker;
metricsElement.innerHTML = `
<article class="metric-card wide">
<div class="metric-head"><span class="metric-dot"></span>Daily walking loop</div>
<span class="metric-value">${number(metrics.walking)} <small>m</small></span>
<p class="metric-detail">
${metrics.minutes} min at 75 m/min · parcel → market → school → clinic → station → parcel
</p>
<span class="comparison">${comparison(metrics.walking, base.walking, "m")}</span>
</article>
<article class="metric-card">
<div class="metric-head"><span class="metric-dot orange"></span>Cultivated area</div>
<span class="metric-value">${number(metrics.cultivated)} <small>m²</small></span>
<p class="metric-detail">Beds and managed orchard floor</p>
<span class="comparison">${comparison(metrics.cultivated, base.cultivated, "m²")}</span>
</article>
<article class="metric-card">
<div class="metric-head"><span class="metric-dot green"></span>Connected green</div>
<span class="metric-value">${number(metrics.connected)} <small>m²</small></span>
<p class="metric-detail">Publicly reachable open space</p>
<span class="comparison">${comparison(metrics.connected, base.connected, "m²")}</span>
</article>
`;
}
function renderTradeoffs(optionId) {
const option = OPTIONS[optionId];
const metrics = METRICS[optionId];
const replacements = {
walk: `${number(metrics.walking)} m`,
cult: `${number(metrics.cultivated)}`,
greenParcel: `${number(metrics.greenParcel)}`
};
const content = [
["Daily access", option.trade.access],
["Food growing", option.trade.food],
["Connected green", option.trade.green],
["Built form and public use", option.trade.balance]
];
tradeoffsElement.innerHTML = content.map(([title, text]) => `
<div class="tradeoff">
<span class="tradeoff-marker"></span>
<div>
<strong>${title}</strong>
<p>${text.replace(/\{(\w+)\}/g, (_, key) => replacements[key])}</p>
</div>
</div>
`).join("");
}
function selectOption(optionId) {
selectedOption = optionId;
const option = OPTIONS[optionId];
document.querySelectorAll(".option").forEach((button) => {
const active = button.dataset.option === optionId;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
buildParcel(optionId);
updateRoute(optionId);
renderMetrics(optionId);
renderTradeoffs(optionId);
currentUseElement.textContent = optionId === "maker" ? "Maker court" : `Preview · ${option.title}`;
sceneEyebrowElement.textContent = optionId === "maker" ? "Existing parcel" : "Replacement preview";
sceneTitleElement.textContent = option.title;
parcelLabel.element.textContent = `P-07 · ${option.title.toUpperCase()}`;
}
document.getElementById("resetButton").addEventListener("click", () => selectOption("maker"));
// Layer toggles
document.getElementById("routeToggle").addEventListener("click", (event) => {
routeGroup.visible = !routeGroup.visible;
event.currentTarget.setAttribute("aria-pressed", String(routeGroup.visible));
});
document.getElementById("greenToggle").addEventListener("click", (event) => {
greenNetworkGroup.visible = !greenNetworkGroup.visible;
event.currentTarget.setAttribute("aria-pressed", String(greenNetworkGroup.visible));
});
// -------------------------------------------------------------------------
// Camera controls implemented directly, without add-ons
// -------------------------------------------------------------------------
let viewportWidth = 1;
let viewportHeight = 1;
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const offset = new THREE.Vector3(
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.radius * Math.cos(cameraState.phi),
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
viewportWidth = Math.max(1, viewport.clientWidth);
viewportHeight = Math.max(1, viewport.clientHeight);
renderer.setSize(viewportWidth, viewportHeight, false);
const aspect = viewportWidth / viewportHeight;
const verticalSpan = Math.max(150, 205 / aspect);
camera.left = -verticalSpan * aspect / 2;
camera.right = verticalSpan * aspect / 2;
camera.top = verticalSpan / 2;
camera.bottom = -verticalSpan / 2;
updateCamera();
}
new ResizeObserver(resize).observe(viewport);
const pointer = {
active: false,
id: null,
startX: 0,
startY: 0,
previousX: 0,
previousY: 0,
pan: false
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
pointer.previousX = event.clientX;
pointer.previousY = event.clientY;
pointer.pan = event.shiftKey || event.button === 2;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.previousX;
const dy = event.clientY - pointer.previousY;
pointer.previousX = event.clientX;
pointer.previousY = event.clientY;
if (pointer.pan) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, new THREE.Vector3(0, 1, 0));
const scale = 0.0018 * (160 / cameraState.zoom);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - dy * 0.005, 0.22, 1.42);
}
updateCamera();
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.4
);
updateCamera();
}, { passive: false });
document.getElementById("zoomIn").addEventListener("click", () => {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom * 1.16, 0.65, 2.4);
updateCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom / 1.16, 0.65, 2.4);
updateCamera();
});
document.getElementById("planView").addEventListener("click", () => {
cameraState.phi = 0.18;
cameraState.theta = 0;
cameraState.zoom = 0.98;
updateCamera();
});
document.getElementById("resetView").addEventListener("click", () => {
cameraState.target.set(0, 0, 0);
cameraState.theta = 0.76;
cameraState.phi = 0.88;
cameraState.radius = 165;
cameraState.zoom = 1;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (["INPUT", "TEXTAREA", "SELECT", "BUTTON"].includes(document.activeElement?.tagName)) return;
const key = event.key.toLowerCase();
if (key === "arrowleft") cameraState.theta += 0.12;
else if (key === "arrowright") cameraState.theta -= 0.12;
else if (key === "arrowup") cameraState.phi = Math.max(0.22, cameraState.phi - 0.08);
else if (key === "arrowdown") cameraState.phi = Math.min(1.42, cameraState.phi + 0.08);
else if (key === "+" || key === "=") cameraState.zoom = Math.min(2.4, cameraState.zoom * 1.1);
else if (key === "-") cameraState.zoom = Math.max(0.65, cameraState.zoom / 1.1);
else if (key === "r") {
cameraState.target.set(0, 0, 0);
cameraState.theta = 0.76;
cameraState.phi = 0.88;
cameraState.zoom = 1;
} else return;
event.preventDefault();
updateCamera();
});
// Initial scenario
selectOption("maker");
resize();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```