Prompt specification
Build or customize the Three.js 3D scene "Urban cooling scenario explorer" 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: Urban cooling scenario explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/urban-cooling-scenario-explorer-x1224
Scene Description Prompt:
Toggle voxel trees, reflective roofs, and permeable ground on a city block, showing qualitative cooling indicators rather than predictions. One HTML file, Three.js from cdnjs.
Working Three.js Starter (urban-cooling-scenario-explorer-x1224):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cool Block — Qualitative Cooling Cues</title>
<style>
:root {
--ink: #17333a;
--muted: #65777a;
--panel: rgba(250, 253, 251, 0.88);
--line: rgba(27, 64, 68, 0.13);
--green: #167b68;
--green-soft: #d9eee7;
--amber: #bd7a24;
--amber-soft: #f6e8cf;
--blue: #277f9d;
--blue-soft: #dceef4;
--shadow: 0 16px 44px rgba(27, 56, 57, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene-wrap {
position: fixed;
inset: 0;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
min-height: 78px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 16px 24px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
border-radius: 12px;
background: #173f43;
box-shadow: 0 8px 20px rgba(19, 61, 63, 0.18);
overflow: hidden;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
width: 12px;
height: 12px;
border-radius: 3px;
background: #8ed8bd;
transform: rotate(-8deg);
}
.brand-mark::before {
left: 8px;
top: 19px;
}
.brand-mark::after {
left: 22px;
top: 10px;
background: #f2c66f;
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.05;
letter-spacing: 0.09em;
font-weight: 800;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.disclaimer {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 13px;
border: 1px solid rgba(23, 63, 67, 0.12);
border-radius: 999px;
background: rgba(250, 253, 251, 0.76);
color: #4d686b;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.02em;
backdrop-filter: blur(12px);
}
.disclaimer-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(22, 123, 104, 0.11);
}
.small-button {
border: 1px solid rgba(23, 63, 67, 0.14);
border-radius: 10px;
padding: 10px 13px;
background: rgba(250, 253, 251, 0.86);
color: var(--ink);
font-size: 11px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
transform 150ms ease,
background 150ms ease;
}
.small-button:hover {
transform: translateY(-1px);
background: #fff;
}
.small-button:active {
transform: translateY(0);
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(125%);
}
.control-panel {
left: 24px;
top: 92px;
width: 286px;
padding: 18px;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 18px;
letter-spacing: -0.025em;
}
.cue-count {
flex: 0 0 auto;
margin-top: 2px;
padding: 6px 8px;
border-radius: 999px;
background: #e8efec;
color: #627674;
font-size: 10px;
font-weight: 800;
}
.feature-list {
display: grid;
gap: 9px;
}
.feature {
display: grid;
grid-template-columns: 40px 1fr auto;
align-items: center;
gap: 11px;
padding: 11px;
border: 1px solid rgba(23, 63, 67, 0.1);
border-radius: 14px;
background: rgba(255, 255, 255, 0.54);
}
.feature-icon {
display: grid;
place-items: center;
width: 40px;
height: 40px;
border-radius: 11px;
}
.feature-icon svg {
width: 22px;
height: 22px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.feature-icon.trees {
color: var(--green);
background: var(--green-soft);
}
.feature-icon.roofs {
color: var(--amber);
background: var(--amber-soft);
}
.feature-icon.ground {
color: var(--blue);
background: var(--blue-soft);
}
.feature-copy strong {
display: block;
font-size: 13px;
line-height: 1.2;
}
.feature-copy span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.toggle {
position: relative;
width: 43px;
height: 25px;
padding: 0;
border: 0;
border-radius: 999px;
background: #cbd4d1;
cursor: pointer;
transition: background 180ms ease;
}
.toggle::after {
content: "";
position: absolute;
top: 4px;
left: 4px;
width: 17px;
height: 17px;
border-radius: 50%;
background: #fff;
box-shadow: 0 2px 6px rgba(25, 51, 54, 0.22);
transition: transform 180ms ease;
}
.toggle.active {
background: var(--green);
}
.toggle.active::after {
transform: translateX(18px);
}
.toggle:focus-visible,
.small-button:focus-visible,
.view-button:focus-visible {
outline: 3px solid rgba(39, 127, 157, 0.35);
outline-offset: 2px;
}
.method-note {
margin: 15px 2px 0;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.method-note strong {
color: #466064;
}
.text-button {
margin-top: 10px;
padding: 0;
border: 0;
background: transparent;
color: var(--green);
font-size: 10px;
font-weight: 850;
cursor: pointer;
}
.indicator-panel {
right: 24px;
top: 92px;
width: 292px;
padding: 18px;
}
.indicator-panel .panel-heading {
margin-bottom: 12px;
}
.indicator-list {
display: grid;
gap: 8px;
}
.indicator {
display: grid;
grid-template-columns: 34px 1fr;
align-items: center;
gap: 10px;
padding: 10px;
border-radius: 13px;
background: rgba(255, 255, 255, 0.48);
border: 1px solid rgba(23, 63, 67, 0.08);
}
.indicator-symbol {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border-radius: 10px;
font-size: 12px;
font-weight: 900;
}
.indicator:nth-child(1) .indicator-symbol {
color: var(--green);
background: var(--green-soft);
}
.indicator:nth-child(2) .indicator-symbol {
color: var(--amber);
background: var(--amber-soft);
}
.indicator:nth-child(3) .indicator-symbol {
color: var(--blue);
background: var(--blue-soft);
}
.indicator-title {
display: block;
color: #6a7d7e;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.indicator-state {
display: block;
margin-top: 2px;
font-size: 13px;
font-weight: 800;
}
.indicator-state.good {
color: var(--green);
}
.indicator-state.warn {
color: var(--amber);
}
.indicator-detail {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
line-height: 1.3;
}
.qualitative-note {
margin-top: 13px;
padding: 11px 12px;
border-radius: 12px;
background: #edf2ef;
color: #5f7373;
font-size: 10px;
line-height: 1.45;
}
.legend {
position: fixed;
z-index: 8;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 16px;
padding: 10px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(250, 253, 251, 0.84);
box-shadow: 0 9px 30px rgba(28, 59, 60, 0.1);
backdrop-filter: blur(14px);
color: #587072;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
.legend-swatch.green {
background: var(--green);
}
.legend-swatch.amber {
background: #d49b3d;
}
.legend-swatch.blue {
background: var(--blue);
}
.view-controls {
position: fixed;
z-index: 9;
right: 24px;
bottom: 22px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(250, 253, 251, 0.85);
box-shadow: 0 9px 30px rgba(28, 59, 60, 0.1);
backdrop-filter: blur(14px);
}
.view-button {
width: 34px;
height: 34px;
padding: 0;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--ink);
font-size: 18px;
font-weight: 700;
cursor: pointer;
}
.view-button:hover {
background: #e8efec;
}
.view-button.reset {
width: auto;
padding: 0 11px;
font-size: 10px;
font-weight: 850;
}
.scene-tag {
position: fixed;
z-index: 6;
pointer-events: none;
transform: translate(-50%, -100%);
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 9px;
background: rgba(27, 52, 55, 0.88);
color: #fff;
box-shadow: 0 6px 18px rgba(20, 44, 46, 0.18);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
opacity: 0;
transition: opacity 180ms ease;
}
.scene-tag.visible {
opacity: 1;
}
.scene-tag::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
background: rgba(27, 52, 55, 0.88);
transform: translateX(-50%) rotate(45deg);
}
.scene-tag.trees {
background: rgba(18, 105, 87, 0.9);
}
.scene-tag.trees::after {
background: rgba(18, 105, 87, 0.9);
}
.scene-tag.roofs {
background: rgba(169, 111, 28, 0.91);
}
.scene-tag.roofs::after {
background: rgba(169, 111, 28, 0.91);
}
.scene-tag.ground {
background: rgba(29, 108, 135, 0.91);
}
.scene-tag.ground::after {
background: rgba(29, 108, 135, 0.91);
}
@media (max-width: 820px) {
.topbar {
padding: 12px;
}
.disclaimer {
display: none;
}
.control-panel {
top: auto;
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
padding: 13px;
}
.control-panel .panel-heading {
margin-bottom: 9px;
}
.control-panel h2,
.eyebrow,
.method-note,
.text-button {
display: none;
}
.feature-list {
grid-template-columns: repeat(3, 1fr);
}
.feature {
grid-template-columns: 1fr auto;
gap: 7px;
padding: 8px;
}
.feature-icon {
display: none;
}
.feature-copy span {
display: none;
}
.indicator-panel {
top: 72px;
right: 12px;
width: 250px;
padding: 13px;
}
.indicator-panel .panel-heading {
margin-bottom: 8px;
}
.indicator-panel h2 {
font-size: 15px;
}
.indicator {
padding: 7px;
}
.indicator-detail,
.qualitative-note {
display: none;
}
.legend {
display: none;
}
.view-controls {
right: 12px;
bottom: 111px;
}
}
@media (max-width: 480px) {
.brand h1 {
font-size: 14px;
}
.brand p {
display: none;
}
.brand-mark {
width: 36px;
height: 36px;
}
.small-button {
padding: 9px 10px;
}
.indicator-panel {
width: 224px;
}
.feature-copy strong {
font-size: 11px;
}
.toggle {
width: 39px;
height: 23px;
}
.toggle::after {
width: 15px;
height: 15px;
}
.toggle.active::after {
transform: translateX(16px);
}
}
</style>
</head>
<body>
<div id="scene-wrap">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel city block. Drag to orbit, scroll to zoom, and use arrow keys to rotate."
></canvas>
</div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>COOL BLOCK</h1>
<p>Qualitative urban cooling cues</p>
</div>
</div>
<div class="top-actions">
<div class="disclaimer">
<span class="disclaimer-dot"></span>
Illustrative, not predictive
</div>
<button class="small-button" id="resetView">Reset view</button>
</div>
</header>
<section class="panel control-panel" aria-labelledby="controls-title">
<div class="panel-heading">
<div>
<p class="eyebrow">Street-level interventions</p>
<h2 id="controls-title">Cooling elements</h2>
</div>
<span class="cue-count" id="cueCount">3 cues visible</span>
</div>
<div class="feature-list">
<div class="feature">
<div class="feature-icon trees" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M12 21v-7"></path>
<path d="M8 18h8"></path>
<path d="M7 15h10l-2-3H9z"></path>
<path d="M9 12h6l-2-3h-2z"></path>
<path d="M11 9h2V6h-2z"></path>
</svg>
</div>
<div class="feature-copy">
<strong>Voxel trees</strong>
<span>Canopy shade</span>
</div>
<button
class="toggle active"
data-feature="trees"
aria-label="Toggle voxel trees"
aria-pressed="true"
></button>
</div>
<div class="feature">
<div class="feature-icon roofs" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M3 11 12 4l9 7"></path>
<path d="M5 10v10h14V10"></path>
<path d="m9 20 3-6 3 6"></path>
<path d="M12 14v6"></path>
</svg>
</div>
<div class="feature-copy">
<strong>Reflective roofs</strong>
<span>Light reflection</span>
</div>
<button
class="toggle active"
data-feature="roofs"
aria-label="Toggle reflective roofs"
aria-pressed="true"
></button>
</div>
<div class="feature">
<div class="feature-icon ground" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M3 8h18"></path>
<path d="M5 8v11M10 8v11M15 8v11M20 8v11"></path>
<path d="M3 12h18M3 16h18"></path>
<path d="m8 5 4-3 4 3"></path>
</svg>
</div>
<div class="feature-copy">
<strong>Permeable ground</strong>
<span>Water infiltration</span>
</div>
<button
class="toggle active"
data-feature="ground"
aria-label="Toggle permeable ground"
aria-pressed="true"
></button>
</div>
</div>
<p class="method-note">
<strong>Qualitative only.</strong> The indicators describe the direction
of common cooling pathways. They do not estimate temperature, energy,
runoff volume, or real-world performance.
</p>
<button class="text-button" id="resetScenario">Restore all cooling cues</button>
</section>
<section class="panel indicator-panel" aria-labelledby="indicator-title">
<div class="panel-heading">
<div>
<p class="eyebrow">Visible conditions</p>
<h2 id="indicator-title">Cooling indicators</h2>
</div>
</div>
<div class="indicator-list" aria-live="polite">
<div class="indicator" id="indicatorTrees">
<div class="indicator-symbol">T</div>
<div>
<span class="indicator-title">Tree canopy</span>
<span class="indicator-state good">More shade</span>
<span class="indicator-detail">Shaded outdoor surfaces increase</span>
</div>
</div>
<div class="indicator" id="indicatorRoofs">
<div class="indicator-symbol">R</div>
<div>
<span class="indicator-title">Roof response</span>
<span class="indicator-state good">Glare reduced</span>
<span class="indicator-detail">More incident light is redirected</span>
</div>
</div>
<div class="indicator" id="indicatorGround">
<div class="indicator-symbol">G</div>
<div>
<span class="indicator-title">Ground response</span>
<span class="indicator-state good">More infiltration</span>
<span class="indicator-detail">Porous paving can receive water</span>
</div>
</div>
</div>
<div class="qualitative-note">
Directional cues only — no predictions or numerical performance values.
</div>
</section>
<div class="legend" aria-label="Conceptual color legend">
<span class="legend-item">
<span class="legend-swatch green"></span>
Shade
</span>
<span class="legend-item">
<span class="legend-swatch amber"></span>
Reflection
</span>
<span class="legend-item">
<span class="legend-swatch blue"></span>
Infiltration
</span>
</div>
<div class="view-controls" aria-label="Camera controls">
<button class="view-button" id="zoomOut" aria-label="Zoom out">−</button>
<button class="view-button" id="zoomIn" aria-label="Zoom in">+</button>
<button class="view-button reset" id="resetCamera">Reset</button>
</div>
<div class="scene-tag trees" id="tagTrees">Voxel canopy</div>
<div class="scene-tag roofs" id="tagRoofs">Reflective roof</div>
<div class="scene-tag ground" id="tagGround">Permeable paving</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e6);
scene.fog = new THREE.Fog(0xdce9e6, 38, 72);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const camera = new THREE.OrthographicCamera(-20, 20, 13, -13, 0.1, 100);
const cameraState = {
theta: -0.66,
phi: 0.91,
zoom: 1,
target: new THREE.Vector3(0, 1.5, 0)
};
const hemisphere = new THREE.HemisphereLight(0xf4fbff, 0xa28e73, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.1);
sun.position.set(-14, 23, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.0001;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dded, 0.55);
fill.position.set(12, 8, -15);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitPlane = new THREE.PlaneGeometry(1, 1);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xc9c5b4,
roughness: 0.96
}),
road: new THREE.MeshStandardMaterial({
color: 0x596467,
roughness: 0.94
}),
sidewalk: new THREE.MeshStandardMaterial({
color: 0xdeddd3,
roughness: 0.91
}),
curb: new THREE.MeshStandardMaterial({
color: 0xf0eee4,
roughness: 0.86
}),
roadMark: new THREE.MeshStandardMaterial({
color: 0xe7dfbd,
roughness: 0.84
}),
roofBase: new THREE.MeshStandardMaterial({
color: 0x707a78,
roughness: 0.86
}),
equipment: new THREE.MeshStandardMaterial({
color: 0x596765,
roughness: 0.7,
metalness: 0.22
}),
window: new THREE.MeshStandardMaterial({
color: 0x8ba2a4,
emissive: 0x19383d,
emissiveIntensity: 0.14,
roughness: 0.26,
metalness: 0.18
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x775d42,
roughness: 0.96
}),
leafDark: new THREE.MeshStandardMaterial({
color: 0x246653,
roughness: 0.92
}),
leafMid: new THREE.MeshStandardMaterial({
color: 0x3b8064,
roughness: 0.9
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x69a878,
roughness: 0.9
}),
shade: new THREE.MeshBasicMaterial({
color: 0x2c967b,
transparent: true,
opacity: 0.11,
depthWrite: false,
side: THREE.DoubleSide
}),
reflective: new THREE.MeshStandardMaterial({
color: 0xe6dcc1,
roughness: 0.18,
metalness: 0.82,
envMapIntensity: 0.8
}),
roofSeam: new THREE.MeshStandardMaterial({
color: 0x9b967e,
roughness: 0.42,
metalness: 0.58
}),
roofGlint: new THREE.MeshBasicMaterial({
color: 0xffcf68,
transparent: true,
opacity: 0.9
}),
porousBed: new THREE.MeshStandardMaterial({
color: 0x7e9b9d,
roughness: 1
}),
paverA: new THREE.MeshStandardMaterial({
color: 0x4f91a1,
roughness: 0.96
}),
paverB: new THREE.MeshStandardMaterial({
color: 0x79a8a4,
roughness: 0.96
}),
paverC: new THREE.MeshStandardMaterial({
color: 0x3d7f8e,
roughness: 0.96
}),
waterRing: new THREE.MeshBasicMaterial({
color: 0xb8eff2,
transparent: true,
opacity: 0.48,
depthWrite: false,
side: THREE.DoubleSide
})
};
function cube(
width,
height,
depth,
material,
x,
y,
z,
parent = scene,
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;
}
function plane(material, x, y, z, width, height, rotationY = 0, parent = scene) {
const mesh = new THREE.Mesh(unitPlane, material);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, 1);
mesh.rotation.y = rotationY;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Urban base and streets.
cube(29, 0.3, 24, materials.ground, 0, -0.17, 0);
cube(29, 0.06, 4.8, materials.road, 0, 0.015, 0);
cube(4.8, 0.07, 24, materials.road, 0, 0.025, 0);
const plotCenters = [
[-7.65, -6.45],
[7.65, -6.45],
[-7.65, 6.45],
[7.65, 6.45]
];
for (const [x, z] of plotCenters) {
cube(10.1, 0.16, 7.8, materials.sidewalk, x, 0.11, z);
cube(10.22, 0.1, 0.18, materials.curb, x, 0.16, z + 3.9);
cube(10.22, 0.1, 0.18, materials.curb, x, 0.16, z - 3.9);
cube(0.18, 0.1, 7.8, materials.curb, x - 5.05, 0.16, z);
cube(0.18, 0.1, 7.8, materials.curb, x + 5.05, 0.16, z);
}
// Lane dashes.
for (let x = -12.5; x <= 12.5; x += 1.55) {
if (Math.abs(x) < 3.1) continue;
cube(0.72, 0.025, 0.09, materials.roadMark, x, 0.085, 0);
}
for (let z = -10.4; z <= 10.5; z += 1.55) {
if (Math.abs(z) < 3.1) continue;
cube(0.09, 0.025, 0.72, materials.roadMark, 0, 0.095, z);
}
// Crosswalk bands near the intersection.
for (let i = 0; i < 6; i++) {
const x = -3.25 + i * 0.7;
cube(0.38, 0.026, 1.05, materials.roadMark, x, 0.102, -3.05);
cube(0.38, 0.026, 1.05, materials.roadMark, x, 0.102, 3.05);
}
for (let i = 0; i < 6; i++) {
const z = -3.25 + i * 0.7;
cube(1.05, 0.026, 0.38, materials.roadMark, -3.05, 0.112, z);
cube(1.05, 0.026, 0.38, materials.roadMark, 3.05, 0.112, z);
}
const treeLayer = new THREE.Group();
const roofLayer = new THREE.Group();
const groundLayer = new THREE.Group();
scene.add(treeLayer, roofLayer, groundLayer);
const buildingData = [
{
x: -8.0,
z: -6.1,
w: 6.2,
d: 4.8,
h: 5.4,
color: 0xc9bbaa,
band: 0xdfd4c4
},
{
x: 7.2,
z: -6.0,
w: 7.0,
d: 4.9,
h: 8.2,
color: 0xd5c4b2,
band: 0xeadccb
},
{
x: -8.0,
z: 6.0,
w: 6.5,
d: 4.7,
h: 3.5,
color: 0xaebab6,
band: 0xd3ddd9
},
{
x: 7.2,
z: 6.0,
w: 7.2,
d: 4.8,
h: 5.8,
color: 0xc5aaa0,
band: 0xe0c8bc
}
];
const roofGlints = [];
function addWindows(data, base) {
const floorCount = Math.max(1, Math.floor((data.h - 0.5) / 2.05));
for (let floor = 0; floor < floorCount; floor++) {
const y = base + 1.25 + floor * 2.05;
const frontCols = Math.max(2, Math.floor(data.w / 1.35));
const sideCols = Math.max(2, Math.floor(data.d / 1.35));
for (let col = 0; col < frontCols; col++) {
const x =
data.x - data.w / 2 + ((col + 1) * data.w) / (frontCols + 1);
plane(materials.window, x, y, data.z + data.d / 2 + 0.012, 0.6, 0.78);
plane(
materials.window,
x,
y,
data.z - data.d / 2 - 0.012,
0.6,
0.78,
Math.PI
);
}
for (let col = 0; col < sideCols; col++) {
const z =
data.z - data.d / 2 + ((col + 1) * data.d) / (sideCols + 1);
plane(
materials.window,
data.x + data.w / 2 + 0.012,
y,
z,
0.58,
0.78,
Math.PI / 2
);
plane(
materials.window,
data.x - data.w / 2 - 0.012,
y,
z,
0.58,
0.78,
-Math.PI / 2
);
}
}
}
for (const data of buildingData) {
const base = 0.26;
const bodyMaterial = new THREE.MeshStandardMaterial({
color: data.color,
roughness: 0.84
});
const bandMaterial = new THREE.MeshStandardMaterial({
color: data.band,
roughness: 0.8
});
cube(
data.w,
data.h,
data.d,
bodyMaterial,
data.x,
base + data.h / 2,
data.z
);
for (let floor = 1; floor < data.h / 2; floor += 1) {
cube(
data.w + 0.08,
0.12,
data.d + 0.08,
bandMaterial,
data.x,
base + floor * 2.05,
data.z
);
}
cube(
data.w + 0.16,
0.16,
data.d + 0.16,
materials.curb,
data.x,
base + data.h,
data.z
);
addWindows(data, base);
// Small rooftop equipment remains visible with or without reflective panels.
cube(
1.05,
0.55,
0.8,
materials.equipment,
data.x - data.w * 0.23,
base + data.h + 0.43,
data.z - data.d * 0.16
);
cube(
0.62,
0.28,
0.62,
materials.equipment,
data.x + data.w * 0.22,
base + data.h + 0.3,
data.z + data.d * 0.13
);
// Reflective roof panels.
const roofY = base + data.h + 0.13;
cube(
data.w * 0.94,
0.14,
data.d * 0.94,
materials.reflective,
data.x,
roofY,
data.z,
roofLayer
);
for (let i = 1; i < 4; i++) {
const seamX = data.x - (data.w * 0.94) / 2 + (data.w * 0.94 * i) / 4;
cube(
0.035,
0.035,
data.d * 0.9,
materials.roofSeam,
seamX,
roofY + 0.09,
data.z,
roofLayer,
false,
true
);
}
for (let i = 1; i < 3; i++) {
const seamZ = data.z - (data.d * 0.94) / 2 + (data.d * 0.94 * i) / 3;
cube(
data.w * 0.9,
0.035,
0.035,
materials.roofSeam,
data.x,
roofY + 0.095,
seamZ,
roofLayer,
false,
true
);
}
const glint = cube(
1.05,
0.045,
0.13,
materials.roofGlint,
data.x,
roofY + 0.12,
data.z,
roofLayer,
false,
false
);
glint.userData.startX = data.x;
glint.userData.span = data.w * 0.32;
roofGlints.push(glint);
}
const treePositions = [
[-4.45, -4.2],
[-4.45, -8.2],
[-11.0, -3.7],
[-11.2, -8.5],
[4.35, -4.35],
[4.35, -8.35],
[11.2, -3.7],
[11.0, -8.3],
[-11.1, 3.65],
[-4.55, 3.7],
[-4.45, 8.6],
[4.35, 3.7],
[11.2, 3.7],
[4.45, 8.6]
];
function createTree(x, z, index) {
const tree = new THREE.Group();
tree.position.set(x, 0.2, z);
treeLayer.add(tree);
const scale = 0.88 + ((index * 7) % 5) * 0.035;
cube(
0.36,
1.65,
0.36,
materials.trunk,
0,
0.82,
0,
tree
);
cube(
1.85,
1.25,
1.8,
materials.leafDark,
0,
2.05,
0,
tree
);
cube(
1.42,
1.15,
1.38,
materials.leafMid,
-0.04,
2.96,
0.03,
tree
);
cube(
0.85,
0.82,
0.9,
materials.leafLight,
0.53,
2.3,
-0.38,
tree
);
cube(
0.72,
0.72,
0.78,
materials.leafLight,
-0.55,
2.45,
0.35,
tree
);
tree.scale.setScalar(scale);
const halo = new THREE.Mesh(
new THREE.CircleGeometry(1.45, 20),
materials.shade
);
halo.rotation.x = -Math.PI / 2;
halo.position.set(x, 0.205, z);
halo.renderOrder = 1;
treeLayer.add(halo);
}
treePositions.forEach(createTree);
function createPermeablePatch(centerX, centerZ, cols, rows, phase) {
const spacing = 0.69;
const width = cols * spacing;
const depth = rows * spacing;
cube(
width + 0.16,
0.045,
depth + 0.16,
materials.porousBed,
centerX,
0.218,
centerZ,
groundLayer,
false,
true
);
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const x = centerX - width / 2 + spacing / 2 + col * spacing;
const z = centerZ - depth / 2 + spacing / 2 + row * spacing;
const variant = (row + col + phase) % 3;
const material =
variant === 0
? materials.paverA
: variant === 1
? materials.paverB
: materials.paverC;
cube(
0.57,
0.08,
0.57,
material,
x,
0.285,
z,
groundLayer,
false,
true
);
if ((row + col + phase) % 4 === 0) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.11, 0.16, 16),
materials.waterRing
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, 0.33, z);
groundLayer.add(ring);
}
}
}
}
createPermeablePatch(-8.45, -3.12, 7, 2, 0);
createPermeablePatch(7.9, -3.12, 8, 2, 1);
createPermeablePatch(-8.1, 3.13, 8, 2, 2);
createPermeablePatch(8.1, 3.13, 8, 2, 0);
// Small street details.
const benchMaterial = new THREE.MeshStandardMaterial({
color: 0x8a6f50,
roughness: 0.9
});
const benchPositions = [
[-5.1, 5.1],
[5.1, 7.2],
[10.8, -5.1]
];
for (const [x, z] of benchPositions) {
cube(1.55, 0.16, 0.48, benchMaterial, x, 0.65, z);
cube(0.16, 0.5, 0.4, materials.equipment, x - 0.55, 0.38, z);
cube(0.16, 0.5, 0.4, materials.equipment, x + 0.55, 0.38, z);
}
const featureState = {
trees: true,
roofs: true,
ground: true
};
const layerMap = {
trees: treeLayer,
roofs: roofLayer,
ground: groundLayer
};
const indicatorCopy = {
trees: {
on: ["More shade", "Shaded outdoor surfaces increase", "good"],
off: ["Less shade", "Shaded outdoor surfaces are reduced", "warn"]
},
roofs: {
on: ["Glare reduced", "More incident light is redirected", "good"],
off: ["Glare exposed", "Roof response is less reflective", "warn"]
},
ground: {
on: ["More infiltration", "Porous paving can receive water", "good"],
off: ["More runoff", "Water remains on sealed ground", "warn"]
}
};
function updateFeature(key) {
const isOn = featureState[key];
const button = document.querySelector(`[data-feature="${key}"]`);
const indicator = document.getElementById(`indicator${key[0].toUpperCase()}${key.slice(1)}`);
button.classList.toggle("active", isOn);
button.setAttribute("aria-pressed", String(isOn));
layerMap[key].visible = isOn;
const [label, detail, tone] = indicatorCopy[key][isOn ? "on" : "off"];
const stateElement = indicator.querySelector(".indicator-state");
stateElement.textContent = label;
stateElement.className = `indicator-state ${tone}`;
indicator.querySelector(".indicator-detail").textContent = detail;
const count = Object.values(featureState).filter(Boolean).length;
document.getElementById("cueCount").textContent = `${count} cue${count === 1 ? "" : "s"} visible`;
}
document.querySelectorAll("[data-feature]").forEach((button) => {
button.addEventListener("click", () => {
const key = button.dataset.feature;
featureState[key] = !featureState[key];
updateFeature(key);
});
});
document.getElementById("resetScenario").addEventListener("click", () => {
Object.keys(featureState).forEach((key) => {
featureState[key] = true;
updateFeature(key);
});
});
function updateCamera() {
const radius = 38;
const { theta, phi, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = -0.66;
cameraState.phi = 0.91;
cameraState.zoom = 1;
cameraState.target.set(0, 1.5, 0);
updateCamera();
}
function zoomBy(factor) {
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * factor,
0.68,
1.85
);
updateCamera();
}
document.getElementById("resetView").addEventListener("click", resetCamera);
document.getElementById("resetCamera").addEventListener("click", resetCamera);
document.getElementById("zoomIn").addEventListener("click", () => zoomBy(1.14));
document.getElementById("zoomOut").addEventListener("click", () => zoomBy(0.88));
// Direct orbit controls: drag to rotate, wheel/pinch-free buttons to zoom.
let pointerActive = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
pointerActive = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerActive) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (event.shiftKey) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const panUp = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
cameraState.target.addScaledVector(right, -dx * 0.025);
cameraState.target.x += panUp.x * dy * 0.02;
cameraState.target.z += panUp.z * dy * 0.02;
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.46,
1.32
);
}
updateCamera();
});
function endPointer(event) {
pointerActive = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoomBy(Math.exp(-event.deltaY * 0.001));
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") cameraState.theta += 0.08;
else if (key === "ArrowRight") cameraState.theta -= 0.08;
else if (key === "ArrowUp") {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - 0.06, 0.46, 1.32);
} else if (key === "ArrowDown") {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + 0.06, 0.46, 1.32);
} else if (key === "+" || key === "=") {
zoomBy(1.1);
return;
} else if (key === "-") {
zoomBy(0.9);
return;
} else {
return;
}
event.preventDefault();
updateCamera();
});
const tags = [
{
element: document.getElementById("tagTrees"),
position: new THREE.Vector3(-4.45, 4.25, -4.2),
key: "trees"
},
{
element: document.getElementById("tagRoofs"),
position: new THREE.Vector3(7.2, 9.35, -6),
key: "roofs"
},
{
element: document.getElementById("tagGround"),
position: new THREE.Vector3(-8.45, 0.75, -3.12),
key: "ground"
}
];
const projected = new THREE.Vector3();
function updateTags() {
const width = canvas.clientWidth;
const height = canvas.clientHeight;
for (const tag of tags) {
if (!featureState[tag.key]) {
tag.element.classList.remove("visible");
continue;
}
projected.copy(tag.position).project(camera);
if (projected.z < -1 || projected.z > 1) {
tag.element.classList.remove("visible");
continue;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
tag.element.style.left = `${x}px`;
tag.element.style.top = `${y}px`;
tag.element.classList.add("visible");
}
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = 13;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
function animate(time) {
requestAnimationFrame(animate);
for (let i = 0; i < roofGlints.length; i++) {
const glint = roofGlints[i];
const phase = time * 0.00065 + i * 1.7;
glint.position.x =
glint.userData.startX + Math.sin(phase) * glint.userData.span;
glint.scale.x = 0.65 + (Math.sin(phase * 1.6) + 1) * 0.32;
}
updateTags();
renderer.render(scene, camera);
}
resize();
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```