Prompt specification
Build or customize the Three.js 3D scene "Neighborhood heat teaching model" 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: Neighborhood heat teaching model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-heat-teaching-model-x1223
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts urban heat islands. Compose a dense block, park, water feature, and open square; use clearly synthetic temperature colors and show that surface type, shade, and airflow are distinct factors. Voxel style.
Working Three.js Starter (neighborhood-heat-teaching-model-x1223):
```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 — Voxel Climate Study</title>
<style>
:root {
--bg: #0b1320;
--panel: rgba(14, 23, 36, 0.86);
--border: rgba(183, 218, 255, 0.16);
--text: #edf5ff;
--muted: #9eb0c6;
--cyan: #67f3ff;
--violet: #8b8cff;
--orange: #ff9a61;
--green: #72e1a8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
user-select: none;
}
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
header {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 16px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
header p {
max-width: 370px;
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#factors {
top: 22px;
right: 22px;
width: 250px;
padding: 13px;
border-radius: 16px;
}
.factor-heading {
padding: 2px 4px 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.factor-button {
width: 100%;
margin: 0 0 7px;
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
color: var(--text);
cursor: pointer;
text-align: left;
transition: background 160ms, opacity 160ms, border-color 160ms;
}
.factor-button:hover {
background: rgba(255, 255, 255, 0.075);
border-color: rgba(255, 255, 255, 0.16);
}
.factor-button[aria-pressed="false"] {
opacity: 0.42;
}
.factor-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
font-weight: 800;
}
.factor-description {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 2px;
}
.swatch.surface {
background: linear-gradient(
90deg,
#ef5368 0 25%,
#58d99e 25% 50%,
#39c9d2 50% 75%,
#e5bd58 75%
);
}
.swatch.shade {
background: var(--violet);
}
.swatch.airflow {
background: var(--cyan);
}
#legend {
bottom: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 15px 17px 14px;
border-radius: 15px;
}
.legend-title {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.legend-title span:last-child {
color: var(--muted);
font-weight: 600;
letter-spacing: 0.04em;
}
.gradient {
height: 11px;
border-radius: 3px;
background: linear-gradient(
90deg,
#35d4d0 0%,
#58dc9d 20%,
#c4df70 36%,
#ffc857 54%,
#ff7d4f 73%,
#eb4e68 88%,
#a43874 100%
);
box-shadow: 0 0 20px rgba(255, 100, 90, 0.12);
}
.ticks {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.legend-note {
margin-top: 9px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
#help {
right: 22px;
bottom: 22px;
padding: 11px 13px;
border-radius: 12px;
color: var(--muted);
font-size: 10px;
}
#help button {
margin-left: 9px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 7px;
background: rgba(255, 255, 255, 0.05);
color: var(--text);
cursor: pointer;
font: inherit;
}
#help button:hover {
background: rgba(255, 255, 255, 0.1);
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.scene-label,
.temp-label {
position: absolute;
top: 0;
left: 0;
white-space: nowrap;
will-change: transform;
}
.scene-label {
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 8px;
background: rgba(8, 15, 25, 0.78);
box-shadow: 0 7px 20px rgba(0, 0, 0, 0.2);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scene-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
background: rgba(255, 255, 255, 0.28);
content: "";
}
.label-sub {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 7px;
font-weight: 650;
letter-spacing: 0.05em;
}
.temp-label {
padding: 4px 6px;
border-radius: 6px;
background: rgba(8, 15, 25, 0.8);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 800;
}
.temp-label.hot {
color: #ff8b77;
}
.temp-label.warm {
color: #ffd06a;
}
.temp-label.cool {
color: #7ce9bb;
}
.temp-label.cold {
color: #76eef3;
}
@media (max-width: 760px) {
header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
header p {
display: none;
}
#factors {
top: 112px;
right: 12px;
width: 190px;
padding: 9px;
}
.factor-description,
.factor-heading {
display: none;
}
.factor-button {
margin-bottom: 4px;
padding: 7px 8px;
}
.factor-title {
font-size: 10px;
}
#legend {
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 11px 13px;
}
.legend-note {
display: none;
}
#help {
display: none;
}
.scene-label:not(.essential) {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="panel">
<div class="eyebrow">Voxel Climate Study / Concept Model</div>
<h1>Urban Heat Islands</h1>
<p>
A synthetic block-scale study showing how material, shade, and moving air
influence surface temperature independently.
</p>
</header>
<aside id="factors" class="panel">
<div class="factor-heading">Independent layers</div>
<button class="factor-button" data-layer="surface" aria-pressed="true">
<span class="factor-title">
<span class="swatch surface"></span>
Surface type
</span>
<span class="factor-description">
Material glyphs distinguish façades, grass, paving, and water.
</span>
</button>
<button class="factor-button" data-layer="shade" aria-pressed="true">
<span class="factor-title">
<span class="swatch shade"></span>
Shade
</span>
<span class="factor-description">
Violet cells mark cooling from blocked direct sunlight.
</span>
</button>
<button class="factor-button" data-layer="airflow" aria-pressed="true">
<span class="factor-title">
<span class="swatch airflow"></span>
Airflow
</span>
<span class="factor-description">
Cyan vectors reveal cooling corridors through the block.
</span>
</button>
</aside>
<aside id="legend" class="panel">
<div class="legend-title">
<span>Synthetic surface temperature</span>
<span>Illustrative data</span>
</div>
<div class="gradient"></div>
<div class="ticks">
<span>18°C</span>
<span>25°C</span>
<span>32°C</span>
<span>39°C</span>
<span>44°C</span>
</div>
<div class="legend-note">
Colors are deliberately synthetic—not satellite observations or live data.
</div>
</aside>
<div id="help" class="panel">
Drag to orbit · Scroll to zoom
<button id="reset">Reset</button>
</div>
<div id="labels" aria-hidden="true"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labels");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1320);
scene.fog = new THREE.Fog(0x0b1320, 34, 58);
const camera = new THREE.OrthographicCamera(-15, 15, 10, -10, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xdceaff, 0x28323f, 1.7);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d5, 3.2);
sun.position.set(-11, 19, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x62b8ff, 0.75);
rim.position.set(10, 8, -12);
scene.add(rim);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
...options
});
}
function addBox(
parent,
mat,
x,
y,
z,
width,
height,
depth,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Independent visual layers
// ---------------------------------------------------------------------
const surfaceLayer = new THREE.Group();
const shadeLayer = new THREE.Group();
const airflowLayer = new THREE.Group();
scene.add(surfaceLayer, shadeLayer, airflowLayer);
// ---------------------------------------------------------------------
// Shared materials
// ---------------------------------------------------------------------
const baseMat = material(0x182436);
const baseEdgeMat = material(0x253650);
const roadMat = material(0x303b48);
const roadMarkMat = material(0xd7c98d, { roughness: 0.7 });
const denseGroundMat = material(0xdb5965);
const parkGroundMat = material(0x57d69a);
const squareGroundMat = material(0xe4b956);
const waterMat = material(0x31c6d0, {
roughness: 0.28,
metalness: 0.08
});
const pathMat = material(0xd7c99a);
const pavingA = material(0xe9c65f);
const pavingB = material(0xf0d172);
const pavingC = material(0xd3a650);
const trunkMat = material(0x765139);
const leafMatA = material(0x39b978);
const leafMatB = material(0x55d695);
const leafMatC = material(0x2da66f);
const darkMat = material(0x263341);
const roofUnitMat = material(0x596170);
const windowMat = material(0x172638, { roughness: 0.48 });
const shadeMat = new THREE.MeshBasicMaterial({
color: 0x7479ff,
transparent: true,
opacity: 0.27,
depthWrite: false,
side: THREE.DoubleSide
});
const flowLineMat = new THREE.LineDashedMaterial({
color: 0x67f3ff,
dashSize: 0.38,
gapSize: 0.18,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const flowArrowMat = new THREE.MeshBasicMaterial({
color: 0x67f3ff,
depthWrite: false
});
const flowPacketMat = new THREE.MeshBasicMaterial({
color: 0xd8ffff
});
// ---------------------------------------------------------------------
// Voxel plinth and streets
// ---------------------------------------------------------------------
addBox(scene, baseMat, 0, -0.78, 0, 26, 1.2, 18);
addBox(scene, baseEdgeMat, 0, -0.18, 0, 25.6, 0.3, 17.6);
addBox(scene, roadMat, 0, 0.01, 0, 25.2, 0.16, 17.2);
// Perimeter lane markings.
for (let x = -10.8; x <= 10.8; x += 2.2) {
addBox(scene, roadMarkMat, x, 0.105, 7.75, 1.05, 0.025, 0.12, false, false);
addBox(scene, roadMarkMat, x, 0.105, -7.75, 1.05, 0.025, 0.12, false, false);
}
for (let z = -6.5; z <= 6.5; z += 2.2) {
addBox(scene, roadMarkMat, -11.75, 0.105, z, 0.12, 0.025, 1.05, false, false);
addBox(scene, roadMarkMat, 11.75, 0.105, z, 0.12, 0.025, 1.05, false, false);
}
// Main pedestrian and vehicle corridors.
addBox(scene, roadMat, -0.15, 0.11, 0.1, 1.05, 0.2, 15.8);
addBox(scene, roadMat, 6.55, 0.11, -0.15, 15.8, 0.2, 0.8);
// ---------------------------------------------------------------------
// Dense block
// ---------------------------------------------------------------------
addBox(
scene,
denseGroundMat,
-6.35,
0.13,
-3.8,
9.2,
0.24,
8.0
);
const buildingSpecs = [
[-9.2, -6.35, 1.72, 1.85, 5.6],
[-6.35, -6.5, 1.85, 1.85, 6.45],
[-3.45, -6.25, 1.75, 1.85, 4.55],
[-9.05, -3.72, 1.85, 1.85, 4.05],
[-6.25, -3.9, 1.95, 1.9, 5.45],
[-3.42, -3.58, 1.78, 1.82, 3.3],
[-9.2, -1.02, 1.72, 1.72, 3.05],
[-6.3, -1.08, 1.78, 1.78, 4.15],
[-3.35, -0.98, 1.78, 1.72, 2.75]
];
const hotMaterials = [
material(0xff744f),
material(0xe94d67),
material(0xff8e50),
material(0xdc4968),
material(0xf05c58),
material(0xff8450),
material(0xeb536d),
material(0xff704e),
material(0xd94770)
];
const roofMaterials = [
material(0xffa05c),
material(0xf27172),
material(0xffb267),
material(0xe96b79),
material(0xfa7c68),
material(0xffa665),
material(0xf06f7c),
material(0xff8f60),
material(0xe76d83)
];
const windowInstances = [];
function windowTransform(x, y, z, sx, sy, sz) {
windowInstances.push({ x, y, z, sx, sy, sz });
}
buildingSpecs.forEach((spec, index) => {
const [x, z, width, depth, height] = spec;
const baseY = 0.25;
addBox(
scene,
hotMaterials[index],
x,
baseY + height / 2,
z,
width,
height,
depth
);
addBox(
scene,
roofMaterials[index],
x,
baseY + height + 0.06,
z,
width + 0.08,
0.12,
depth + 0.08
);
// Rooftop mechanical units.
addBox(
scene,
roofUnitMat,
x + width * 0.12,
baseY + height + 0.27,
z - depth * 0.08,
0.43,
0.35,
0.5
);
if (index % 3 === 0) {
addBox(
scene,
darkMat,
x - width * 0.2,
baseY + height + 0.25,
z + depth * 0.14,
0.5,
0.3,
0.42
);
}
// Window grids on all four façades.
const floors = Math.max(2, Math.floor((height - 0.6) / 0.78));
for (let floor = 0; floor < floors; floor++) {
const wy = baseY + 0.64 + floor * 0.78;
for (const offset of [-width * 0.24, width * 0.24]) {
windowTransform(
x + offset,
wy,
z + depth / 2 + 0.035,
0.34,
0.27,
0.06
);
windowTransform(
x + offset,
wy,
z - depth / 2 - 0.035,
0.34,
0.27,
0.06
);
}
for (const offset of [-depth * 0.24, depth * 0.24]) {
windowTransform(
x + width / 2 + 0.035,
wy,
z + offset,
0.06,
0.27,
0.34
);
windowTransform(
x - width / 2 - 0.035,
wy,
z + offset,
0.06,
0.27,
0.34
);
}
}
});
const windowMesh = new THREE.InstancedMesh(
unitBox,
windowMat,
windowInstances.length
);
const dummy = new THREE.Object3D();
windowInstances.forEach((w, i) => {
dummy.position.set(w.x, w.y, w.z);
dummy.scale.set(w.sx, w.sy, w.sz);
dummy.updateMatrix();
windowMesh.setMatrixAt(i, dummy.matrix);
});
windowMesh.instanceMatrix.needsUpdate = true;
windowMesh.castShadow = false;
windowMesh.receiveShadow = true;
windowMesh.computeBoundingSphere();
scene.add(windowMesh);
// ---------------------------------------------------------------------
// Park
// ---------------------------------------------------------------------
addBox(
scene,
parkGroundMat,
6.2,
0.13,
-4.1,
9.0,
0.24,
7.2
);
// Park paths.
addBox(surfaceLayer, pathMat, 5.95, 0.29, -4.2, 8.0, 0.07, 0.48);
addBox(surfaceLayer, pathMat, 6.2, 0.30, -4.2, 0.48, 0.07, 6.3);
function addTree(parent, x, z, scale = 1, baseY = 0.25) {
addBox(
parent,
trunkMat,
x,
baseY + 0.34 * scale,
z,
0.18 * scale,
0.68 * scale,
0.18 * scale
);
addBox(
parent,
leafMatA,
x,
baseY + 0.92 * scale,
z,
0.82 * scale,
0.7 * scale,
0.82 * scale
);
addBox(
parent,
leafMatB,
x + 0.2 * scale,
baseY + 1.18 * scale,
z - 0.12 * scale,
0.53 * scale,
0.48 * scale,
0.53 * scale
);
addBox(
parent,
leafMatC,
x - 0.23 * scale,
baseY + 1.08 * scale,
z + 0.17 * scale,
0.45 * scale,
0.43 * scale,
0.48 * scale
);
}
const treePositions = [
[2.55, -6.35, 0.9],
[4.35, -6.55, 1.05],
[7.05, -6.65, 0.88],
[9.45, -5.95, 1.05],
[2.4, -3.55, 1.0],
[4.45, -3.65, 0.86],
[7.25, -3.65, 1.08],
[9.4, -3.45, 0.91],
[2.6, -1.25, 0.88],
[4.35, -1.15, 1.02],
[7.25, -1.2, 0.92],
[9.4, -1.1, 1.08]
];
treePositions.forEach(([x, z, scale]) => {
addTree(scene, x, z, scale, 0.25);
});
// Pixel grass tufts: surface-type glyphs.
const grassPositions = [
[3.35, -5.6], [3.7, -2.8], [5.4, -5.55], [5.55, -2.75],
[6.65, -5.55], [8.05, -2.85], [8.15, -5.55], [10.0, -4.9],
[3.25, -1.8], [5.5, -1.8], [8.3, -1.8]
];
grassPositions.forEach(([x, z]) => {
addBox(surfaceLayer, leafMatC, x, 0.34, z, 0.09, 0.24, 0.09, false, false);
addBox(surfaceLayer, leafMatB, x + 0.11, 0.29, z + 0.04, 0.08, 0.16, 0.08, false, false);
});
// Park bench.
addBox(scene, darkMat, 5.55, 0.55, -2.7, 1.25, 0.16, 0.32);
addBox(scene, darkMat, 5.55, 0.83, -2.86, 1.25, 0.48, 0.1);
addBox(scene, roofUnitMat, 5.15, 0.36, -2.7, 0.12, 0.3, 0.26);
addBox(scene, roofUnitMat, 5.95, 0.36, -2.7, 0.12, 0.3, 0.26);
// ---------------------------------------------------------------------
// Open square
// ---------------------------------------------------------------------
addBox(
scene,
squareGroundMat,
-1.8,
0.13,
4.2,
5.65,
0.24,
6.1
);
// Individual paving tiles make the surface type visually distinct.
for (let ix = 0; ix < 7; ix++) {
for (let iz = 0; iz < 7; iz++) {
const x = -4.0 + ix * 0.72;
const z = 1.7 + iz * 0.72;
const tileMat = (ix + iz) % 3 === 0 ? pavingC : (ix % 2 ? pavingA : pavingB);
addBox(
surfaceLayer,
tileMat,
x,
0.285,
z,
0.66,
0.07,
0.66,
false,
true
);
}
}
// Central voxel monument.
addBox(scene, material(0x475266), -1.8, 0.56, 4.15, 1.15, 0.55, 1.15);
addBox(scene, material(0x67758a), -1.8, 1.08, 4.15, 0.78, 0.55, 0.78);
addBox(scene, material(0x76d9d2), -1.8, 1.62, 4.15, 0.42, 0.55, 0.42);
addBox(scene, material(0xffbc63), -1.8, 2.13, 4.15, 0.22, 0.48, 0.22);
// Square planters and trees.
const squareTrees = [
[-4.05, 1.65],
[-4.05, 6.55],
[0.45, 1.65],
[0.45, 6.55]
];
squareTrees.forEach(([x, z]) => {
addBox(scene, darkMat, x, 0.4, z, 0.68, 0.36, 0.68);
addTree(scene, x, z, 0.68, 0.53);
});
// Benches around the square.
addBox(scene, darkMat, -3.2, 0.55, 5.9, 1.35, 0.16, 0.3);
addBox(scene, darkMat, -0.25, 0.55, 2.45, 1.35, 0.16, 0.3);
// ---------------------------------------------------------------------
// Water feature
// ---------------------------------------------------------------------
addBox(
scene,
waterMat,
6.8,
0.14,
3.65,
6.35,
0.27,
5.75
);
// Pool edge.
const waterEdgeMat = material(0x7d8993);
addBox(scene, waterEdgeMat, 6.8, 0.34, 0.83, 6.55, 0.3, 0.2);
addBox(scene, waterEdgeMat, 6.8, 0.34, 6.47, 6.55, 0.3, 0.2);
addBox(scene, waterEdgeMat, 3.62, 0.34, 3.65, 0.2, 0.3, 5.65);
addBox(scene, waterEdgeMat, 9.98, 0.34, 3.65, 0.2, 0.3, 5.65);
// Pixel ripples: surface-type glyphs.
const rippleMat = material(0x9cf4ef, {
roughness: 0.25,
metalness: 0.05
});
const ripples = [
[4.8, 2.2, 1.3, 0.1],
[6.1, 1.55, 1.8, 0.1],
[7.7, 2.5, 1.45, 0.1],
[5.2, 4.35, 1.0, 0.1],
[7.25, 4.6, 1.75, 0.1],
[8.6, 5.45, 1.1, 0.1],
[6.45, 5.8, 1.3, 0.1]
];
ripples.forEach(([x, z, width, depth]) => {
addBox(
surfaceLayer,
rippleMat,
x,
0.31,
z,
width,
0.045,
depth,
false,
false
);
});
// Cubic fountain.
addBox(scene, material(0x85929a), 6.8, 0.48, 3.65, 0.8, 0.4, 0.8);
addBox(scene, waterMat, 6.8, 0.95, 3.65, 0.42, 0.55, 0.42);
addBox(scene, rippleMat, 6.8, 1.36, 3.65, 0.16, 0.35, 0.16);
addBox(scene, rippleMat, 6.8, 1.56, 3.65, 0.42, 0.16, 0.42);
// ---------------------------------------------------------------------
// Shade cells: intentionally violet and separate from physical shadows
// ---------------------------------------------------------------------
const shadeCells = [
[-7.72, -3.7, 0.58, 5.8],
[-4.82, -3.7, 0.58, 5.8],
[-1.65, -5.8, 1.05, 1.8],
[3.35, -4.0, 1.3, 1.4],
[8.2, -3.8, 1.25, 1.5],
[-3.4, 2.2, 1.25, 1.05],
[0.0, 5.65, 1.2, 1.0]
];
shadeCells.forEach(([x, z, width, depth]) => {
addBox(
shadeLayer,
shadeMat,
x,
0.315,
z,
width,
0.035,
depth,
false,
false
);
});
// Small violet markers make the shade layer legible from high angles.
const shadeEdgeMat = new THREE.MeshBasicMaterial({
color: 0xa7a6ff,
transparent: true,
opacity: 0.62,
depthWrite: false
});
shadeCells.forEach(([x, z, width, depth], index) => {
addBox(
shadeLayer,
shadeEdgeMat,
x,
0.34,
z + depth / 2 - 0.04,
Math.max(0.22, width * 0.75),
0.035,
0.06,
false,
false
);
});
// ---------------------------------------------------------------------
// Airflow: dashed curves, arrowheads, and animated packets
// ---------------------------------------------------------------------
const flowRecords = [];
const arrowGeometry = new THREE.ConeGeometry(0.14, 0.42, 4);
const packetGeometry = new THREE.BoxGeometry(0.13, 0.13, 0.13);
function addFlow(points) {
const curve = new THREE.CatmullRomCurve3(
points.map(([x, y, z]) => new THREE.Vector3(x, y, z)),
false,
"catmullrom",
0.4
);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(90)
);
const line = new THREE.Line(geometry, flowLineMat);
line.computeLineDistances();
airflowLayer.add(line);
[0.24, 0.58, 0.84].forEach((t) => {
const arrow = new THREE.Mesh(arrowGeometry, flowArrowMat);
arrow.position.copy(curve.getPointAt(t));
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
curve.getTangentAt(t).normalize()
);
airflowLayer.add(arrow);
});
const packet = new THREE.Mesh(packetGeometry, flowPacketMat);
airflowLayer.add(packet);
flowRecords.push({ curve, packet });
}
addFlow([
[-1.15, 0.55, 7.15],
[-0.65, 0.8, 4.3],
[-0.85, 1.08, 1.45],
[-1.45, 1.42, -1.15],
[-1.4, 1.72, -4.1],
[-1.18, 1.95, -6.75]
]);
addFlow([
[1.85, 0.5, 2.2],
[2.4, 0.72, -0.9],
[4.05, 0.96, -3.05],
[6.45, 1.22, -4.95],
[9.45, 1.42, -6.65]
]);
addFlow([
[9.65, 0.5, 6.55],
[9.15, 0.7, 4.0],
[8.55, 0.92, 1.55],
[6.2, 1.16, -0.35],
[4.25, 1.38, -2.15]
]);
addFlow([
[-4.45, 0.55, 6.75],
[-3.05, 0.75, 5.0],
[-1.5, 1.0, 3.0],
[0.0, 1.2, 1.0],
[1.95, 1.4, -0.9]
]);
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const labels = [];
function addLabel(text, sub, anchor, className = "") {
const element = document.createElement("div");
element.className = `scene-label ${className}`.trim();
element.innerHTML = `
<span>${text}</span>
<span class="label-sub">${sub}</span>
`;
labelLayer.appendChild(element);
labels.push({ element, anchor });
}
function addTemperature(text, anchor, className) {
const element = document.createElement("div");
element.className = `temp-label ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({ element, anchor });
}
addLabel(
"Dense block",
"warm façades / stored heat",
new THREE.Vector3(-7.0, 7.65, -6.55),
"essential"
);
addLabel(
"Park",
"grass + tree canopy",
new THREE.Vector3(6.9, 3.0, -6.5),
"essential"
);
addLabel(
"Open square",
"exposed stone paving",
new THREE.Vector3(-2.0, 0.75, 6.65),
"essential"
);
addLabel(
"Water feature",
"evaporative cooling",
new THREE.Vector3(7.1, 1.8, 4.4),
"essential"
);
addLabel(
"Shade cells",
"blocked sunlight",
new THREE.Vector3(-6.3, 0.55, -0.35),
""
);
addLabel(
"Airflow corridor",
"cool moving air",
new THREE.Vector3(-0.05, 1.65, 1.85),
""
);
addTemperature("42°C", new THREE.Vector3(-6.35, 6.85, -6.5), "hot");
addTemperature("35°C", new THREE.Vector3(-1.8, 2.5, 4.15), "warm");
addTemperature("25°C", new THREE.Vector3(4.45, 2.0, -3.65), "cool");
addTemperature("18°C", new THREE.Vector3(6.8, 1.65, 3.65), "cold");
const projected = new THREE.Vector3();
function updateLabels() {
labels.forEach(({ element, anchor }) => {
projected.copy(anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -80 &&
x < window.innerWidth + 80 &&
y > -80 &&
y < window.innerHeight + 80;
element.style.display = visible ? "" : "none";
element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -100%)`;
});
}
// ---------------------------------------------------------------------
// Direct camera controls: no addons
// ---------------------------------------------------------------------
const initialCamera = {
azimuth: 0.73,
polar: 0.69,
zoom: 1.03
};
const cameraState = {
azimuth: initialCamera.azimuth,
targetAzimuth: initialCamera.azimuth,
polar: initialCamera.polar,
targetPolar: initialCamera.polar,
zoom: initialCamera.zoom,
targetZoom: initialCamera.zoom
};
const cameraTarget = new THREE.Vector3(0, 1.45, 0);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
cameraState.targetAzimuth -= dx * 0.0075;
cameraState.targetPolar = THREE.MathUtils.clamp(
cameraState.targetPolar - dy * 0.006,
0.42,
1.18
);
pointerX = event.clientX;
pointerY = event.clientY;
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetZoom = THREE.MathUtils.clamp(
cameraState.targetZoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.65
);
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
cameraState.targetAzimuth = initialCamera.azimuth;
cameraState.targetPolar = initialCamera.polar;
cameraState.targetZoom = initialCamera.zoom;
});
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 10);
cameraState.azimuth +=
(cameraState.targetAzimuth - cameraState.azimuth) * smoothing;
cameraState.polar +=
(cameraState.targetPolar - cameraState.polar) * smoothing;
cameraState.zoom +=
(cameraState.targetZoom - cameraState.zoom) * smoothing;
const radius = 34;
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraTarget.x + radius * sinPolar * Math.sin(cameraState.azimuth),
cameraTarget.y + radius * Math.cos(cameraState.polar),
cameraTarget.z + radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
// ---------------------------------------------------------------------
// Layer toggles
// ---------------------------------------------------------------------
const layerGroups = {
surface: surfaceLayer,
shade: shadeLayer,
airflow: airflowLayer
};
document.querySelectorAll("[data-layer]").forEach((button) => {
button.addEventListener("click", () => {
const key = button.dataset.layer;
const group = layerGroups[key];
group.visible = !group.visible;
button.setAttribute("aria-pressed", String(group.visible));
});
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Keep the entire diorama framed on narrow screens.
const halfHeight = Math.max(10.8, 14 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
flowRecords.forEach((record, index) => {
const t = (elapsed * 0.13 + index * 0.19) % 1;
record.packet.position.copy(record.curve.getPointAt(t));
record.packet.rotation.set(
elapsed * 0.8,
elapsed * 1.1,
elapsed * 0.6
);
});
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```