Prompt specification
Build or customize the Three.js 3D scene "Public promenade comfort planner" 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: Public promenade comfort planner
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/public-promenade-comfort-planner-x0464
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts public-route rest points. Create a riverfront route with configurable benches and shade structures; users compare longest gaps between rest points while maintaining continuous movement space and unobstructed viewpoints. Low-poly.
Working Three.js Starter (public-promenade-comfort-planner-x0464):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Riverfront Rest Route</title>
<style>
:root {
--ink: #17332f;
--muted: #617671;
--panel: rgba(248, 251, 247, 0.94);
--line: rgba(23, 51, 47, 0.13);
--green: #267b68;
--green-dark: #19594d;
--mint: #d7eee4;
--amber: #d69b37;
--red: #d45c4f;
--shadow: 0 18px 50px rgba(29, 57, 51, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe8e3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button,
select {
cursor: pointer;
}
#viewport,
#labels {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#labels {
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.gap-label {
position: absolute;
top: 0;
left: 0;
min-width: 54px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 999px;
color: white;
background: rgba(20, 40, 36, 0.82);
box-shadow: 0 4px 12px rgba(20, 40, 36, 0.14);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
text-align: center;
white-space: nowrap;
will-change: transform;
}
#panel {
position: fixed;
z-index: 10;
top: 18px;
bottom: 18px;
left: 18px;
width: 344px;
overflow: auto;
padding: 22px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(120%);
scrollbar-width: thin;
}
.eyebrow {
margin-bottom: 8px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 27px;
font-weight: 790;
letter-spacing: -0.045em;
line-height: 1.02;
}
.intro {
margin: 11px 0 20px;
color: var(--muted);
font-size: 12.5px;
line-height: 1.55;
}
section {
padding: 16px 0;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
font-size: 11px;
font-weight: 820;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-title span:last-child {
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
text-transform: none;
}
label.control-label {
display: block;
margin: 12px 0 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
select {
width: 100%;
height: 38px;
padding: 0 34px 0 11px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
background: white;
font-size: 12px;
font-weight: 650;
}
.range-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
output {
min-width: 42px;
padding: 3px 7px;
border-radius: 7px;
color: var(--green-dark);
background: var(--mint);
font-size: 10px;
font-weight: 850;
text-align: center;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 5px 0 0;
accent-color: var(--green);
cursor: pointer;
}
.check-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.check-row input {
width: 16px;
height: 16px;
accent-color: var(--green);
}
.primary-button,
.secondary-button {
width: 100%;
min-height: 39px;
border-radius: 11px;
font-size: 11px;
font-weight: 820;
letter-spacing: 0.015em;
}
.primary-button {
margin-top: 14px;
border: 0;
color: white;
background: var(--green);
box-shadow: 0 7px 15px rgba(38, 123, 104, 0.2);
}
.primary-button:hover {
background: var(--green-dark);
}
.secondary-button {
border: 1px solid var(--line);
color: var(--ink);
background: rgba(255, 255, 255, 0.82);
}
.secondary-button:hover {
border-color: rgba(38, 123, 104, 0.35);
background: white;
}
.metric-main {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 10px;
padding: 13px 14px;
border: 1px solid rgba(38, 123, 104, 0.12);
border-radius: 14px;
background: rgba(215, 238, 228, 0.54);
}
.metric-main small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 720;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.metric-main strong {
font-size: 31px;
font-weight: 790;
letter-spacing: -0.055em;
line-height: 1;
}
#longestNote {
max-width: 105px;
color: var(--green-dark);
font-size: 10px;
font-weight: 750;
line-height: 1.35;
text-align: right;
}
#longestNote.over {
color: var(--red);
}
.mini-metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 9px;
}
.mini-metric {
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.7);
}
.mini-metric span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 760;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.mini-metric strong {
font-size: 16px;
font-weight: 790;
}
.comparison {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 10px;
}
.comparison > div {
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.68);
}
.comparison span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 760;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.comparison strong {
font-size: 14px;
font-weight: 790;
}
#baselineButton {
grid-column: 1 / -1;
}
.gap-list {
display: grid;
gap: 8px;
}
.gap-row {
display: grid;
grid-template-columns: 22px 1fr 52px;
align-items: center;
gap: 8px;
}
.gap-rank {
display: grid;
width: 20px;
height: 20px;
place-items: center;
border-radius: 7px;
color: var(--muted);
background: rgba(23, 51, 47, 0.06);
font-size: 9px;
font-weight: 850;
}
.gap-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(23, 51, 47, 0.08);
}
.gap-fill {
height: 100%;
border-radius: inherit;
transition: width 250ms ease;
}
.gap-value {
color: var(--ink);
font-size: 10px;
font-weight: 820;
text-align: right;
}
.panel-note {
margin: 14px 0 0;
padding: 11px 12px;
border-radius: 12px;
color: var(--muted);
background: rgba(23, 51, 47, 0.045);
font-size: 10px;
line-height: 1.5;
}
#viewControls {
position: fixed;
z-index: 11;
top: 18px;
right: 18px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 14px;
background: rgba(248, 251, 247, 0.9);
box-shadow: 0 10px 28px rgba(29, 57, 51, 0.14);
backdrop-filter: blur(14px);
}
#viewControls button {
height: 34px;
padding: 0 12px;
border: 0;
border-radius: 9px;
color: var(--muted);
background: transparent;
font-size: 10px;
font-weight: 800;
}
#viewControls button:hover,
#viewControls button.active {
color: white;
background: var(--green);
}
#legend {
position: fixed;
z-index: 10;
right: 18px;
bottom: 18px;
width: 235px;
padding: 14px 15px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 16px;
background: rgba(248, 251, 247, 0.9);
box-shadow: 0 10px 30px rgba(29, 57, 51, 0.13);
backdrop-filter: blur(14px);
pointer-events: none;
}
#legend strong {
display: block;
margin-bottom: 9px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-size: 9.5px;
font-weight: 650;
}
.legend-label {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 18px;
height: 5px;
border-radius: 999px;
}
.swatch.safe {
background: var(--green);
}
.swatch.watch {
background: var(--amber);
}
.swatch.over {
background: var(--red);
}
.swatch.baseline {
width: 9px;
height: 9px;
border: 2px solid var(--amber);
border-radius: 50%;
background: transparent;
}
.control-hint {
position: fixed;
z-index: 9;
left: 380px;
bottom: 20px;
padding: 8px 11px;
border-radius: 10px;
color: rgba(23, 51, 47, 0.68);
background: rgba(248, 251, 247, 0.74);
font-size: 9.5px;
font-weight: 700;
pointer-events: none;
}
#toast {
position: fixed;
z-index: 20;
left: 50%;
top: 20px;
padding: 10px 15px;
border-radius: 999px;
color: white;
background: rgba(23, 51, 47, 0.92);
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 750;
opacity: 0;
transform: translate(-50%, -12px);
transition: 180ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 760px) {
#panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 46vh;
padding: 17px;
border-radius: 18px;
}
h1 {
font-size: 23px;
}
.intro {
margin-bottom: 12px;
}
#viewControls {
top: 10px;
right: 10px;
}
#viewControls button {
padding: 0 9px;
}
#legend {
top: 60px;
right: 10px;
bottom: auto;
width: 190px;
}
.control-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels" aria-hidden="true"></div>
<aside id="panel" aria-label="Route configuration">
<div class="eyebrow">Public-space planning sandbox</div>
<h1>Riverfront<br>Rest Route</h1>
<p class="intro">
Compare the distance between public rest points while preserving a
continuous, four-metre movement corridor and open views across the river.
</p>
<section>
<div class="section-title">
<span>01 / Configure</span>
<span>Live layout</span>
</div>
<label class="control-label" for="preset">Layout preset</label>
<select id="preset">
<option value="balanced">Balanced rhythm</option>
<option value="benches">Bench-led</option>
<option value="shades">Shade-led</option>
<option value="paired">Paired rest stops</option>
</select>
<label class="control-label" for="layout">Distribution method</label>
<select id="layout">
<option value="even">Even rhythm</option>
<option value="clustered">Cluster by type</option>
<option value="paired">Pair benches with shade</option>
</select>
<div class="range-title">
<label for="benchCount">Benches</label>
<output id="benchValue" for="benchCount">4</output>
</div>
<input id="benchCount" type="range" min="2" max="8" value="4">
<div class="range-title">
<label for="shadeCount">Shade structures</label>
<output id="shadeValue" for="shadeCount">3</output>
</div>
<input id="shadeCount" type="range" min="1" max="6" value="3">
<div class="range-title">
<label for="targetGap">Target maximum gap</label>
<output id="targetValue" for="targetGap">18 m</output>
</div>
<input id="targetGap" type="range" min="10" max="30" step="1" value="18">
<label class="check-row">
<span>Show gap analysis bands</span>
<input id="gapBands" type="checkbox" checked>
</label>
<label class="check-row">
<span>Show clear movement corridor</span>
<input id="clearCorridor" type="checkbox" checked>
</label>
</section>
<section>
<div class="section-title">
<span>02 / Gap comparison</span>
<span>100 m route</span>
</div>
<div class="metric-main" aria-live="polite">
<div>
<small>Longest rest gap</small>
<strong id="longest">—</strong>
</div>
<div id="longestNote">Set a target</div>
</div>
<div class="mini-metrics">
<div class="mini-metric">
<span>Median gap</span>
<strong id="median">—</strong>
</div>
<div class="mini-metric">
<span>Rest points</span>
<strong id="stops">—</strong>
</div>
</div>
<div class="comparison">
<div>
<span>Pinned baseline</span>
<strong id="baselineLongest">Not set</strong>
</div>
<div>
<span>Difference</span>
<strong id="delta">—</strong>
</div>
<button id="baselineButton" class="secondary-button">
Pin current layout as baseline
</button>
</div>
</section>
<section>
<div class="section-title">
<span>03 / Largest intervals</span>
<span>Ranked</span>
</div>
<div id="gapList" class="gap-list"></div>
</section>
<p class="panel-note">
All benches and shade supports sit beyond the marked walking corridor.
Shades use open-sided frames and elevated roofs to preserve river views.
Amber rings show the pinned baseline.
</p>
</aside>
<nav id="viewControls" aria-label="Camera views">
<button data-view="overview" class="active">Overview</button>
<button data-view="plan">Plan</button>
<button id="walkButton">Walk route</button>
</nav>
<div id="legend">
<strong>Gap key</strong>
<div class="legend-item">
<span class="legend-label"><i class="swatch safe"></i>Within target</span>
<span>≤ 75%</span>
</div>
<div class="legend-item">
<span class="legend-label"><i class="swatch watch"></i>Monitor</span>
<span>75–100%</span>
</div>
<div class="legend-item">
<span class="legend-label"><i class="swatch over"></i>Over target</span>
<span>> 100%</span>
</div>
<div class="legend-item">
<span class="legend-label"><i class="swatch baseline"></i>Baseline point</span>
<span>Pinned</span>
</div>
</div>
<div class="control-hint">
Drag to orbit · Right-drag to pan · Scroll to zoom · Arrow keys supported
</div>
<div id="toast" role="status"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const viewport = $("#viewport");
const labelsLayer = $("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dbe8e3");
scene.fog = new THREE.Fog("#dbe8e3", 95, 210);
const camera = new THREE.PerspectiveCamera(
45,
innerWidth / innerHeight,
0.1,
300
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly riverfront route visualization"
);
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#eaf8f2", "#829078", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff4d8", 3.1);
sun.position.set(-35, 55, 30);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -70;
sun.shadow.camera.right = 70;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 140;
sun.shadow.bias = -0.00035;
scene.add(sun);
scene.add(sun.target);
const materials = {
grass: new THREE.MeshStandardMaterial({
color: "#a9bd91",
roughness: 1,
flatShading: true
}),
path: new THREE.MeshStandardMaterial({
color: "#d8d0bd",
roughness: 0.96
}),
curb: new THREE.MeshStandardMaterial({
color: "#f0eadb",
roughness: 0.9
}),
bank: new THREE.MeshStandardMaterial({
color: "#c9bb9d",
roughness: 1
}),
wood: new THREE.MeshStandardMaterial({
color: "#9c6740",
roughness: 0.9,
flatShading: true
}),
woodLight: new THREE.MeshStandardMaterial({
color: "#bd8352",
roughness: 0.88,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: "#40554f",
roughness: 0.62,
metalness: 0.2,
flatShading: true
}),
shadeA: new THREE.MeshStandardMaterial({
color: "#e5a64e",
roughness: 0.82,
flatShading: true
}),
shadeB: new THREE.MeshStandardMaterial({
color: "#4e9b86",
roughness: 0.82,
flatShading: true
}),
trunk: new THREE.MeshStandardMaterial({
color: "#776149",
roughness: 1,
flatShading: true
}),
leafA: new THREE.MeshStandardMaterial({
color: "#527c62",
roughness: 1,
flatShading: true
}),
leafB: new THREE.MeshStandardMaterial({
color: "#73936b",
roughness: 1,
flatShading: true
}),
city: new THREE.MeshStandardMaterial({
color: "#a8bab3",
roughness: 1,
flatShading: true
}),
marker: new THREE.MeshStandardMaterial({
color: "#f4f0df",
roughness: 0.75
}),
markerGreen: new THREE.MeshStandardMaterial({
color: "#2b806b",
roughness: 0.75
}),
gapSafe: new THREE.MeshBasicMaterial({
color: "#319077",
transparent: true,
opacity: 0.29,
depthWrite: false
}),
gapWatch: new THREE.MeshBasicMaterial({
color: "#d6a13e",
transparent: true,
opacity: 0.31,
depthWrite: false
}),
gapOver: new THREE.MeshBasicMaterial({
color: "#d45c4f",
transparent: true,
opacity: 0.34,
depthWrite: false
}),
baseline: new THREE.MeshBasicMaterial({
color: "#d69b37",
transparent: true,
opacity: 0.92,
depthWrite: false
}),
corridor: new THREE.MeshBasicMaterial({
color: "#56d6c0",
transparent: true,
opacity: 0.12,
depthWrite: false
}),
dash: new THREE.MeshBasicMaterial({
color: "#ffffff",
transparent: true,
opacity: 0.72,
depthWrite: false
}),
ripple: new THREE.MeshBasicMaterial({
color: "#d3f2ec",
transparent: true,
opacity: 0.33,
depthWrite: false
})
};
function addBox(
parent,
width,
height,
depth,
x,
y,
z,
material,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children[0];
group.remove(child);
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
}
}
// ----- Static landscape -------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(160, 72),
materials.grass
);
ground.rotation.x = -Math.PI / 2;
ground.position.set(0, -0.08, 8);
ground.receiveShadow = true;
scene.add(ground);
let waterGeometry = new THREE.PlaneGeometry(160, 38, 32, 8);
waterGeometry.rotateX(-Math.PI / 2);
const waterPositions = waterGeometry.attributes.position;
for (let i = 0; i < waterPositions.count; i++) {
const x = waterPositions.getX(i);
const z = waterPositions.getZ(i);
const wave =
Math.sin(x * 0.22 + z * 0.36) * 0.07 +
Math.sin(x * 0.08 - z * 0.2) * 0.04;
waterPositions.setY(i, wave);
}
waterGeometry = waterGeometry.toNonIndexed();
waterGeometry.computeVertexNormals();
const waterColors = [];
const waterPalette = ["#5fa9ae", "#6bb5b7", "#579da6"];
for (let i = 0; i < waterGeometry.attributes.position.count; i += 3) {
const color = new THREE.Color(
waterPalette[Math.floor(Math.random() * waterPalette.length)]
);
for (let j = 0; j < 3; j++) {
waterColors.push(color.r, color.g, color.b);
}
}
waterGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
const waterMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.36,
metalness: 0.03,
flatShading: true
});
const water = new THREE.Mesh(waterGeometry, waterMaterial);
water.position.set(0, 0.02, 27);
water.receiveShadow = true;
scene.add(water);
addBox(scene, 160, 0.36, 2.3, 0, 0.1, 7.25, materials.bank, false);
addBox(scene, 160, 0.45, 6, 0, 0.12, 48, materials.grass, false);
// Continuous public route, with furniture kept beyond its edges.
addBox(scene, 100, 0.18, 4, 0, 0, -1, materials.path, false);
addBox(scene, 100, 0.22, 0.16, 0, 0.02, -3.08, materials.curb, false);
addBox(scene, 100, 0.22, 0.16, 0, 0.02, 1.08, materials.curb, false);
for (let x = -48; x <= 48; x += 4) {
addBox(
scene,
1.45,
0.025,
0.09,
x,
0.115,
-1,
materials.dash,
false
);
}
const corridorGroup = new THREE.Group();
scene.add(corridorGroup);
addBox(
corridorGroup,
99.6,
0.025,
3.9,
0,
0.115,
-1,
materials.corridor,
false
);
// Low-poly river ripples.
for (let i = 0; i < 32; i++) {
const ripple = addBox(
scene,
2 + Math.random() * 5,
0.018,
0.07,
-72 + Math.random() * 144,
0.13,
10 + Math.random() * 32,
materials.ripple,
false
);
ripple.rotation.y = (Math.random() - 0.5) * 0.35;
}
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.2, 0.31, 2.5, 5),
materials.trunk
);
trunk.position.y = 1.25;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(1.65, 3.4, 6),
Math.random() > 0.5 ? materials.leafA : materials.leafB
);
crown.position.y = 3.6;
crown.rotation.y = Math.random() * Math.PI;
crown.castShadow = true;
group.add(crown);
const lowerCrown = new THREE.Mesh(
new THREE.ConeGeometry(1.25, 2.5, 6),
materials.leafA
);
lowerCrown.position.set(0.25, 2.8, 0.1);
lowerCrown.castShadow = true;
group.add(lowerCrown);
scene.add(group);
}
const treeLocations = [
[-58, -9, 1.05], [-48, -13, 0.9], [-37, -8, 1.15],
[-26, -14, 0.92], [-14, -9, 1.08], [-2, -13, 0.95],
[11, -8.5, 1.12], [23, -13, 1], [36, -8, 0.96],
[49, -12, 1.1], [59, -8, 0.93], [-43, -20, 1.2],
[-29, -22, 1.05], [-11, -19, 1.15], [7, -21, 1.02],
[27, -20, 1.14], [43, -20, 1.08], [58, -19, 1.2]
];
treeLocations.forEach((location) => addTree(...location));
// Simple distant urban silhouette.
for (let i = 0; i < 19; i++) {
const height = 3 + Math.random() * 9;
const width = 3 + Math.random() * 5;
const depth = 3 + Math.random() * 5;
addBox(
scene,
width,
height,
depth,
-76 + i * 8.4 + (Math.random() - 0.5) * 2,
height / 2 + 0.3,
54 + Math.random() * 3,
materials.city,
false
);
}
// Distance markers sit outside the movement corridor.
for (const x of [-40, -20, 0, 20, 40]) {
const marker = new THREE.Group();
marker.position.set(x, 0, -3.8);
addBox(marker, 0.1, 1.45, 0.1, 0, 0.72, 0, materials.metal);
addBox(
marker,
0.62,
0.48,
0.12,
0,
1.45,
0,
x === 0 ? materials.markerGreen : materials.marker
);
scene.add(marker);
}
// ----- Furniture and analysis -------------------------------------------
const amenityGroup = new THREE.Group();
const gapGroup = new THREE.Group();
const baselineGroup = new THREE.Group();
scene.add(amenityGroup, gapGroup, baselineGroup);
function addBench(x, index) {
const group = new THREE.Group();
group.position.x = x;
for (let i = 0; i < 4; i++) {
addBox(
group,
2.75,
0.13,
0.17,
0,
0.72,
3.79 + i * 0.18,
i % 2 ? materials.wood : materials.woodLight
);
}
for (const legX of [-1.03, 1.03]) {
addBox(group, 0.13, 0.7, 0.13, legX, 0.35, 3.86, materials.metal);
addBox(
group,
0.13,
0.95,
0.13,
legX,
1.02,
3.62,
materials.metal
);
}
for (let i = 0; i < 3; i++) {
addBox(
group,
2.75,
0.18,
0.13,
0,
1.02 + i * 0.24,
3.58,
i % 2 ? materials.wood : materials.woodLight
);
}
addBox(group, 0.1, 0.1, 0.75, -1.03, 1.0, 3.95, materials.metal);
addBox(group, 0.1, 0.1, 0.75, 1.03, 1.0, 3.95, materials.metal);
group.userData = { kind: "Bench", index };
amenityGroup.add(group);
}
function addShade(x, index) {
const group = new THREE.Group();
group.position.x = x;
for (const postX of [-1.4, 1.4]) {
for (const postZ of [3.18, 5.28]) {
addBox(
group,
0.13,
2.9,
0.13,
postX,
1.45,
postZ,
materials.metal
);
}
}
addBox(group, 3.05, 0.12, 0.12, 0, 2.84, 3.18, materials.metal);
addBox(group, 3.05, 0.12, 0.12, 0, 2.84, 5.28, materials.metal);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.45, 1.05, 4),
index % 2 ? materials.shadeA : materials.shadeB
);
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.68;
roof.position.set(0, 3.48, 4.28);
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
group.userData = { kind: "Shade structure", index };
amenityGroup.add(group);
}
function evenlySpaced(count, start, end) {
if (count === 1) return [(start + end) / 2];
return Array.from(
{ length: count },
(_, i) => start + ((end - start) * i) / (count - 1)
);
}
function buildLayout() {
const benchCount = Number($("#benchCount").value);
const shadeCount = Number($("#shadeCount").value);
const mode = $("#layout").value;
const structures = [];
if (mode === "even") {
const total = benchCount + shadeCount;
const positions = evenlySpaced(total, -44, 44);
let benchesUsed = 0;
let shadesUsed = 0;
for (let i = 0; i < total; i++) {
const useBench =
benchesUsed < benchCount &&
(shadesUsed >= shadeCount || benchesUsed <= shadesUsed);
if (useBench) {
structures.push({ x: positions[i], type: "bench" });
benchesUsed++;
} else {
structures.push({ x: positions[i], type: "shade" });
shadesUsed++;
}
}
} else if (mode === "clustered") {
const benchPositions = evenlySpaced(benchCount, -44, -5);
const shadePositions = evenlySpaced(shadeCount, 5, 44);
benchPositions.forEach((x) =>
structures.push({ x, type: "bench" })
);
shadePositions.forEach((x) =>
structures.push({ x, type: "shade" })
);
} else {
const stationCount = Math.max(benchCount, shadeCount);
const positions = evenlySpaced(stationCount, -42, 42);
for (let i = 0; i < benchCount; i++) {
structures.push({ x: positions[i], type: "bench" });
}
for (let i = 0; i < shadeCount; i++) {
const stationIndex = Math.round(
(i * (stationCount - 1)) / Math.max(1, shadeCount - 1)
);
structures.push({ x: positions[stationIndex], type: "shade" });
}
}
return structures;
}
function getStations(structures) {
return [
...new Set(structures.map((item) => Number(item.x.toFixed(2))))
].sort((a, b) => a - b);
}
function getGaps(stations) {
const gaps = [];
for (let i = 1; i < stations.length; i++) {
gaps.push({
from: stations[i - 1],
to: stations[i],
length: stations[i] - stations[i - 1],
fromIndex: i - 1,
toIndex: i
});
}
return gaps;
}
function gapMaterial(gap, target) {
if (gap > target) return materials.gapOver;
if (gap > target * 0.75) return materials.gapWatch;
return materials.gapSafe;
}
function gapCssColor(gap, target) {
if (gap > target) return "#d45c4f";
if (gap > target * 0.75) return "#d69b37";
return "#267b68";
}
let currentStructures = [];
let currentStations = [];
let currentGaps = [];
let baseline = null;
let gapLabelElements = [];
function renderAmenities() {
clearGroup(amenityGroup);
clearGroup(gapGroup);
clearGroup(baselineGroup);
labelsLayer.replaceChildren();
gapLabelElements = [];
let benchIndex = 0;
let shadeIndex = 0;
currentStructures.forEach((item) => {
if (item.type === "bench") {
addBench(item.x, benchIndex++);
} else {
addShade(item.x, shadeIndex++);
}
});
currentStations = getStations(currentStructures);
currentGaps = getGaps(currentStations);
const target = Number($("#targetGap").value);
currentGaps.forEach((gap) => {
const width = Math.max(0.08, gap.length - 0.25);
const band = addBox(
gapGroup,
width,
0.028,
3.55,
(gap.from + gap.to) / 2,
0.155,
-1,
gapMaterial(gap.length, target),
false
);
band.renderOrder = 2;
const label = document.createElement("div");
label.className = "gap-label";
label.textContent = `${gap.length.toFixed(1)} m`;
label.style.borderColor = gapCssColor(gap.length, target);
labelsLayer.appendChild(label);
gapLabelElements.push({
element: label,
world: new THREE.Vector3(
(gap.from + gap.to) / 2,
0.65,
-1
)
});
});
if (baseline) {
baseline.stations.forEach((x) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.42, 0.075, 4, 18),
materials.baseline
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.18, 0.65);
ring.renderOrder = 4;
baselineGroup.add(ring);
});
}
gapGroup.visible = $("#gapBands").checked;
corridorGroup.visible = $("#clearCorridor").checked;
}
function updateMetrics() {
const gaps = currentGaps.map((gap) => gap.length).sort((a, b) => a - b);
const longest = gaps.length ? gaps[gaps.length - 1] : 0;
const median = gaps.length
? gaps.length % 2
? gaps[(gaps.length - 1) / 2]
: (gaps[gaps.length / 2 - 1] + gaps[gaps.length / 2]) / 2
: 0;
const target = Number($("#targetGap").value);
$("#longest").textContent = `${longest.toFixed(1)} m`;
$("#median").textContent = `${median.toFixed(1)} m`;
$("#stops").textContent = currentStations.length;
const note = $("#longestNote");
note.classList.toggle("over", longest > target);
note.textContent =
longest > target
? `Above target by ${(longest - target).toFixed(1)} m`
: `Within the ${target} m target`;
if (baseline) {
$("#baselineLongest").textContent = `${baseline.longest.toFixed(1)} m`;
const difference = longest - baseline.longest;
const delta = $("#delta");
delta.textContent =
Math.abs(difference) < 0.05
? "No change"
: `${difference > 0 ? "+" : "−"}${Math.abs(difference).toFixed(1)} m`;
delta.style.color =
Math.abs(difference) < 0.05
? "var(--muted)"
: difference > 0
? "var(--red)"
: "var(--green)";
} else {
$("#baselineLongest").textContent = "Not set";
$("#delta").textContent = "—";
$("#delta").style.color = "var(--ink)";
}
const ranked = [...currentGaps].sort((a, b) => b.length - a.length);
$("#gapList").innerHTML = ranked
.slice(0, 5)
.map((gap, index) => {
const percentage = Math.min(
100,
(gap.length / Math.max(longest, 0.01)) * 100
);
const color = gapCssColor(gap.length, target);
return `
<div class="gap-row">
<span class="gap-rank">${index + 1}</span>
<div class="gap-track">
<div
class="gap-fill"
style="width:${percentage}%;background:${color}"
></div>
</div>
<span class="gap-value">${gap.length.toFixed(1)} m</span>
</div>
`;
})
.join("");
if (!ranked.length) {
$("#gapList").innerHTML =
'<div class="panel-note" style="margin:0">Add at least two rest points to calculate gaps.</div>';
}
}
function updateLayout() {
$("#benchValue").value = $("#benchCount").value;
$("#shadeValue").value = $("#shadeCount").value;
$("#targetValue").value = `${$("#targetGap").value} m`;
currentStructures = buildLayout();
renderAmenities();
updateMetrics();
}
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(showToast.timeout);
showToast.timeout = setTimeout(() => toast.classList.remove("show"), 2200);
}
$("#benchCount").addEventListener("input", updateLayout);
$("#shadeCount").addEventListener("input", updateLayout);
$("#targetGap").addEventListener("input", updateLayout);
$("#layout").addEventListener("change", updateLayout);
$("#gapBands").addEventListener("change", () => {
gapGroup.visible = $("#gapBands").checked;
});
$("#clearCorridor").addEventListener("change", () => {
corridorGroup.visible = $("#clearCorridor").checked;
});
$("#preset").addEventListener("change", () => {
const presets = {
balanced: { benches: 4, shades: 3, layout: "even" },
benches: { benches: 7, shades: 2, layout: "clustered" },
shades: { benches: 2, shades: 6, layout: "clustered" },
paired: { benches: 4, shades: 4, layout: "paired" }
};
const preset = presets[$("#preset").value];
$("#benchCount").value = preset.benches;
$("#shadeCount").value = preset.shades;
$("#layout").value = preset.layout;
updateLayout();
});
$("#baselineButton").addEventListener("click", () => {
const longest = currentGaps.length
? Math.max(...currentGaps.map((gap) => gap.length))
: 0;
baseline = {
stations: [...currentStations],
longest,
gaps: [...currentGaps]
};
renderAmenities();
updateMetrics();
showToast("Current layout pinned for comparison");
});
// ----- Direct camera controls -------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.4, 1),
radius: 72,
theta: 0.64,
phi: 0.96
};
let cameraTween = null;
let walking = false;
let walkStartedAt = 0;
const walkLookTarget = new THREE.Vector3();
function applyCameraState() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
}
function setView(name, immediate = false) {
stopWalk(false);
const views = {
overview: {
target: new THREE.Vector3(0, 0.4, 1),
radius: 72,
theta: 0.64,
phi: 0.96
},
plan: {
target: new THREE.Vector3(0, 0, 1),
radius: 98,
theta: 0,
phi: 0.075
}
};
const destination = views[name];
if (!destination) return;
document.querySelectorAll("#viewControls button[data-view]").forEach(
(button) => {
button.classList.toggle("active", button.dataset.view === name);
}
);
if (immediate) {
cameraState.target.copy(destination.target);
cameraState.radius = destination.radius;
cameraState.theta = destination.theta;
cameraState.phi = destination.phi;
cameraTween = null;
applyCameraState();
return;
}
cameraTween = {
startedAt: performance.now(),
duration: 850,
from: {
target: cameraState.target.clone(),
radius: cameraState.radius,
theta: cameraState.theta,
phi: cameraState.phi
},
to: destination
};
}
document.querySelectorAll("#viewControls button[data-view]").forEach(
(button) => {
button.addEventListener("click", () => setView(button.dataset.view));
}
);
function startWalk() {
cameraTween = null;
walking = true;
walkStartedAt = performance.now();
camera.fov = 52;
camera.updateProjectionMatrix();
$("#walkButton").textContent = "Stop walk";
$("#walkButton").classList.add("active");
document
.querySelectorAll("#viewControls button[data-view]")
.forEach((button) => button.classList.remove("active"));
}
function stopWalk(restore = true) {
if (!walking) return;
walking = false;
camera.fov = 45;
camera.updateProjectionMatrix();
$("#walkButton").textContent = "Walk route";
$("#walkButton").classList.remove("active");
if (restore) applyCameraState();
}
$("#walkButton").addEventListener("click", () => {
if (walking) stopWalk();
else startWalk();
});
const pointers = new Map();
let lastTouch = null;
function panCamera(dx, dy) {
const direction = new THREE.Vector3();
camera.getWorldDirection(direction);
const right = new THREE.Vector3()
.crossVectors(direction, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, direction)
.normalize();
const scale = cameraState.radius * 0.00135;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-60,
60
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-25,
28
);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
-1,
8
);
}
function zoomBy(factor) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * factor,
22,
135
);
}
function touchReference() {
const values = [...pointers.values()];
if (values.length < 2) return null;
const center = new THREE.Vector2(
(values[0].x + values[1].x) / 2,
(values[0].y + values[1].y) / 2
);
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
return { center, distance };
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
stopWalk();
cameraTween = null;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button,
shift: event.shiftKey,
type: event.pointerType
});
renderer.domElement.setPointerCapture(event.pointerId);
if (pointers.size === 2) lastTouch = touchReference();
});
renderer.domElement.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.type === "mouse") {
if (pointer.button === 0 && !pointer.shift) {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.055,
1.46
);
} else {
panCamera(dx, dy);
}
} else if (pointers.size === 1) {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.055,
1.46
);
} else {
const reference = touchReference();
if (reference && lastTouch) {
panCamera(
reference.center.x - lastTouch.center.x,
reference.center.y - lastTouch.center.y
);
if (reference.distance > 0 && lastTouch.distance > 0) {
zoomBy(lastTouch.distance / reference.distance);
}
}
lastTouch = reference;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastTouch = touchReference();
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
stopWalk();
cameraTween = null;
zoomBy(Math.exp(event.deltaY * 0.001));
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target.matches("input, select, button, textarea")) return;
if (event.code === "Space") {
event.preventDefault();
if (walking) stopWalk();
else startWalk();
return;
}
cameraTween = null;
stopWalk();
if (event.key === "ArrowLeft") cameraState.theta += 0.08;
if (event.key === "ArrowRight") cameraState.theta -= 0.08;
if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.055, cameraState.phi - 0.05);
}
if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.46, cameraState.phi + 0.05);
}
if (event.key === "+" || event.key === "=") zoomBy(0.9);
if (event.key === "-" || event.key === "_") zoomBy(1.1);
});
// ----- Resize and render loop --------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
if ("ResizeObserver" in window) {
new ResizeObserver(resize).observe(viewport);
}
const projected = new THREE.Vector3();
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
gapLabelElements.forEach(({ element, world }) => {
projected.copy(world).project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.display = "block";
element.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`;
});
}
function animate(now) {
requestAnimationFrame(animate);
if (cameraTween) {
const progress = Math.min(
1,
(now - cameraTween.startedAt) / cameraTween.duration
);
const eased = 1 - Math.pow(1 - progress, 3);
cameraState.target.lerpVectors(
cameraTween.from.target,
cameraTween.to.target,
eased
);
cameraState.radius = THREE.MathUtils.lerp(
cameraTween.from.radius,
cameraTween.to.radius,
eased
);
cameraState.theta = THREE.MathUtils.lerp(
cameraTween.from.theta,
cameraTween.to.theta,
eased
);
cameraState.phi = THREE.MathUtils.lerp(
cameraTween.from.phi,
cameraTween.to.phi,
eased
);
if (progress >= 1) cameraTween = null;
}
if (walking) {
const progress = Math.min(
1,
(now - walkStartedAt) / 26000
);
const x = THREE.MathUtils.lerp(-48, 48, progress);
camera.position.set(x, 1.72, -0.85);
walkLookTarget.set(x + 4.5, 1.45, 3.35);
camera.lookAt(walkLookTarget);
if (progress >= 1) {
stopWalk();
showToast("Route preview complete");
}
} else {
applyCameraState();
}
renderer.render(scene, camera);
updateLabels();
}
updateLayout();
applyCameraState();
resize();
requestAnimationFrame(animate);
</script>
</body>
</html>
```