Prompt specification
Build or customize the Three.js 3D scene "Paved and planted ground cross-sections" 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: Paved and planted ground cross-sections
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/paved-and-planted-ground-cross-sections-x1221
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring urban heat islands. Create equal-area ground tiles with paving and vegetation, exposing soil and surface layers; label thermal and moisture differences as conceptual rather than measured temperature predictions. Low-poly.
Working Three.js Starter (paved-and-planted-ground-cross-sections-x1221):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Urban Heat Islands — Equal-Area Ground Tiles</title>
<style>
:root {
--ink: #172326;
--muted: #5e6969;
--paper: rgba(249, 247, 239, 0.92);
--line: rgba(23, 35, 38, 0.16);
--accent: #087f7d;
--warm: #df6b4d;
--cool: #4a9e93;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e5dc;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: 0 16px 50px rgba(39, 47, 43, 0.11);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.intro {
position: absolute;
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 310px;
font-size: clamp(27px, 3vw, 40px);
font-weight: 680;
letter-spacing: -0.045em;
line-height: 0.98;
}
.intro-copy {
margin: 12px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.48;
}
.tile-count {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 12px;
color: var(--ink);
font-size: 11px;
font-weight: 700;
}
.tile-count::before {
width: 8px;
height: 8px;
border: 2px solid var(--accent);
border-radius: 2px;
content: "";
}
.disclaimer {
padding: 10px 11px;
border-left: 3px solid #e7a24d;
border-radius: 0 8px 8px 0;
background: rgba(255, 238, 205, 0.72);
color: #654a25;
font-size: 10.5px;
font-weight: 650;
line-height: 1.42;
}
.mode-switch {
position: absolute;
top: 22px;
right: 22px;
display: flex;
padding: 5px;
border-radius: 14px;
pointer-events: auto;
}
.mode-switch button {
padding: 9px 13px;
border: 0;
border-radius: 10px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.mode-switch button:hover {
color: var(--ink);
}
.mode-switch button.active {
background: var(--ink);
color: #fffdf5;
box-shadow: 0 4px 12px rgba(23, 35, 38, 0.2);
}
.mode-switch button:focus-visible,
.layer-toggle:focus-visible,
.close-readout:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.legend {
position: absolute;
bottom: 22px;
left: 22px;
width: 286px;
padding: 16px 17px;
border-radius: 16px;
}
.panel-kicker {
margin: 0 0 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend h2,
.layers h2 {
margin: 0 0 12px;
font-size: 15px;
font-weight: 750;
letter-spacing: -0.02em;
}
.swatch-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 10px;
}
.swatch-item {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 10.5px;
font-weight: 650;
}
.swatch {
width: 14px;
height: 14px;
flex: 0 0 auto;
border: 1px solid rgba(23, 35, 38, 0.14);
border-radius: 4px;
}
.gradient {
height: 12px;
margin: 7px 0 7px;
border: 1px solid rgba(23, 35, 38, 0.08);
border-radius: 999px;
}
.gradient.heat {
background: linear-gradient(90deg, #55aa9c, #e8c36c, #df624b);
}
.gradient.moisture {
background: linear-gradient(90deg, #d8b878, #9cab79, #3f9189);
}
.scale-labels {
display: flex;
justify-content: space-between;
gap: 12px;
color: var(--muted);
font-size: 9.5px;
font-weight: 650;
line-height: 1.25;
}
.scale-labels span:last-child {
text-align: right;
}
.legend-note {
margin: 12px 0 0;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9.5px;
line-height: 1.4;
}
.layers {
position: absolute;
right: 22px;
bottom: 22px;
width: 252px;
padding: 16px 17px;
border-radius: 16px;
}
.layer-list {
display: grid;
gap: 9px;
}
.layer-row {
display: grid;
grid-template-columns: 13px 1fr;
align-items: start;
gap: 9px;
}
.layer-chip {
width: 13px;
height: 13px;
margin-top: 1px;
border: 1px solid rgba(23, 35, 38, 0.14);
border-radius: 3px;
}
.layer-row strong {
display: block;
font-size: 10.5px;
font-weight: 750;
}
.layer-row small {
display: block;
margin-top: 1px;
color: var(--muted);
font-size: 9.5px;
line-height: 1.35;
}
.layer-toggle {
width: 100%;
margin-top: 14px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.62);
color: var(--ink);
cursor: pointer;
font-size: 10.5px;
font-weight: 750;
}
.layer-toggle:hover {
border-color: rgba(8, 127, 125, 0.5);
color: var(--accent);
}
.help {
position: absolute;
bottom: 24px;
left: 50%;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 999px;
background: rgba(249, 247, 239, 0.76);
color: var(--muted);
font-size: 9.5px;
font-weight: 650;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.world-label {
position: fixed;
z-index: 5;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 6px;
background: rgba(250, 248, 240, 0.91);
box-shadow: 0 5px 18px rgba(32, 42, 39, 0.12);
color: var(--ink);
font-size: 8.5px;
font-weight: 850;
letter-spacing: 0.1em;
line-height: 1;
pointer-events: none;
text-transform: uppercase;
transform: translate(9px, -50%);
transition: opacity 140ms ease;
white-space: nowrap;
}
.world-label::before {
position: absolute;
top: 50%;
left: -21px;
width: 21px;
height: 1px;
background: rgba(23, 35, 38, 0.52);
content: "";
}
.world-label::after {
position: absolute;
top: calc(50% - 2px);
left: -24px;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--accent);
content: "";
}
.world-label.left {
transform: translate(calc(-100% - 9px), -50%);
}
.world-label.left::before {
right: -21px;
left: auto;
}
.world-label.left::after {
right: -24px;
left: auto;
}
.world-label.section-label {
border-color: rgba(8, 127, 125, 0.42);
background: rgba(226, 246, 240, 0.92);
color: #075e5d;
}
.readout {
position: relative;
margin-top: 12px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.57);
}
.readout[hidden] {
display: none;
}
.readout-kicker {
color: var(--accent);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.readout h3 {
margin: 4px 24px 9px 0;
font-size: 14px;
font-weight: 780;
}
.readout-row {
display: flex;
justify-content: space-between;
gap: 10px;
padding: 4px 0;
color: var(--muted);
font-size: 10px;
}
.readout-row strong {
color: var(--ink);
font-weight: 750;
text-align: right;
}
.readout small {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 8.5px;
line-height: 1.35;
}
.close-readout {
position: absolute;
top: 8px;
right: 8px;
width: 23px;
height: 23px;
padding: 0;
border: 0;
border-radius: 50%;
background: rgba(23, 35, 38, 0.07);
color: var(--muted);
cursor: pointer;
font-size: 15px;
line-height: 20px;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8e5dc;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
border-radius: 14px;
}
h1 {
max-width: 280px;
font-size: 27px;
}
.intro-copy {
display: none;
}
.tile-count {
margin-bottom: 8px;
}
.disclaimer {
font-size: 9.5px;
}
.mode-switch {
top: 191px;
right: auto;
left: 12px;
width: calc(100vw - 24px);
}
.mode-switch button {
flex: 1;
padding: 9px 7px;
font-size: 10px;
}
.legend {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 12px 14px;
border-radius: 13px;
}
.legend h2 {
margin-bottom: 8px;
}
.legend-note {
margin-top: 8px;
padding-top: 7px;
}
.layers,
.help {
display: none;
}
}
@media (max-height: 650px) and (min-width: 801px) {
.intro-copy,
.legend-note {
display: none;
}
.intro {
width: 315px;
}
.layers {
bottom: 14px;
}
.legend {
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="intro panel">
<p class="eyebrow">Urban climate / material study</p>
<h1>The ground tells a hotter story.</h1>
<p class="intro-copy">
An equal-footprint study of how paving and vegetation can differ in
heat retention and moisture availability.
</p>
<div class="tile-count">49 equal-area ground tiles</div>
<div class="disclaimer">
Conceptual comparison only — relative patterns, not measured
temperature or moisture predictions.
</div>
<section id="readout" class="readout" hidden aria-live="polite">
<button id="closeReadout" class="close-readout" aria-label="Close tile details">×</button>
<div class="readout-kicker">Selected equal-area tile</div>
<h3 id="readoutTitle">Surface</h3>
<div class="readout-row">
<span>Relative heat</span>
<strong id="readoutHeat"></strong>
</div>
<div class="readout-row">
<span>Relative moisture</span>
<strong id="readoutMoisture"></strong>
</div>
<small>Conceptual material relationship. No measured values are implied.</small>
</section>
</header>
<nav class="mode-switch panel" aria-label="Surface visualization mode">
<button class="active" data-mode="material" aria-pressed="true">Material</button>
<button data-mode="heat" aria-pressed="false">Relative heat</button>
<button data-mode="moisture" aria-pressed="false">Moisture</button>
</nav>
<section class="legend panel">
<p class="panel-kicker">Surface key</p>
<h2 id="legendTitle">Material families</h2>
<div id="legendContent"></div>
<p class="legend-note">
The heat and moisture lenses show conceptual material relationships,
not calibrated temperatures, forecasts, or site measurements.
</p>
</section>
<section class="layers panel">
<p class="panel-kicker">Exploded ground section</p>
<h2>Surface and substrate</h2>
<div class="layer-list">
<div class="layer-row">
<span class="layer-chip" style="background:#c7bea8"></span>
<div>
<strong>Surface</strong>
<small>Paving or vegetation cover</small>
</div>
</div>
<div class="layer-row">
<span class="layer-chip" style="background:#b39a76"></span>
<div>
<strong>Mineral sub-base</strong>
<small>Aggregate and bedding layer</small>
</div>
</div>
<div class="layer-row">
<span class="layer-chip" style="background:#8b6248"></span>
<div>
<strong>Soil / substrate</strong>
<small>Ground beneath the built surface</small>
</div>
</div>
</div>
<button id="explodeButton" class="layer-toggle" aria-pressed="true">
Collapse section
</button>
</section>
<div class="help">Drag to orbit · Scroll / pinch to zoom · Click a tile · R resets</div>
</div>
<div id="annotationDense" class="world-label">Dense paving</div>
<div id="annotationGreen" class="world-label">Vegetated ground</div>
<div id="annotationSection" class="world-label section-label">Exploded section</div>
<div id="annotationSurface" class="world-label left">Surface</div>
<div id="annotationSubbase" class="world-label left">Sub-base</div>
<div id="annotationSoil" class="world-label left">Soil</div>
<div id="loading" class="loading">Building the ground study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -----------------------------------------------------------------------
// Renderer, camera, lighting
// -----------------------------------------------------------------------
const host = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e5dc);
scene.fog = new THREE.Fog(0xe8e5dc, 38, 72);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 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 camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraTarget = new THREE.Vector3(0.6, -0.05, 0.2);
let yaw = 0.66;
let pitch = 0.67;
let radius = window.innerWidth < 800 ? 39 : 30;
let cameraTouched = false;
function updateCamera() {
const horizontal = radius * Math.cos(pitch);
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfffdf3, 0x746c5d, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d3, 3.1);
sun.position.set(12, 20, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc5e2df, 0.65);
fill.position.set(-14, 8, -12);
scene.add(fill);
// -----------------------------------------------------------------------
// Materials
// -----------------------------------------------------------------------
const TILE_SIZE = 2.2;
const TILE_STEP = 2.28;
const GRID_SIZE = 7;
const palettes = {
material: {
asphalt: 0x52585a,
paving: 0xc7bea8,
permeable: 0xa99f79,
vegetation: 0x748b55
},
heat: {
asphalt: 0xd85d48,
paving: 0xe89a61,
permeable: 0xd6c46d,
vegetation: 0x55aa9d
},
moisture: {
asphalt: 0xd8b675,
paving: 0xc9ae78,
permeable: 0x75a18d,
vegetation: 0x3f9189
}
};
const surfaceMaterials = {};
for (const type of Object.keys(palettes.material)) {
surfaceMaterials[type] = new THREE.MeshStandardMaterial({
color: palettes.material[type],
roughness: 0.94,
metalness: 0,
flatShading: true
});
}
const soilMaterial = new THREE.MeshStandardMaterial({
color: 0x8b6248,
roughness: 1,
flatShading: true
});
const subbaseMaterial = new THREE.MeshStandardMaterial({
color: 0xb39a76,
roughness: 1,
flatShading: true
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xd5cebd,
roughness: 0.96,
flatShading: true
});
const platformEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xb8b09f,
roughness: 1,
flatShading: true
});
const jointMaterial = new THREE.LineBasicMaterial({
color: 0x746f63,
transparent: true,
opacity: 0.42
});
const roadPaintMaterial = new THREE.MeshStandardMaterial({
color: 0xe9dfbd,
roughness: 0.92
});
const vegetationDetailMaterial = new THREE.MeshStandardMaterial({
color: 0x668447,
roughness: 1,
flatShading: true
});
const permeablePlantMaterial = new THREE.MeshStandardMaterial({
color: 0x788b4e,
roughness: 1,
flatShading: true
});
const asphaltPatchMaterial = new THREE.MeshStandardMaterial({
color: 0x646a69,
roughness: 1,
flatShading: true
});
const treeTrunkMaterial = new THREE.MeshStandardMaterial({
color: 0x76513a,
roughness: 1,
flatShading: true
});
const buildingMaterials = [
new THREE.MeshStandardMaterial({
color: 0xd5cdbb,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xc5bca9,
roughness: 0.92,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xb9b5aa,
roughness: 0.94,
flatShading: true
})
];
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x8f9189,
roughness: 0.95,
flatShading: true
});
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x526568,
roughness: 0.62,
metalness: 0.08
});
// -----------------------------------------------------------------------
// Base platform
// -----------------------------------------------------------------------
const platform = new THREE.Mesh(
new THREE.BoxGeometry(23, 0.28, 19),
platformMaterial
);
platform.position.set(0.4, -0.92, 0.2);
platform.receiveShadow = true;
scene.add(platform);
const platformEdge = new THREE.Mesh(
new THREE.BoxGeometry(23.3, 0.18, 19.3),
platformEdgeMaterial
);
platformEdge.position.set(0.4, -1.15, 0.2);
platformEdge.receiveShadow = true;
scene.add(platformEdge);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xe8e5dc,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.25;
ground.receiveShadow = true;
scene.add(ground);
// -----------------------------------------------------------------------
// Tile layout
// -----------------------------------------------------------------------
const tileRecords = [];
const surfaceMeshes = [];
const buildingSpecs = new Map([
["2,1", { w: 1.35, d: 1.15, h: 3.1 }],
["1,2", { w: 1.20, d: 1.38, h: 2.35 }],
["2,2", { w: 1.42, d: 1.42, h: 4.15 }],
["4,1", { w: 1.36, d: 1.12, h: 2.75 }],
["2,4", { w: 1.45, d: 1.22, h: 3.45 }],
["4,4", { w: 1.25, d: 1.30, h: 2.2 }],
["4,5", { w: 1.40, d: 1.36, h: 3.75 }],
["5,4", { w: 1.18, d: 1.12, h: 2.55 }]
]);
function tileType(column, row) {
if (column === 3 || row === 3) return "asphalt";
const vegetated =
(column <= 1 && row <= 1) ||
(column >= 5 && row >= 5) ||
(column === 5 && row === 1) ||
(column === 0 && row === 4);
if (vegetated) return "vegetation";
const permeable = new Set([
"1,5",
"2,5",
"5,2",
"6,2",
"4,0",
"1,2"
]);
if (permeable.has(`${column},${row}`)) return "permeable";
return "paving";
}
function deterministicRandom(column, row, salt = 0) {
const value = Math.sin(
column * 127.1 + row * 311.7 + salt * 74.7
) * 43758.5453;
return value - Math.floor(value);
}
function addPavingJoints(parent) {
const positions = [];
const offset = TILE_SIZE / 3;
for (const x of [-offset, 0, offset]) {
positions.push(
x, 0.148, -TILE_SIZE / 2 + 0.06,
x, 0.148, TILE_SIZE / 2 - 0.06
);
}
for (const z of [-offset, 0, offset]) {
positions.push(
-TILE_SIZE / 2 + 0.06, 0.148, z,
TILE_SIZE / 2 - 0.06, 0.148, z
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const joints = new THREE.LineSegments(geometry, jointMaterial);
parent.add(joints);
}
function addAsphaltDetails(parent, column, row) {
const patchGeometry = new THREE.CircleGeometry(0.42, 5);
for (let i = 0; i < 2; i++) {
const patch = new THREE.Mesh(
patchGeometry,
asphaltPatchMaterial
);
patch.rotation.x = -Math.PI / 2;
patch.position.set(
(deterministicRandom(column, row, i + 4) - 0.5) * 1.2,
0.146,
(deterministicRandom(column, row, i + 9) - 0.5) * 1.2
);
patch.scale.set(
0.7 + deterministicRandom(column, row, i + 12) * 0.5,
0.7 + deterministicRandom(column, row, i + 15) * 0.5,
1
);
patch.receiveShadow = true;
parent.add(patch);
}
if (column === 3 && row !== 3) {
const marking = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.012, 0.62),
roadPaintMaterial
);
marking.position.y = 0.151;
parent.add(marking);
}
if (row === 3 && column !== 3) {
const marking = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.012, 0.045),
roadPaintMaterial
);
marking.position.y = 0.151;
parent.add(marking);
}
}
function addShrub(parent, x, z, scale = 1, permeable = false) {
const shrub = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.23 * scale, 0),
permeable ? permeablePlantMaterial : vegetationDetailMaterial
);
shrub.position.set(x, 0.2, z);
shrub.scale.set(1, 0.68, 1);
shrub.rotation.y = deterministicRandom(x * 10, z * 10) * Math.PI;
shrub.castShadow = true;
shrub.receiveShadow = true;
parent.add(shrub);
}
function addTree(parent, x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.14, z);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.105, 0.7 * scale, 5),
treeTrunkMaterial
);
trunk.position.y = 0.35 * scale;
trunk.castShadow = true;
tree.add(trunk);
const crownA = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.48 * scale, 0),
vegetationDetailMaterial
);
crownA.position.set(-0.1 * scale, 0.93 * scale, 0.02 * scale);
crownA.scale.set(1, 1.12, 0.95);
crownA.castShadow = true;
tree.add(crownA);
const crownB = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.34 * scale, 0),
vegetationDetailMaterial
);
crownB.position.set(0.22 * scale, 0.78 * scale, -0.05 * scale);
crownB.scale.set(0.9, 1.05, 0.95);
crownB.castShadow = true;
tree.add(crownB);
parent.add(tree);
}
function addVegetationDetails(parent, column, row) {
const treeOffsetX =
(deterministicRandom(column, row, 21) - 0.5) * 0.55;
const treeOffsetZ =
(deterministicRandom(column, row, 22) - 0.5) * 0.55;
if (deterministicRandom(column, row, 23) > 0.18) {
addTree(
parent,
treeOffsetX,
treeOffsetZ,
0.85 + deterministicRandom(column, row, 24) * 0.35
);
}
addShrub(parent, -0.65, 0.62, 0.9);
addShrub(parent, 0.63, -0.55, 0.75);
addShrub(parent, 0.62, 0.68, 0.58);
}
function addPermeableDetails(parent, column, row) {
const pocketMaterial = new THREE.MeshStandardMaterial({
color: 0x625d43,
roughness: 1,
flatShading: true
});
const positions = [
[-0.48, -0.48],
[0.48, -0.48],
[-0.48, 0.48],
[0.48, 0.48]
];
positions.forEach(([x, z], index) => {
const pocket = new THREE.Mesh(
new THREE.BoxGeometry(0.43, 0.025, 0.43),
pocketMaterial
);
pocket.position.set(x, 0.15, z);
pocket.receiveShadow = true;
parent.add(pocket);
addShrub(
parent,
x + (deterministicRandom(column, row, index) - 0.5) * 0.12,
z + (deterministicRandom(column, row, index + 5) - 0.5) * 0.12,
0.48,
true
);
});
}
function addBuilding(parent, spec, column, row) {
const building = new THREE.Group();
const { w, d, h } = spec;
const material =
buildingMaterials[
Math.floor(deterministicRandom(column, row, 41) * buildingMaterials.length)
];
const body = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
body.position.y = 0.14 + h / 2;
body.castShadow = true;
body.receiveShadow = true;
building.add(body);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(w + 0.10, 0.10, d + 0.10),
roofMaterial
);
roof.position.y = 0.14 + h + 0.05;
roof.castShadow = true;
building.add(roof);
if (h > 3.0) {
const rooftop = new THREE.Mesh(
new THREE.BoxGeometry(w * 0.38, 0.28, d * 0.34),
material
);
rooftop.position.set(
w * 0.12,
0.14 + h + 0.24,
-d * 0.08
);
rooftop.castShadow = true;
building.add(rooftop);
}
const floors = Math.max(1, Math.floor(h / 0.72));
for (let floor = 0; floor < floors; floor++) {
const y = 0.14 + 0.43 + floor * 0.68;
for (const side of [-1, 1]) {
const windowFront = new THREE.Mesh(
new THREE.BoxGeometry(0.21, 0.12, 0.015),
windowMaterial
);
windowFront.position.set(
side * w * 0.23,
y,
d / 2 + 0.008
);
building.add(windowFront);
const windowSide = new THREE.Mesh(
new THREE.BoxGeometry(0.015, 0.12, 0.20),
windowMaterial
);
windowSide.position.set(
w / 2 + 0.008,
y,
side * d * 0.22
);
building.add(windowSide);
}
}
parent.add(building);
}
for (let row = 0; row < GRID_SIZE; row++) {
for (let column = 0; column < GRID_SIZE; column++) {
const type = tileType(column, row);
const x = (column - 3) * TILE_STEP;
const z = (row - 3) * TILE_STEP;
const group = new THREE.Group();
group.position.set(x, 0, z);
const soil = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE, 0.56, TILE_SIZE),
soilMaterial
);
soil.position.y = -0.50;
soil.castShadow = true;
soil.receiveShadow = true;
group.add(soil);
const subbase = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE, 0.18, TILE_SIZE),
subbaseMaterial
);
subbase.position.y = -0.11;
subbase.castShadow = true;
subbase.receiveShadow = true;
group.add(subbase);
const surface = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE, 0.14, TILE_SIZE),
surfaceMaterials[type]
);
surface.position.y = 0.07;
surface.castShadow = true;
surface.receiveShadow = true;
surface.userData.tile = {
type,
column,
row,
x,
z
};
group.add(surface);
surfaceMeshes.push(surface);
if (type === "paving") {
addPavingJoints(group);
} else if (type === "asphalt") {
addAsphaltDetails(group, column, row);
} else if (type === "vegetation") {
addVegetationDetails(group, column, row);
} else if (type === "permeable") {
addPermeableDetails(group, column, row);
}
const building = buildingSpecs.get(`${column},${row}`);
if (building) {
addBuilding(group, building, column, row);
}
scene.add(group);
tileRecords.push({
type,
column,
row,
x,
z,
group
});
}
}
// -----------------------------------------------------------------------
// Exploded ground section
// -----------------------------------------------------------------------
const sectionRoot = new THREE.Group();
sectionRoot.position.set(9.15, 0, 6.55);
scene.add(sectionRoot);
const sectionSize = 1.72;
const sectionSoil = new THREE.Mesh(
new THREE.BoxGeometry(sectionSize, 0.56, sectionSize),
soilMaterial
);
sectionSoil.position.y = -0.50;
sectionSoil.castShadow = true;
sectionSoil.receiveShadow = true;
sectionRoot.add(sectionSoil);
const sectionSubbase = new THREE.Mesh(
new THREE.BoxGeometry(sectionSize, 0.18, sectionSize),
subbaseMaterial
);
sectionSubbase.position.y = -0.11;
sectionSubbase.castShadow = true;
sectionSubbase.receiveShadow = true;
sectionRoot.add(sectionSubbase);
const sectionSurface = new THREE.Mesh(
new THREE.BoxGeometry(sectionSize, 0.14, sectionSize),
surfaceMaterials.paving
);
sectionSurface.position.y = 0.07;
sectionSurface.castShadow = true;
sectionSurface.receiveShadow = true;
sectionRoot.add(sectionSurface);
const sectionJointPositions = [];
for (const offset of [-sectionSize / 3, 0, sectionSize / 3]) {
sectionJointPositions.push(
offset, 0.076, -sectionSize / 2,
offset, 0.076, sectionSize / 2,
-sectionSize / 2, 0.076, offset,
sectionSize / 2, 0.076, offset
);
}
const sectionJointGeometry = new THREE.BufferGeometry();
sectionJointGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(sectionJointPositions, 3)
);
sectionSurface.add(
new THREE.LineSegments(sectionJointGeometry, jointMaterial)
);
const guidePositions = [];
for (const x of [-0.72, 0.72]) {
for (const z of [-0.72, 0.72]) {
guidePositions.push(x, -0.21, z, x, 0.83, z);
}
}
const guideGeometry = new THREE.BufferGeometry();
guideGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(guidePositions, 3)
);
const guideMaterial = new THREE.LineDashedMaterial({
color: 0x5e7774,
dashSize: 0.08,
gapSize: 0.055,
transparent: true,
opacity: 0.58
});
const guideLines = new THREE.LineSegments(guideGeometry, guideMaterial);
guideLines.computeLineDistances();
sectionRoot.add(guideLines);
const sectionParts = {
soil: {
mesh: sectionSoil,
base: -0.50,
spread: 0
},
subbase: {
mesh: sectionSubbase,
base: -0.11,
spread: 0.47
},
surface: {
mesh: sectionSurface,
base: 0.07,
spread: 0.86
}
};
let sectionExploded = true;
let sectionExplodeAmount = 1;
const explodeButton = document.querySelector("#explodeButton");
function setSectionExploded(value) {
sectionExploded = value;
explodeButton.setAttribute("aria-pressed", String(value));
explodeButton.textContent = value
? "Collapse section"
: "Explode section";
}
explodeButton.addEventListener("click", () => {
setSectionExploded(!sectionExploded);
});
// -----------------------------------------------------------------------
// Selected-tile outline
// -----------------------------------------------------------------------
const selectionFrame = new THREE.Group();
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0x087f7d
});
const horizontalBar = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE + 0.12, 0.035, 0.045),
selectionMaterial
);
const verticalBar = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.035, TILE_SIZE + 0.12),
selectionMaterial
);
selectionFrame.add(
horizontalBar.clone(),
horizontalBar.clone(),
verticalBar.clone(),
verticalBar.clone()
);
selectionFrame.children[0].position.z = -TILE_SIZE / 2;
selectionFrame.children[1].position.z = TILE_SIZE / 2;
selectionFrame.children[2].position.x = -TILE_SIZE / 2;
selectionFrame.children[3].position.x = TILE_SIZE / 2;
selectionFrame.visible = false;
scene.add(selectionFrame);
// -----------------------------------------------------------------------
// Mode switching and legend
// -----------------------------------------------------------------------
const categoryInfo = {
asphalt: {
label: "Dense asphalt",
heat: "Higher relative retention",
moisture: "Lower relative availability"
},
paving: {
label: "Concrete paving",
heat: "Higher relative retention",
moisture: "Lower relative availability"
},
permeable: {
label: "Permeable paving",
heat: "Intermediate relative retention",
moisture: "Intermediate availability"
},
vegetation: {
label: "Vegetated ground",
heat: "Lower relative retention",
moisture: "Higher relative availability"
}
};
const legendTitle = document.querySelector("#legendTitle");
const legendContent = document.querySelector("#legendContent");
const modeButtons = [...document.querySelectorAll("[data-mode]")];
let currentMode = "material";
function renderLegend(mode) {
if (mode === "material") {
legendTitle.textContent = "Material families";
legendContent.innerHTML = `
<div class="swatch-grid">
<div class="swatch-item">
<span class="swatch" style="background:#52585a"></span>
<span>Asphalt</span>
</div>
<div class="swatch-item">
<span class="swatch" style="background:#c7bea8"></span>
<span>Paving</span>
</div>
<div class="swatch-item">
<span class="swatch" style="background:#a99f79"></span>
<span>Permeable</span>
</div>
<div class="swatch-item">
<span class="swatch" style="background:#748b55"></span>
<span>Vegetation</span>
</div>
</div>
`;
} else if (mode === "heat") {
legendTitle.textContent = "Relative heat lens";
legendContent.innerHTML = `
<div class="gradient heat"></div>
<div class="scale-labels">
<span>Lower relative<br>heat retention</span>
<span>Higher relative<br>heat retention</span>
</div>
`;
} else {
legendTitle.textContent = "Relative moisture lens";
legendContent.innerHTML = `
<div class="gradient moisture"></div>
<div class="scale-labels">
<span>Lower relative<br>availability</span>
<span>Higher relative<br>availability</span>
</div>
`;
}
}
function updateAnnotationText() {
const dense = document.querySelector("#annotationDense");
const green = document.querySelector("#annotationGreen");
if (currentMode === "heat") {
dense.textContent = "Higher relative heat";
green.textContent = "Lower relative heat";
} else if (currentMode === "moisture") {
dense.textContent = "Lower relative moisture";
green.textContent = "Higher relative moisture";
} else {
dense.textContent = "Dense paving";
green.textContent = "Vegetated ground";
}
}
function setMode(mode) {
currentMode = mode;
for (const [type, material] of Object.entries(surfaceMaterials)) {
material.color.setHex(palettes[mode][type]);
}
if (mode === "material") {
vegetationDetailMaterial.color.setHex(0x668447);
permeablePlantMaterial.color.setHex(0x788b4e);
} else if (mode === "heat") {
vegetationDetailMaterial.color.setHex(0x4f9e8f);
permeablePlantMaterial.color.setHex(0x9aaa62);
} else {
vegetationDetailMaterial.color.setHex(0x3f9189);
permeablePlantMaterial.color.setHex(0x57978a);
}
modeButtons.forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
renderLegend(mode);
updateAnnotationText();
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => {
setMode(button.dataset.mode);
});
});
renderLegend(currentMode);
// -----------------------------------------------------------------------
// Projected HTML annotations
// -----------------------------------------------------------------------
const annotationDense = document.querySelector("#annotationDense");
const annotationGreen = document.querySelector("#annotationGreen");
const annotationSection = document.querySelector("#annotationSection");
const annotationSurface = document.querySelector("#annotationSurface");
const annotationSubbase = document.querySelector("#annotationSubbase");
const annotationSoil = document.querySelector("#annotationSoil");
const annotations = [
{
element: annotationDense,
point: new THREE.Vector3(
(4 - 3) * TILE_STEP,
0.52,
(3 - 3) * TILE_STEP
)
},
{
element: annotationGreen,
point: new THREE.Vector3(
(0 - 3) * TILE_STEP,
1.05,
(0 - 3) * TILE_STEP
)
},
{
element: annotationSection,
point: new THREE.Vector3(
sectionRoot.position.x,
1.55,
sectionRoot.position.z
)
},
{
element: annotationSurface,
point: new THREE.Vector3(),
getPoint() {
return new THREE.Vector3(
sectionRoot.position.x - 0.78,
sectionSurface.position.y + 0.08,
sectionRoot.position.z
);
}
},
{
element: annotationSubbase,
point: new THREE.Vector3(),
getPoint() {
return new THREE.Vector3(
sectionRoot.position.x - 0.78,
sectionSubbase.position.y,
sectionRoot.position.z
);
}
},
{
element: annotationSoil,
point: new THREE.Vector3(),
getPoint() {
return new THREE.Vector3(
sectionRoot.position.x - 0.78,
sectionSoil.position.y,
sectionRoot.position.z
);
}
}
];
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
const point = annotation.getPoint
? annotation.getPoint()
: annotation.point;
projected.copy(point).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
annotation.element.style.visibility = visible ? "visible" : "hidden";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
}
}
}
// -----------------------------------------------------------------------
// Tile selection
// -----------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const readout = document.querySelector("#readout");
const readoutTitle = document.querySelector("#readoutTitle");
const readoutHeat = document.querySelector("#readoutHeat");
const readoutMoisture = document.querySelector("#readoutMoisture");
document.querySelector("#closeReadout").addEventListener("click", () => {
readout.hidden = true;
selectionFrame.visible = false;
});
function selectTile(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(surfaceMeshes, false);
if (!hits.length) {
readout.hidden = true;
selectionFrame.visible = false;
return;
}
const tile = hits[0].object.userData.tile;
const info = categoryInfo[tile.type];
readoutTitle.textContent = info.label;
readoutHeat.textContent = info.heat;
readoutMoisture.textContent = info.moisture;
readout.hidden = false;
selectionFrame.position.set(tile.x, 0.165, tile.z);
selectionFrame.visible = true;
}
// -----------------------------------------------------------------------
// Custom camera controls: orbit, wheel zoom, pinch zoom
// -----------------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let primaryPointerId = null;
let lastX = 0;
let lastY = 0;
let gestureMoved = false;
let multiTouchGesture = false;
let previousPinchDistance = 0;
function getPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
const dx = values[0].x - values[1].x;
const dy = values[0].y - values[1].y;
return Math.hypot(dx, dy);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
primaryPointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
gestureMoved = false;
multiTouchGesture = false;
} else if (pointers.size === 2) {
multiTouchGesture = true;
previousPinchDistance = getPinchDistance();
}
cameraTouched = true;
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const distance = getPinchDistance();
if (previousPinchDistance > 0 && distance > 0) {
radius = THREE.MathUtils.clamp(
radius * (previousPinchDistance / distance),
15,
52
);
updateCamera();
}
previousPinchDistance = distance;
gestureMoved = true;
return;
}
if (event.pointerId === primaryPointerId) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
gestureMoved = true;
}
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, 0.30, 1.32);
lastX = event.clientX;
lastY = event.clientY;
cameraTouched = true;
updateCamera();
}
});
function endPointer(event, cancelled = false) {
if (!pointers.has(event.pointerId)) return;
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = 0;
}
if (pointers.size === 0) {
if (!cancelled && !gestureMoved && !multiTouchGesture) {
selectTile(event.clientX, event.clientY);
}
primaryPointerId = null;
}
}
canvas.addEventListener("pointerup", (event) => endPointer(event));
canvas.addEventListener("pointercancel", (event) => endPointer(event, true));
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
15,
52
);
cameraTouched = true;
updateCamera();
},
{ passive: false }
);
function resetCamera() {
yaw = 0.66;
pitch = 0.67;
radius = window.innerWidth < 800 ? 39 : 30;
cameraTarget.set(0.6, -0.05, 0.2);
cameraTouched = false;
updateCamera();
}
window.addEventListener("keydown", (event) => {
const tag = event.target?.tagName;
if (tag === "INPUT" || tag === "TEXTAREA") return;
if (event.key.toLowerCase() === "r") {
resetCamera();
} else if (event.key.toLowerCase() === "e") {
setSectionExploded(!sectionExploded);
} else if (event.key === "ArrowLeft") {
yaw -= 0.1;
updateCamera();
} else if (event.key === "ArrowRight") {
yaw += 0.1;
updateCamera();
} else if (event.key === "ArrowUp") {
pitch = THREE.MathUtils.clamp(pitch + 0.08, 0.30, 1.32);
updateCamera();
} else if (event.key === "ArrowDown") {
pitch = THREE.MathUtils.clamp(pitch - 0.08, 0.30, 1.32);
updateCamera();
} else if (event.key === "+" || event.key === "=") {
radius = THREE.MathUtils.clamp(radius - 1.5, 15, 52);
updateCamera();
} else if (event.key === "-" || event.key === "_") {
radius = THREE.MathUtils.clamp(radius + 1.5, 15, 52);
updateCamera();
}
});
// -----------------------------------------------------------------------
// Resize and animation
// -----------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 800 ? 44 : 36;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height);
if (!cameraTouched) {
radius = width < 800 ? 39 : 30;
updateCamera();
}
}
window.addEventListener("resize", onResize);
function animate() {
requestAnimationFrame(animate);
const targetAmount = sectionExploded ? 1 : 0;
sectionExplodeAmount +=
(targetAmount - sectionExplodeAmount) * 0.085;
for (const part of Object.values(sectionParts)) {
part.mesh.position.y =
part.base + part.spread * sectionExplodeAmount;
}
renderer.render(scene, camera);
updateAnnotations();
}
animate();
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
</script>
</body>
</html>
```