Prompt specification
Build or customize the Three.js 3D scene "Park or Parking Lot Planning Table" 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: Park or Parking Lot Planning Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/park-or-parking-lot-planning-table-x3175
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing opportunity costs of mutually exclusive choices. Build a fictional block with one vacant parcel, surrounding homes, and two removable land-use models. Display the facilities gained and displaced under each choice. Voxel style.
Working Three.js Starter (park-or-parking-lot-planning-table-x3175):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Block 04 — The Opportunity Cost of Choice</title>
<style>
:root {
--ink: #20322e;
--muted: #687872;
--paper: #f7f4ec;
--panel: #fffdf8;
--line: #dce1d9;
--gain: #178b72;
--gain-soft: #e4f3ed;
--loss: #d65349;
--loss-soft: #fbe8e4;
--accent: #316f65;
--shadow: 0 14px 38px rgba(30, 53, 46, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: #e8ede7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button {
font: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
width: 100%;
height: 100vh;
}
#viewport {
position: relative;
min-width: 0;
overflow: hidden;
background:
linear-gradient(rgba(255,255,255,.16), rgba(255,255,255,.16)),
#dfe7df;
}
#viewport canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#labels {
position: absolute;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.pin {
position: absolute;
z-index: 4;
display: none;
max-width: 170px;
padding: 7px 9px;
border: 1px solid rgba(255,255,255,.85);
border-radius: 7px;
background: rgba(255, 253, 248, .94);
box-shadow: 0 6px 18px rgba(28, 46, 40, .17);
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: .045em;
line-height: 1.15;
text-align: center;
white-space: nowrap;
transform: translate(-50%, calc(-100% - 9px));
}
.pin::after {
content: "";
position: absolute;
left: 50%;
bottom: -9px;
width: 1px;
height: 9px;
background: rgba(40, 60, 54, .42);
}
.pin::before {
content: "";
position: absolute;
left: calc(50% - 3px);
bottom: -12px;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--ink);
}
.pin.gain::before {
background: var(--gain);
}
.pin.loss::before {
background: var(--loss);
}
.pin.neutral::before {
background: #6f8179;
}
.pin.vacant {
color: #876d36;
background: #fff4cf;
border-color: #eddaa3;
}
.scene-heading {
position: absolute;
z-index: 5;
top: 22px;
left: 24px;
max-width: 440px;
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--accent);
font-size: 11px;
font-weight: 850;
letter-spacing: .13em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 19px;
height: 3px;
border-radius: 3px;
background: var(--accent);
}
.scene-heading h1 {
margin: 0;
max-width: 390px;
font-size: clamp(28px, 3.2vw, 48px);
line-height: .98;
letter-spacing: -.045em;
}
.scene-heading p {
max-width: 360px;
margin: 10px 0 0;
color: #566b63;
font-size: 13px;
line-height: 1.45;
}
.scene-status {
position: absolute;
z-index: 5;
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,.8);
border-radius: 10px;
background: rgba(255,253,248,.88);
box-shadow: 0 8px 24px rgba(40, 60, 54, .09);
color: #51645d;
font-size: 10px;
font-weight: 850;
letter-spacing: .07em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #b9a26a;
box-shadow: 0 0 0 4px rgba(185, 162, 106, .15);
}
.status-dot.civic {
background: var(--gain);
box-shadow: 0 0 0 4px rgba(23, 139, 114, .13);
}
.status-dot.housing {
background: #427ca5;
box-shadow: 0 0 0 4px rgba(66, 124, 165, .13);
}
.scene-tools {
position: absolute;
z-index: 6;
left: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 7px;
}
.tool-button {
min-height: 36px;
padding: 0 12px;
border: 1px solid rgba(255,255,255,.82);
border-radius: 8px;
background: rgba(255,253,248,.92);
box-shadow: 0 5px 15px rgba(31, 51, 44, .09);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 750;
}
.tool-button:hover {
background: #fff;
transform: translateY(-1px);
}
.tool-button:disabled {
opacity: .4;
cursor: default;
transform: none;
}
.camera-hint {
margin-left: 5px;
color: #60726b;
font-size: 10px;
font-weight: 650;
}
.legend {
position: absolute;
z-index: 5;
right: 22px;
bottom: 22px;
display: flex;
gap: 13px;
padding: 9px 11px;
border: 1px solid rgba(255,255,255,.8);
border-radius: 9px;
background: rgba(255,253,248,.88);
color: #60726b;
font-size: 10px;
font-weight: 750;
backdrop-filter: blur(8px);
}
.legend span {
display: flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 50%;
}
.legend .gain-dot {
background: var(--gain);
}
.legend .loss-dot {
background: var(--loss);
}
#loading {
position: absolute;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #e5ebe4;
color: #527168;
font-size: 13px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
transition: opacity .3s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
aside {
position: relative;
z-index: 7;
height: 100vh;
overflow-y: auto;
padding: 27px 26px 32px;
border-left: 1px solid rgba(49, 79, 69, .12);
background: var(--paper);
box-shadow: -12px 0 35px rgba(35, 55, 49, .08);
}
.sidebar-intro {
margin-bottom: 22px;
}
.sidebar-intro .eyebrow {
margin-bottom: 11px;
}
.sidebar-intro h2 {
margin: 0;
font-size: 29px;
line-height: 1.02;
letter-spacing: -.035em;
}
.sidebar-intro p {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.52;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 21px 0 10px;
}
.section-label h3 {
margin: 0;
font-size: 11px;
letter-spacing: .11em;
text-transform: uppercase;
}
.section-label span {
color: #87938e;
font-size: 10px;
}
.option-list {
display: grid;
gap: 12px;
}
.option-card {
position: relative;
overflow: hidden;
padding: 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
transition:
border-color .18s ease,
box-shadow .18s ease,
transform .18s ease;
}
.option-card:hover {
transform: translateY(-1px);
box-shadow: var(--shadow);
}
.option-card.active {
border-color: #438879;
box-shadow:
0 0 0 2px rgba(67, 136, 121, .12),
var(--shadow);
}
.option-card.active::after {
content: "ON PARCEL";
position: absolute;
top: 14px;
right: -30px;
width: 112px;
padding: 5px 0;
background: var(--accent);
color: white;
font-size: 8px;
font-weight: 900;
letter-spacing: .12em;
text-align: center;
transform: rotate(38deg);
}
.option-head {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 13px;
}
.voxel-icon {
position: relative;
flex: 0 0 48px;
width: 48px;
height: 48px;
border-radius: 10px;
background: #edf0e8;
overflow: hidden;
}
.voxel-icon span {
position: absolute;
display: block;
border-radius: 2px;
box-shadow: inset 0 -3px 0 rgba(0,0,0,.08);
}
.voxel-icon.civic span:nth-child(1) {
width: 23px;
height: 23px;
left: 8px;
top: 16px;
background: #27a38e;
}
.voxel-icon.civic span:nth-child(2) {
width: 13px;
height: 13px;
left: 27px;
top: 11px;
background: #ee9650;
}
.voxel-icon.civic span:nth-child(3) {
width: 13px;
height: 18px;
left: 27px;
top: 27px;
background: #df705e;
}
.voxel-icon.housing span:nth-child(1) {
width: 28px;
height: 29px;
left: 8px;
top: 11px;
background: #4c7fa4;
}
.voxel-icon.housing span:nth-child(2) {
width: 10px;
height: 13px;
left: 7px;
top: 36px;
background: #e27e62;
}
.voxel-icon.housing span:nth-child(3) {
width: 13px;
height: 9px;
left: 24px;
top: 32px;
background: #8eb866;
}
.option-title {
margin: 0 0 3px;
font-size: 16px;
letter-spacing: -.015em;
}
.option-type {
color: #7b8983;
font-size: 9px;
font-weight: 850;
letter-spacing: .11em;
text-transform: uppercase;
}
.mini-ledger {
display: grid;
gap: 8px;
margin: 0 0 14px;
color: #53665f;
font-size: 11px;
line-height: 1.35;
}
.mini-ledger > div {
display: grid;
grid-template-columns: 14px 47px 1fr;
gap: 5px;
align-items: start;
}
.mini-ledger b {
color: #334841;
font-size: 9px;
letter-spacing: .05em;
text-transform: uppercase;
}
.mini-ledger .dot {
width: 7px;
height: 7px;
margin-top: 3px;
border-radius: 50%;
}
.dot.gain {
background: var(--gain);
}
.dot.loss {
background: var(--loss);
}
.dot.trade {
background: #b78a46;
}
.model-button {
width: 100%;
min-height: 39px;
border: 0;
border-radius: 8px;
background: #2e685d;
color: white;
cursor: pointer;
font-size: 11px;
font-weight: 850;
letter-spacing: .03em;
transition:
background .15s ease,
transform .15s ease;
}
.model-button:hover {
background: #23564d;
transform: translateY(-1px);
}
.option-card.active .model-button {
background: #d65349;
}
.option-card.active .model-button:hover {
background: #bd443c;
}
.impact-panel {
margin-top: 18px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.panel-heading h3 {
margin: 0;
font-size: 15px;
}
.model-state {
padding: 5px 7px;
border-radius: 6px;
background: #edf1eb;
color: #61736c;
font-size: 8px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
}
.impact-columns {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.impact-column {
min-height: 145px;
padding: 12px;
border-radius: 10px;
}
.impact-column.gained {
background: var(--gain-soft);
}
.impact-column.displaced {
background: var(--loss-soft);
}
.impact-column h4 {
display: flex;
align-items: center;
gap: 6px;
margin: 0 0 9px;
font-size: 10px;
letter-spacing: .06em;
text-transform: uppercase;
}
.impact-column.gained h4 {
color: var(--gain);
}
.impact-column.displaced h4 {
color: var(--loss);
}
.impact-column ul {
display: grid;
gap: 7px;
margin: 0;
padding: 0;
list-style: none;
}
.impact-column li {
position: relative;
padding-left: 11px;
color: #52645d;
font-size: 10px;
line-height: 1.35;
}
.impact-column li::before {
content: "";
position: absolute;
left: 0;
top: 5px;
width: 4px;
height: 4px;
border-radius: 1px;
background: currentColor;
opacity: .65;
}
.opportunity-box {
margin-top: 10px;
padding: 13px;
border: 1px solid #ead9ae;
border-radius: 10px;
background: #fff5d9;
}
.opportunity-box .label {
margin-bottom: 5px;
color: #9a742d;
font-size: 9px;
font-weight: 900;
letter-spacing: .09em;
text-transform: uppercase;
}
.opportunity-box p {
margin: 0;
color: #675a3f;
font-size: 11px;
line-height: 1.45;
}
.balance {
display: grid;
gap: 10px;
margin-top: 14px;
}
.balance-row {
display: grid;
grid-template-columns: 88px 1fr 32px;
align-items: center;
gap: 8px;
color: #61726c;
font-size: 9px;
font-weight: 750;
}
.balance-track {
height: 7px;
overflow: hidden;
border-radius: 7px;
background: #e9ede7;
}
.balance-track i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width .3s ease;
}
#publicBar {
background: var(--gain);
}
#homeBar {
background: #427ca5;
}
.balance-value {
text-align: right;
color: #42564f;
}
.assumption {
margin: 17px 2px 0;
color: #7a8882;
font-size: 10px;
line-height: 1.5;
}
.assumption strong {
color: #5d6e67;
}
@media (max-width: 980px) {
#app {
grid-template-columns: minmax(0, 1fr) 355px;
}
aside {
padding: 24px 20px;
}
}
@media (max-width: 760px) {
body {
overflow: auto;
}
#app {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 62vh auto;
height: auto;
min-height: 100vh;
}
#viewport {
min-height: 62vh;
}
aside {
height: auto;
overflow: visible;
border-top: 1px solid rgba(49, 79, 69, .12);
border-left: 0;
}
.scene-heading {
top: 17px;
left: 17px;
}
.scene-heading h1 {
font-size: 31px;
}
.scene-heading p {
display: none;
}
.scene-status {
top: auto;
right: 15px;
bottom: 67px;
}
.scene-tools {
left: 15px;
bottom: 15px;
}
.camera-hint,
.legend {
display: none;
}
.impact-columns {
grid-template-columns: 1fr 1fr;
}
}
@media (max-width: 430px) {
.impact-columns {
grid-template-columns: 1fr;
}
.impact-column {
min-height: auto;
}
}
</style>
</head>
<body>
<div id="app">
<main id="viewport" aria-label="Interactive voxel model of a city block">
<div id="loading">Loading voxel block…</div>
<div id="labels"></div>
<header class="scene-heading">
<div class="eyebrow">Fictional planning study · Block 04</div>
<h1>One parcel.<br>Two futures.</h1>
<p>
Place a public-service campus or a mixed-use housing court on the
same vacant site, then compare what each choice creates—and gives up.
</p>
</header>
<div class="scene-status">
<span id="statusDot" class="status-dot"></span>
<span id="sceneStatus">Vacant parcel</span>
</div>
<div class="scene-tools">
<button id="zoomIn" class="tool-button" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" class="tool-button" type="button" aria-label="Zoom out">−</button>
<button id="resetView" class="tool-button" type="button">Reset view</button>
<button id="clearModel" class="tool-button" type="button" disabled>Clear parcel</button>
<span class="camera-hint">Drag to orbit · Scroll to zoom</span>
</div>
<div class="legend" aria-hidden="true">
<span><i class="gain-dot"></i>Facility gained</span>
<span><i class="loss-dot"></i>Resource displaced</span>
</div>
</main>
<aside>
<div class="sidebar-intro">
<div class="eyebrow">Mutually exclusive choices</div>
<h2>What should the block become?</h2>
<p>
Both models use the same 12 × 10 parcel and the same existing site
amenities. Only one can be built at a time.
</p>
</div>
<div class="section-label">
<h3>Choose a land-use model</h3>
<span>Click again to remove</span>
</div>
<div class="option-list">
<article id="civicCard" class="option-card">
<div class="option-head">
<div class="voxel-icon civic" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div>
<h4 class="option-title">Civic Commons</h4>
<div class="option-type">Public services</div>
</div>
</div>
<div class="mini-ledger">
<div>
<span class="dot gain"></span><b>Gain</b>
<span>Library, childcare, clinic and a public plaza.</span>
</div>
<div>
<span class="dot loss"></span><b>Displace</b>
<span>6 parking spaces, 2 trees and 1 loading zone.</span>
</div>
<div>
<span class="dot trade"></span><b>Forego</b>
<span>12 new apartments and a corner shop.</span>
</div>
</div>
<button class="model-button" type="button" data-model="civic" aria-pressed="false">
Place Civic Commons
</button>
</article>
<article id="housingCard" class="option-card">
<div class="option-head">
<div class="voxel-icon housing" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div>
<h4 class="option-title">Housing Court</h4>
<div class="option-type">Mixed-use homes</div>
</div>
</div>
<div class="mini-ledger">
<div>
<span class="dot gain"></span><b>Gain</b>
<span>12 apartments, a corner shop and a green courtyard.</span>
</div>
<div>
<span class="dot loss"></span><b>Displace</b>
<span>6 parking spaces, 2 trees and 1 loading zone.</span>
</div>
<div>
<span class="dot trade"></span><b>Forego</b>
<span>Library, childcare, clinic and public gathering space.</span>
</div>
</div>
<button class="model-button" type="button" data-model="housing" aria-pressed="false">
Place Housing Court
</button>
</article>
</div>
<section class="impact-panel" aria-live="polite">
<div class="panel-heading">
<h3>Impact ledger</h3>
<span id="modelState" class="model-state">Vacant</span>
</div>
<div class="impact-columns">
<div class="impact-column gained">
<h4><span class="dot gain"></span>Facilities gained</h4>
<ul id="gainedList">
<li>No development model placed</li>
</ul>
</div>
<div class="impact-column displaced">
<h4><span class="dot loss"></span>Facilities displaced</h4>
<ul id="displacedList">
<li>Existing surface amenities remain</li>
</ul>
</div>
</div>
<div class="opportunity-box">
<div class="label">Opportunity cost</div>
<p id="opportunityText">
Select a model to reveal the facilities that cannot be provided
because the parcel is used for another purpose.
</p>
</div>
<div class="balance" aria-label="Scenario emphasis">
<div class="balance-row">
<span>Public services</span>
<div class="balance-track"><i id="publicBar"></i></div>
<span id="publicValue" class="balance-value">0%</span>
</div>
<div class="balance-row">
<span>New homes</span>
<div class="balance-track"><i id="homeBar"></i></div>
<span id="homeValue" class="balance-value">0%</span>
</div>
</div>
</section>
<p class="assumption">
<strong>Illustrative assumptions only.</strong>
The displaced parking, street trees and loading zone are the same in
both scenarios so the opportunity cost of the two land uses can be
compared directly. Click the model in the 3D scene to remove it.
</p>
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const labelsLayer = document.getElementById("labels");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dfe7df");
scene.fog = new THREE.Fog("#dfe7df", 66, 110);
const camera = new THREE.PerspectiveCamera(
38,
viewport.clientWidth / viewport.clientHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel city block. Drag to orbit, scroll to zoom, or use the view buttons."
);
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#ffffff", "#84958a", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff7df", 3.15);
sun.position.set(18, 30, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9d9e5", 0.75);
fill.position.set(-20, 14, -12);
scene.add(fill);
const materialCache = new Map();
function material(color) {
if (color && color.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0
})
);
}
return materialCache.get(color);
}
function box(
parent,
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotationY) {
mesh.rotation.y = options.rotationY;
}
if (options.rotationX) {
mesh.rotation.x = options.rotationX;
}
if (options.rotationZ) {
mesh.rotation.z = options.rotationZ;
}
parent.add(mesh);
return mesh;
}
const mats = {
glass: new THREE.MeshStandardMaterial({
color: "#a9d9e3",
roughness: 0.28,
metalness: 0.08
}),
darkGlass: new THREE.MeshStandardMaterial({
color: "#315b66",
roughness: 0.34,
metalness: 0.12
}),
road: "#536168",
cream: "#eee7d4",
white: "#f8f4e9"
};
const staticRoot = new THREE.Group();
scene.add(staticRoot);
// Raised block and street grid.
box(staticRoot, 40, 0.8, 34, 0, -0.46, 0, "#cbd4cb");
box(staticRoot, 39.5, 0.18, 33.5, 0, -0.03, 0, "#d9dfd5");
// Roads around the central parcel.
box(staticRoot, 39, 0.08, 5.6, 0, 0.08, -8.3, mats.road);
box(staticRoot, 39, 0.08, 5.6, 0, 0.08, 8.3, mats.road);
box(staticRoot, 5.6, 0.09, 11.2, -9, 0.09, 0, mats.road);
box(staticRoot, 5.6, 0.09, 11.2, 9, 0.09, 0, mats.road);
// Center parcel and curb.
box(staticRoot, 12.4, 0.16, 10.4, 0, 0.11, 0, "#ebe6d8");
box(staticRoot, 12, 0.13, 10, 0, 0.15, 0, "#e7d4a8");
box(staticRoot, 12.8, 0.14, 0.38, 0, 0.12, -5.25, "#f1eee3");
box(staticRoot, 12.8, 0.14, 0.38, 0, 0.12, 5.25, "#f1eee3");
box(staticRoot, 0.38, 0.14, 10.9, -6.25, 0.12, 0, "#f1eee3");
box(staticRoot, 0.38, 0.14, 10.9, 6.25, 0.12, 0, "#f1eee3");
// Lane markings.
for (let x = -18; x <= 18; x += 3) {
if (Math.abs(x) > 7) {
box(staticRoot, 1.35, 0.025, 0.12, x, 0.14, -8.3, "#f3e8c4", {
castShadow: false
});
box(staticRoot, 1.35, 0.025, 0.12, x, 0.14, 8.3, "#f3e8c4", {
castShadow: false
});
}
}
for (let z = -4.7; z <= 4.7; z += 1.25) {
box(staticRoot, 0.12, 0.025, 0.7, -9, 0.16, z, "#f3e8c4", {
castShadow: false
});
box(staticRoot, 0.12, 0.025, 0.7, 9, 0.16, z, "#f3e8c4", {
castShadow: false
});
}
// Crosswalks.
for (let i = 0; i < 6; i++) {
box(staticRoot, 0.6, 0.025, 1.3, 6.35 + i * 0.92, 0.16, -8.3, "#f4ebd2", {
castShadow: false
});
box(staticRoot, 0.6, 0.025, 1.3, -12.45 + i * 0.92, 0.16, 8.3, "#f4ebd2", {
castShadow: false
});
}
function makeTree(parent, x, z, scale = 1, palette = 0) {
const tree = new THREE.Group();
tree.position.set(x, 0.1, z);
tree.scale.setScalar(scale);
const leafColors = [
["#5b9b63", "#6fa96d", "#4d8959"],
["#719d63", "#83ad6b", "#5d8f5a"]
];
const leaves = leafColors[palette % leafColors.length];
box(tree, 0.32, 1.7, 0.32, 0, 0.85, 0, "#8b6545");
box(tree, 1.55, 1.35, 1.45, 0, 2.25, 0, leaves[0]);
box(tree, 1.05, 1.05, 1.15, -0.55, 2.95, 0.1, leaves[1]);
box(tree, 0.85, 0.85, 0.95, 0.55, 2.8, -0.1, leaves[2]);
box(tree, 0.75, 0.75, 0.8, 0.05, 3.45, 0.08, leaves[1]);
parent.add(tree);
return tree;
}
function makeHome(x, z, rotation, bodyColor, roofColor, width = 3.6, depth = 3.2) {
const home = new THREE.Group();
home.position.set(x, 0, z);
home.rotation.y = rotation;
box(home, width + 1.1, 0.08, depth + 1.1, 0, 0.08, 0, "#c9d8c4");
box(home, width, 2.45, depth, 0, 1.32, 0, bodyColor);
box(home, width + 0.3, 0.34, depth + 0.3, 0, 2.7, 0, roofColor);
box(home, width * 0.72, 0.34, depth * 0.76, 0, 3.02, 0, roofColor);
box(home, width * 0.42, 0.32, depth * 0.45, 0, 3.3, 0, roofColor);
box(home, 0.42, 0.85, 0.42, width * 0.25, 3.65, -depth * 0.2, "#9a8068");
// Front door.
box(home, 0.58, 1.2, 0.09, 0, 0.82, depth / 2 + 0.055, "#5a5148");
// Front windows.
box(home, 0.72, 0.7, 0.09, -1.05, 1.58, depth / 2 + 0.055, mats.darkGlass);
box(home, 0.72, 0.7, 0.09, 1.05, 1.58, depth / 2 + 0.055, mats.darkGlass);
// Side windows.
box(home, 0.09, 0.68, 0.75, -width / 2 - 0.045, 1.58, 0, mats.darkGlass);
box(home, 0.09, 0.68, 0.75, width / 2 + 0.045, 1.58, 0, mats.darkGlass);
// Path and tiny front garden.
box(home, 0.65, 0.035, 1.2, 0, 0.16, depth / 2 + 0.5, "#ddd4bd");
box(home, 0.85, 0.16, 0.75, -1.15, 0.22, depth / 2 + 0.65, "#79a76d");
staticRoot.add(home);
return home;
}
const homeColors = [
"#e6b487",
"#b9d2c5",
"#d7a7a0",
"#c7c7db",
"#e4d4a3",
"#a9c3d0"
];
const roofColors = ["#695e5c", "#596b6d", "#766459", "#59656f"];
// North and south rows.
[-16, -6, 0, 6, 16].forEach((x, i) => {
makeHome(
x,
-13.35,
0,
homeColors[i % homeColors.length],
roofColors[i % roofColors.length]
);
makeHome(
x,
13.35,
Math.PI,
homeColors[(i + 2) % homeColors.length],
roofColors[(i + 1) % roofColors.length]
);
});
// Side rows face inward.
[-3.25, 3.25].forEach((z, i) => {
makeHome(
-16,
z,
Math.PI / 2,
homeColors[(i + 3) % homeColors.length],
roofColors[(i + 2) % roofColors.length]
);
makeHome(
16,
z,
-Math.PI / 2,
homeColors[(i + 4) % homeColors.length],
roofColors[(i + 3) % roofColors.length]
);
});
// Existing street trees.
[
[-16.8, -5.9, .86, 0],
[-12.4, -10.4, .78, 1],
[12.4, -10.4, .82, 0],
[16.8, -5.8, .9, 1],
[-16.8, 5.9, .82, 1],
[-12.4, 10.4, .76, 0],
[12.4, 10.4, .88, 1],
[16.8, 5.8, .84, 0]
].forEach(([x, z, s, p]) => makeTree(staticRoot, x, z, s, p));
function makeStreetlight(x, z, rotation = 0) {
const light = new THREE.Group();
light.position.set(x, 0.1, z);
light.rotation.y = rotation;
box(light, 0.16, 3.2, 0.16, 0, 1.6, 0, "#526269");
box(light, 0.9, 0.14, 0.16, 0.4, 3.15, 0, "#526269");
box(light, 0.55, 0.16, 0.38, 0.72, 3.04, 0, "#f2dfa3");
staticRoot.add(light);
}
makeStreetlight(-7, -5.75, Math.PI);
makeStreetlight(7, 5.75, 0);
makeStreetlight(-7, 5.75, 0);
makeStreetlight(7, -5.75, Math.PI);
function makeCar(x, z, color, rotation = 0) {
const car = new THREE.Group();
car.position.set(x, 0.18, z);
car.rotation.y = rotation;
box(car, 1.05, 0.46, 1.95, 0, 0.23, 0, color);
box(car, 0.86, 0.38, 1.0, 0, 0.62, -0.08, mats.darkGlass);
box(car, 1.08, 0.08, 0.1, 0, 0.1, 1.01, "#dfe5dd");
staticRoot.add(car);
}
makeCar(-11.5, -7.1, "#d87e62", Math.PI / 2);
makeCar(8.5, 9.5, "#d9bd62", Math.PI / 2);
makeCar(-4.2, -9.3, "#6b91a3", 0);
makeCar(4.3, 7.2, "#d6dce0", 0);
// Existing amenities on the currently vacant parcel.
const surfaceFeatures = new THREE.Group();
scene.add(surfaceFeatures);
const parkingCoordinates = [];
[-1.55, 0.95].forEach((z, row) => {
[-4.25, -2.55, -0.85].forEach((x, col) => {
parkingCoordinates.push([x, z]);
box(
surfaceFeatures,
0.055,
0.025,
2.05,
x + 0.78,
0.245,
z,
mats.white,
{ castShadow: false }
);
if ((row + col) % 3 !== 0) {
const carColors = ["#d66e5c", "#6e91a1", "#d5b861"];
box(
surfaceFeatures,
1.05,
0.45,
1.9,
x,
0.47,
z,
carColors[(row + col) % carColors.length]
);
box(
surfaceFeatures,
0.84,
0.34,
0.95,
x,
0.83,
z - 0.05,
mats.darkGlass
);
}
});
});
// Loading zone.
box(surfaceFeatures, 2.7, 0.03, 1.05, -3.15, 0.245, 3.65, "#f1e8c9", {
castShadow: false
});
box(surfaceFeatures, 2.5, 0.03, 0.06, -3.15, 0.265, 3.65, "#d5bd6d", {
castShadow: false
});
// The two parcel trees are part of the baseline site.
makeTree(surfaceFeatures, 4.65, -3.8, .76, 0);
makeTree(surfaceFeatures, 4.65, 2.85, .72, 1);
// Red displaced-resource overlays.
const lossMarkers = new THREE.Group();
scene.add(lossMarkers);
lossMarkers.visible = false;
const lossMaterial = new THREE.MeshBasicMaterial({
color: "#e4574f",
transparent: true,
opacity: 0.18,
depthTest: false,
depthWrite: false
});
const lossLineMaterial = new THREE.MeshBasicMaterial({
color: "#e4574f",
transparent: true,
opacity: 0.78,
depthTest: false,
depthWrite: false
});
box(lossMarkers, 5.2, 0.035, 4.65, -2.55, 0.34, -0.3, lossMaterial, {
castShadow: false,
receiveShadow: false
});
function squareMarker(x, z, size = 1.1) {
const t = 0.075;
box(lossMarkers, size, 0.04, t, x, 0.36, z - size / 2, lossLineMaterial, {
castShadow: false,
receiveShadow: false
});
box(lossMarkers, size, 0.04, t, x, 0.36, z + size / 2, lossLineMaterial, {
castShadow: false,
receiveShadow: false
});
box(lossMarkers, t, 0.04, size, x - size / 2, 0.36, z, lossLineMaterial, {
castShadow: false,
receiveShadow: false
});
box(lossMarkers, t, 0.04, size, x + size / 2, 0.36, z, lossLineMaterial, {
castShadow: false,
receiveShadow: false
});
}
squareMarker(4.65, -3.8, 1.05);
squareMarker(4.65, 2.85, 1.05);
squareMarker(-3.15, 3.65, 2.7);
function makeBench(parent, x, z, color = "#9b7654", rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0.28, z);
bench.rotation.y = rotation;
box(bench, 1.65, 0.16, 0.48, 0, 0.38, 0, color);
box(bench, 1.65, 0.55, 0.13, 0, 0.67, -0.2, color);
box(bench, 0.13, 0.38, 0.36, -0.58, 0.17, 0, "#536269");
box(bench, 0.13, 0.38, 0.36, 0.58, 0.17, 0, "#536269");
parent.add(bench);
}
function buildCivic() {
const group = new THREE.Group();
group.name = "Civic Commons";
box(group, 11.2, 0.18, 9.2, 0, 0.29, 0, "#d6ded2");
// Main library mass.
box(group, 5.5, 3.45, 4.0, -1.35, 2.05, -1.2, "#279b88");
box(group, 5.8, 0.28, 4.3, -1.35, 3.91, -1.2, "#ebefdf");
box(group, 4.65, 0.55, 3.35, -1.5, 4.3, -1.35, "#4db09b");
for (const x of [-3.05, -1.55, -0.05]) {
for (const y of [1.35, 2.45]) {
box(group, 0.68, 0.72, 0.09, x, y, 0.86, mats.glass);
}
}
box(group, 1.05, 1.65, 0.1, -1.35, 1.13, 0.87, "#315b60");
box(group, 2.2, 0.16, 1.0, -1.35, 0.41, 0.8, "#d8d1b9");
// Library roof garden.
box(group, 1.1, 0.3, 1.0, -2.9, 4.77, -1.4, "#78a96a");
box(group, 0.9, 0.3, 0.8, -0.2, 4.77, -1.1, "#8bb66f");
// Childcare wing.
box(group, 2.9, 2.55, 2.8, 3.25, 1.59, -2.8, "#e69b5d");
box(group, 3.2, 0.28, 3.1, 3.25, 3.0, -2.8, "#f5d692");
box(group, 0.72, 0.72, 0.09, 3.25, 1.95, -1.84, mats.glass);
box(group, 0.58, 1.12, 0.09, 2.55, 0.9, -1.84, "#f4d9a6");
// Clinic wing.
box(group, 2.9, 3.05, 2.7, 3.25, 1.83, 1.45, "#df735e");
box(group, 3.2, 0.28, 3.0, 3.25, 3.49, 1.45, "#f1c5a9");
box(group, 0.7, 0.72, 0.09, 3.25, 2.1, 0.04, mats.glass);
box(group, 0.58, 1.12, 0.09, 2.4, 0.88, 0.04, "#f5d6bd");
// Roof medical cross.
box(group, 1.25, 0.09, 0.42, 3.25, 3.69, 1.45, "#fff9e9", {
castShadow: false
});
box(group, 0.42, 0.10, 1.25, 3.25, 3.7, 1.45, "#fff9e9", {
castShadow: false
});
// Public plaza.
box(group, 6.1, 0.18, 2.65, -1.45, 0.43, 3.05, "#d8c69f");
box(group, 1.25, 0.32, 1.25, -3.65, 0.66, 3.15, "#80a66d");
box(group, 0.65, 0.55, 0.65, -3.65, 1.08, 3.15, "#e9b45f");
box(group, 0.55, 0.55, 0.55, -3.05, 1.02, 3.65, "#df765f");
makeBench(group, -1.25, 3.05, "#a46e4d");
makeBench(group, 0.3, 3.05, "#a46e4d", Math.PI);
// Small play elements in the childcare area.
box(group, 0.18, 1.35, 0.18, 2.25, 0.86, -3.6, "#698a78");
box(group, 0.75, 0.18, 0.18, 2.58, 1.35, -3.6, "#f1d26e");
return group;
}
function buildHousing() {
const group = new THREE.Group();
group.name = "Housing Court";
box(group, 11.2, 0.18, 9.2, 0, 0.29, 0, "#d6ded2");
// Three-storey apartment slab: four units on each floor.
box(group, 7.6, 6.55, 4.0, -1.2, 3.59, -1.2, "#4b7fa4");
box(group, 7.9, 0.28, 4.3, -1.2, 7.0, -1.2, "#d9dfd8");
const balconyColors = ["#df8065", "#e5bd62", "#8eb66b", "#72a9b2"];
[1.3, 3.4, 5.5].forEach((floorY, floor) => {
box(
group,
7.75,
0.14,
4.12,
-1.2,
floorY - 1.04,
-1.2,
"#d8dfda"
);
[-4.2, -2.1, 0, 2.1].forEach((x, unit) => {
const color = balconyColors[(floor + unit) % balconyColors.length];
// Unit door/window panel.
box(group, 0.82, 1.35, 0.1, x, floorY, 0.86, color);
box(group, 0.52, 0.52, 0.12, x, floorY + 0.03, 0.925, mats.darkGlass);
// Balcony.
box(group, 1.12, 0.14, 0.7, x, floorY - 0.78, 1.15, "#d8d4c6");
box(group, 1.12, 0.46, 0.08, x, floorY - 0.55, 1.46, "#edf0e8");
box(group, 0.08, 0.46, 0.7, x - 0.52, floorY - 0.55, 1.15, "#edf0e8");
box(group, 0.08, 0.46, 0.7, x + 0.52, floorY - 0.55, 1.15, "#edf0e8");
});
});
// Ground-floor entrance.
box(group, 1.3, 1.65, 0.12, -1.1, 1.18, 0.87, "#e5d6af");
box(group, 0.92, 1.35, 0.13, -1.1, 1.02, 0.95, mats.darkGlass);
// Rooftop garden and solar panels.
box(group, 1.25, 0.35, 1.0, -3.9, 7.3, -1.4, "#78a66b");
box(group, 1.0, 0.35, 0.85, -2.2, 7.3, -0.6, "#8eb66f");
for (let i = 0; i < 3; i++) {
box(
group,
0.85,
0.08,
1.45,
0.25 + i * 0.82,
7.25,
-1.55,
mats.darkGlass
);
}
// Corner shop.
box(group, 3.0, 2.3, 3.15, 3.7, 1.46, -2.75, "#df7f62");
box(group, 3.25, 0.25, 3.4, 3.7, 2.73, -2.75, "#f0d8b3");
box(group, 2.3, 0.85, 0.1, 3.7, 1.65, -1.11, mats.glass);
box(group, 3.25, 0.12, 0.65, 3.7, 1.13, -0.78, "#f0c65f");
// Shared green courtyard.
box(group, 3.15, 0.18, 3.35, 3.7, 0.44, 1.35, "#b8ce9d");
makeTree(group, 4.45, 1.25, 0.65, 1);
makeBench(group, 3.0, 2.05, "#9b7654");
box(group, 0.9, 0.26, 0.9, 4.55, 0.65, 2.3, "#d6a866");
return group;
}
const civicModel = buildCivic();
const housingModel = buildHousing();
civicModel.visible = false;
housingModel.visible = false;
scene.add(civicModel, housingModel);
const models = {
civic: {
group: civicModel,
status: "Civic Commons placed",
state: "Civic selected",
gained: [
"Public library",
"40-place childcare center",
"Neighborhood clinic",
"Public plaza"
],
displaced: [
"6 surface parking spaces",
"2 mature street trees",
"1 curbside loading zone"
],
opportunity:
"Placing Civic Commons gives up the opportunity to house 12 households and add a corner shop.",
publicValue: 100,
homeValue: 0
},
housing: {
group: housingModel,
status: "Housing Court placed",
state: "Housing selected",
gained: [
"12 new apartments",
"1 neighborhood corner shop",
"1 shared green courtyard"
],
displaced: [
"6 surface parking spaces",
"2 mature street trees",
"1 curbside loading zone"
],
opportunity:
"Placing Housing Court gives up the opportunity to provide a library, childcare, a clinic and a public gathering place.",
publicValue: 25,
homeValue: 100
}
};
function createPin(text, type = "gain", position = [0, 0, 0]) {
const pin = document.createElement("div");
pin.className = `pin ${type}`;
pin.textContent = text;
pin.userData = { position: new THREE.Vector3(...position) };
labelsLayer.appendChild(pin);
return pin;
}
const pins = {
existingHomes: createPin("EXISTING HOMES ×14", "neutral", [-9, 4.8, -13.35]),
vacant: createPin("VACANT PARCEL", "vacant", [0, 0.9, 0]),
civic: [
createPin("PUBLIC LIBRARY", "gain", [-1.35, 5.0, -1.2]),
createPin("CHILDCARE", "gain", [3.25, 3.7, -2.8]),
createPin("NEIGHBORHOOD CLINIC", "gain", [3.25, 4.2, 1.45]),
createPin("PUBLIC PLAZA", "gain", [-1.45, 1.4, 3.05])
],
housing: [
createPin("12 APARTMENTS", "gain", [-1.2, 7.8, -1.2]),
createPin("CORNER SHOP", "gain", [3.7, 3.4, -2.75]),
createPin("GREEN COURTYARD", "gain", [3.7, 2.2, 1.35])
],
loss: [
createPin("6 PARKING SPACES", "loss", [-2.8, 1.0, -0.4]),
createPin("2 TREES + LOADING", "loss", [4.8, 2.8, -2.7])
]
};
let activeModel = "civic";
const civicCard = document.getElementById("civicCard");
const housingCard = document.getElementById("housingCard");
const statusDot = document.getElementById("statusDot");
const sceneStatus = document.getElementById("sceneStatus");
const modelState = document.getElementById("modelState");
const gainedList = document.getElementById("gainedList");
const displacedList = document.getElementById("displacedList");
const opportunityText = document.getElementById("opportunityText");
const publicBar = document.getElementById("publicBar");
const homeBar = document.getElementById("homeBar");
const publicValue = document.getElementById("publicValue");
const homeValue = document.getElementById("homeValue");
const clearModel = document.getElementById("clearModel");
function setActiveModel(model) {
activeModel = model;
Object.entries(models).forEach(([key, item]) => {
item.group.visible = key === model;
});
surfaceFeatures.visible = !model;
lossMarkers.visible = Boolean(model);
civicCard.classList.toggle("active", model === "civic");
housingCard.classList.toggle("active", model === "housing");
document.querySelectorAll("[data-model]").forEach((button) => {
const key = button.dataset.model;
const selected = key === model;
button.setAttribute("aria-pressed", String(selected));
button.textContent = selected
? `Remove ${key === "civic" ? "Civic Commons" : "Housing Court"}`
: `Place ${key === "civic" ? "Civic Commons" : "Housing Court"}`;
});
clearModel.disabled = !model;
statusDot.className = `status-dot ${model || ""}`;
if (model) {
const item = models[model];
sceneStatus.textContent = item.status;
modelState.textContent = item.state;
gainedList.innerHTML = item.gained.map((entry) => `<li>${entry}</li>`).join("");
displacedList.innerHTML = item.displaced.map((entry) => `<li>${entry}</li>`).join("");
opportunityText.textContent = item.opportunity;
publicBar.style.width = `${item.publicValue}%`;
homeBar.style.width = `${item.homeValue}%`;
publicValue.textContent = `${item.publicValue}%`;
homeValue.textContent = `${item.homeValue}%`;
} else {
sceneStatus.textContent = "Vacant parcel";
modelState.textContent = "Vacant";
gainedList.innerHTML = "<li>No development model placed</li>";
displacedList.innerHTML = "<li>Existing surface amenities remain</li>";
opportunityText.textContent =
"Select a model to reveal the facilities that cannot be provided because the parcel is used for another purpose.";
publicBar.style.width = "0%";
homeBar.style.width = "0%";
publicValue.textContent = "0%";
homeValue.textContent = "0%";
}
}
document.querySelectorAll("[data-model]").forEach((button) => {
button.addEventListener("click", () => {
const key = button.dataset.model;
setActiveModel(activeModel === key ? null : key);
});
});
clearModel.addEventListener("click", () => setActiveModel(null));
// Camera controls are implemented directly, without external controls.
const cameraState = {
theta: 0.72,
phi: 0.87,
radius: 48,
target: new THREE.Vector3(0, 0.8, 0)
};
function updateCamera() {
const responsiveScale = Math.max(1, 0.98 / camera.aspect);
const radius = cameraState.radius * responsiveScale;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + radius * sinPhi * Math.cos(cameraState.theta),
cameraState.target.y + radius * Math.cos(cameraState.phi),
cameraState.target.z + radius * sinPhi * Math.sin(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = 0.72;
cameraState.phi = 0.87;
cameraState.radius = 48;
cameraState.target.set(0, 0.8, 0);
updateCamera();
}
document.getElementById("zoomIn").addEventListener("click", () => {
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius - 4, 28, 72);
updateCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius + 4, 28, 72);
updateCamera();
});
document.getElementById("resetView").addEventListener("click", resetCamera);
const canvas = renderer.domElement;
let pointerState = null;
canvas.addEventListener("pointerdown", (event) => {
pointerState = {
id: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerState || pointerState.id !== event.pointerId) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
if (
Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
) > 4
) {
pointerState.moved = true;
}
cameraState.theta -= dx * 0.007;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.34,
1.25
);
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
updateCamera();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
canvas.addEventListener("pointerup", (event) => {
if (
pointerState &&
!pointerState.moved &&
activeModel &&
models[activeModel].group
) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObject(models[activeModel].group, true);
if (hits.length > 0) {
setActiveModel(null);
}
}
pointerState = null;
});
canvas.addEventListener("pointercancel", () => {
pointerState = null;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
28,
72
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("keydown", (event) => {
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.34, cameraState.phi - 0.08);
else if (key === "arrowdown") cameraState.phi = Math.min(1.25, cameraState.phi + 0.08);
else if (key === "+" || key === "=") cameraState.radius = Math.max(28, cameraState.radius - 3);
else if (key === "-") cameraState.radius = Math.min(72, cameraState.radius + 3);
else if (key === "r") resetCamera();
else return;
event.preventDefault();
updateCamera();
});
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
updateCamera();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
const projected = new THREE.Vector3();
function updatePin(pin, visible) {
if (!visible) {
pin.style.display = "none";
return;
}
projected.copy(pin.userData.position).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
if (!onScreen) {
pin.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
pin.style.display = "block";
pin.style.left = `${x}px`;
pin.style.top = `${y}px`;
}
function animate() {
requestAnimationFrame(animate);
updatePin(pins.existingHomes, true);
updatePin(pins.vacant, !activeModel);
pins.loss.forEach((pin) => updatePin(pin, Boolean(activeModel)));
pins.civic.forEach((pin) => updatePin(pin, activeModel === "civic"));
pins.housing.forEach((pin) => updatePin(pin, activeModel === "housing"));
renderer.render(scene, camera);
}
resize();
setActiveModel(activeModel);
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```