Prompt specification
Build or customize the Three.js 3D scene "Shaded public garden circuit" 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: Shaded public garden circuit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shaded-public-garden-circuit-x0463
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows public-route rest points. Build a loop garden with benches, water point, signs, and varied planting; visitors choose short and long circuits with visible resting opportunities along both. Voxel style.
Working Three.js Starter (shaded-public-garden-circuit-x0463):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#dfe9e6">
<title>Common Ground — Public Rest Garden</title>
<style>
:root {
--ink: #20342d;
--muted: #64756e;
--paper: rgba(251, 250, 244, 0.94);
--line: rgba(32, 52, 45, 0.12);
--orange: #dc8256;
--teal: #2b9e96;
--blue: #3d91bd;
--shadow: 0 14px 38px rgba(36, 58, 50, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe9e6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#app, #scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
outline: none;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255,255,255,.7);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
top: 20px;
left: 20px;
width: 310px;
padding: 17px 18px 16px;
border-radius: 18px;
}
.brand-row {
display: flex;
align-items: center;
gap: 11px;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
flex: 0 0 auto;
border-radius: 11px;
color: white;
background: var(--ink);
font-weight: 900;
font-size: 17px;
letter-spacing: -1px;
}
.eyebrow {
margin: 0 0 4px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.1;
letter-spacing: -.025em;
}
.brand-copy {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.status-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #55a967;
box-shadow: 0 0 0 3px rgba(85,169,103,.14);
}
.route-panel {
top: 20px;
right: 20px;
width: 330px;
padding: 17px;
border-radius: 18px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-size: 15px;
letter-spacing: -.015em;
}
.route-count {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.route-list {
display: grid;
gap: 9px;
}
.route-card {
position: relative;
width: 100%;
padding: 13px 13px 12px 15px;
text-align: left;
color: var(--ink);
background: rgba(255,255,255,.64);
border: 1px solid var(--line);
border-radius: 13px;
cursor: pointer;
transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.route-card::before {
content: "";
position: absolute;
left: 0;
top: 12px;
bottom: 12px;
width: 4px;
border-radius: 0 4px 4px 0;
background: var(--route);
opacity: .55;
transition: opacity .18s ease;
}
.route-card:hover {
transform: translateY(-1px);
border-color: rgba(32,52,45,.25);
background: white;
}
.route-card.active {
border-color: var(--route);
background: white;
box-shadow: 0 8px 20px rgba(42,61,54,.09);
}
.route-card.active::before { opacity: 1; }
.route-card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.route-card strong {
display: block;
font-size: 14px;
}
.route-card .distance {
color: var(--route);
font-size: 12px;
font-weight: 850;
white-space: nowrap;
}
.route-card-meta {
display: flex;
gap: 7px;
align-items: center;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
}
.route-card-meta span + span::before {
content: "•";
margin-right: 7px;
color: #a7b0aa;
}
.legend {
left: 50%;
bottom: 20px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 18px;
padding: 10px 14px;
border-radius: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
white-space: nowrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-line {
width: 21px;
height: 4px;
border-radius: 2px;
}
.legend-line.short { background: var(--orange); }
.legend-line.long { background: var(--teal); }
.legend-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--blue);
}
.detail-card {
left: 20px;
bottom: 20px;
width: 325px;
min-height: 126px;
padding: 16px 44px 16px 17px;
border-radius: 16px;
}
.detail-card h2 {
margin: 2px 0 6px;
font-size: 17px;
letter-spacing: -.025em;
}
.detail-card p:last-child {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#detailClose {
position: absolute;
top: 11px;
right: 11px;
width: 29px;
height: 29px;
border: 0;
border-radius: 9px;
color: var(--muted);
background: rgba(32,52,45,.06);
cursor: pointer;
font-size: 18px;
line-height: 1;
}
.controls {
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 5px;
padding: 7px;
border-radius: 14px;
}
.control-button {
width: 36px;
height: 36px;
border: 0;
border-radius: 9px;
color: var(--ink);
background: transparent;
cursor: pointer;
font-size: 17px;
font-weight: 800;
}
.control-button:hover {
background: rgba(32,52,45,.08);
}
.control-separator {
width: 1px;
height: 23px;
margin: 0 2px;
background: var(--line);
}
.poi-label {
position: absolute;
z-index: 6;
display: flex;
align-items: center;
gap: 8px;
min-width: 112px;
padding: 7px 10px 7px 8px;
color: var(--ink);
background: rgba(255,255,255,.94);
border: 1px solid rgba(32,52,45,.12);
border-radius: 10px;
box-shadow: 0 7px 18px rgba(35,54,48,.15);
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -115%);
transition: opacity .15s ease, background .15s ease, border-color .15s ease;
}
.poi-label:hover {
background: white;
border-color: var(--poi-color);
}
.poi-label.selected {
border-color: var(--poi-color);
box-shadow: 0 8px 22px rgba(35,54,48,.2);
}
.poi-dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--poi-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--poi-color) 16%, transparent);
}
.poi-label b {
display: block;
font-size: 11px;
line-height: 1.15;
}
.poi-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #dfe9e6;
transition: opacity .5s ease, visibility .5s ease;
}
.loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-inner {
text-align: center;
color: var(--ink);
}
.loading-cubes {
display: flex;
justify-content: center;
gap: 6px;
margin-bottom: 14px;
}
.loading-cubes i {
width: 12px;
height: 12px;
background: var(--ink);
animation: cubePulse .9s infinite alternate;
}
.loading-cubes i:nth-child(2) { animation-delay: .15s; }
.loading-cubes i:nth-child(3) { animation-delay: .3s; }
@keyframes cubePulse {
to { transform: translateY(-7px); background: var(--orange); }
}
.loading strong {
display: block;
font-size: 13px;
}
.loading small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
}
.visually-hidden {
position: absolute !important;
width: 1px !important;
height: 1px !important;
padding: 0 !important;
margin: -1px !important;
overflow: hidden !important;
clip: rect(0,0,0,0) !important;
white-space: nowrap !important;
border: 0 !important;
}
@media (max-width: 760px) {
.brand {
top: 10px;
left: 10px;
width: 245px;
padding: 12px 13px;
}
.brand-mark {
width: 31px;
height: 31px;
border-radius: 9px;
font-size: 14px;
}
.brand h1 { font-size: 15px; }
.brand-copy, .status-row { display: none; }
.route-panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
padding: 11px;
border-radius: 16px;
}
.panel-heading { margin-bottom: 8px; }
.panel-heading h2 { font-size: 13px; }
.route-list { grid-template-columns: 1fr 1fr; gap: 7px; }
.route-card { padding: 10px 8px 9px 12px; }
.route-card strong { font-size: 12px; }
.route-card .distance { font-size: 10px; }
.route-card-meta { display: none; }
.detail-card {
left: 10px;
bottom: 143px;
width: min(290px, calc(100vw - 20px));
min-height: 0;
padding: 12px 38px 12px 13px;
}
.detail-card h2 { font-size: 14px; }
.detail-card p:last-child { font-size: 10px; }
.controls {
right: 10px;
bottom: 143px;
padding: 5px;
}
.control-button {
width: 31px;
height: 31px;
font-size: 14px;
}
.legend { display: none; }
.poi-label {
min-width: 0;
padding: 6px;
}
.poi-label b { font-size: 9px; }
.poi-label small { display: none; }
}
@media (max-width: 440px) {
.route-panel { bottom: 8px; }
.detail-card, .controls { bottom: 132px; }
.brand { width: 220px; }
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" tabindex="0" aria-label="Interactive three-dimensional map of the public rest garden"></canvas>
<div id="labels" aria-hidden="false"></div>
<header class="panel brand">
<div class="brand-row">
<div class="brand-mark" aria-hidden="true">CG</div>
<div>
<p class="eyebrow">Public route garden</p>
<h1>Common Ground</h1>
</div>
</div>
<p class="brand-copy">
Two easy circuits through a planted garden, with benches and drinking water along the way.
</p>
<div class="status-row">
<span class="status-dot"></span>
<span>Garden open · 06:00–22:00</span>
</div>
</header>
<section class="panel route-panel" aria-labelledby="routeHeading">
<div class="panel-heading">
<h2 id="routeHeading">Choose your circuit</h2>
<span class="route-count">2 routes</span>
</div>
<div class="route-list">
<button class="route-card active" data-route="short" style="--route: var(--orange)" aria-pressed="true">
<span class="route-card-top">
<strong>Short circuit</strong>
<span class="distance">420 m</span>
</span>
<span class="route-card-meta">
<span>8 min</span><span>4 benches</span><span>Water point</span>
</span>
</button>
<button class="route-card" data-route="long" style="--route: var(--teal)" aria-pressed="false">
<span class="route-card-top">
<strong>Long circuit</strong>
<span class="distance">980 m</span>
</span>
<span class="route-card-meta">
<span>18 min</span><span>6 benches</span><span>Water point</span>
</span>
</button>
</div>
</section>
<section class="panel detail-card" aria-live="polite">
<button id="detailClose" aria-label="Close rest point details">×</button>
<p class="eyebrow" id="detailEyebrow">Short circuit</p>
<h2 id="detailTitle">The Courtyard Loop</h2>
<p id="detailText">Follow the orange markers for an easy garden loop with four benches and a shared water point.</p>
</section>
<div class="panel legend" aria-label="Map legend">
<span class="legend-item"><i class="legend-line short"></i>Short route</span>
<span class="legend-item"><i class="legend-line long"></i>Long route</span>
<span class="legend-item"><i class="legend-dot"></i>Water point</span>
</div>
<nav class="panel controls" aria-label="Camera controls">
<button class="control-button" id="rotateLeft" aria-label="Rotate left">↶</button>
<button class="control-button" id="rotateRight" aria-label="Rotate right">↷</button>
<span class="control-separator"></span>
<button class="control-button" id="zoomOut" aria-label="Zoom out">−</button>
<button class="control-button" id="zoomIn" aria-label="Zoom in">+</button>
<button class="control-button" id="resetView" aria-label="Reset camera view" title="Reset view">⌂</button>
</nav>
<div class="loading" id="loading">
<div class="loading-inner">
<div class="loading-cubes"><i></i><i></i><i></i></div>
<strong>Growing the garden</strong>
<small>Loading the public route map…</small>
</div>
</div>
<p id="announcement" class="visually-hidden" aria-live="polite"></p>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const announcement = document.querySelector("#announcement");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe9e6);
scene.fog = new THREE.Fog(0xdfe9e6, 78, 145);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const camera = new THREE.OrthographicCamera(-40, 40, 24, -24, 0.1, 200);
const cameraView = {
azimuth: 0.72,
polar: 0.73,
zoom: 0.94,
target: new THREE.Vector3(0, 0, 0)
};
const hemi = new THREE.HemisphereLight(0xf4fbff, 0x73835d, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d7, 3.2);
sun.position.set(-30, 48, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -48;
sun.shadow.camera.right = 48;
sun.shadow.camera.top = 42;
sun.shadow.camera.bottom = -42;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 110;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9dce6, 0.75);
fill.position.set(25, 18, -30);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
});
}
const mats = {
soil: material(0x765e49),
soilDark: material(0x604c3c),
grass: material(0x91b878),
grassDark: material(0x71995f),
curb: material(0xd8d0b8),
pathShort: material(0xe2aa82),
pathLong: material(0xb7c9bc),
pathNeutral: material(0xd8c9ad),
plaza: material(0xd8d1bd),
wood: material(0xa86f43),
woodLight: material(0xc58a57),
woodDark: material(0x754b35),
metal: material(0x40514c, { metalness: 0.38, roughness: 0.55 }),
stone: material(0xb9b8aa),
stoneLight: material(0xd8d5c4),
water: material(0x58aeca, { roughness: 0.2, metalness: 0.05 }),
waterDeep: material(0x327f9e, { roughness: 0.35 }),
trunk: material(0x765039),
shrub: material(0x5d8d55),
shrubLight: material(0x7fa563),
stem: material(0x527846),
blossomPink: material(0xe7a2a7),
blossomYellow: material(0xefc761),
blossomWhite: material(0xf1eee0),
blossomBlue: material(0x8cb9d3)
};
function box(parent, mat, sx, sy, sz, x, y, z, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function instanceBoxes(items, mat, cast = true, receive = true) {
const mesh = new THREE.InstancedMesh(unitBox, mat, items.length);
const dummy = new THREE.Object3D();
let hasColor = false;
items.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, item.ry || 0, 0);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (item.color !== undefined) {
mesh.setColorAt(index, new THREE.Color(item.color));
hasColor = true;
}
});
mesh.instanceMatrix.needsUpdate = true;
if (hasColor && mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
return mesh;
}
// Layered voxel landscape.
box(scene, mats.soilDark, 72, 1.6, 58, 0, -1.1, 0, false, true);
box(scene, mats.soil, 71.2, 0.7, 57.2, 0, -0.38, 0, false, true);
box(scene, mats.grass, 70, 0.55, 56, 0, 0, 0, false, true);
const curbItems = [];
for (let x = -34; x <= 34; x += 2) {
curbItems.push({ x, y: 0.37, z: -27.65, sx: 1.85, sy: 0.32, sz: 0.55 });
curbItems.push({ x, y: 0.37, z: 27.65, sx: 1.85, sy: 0.32, sz: 0.55 });
}
for (let z = -25.5; z <= 25.5; z += 2) {
curbItems.push({ x: -34.65, y: 0.37, z, sx: 0.55, sy: 0.32, sz: 1.85 });
curbItems.push({ x: 34.65, y: 0.37, z, sx: 0.55, sy: 0.32, sz: 1.85 });
}
instanceBoxes(curbItems, mats.curb, false, true);
const shortPoint = t => {
const a = t * Math.PI * 2;
return new THREE.Vector3(14 * Math.cos(a), 0, 8.5 * Math.sin(a));
};
const longPoint = t => {
const a = t * Math.PI * 2;
return new THREE.Vector3(
27 * Math.cos(a) + 1.2 * Math.sin(a * 2),
0,
17.5 * Math.sin(a) + 0.8 * Math.cos(a * 2)
);
};
function segmentItem(a, b, width, height, y) {
const dx = b.x - a.x;
const dz = b.z - a.z;
return {
x: (a.x + b.x) * 0.5,
y,
z: (a.z + b.z) * 0.5,
sx: Math.hypot(dx, dz) + 0.12,
sy: height,
sz: width,
ry: -Math.atan2(dz, dx)
};
}
function buildLoop(pointFn, pathMat, dashMat, segments = 72) {
const tiles = [];
const dashes = [];
let previous = pointFn(0);
for (let i = 0; i < segments; i++) {
const next = pointFn((i + 1) / segments);
const tile = segmentItem(previous, next, 2.25, 0.15, 0.34);
tiles.push(tile);
if (i % 4 === 0) {
dashes.push({
x: tile.x,
y: 0.435,
z: tile.z,
sx: 0.8,
sy: 0.055,
sz: 0.19,
ry: tile.ry
});
}
previous = next;
}
const path = instanceBoxes(tiles, pathMat, false, true);
const dash = instanceBoxes(dashes, dashMat, false, false);
dash.renderOrder = 2;
return { path, dash };
}
const shortDashMat = new THREE.MeshStandardMaterial({
color: 0xdc8256,
emissive: 0x5d2613,
emissiveIntensity: 0.12,
roughness: 0.8,
transparent: true,
opacity: 1,
depthWrite: false
});
const longDashMat = new THREE.MeshStandardMaterial({
color: 0x2b9e96,
emissive: 0x0b3936,
emissiveIntensity: 0.12,
roughness: 0.8,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const routes = {
short: {
name: "Short circuit",
title: "The Courtyard Loop",
point: shortPoint,
rx: 14,
rz: 8.5,
color: 0xdc8256,
selectedPath: new THREE.Color(0xe2aa82),
mutedPath: new THREE.Color(0xc9b9a4),
pathMat: mats.pathShort,
dashMat: shortDashMat
},
long: {
name: "Long circuit",
title: "The Perimeter Walk",
point: longPoint,
rx: 27,
rz: 17.5,
color: 0x2b9e96,
selectedPath: new THREE.Color(0x87beb5),
mutedPath: new THREE.Color(0xb8beb4),
pathMat: mats.pathLong,
dashMat: longDashMat
}
};
routes.short.geometry = buildLoop(shortPoint, routes.short.pathMat, shortDashMat, 64);
routes.long.geometry = buildLoop(longPoint, routes.long.pathMat, longDashMat, 88);
// A shared accessible spur connects the plaza, short loop, and long loop.
const branchItems = [
segmentItem(new THREE.Vector3(0, 0, 0), shortPoint(0), 1.55, 0.15, 0.34),
segmentItem(shortPoint(0), longPoint(0), 1.55, 0.15, 0.34)
];
instanceBoxes(branchItems, mats.pathNeutral, false, true);
// Square-voxel central plaza.
const plazaItems = [];
for (let x = -4.7; x <= 4.7; x += 0.78) {
for (let z = -4.7; z <= 4.7; z += 0.78) {
if (Math.hypot(x, z) < 4.95) {
plazaItems.push({
x, y: 0.34, z,
sx: 0.72, sy: 0.12, sz: 0.72,
ry: ((x + z) % 2) * 0.012
});
}
}
}
instanceBoxes(plazaItems, mats.plaza, false, true);
function makeTree(x, z, scale, type = 0) {
const group = new THREE.Group();
group.position.set(x, 0.2, z);
group.scale.setScalar(scale);
scene.add(group);
const palettes = [
[0x4f7d49, 0x5f9153, 0x78a45d],
[0x315f46, 0x427455, 0x568a5b],
[0xb76f7a, 0xd3919a, 0xe5aeb2]
];
const leaves = palettes[type];
box(group, mats.trunk, 0.58, 2.6, 0.58, 0, 1.3, 0);
box(group, material(leaves[0]), 3.25, 1.65, 3.15, 0, 3.05, 0);
box(group, material(leaves[1]), 2.45, 1.35, 2.4, 0, 4.15, 0);
if (type === 0) {
box(group, material(leaves[2]), 1.35, 1.2, 1.5, -1.45, 2.7, 0.15);
box(group, material(leaves[1]), 1.35, 1.15, 1.4, 1.45, 2.75, -0.1);
} else if (type === 1) {
box(group, material(leaves[2]), 2.8, 0.7, 2.7, 0, 4.95, 0);
box(group, material(leaves[0]), 1.75, 1.2, 1.75, 0, 5.65, 0);
} else {
box(group, material(leaves[2]), 1.1, 0.85, 1.2, -1.2, 3.8, 0.2);
box(group, material(leaves[1]), 1.05, 0.8, 1.1, 1.15, 3.7, -0.15);
}
}
const treePositions = [
[-31,-20,1.05,0], [-30,-11,.82,1], [-32,1,1,0], [-31,13,1.08,2],
[-27,21,.88,0], [-19,24,1,1], [-8,24,.82,0], [7,24,1.05,2],
[19,23,.88,0], [29,18,1,1], [32,8,.82,0], [32,-4,1,2],
[29,-17,1.05,0], [20,-23,.9,1], [5,-24,.78,0], [-10,-24,1,2],
[-22,-22,.9,0], [-7,1,.72,0], [7,1,.76,2], [-5,-4,.62,1],
[5,-4,.68,0], [0,6,.58,2]
];
treePositions.forEach(args => makeTree(...args));
function seededRandom(seed) {
return function() {
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 random = seededRandom(48291);
function makeBed(x, z, width, depth, seed) {
box(scene, mats.soilDark, width, 0.24, depth, x, 0.36, z, false, true);
box(scene, mats.curb, width + 0.22, 0.18, 0.18, x, 0.4, z - depth / 2, false, true);
box(scene, mats.curb, width + 0.22, 0.18, 0.18, x, 0.4, z + depth / 2, false, true);
const stems = [];
const flowers = [];
const colors = [0xe7a2a7, 0xefc761, 0xf1eee0, 0x8cb9d3];
const r = seededRandom(seed);
for (let i = 0; i < 38; i++) {
const fx = x + (r() - 0.5) * (width - 0.55);
const fz = z + (r() - 0.5) * (depth - 0.55);
const height = 0.32 + r() * 0.25;
stems.push({ x: fx, y: 0.48 + height / 2, z: fz, sx: 0.07, sy: height, sz: 0.07 });
flowers.push({
x: fx, y: 0.51 + height, z: fz,
sx: 0.19, sy: 0.19, sz: 0.19,
color: colors[Math.floor(r() * colors.length)]
});
}
instanceBoxes(stems, mats.stem, false, true);
instanceBoxes(flowers, material(0xffffff), false, true);
}
makeBed(-20, -2, 7, 4, 11);
makeBed(20, -2, 7, 4, 23);
makeBed(-18, 8, 6, 3, 37);
makeBed(18, 8, 6, 3, 49);
makeBed(-17, -12, 8, 3, 61);
makeBed(17, -12, 8, 3, 79);
function distanceToRoute(x, z, fn) {
let best = Infinity;
for (let i = 0; i < 40; i++) {
const p = fn(i / 40);
best = Math.min(best, Math.hypot(x - p.x, z - p.z));
}
return best;
}
const shrubItems = [];
for (let i = 0; i < 250; i++) {
const x = (random() - 0.5) * 66;
const z = (random() - 0.5) * 51;
if (Math.hypot(x, z) < 6) continue;
if (distanceToRoute(x, z, shortPoint) < 1.8) continue;
if (distanceToRoute(x, z, longPoint) < 1.8) continue;
const size = 0.45 + random() * 0.55;
shrubItems.push({
x, y: 0.3 + size / 2, z,
sx: size, sy: size * (0.7 + random() * 0.45), sz: size,
color: random() > 0.45 ? 0x5d8d55 : 0x7fa563
});
}
instanceBoxes(shrubItems, material(0xffffff), true, true);
const grassItems = [];
for (let i = 0; i < 190; i++) {
const x = (random() - 0.5) * 67;
const z = (random() - 0.5) * 52;
if (Math.hypot(x, z) < 5.5) continue;
if (distanceToRoute(x, z, shortPoint) < 1.35) continue;
if (distanceToRoute(x, z, longPoint) < 1.35) continue;
const h = 0.35 + random() * 0.35;
grassItems.push({
x, y: 0.24 + h / 2, z,
sx: 0.07, sy: h, sz: 0.07,
ry: (random() - 0.5) * 0.3,
color: random() > 0.5 ? 0x537d49 : 0x77985a
});
}
instanceBoxes(grassItems, material(0xffffff), false, true);
// Rest-point data and meshes.
const pois = [];
const restMeshes = [];
function registerRest(group, poi) {
poi.group = group;
poi.anchor = new THREE.Vector3(
group.position.x,
group.position.y + (poi.type === "water" ? 3.5 : 2.55),
group.position.z
);
pois.push(poi);
group.traverse(child => {
if (child.isMesh) {
child.userData.poi = poi;
restMeshes.push(child);
}
});
}
function createBench(routeId, index, t) {
const route = routes[routeId];
const p = route.point(t);
const outward = new THREE.Vector3(p.x / route.rx, 0, p.z / route.rz).normalize();
const inward = outward.clone().negate();
const position = p.clone().addScaledVector(outward, 2.35);
const group = new THREE.Group();
group.position.set(position.x, 0.2, position.z);
group.rotation.y = Math.atan2(inward.x, inward.z);
scene.add(group);
// Legs.
box(group, mats.metal, 0.22, 0.72, 0.72, -1.18, 0.42, 0);
box(group, mats.metal, 0.22, 0.72, 0.72, 1.18, 0.42, 0);
box(group, mats.metal, 0.18, 1.2, 0.18, -1.28, 1.05, -0.47);
box(group, mats.metal, 0.18, 1.2, 0.18, 1.28, 1.05, -0.47);
// Seat slats.
for (let i = 0; i < 4; i++) {
box(group, i % 2 ? mats.woodLight : mats.wood, 3.2, 0.17, 0.18, 0, 0.83, -0.34 + i * 0.23);
}
// Back slats.
for (let i = 0; i < 3; i++) {
box(group, mats.wood, 3.05, 0.17, 0.18, 0, 1.2 + i * 0.25, -0.49);
}
// Route-color plaque.
const plaque = new THREE.MeshBasicMaterial({ color: route.color });
box(group, plaque, 0.48, 0.14, 0.07, 0, 1.32, -0.63, false, false);
// Armrests.
box(group, mats.metal, 0.16, 0.16, 0.95, -1.4, 1.08, 0.05);
box(group, mats.metal, 0.16, 0.16, 0.95, 1.4, 1.08, 0.05);
const poi = {
id: `${routeId}-bench-${index}`,
type: "bench",
routes: [routeId],
routeId,
title: `Bench ${String(index).padStart(2, "0")}`,
subtitle: "Rest • shade",
detail: "Timber slats, back support and arm rests. The bench is set just beside the marked path.",
color: route.color
};
registerRest(group, poi);
}
createBench("short", 1, 0.08);
createBench("short", 2, 0.33);
createBench("short", 3, 0.60);
createBench("short", 4, 0.86);
createBench("long", 1, 0.08);
createBench("long", 2, 0.27);
createBench("long", 3, 0.45);
createBench("long", 4, 0.63);
createBench("long", 5, 0.81);
createBench("long", 6, 0.95);
// Shared drinking-water point.
const waterGroup = new THREE.Group();
waterGroup.position.set(0, 0.34, 0);
scene.add(waterGroup);
box(waterGroup, mats.stone, 3.25, 0.28, 3.25, 0, 0.14, 0);
box(waterGroup, mats.stoneLight, 2.35, 0.35, 2.35, 0, 0.42, 0);
box(waterGroup, mats.waterDeep, 1.72, 0.17, 1.72, 0, 0.66, 0);
box(waterGroup, mats.water, 1.5, 0.07, 1.5, 0, 0.78, 0);
box(waterGroup, mats.stoneLight, 0.42, 1.25, 0.42, 0, 1.22, -0.72);
box(waterGroup, mats.metal, 0.17, 0.17, 0.92, 0, 1.74, -0.35);
box(waterGroup, mats.metal, 0.42, 0.17, 0.17, 0, 1.74, -0.02);
box(waterGroup, material(0x3d91bd, { emissive: 0x123849, emissiveIntensity: 0.2 }),
0.48, 0.48, 0.1, 0, 1.24, -0.47, false, false);
const waterPoi = {
id: "water-point",
type: "water",
routes: ["short", "long"],
routeId: null,
title: "Water point",
subtitle: "Drinking water",
detail: "A shared refill point on the central plaza, connected to both circuits by the level garden path.",
color: 0x3d91bd
};
registerRest(waterGroup, waterPoi);
// Canvas-backed voxel signs.
function signTexture(title, subtitle, accent) {
const c = document.createElement("canvas");
c.width = 512;
c.height = 256;
const ctx = c.getContext("2d");
ctx.fillStyle = "#f4f0df";
ctx.fillRect(0, 0, 512, 256);
ctx.fillStyle = `#${new THREE.Color(accent).getHexString()}`;
ctx.fillRect(0, 0, 512, 27);
ctx.fillRect(28, 71, 10, 88);
ctx.fillRect(474, 71, 10, 88);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#20342d";
ctx.font = "800 48px system-ui, sans-serif";
ctx.fillText(title, 256, 92);
ctx.fillStyle = "#53665d";
ctx.font = "600 28px system-ui, sans-serif";
ctx.fillText(subtitle, 256, 166);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createSign(x, z, rotation, title, subtitle, accent) {
const group = new THREE.Group();
group.position.set(x, 0.22, z);
group.rotation.y = rotation;
scene.add(group);
box(group, mats.woodDark, 0.25, 2.65, 0.25, -1.22, 1.32, 0);
box(group, mats.woodDark, 0.25, 2.65, 0.25, 1.22, 1.32, 0);
const face = new THREE.MeshStandardMaterial({
map: signTexture(title, subtitle, accent),
roughness: 0.9
});
const edge = new THREE.MeshStandardMaterial({ color: 0x77533c, roughness: 0.9 });
const back = new THREE.MeshStandardMaterial({ color: 0xb48a61, roughness: 0.9 });
const board = new THREE.Mesh(unitBox, [edge, edge, edge, edge, face, back]);
board.scale.set(4.2, 2.1, 0.25);
board.position.y = 2.35;
board.castShadow = true;
board.receiveShadow = true;
group.add(board);
return group;
}
function createRouteSign(routeId, t) {
const route = routes[routeId];
const p = route.point(t);
const outward = new THREE.Vector3(p.x / route.rx, 0, p.z / route.rz).normalize();
const position = p.clone().addScaledVector(outward, 1.75);
const inward = outward.clone().negate();
const count = routeId === "short" ? "4 benches" : "6 benches";
createSign(
position.x,
position.z,
Math.atan2(inward.x, inward.z),
routeId === "short" ? "SHORT LOOP" : "LONG LOOP",
`${count} • WATER`,
route.color
);
}
createRouteSign("short", 0.16);
createRouteSign("long", 0.16);
createSign(4.9, 3.15, 0, "REST GARDEN", "PUBLIC ROUTES", 0x5e8c5a);
createSign(0, 25.7, 0, "COMMON GROUND", "TAKE A REST • TAKE A WALK", 0x2b9e96);
// DOM labels projected from world positions.
function makeLabel(poi) {
const button = document.createElement("button");
button.className = "poi-label";
button.style.setProperty("--poi-color", `#${new THREE.Color(poi.color).getHexString()}`);
button.innerHTML = `
<span class="poi-dot"></span>
<span><b>${poi.title}</b><small>${poi.subtitle}</small></span>
`;
button.setAttribute("aria-label", `${poi.title}, ${poi.subtitle}`);
button.addEventListener("click", event => {
event.stopPropagation();
selectRest(poi);
});
labelsLayer.appendChild(button);
poi.label = button;
}
pois.forEach(makeLabel);
// Selection frame around the active rest point.
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0xdc8256,
transparent: true,
opacity: 0.9,
depthWrite: false
});
const selectionMarker = new THREE.Group();
box(selectionMarker, selectionMaterial, 4.4, 0.07, 0.12, 0, 0, -1.25, false, false);
box(selectionMarker, selectionMaterial, 4.4, 0.07, 0.12, 0, 0, 1.25, false, false);
box(selectionMarker, selectionMaterial, 0.12, 0.07, 2.62, -2.2, 0, 0, false, false);
box(selectionMarker, selectionMaterial, 0.12, 0.07, 2.62, 2.2, 0, 0, false, false);
selectionMarker.visible = false;
scene.add(selectionMarker);
let activeRoute = "short";
let selectedPoi = null;
const detailEyebrow = document.querySelector("#detailEyebrow");
const detailTitle = document.querySelector("#detailTitle");
const detailText = document.querySelector("#detailText");
function showRouteDetail() {
const route = routes[activeRoute];
detailEyebrow.textContent = route.name;
detailTitle.textContent = route.title;
detailText.textContent = activeRoute === "short"
? "Follow the orange markers for an easy garden loop with four benches and a shared water point."
: "Follow the teal markers around the perimeter, with six benches and access to the central water point.";
}
function setActiveRoute(routeId) {
activeRoute = routeId;
selectedPoi = null;
selectionMarker.visible = false;
document.querySelectorAll(".route-card").forEach(button => {
const active = button.dataset.route === routeId;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
pois.forEach(poi => {
const visible = poi.routes.includes(routeId);
poi.label.style.display = visible ? "flex" : "none";
poi.label.classList.remove("selected");
});
showRouteDetail();
announcement.textContent = `${routes[routeId].name} selected.`;
}
function selectRest(poi) {
selectedPoi = poi;
const route = routes[poi.routeId || activeRoute];
detailEyebrow.textContent = poi.type === "water" ? "Shared facility" : route.name;
detailTitle.textContent = poi.title;
detailText.textContent = poi.detail;
pois.forEach(item => item.label.classList.toggle("selected", item === poi));
selectionMaterial.color.setHex(poi.type === "water" ? 0x3d91bd : route.color);
selectionMarker.position.set(poi.group.position.x, 0.46, poi.group.position.z);
selectionMarker.scale.setScalar(poi.type === "water" ? 0.78 : 1);
selectionMarker.visible = true;
announcement.textContent = `${poi.title} selected.`;
}
document.querySelectorAll(".route-card").forEach(button => {
button.addEventListener("click", () => setActiveRoute(button.dataset.route));
});
document.querySelector("#detailClose").addEventListener("click", () => {
selectedPoi = null;
selectionMarker.visible = false;
pois.forEach(poi => poi.label.classList.remove("selected"));
showRouteDetail();
});
// Direct camera controls: orbit, wheel zoom, and pinch zoom.
function updateCamera() {
const sinPolar = Math.sin(cameraView.polar);
const radius = 60;
camera.position.set(
cameraView.target.x + radius * sinPolar * Math.sin(cameraView.azimuth),
cameraView.target.y + radius * Math.cos(cameraView.polar),
cameraView.target.z + radius * sinPolar * Math.cos(cameraView.azimuth)
);
camera.lookAt(cameraView.target);
camera.zoom = cameraView.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(48, 78 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const pointers = new Map();
let pinchDistance = 0;
let dragDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragDistance = 0;
if (pointers.size === 2) pinchDistance = pointerDistance();
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragDistance += Math.hypot(dx, dy);
if (pointers.size === 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
cameraView.zoom = THREE.MathUtils.clamp(
cameraView.zoom * (distance / pinchDistance),
0.58,
2.15
);
}
pinchDistance = distance;
} else {
cameraView.azimuth -= dx * 0.005;
cameraView.polar = THREE.MathUtils.clamp(
cameraView.polar - dy * 0.004,
0.42,
1.18
);
}
});
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
canvas.addEventListener("pointerup", event => {
const wasClick = dragDistance < 5 && pointers.size === 1;
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (wasClick) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(restMeshes, false);
if (hits.length) selectRest(hits[0].object.userData.poi);
}
});
canvas.addEventListener("pointercancel", event => {
pointers.delete(event.pointerId);
pinchDistance = 0;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraView.zoom = THREE.MathUtils.clamp(
cameraView.zoom * Math.exp(-event.deltaY * 0.001),
0.58,
2.15
);
}, { passive: false });
canvas.addEventListener("contextmenu", event => event.preventDefault());
function resetView() {
cameraView.azimuth = 0.72;
cameraView.polar = 0.73;
cameraView.zoom = window.innerWidth < 760 ? 0.98 : 0.94;
cameraView.target.set(0, 0, 0);
}
document.querySelector("#rotateLeft").addEventListener("click", () => {
cameraView.azimuth += 0.22;
});
document.querySelector("#rotateRight").addEventListener("click", () => {
cameraView.azimuth -= 0.22;
});
document.querySelector("#zoomIn").addEventListener("click", () => {
cameraView.zoom = THREE.MathUtils.clamp(cameraView.zoom * 1.15, 0.58, 2.15);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
cameraView.zoom = THREE.MathUtils.clamp(cameraView.zoom / 1.15, 0.58, 2.15);
});
document.querySelector("#resetView").addEventListener("click", resetView);
window.addEventListener("keydown", event => {
if (["BUTTON", "INPUT", "TEXTAREA"].includes(document.activeElement.tagName)) return;
const key = event.key;
if (key === "ArrowLeft") cameraView.azimuth += 0.12;
else if (key === "ArrowRight") cameraView.azimuth -= 0.12;
else if (key === "ArrowUp") cameraView.polar = Math.max(0.42, cameraView.polar - 0.08);
else if (key === "ArrowDown") cameraView.polar = Math.min(1.18, cameraView.polar + 0.08);
else if (key === "+" || key === "=") cameraView.zoom = Math.min(2.15, cameraView.zoom * 1.1);
else if (key === "-") cameraView.zoom = Math.max(0.58, cameraView.zoom / 1.1);
else if (key === "0") resetView();
else return;
event.preventDefault();
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
pois.forEach(poi => {
if (!poi.label || poi.label.style.display === "none") return;
projected.copy(poi.anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1 &&
projected.x > -1.12 && projected.x < 1.12 &&
projected.y > -1.1 && projected.y < 1.1;
poi.label.style.visibility = visible ? "visible" : "hidden";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
poi.label.style.left = `${x}px`;
poi.label.style.top = `${y}px`;
});
}
setActiveRoute("short");
let lastTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
Object.values(routes).forEach(route => {
const selected = route === routes[activeRoute];
const targetColor = selected ? route.selectedPath : route.mutedPath;
route.pathMat.color.lerp(targetColor, 1 - Math.exp(-delta * 7));
route.dashMat.opacity = THREE.MathUtils.lerp(
route.dashMat.opacity,
selected ? 1 : 0.28,
1 - Math.exp(-delta * 8)
);
});
if (selectionMarker.visible) {
const pulse = 1 + Math.sin(now * 0.004) * 0.035;
selectionMarker.scale.multiplyScalar(pulse / selectionMarker.scale.x);
}
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 600);
});
</script>
</body>
</html>
```