Prompt specification
Build or customize the Three.js 3D scene "Compare waterfront access before and after a hypothetical path link" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Compare waterfront access before and after a hypothetical path link
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-waterfront-access-before-and-after-a-hypotheti-x3024
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Suzhou Creek's waterfront in Shanghai. Let users add a clearly fictional missing walkway segment. Show changed connectivity between public-space nodes while leaving heritage buildings and creek geometry fixed. Low-poly.
Working Three.js Starter (compare-waterfront-access-before-and-after-a-hypotheti-x3024):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Suzhou Creek — Fictional Walkway Lab</title>
<style>
:root {
--ink: #172b31;
--muted: #607579;
--paper: rgba(248, 247, 239, 0.94);
--line: rgba(23, 43, 49, 0.14);
--teal: #087f83;
--cyan: #00bfc4;
--pink: #ef3f91;
--gold: #e5a93d;
--fixed: #7c6655;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8d8dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.title-block {
position: fixed;
top: 20px;
left: 24px;
z-index: 3;
max-width: 520px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
.eyebrow {
display: inline-block;
margin-bottom: 6px;
padding: 5px 9px;
border-radius: 999px;
background: rgba(248,247,239,.86);
border: 1px solid rgba(23,43,49,.12);
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 48px);
font-weight: 600;
line-height: .98;
letter-spacing: -.035em;
}
.subtitle {
margin: 8px 0 0;
color: #35545a;
font-size: 13px;
font-weight: 600;
}
.panel {
position: fixed;
z-index: 4;
top: 18px;
right: 18px;
width: 344px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border: 1px solid rgba(255,255,255,.62);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(27, 53, 57, .18);
backdrop-filter: blur(15px);
scrollbar-width: thin;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-bottom: 13px;
border-bottom: 1px solid var(--line);
}
.panel-head h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 600;
letter-spacing: -.025em;
}
.fictional-badge {
flex: 0 0 auto;
padding: 5px 8px;
border-radius: 999px;
color: #a51e62;
background: rgba(239,63,145,.12);
font-size: 9px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.section {
padding: 15px 0;
border-bottom: 1px solid var(--line);
}
.section:last-child { border-bottom: 0; }
.section-title {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 9px;
font-size: 11px;
font-weight: 900;
letter-spacing: .11em;
text-transform: uppercase;
}
.step {
display: inline-grid;
place-items: center;
width: 22px;
height: 22px;
border-radius: 7px;
color: white;
background: var(--ink);
font-size: 10px;
letter-spacing: 0;
}
.copy {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status-card {
display: flex;
align-items: center;
gap: 10px;
margin-top: 11px;
padding: 10px 11px;
border: 1px solid rgba(239,63,145,.2);
border-radius: 11px;
background: rgba(239,63,145,.065);
}
.status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--pink);
box-shadow: 0 0 0 4px rgba(239,63,145,.12);
}
#link-status {
font-size: 11px;
font-weight: 750;
line-height: 1.35;
}
.route-grid {
display: grid;
grid-template-columns: 1fr 18px 1fr;
align-items: end;
gap: 7px;
margin: 11px 0 12px;
}
label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: .1em;
text-transform: uppercase;
}
select {
width: 100%;
padding: 9px 27px 9px 9px;
border: 1px solid rgba(23,43,49,.18);
border-radius: 9px;
outline: none;
color: var(--ink);
background: rgba(255,255,255,.78);
font: inherit;
font-size: 11px;
font-weight: 700;
}
select:focus {
border-color: var(--teal);
box-shadow: 0 0 0 3px rgba(8,127,131,.1);
}
.arrow {
padding-bottom: 9px;
color: var(--muted);
text-align: center;
}
.route-result {
display: grid;
grid-template-columns: 10px 1fr;
gap: 8px;
margin: 7px 0;
font-size: 11px;
line-height: 1.4;
}
.route-swatch {
width: 8px;
height: 8px;
margin-top: 4px;
border-radius: 50%;
}
.route-swatch.before { background: var(--gold); }
.route-swatch.after { background: var(--cyan); }
.route-result strong {
display: block;
margin-bottom: 2px;
font-size: 10px;
letter-spacing: .08em;
text-transform: uppercase;
}
.route-result span {
color: var(--muted);
}
.impact-count {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin: 10px 0 8px;
padding: 10px 11px;
border-radius: 10px;
background: rgba(8,127,131,.075);
}
.impact-count strong {
color: var(--teal);
font-family: Georgia, "Times New Roman", serif;
font-size: 26px;
font-weight: 600;
}
.impact-count span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
line-height: 1.3;
text-align: right;
text-transform: uppercase;
}
.impact-list {
display: grid;
gap: 5px;
max-height: 154px;
overflow: auto;
}
.impact-row {
display: flex;
justify-content: space-between;
gap: 10px;
padding: 7px 9px;
border: 1px solid rgba(23,43,49,.09);
border-radius: 8px;
background: rgba(255,255,255,.52);
font-size: 10px;
}
.impact-row b { color: var(--teal); }
.impact-row span { color: var(--muted); }
.empty {
padding: 10px;
border: 1px dashed rgba(23,43,49,.18);
border-radius: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 36px;
padding: 8px 10px;
border: 1px solid rgba(23,43,49,.17);
border-radius: 9px;
color: var(--ink);
background: rgba(255,255,255,.72);
font: inherit;
font-size: 10px;
font-weight: 850;
cursor: pointer;
transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(8,127,131,.4);
background: white;
}
button:active { transform: translateY(0); }
button.primary {
grid-column: 1 / -1;
border-color: var(--pink);
color: white;
background: var(--pink);
}
button.primary:hover { background: #d93482; }
.fixed-note {
display: flex;
gap: 9px;
padding: 11px;
border-radius: 10px;
color: #65574d;
background: rgba(124,102,85,.09);
font-size: 10px;
line-height: 1.45;
}
.lock {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 23px;
height: 23px;
border-radius: 7px;
color: white;
background: var(--fixed);
font-size: 11px;
}
.legend {
position: fixed;
z-index: 3;
left: 24px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
max-width: min(610px, calc(100vw - 410px));
padding: 10px 12px;
border: 1px solid rgba(255,255,255,.6);
border-radius: 11px;
background: rgba(248,247,239,.86);
box-shadow: 0 8px 25px rgba(27,53,57,.12);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #486065;
font-size: 9px;
font-weight: 800;
letter-spacing: .04em;
text-transform: uppercase;
}
.legend-line {
width: 19px;
height: 4px;
border-radius: 3px;
background: #c8bda8;
}
.legend-line.pink {
height: 3px;
background: repeating-linear-gradient(90deg, var(--pink) 0 6px, transparent 6px 9px);
}
.legend-line.gold {
height: 3px;
background: repeating-linear-gradient(90deg, var(--gold) 0 5px, transparent 5px 8px);
}
.legend-line.cyan { background: var(--cyan); }
.legend-square {
width: 9px;
height: 9px;
border-radius: 2px;
background: #8b6c57;
}
.help {
position: fixed;
z-index: 3;
left: 24px;
bottom: 84px;
padding: 8px 11px;
border-radius: 9px;
color: #35545a;
background: rgba(248,247,239,.8);
font-size: 10px;
font-weight: 750;
pointer-events: none;
}
#toast {
position: fixed;
z-index: 8;
left: 50%;
bottom: 25px;
max-width: min(480px, calc(100vw - 40px));
padding: 11px 15px;
border-radius: 10px;
color: white;
background: rgba(23,43,49,.93);
box-shadow: 0 10px 30px rgba(0,0,0,.2);
font-size: 11px;
font-weight: 700;
opacity: 0;
transform: translate(-50%, 12px);
transition: opacity .2s ease, transform .2s ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 800px) {
.title-block {
top: 14px;
left: 14px;
}
.subtitle { display: none; }
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
padding: 14px;
border-radius: 14px;
}
.legend,
.help { display: none; }
#toast { bottom: calc(48vh + 22px); }
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="title-block">
<div class="eyebrow">Shanghai · Interpretive public-space model</div>
<h1>Suzhou Creek<br>Walkway Lab</h1>
<p class="subtitle">Add a fictional missing link, then compare the public-space network.</p>
</header>
<aside class="panel" aria-label="Walkway planning controls">
<div class="panel-head">
<h2>Connectivity sandbox</h2>
<span class="fictional-badge">Fictional only</span>
</div>
<section class="section">
<h3 class="section-title"><span class="step">1</span> Add a missing segment</h3>
<p class="copy">
Click any two glowing public-space nodes. The new link is shown in magenta and is
explicitly marked as fictional.
</p>
<div class="status-card">
<span class="status-dot"></span>
<span id="link-status">No fictional segment yet</span>
</div>
<div class="buttons" style="margin-top:10px">
<button id="suggest-button" class="primary" type="button">Try suggested gap: P3 ↔ P7</button>
<button id="undo-button" type="button">Undo last link</button>
<button id="clear-button" type="button">Clear links</button>
<button id="view-button" type="button">Reset view</button>
</div>
</section>
<section class="section">
<h3 class="section-title"><span class="step">2</span> Compare a route</h3>
<div class="route-grid">
<div>
<label for="from-node">From</label>
<select id="from-node"></select>
</div>
<div class="arrow">→</div>
<div>
<label for="to-node">To</label>
<select id="to-node"></select>
</div>
</div>
<div class="route-result">
<span class="route-swatch before"></span>
<div>
<strong>Existing network</strong>
<span id="base-route">—</span>
</div>
</div>
<div class="route-result">
<span class="route-swatch after"></span>
<div>
<strong>With fictional link</strong>
<span id="after-route">—</span>
</div>
</div>
</section>
<section class="section">
<h3 class="section-title"><span class="step">3</span> Network impact</h3>
<div class="impact-count">
<strong id="impact-count">0</strong>
<span>public-space pairs with<br>improved connectivity</span>
</div>
<div id="impact-list" class="impact-list"></div>
</section>
<section class="section">
<div class="fixed-note">
<span class="lock">▣</span>
<span>
<b>Heritage buildings and creek geometry are fixed.</b><br>
The intervention changes only the proposed pedestrian network; the water, banks,
and historic blocks are not edited.
</span>
</div>
</section>
</aside>
<div class="help">Drag to orbit · wheel to zoom · right-drag to pan · Esc cancels selection</div>
<div class="legend" aria-label="Legend">
<span class="legend-item"><span class="legend-line"></span>Existing network</span>
<span class="legend-item"><span class="legend-line gold"></span>Existing shortest route</span>
<span class="legend-item"><span class="legend-line cyan"></span>Improved route</span>
<span class="legend-item"><span class="legend-line pink"></span>Fictional segment</span>
<span class="legend-item"><span class="legend-square"></span>Heritage fixed</span>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const toastElement = document.getElementById("toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d8dc);
scene.fog = new THREE.Fog(0xb8d8dc, 105, 190);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 350);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe8fbfb, 0x6e6553, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.2);
sun.position.set(-35, 65, 40);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -85;
sun.shadow.camera.right = 85;
sun.shadow.camera.top = 70;
sun.shadow.camera.bottom = -70;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 170;
sun.shadow.bias = -0.00035;
scene.add(sun);
const world = new THREE.Group();
scene.add(world);
const routeGroup = new THREE.Group();
const proposedGroup = new THREE.Group();
world.add(routeGroup, proposedGroup);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pickTargets = [];
const nodeVisuals = new Map();
const cameraState = {
target: new THREE.Vector3(2, 0, 0),
radius: 112,
theta: 0.67,
phi: 0.88
};
const baseEdges = [
{ a: "P1", b: "P2", type: "quay" },
{ a: "P2", b: "P3", type: "quay" },
{ a: "P3", b: "P4", type: "quay" },
{ a: "P5", b: "P6", type: "quay" },
{ a: "P6", b: "P7", type: "quay" },
{ a: "P7", b: "P8", type: "quay" },
{ a: "P1", b: "P5", type: "bridge" },
{ a: "P2", b: "P6", type: "bridge" }
];
const proposedEdges = [];
let selectedNode = null;
let toastTimer = null;
const nodes = [
{ id: "P1", name: "North Quay", x: -42, side: 1 },
{ id: "P2", name: "Customs Steps", x: -12, side: 1 },
{ id: "P3", name: "Gallery Walk", x: 24, side: 1 },
{ id: "P4", name: "Zhenning Edge", x: 48, side: 1 },
{ id: "P5", name: "Bend Terrace", x: -42, side: -1 },
{ id: "P6", name: "Foundry Court", x: -12, side: -1 },
{ id: "P7", name: "Millfun Walk", x: 32, side: -1 },
{ id: "P8", name: "Depot Steps", x: 52, side: -1 }
];
const nodeMap = new Map();
for (const node of nodes) {
node.position = new THREE.Vector3(
node.x,
0.86,
centerAt(node.x) + node.side * 9.6
);
nodeMap.set(node.id, node);
}
function centerAt(x) {
return 1.5 * Math.sin(x * 0.075) + 0.6 * Math.sin(x * 0.21);
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function textSprite(text, options = {}) {
const {
width = 512,
height = 104,
background = "rgba(248,247,239,0.94)",
border = "rgba(23,43,49,0.15)",
color = "#173038",
font = "700 34px system-ui, sans-serif",
scale = [12, 2.45],
accent = null
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 3, 3, width - 6, height - 6, 18);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 3;
ctx.stroke();
if (accent) {
ctx.fillStyle = accent;
ctx.beginPath();
ctx.arc(34, height / 2, 10, 0, Math.PI * 2);
ctx.fill();
}
ctx.fillStyle = color;
ctx.font = font;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2 + (accent ? 8 : 0), height / 2 + 1, width - 54);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scale[0], scale[1], 1);
sprite.renderOrder = 20;
return sprite;
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.88,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide,
depthWrite: options.depthWrite ?? true
});
}
function addTriangle(positions, colors, a, b, c, color) {
positions.push(...a, ...b, ...c);
for (let i = 0; i < 3; i++) colors.push(color.r, color.g, color.b);
}
function buildWaterGeometry() {
const positions = [];
const colors = [];
const samples = 18;
const palette = [
new THREE.Color(0x4c9da0),
new THREE.Color(0x5aa9aa),
new THREE.Color(0x438f96),
new THREE.Color(0x69b0ad),
new THREE.Color(0x579fa1)
];
for (let i = 0; i < samples; i++) {
const x0 = -64 + i * (128 / samples);
const x1 = -64 + (i + 1) * (128 / samples);
const p0 = new THREE.Vector3(x0, 0.08, centerAt(x0) - 6.2);
const p1 = new THREE.Vector3(x1, 0.08, centerAt(x1) - 6.2);
const p2 = new THREE.Vector3(x0, 0.08, centerAt(x0) + 6.2);
const p3 = new THREE.Vector3(x1, 0.08, centerAt(x1) + 6.2);
const color = palette[i % palette.length];
addTriangle(positions, colors, p0, p1, p2, color);
addTriangle(positions, colors, p1, p3, p2, color.clone().offsetHSL(0, 0, .025));
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
return geometry;
}
function buildBankGeometry(side) {
const positions = [];
const colors = [];
const samples = 18;
const color = new THREE.Color(side > 0 ? 0xaeb38d : 0x9fab88);
for (let i = 0; i < samples; i++) {
const x0 = -64 + i * (128 / samples);
const x1 = -64 + (i + 1) * (128 / samples);
const inner0 = new THREE.Vector3(x0, 0.28, centerAt(x0) + side * 6.2);
const inner1 = new THREE.Vector3(x1, 0.28, centerAt(x1) + side * 6.2);
const outer0 = new THREE.Vector3(x0, 0.28, side * 52);
const outer1 = new THREE.Vector3(x1, 0.28, side * 52);
if (side > 0) {
addTriangle(positions, colors, inner0, inner1, outer0, color);
addTriangle(positions, colors, inner1, outer1, outer0, color);
} else {
addTriangle(positions, colors, inner0, outer0, inner1, color);
addTriangle(positions, colors, inner1, outer0, outer1, color);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
return geometry;
}
function buildPromenadeGeometry(side) {
const positions = [];
const colors = [];
const samples = 18;
const color = new THREE.Color(0xd9d0b8);
for (let i = 0; i < samples; i++) {
const x0 = -64 + i * (128 / samples);
const x1 = -64 + (i + 1) * (128 / samples);
const inner0 = new THREE.Vector3(x0, 0.34, centerAt(x0) + side * 8.2);
const inner1 = new THREE.Vector3(x1, 0.34, centerAt(x1) + side * 8.2);
const outer0 = new THREE.Vector3(x0, 0.34, centerAt(x0) + side * 11.4);
const outer1 = new THREE.Vector3(x1, 0.34, centerAt(x1) + side * 11.4);
if (side > 0) {
addTriangle(positions, colors, inner0, inner1, outer0, color);
addTriangle(positions, colors, inner1, outer1, outer0, color);
} else {
addTriangle(positions, colors, inner0, outer0, inner1, color);
addTriangle(positions, colors, inner1, outer0, outer1, color);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
return geometry;
}
const water = new THREE.Mesh(
buildWaterGeometry(),
standardMaterial(0xffffff, {
vertexColors: true,
roughness: 0.5,
metalness: 0.05,
side: THREE.DoubleSide
})
);
water.receiveShadow = true;
world.add(water);
for (const side of [-1, 1]) {
const bank = new THREE.Mesh(
buildBankGeometry(side),
standardMaterial(0xffffff, { vertexColors: true, side: THREE.DoubleSide })
);
bank.receiveShadow = true;
world.add(bank);
const promenade = new THREE.Mesh(
buildPromenadeGeometry(side),
standardMaterial(0xffffff, { vertexColors: true, side: THREE.DoubleSide })
);
promenade.receiveShadow = true;
world.add(promenade);
}
const xAxis = new THREE.Vector3(1, 0, 0);
function createBeam(start, end, width, height, color, options = {}) {
const direction = end.clone().sub(start);
const length = direction.length();
const geometry = new THREE.BoxGeometry(length, height, width);
const material = standardMaterial(color, {
roughness: options.roughness ?? 0.84,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true,
side: options.side ?? THREE.FrontSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(xAxis, direction.normalize());
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = true;
return mesh;
}
function createDashedBeam(start, end, width, height, color, dashCount = 10, options = {}) {
const group = new THREE.Group();
const direction = end.clone().sub(start);
const length = direction.length();
const dashLength = length / (dashCount * 1.75);
const gapLength = length / dashCount - dashLength;
for (let i = 0; i < dashCount; i++) {
const t0 = (i * (dashLength + gapLength)) / length;
const t1 = t0 + dashLength / length;
const a = start.clone().lerp(end, t0);
const b = start.clone().lerp(end, t1);
group.add(createBeam(a, b, width, height, color, options));
}
return group;
}
function addQuayWalls() {
const samples = 18;
for (const side of [-1, 1]) {
for (let i = 0; i < samples; i++) {
const x0 = -64 + i * (128 / samples);
const x1 = -64 + (i + 1) * (128 / samples);
const a = new THREE.Vector3(x0, 0.38, centerAt(x0) + side * 6.35);
const b = new THREE.Vector3(x1, 0.38, centerAt(x1) + side * 6.35);
world.add(createBeam(a, b, 0.5, 0.58, 0x817d6e, { castShadow: false }));
}
}
}
addQuayWalls();
function createBuilding({ x, z, w, d, h, color, roof, label }) {
const group = new THREE.Group();
group.position.set(x, 0.28, z);
const body = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
standardMaterial(color)
);
body.position.y = h / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const roofHeight = 2.2;
const v = [
-w / 2, h, -d / 2,
w / 2, h, -d / 2,
0, h + roofHeight, -d / 2,
-w / 2, h, d / 2,
w / 2, h, d / 2,
0, h + roofHeight, d / 2
];
const roofGeometry = new THREE.BufferGeometry();
roofGeometry.setAttribute("position", new THREE.Float32BufferAttribute(v, 3));
roofGeometry.setIndex([
0,1,2, 3,5,4,
0,2,5, 0,5,3,
1,4,5, 1,5,2
]);
roofGeometry.computeVertexNormals();
const roofMesh = new THREE.Mesh(roofGeometry, standardMaterial(roof));
roofMesh.castShadow = true;
group.add(roofMesh);
const windowMaterial = standardMaterial(0x405b5b, { roughness: 0.45 });
const windowCount = Math.max(2, Math.floor(w / 2.4));
for (let i = 0; i < windowCount; i++) {
const wx = -w / 2 + (w / (windowCount + 1)) * (i + 1);
const windowMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.85, 1.1, 0.09),
windowMaterial
);
windowMesh.position.set(wx, h * 0.58, -d / 2 - 0.055);
group.add(windowMesh);
}
const marker = textSprite("HERITAGE · FIXED", {
background: "rgba(78,61,48,0.9)",
border: "rgba(255,255,255,0.24)",
color: "#fff9ef",
font: "800 25px system-ui, sans-serif",
scale: [8.4, 1.65]
});
marker.position.set(0, h + roofHeight + 1.15, 0);
group.add(marker);
if (label) {
const labelSprite = textSprite(label, {
background: "rgba(248,247,239,0.9)",
color: "#4e443c",
font: "700 28px Georgia, serif",
scale: [10, 1.9]
});
labelSprite.position.set(0, h + roofHeight + 3.25, 0);
group.add(labelSprite);
}
world.add(group);
return group;
}
createBuilding({ x: -32, z: 24, w: 11, d: 7, h: 6.8, color: 0xb76f57, roof: 0x4b4d48, label: "Historic warehouse block" });
createBuilding({ x: -5, z: 25, w: 10, d: 7.5, h: 8.5, color: 0xd3b58d, roof: 0x655b4e, label: "Customs House" });
createBuilding({ x: 28, z: 25, w: 13, d: 8, h: 6.3, color: 0xa85d4c, roof: 0x454b49 });
createBuilding({ x: 51, z: 25, w: 8, d: 7, h: 7.8, color: 0xc9a781, roof: 0x56504a });
createBuilding({ x: -31, z: -24, w: 12, d: 8, h: 7.2, color: 0xc6a77f, roof: 0x504b43, label: "1933 heritage complex" });
createBuilding({ x: 4, z: -24, w: 13, d: 8, h: 6.2, color: 0x9f6957, roof: 0x474b48 });
createBuilding({ x: 41, z: -24, w: 11, d: 8, h: 8.1, color: 0xc2a17c, roof: 0x534e48, label: "Historic riverside works" });
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.28, z);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.16 * scale, 0.23 * scale, 1.8 * scale, 5),
standardMaterial(0x6f5840)
);
trunk.position.y = 0.9 * scale;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.25 * scale, 0),
standardMaterial(new THREE.Color().setHSL(0.29, 0.27, 0.37 + (scale % 0.2)))
);
crown.position.y = 2.25 * scale;
crown.scale.y = 1.1;
crown.castShadow = true;
group.add(crown);
world.add(group);
}
const treeLocations = [
[-54,15],[-50,31],[-23,18],[-18,34],[9,17],[14,34],[37,18],[45,34],
[-53,-16],[-47,-33],[-19,-17],[-14,-34],[14,-18],[18,-35],[40,-18],[50,-35]
];
treeLocations.forEach(([x,z], i) => createTree(x, z, 0.82 + (i % 4) * 0.09));
function createNode(node) {
const group = new THREE.Group();
group.position.copy(node.position);
group.position.y = 0.34;
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.25, 1.4, 0.55, 8),
standardMaterial(0x294b50)
);
base.position.y = 0.28;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const top = new THREE.Mesh(
new THREE.CylinderGeometry(0.82, 0.96, 0.24, 8),
standardMaterial(0xf8f3e6)
);
top.position.y = 0.66;
top.castShadow = true;
group.add(top);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.36, 0.14, 5, 18),
standardMaterial(0xeef6ef, { roughness: 0.5 })
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.72;
group.add(ring);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.42, 0),
standardMaterial(0x087f83, { roughness: 0.45 })
);
marker.position.y = 1.25;
marker.castShadow = true;
group.add(marker);
const hit = new THREE.Mesh(
new THREE.SphereGeometry(2.15, 8, 6),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hit.position.y = 0.7;
hit.userData.nodeId = node.id;
group.add(hit);
pickTargets.push(hit);
const label = textSprite(`${node.id} · ${node.name}`, {
background: "rgba(248,247,239,0.94)",
border: "rgba(8,127,131,0.24)",
color: "#173038",
font: "750 27px system-ui, sans-serif",
scale: [11.2, 2.2]
});
label.position.set(0, 3.45, 0);
group.add(label);
nodeVisuals.set(node.id, { group, ring, marker, label });
world.add(group);
}
nodes.forEach(createNode);
function buildBaseNetwork() {
for (const edge of baseEdges) {
const a = nodeMap.get(edge.a).position.clone();
const b = nodeMap.get(edge.b).position.clone();
a.y = edge.type === "bridge" ? 0.68 : 0.52;
b.y = edge.type === "bridge" ? 0.68 : 0.52;
const color = edge.type === "bridge" ? 0xb5c1b9 : 0xe2d8c3;
const width = edge.type === "bridge" ? 2.05 : 1.3;
world.add(createBeam(a, b, width, 0.22, color));
if (edge.type === "bridge") {
for (const t of [0.32, 0.68]) {
const p = a.clone().lerp(b, t);
const pier = new THREE.Mesh(
new THREE.BoxGeometry(1.5, 1.1, 1.5),
standardMaterial(0x817d70)
);
pier.position.copy(p);
pier.position.y = 0.02;
pier.castShadow = true;
world.add(pier);
}
}
}
}
buildBaseNetwork();
function edgeWeight(edge) {
return nodeMap.get(edge.a).position.distanceTo(nodeMap.get(edge.b).position);
}
function dijkstra(edges, source, target) {
const adjacency = new Map(nodes.map(node => [node.id, []]));
for (const edge of edges) {
const weight = edgeWeight(edge);
adjacency.get(edge.a).push({ to: edge.b, weight });
adjacency.get(edge.b).push({ to: edge.a, weight });
}
const distance = new Map(nodes.map(node => [node.id, Infinity]));
const previous = new Map();
const visited = new Set();
distance.set(source, 0);
while (visited.size < nodes.length) {
let current = null;
let currentDistance = Infinity;
for (const node of nodes) {
const id = node.id;
if (!visited.has(id) && distance.get(id) < currentDistance) {
current = id;
currentDistance = distance.get(id);
}
}
if (current === null) break;
if (current === target) break;
visited.add(current);
for (const connection of adjacency.get(current)) {
const candidate = currentDistance + connection.weight;
if (candidate < distance.get(connection.to)) {
distance.set(connection.to, candidate);
previous.set(connection.to, current);
}
}
}
if (!Number.isFinite(distance.get(target))) {
return { distance: Infinity, path: [] };
}
const path = [target];
let cursor = target;
while (cursor !== source) {
cursor = previous.get(cursor);
if (!cursor) return { distance: Infinity, path: [] };
path.unshift(cursor);
}
return { distance: distance.get(target), path };
}
function allPairDistances(edges) {
const result = new Map();
for (const a of nodes) {
for (const b of nodes) {
if (a.id === b.id) continue;
const key = `${a.id}|${b.id}`;
result.set(key, dijkstra(edges, a.id, b.id).distance);
}
}
return result;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material) ? object.material : [object.material];
materials.forEach(material => {
if (material.map) material.map.dispose();
material.dispose();
});
}
});
}
}
function renderProposedEdges() {
clearGroup(proposedGroup);
proposedEdges.forEach((edge, index) => {
const a = nodeMap.get(edge.a).position.clone();
const b = nodeMap.get(edge.b).position.clone();
a.y = 1.02;
b.y = 1.02;
const glow = createBeam(a, b, 2.5, 0.12, 0xef3f91, {
transparent: true,
opacity: 0.14,
depthWrite: false,
castShadow: false
});
proposedGroup.add(glow);
proposedGroup.add(createDashedBeam(
a, b, 0.78, 0.24, 0xef3f91, 13,
{ roughness: 0.48 }
));
const label = textSprite(`FICTIONAL LINK ${String(index + 1).padStart(2, "0")}`, {
background: "rgba(239,63,145,0.94)",
border: "rgba(255,255,255,0.55)",
color: "#ffffff",
font: "900 27px system-ui, sans-serif",
scale: [10.6, 2.05]
});
label.position.copy(a.clone().lerp(b, 0.5));
label.position.y += 3.4;
label.userData.baseY = label.position.y;
proposedGroup.add(label);
nodeVisuals.get(edge.a).marker.material.color.set(0xef3f91);
nodeVisuals.get(edge.b).marker.material.color.set(0xef3f91);
});
}
function routeDescription(result) {
if (!result.path.length) return "No route available";
return `${result.path.join(" → ")} · ${result.distance.toFixed(1)} model m`;
}
function renderRoutes() {
clearGroup(routeGroup);
const from = document.getElementById("from-node").value;
const to = document.getElementById("to-node").value;
const before = dijkstra(baseEdges, from, to);
const after = dijkstra([...baseEdges, ...proposedEdges], from, to);
if (before.path.length) {
for (let i = 0; i < before.path.length - 1; i++) {
const a = nodeMap.get(before.path[i]).position.clone();
const b = nodeMap.get(before.path[i + 1]).position.clone();
a.y = 0.92;
b.y = 0.92;
routeGroup.add(createDashedBeam(a, b, 0.55, 0.16, 0xe5a93d, 8, {
transparent: true,
opacity: 0.9,
depthWrite: false,
castShadow: false
}));
}
}
if (after.path.length) {
for (let i = 0; i < after.path.length - 1; i++) {
const a = nodeMap.get(after.path[i]).position.clone();
const b = nodeMap.get(after.path[i + 1]).position.clone();
a.y = 1.18;
b.y = 1.18;
routeGroup.add(createBeam(a, b, 0.72, 0.18, 0x00bfc4, {
transparent: true,
opacity: 0.95,
depthWrite: false,
castShadow: false
}));
}
}
document.getElementById("base-route").textContent = routeDescription(before);
document.getElementById("after-route").textContent = routeDescription(after);
const routeNodeIds = new Set(after.path);
for (const node of nodes) {
const visual = nodeVisuals.get(node.id);
if (selectedNode === node.id) {
visual.ring.material.color.set(0xe5a93d);
visual.ring.scale.setScalar(1.2);
} else if (routeNodeIds.has(node.id)) {
visual.ring.material.color.set(0x00bfc4);
visual.ring.scale.setScalar(1);
} else {
visual.ring.material.color.set(0xeef6ef);
visual.ring.scale.setScalar(1);
}
}
}
function updateImpact() {
const before = allPairDistances(baseEdges);
const after = allPairDistances([...baseEdges, ...proposedEdges]);
const improvements = [];
for (const [key, oldDistance] of before) {
const newDistance = after.get(key);
if (newDistance < oldDistance - 0.1) {
improvements.push({
a: key.split("|")[0],
b: key.split("|")[1],
saving: oldDistance - newDistance,
oldDistance,
newDistance
});
}
}
improvements.sort((a, b) => b.saving - a.saving);
document.getElementById("impact-count").textContent = improvements.length;
const list = document.getElementById("impact-list");
if (!improvements.length) {
list.innerHTML = `
<div class="empty">
No measurable change yet. Add a link between two public-space nodes, or try the
suggested P3 ↔ P7 gap.
</div>`;
return;
}
list.innerHTML = improvements.slice(0, 12).map(item => `
<div class="impact-row">
<span><b>${item.a} ↔ ${item.b}</b><br>${item.oldDistance.toFixed(1)} → ${item.newDistance.toFixed(1)} m</span>
<b>−${item.saving.toFixed(1)} m</b>
</div>
`).join("");
}
function updateLinkStatus() {
const status = document.getElementById("link-status");
if (!proposedEdges.length) {
status.textContent = "No fictional segment yet";
} else {
status.textContent = proposedEdges.map((edge, index) =>
`F${index + 1}: ${edge.a} ↔ ${edge.b}`
).join(" · ");
}
}
function updateAll() {
renderProposedEdges();
renderRoutes();
updateImpact();
updateLinkStatus();
}
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toastElement.classList.remove("show"), 2600);
}
function addProposedEdge(a, b) {
if (a === b) {
showToast("Choose two different public-space nodes.");
return false;
}
const alreadyExists = [...baseEdges, ...proposedEdges].some(edge =>
(edge.a === a && edge.b === b) || (edge.a === b && edge.b === a)
);
if (alreadyExists) {
showToast("That connection already exists in the network.");
return false;
}
proposedEdges.push({ a, b, fictional: true });
selectedNode = null;
updateAll();
showToast("Fictional segment added — heritage buildings and creek geometry remain unchanged.");
return true;
}
function removeLastEdge() {
if (!proposedEdges.length) {
showToast("There are no fictional links to undo.");
return;
}
proposedEdges.pop();
selectedNode = null;
updateAll();
showToast("Last fictional segment removed.");
}
function clearEdges() {
if (!proposedEdges.length) {
showToast("There are no fictional links to clear.");
return;
}
proposedEdges.length = 0;
selectedNode = null;
updateAll();
showToast("All fictional links removed. Fixed geometry is unchanged.");
}
function handleNodeClick(nodeId) {
if (!selectedNode) {
selectedNode = nodeId;
renderRoutes();
showToast(`${nodeId} selected. Choose a second public-space node.`);
return;
}
if (selectedNode === nodeId) {
selectedNode = null;
renderRoutes();
showToast("Selection cancelled.");
return;
}
addProposedEdge(selectedNode, nodeId);
}
const fromSelect = document.getElementById("from-node");
const toSelect = document.getElementById("to-node");
for (const node of nodes) {
for (const select of [fromSelect, toSelect]) {
const option = document.createElement("option");
option.value = node.id;
option.textContent = `${node.id} · ${node.name}`;
select.appendChild(option);
}
}
fromSelect.value = "P1";
toSelect.value = "P8";
fromSelect.addEventListener("change", renderRoutes);
toSelect.addEventListener("change", renderRoutes);
document.getElementById("suggest-button").addEventListener("click", () => {
addProposedEdge("P3", "P7");
});
document.getElementById("undo-button").addEventListener("click", removeLastEdge);
document.getElementById("clear-button").addEventListener("click", clearEdges);
document.getElementById("view-button").addEventListener("click", () => {
cameraState.target.set(2, 0, 0);
cameraState.radius = 112;
cameraState.theta = 0.67;
cameraState.phi = 0.88;
showToast("Camera view reset.");
});
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
let pointerState = null;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
pointerState = {
id: event.pointerId,
button: event.button,
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerState || pointerState.id !== event.pointerId) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
const totalDx = event.clientX - pointerState.x;
const totalDy = event.clientY - pointerState.y;
if (Math.abs(totalDx) + Math.abs(totalDy) > 5) pointerState.moved = true;
if (pointerState.button === 2 || pointerState.button === 1) {
const scale = cameraState.radius * 0.00135;
cameraState.target.x -= dx * scale;
cameraState.target.z += dy * scale;
cameraState.target.x = clamp(cameraState.target.x, -38, 38);
cameraState.target.z = clamp(cameraState.target.z, -30, 30);
} else {
cameraState.theta -= dx * 0.005;
cameraState.phi = clamp(cameraState.phi - dy * 0.005, 0.28, 1.38);
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", event => {
if (!pointerState || pointerState.id !== event.pointerId) return;
if (!pointerState.moved && pointerState.button === 0) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(pickTargets, false);
if (intersections.length) {
handleNodeClick(intersections[0].object.userData.nodeId);
} else {
selectedNode = null;
renderRoutes();
}
}
pointerState = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState = null;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
48,
165
);
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key === "Escape") {
selectedNode = null;
renderRoutes();
showToast("Selection cancelled.");
}
if (event.key.toLowerCase() === "z" && (event.ctrlKey || event.metaKey)) {
event.preventDefault();
removeLastEdge();
}
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
function animate(time) {
requestAnimationFrame(animate);
updateCamera();
const pulse = 1 + Math.sin(time * 0.005) * 0.09;
for (const node of nodes) {
const visual = nodeVisuals.get(node.id);
if (selectedNode === node.id) {
visual.ring.scale.setScalar(pulse + 0.14);
visual.marker.rotation.y += 0.025;
} else {
visual.ring.scale.setScalar(1);
visual.marker.rotation.y += 0.012;
}
}
proposedGroup.children.forEach(child => {
if (child.userData.baseY !== undefined) {
child.position.y = child.userData.baseY + Math.sin(time * 0.0025) * 0.18;
}
});
renderer.render(scene, camera);
}
updateAll();
requestAnimationFrame(animate);
</script>
</body>
</html>
```