Prompt specification
Build or customize the Three.js 3D scene "San Francisco recovery block and service routes" 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: San Francisco recovery block and service routes
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/san-francisco-recovery-block-and-service-routes-x2467
Scene Description Prompt:
Build a voxel San Francisco recovery block after the 1906 earthquake, showing interrupted streets and illustrative shelter and supply placements. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (san-francisco-recovery-block-and-service-routes-x2467):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>San Francisco — Recovery Block, 1906</title>
<style>
:root {
--ink: #272925;
--paper: #eee3cb;
--paper-soft: rgba(238, 227, 203, 0.9);
--line: rgba(39, 41, 37, 0.2);
--shelter: #58c6b2;
--supply: #f0b45d;
--medical: #ed725e;
--damage: #d65b45;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c6b89d;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#stage {
position: absolute;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: absolute;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 45%, transparent 42%, rgba(39, 34, 27, 0.14) 100%),
linear-gradient(180deg, rgba(255, 250, 228, 0.08), rgba(62, 50, 37, 0.05));
z-index: 2;
}
.hud {
position: absolute;
z-index: 10;
}
.title-card {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border: 1px solid rgba(48, 43, 34, 0.24);
border-radius: 4px;
background: var(--paper-soft);
box-shadow: 0 18px 50px rgba(45, 36, 25, 0.14);
backdrop-filter: blur(10px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #665f52;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 26px;
height: 2px;
background: var(--damage);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 4vw, 51px);
font-weight: 500;
line-height: 0.94;
letter-spacing: -0.045em;
}
.subtitle {
margin: 13px 0 0;
max-width: 330px;
color: #555246;
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
line-height: 1.45;
}
.date-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 15px;
color: #736b5d;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.date-row span {
padding: 5px 7px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.22);
}
.layer-panel {
top: 24px;
right: 24px;
display: flex;
flex-direction: column;
gap: 8px;
width: 185px;
}
.layer-btn {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
min-height: 42px;
padding: 10px 12px;
border: 1px solid rgba(48, 43, 34, 0.22);
border-radius: 3px;
color: var(--ink);
background: rgba(238, 227, 203, 0.88);
box-shadow: 0 9px 30px rgba(45, 36, 25, 0.1);
cursor: pointer;
transition: transform 150ms ease, opacity 150ms ease, background 150ms ease;
}
.layer-btn:hover {
transform: translateY(-1px);
background: rgba(248, 239, 218, 0.96);
}
.layer-btn .label {
display: flex;
align-items: center;
gap: 9px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
}
.layer-btn .dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #8e887b;
box-shadow: 0 0 0 3px rgba(39, 41, 37, 0.08);
}
.layer-btn[data-layer="recovery"] .dot {
background: var(--shelter);
}
.layer-btn[data-layer="damage"] .dot {
background: var(--damage);
}
.switch {
position: relative;
width: 28px;
height: 16px;
border-radius: 20px;
background: #9a9385;
transition: background 150ms ease;
}
.switch::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 10px;
height: 10px;
border-radius: 50%;
background: #f4ead4;
transition: transform 150ms ease;
}
.layer-btn.active .switch {
background: #59685e;
}
.layer-btn.active .switch::after {
transform: translateX(12px);
}
.legend {
left: 24px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 9px 15px;
max-width: min(570px, calc(100vw - 48px));
padding: 12px 14px;
border: 1px solid rgba(48, 43, 34, 0.2);
border-radius: 3px;
background: rgba(238, 227, 203, 0.86);
backdrop-filter: blur(8px);
color: #5e594e;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: #6c6c69;
}
.swatch.rubble {
background: #8d5b45;
}
.swatch.shelter {
background: var(--shelter);
}
.swatch.supply {
background: var(--supply);
}
.swatch.medical {
background: var(--medical);
}
.hint {
right: 24px;
bottom: 24px;
padding: 10px 12px;
border: 1px solid rgba(48, 43, 34, 0.18);
border-radius: 3px;
background: rgba(238, 227, 203, 0.78);
color: #615b50;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.025em;
text-align: right;
backdrop-filter: blur(8px);
}
#markers {
position: absolute;
inset: 0;
z-index: 6;
pointer-events: none;
overflow: hidden;
}
.map-marker {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 0;
border: 0;
color: var(--ink);
background: transparent;
cursor: pointer;
pointer-events: auto;
transform: translate(-50%, -100%);
filter: drop-shadow(0 4px 7px rgba(28, 25, 20, 0.18));
}
.pin {
position: relative;
display: block;
width: 18px;
height: 18px;
flex: 0 0 auto;
border: 3px solid #f2e8d1;
border-radius: 50% 50% 50% 0;
background: #777168;
box-shadow: 0 0 0 1px rgba(30, 29, 25, 0.35);
transform: rotate(-45deg);
transition: transform 150ms ease;
}
.pin span {
position: absolute;
top: 3px;
left: 3px;
width: 6px;
height: 6px;
border-radius: 50%;
background: #f4ead4;
transform: rotate(45deg);
}
.map-marker.shelter .pin {
background: var(--shelter);
}
.map-marker.supply .pin {
background: var(--supply);
}
.map-marker.medical .pin {
background: var(--medical);
}
.map-marker:hover .pin,
.map-marker.selected .pin {
transform: rotate(-45deg) scale(1.2);
}
.marker-label {
padding: 6px 8px;
border: 1px solid rgba(40, 37, 31, 0.2);
border-radius: 2px;
background: rgba(241, 230, 206, 0.94);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.025em;
white-space: nowrap;
}
.map-marker.selected .marker-label {
background: #302f29;
color: #f4ead4;
}
.info-card {
position: absolute;
z-index: 15;
right: 24px;
top: 178px;
width: min(320px, calc(100vw - 48px));
padding: 17px 18px 18px;
border: 1px solid rgba(45, 40, 31, 0.25);
border-radius: 4px;
background: rgba(239, 228, 204, 0.96);
box-shadow: 0 18px 55px rgba(38, 30, 22, 0.2);
backdrop-filter: blur(12px);
transform: translateY(-8px);
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.info-card.visible {
transform: translateY(0);
opacity: 1;
pointer-events: auto;
}
.info-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.info-card .category {
margin-bottom: 5px;
color: #756e60;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.info-card h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
line-height: 1.05;
}
.close-btn {
width: 27px;
height: 27px;
flex: 0 0 auto;
border: 1px solid var(--line);
border-radius: 50%;
color: #5f594e;
background: transparent;
cursor: pointer;
line-height: 1;
}
.info-card p {
margin: 12px 0 0;
color: #575246;
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
line-height: 1.5;
}
.info-card .interpretive {
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #80786a;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
line-height: 1.45;
text-transform: uppercase;
}
#loading {
position: absolute;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #c6b89d;
color: #5f584c;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.loading-inner {
display: flex;
align-items: center;
gap: 13px;
}
.loading-inner::before {
content: "";
width: 15px;
height: 15px;
border: 2px solid rgba(39, 41, 37, 0.18);
border-top-color: #5f584c;
border-radius: 50%;
animation: spin 800ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 720px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px 14px;
}
h1 {
font-size: 34px;
}
.subtitle {
max-width: 430px;
margin-top: 9px;
font-size: 12px;
}
.date-row {
margin-top: 10px;
}
.layer-panel {
top: auto;
right: 12px;
bottom: 59px;
width: 145px;
}
.layer-btn {
min-height: 36px;
padding: 8px 10px;
}
.layer-btn .label {
font-size: 10px;
}
.legend {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
gap: 7px 10px;
padding: 9px 10px;
font-size: 8px;
}
.hint {
display: none;
}
.info-card {
top: auto;
right: 12px;
bottom: 59px;
width: calc(100vw - 24px);
}
.marker-label {
display: none;
}
.map-marker.selected .marker-label {
display: block;
}
}
</style>
</head>
<body>
<div id="app">
<div id="stage"></div>
<div class="vignette"></div>
<header class="hud title-card">
<div class="eyebrow">San Francisco · Recovery Archive</div>
<h1>The city,<br />interrupted.</h1>
<p class="subtitle">
A voxel interpretation of shattered streets, improvised refuge, and relief
supply placements in the weeks after the 1906 earthquake.
</p>
<div class="date-row">
<span>18 April 1906</span>
<span>Recovery week 01</span>
</div>
</header>
<nav class="hud layer-panel" aria-label="Map layers">
<button
class="layer-btn active"
id="recoveryToggle"
data-layer="recovery"
type="button"
aria-pressed="true"
>
<span class="label"><span class="dot"></span>Recovery network</span>
<span class="switch"></span>
</button>
<button
class="layer-btn active"
id="damageToggle"
data-layer="damage"
type="button"
aria-pressed="true"
>
<span class="label"><span class="dot"></span>Street damage</span>
<span class="switch"></span>
</button>
<button class="layer-btn" id="resetView" type="button">
<span class="label"><span class="dot"></span>Reset viewpoint</span>
<span>↺</span>
</button>
</nav>
<div class="hud legend" aria-label="Map legend">
<span class="legend-item"><span class="swatch"></span>Interrupted streets</span>
<span class="legend-item"><span class="swatch rubble"></span>Collapse & rubble</span>
<span class="legend-item"><span class="swatch shelter"></span>Shelter</span>
<span class="legend-item"><span class="swatch supply"></span>Supply point</span>
<span class="legend-item"><span class="swatch medical"></span>Emergency service</span>
</div>
<div class="hud hint">
Drag to orbit · Shift-drag to pan · Scroll to zoom<br />
Select a labeled site for context
</div>
<div id="markers"></div>
<section class="info-card" id="infoCard" aria-live="polite">
<div class="info-top">
<div>
<div class="category" id="infoCategory"></div>
<h2 id="infoTitle"></h2>
</div>
<button class="close-btn" id="closeInfo" type="button" aria-label="Close">×</button>
</div>
<p id="infoBody"></p>
<div class="interpretive">
Illustrative placement · Composite reconstruction, not a surveyed address
</div>
</section>
<div id="loading">
<div class="loading-inner">Assembling the recovery block</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const markerLayer = document.querySelector("#markers");
const infoCard = document.querySelector("#infoCard");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc6b89d);
scene.fog = new THREE.Fog(0xc6b89d, 72, 118);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.04;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-35, 35, 21, -21, 0.1, 220);
const cameraTarget = new THREE.Vector3(0, 1, 0);
let yaw = 0.72;
let pitch = 0.78;
let zoom = window.innerWidth < 720 ? 0.84 : 1.0;
const recoveryGroup = new THREE.Group();
const damageGroup = new THREE.Group();
scene.add(recoveryGroup, damageGroup);
const hemisphere = new THREE.HemisphereLight(0xfff1cf, 0x69685e, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd6a0, 3.3);
sun.position.set(-31, 48, 25);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -43;
sun.shadow.camera.right = 43;
sun.shadow.camera.top = 38;
sun.shadow.camera.bottom = -38;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 115;
sun.shadow.normalBias = 0.035;
sun.shadow.bias = -0.00012;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ba9b5, 0.8);
fill.position.set(35, 22, -28);
scene.add(fill);
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
let seed = 1906;
function random() {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
const materialCache = new Map();
function material(color) {
if (color && color.isMaterial) return color;
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(key);
}
function box(
parent,
width,
height,
depth,
x,
y,
z,
color,
rotationY = 0,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color)
);
mesh.position.set(x, y, z);
mesh.rotation.y = rotationY;
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groupAt(parent, x, y, z) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
return group;
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
const radius = 76;
const horizontal = Math.sin(pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + Math.cos(pitch) * radius,
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.zoom = zoom;
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = aspect < 0.8 ? 58 : 42;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Terrain and streets
// -------------------------------------------------------------------------
function buildGround() {
box(scene, 70, 1.25, 54, 0, -0.82, 0, 0x746957);
box(scene, 59, 0.58, 52, -2.5, -0.19, 0, 0xb9aa90);
box(scene, 9, 0.18, 52, 31, -0.03, 0, 0x52777a);
box(scene, 0.45, 0.9, 52, 27.1, 0.18, 0, 0x8c8777);
// Quiet horizontal water marks.
for (let i = 0; i < 15; i++) {
const x = 28.3 + random() * 6.4;
const z = -24 + random() * 48;
const wave = box(
scene,
0.7 + random() * 1.5,
0.025,
0.08,
x,
0.09,
z,
0x9eb5ae,
0,
false
);
wave.material = new THREE.MeshBasicMaterial({
color: 0x9eb5ae,
transparent: true,
opacity: 0.28
});
}
}
function addRoad(ax, az, bx, bz, width, options = {}) {
const dx = bx - ax;
const dz = bz - az;
const length = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const midX = (ax + bx) / 2;
const midZ = (az + bz) / 2;
const layer = options.layer || 0;
const roadColor = options.color || 0x5d5d59;
box(
scene,
length,
0.12,
width,
midX,
0.18 + layer,
midZ,
roadColor,
angle,
false
);
if (!options.noCurbs) {
const px = dz / length;
const pz = -dx / length;
const offset = width / 2 - 0.08;
for (const side of [-1, 1]) {
box(
scene,
length,
0.18,
0.16,
midX + px * offset * side,
0.21 + layer,
midZ + pz * offset * side,
0x98917f,
angle,
false
);
}
}
if (options.dashes !== false) {
const dashCount = Math.max(1, Math.floor(length / 3.4));
const dashColor = options.dashColor || 0xc3b89d;
for (let i = 0; i < dashCount; i++) {
const t = (i + 0.5) / dashCount;
box(
scene,
0.82,
0.025,
0.08,
ax + dx * t,
0.265 + layer,
az + dz * t,
dashColor,
angle,
false
);
}
}
if (options.rails) {
const px = dz / length;
const pz = -dx / length;
for (const side of [-1, 1]) {
box(
scene,
length,
0.045,
0.065,
midX + px * 0.72 * side,
0.315 + layer,
midZ + pz * 0.72 * side,
0x9a9d96,
angle,
false
);
}
box(
scene,
length,
0.025,
0.19,
midX,
0.295 + layer,
midZ,
0x343633,
angle,
false
);
}
}
function addRoadIntervals(axis, coordinate, intervals, options = {}) {
for (const [a, b] of intervals) {
if (axis === "x") {
addRoad(a, coordinate, b, coordinate, options.width || 3.6, options);
} else {
addRoad(coordinate, a, coordinate, b, options.width || 3.6, options);
}
}
}
function buildStreets() {
// North-south streets.
addRoadIntervals("z", -25, [[-24, 5], [9, 24]], { layer: 0 });
addRoadIntervals("z", -13, [[-24, -7], [-2, 24]], { layer: 0 });
addRoadIntervals("z", -1, [[-24, 7], [12, 24]], { layer: 0 });
addRoadIntervals("z", 11, [[-24, -13], [-7, 24]], { layer: 0 });
addRoadIntervals("z", 23, [[-24, 2], [8, 24]], { layer: 0 });
// East-west streets.
addRoadIntervals("x", -17, [
[-31, -28],
[-24, -8],
[-5, 4],
[8, 27]
], { layer: 0.012 });
addRoadIntervals("x", -5, [
[-31, -16],
[-12, 0],
[4, 13],
[17, 27]
], { layer: 0.012 });
addRoadIntervals("x", 7, [
[-31, -25],
[-21, -7],
[-3, 6],
[10, 27]
], { layer: 0.012 });
addRoadIntervals("x", 19, [
[-31, -17],
[-13, -5],
[-1, 9],
[13, 27]
], { layer: 0.012 });
// Market Street, deliberately cut into interrupted sections.
const marketA = new THREE.Vector2(-30, 16);
const marketB = new THREE.Vector2(29, -11);
const marketPoint = (t) =>
new THREE.Vector2(
marketA.x + (marketB.x - marketA.x) * t,
marketA.y + (marketB.y - marketA.y) * t
);
const marketSections = [
[0, 0.23],
[0.29, 0.53],
[0.60, 0.84],
[0.90, 1]
];
for (const [start, end] of marketSections) {
const a = marketPoint(start);
const b = marketPoint(end);
addRoad(a.x, a.y, b.x, b.y, 4.8, {
layer: 0.03,
rails: true,
noCurbs: true,
dashColor: 0xb59d67
});
}
// Cable poles and wire.
for (let i = 0; i < 8; i++) {
const p = marketPoint(0.06 + i * 0.12);
if (p.x > 28) continue;
box(scene, 0.15, 4.2, 0.15, p.x + 1.4, 2.25, p.y + 0.5, 0x5f5549);
box(scene, 1.0, 0.12, 0.12, p.x + 0.95, 4.2, p.y + 0.5, 0x5f5549);
}
}
// -------------------------------------------------------------------------
// Building generation
// -------------------------------------------------------------------------
const buildingColors = [
0xb98268,
0xc0aa86,
0x9f9d86,
0xaeb5a5,
0x9d7464,
0xc2b89e,
0x7f8f89,
0xb18c72
];
const roofColors = [0x5f625c, 0x776a5c, 0x6f5148, 0x777970];
const rubbleColors = [0x8c6653, 0x9c8068, 0x76665a, 0xaaa087, 0x705349];
function addWindowGrid(group, width, depth, maxHeight) {
const floors = Math.max(1, Math.floor(maxHeight / 1.35));
const frontCount = width > 3.7 ? 3 : 2;
for (let floor = 0; floor < floors; floor++) {
const y = 0.76 + floor * 1.22;
if (y + 0.32 > maxHeight - 0.15) continue;
for (let i = 0; i < frontCount; i++) {
const x = -width / 2 + ((i + 1) * width) / (frontCount + 1);
box(group, 0.46, 0.63, 0.045, x, y, depth / 2 + 0.025, 0x39464a);
}
const sideCount = depth > 3.6 ? 3 : 2;
for (const side of [-1, 1]) {
for (let i = 0; i < sideCount; i++) {
const z = -depth / 2 + ((i + 1) * depth) / (sideCount + 1);
box(group, 0.045, 0.62, 0.42, side * (width / 2 + 0.025), y, z, 0x39464a);
}
}
}
}
function addRubble(group, width, depth, count) {
for (let i = 0; i < count; i++) {
const size = 0.18 + random() * 0.62;
const x = (random() - 0.5) * width;
const z = (random() - 0.5) * depth;
const y = size * 0.45 + random() * 0.25;
box(
group,
size,
size * (0.55 + random() * 0.7),
size * (0.6 + random() * 0.9),
x,
y,
z,
rubbleColors[Math.floor(random() * rubbleColors.length)],
random() * Math.PI
);
}
for (let i = 0; i < Math.max(2, Math.floor(count / 4)); i++) {
box(
group,
0.14,
0.12,
1.2 + random(),
(random() - 0.5) * width,
0.45,
(random() - 0.5) * depth,
0x58483b,
random() * Math.PI
);
}
}
function makeStoreSign(group, text, width, depth) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const context = canvas.getContext("2d");
context.fillStyle = "#343934";
context.fillRect(0, 0, 256, 64);
context.strokeStyle = "#d8c9a9";
context.lineWidth = 3;
context.strokeRect(5, 5, 246, 54);
context.fillStyle = "#e8d9b8";
context.font = "700 27px Georgia";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 34);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(Math.min(width - 0.5, 3.4), 0.68),
new THREE.MeshBasicMaterial({ map: texture })
);
sign.position.set(0, 1.03, depth / 2 + 0.055);
group.add(sign);
}
function makeBuilding(cx, cz, width, depth, height, state, colorIndex) {
const group = groupAt(scene, cx, 0.27, cz);
const wallColor = buildingColors[colorIndex % buildingColors.length];
const roofColor = roofColors[colorIndex % roofColors.length];
box(group, width + 0.12, 0.18, depth + 0.12, 0, 0.09, 0, 0x9b927f);
if (state === 0) {
box(group, width, height, depth, 0, height / 2, 0, wallColor);
box(group, width + 0.25, 0.22, depth + 0.25, 0, height + 0.1, 0, roofColor);
box(group, width + 0.08, 0.12, depth + 0.08, 0, height - 0.18, 0, 0x887c68);
addWindowGrid(group, width, depth, height - 0.15);
box(
group,
0.55 + random() * 0.45,
0.7 + random() * 0.5,
0.55,
(random() - 0.5) * width * 0.45,
height + 0.55,
(random() - 0.5) * depth * 0.4,
0x756a5d
);
if (random() < 0.2) {
const names = ["GROCER", "HOTEL", "PHARMACY", "LODGE", "BAKERY"];
makeStoreSign(
group,
names[Math.floor(random() * names.length)],
width,
depth
);
}
} else if (state === 1) {
const lowerHeight = height * (0.28 + random() * 0.15);
box(group, width, lowerHeight, depth, 0, lowerHeight / 2, 0, wallColor);
addWindowGrid(group, width, depth, lowerHeight);
const sideHeight = height * (0.45 + random() * 0.38);
box(
group,
0.23,
sideHeight,
depth * (0.6 + random() * 0.25),
-width / 2 + 0.12,
sideHeight / 2,
-depth * 0.08,
wallColor
);
const rearHeight = height * (0.28 + random() * 0.35);
box(
group,
width * (0.45 + random() * 0.35),
rearHeight,
0.23,
width * 0.15,
rearHeight / 2,
-depth / 2 + 0.11,
wallColor
);
box(
group,
width * 0.58,
0.18,
depth * 0.55,
-width * 0.08,
lowerHeight + 0.03,
0,
roofColor
);
addRubble(group, width + 1.1, depth + 0.9, 12);
} else {
const fragmentHeight = 0.35 + random() * 0.95;
box(
group,
width * 0.72,
fragmentHeight,
0.25,
-width * 0.08,
fragmentHeight / 2,
-depth / 2,
wallColor
);
box(
group,
0.25,
fragmentHeight * 0.72,
depth * 0.55,
width / 2,
fragmentHeight * 0.36,
depth * 0.1,
wallColor
);
box(
group,
width * 0.35,
0.22,
depth * 0.48,
-width * 0.15,
0.24,
depth * 0.05,
roofColor
);
addRubble(group, width + 1.4, depth + 1.4, 22);
}
return group;
}
const marketStart = new THREE.Vector2(-30, 16);
const marketEnd = new THREE.Vector2(29, -11);
const marketVector = marketEnd.clone().sub(marketStart);
function distanceToMarket(x, z) {
const point = new THREE.Vector2(x, z);
const t = clamp(
point.clone().sub(marketStart).dot(marketVector) /
marketVector.lengthSq(),
0,
1
);
const closest = marketStart.clone().addScaledVector(marketVector, t);
return point.distanceTo(closest);
}
function buildCityBlocks() {
const blockX = [-19, -7, 5, 17];
const blockZ = [-11, 1, 13];
const reserved = new Set([
"-19,-11",
"-7,-11",
"5,-11",
"-7,13",
"17,13"
]);
for (const bx of blockX) {
for (const bz of blockZ) {
if (reserved.has(`${bx},${bz}`)) continue;
for (const ox of [-2.05, 2.05]) {
for (const oz of [-2.05, 2.05]) {
if (random() < 0.1) continue;
const x = bx + ox;
const z = bz + oz;
const marketDistance = distanceToMarket(x, z);
if (marketDistance < 5.1) continue;
const width = 3.0 + random() * 1.05;
const depth = 3.0 + random() * 1.05;
const height = 3.1 + random() * 4.6;
const nearMarket = marketDistance < 8.5;
const roll = random();
let state;
if (roll < (nearMarket ? 0.43 : 0.13)) {
state = 2;
} else if (roll < (nearMarket ? 0.84 : 0.6)) {
state = 1;
} else {
state = 0;
}
makeBuilding(
x,
z,
width,
depth,
height,
state,
Math.floor(random() * buildingColors.length)
);
}
}
}
}
}
// -------------------------------------------------------------------------
// Damage features
// -------------------------------------------------------------------------
function makeRift(x, z, rotation, width = 4.2) {
const group = groupAt(damageGroup, x, 0, z);
group.rotation.y = rotation;
for (let i = 0; i < 9; i++) {
const segmentWidth = 0.42 + random() * 0.8;
const offset = -width / 2 + (i / 8) * width;
const jitter = (random() - 0.5) * 0.48;
box(
group,
segmentWidth,
0.09,
0.23 + random() * 0.3,
offset,
0.43,
jitter,
0x332f2c,
(random() - 0.5) * 0.18,
false
);
}
for (let i = 0; i < 7; i++) {
const size = 0.16 + random() * 0.35;
box(
group,
size,
size * 0.7,
size,
(random() - 0.5) * width,
0.47,
(random() - 0.5) * 1.2,
rubbleColors[Math.floor(random() * rubbleColors.length)],
random() * Math.PI
);
}
}
function makeBarricade(x, z, rotation = 0) {
const group = groupAt(damageGroup, x, 0.48, z);
group.rotation.y = rotation;
box(group, 0.16, 1.2, 0.16, -1.25, 0.6, 0, 0x594d42);
box(group, 0.16, 1.2, 0.16, 1.25, 0.6, 0, 0x594d42);
box(group, 2.8, 0.33, 0.15, 0, 0.88, 0, 0xb18b61);
for (let i = 0; i < 4; i++) {
box(group, 0.18, 0.35, 0.17, -0.95 + i * 0.63, 0.88, 0, 0x7a493b);
}
}
function buildDamage() {
makeRift(-25, 7, 0);
makeRift(-13, -4.5, 0);
makeRift(-1, 9.5, 0);
makeRift(11, -10, 0);
makeRift(23, 5, 0);
makeRift(-26, -17, Math.PI / 2, 3.8);
makeRift(-6.5, -17, Math.PI / 2, 3.8);
makeRift(6, -17, Math.PI / 2, 3.8);
makeRift(-14, -5, Math.PI / 2, 3.8);
makeRift(2, -5, Math.PI / 2, 3.8);
makeRift(15, -5, Math.PI / 2, 3.8);
makeRift(-23, 7, Math.PI / 2, 3.8);
makeRift(-5, 7, Math.PI / 2, 3.8);
makeRift(8, 7, Math.PI / 2, 3.8);
makeRift(-15, 19, Math.PI / 2, 3.8);
makeRift(-3, 19, Math.PI / 2, 3.8);
makeRift(11, 19, Math.PI / 2, 3.8);
const marketRoadAngle = -Math.atan2(
marketVector.y,
marketVector.x
);
for (const t of [0.26, 0.565, 0.87]) {
const x = marketStart.x + marketVector.x * t;
const z = marketStart.y + marketVector.y * t;
makeRift(x, z, marketRoadAngle + Math.PI / 2, 5.0);
}
makeBarricade(-25, 8.4, 0);
makeBarricade(-12.2, -4.5, 0);
makeBarricade(-6.8, -16.1, Math.PI / 2);
makeBarricade(2.8, -4.9, Math.PI / 2);
makeBarricade(-4.1, 8.3, Math.PI / 2);
// A partial plank crossing, leaving the fissure exposed.
for (let i = 0; i < 5; i++) {
box(
damageGroup,
2.75,
0.13,
0.43,
-13,
0.47,
-5.85 + i * 0.52,
0x8d6b48
);
}
for (let i = 0; i < 3; i++) {
box(
damageGroup,
0.42,
0.13,
2.6,
-5.9 + i * 0.49,
0.48,
7,
0x8d6b48
);
}
}
// -------------------------------------------------------------------------
// Trees, tents, relief supplies, and landmarks
// -------------------------------------------------------------------------
function makeTree(x, z, scale = 1, parent = scene) {
const group = groupAt(parent, x, 0.42, z);
box(group, 0.28 * scale, 1.55 * scale, 0.28 * scale, 0, 0.78 * scale, 0, 0x685441);
box(group, 1.35 * scale, 1.05 * scale, 1.2 * scale, 0, 1.85 * scale, 0, 0x64765d);
box(group, 0.9 * scale, 0.85 * scale, 0.85 * scale, -0.15 * scale, 2.55 * scale, 0.05, 0x748467);
return group;
}
function makeTent(x, z, options = {}) {
const width = options.width || 1.8;
const depth = options.depth || 2.8;
const height = options.height || 1.35;
const color = options.color || 0xd8ccb0;
const group = groupAt(recoveryGroup, x, 0.52, z);
group.rotation.y = options.rotation || 0;
const vertices = new Float32Array([
-width / 2, 0, -depth / 2,
width / 2, 0, -depth / 2,
0, height, -depth / 2,
-width / 2, 0, depth / 2,
width / 2, 0, depth / 2,
0, height, depth / 2
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
geometry.setIndex([
0, 2, 1,
3, 4, 5,
0, 3, 5,
0, 5, 2,
1, 2, 5,
1, 5, 4,
0, 1, 4,
0, 4, 3
]);
geometry.computeVertexNormals();
const tent = new THREE.Mesh(geometry, material(color));
tent.castShadow = true;
tent.receiveShadow = true;
group.add(tent);
box(group, 0.055, 0.68, 0.72, -width / 2 - 0.035, 0.34, 0, 0x554c43);
if (options.cross) {
box(group, 0.04, 0.54, 0.16, -width / 2 - 0.08, 0.72, 0, 0xb94e40);
box(group, 0.04, 0.16, 0.54, -width / 2 - 0.08, 0.72, 0, 0xb94e40);
}
return group;
}
function makeCrate(x, z, scale = 1, parent = recoveryGroup) {
const group = groupAt(parent, x, 0.47, z);
group.rotation.y = (random() - 0.5) * 0.3;
box(group, 1.05 * scale, 0.9 * scale, 1.05 * scale, 0, 0.45 * scale, 0, 0x9b744e);
box(group, 1.1 * scale, 0.09 * scale, 1.1 * scale, 0, 0.17 * scale, 0, 0x5d4a38);
box(group, 0.12 * scale, 0.92 * scale, 1.09 * scale, -0.33 * scale, 0.46 * scale, 0, 0x67503c);
box(group, 1.09 * scale, 0.12 * scale, 0.12 * scale, 0, 0.46 * scale, 0.54 * scale, 0x67503c);
return group;
}
function makeBarrel(x, z, parent = recoveryGroup) {
const group = groupAt(parent, x, 0.48, z);
box(group, 0.72, 1.05, 0.72, 0, 0.52, 0, 0x66736d);
box(group, 0.78, 0.1, 0.78, 0, 0.25, 0, 0x414b47);
box(group, 0.78, 0.1, 0.78, 0, 0.78, 0, 0x414b47);
return group;
}
function makeBench(x, z, rotation = 0, parent = scene) {
const group = groupAt(parent, x, 0.44, z);
group.rotation.y = rotation;
box(group, 1.8, 0.16, 0.45, 0, 0.48, 0, 0x806448);
box(group, 0.15, 0.45, 0.35, -0.65, 0.23, 0, 0x50483f);
box(group, 0.15, 0.45, 0.35, 0.65, 0.23, 0, 0x50483f);
return group;
}
function makePark() {
box(scene, 8.4, 0.18, 8.4, -19, 0.32, -11, 0x73836a);
box(scene, 8.15, 0.05, 1.35, -19, 0.44, -11, 0xb5a486);
box(scene, 1.35, 0.05, 8.15, -19, 0.445, -11, 0xb5a486);
makeTree(-22.4, -14.4, 1.0);
makeTree(-15.7, -14.4, 0.86);
makeTree(-22.4, -7.7, 0.9);
makeTree(-15.7, -7.7, 1.05);
makeBench(-20.8, -11, Math.PI / 2);
makeBench(-17.2, -11, Math.PI / 2);
makeBench(-19, -13.1, 0);
makeBench(-19, -8.9, 0);
}
function buildShelter() {
makeTent(-22.2, -9.7, { color: 0xd8ccb0, rotation: 0.05 });
makeTent(-20.4, -9.7, { color: 0xc8bca1, rotation: -0.03 });
makeTent(-18.6, -9.7, { color: 0xd9ceb3 });
makeTent(-16.8, -9.7, { color: 0xc4b99f });
for (let i = 0; i < 6; i++) {
box(
recoveryGroup,
1.3,
0.18,
0.62,
-22 + i * 1.25,
0.55,
-12.25,
i % 2 ? 0x8e8d78 : 0xa29d83
);
}
makeCrate(-22.3, -12.5, 0.72);
makeBarrel(-15.5, -12.1);
makeBarrel(-14.7, -12.2);
}
function buildKitchen() {
box(recoveryGroup, 8.2, 0.16, 8.0, 5, 0.33, -11, 0xa99b80);
makeTent(2.7, -11.7, { width: 2.3, depth: 3.2, cross: true });
makeTent(5.2, -11.7, { width: 2.3, depth: 3.2, color: 0xc7bca3 });
box(recoveryGroup, 3.7, 0.18, 1.0, 4, 1.16, -13.6, 0x8a6747);
box(recoveryGroup, 0.18, 0.85, 0.85, 2.4, 0.78, -13.6, 0x59493a);
box(recoveryGroup, 0.18, 0.85, 0.85, 5.6, 0.78, -13.6, 0x59493a);
for (let i = 0; i < 4; i++) {
box(recoveryGroup, 0.62, 0.45, 0.62, 2.7 + i * 0.88, 1.46, -13.6, 0x3e4846);
box(recoveryGroup, 0.72, 0.08, 0.72, 2.7 + i * 0.88, 1.72, -13.6, 0x777e74);
}
for (let i = 0; i < 4; i++) {
box(
recoveryGroup,
0.5,
0.16,
0.5,
6.6 + (i % 2) * 0.7,
0.53,
-8.7 - Math.floor(i / 2) * 0.8,
0xb2a58b
);
}
}
function buildDepot() {
box(recoveryGroup, 8.25, 0.18, 8.1, 17, 0.33, 13, 0xa89b82);
// Covered loading bay.
for (const x of [14.0, 17.0, 20.0]) {
for (const z of [11.2, 14.8]) {
box(recoveryGroup, 0.19, 3.0, 0.19, x, 1.95, z, 0x6f5942);
}
}
box(recoveryGroup, 7.0, 0.22, 4.5, 17, 3.52, 13, 0x7e705b);
const crateLocations = [
[14.4, 15.2], [15.7, 15.2], [15.7, 14.0],
[18.9, 15.1], [20.0, 14.8], [13.7, 12.2],
[18.2, 11.1], [19.4, 11.1]
];
for (const [x, z] of crateLocations) {
makeCrate(x, z, 0.85 + random() * 0.25);
}
makeBarrel(16.0, 11.3);
makeBarrel(16.8, 11.1);
makeBarrel(20.7, 12.7);
makeBarrel(21.1, 13.5);
// Small handcart.
const cart = groupAt(recoveryGroup, 13.4, 0.48, 15.5);
box(cart, 2.0, 0.55, 1.0, 0, 0.62, 0, 0x8b6949);
box(cart, 0.75, 0.16, 0.12, 1.25, 0.55, 0, 0x5a4a3a);
box(cart, 0.45, 0.45, 0.16, -0.65, 0.25, 0.58, 0x3e3d37);
box(cart, 0.45, 0.45, 0.16, -0.65, 0.25, -0.58, 0x3e3d37);
}
function buildWaterStation() {
box(recoveryGroup, 8.0, 0.16, 7.8, -7, 0.33, 13, 0xb2a386);
box(recoveryGroup, 3.2, 0.9, 1.0, -7.8, 0.88, 13.2, 0x657b78);
box(recoveryGroup, 3.35, 0.12, 1.12, -7.8, 1.38, 13.2, 0x414f4c);
box(recoveryGroup, 0.15, 2.8, 0.15, -9.3, 1.85, 13.8, 0x5b5144);
box(recoveryGroup, 1.0, 0.14, 0.14, -8.85, 3.1, 13.8, 0x5b5144);
for (let i = 0; i < 5; i++) {
box(
recoveryGroup,
0.5,
0.48,
0.5,
-9.3 + i * 1.0,
0.72,
15.0,
i % 2 ? 0x8d7150 : 0xa17b50
);
}
makeBarrel(-4.5, 14.2);
makeBarrel(-3.7, 14.3);
}
function buildPier() {
box(scene, 8.8, 0.34, 3.4, 31.3, 0.55, 8, 0x8c7656);
for (let i = 0; i < 7; i++) {
box(scene, 0.28, 2.0, 0.28, 27.5 + i * 1.25, 0.05, 6.7, 0x5e503f);
box(scene, 0.28, 2.0, 0.28, 27.5 + i * 1.25, 0.05, 9.3, 0x5e503f);
}
// Relief boat.
const boat = groupAt(scene, 34, 0.55, 3.8);
box(boat, 3.2, 1.0, 7.0, 0, 0, 0, 0x465b59);
box(boat, 2.6, 0.65, 5.8, 0, 0.72, 0, 0x786e56);
box(boat, 2.15, 1.45, 2.1, 0, 1.68, -0.65, 0xd0c4a4);
box(boat, 2.3, 0.13, 2.25, 0, 2.47, -0.65, 0x5e625a);
makeCrate(30.3, 8.7, 0.8);
makeCrate(31.4, 8.8, 0.85);
makeBarrel(32.5, 8.8);
}
function makeFerryBuilding() {
const group = groupAt(scene, 26.1, 0.4, -17.3);
box(group, 4.4, 6.5, 4.4, 0, 3.25, 0, 0xd2c6a8);
box(group, 4.7, 0.3, 4.7, 0, 6.6, 0, 0xb0a183);
box(group, 3.1, 4.8, 3.1, 0, 8.8, 0, 0xd9cdb0);
box(group, 3.35, 0.25, 3.35, 0, 11.25, 0, 0xb7aa8c);
box(group, 2.3, 1.1, 2.3, 0, 11.9, 0, 0x6e786d);
for (let floor = 0; floor < 3; floor++) {
box(group, 0.58, 1.0, 0.05, -1.0, 1.5 + floor * 1.5, 2.23, 0x435255);
box(group, 0.58, 1.0, 0.05, 1.0, 1.5 + floor * 1.5, 2.23, 0x435255);
}
const clock = new THREE.Mesh(
new THREE.CircleGeometry(0.67, 24),
new THREE.MeshBasicMaterial({ color: 0xe4d7b9 })
);
clock.position.set(0, 9.2, 1.565);
group.add(clock);
box(group, 0.06, 0.42, 0.04, 0, 9.32, 1.59, 0x373a36);
box(group, 0.3, 0.06, 0.04, 0.08, 9.2, 1.595, 0x373a36);
}
function makeWreckedCableCar() {
const group = groupAt(scene, 9.0, 0.48, -2.7);
group.rotation.y = -Math.atan2(marketVector.y, marketVector.x);
box(group, 3.5, 1.45, 1.55, 0, 0.82, 0, 0x8d4f42);
box(group, 3.75, 0.18, 1.75, 0, 1.62, 0, 0x5c5b53);
box(group, 0.9, 0.72, 1.58, -0.85, 1.12, 0, 0x354347);
box(group, 0.9, 0.72, 1.58, 0.85, 1.12, 0, 0x354347);
box(group, 1.15, 0.72, 1.58, 0, 1.12, 0, 0x354347);
box(group, 0.12, 1.0, 1.68, 0, 1.95, 0, 0x544d43);
}
// -------------------------------------------------------------------------
// Recovery routes and map markers
// -------------------------------------------------------------------------
function addRoute(points, color) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(point[0], 0.47, point[1]))
);
const geometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(90));
const material = new THREE.LineDashedMaterial({
color,
dashSize: 1.1,
gapSize: 0.8,
transparent: true,
opacity: 0.85,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
recoveryGroup.add(line);
const routePoints = curve.getPoints(45);
for (let i = 0; i < routePoints.length; i += 7) {
const point = routePoints[i];
box(
recoveryGroup,
0.22,
0.045,
0.22,
point.x,
0.51,
point.z,
color,
0,
false
);
}
}
function makeBeacon(x, z, color) {
const group = groupAt(recoveryGroup, x, 0, z);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.68, 0.055, 6, 28),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.82
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.49;
group.add(ring);
box(group, 0.09, 1.9, 0.09, 0, 1.35, 0, color);
box(group, 0.28, 0.28, 0.28, 0, 2.35, 0, color);
beaconRings.push(ring);
return ring;
}
const beaconRings = [];
const markerDefinitions = [
{
type: "shelter",
category: "Illustrative shelter",
title: "Temporary refuge",
position: new THREE.Vector3(-19, 4.1, -11),
body:
"A cleared public space becomes a family refuge. Field cots, water containers and canvas shelters represent the improvised accommodation that followed the collapse of permanent housing."
},
{
type: "medical",
category: "Illustrative emergency service",
title: "Emergency kitchen",
position: new THREE.Vector3(5, 4.1, -11),
body:
"Shared cook tents and a communal table suggest a neighborhood hot-meal point. The placement is composite: kitchens like this could operate in squares, schools, church halls and surviving storefronts."
},
{
type: "supply",
category: "Illustrative supply point",
title: "Relief supply depot",
position: new THREE.Vector3(17, 5.0, 13),
body:
"Crates, fuel drums, handcarts and a covered loading bay indicate a consolidation point where donated food, clothing and tools could be sorted before local distribution."
},
{
type: "supply",
category: "Illustrative water service",
title: "Neighborhood water relay",
position: new THREE.Vector3(-7, 3.8, 13),
body:
"A public stand-in represents emergency water collection. Damaged mains and cisterns made local relay points essential even where the wider distribution network had failed."
},
{
type: "supply",
category: "Illustrative landing point",
title: "Relief arrival landing",
position: new THREE.Vector3(30.3, 4.3, 8),
body:
"Relief arriving by water could be unloaded here before moving inland to depots. The pier and landing point are interpretive rather than a reconstruction of a specific wharf."
}
];
function buildRecoveryNetwork() {
addRoute(
[[30.2, 8], [26.5, 8], [22.8, 8], [19.7, 10.5], [17, 11]],
0x58c6b2
);
addRoute(
[[17, 11.4], [17, 8.8], [12, 8.7], [7, 8.6], [5, -8.8]],
0xf0b45d
);
addRoute(
[[5, -10], [-1, -10], [-7, -10], [-13, -9], [-19, -9]],
0x58c6b2
);
makeBeacon(-19, -11, 0x58c6b2);
makeBeacon(5, -11, 0xed725e);
makeBeacon(17, 13, 0xf0b45d);
makeBeacon(-7, 13, 0x58c6b2);
makeBeacon(30.3, 8, 0xf0b45d);
}
function showInfo(definition, element) {
document.querySelector("#infoCategory").textContent = definition.category;
document.querySelector("#infoTitle").textContent = definition.title;
document.querySelector("#infoBody").textContent = definition.body;
infoCard.classList.add("visible");
markerDefinitions.forEach((marker) => {
marker.element?.classList.remove("selected");
});
element.classList.add("selected");
}
function createMarkers() {
markerDefinitions.forEach((definition) => {
const element = document.createElement("button");
element.type = "button";
element.className = `map-marker ${definition.type}`;
element.setAttribute("aria-label", definition.title);
element.innerHTML = `
<span class="pin"><span></span></span>
<span class="marker-label">${definition.title}</span>
`;
element.addEventListener("click", (event) => {
event.stopPropagation();
showInfo(definition, element);
});
markerLayer.appendChild(element);
definition.element = element;
});
}
// -------------------------------------------------------------------------
// Smoke and atmosphere
// -------------------------------------------------------------------------
const smokePuffs = [];
function makeSmoke(x, z) {
const smokeMaterial = new THREE.MeshStandardMaterial({
color: 0x77766e,
transparent: true,
opacity: 0.2,
roughness: 1,
depthWrite: false
});
const group = groupAt(scene, x, 0.35, z);
for (let i = 0; i < 7; i++) {
const size = 0.55 + i * 0.15;
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(size, 1),
smokeMaterial
);
puff.position.set(
(random() - 0.5) * 1.2,
1.1 + i * 0.65,
(random() - 0.5) * 1.0
);
puff.userData.baseY = puff.position.y;
puff.userData.phase = random() * Math.PI * 2;
puff.userData.speed = 0.35 + random() * 0.25;
group.add(puff);
smokePuffs.push(puff);
}
for (let i = 0; i < 5; i++) {
box(
scene,
0.18 + random() * 0.25,
0.15,
0.18 + random() * 0.25,
x + (random() - 0.5) * 1.3,
0.46,
z + (random() - 0.5) * 1.3,
i % 2 ? 0x5a3930 : 0xd16a38,
random() * Math.PI
);
}
}
function makeDust() {
const count = 150;
const positions = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
positions[i * 3] = (random() - 0.5) * 68;
positions[i * 3 + 1] = 0.6 + random() * 10;
positions[i * 3 + 2] = (random() - 0.5) * 50;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
const points = new THREE.Points(
geometry,
new THREE.PointsMaterial({
color: 0xf4e8cb,
size: 0.065,
transparent: true,
opacity: 0.3,
depthWrite: false
})
);
scene.add(points);
return points;
}
// -------------------------------------------------------------------------
// Assemble the scene
// -------------------------------------------------------------------------
buildGround();
buildStreets();
buildCityBlocks();
buildDamage();
makePark();
buildShelter();
buildKitchen();
buildDepot();
buildWaterStation();
buildPier();
makeFerryBuilding();
makeWreckedCableCar();
buildRecoveryNetwork();
makeSmoke(-7, 1);
makeSmoke(5, 13);
makeSmoke(11, 1);
const dust = makeDust();
createMarkers();
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, wheel zoom, and touch gestures
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let singlePointerMode = "orbit";
let pinchState = null;
function panCamera(dx, dy) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 2);
forward.y = 0;
forward.normalize().multiplyScalar(-1);
const scale = 0.045 / camera.zoom;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(forward, dy * scale);
updateCamera();
}
function gestureState() {
const values = [...pointers.values()];
if (values.length < 2) return null;
const centerX = (values[0].x + values[1].x) / 2;
const centerY = (values[0].y + values[1].y) / 2;
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
return { centerX, centerY, distance };
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
singlePointerMode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
} else {
pinchState = gestureState();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
if (pointers.size === 1) {
if (singlePointerMode === "pan") {
panCamera(dx, dy);
} else {
yaw -= dx * 0.006;
pitch = clamp(pitch + dy * 0.005, 0.44, 1.22);
updateCamera();
}
} else {
const current = gestureState();
if (current && pinchState) {
const scale = pinchState.distance / Math.max(1, current.distance);
zoom = clamp(zoom * scale, 0.62, 2.65);
panCamera(
current.centerX - pinchState.centerX,
current.centerY - pinchState.centerY
);
}
pinchState = current;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchState = pointers.size >= 2 ? gestureState() : null;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = clamp(zoom * Math.exp(-event.deltaY * 0.001), 0.62, 2.65);
updateCamera();
},
{ passive: false }
);
function resetView() {
cameraTarget.set(0, 1, 0);
yaw = 0.72;
pitch = 0.78;
zoom = window.innerWidth < 720 ? 0.84 : 1.0;
updateCamera();
}
document.querySelector("#resetView").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key === "+" || event.key === "=") {
zoom = clamp(zoom * 1.1, 0.62, 2.65);
updateCamera();
}
if (event.key === "-") {
zoom = clamp(zoom / 1.1, 0.62, 2.65);
updateCamera();
}
if (event.key === "Escape") infoCard.classList.remove("visible");
});
document.querySelector("#closeInfo").addEventListener("click", () => {
infoCard.classList.remove("visible");
markerDefinitions.forEach((marker) => {
marker.element?.classList.remove("selected");
});
});
const recoveryToggle = document.querySelector("#recoveryToggle");
const damageToggle = document.querySelector("#damageToggle");
recoveryToggle.addEventListener("click", () => {
recoveryGroup.visible = !recoveryGroup.visible;
recoveryToggle.classList.toggle("active", recoveryGroup.visible);
recoveryToggle.setAttribute("aria-pressed", recoveryGroup.visible);
});
damageToggle.addEventListener("click", () => {
damageGroup.visible = !damageGroup.visible;
damageToggle.classList.toggle("active", damageGroup.visible);
damageToggle.setAttribute("aria-pressed", damageGroup.visible);
});
// -------------------------------------------------------------------------
// Render loop and screen-space marker placement
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateMarkers() {
markerDefinitions.forEach((definition) => {
if (!recoveryGroup.visible) {
definition.element.style.display = "none";
return;
}
projected.copy(definition.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
definition.element.style.display = visible ? "flex" : "none";
definition.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
});
}
function animate() {
const elapsed = clock.getElapsedTime();
smokePuffs.forEach((puff) => {
puff.position.y =
puff.userData.baseY +
Math.sin(elapsed * puff.userData.speed + puff.userData.phase) * 0.22;
puff.rotation.y += 0.0015;
});
beaconRings.forEach((ring, index) => {
const pulse = 1 + Math.sin(elapsed * 2.1 + index) * 0.08;
ring.scale.setScalar(pulse);
});
dust.rotation.y = elapsed * 0.006;
dust.position.y = Math.sin(elapsed * 0.15) * 0.15;
updateMarkers();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
renderer.render(scene, camera);
document.querySelector("#loading")?.remove();
animate();
</script>
</body>
</html>
```