Prompt specification
Build or customize the Three.js 3D scene "Compare pedestrian routes with open and enclosed pilotis" 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: Compare pedestrian routes with open and enclosed pilotis
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-pedestrian-routes-with-open-and-enclosed-pilot-x2652
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a residential superquadra in Brasília. Let users toggle a hypothetical enclosure beneath one block. Show changed connectivity across the shared green space while clearly identifying the enclosure as a teaching counterfactual. Voxel style.
Working Three.js Starter (compare-pedestrian-routes-with-open-and-enclosed-pilot-x2652):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#e8eee9">
<title>Brasília Superquadra — Teaching Counterfactual</title>
<style>
:root {
--ink: #17312f;
--muted: #63736f;
--paper: rgba(250, 249, 243, 0.94);
--line: rgba(23, 49, 47, 0.14);
--teal: #138b86;
--magenta: #d53f79;
--amber: #e79a25;
--amber-dark: #9b5b08;
--shadow: 0 18px 50px rgba(32, 55, 50, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
overscroll-behavior: none;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 22px;
left: 24px;
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 8px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 2px;
background: currentColor;
content: "";
}
h1 {
max-width: 480px;
margin: 0;
font-size: clamp(25px, 3.1vw, 43px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 430px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
#statePill {
position: fixed;
z-index: 12;
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 9px;
min-height: 34px;
padding: 0 13px;
border: 1px solid rgba(23, 49, 47, 0.12);
border-radius: 999px;
background: rgba(250, 249, 243, 0.84);
backdrop-filter: blur(12px);
box-shadow: 0 8px 24px rgba(32, 55, 50, 0.08);
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#statePill::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(19, 139, 134, 0.11);
content: "";
}
body.counterfactual #statePill {
border-color: rgba(231, 154, 37, 0.35);
color: var(--amber-dark);
}
body.counterfactual #statePill::before {
background: var(--amber);
box-shadow: 0 0 0 4px rgba(231, 154, 37, 0.14);
}
#counterNotice {
position: fixed;
z-index: 11;
top: 70px;
right: 24px;
width: min(330px, calc(100vw - 48px));
padding: 13px 15px;
border: 1px solid rgba(155, 91, 8, 0.22);
border-radius: 12px;
background: rgba(255, 244, 216, 0.94);
box-shadow: var(--shadow);
opacity: 0;
transform: translateY(-8px);
pointer-events: none;
transition:
opacity 220ms ease,
transform 220ms ease;
}
body.counterfactual #counterNotice {
opacity: 1;
transform: translateY(0);
}
#counterNotice strong {
display: block;
color: var(--amber-dark);
font-size: 11px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#counterNotice span {
display: block;
margin-top: 4px;
color: #6e5b38;
font-size: 12px;
line-height: 1.4;
}
.panel {
position: fixed;
z-index: 10;
left: 24px;
bottom: 24px;
width: 370px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 19px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.panel h2 {
margin: 0;
font-size: 19px;
letter-spacing: -0.025em;
}
.not-proposal {
flex: 0 0 auto;
padding: 5px 7px;
border: 1px solid rgba(231, 154, 37, 0.28);
border-radius: 6px;
background: #fff4d8;
color: var(--amber-dark);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.description {
margin: 10px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.52;
}
.scenario-control {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.52);
}
.scenario-control strong {
display: block;
font-size: 13px;
}
.scenario-control small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
#scenarioToggle {
position: relative;
flex: 0 0 auto;
width: 58px;
height: 32px;
padding: 0;
border: 0;
border-radius: 999px;
background: #cbd4d1;
cursor: pointer;
transition: background 180ms ease;
}
#scenarioToggle::after {
position: absolute;
top: 4px;
left: 4px;
width: 24px;
height: 24px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 8px rgba(23, 49, 47, 0.22);
content: "";
transition: transform 180ms ease;
}
#scenarioToggle[aria-pressed="true"] {
background: var(--amber);
}
#scenarioToggle[aria-pressed="true"]::after {
transform: translateX(26px);
}
#scenarioToggle:focus-visible,
#resetCamera:focus-visible {
outline: 3px solid rgba(19, 139, 134, 0.32);
outline-offset: 3px;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.metric {
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.45);
}
.metric span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 4px;
font-size: 18px;
letter-spacing: -0.03em;
}
#directMetric strong {
color: var(--teal);
}
#divertedMetric strong {
color: var(--magenta);
}
.impact {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
padding: 10px 11px;
border-radius: 10px;
background: #e8f0ed;
color: #45635d;
font-size: 11px;
font-weight: 700;
}
body.counterfactual .impact {
background: #f9e7ef;
color: #8a3156;
}
.mini-map {
margin-top: 12px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.48);
}
.mini-map-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 9px 10px 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.mini-map svg {
display: block;
width: 100%;
height: 142px;
}
.mini-map text {
font-family: inherit;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.04em;
}
.base-route {
transition: opacity 200ms ease;
}
.cf-route {
opacity: 0.18;
transition: opacity 200ms ease;
}
body.counterfactual .base-route {
opacity: 0.18;
}
body.counterfactual .cf-route {
opacity: 1;
}
.panel-foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 12px;
}
.panel-foot small {
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
#resetCamera {
flex: 0 0 auto;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: white;
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 700;
}
#legend {
position: fixed;
z-index: 9;
right: 24px;
bottom: 24px;
display: flex;
flex-direction: column;
gap: 7px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(250, 249, 243, 0.87);
box-shadow: 0 10px 30px rgba(32, 55, 50, 0.08);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 10px;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 22px;
height: 5px;
border-radius: 2px;
}
.swatch.link {
background: var(--teal);
}
.swatch.detour {
background: var(--magenta);
}
.swatch.enclosure {
border: 2px solid var(--amber);
background: rgba(231, 154, 37, 0.16);
}
#instructions {
position: fixed;
z-index: 8;
left: 50%;
bottom: 23px;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 999px;
background: rgba(250, 249, 243, 0.72);
color: rgba(23, 49, 47, 0.6);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
}
#worldLabels {
position: fixed;
z-index: 7;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
display: none;
transform: translate(-50%, -100%);
white-space: nowrap;
padding: 6px 8px;
border: 1px solid rgba(23, 49, 47, 0.12);
border-radius: 7px;
background: rgba(250, 249, 243, 0.9);
box-shadow: 0 5px 14px rgba(23, 49, 47, 0.1);
color: var(--ink);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.world-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 7px;
font-weight: 650;
letter-spacing: 0.04em;
}
.world-label.block {
border-color: rgba(19, 139, 134, 0.25);
}
.world-label.enclosure {
border-color: rgba(231, 154, 37, 0.5);
background: rgba(255, 244, 216, 0.94);
color: var(--amber-dark);
}
.world-label.route {
border-color: rgba(213, 63, 121, 0.3);
color: #9d2d59;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #e5ece8;
color: var(--ink);
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-mark {
text-align: center;
}
.loading-cube {
width: 36px;
height: 36px;
margin: 0 auto 14px;
background: var(--amber);
box-shadow:
10px 9px 0 rgba(231, 154, 37, 0.45),
-8px 7px 0 rgba(19, 139, 134, 0.35);
animation: breathe 1.2s ease-in-out infinite alternate;
}
.loading-mark strong {
display: block;
font-size: 12px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
@keyframes breathe {
to {
transform: translateY(-5px) rotate(4deg);
}
}
@media (max-width: 820px) {
.topbar {
top: 15px;
left: 15px;
}
h1 {
max-width: 330px;
font-size: 27px;
}
.subtitle {
display: none;
}
#statePill {
top: 15px;
right: 15px;
max-width: 43vw;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#counterNotice {
top: 60px;
right: 15px;
}
.panel {
left: 12px;
bottom: 12px;
width: min(370px, calc(100vw - 24px));
max-height: 48vh;
padding: 14px;
}
.description {
margin-bottom: 10px;
}
.mini-map,
.panel-foot small {
display: none;
}
#legend {
display: none;
}
#instructions {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel model of a Brasília superquadra"></div>
<header class="topbar">
<div class="eyebrow">Urban systems teaching model</div>
<h1>Brasília<br>Superquadra</h1>
<p class="subtitle">
Explore how a hypothetical enclosure beneath one residential block
changes pedestrian connectivity through the shared green.
</p>
</header>
<div id="statePill">Baseline network</div>
<aside id="counterNotice" aria-live="polite">
<strong>Teaching counterfactual active</strong>
<span>
Not a proposed building. The amber enclosure is a hypothetical
condition used to demonstrate route relocation.
</span>
</aside>
<section class="panel" aria-label="Counterfactual controls and explanation">
<div class="panel-head">
<h2>Enclose the undercroft?</h2>
<span class="not-proposal">Not a proposal</span>
</div>
<p class="description">
The enclosure occupies the pilotis beneath <strong>Bloco 04</strong>.
Its direct connection to the central commons is removed, relocating
the east–green walking link to a controlled gate on the north side.
</p>
<div class="scenario-control">
<div>
<strong>Under-block enclosure</strong>
<small id="toggleHelp" aria-live="polite">Baseline condition</small>
</div>
<button
id="scenarioToggle"
type="button"
aria-pressed="false"
aria-describedby="toggleHelp"
aria-label="Toggle hypothetical under-block enclosure"
></button>
</div>
<div class="metrics">
<div class="metric" id="directMetric">
<span>Baseline link</span>
<strong>12.3 m</strong>
</div>
<div class="metric" id="divertedMetric">
<span>Diverted link</span>
<strong>22.5 m</strong>
</div>
</div>
<div class="impact" id="impactText">
<span>Network condition</span>
<strong>Direct connection open</strong>
</div>
<div class="mini-map" aria-label="Schematic of changed pedestrian connectivity">
<div class="mini-map-head">
<span>Shared-green connectivity</span>
<span id="networkStatus">Baseline</span>
</div>
<svg viewBox="0 0 320 142" role="img" aria-label="Four blocks around a shared green">
<rect x="55" y="16" width="210" height="110" rx="3" fill="#dce8d7"/>
<rect x="54" y="5" width="212" height="13" rx="2" fill="#c9c5ba"/>
<rect x="54" y="124" width="212" height="13" rx="2" fill="#c9c5ba"/>
<rect x="43" y="16" width="13" height="110" rx="2" fill="#c9c5ba"/>
<rect x="264" y="16" width="13" height="110" rx="2" fill="#c9c5ba"/>
<path d="M160 71 H264" stroke="#e7e0d1" stroke-width="8"/>
<path d="M160 71 V17 M160 71 V124" stroke="#e7e0d1" stroke-width="7"/>
<path
class="base-route"
d="M160 71 H259"
fill="none"
stroke="#138b86"
stroke-width="5"
stroke-linecap="square"
/>
<path
class="cf-route"
d="M160 71 V34 H258"
fill="none"
stroke="#d53f79"
stroke-width="5"
stroke-linecap="square"
stroke-linejoin="miter"
/>
<rect x="248" y="56" width="20" height="30" rx="2" fill="#e79a25" opacity="0.75"/>
<circle cx="160" cy="71" r="6" fill="#17312f"/>
<text x="160" y="73" text-anchor="middle" fill="#fff">C</text>
<text x="258" y="45" text-anchor="middle" fill="#9b5b08">04</text>
<text x="81" y="76" fill="#49625d">SHARED GREEN</text>
</svg>
</div>
<div class="panel-foot">
<small>
Click Bloco 04 to toggle · C toggles scenario · R resets view
</small>
<button id="resetCamera" type="button">Reset view</button>
</div>
</section>
<aside id="legend" aria-label="Scene legend">
<div class="legend-row">
<span class="swatch link"></span>
<span>Existing commons link</span>
</div>
<div class="legend-row">
<span class="swatch detour"></span>
<span>Counterfactual detour</span>
</div>
<div class="legend-row">
<span class="swatch enclosure"></span>
<span>Hypothetical enclosure</span>
</div>
</aside>
<div id="instructions">drag to orbit · scroll to zoom · shift-drag to pan · click a block</div>
<div id="worldLabels" aria-hidden="true">
<div class="world-label block" id="blockLabel">
Bloco 04
<small>selected undercroft</small>
</div>
<div class="world-label enclosure" id="enclosureLabel">
Hypothetical enclosure
<small>teaching counterfactual</small>
</div>
<div class="world-label route" id="directLabel">
Direct commons link
<small>baseline condition</small>
</div>
<div class="world-label route" id="divertedLabel">
Relocated link
<small>counterfactual condition</small>
</div>
<div class="world-label" id="greenLabel">
Shared green
<small>central commons</small>
</div>
</div>
<div id="loading">
<div class="loading-mark">
<div class="loading-cube"></div>
<strong>Building the superquadra</strong>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const host = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e8);
scene.fog = new THREE.Fog(0xdce8e8, 75, 135);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
host.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf7fbf3, 0x7b8c82, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3d4, 3.1);
sun.position.set(-28, 46, 26);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -42;
sun.shadow.camera.right = 42;
sun.shadow.camera.top = 38;
sun.shadow.camera.bottom = -38;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbcd8e8, 0.65);
fill.position.set(32, 18, -28);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const palette = {
concrete: 0xd6d1c6,
concreteLight: 0xe4dfd5,
concreteDark: 0xb8b3aa,
glass: 0x315f65,
glass2: 0x6b9290,
glass3: 0x9a7654,
teal: 0x138b86,
magenta: 0xd53f79,
amber: 0xe79a25,
path: 0xe9dfca,
lawn: 0xaec995,
lawnDark: 0x8eae78,
road: 0x68716f,
curb: 0xc8c4b8,
base: 0xb8c4b6
};
const materials = {
concrete: new THREE.MeshStandardMaterial({
color: palette.concrete,
roughness: 0.9,
flatShading: true
}),
concreteLight: new THREE.MeshStandardMaterial({
color: palette.concreteLight,
roughness: 0.88,
flatShading: true
}),
concreteDark: new THREE.MeshStandardMaterial({
color: palette.concreteDark,
roughness: 0.95,
flatShading: true
}),
glass: new THREE.MeshStandardMaterial({
color: palette.glass,
roughness: 0.35,
metalness: 0.12,
flatShading: true
}),
glass2: new THREE.MeshStandardMaterial({
color: palette.glass2,
roughness: 0.4,
metalness: 0.08,
flatShading: true
}),
glass3: new THREE.MeshStandardMaterial({
color: palette.glass3,
roughness: 0.7,
flatShading: true
}),
path: new THREE.MeshStandardMaterial({
color: palette.path,
roughness: 1,
flatShading: true
}),
lawn: new THREE.MeshStandardMaterial({
color: palette.lawn,
roughness: 1,
flatShading: true
}),
lawnDark: new THREE.MeshStandardMaterial({
color: palette.lawnDark,
roughness: 1,
flatShading: true
}),
road: new THREE.MeshStandardMaterial({
color: palette.road,
roughness: 1,
flatShading: true
}),
curb: new THREE.MeshStandardMaterial({
color: palette.curb,
roughness: 1,
flatShading: true
}),
base: new THREE.MeshStandardMaterial({
color: palette.base,
roughness: 1,
flatShading: true
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x75553c,
roughness: 1,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x477957,
roughness: 1,
flatShading: true
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x69965f,
roughness: 1,
flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x193a3d,
roughness: 0.7,
flatShading: true
})
};
function box(
parent,
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Site and superquadra ground plane
// ------------------------------------------------------------
const site = new THREE.Group();
scene.add(site);
box(site, 66, 1.2, 56, materials.base, 0, -1.15, 0);
box(site, 62, 0.25, 52, materials.lawnDark, 0, -0.42, 0);
// Perimeter roads.
box(site, 6, 0.16, 51, materials.road, -29.2, -0.18, 0, false, true);
box(site, 6, 0.16, 51, materials.road, 29.2, -0.18, 0, false, true);
box(site, 53, 0.16, 5.5, materials.road, 0, -0.18, -24, false, true);
box(site, 53, 0.16, 5.5, materials.road, 0, -0.18, 24, false, true);
// Sidewalks and the raised superquadra platform.
box(site, 3.2, 0.24, 50, materials.curb, -25.4, -0.03, 0);
box(site, 3.2, 0.24, 50, materials.curb, 25.4, -0.03, 0);
box(site, 49, 0.24, 3.2, materials.curb, 0, -0.03, -21.1);
box(site, 49, 0.24, 3.2, materials.curb, 0, -0.03, 21.1);
box(site, 48.5, 0.58, 38.5, materials.concreteLight, 0, 0.05, 0);
box(site, 32, 0.25, 27, materials.lawn, 0, 0.43, 0);
// Central pedestrian network.
box(site, 32, 0.12, 1.85, materials.path, 0, 0.66, 0, false, true);
box(site, 1.85, 0.12, 26.8, materials.path, 0, 0.66, 0, false, true);
// A quiet perimeter loop around the shared green.
box(site, 29.3, 0.11, 1.25, materials.path, 0, 0.65, -11.9, false, true);
box(site, 29.3, 0.11, 1.25, materials.path, 0, 0.65, 11.9, false, true);
box(site, 1.25, 0.11, 24.5, materials.path, -14.2, 0.65, 0, false, true);
box(site, 1.25, 0.11, 24.5, materials.path, 14.2, 0.65, 0, false, true);
// Central plaza and a small abstract Brasília-like sculpture.
box(site, 4.2, 0.16, 4.2, materials.path, -1.15, 0.71, 0, false, true);
box(site, 0.7, 1.7, 0.7, materials.dark, -1.25, 1.58, 0);
box(site, 1.35, 0.48, 0.48, materials.concreteLight, -1.05, 2.47, 0);
box(site, 0.38, 0.9, 0.38, materials.tealAccent ?? materials.glass2, -1.55, 2.97, 0);
// ------------------------------------------------------------
// Voxel residential blocks
// ------------------------------------------------------------
function createResidential(length, depth, seed, accentColor = null) {
const group = new THREE.Group();
const body = box(
group,
length,
5.4,
depth,
materials.concrete,
0,
7.1,
0
);
box(group, length + 0.65, 0.34, depth + 0.55, materials.concreteLight, 0, 9.97, 0);
box(group, length * 0.22, 0.7, depth * 0.32, materials.concreteDark, -length * 0.18, 10.47, 0);
if (accentColor !== null) {
const accent = new THREE.MeshStandardMaterial({
color: accentColor,
roughness: 0.55,
flatShading: true
});
box(group, length + 0.72, 0.18, depth + 0.61, accent, 0, 9.81, 0);
}
// Continuous window ribbons on both long elevations.
box(group, length - 1.7, 1.25, 0.1, materials.glass, 0, 7.15, depth / 2 + 0.055);
box(group, length - 1.7, 1.25, 0.1, materials.glass, 0, 7.15, -depth / 2 - 0.055);
const coloredWindowMaterials = [
materials.glass,
materials.glass2,
materials.glass3
];
const bayCount = Math.floor((length - 2) / 2.45);
for (let i = 0; i < bayCount; i++) {
const x = -length / 2 + 1.4 + i * 2.45;
// White structural mullions.
box(group, 0.16, 5.3, 0.16, materials.concreteLight, x, 7.08, depth / 2 + 0.12);
box(group, 0.16, 5.3, 0.16, materials.concreteLight, x, 7.08, -depth / 2 - 0.12);
// Sparse colored infill gives each slab a modular rhythm.
if ((i + seed) % 4 === 0) {
const wm = coloredWindowMaterials[(i + seed) % coloredWindowMaterials.length];
box(group, 1.65, 1.27, 0.13, wm, x + 1.16, 7.15, depth / 2 + 0.08);
box(group, 1.65, 1.27, 0.13, wm, x + 1.16, 7.15, -depth / 2 - 0.08);
}
// Small projecting balcony slabs.
if ((i + seed) % 3 === 0) {
box(group, 1.9, 0.16, 0.7, materials.concreteLight, x + 0.9, 6.38, depth / 2 + 0.28);
box(group, 1.9, 0.16, 0.7, materials.concreteLight, x + 0.9, 6.38, -depth / 2 - 0.28);
}
}
// Pilotis: two rows of square columns.
const columnSpacing = 3.15;
const columnCount = Math.floor((length - 1) / columnSpacing);
for (let i = 0; i <= columnCount; i++) {
const x = -length / 2 + 0.8 + i * columnSpacing;
for (const z of [-depth * 0.31, depth * 0.31]) {
box(group, 0.42, 3.72, 0.42, materials.concreteDark, x, 2.43, z);
}
}
// Ground-floor service volume, leaving the undercroft visually open.
box(group, 4.4, 2.85, depth * 0.6, materials.concrete, -length * 0.28, 1.95, 0);
return { group, body };
}
const north = createResidential(32.5, 4.15, 0);
north.group.position.set(0, 0, -15.25);
site.add(north.group);
const south = createResidential(32.5, 4.15, 1);
south.group.position.set(0, 0, 15.25);
site.add(south.group);
const west = createResidential(26.2, 4.15, 2);
west.group.position.set(-16.7, 0, 0);
west.group.rotation.y = Math.PI / 2;
site.add(west.group);
const east = createResidential(26.2, 4.15, 3, palette.teal);
east.group.position.set(16.7, 0, 0);
east.group.rotation.y = Math.PI / 2;
site.add(east.group);
const selectedBody = east.body;
// ------------------------------------------------------------
// Trees, shrubs, benches, street details
// ------------------------------------------------------------
function addTree(parent, x, z, size = 1) {
const trunkHeight = 2.0 * size;
box(parent, 0.42 * size, trunkHeight, 0.42 * size, materials.trunk, x, 0.65 + trunkHeight / 2, z);
box(parent, 2.25 * size, 1.65 * size, 2.15 * size, materials.leaf, x, 3.0 * size, z);
box(parent, 1.5 * size, 1.25 * size, 1.55 * size, materials.leafLight, x + 0.55 * size, 3.9 * size, z + 0.15 * size);
box(parent, 1.25 * size, 0.9 * size, 1.3 * size, materials.leaf, x - 0.65 * size, 3.75 * size, z - 0.2 * size);
}
const treePositions = [
[-11.8, -9.6, 1.05],
[-9.4, -10.6, 0.85],
[-6.8, -10.2, 1.0],
[-11.9, 8.7, 0.9],
[-8.8, 10.4, 1.08],
[-5.8, 10.2, 0.82],
[10.8, 9.8, 0.95],
[12.5, 7.8, 1.08],
[10.4, -9.6, 0.82],
[-22, -10, 1.0],
[-22, 8, 0.9],
[22.8, -8.5, 1.05],
[22.8, 8.2, 0.85]
];
for (const [x, z, size] of treePositions) {
addTree(site, x, z, size);
}
function addShrub(x, z) {
box(site, 1.45, 0.72, 1.25, materials.leaf, x, 1.0, z);
box(site, 0.75, 0.9, 0.85, materials.leafLight, x + 0.7, 1.12, z + 0.1);
}
[
[-7.1, -8.8],
[-7.1, 8.8],
[7.1, 8.8],
[12.8, 3.2],
[-12.7, -3.2]
].forEach(([x, z]) => addShrub(x, z));
function addBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
box(bench, 2.3, 0.18, 0.55, materials.trunk, 0, 1.25, 0);
box(bench, 2.3, 0.65, 0.14, materials.trunk, 0, 1.55, -0.25);
box(bench, 0.2, 0.7, 0.5, materials.concreteDark, -0.85, 0.88, 0);
box(bench, 0.2, 0.7, 0.5, materials.concreteDark, 0.85, 0.88, 0);
site.add(bench);
}
addBench(-4.3, 2.6);
addBench(5.2, -3.1, Math.PI);
addBench(-8.4, -6.7, Math.PI / 2);
// Small voxel cars around the perimeter.
const carMaterials = [
new THREE.MeshStandardMaterial({ color: 0xe8e4d9, roughness: 0.65 }),
new THREE.MeshStandardMaterial({ color: 0x466e78, roughness: 0.65 }),
new THREE.MeshStandardMaterial({ color: 0xb35345, roughness: 0.65 })
];
function addCar(x, z, rotation, colorIndex) {
const car = new THREE.Group();
car.position.set(x, -0.02, z);
car.rotation.y = rotation;
box(car, 1.4, 0.55, 2.7, carMaterials[colorIndex], 0, 0.45, 0);
box(car, 1.15, 0.55, 1.35, materials.glass, 0, 0.92, -0.15);
box(car, 0.18, 0.65, 0.65, materials.dark, -0.71, 0.35, 0.8);
box(car, 0.18, 0.65, 0.65, materials.dark, 0.71, 0.35, 0.8);
site.add(car);
}
addCar(-29.2, -11, Math.PI / 2, 0);
addCar(-29.2, 9, Math.PI / 2, 1);
addCar(29.2, 2, Math.PI / 2, 2);
addCar(13, -24, 0, 1);
addCar(-18, 24, Math.PI, 0);
// ------------------------------------------------------------
// Connectivity paths
// ------------------------------------------------------------
const directMaterial = new THREE.MeshBasicMaterial({
color: palette.teal,
transparent: true,
opacity: 0.96,
toneMapped: false
});
const divertedMaterial = new THREE.MeshBasicMaterial({
color: palette.magenta,
transparent: true,
opacity: 0,
depthWrite: false,
toneMapped: false
});
const directRoute = new THREE.Group();
const divertedRoute = new THREE.Group();
scene.add(directRoute, divertedRoute);
function routeSegment(parent, x1, z1, x2, z2, width, material, y = 0.79) {
const length = Math.abs(x2 - x1) + Math.abs(z2 - z1);
const alongX = Math.abs(x2 - x1) > Math.abs(z2 - z1);
return box(
parent,
alongX ? length : width,
0.075,
alongX ? width : length,
material,
(x1 + x2) / 2,
y,
(z1 + z2) / 2,
false,
false
);
}
routeSegment(directRoute, 2.3, 0, 14.55, 0, 0.42, directMaterial);
box(directRoute, 0.72, 0.09, 0.72, directMaterial, 2.3, 0.8, 0, false, false);
box(directRoute, 0.72, 0.09, 0.72, directMaterial, 14.55, 0.8, 0, false, false);
routeSegment(divertedRoute, 2.3, 0, 2.3, -10.2, 0.42, divertedMaterial);
routeSegment(divertedRoute, 2.3, -10.2, 14.55, -10.2, 0.42, divertedMaterial);
box(divertedRoute, 0.72, 0.09, 0.72, divertedMaterial, 2.3, 0.8, 0, false, false);
box(divertedRoute, 0.72, 0.09, 0.72, divertedMaterial, 2.3, 0.8, -10.2, false, false);
box(divertedRoute, 0.72, 0.09, 0.72, divertedMaterial, 14.55, 0.8, -10.2, false, false);
// ------------------------------------------------------------
// Hypothetical enclosure beneath Bloco 04
// ------------------------------------------------------------
const enclosure = new THREE.Group();
enclosure.visible = false;
scene.add(enclosure);
const fadeMaterials = [];
function fadedMaterial(parameters, baseOpacity) {
const material = new THREE.MeshStandardMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
roughness: 0.7,
flatShading: true,
...parameters
});
fadeMaterials.push({ material, baseOpacity });
return material;
}
const amberPanel = fadedMaterial({
color: palette.amber
}, 0.14);
const amberSolid = fadedMaterial({
color: palette.amber
}, 0.9);
const amberDark = fadedMaterial({
color: 0xb46b0d
}, 0.95);
const gateMaterial = fadedMaterial({
color: palette.magenta,
emissive: palette.magenta,
emissiveIntensity: 0.18
}, 0.45);
// Undercroft floor and roof.
box(enclosure, 4.05, 0.08, 26.1, amberPanel, 16.7, 0.67, 0, false, false);
box(enclosure, 4.15, 0.12, 26.2, amberSolid, 16.7, 4.32, 0, false, false);
// West elevation panels, leaving a controlled gate around z = -10.2.
box(enclosure, 0.08, 3.25, 1.8, amberPanel, 14.61, 2.45, -12.15);
box(enclosure, 0.08, 3.25, 22.0, amberPanel, 14.61, 2.45, 2.0);
// East and end panels.
box(enclosure, 0.08, 3.25, 26.1, amberPanel, 18.79, 2.45, 0);
box(enclosure, 4.12, 3.25, 0.08, amberPanel, 16.7, 2.45, -13.02);
box(enclosure, 4.12, 3.25, 0.08, amberPanel, 16.7, 2.45, 13.02);
// Voxel structural studs on the western face.
for (let z = -12.5; z <= 12.5; z += 2.5) {
box(enclosure, 0.16, 3.48, 0.16, amberDark, 14.56, 2.45, z, false, false);
}
// Roof grid.
for (let z = -12.5; z <= 12.5; z += 2.5) {
box(enclosure, 4.2, 0.15, 0.12, amberDark, 16.7, 4.28, z, false, false);
}
box(enclosure, 0.13, 0.15, 26.1, amberDark, 14.65, 4.28, 0, false, false);
box(enclosure, 0.13, 0.15, 26.1, amberDark, 18.75, 4.28, 0, false, false);
// Controlled gate at the relocated access point.
box(enclosure, 0.12, 3.35, 0.15, amberDark, 14.52, 2.45, -11.15);
box(enclosure, 0.12, 3.35, 0.15, amberDark, 14.52, 2.45, -9.25);
box(enclosure, 0.12, 0.15, 2.05, amberDark, 14.52, 4.03, -10.2);
box(enclosure, 0.08, 2.95, 1.72, gateMaterial, 14.48, 2.35, -10.2, false, false);
// Closure marker on the former direct access.
const closureGroup = new THREE.Group();
closureGroup.visible = false;
scene.add(closureGroup);
const closureMaterial = new THREE.MeshBasicMaterial({
color: 0xcf3e3e,
transparent: true,
opacity: 0,
toneMapped: false
});
const closurePanel = new THREE.MeshBasicMaterial({
color: 0xe36b5e,
transparent: true,
opacity: 0,
depthWrite: false,
toneMapped: false
});
box(closureGroup, 0.08, 3.1, 3.1, closurePanel, 14.48, 2.35, 0, false, false);
const barA = box(closureGroup, 0.18, 2.25, 0.28, closureMaterial, 14.4, 2.35, 0, false, false);
const barB = box(closureGroup, 0.18, 2.25, 0.28, closureMaterial, 14.4, 2.35, 0, false, false);
barA.rotation.x = Math.PI / 4;
barB.rotation.x = -Math.PI / 4;
// ------------------------------------------------------------
// Small voxel pedestrians
// ------------------------------------------------------------
const personMaterial = new THREE.MeshStandardMaterial({
color: 0x294e59,
roughness: 0.9,
flatShading: true
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xc98e66,
roughness: 0.95,
flatShading: true
});
function addPerson(x, z, colorMaterial = personMaterial, scale = 1) {
const person = new THREE.Group();
person.position.set(x, 0.75, z);
person.scale.setScalar(scale);
box(person, 0.34, 0.75, 0.28, colorMaterial, 0, 0.42, 0, false, false);
box(person, 0.3, 0.3, 0.3, skinMaterial, 0, 0.95, 0, false, false);
box(person, 0.18, 0.5, 0.18, materials.dark, -0.1, 0, 0, false, false);
box(person, 0.18, 0.5, 0.18, materials.dark, 0.1, 0, 0, false, false);
site.add(person);
}
addPerson(6.3, 0.55);
addPerson(-3.4, -4.7, materials.glass3, 0.95);
addPerson(7.5, -10.0, materials.glass2, 0.9);
addPerson(-10.1, 4.5, materials.glass3, 0.88);
// ------------------------------------------------------------
// Custom orbit / pan / zoom controls
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 2.7, 0),
radius: 58,
theta: -0.62,
phi: 0.91
};
const defaultControls = {
radius: 58,
theta: -0.62,
phi: 0.91,
target: new THREE.Vector3(0, 2.7, 0)
};
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);
camera.updateMatrixWorld();
}
function resetCamera() {
controls.radius = defaultControls.radius;
controls.theta = defaultControls.theta;
controls.phi = defaultControls.phi;
controls.target.copy(defaultControls.target);
updateCamera();
}
let dragging = false;
let panMode = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let downX = 0;
let downY = 0;
let movedDistance = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panMode = event.shiftKey || event.button === 2;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
downX = event.clientX;
downY = event.clientY;
movedDistance = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) {
if (!dragging) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObject(selectedBody, false).length > 0;
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
}
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
movedDistance += Math.abs(dx) + Math.abs(dy);
lastX = event.clientX;
lastY = event.clientY;
if (panMode) {
const right = new THREE.Vector3(
Math.cos(controls.theta),
0,
-Math.sin(controls.theta)
);
const forward = new THREE.Vector3(
-Math.sin(controls.theta),
0,
-Math.cos(controls.theta)
);
const scale = controls.radius * 0.0013;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, -dy * scale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -18, 18);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -15, 15);
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.38,
1.34
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
panMode = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
const clickDistance =
Math.abs(event.clientX - downX) + Math.abs(event.clientY - downY);
if (clickDistance < 6 && movedDistance < 8) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
if (raycaster.intersectObject(selectedBody, false).length > 0) {
setScenario(scenarioTarget < 0.5);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
panMode = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
35,
88
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// Scenario state and UI
// ------------------------------------------------------------
const scenarioToggle = document.querySelector("#scenarioToggle");
const toggleHelp = document.querySelector("#toggleHelp");
const impactText = document.querySelector("#impactText strong");
const networkStatus = document.querySelector("#networkStatus");
const blockLabel = document.querySelector("#blockLabel");
let scenarioTarget = 0;
let scenarioMix = 0;
function setScenario(enabled) {
scenarioTarget = enabled ? 1 : 0;
document.body.classList.toggle("counterfactual", enabled);
scenarioToggle.setAttribute("aria-pressed", String(enabled));
document.querySelector("#statePill").textContent = enabled ? "Teaching counterfactual" : "Baseline network";
if (enabled) {
toggleHelp.textContent = "Counterfactual condition";
impactText.textContent = "Route relocated · 1.8× longer";
networkStatus.textContent = "Counterfactual";
blockLabel.querySelector("small").textContent = "hypothetical enclosure";
} else {
toggleHelp.textContent = "Baseline condition";
impactText.textContent = "Direct connection open";
networkStatus.textContent = "Baseline";
blockLabel.querySelector("small").textContent = "selected undercroft";
}
}
scenarioToggle.addEventListener("click", () => {
setScenario(scenarioTarget < 0.5);
});
document.querySelector("#resetCamera").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "c") {
setScenario(scenarioTarget < 0.5);
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// ------------------------------------------------------------
// HTML labels projected from 3D positions
// ------------------------------------------------------------
const labelPositions = {
blockLabel: new THREE.Vector3(16.7, 11.2, 0),
enclosureLabel: new THREE.Vector3(16.5, 4.8, -9.7),
directLabel: new THREE.Vector3(8.2, 1.05, 0),
divertedLabel: new THREE.Vector3(8.1, 1.05, -10.2),
greenLabel: new THREE.Vector3(-7.2, 1.0, 7.5)
};
const projected = new THREE.Vector3();
function projectLabel(element, worldPosition, opacity = 1) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
if (!visible || opacity <= 0.001) {
element.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.display = "block";
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = String(opacity);
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-dt * 5.5);
scenarioMix += (scenarioTarget - scenarioMix) * damping;
enclosure.visible = scenarioMix > 0.002;
closureGroup.visible = scenarioMix > 0.002;
for (const entry of fadeMaterials) {
entry.material.opacity = entry.baseOpacity * scenarioMix;
}
divertedMaterial.opacity = scenarioMix * 0.98;
directMaterial.opacity = 0.96 - scenarioMix * 0.66;
closureMaterial.opacity = scenarioMix;
closurePanel.opacity = scenarioMix * 0.16;
const closureScale = 0.78 + scenarioMix * 0.22;
closureGroup.scale.setScalar(closureScale);
const routeLabelOpacity = THREE.MathUtils.clamp(
(scenarioMix - 0.42) / 0.58,
0,
1
);
const enclosureLabelOpacity = THREE.MathUtils.clamp(
(scenarioMix - 0.18) / 0.72,
0,
1
);
renderer.render(scene, camera);
projectLabel(
document.querySelector("#blockLabel"),
labelPositions.blockLabel
);
projectLabel(
document.querySelector("#enclosureLabel"),
labelPositions.enclosureLabel,
enclosureLabelOpacity
);
projectLabel(
document.querySelector("#directLabel"),
labelPositions.directLabel,
1 - routeLabelOpacity * 0.62
);
projectLabel(
document.querySelector("#divertedLabel"),
labelPositions.divertedLabel,
routeLabelOpacity
);
projectLabel(
document.querySelector("#greenLabel"),
labelPositions.greenLabel
);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
updateCamera();
setScenario(false);
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```