Prompt specification
Build or customize the Three.js 3D scene "Park hydration and rest node" 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: Park hydration and rest node
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/park-hydration-and-rest-node-x0427
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows accessible drinking fountains. Compose a park junction with fountains, bench, bottle refill point, and signs; walkers pause without blocking the through-route connecting the surrounding paths. Voxel style.
Working Three.js Starter (park-hydration-and-rest-node-x0427):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Accessible Park Junction</title>
<style>
:root {
--ink: #173c42;
--muted: #557176;
--panel: rgba(255, 252, 240, 0.93);
--border: rgba(23, 60, 66, 0.14);
--blue: #167b91;
--gold: #e5b84c;
--green: #4e8d63;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfe8e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#scene:focus-visible {
outline: 4px solid var(--gold);
outline-offset: -6px;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 20px 17px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 14px 38px rgba(24, 65, 63, 0.14);
backdrop-filter: blur(12px);
}
.eyebrow {
margin: 0 0 7px;
color: var(--blue);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 32px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.panel p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.actions {
position: absolute;
top: 22px;
right: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: min(480px, calc(100vw - 44px));
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(23, 60, 66, 0.16);
border-radius: 10px;
background: rgba(255, 252, 240, 0.95);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 5px 16px rgba(24, 65, 63, 0.1);
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(22, 123, 145, 0.5);
}
button:focus-visible {
outline: 3px solid var(--gold);
outline-offset: 2px;
}
button[aria-pressed="true"] {
border-color: var(--blue);
background: #dff0ec;
color: #0c6173;
}
.zoom {
min-width: 38px;
padding: 0 10px;
font-size: 18px;
}
.legend {
position: absolute;
left: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100vw - 44px);
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 9px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(255, 252, 240, 0.92);
color: #466267;
font-size: 11px;
font-weight: 700;
box-shadow: 0 5px 16px rgba(24, 65, 63, 0.08);
}
.dot {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--green);
}
.dot.blue {
background: var(--blue);
}
.dot.gold {
background: var(--gold);
}
.help {
position: absolute;
right: 22px;
bottom: 22px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(23, 60, 66, 0.82);
color: #f8f4e8;
font-size: 11px;
line-height: 1.45;
text-align: right;
}
#status {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 20;
background: #cfe8e2;
color: var(--ink);
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.panel p {
font-size: 12px;
}
.actions {
top: auto;
right: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
.legend {
display: none;
}
.help {
right: 12px;
bottom: 62px;
max-width: 210px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel-style park junction with accessible fountains, a bench, a bottle refill station, signs, and an unobstructed through-route."
></canvas>
<div class="ui">
<section class="panel" aria-labelledby="title">
<p class="eyebrow">Rivermead Park · Junction 04</p>
<h1 id="title">Water stop, off the main path</h1>
<p>
A 3.2 m clear route connects the surrounding paths. Fountains, a bench,
bottle filler, and all pause areas sit in flush paved bays beyond the
tactile edge markers.
</p>
</section>
<nav class="actions" aria-label="Scene controls">
<button id="reset" type="button">Isometric</button>
<button id="plan" type="button">Plan view</button>
<button id="route" type="button" aria-pressed="true">Route guides</button>
<button
id="zoomOut"
class="zoom"
type="button"
aria-label="Zoom out"
>−</button>
<button
id="zoomIn"
class="zoom"
type="button"
aria-label="Zoom in"
>+</button>
</nav>
<div class="legend" aria-label="Scene legend">
<span><i class="dot blue"></i> Accessible water</span>
<span><i class="dot gold"></i> Clear route edge</span>
<span><i class="dot"></i> Off-route pause bay</span>
</div>
<div class="help">
Drag to orbit · Scroll to zoom<br />
Arrow keys rotate · + / − zoom
</div>
<p id="status" role="status" aria-live="polite"></p>
</div>
<div id="loading">Building park junction…</div>
<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 status = document.querySelector("#status");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfe8e2);
scene.fog = new THREE.Fog(0xcfe8e2, 48, 88);
const camera = new THREE.OrthographicCamera(-30, 30, 18, -18, 0.1, 120);
const cameraState = {
target: new THREE.Vector3(0, 0.7, 0),
theta: 0.72,
phi: 0.98,
zoom: 1,
desiredTheta: 0.72,
desiredPhi: 0.98,
desiredZoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xf4fff8, 0x52724d, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2cf, 3.15);
sun.position.set(-13, 25, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 27;
sun.shadow.camera.bottom = -27;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bd9e2, 0.7);
fill.position.set(18, 10, -20);
scene.add(fill);
const standard = (color, roughness = 0.88) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
flatShading: true
});
const metal = (color, roughness = 0.42) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0.5,
flatShading: true
});
const M = {
grass: standard(0x78a968),
grassDark: standard(0x527f50),
base: standard(0x365f48),
path: standard(0xe8ddc3),
court: standard(0xd9ceb2),
pathEdge: standard(0xbfae88),
wood: standard(0xb7794b),
woodLight: standard(0xc99059),
metal: metal(0xafc3c2),
metalDark: metal(0x36565b),
navy: standard(0x173f48),
blue: standard(0x15849b),
blueLight: standard(0x53c4d0),
gold: standard(0xe5b84c),
cream: standard(0xf8f1d9),
water: metal(0x43b9ca, 0.22),
dark: standard(0x203c42),
skin: standard(0xd99b73),
skinLight: standard(0xefbd91),
hair: standard(0x4a342d),
shirtBlue: standard(0x4c91aa),
shirtRust: standard(0xd87659),
shirtGold: standard(0xe5b84c),
pants: standard(0x315269),
foliage: [
standard(0x4f8e59),
standard(0x5e9d5d),
standard(0x3f7d51),
standard(0x6da663)
],
trunk: standard(0x78523a)
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function block(w, h, d, material, x = 0, y = 0, z = 0, parent = scene, cast = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground and connected path network
// ------------------------------------------------------------
block(44, 1.0, 38, M.grass, 0, -0.55, 0);
block(44.4, 0.45, 38.4, M.base, 0, -1.08, 0);
// Main east-west route.
block(43.6, 0.13, 5.2, M.path, 0, 0.005, 0);
// North and south routes connect the junction to the park edges.
block(5.2, 0.12, 18.2, M.path, -12.5, -0.015, -9.1);
block(5.2, 0.12, 18.2, M.path, 12.5, -0.015, 9.1);
// Off-route water court.
block(14.0, 0.13, 4.6, M.court, 0, 0.005, -5.55);
// Flush connectors keep the route level while preserving its clear width.
block(2.25, 0.13, 1.25, M.path, -2.6, 0.005, -2.85);
block(2.25, 0.13, 1.25, M.path, 4.1, 0.005, -2.85);
block(2.5, 0.13, 1.25, M.path, 1.2, 0.005, 2.85);
// Rest bay.
block(8.5, 0.13, 4.5, M.court, 0.8, 0.005, 5.3);
// Low court edging.
for (let x = -6.6; x <= 6.6; x += 1.1) {
block(0.9, 0.09, 0.16, M.pathEdge, x, 0.11, -7.9);
}
for (let x = -3.1; x <= 4.7; x += 1.1) {
block(0.9, 0.09, 0.16, M.pathEdge, x, 0.11, 7.55);
}
// Tactile route-edge guides. They are flush and visually mark the
// 3.2 m unobstructed corridor without becoming obstacles.
const routeGuides = new THREE.Group();
scene.add(routeGuides);
for (let x = -20.3; x <= 20.3; x += 1.08) {
for (const z of [-1.7, 1.7]) {
block(0.56, 0.035, 0.18, M.gold, x, 0.087, z, routeGuides, false);
}
}
for (let z = -17.4; z <= -2.1; z += 1.08) {
for (const x of [-14.2, -10.8]) {
block(0.18, 0.035, 0.56, M.gold, x, 0.079, z, routeGuides, false);
}
}
for (let z = 2.1; z <= 17.4; z += 1.08) {
for (const x of [10.8, 14.2]) {
block(0.18, 0.035, 0.56, M.gold, x, 0.079, z, routeGuides, false);
}
}
// ------------------------------------------------------------
// Procedural sign textures
// ------------------------------------------------------------
function drawPixelIcon(ctx, type, x, y, cell) {
ctx.save();
ctx.translate(x, y);
ctx.fillStyle = "#f8f1d9";
const rect = (px, py, w = 1, h = 1) =>
ctx.fillRect(px * cell, py * cell, w * cell, h * cell);
if (type === "accessible") {
rect(5, 1);
rect(4, 3, 2, 4);
rect(5, 4, 4);
rect(4, 6, 4);
rect(7, 7, 1, 3);
rect(8, 9, 2);
// Pixelated wheel.
rect(2, 6);
rect(1, 7);
rect(1, 8);
rect(2, 9);
rect(3, 9);
rect(4, 8);
rect(4, 7);
rect(3, 6);
} else if (type === "bottle") {
rect(4, 1, 3, 2);
rect(3, 3, 5, 7);
rect(2, 4);
rect(7, 4);
rect(3, 6, 5);
} else if (type === "water") {
rect(2, 4, 7);
rect(1, 6, 9);
rect(2, 8, 7);
rect(4, 1, 3);
rect(3, 2, 5);
} else if (type === "arrow") {
rect(4, 1, 2, 8);
rect(2, 3, 2, 4);
rect(1, 4, 2, 2);
rect(3, 7, 4);
}
ctx.restore();
}
function makeBoardTexture(title, subtitle, icon = "water", accent = "#50c4cf") {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 512;
textureCanvas.height = 256;
const ctx = textureCanvas.getContext("2d");
ctx.fillStyle = "#173f48";
ctx.fillRect(0, 0, 512, 256);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 16, 256);
ctx.strokeStyle = "#f8f1d9";
ctx.lineWidth = 7;
ctx.strokeRect(18, 16, 478, 224);
drawPixelIcon(ctx, icon, 34, 48, 13);
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f8f1d9";
const titleSize = title.length > 13 ? 36 : title.length > 10 ? 41 : 47;
ctx.font = `800 ${titleSize}px Arial, sans-serif`;
ctx.fillText(title, 190, 101);
ctx.fillStyle = accent;
ctx.font = "700 25px Arial, sans-serif";
ctx.fillText(subtitle, 191, 161);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeSign({
x,
z,
title,
subtitle,
icon = "water",
accent = "#50c4cf",
width = 3.0,
height = 1.25,
centerY = 2.15,
rotation = 0
}) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.rotation.y = rotation;
scene.add(group);
const postHeight = centerY - height / 2 + 0.08;
block(0.18, postHeight, 0.18, M.metalDark, 0, postHeight / 2, 0, group);
block(width, height, 0.16, M.navy, 0, centerY, 0, group);
const texture = makeBoardTexture(title, subtitle, icon, accent);
const signMaterial = new THREE.MeshBasicMaterial({ map: texture });
const front = new THREE.Mesh(
new THREE.PlaneGeometry(width - 0.12, height - 0.1),
signMaterial
);
front.position.z = 0.087;
group.add(front);
const back = front.clone();
back.position.z = -0.087;
back.rotation.y = Math.PI;
group.add(back);
return group;
}
// ------------------------------------------------------------
// Accessible fountains and bottle refill station
// ------------------------------------------------------------
const waterStreams = [];
function makeAccessibleFountain(x, z) {
const g = new THREE.Group();
g.position.set(x, 0.08, z);
scene.add(g);
// Side supports leave visible knee and toe clearance.
block(0.18, 0.66, 0.85, M.metal, -0.57, 0.33, 0, g);
block(0.18, 0.66, 0.85, M.metal, 0.57, 0.33, 0, g);
// Recessed basin assembly.
block(1.5, 0.12, 1.0, M.metal, 0, 0.69, 0, g);
block(1.5, 0.14, 0.12, M.metal, 0, 0.82, -0.44, g);
block(1.5, 0.14, 0.12, M.metal, 0, 0.82, 0.44, g);
block(0.12, 0.14, 0.78, M.metal, -0.69, 0.82, 0, g);
block(0.12, 0.14, 0.78, M.metal, 0.69, 0.82, 0, g);
block(0.98, 0.025, 0.64, M.water, 0, 0.76, 0, g, false);
// Square voxel spout and push button.
block(0.13, 0.31, 0.13, M.metalDark, 0, 1.01, -0.39, g);
block(0.13, 0.12, 0.52, M.metalDark, 0, 1.12, -0.13, g);
block(0.13, 0.17, 0.13, M.metalDark, 0, 1.04, 0.1, g);
block(0.16, 0.16, 0.1, M.blueLight, 0.63, 0.69, 0.28, g);
const stream = block(
0.055,
0.26,
0.055,
M.blueLight,
0,
0.89,
0.1,
g,
false
);
waterStreams.push(stream);
return g;
}
function makeStandardFountain(x, z) {
const g = new THREE.Group();
g.position.set(x, 0.08, z);
scene.add(g);
block(0.68, 1.02, 0.68, M.metal, 0, 0.51, 0, g);
block(1.28, 0.12, 0.94, M.metal, 0, 1.06, 0, g);
block(0.92, 0.025, 0.58, M.water, 0, 1.13, 0, g, false);
block(0.12, 0.34, 0.12, M.metalDark, 0, 1.27, -0.34, g);
block(0.12, 0.12, 0.46, M.metalDark, 0, 1.39, -0.11, g);
block(0.12, 0.17, 0.12, M.metalDark, 0, 1.31, 0.09, g);
block(0.15, 0.15, 0.1, M.blueLight, 0.37, 1.02, 0.26, g);
return g;
}
function makeBottleRefill(x, z) {
const g = new THREE.Group();
g.position.set(x, 0.08, z);
scene.add(g);
block(1.28, 1.82, 0.68, M.metal, 0, 0.91, 0, g);
block(1.0, 1.02, 0.08, M.navy, 0, 1.19, 0.37, g);
block(0.62, 0.3, 0.12, M.blue, 0, 1.38, 0.43, g);
block(0.13, 0.28, 0.13, M.metalDark, 0, 1.14, 0.48, g);
block(0.12, 0.12, 0.3, M.metalDark, 0, 1.02, 0.57, g);
block(0.12, 0.14, 0.12, M.metalDark, 0, 0.95, 0.69, g);
block(0.17, 0.14, 0.1, M.blueLight, 0.47, 1.18, 0.38, g);
// A voxel bottle in a side holder.
block(0.27, 0.42, 0.27, M.blueLight, 0.83, 0.58, 0, g);
block(0.16, 0.17, 0.16, M.blueLight, 0.83, 0.87, 0, g);
block(0.19, 0.08, 0.19, M.cream, 0.83, 0.99, 0, g);
block(0.09, 0.58, 0.09, M.metalDark, 0.96, 0.58, 0, g);
const stream = block(
0.045,
0.16,
0.045,
M.blueLight,
0,
0.87,
0.69,
g,
false
);
waterStreams.push(stream);
return g;
}
makeAccessibleFountain(-2.6, -5.55);
makeStandardFountain(-5.0, -5.55);
makeBottleRefill(4.1, -5.6);
makeSign({
x: -0.1,
z: -7.05,
title: "WATER",
subtitle: "LOW + STANDARD BASINS",
icon: "accessible",
accent: "#53c4d0",
width: 3.55,
height: 1.35,
centerY: 2.35
});
makeSign({
x: 5.8,
z: -7.05,
title: "REFILL",
subtitle: "FILTERED WATER",
icon: "bottle",
accent: "#e5b84c",
width: 3.0,
height: 1.35,
centerY: 2.35
});
makeSign({
x: 8.35,
z: 3.0,
title: "THROUGH ROUTE",
subtitle: "3.2 m - KEEP CLEAR",
icon: "arrow",
accent: "#e5b84c",
width: 3.55,
height: 1.2,
centerY: 1.85,
rotation: -0.12
});
// ------------------------------------------------------------
// Voxel bench
// ------------------------------------------------------------
const bench = new THREE.Group();
bench.position.set(0.8, 0.08, 5.35);
scene.add(bench);
for (let i = 0; i < 4; i++) {
block(
4.25,
0.12,
0.17,
i % 2 ? M.wood : M.woodLight,
0,
0.64,
-0.30 + i * 0.20,
bench
);
}
for (const y of [0.96, 1.21, 1.46]) {
block(4.25, 0.15, 0.12, M.wood, 0, y, 0.42, bench);
}
for (const x of [-1.55, 1.55]) {
block(0.14, 0.66, 0.15, M.metalDark, x, 0.33, -0.22, bench);
block(0.14, 0.66, 0.15, M.metalDark, x, 0.33, 0.28, bench);
block(0.12, 0.95, 0.13, M.metalDark, x, 0.75, 0.4, bench);
block(0.12, 0.12, 0.78, M.metalDark, x, 0.79, 0.05, bench);
}
// ------------------------------------------------------------
// Stylized voxel walkers
// ------------------------------------------------------------
function makeStanding({
shirt = M.shirtBlue,
pants = M.pants,
skin = M.skin,
hair = M.hair
} = {}) {
const root = new THREE.Group();
const legs = [];
const arms = [];
for (const x of [-0.18, 0.18]) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.87, 0);
root.add(pivot);
block(0.21, 0.70, 0.22, pants, 0, -0.35, 0, pivot);
block(0.23, 0.15, 0.36, M.dark, 0, -0.75, 0.06, pivot);
legs.push(pivot);
}
block(0.64, 0.65, 0.36, shirt, 0, 1.18, 0, root);
block(0.46, 0.46, 0.43, skin, 0, 1.76, 0, root);
block(0.49, 0.13, 0.45, hair, 0, 1.98, 0, root);
block(0.10, 0.10, 0.10, skin, 0, 1.75, 0.24, root);
for (const x of [-0.41, 0.41]) {
const pivot = new THREE.Group();
pivot.position.set(x, 1.47, 0);
root.add(pivot);
block(0.17, 0.58, 0.20, shirt, 0, -0.29, 0, pivot);
block(0.18, 0.18, 0.19, skin, 0, -0.64, 0, pivot);
arms.push(pivot);
}
return { root, legs, arms };
}
function makeSeated({ shirt = M.shirtRust, skin = M.skinLight } = {}) {
const root = new THREE.Group();
block(0.64, 0.65, 0.36, shirt, 0, 1.13, 0, root);
block(0.46, 0.46, 0.43, skin, 0, 1.69, 0, root);
block(0.49, 0.13, 0.45, M.hair, 0, 1.91, 0, root);
block(0.10, 0.10, 0.10, skin, 0, 1.68, 0.24, root);
for (const x of [-0.18, 0.18]) {
block(0.21, 0.22, 0.57, M.pants, x, 0.55, 0.28, root);
block(0.20, 0.48, 0.21, M.pants, x, 0.30, 0.53, root);
block(0.23, 0.14, 0.35, M.dark, x, 0.08, 0.59, root);
}
for (const x of [-0.41, 0.41]) {
const arm = new THREE.Group();
arm.position.set(x, 1.35, 0);
root.add(arm);
block(0.16, 0.54, 0.18, shirt, 0, -0.27, 0, arm);
block(0.17, 0.16, 0.18, skin, 0, -0.59, 0.03, arm);
}
return root;
}
function makeWheelchairUser() {
const root = new THREE.Group();
// Voxel wheels: small cubes arranged into a circular silhouette.
for (const x of [-0.47, 0.47]) {
for (let i = 0; i < 16; i++) {
const a = (i / 16) * Math.PI * 2;
block(
0.13,
0.13,
0.13,
M.dark,
x,
0.43 + Math.cos(a) * 0.37,
-0.18 + Math.sin(a) * 0.37,
root
);
}
block(0.15, 0.15, 0.15, M.metal, x, 0.43, -0.18, root);
block(0.11, 0.12, 0.12, M.dark, x, 0.13, 0.47, root);
}
block(0.84, 0.14, 0.72, M.metalDark, 0, 0.57, 0, root);
block(0.84, 0.73, 0.14, M.metalDark, 0, 0.95, -0.32, root);
block(0.12, 0.12, 0.64, M.metalDark, -0.39, 0.48, 0.1, root);
block(0.12, 0.12, 0.64, M.metalDark, 0.39, 0.48, 0.1, root);
block(0.82, 0.12, 0.12, M.metalDark, 0, 0.22, 0.47, root);
// Seated person.
block(0.62, 0.63, 0.35, M.shirtGold, 0, 1.13, 0.02, root);
block(0.45, 0.45, 0.42, M.skinLight, 0, 1.69, 0.02, root);
block(0.48, 0.13, 0.44, M.hair, 0, 1.91, 0.01, root);
block(0.10, 0.10, 0.10, M.skinLight, 0, 1.68, 0.25, root);
for (const x of [-0.18, 0.18]) {
block(0.21, 0.20, 0.55, M.pants, x, 0.55, 0.28, root);
block(0.20, 0.44, 0.20, M.pants, x, 0.31, 0.52, root);
block(0.23, 0.14, 0.35, M.dark, x, 0.09, 0.58, root);
}
for (const x of [-0.4, 0.4]) {
const arm = new THREE.Group();
arm.position.set(x, 1.34, 0.04);
arm.rotation.x = -0.95;
root.add(arm);
block(0.16, 0.54, 0.18, M.shirtGold, 0, -0.27, 0, arm);
block(0.17, 0.16, 0.18, M.skinLight, 0, -0.59, 0, arm);
}
return root;
}
// Paused fountain users, all outside the main route.
const standardUser = makeStanding({
shirt: M.shirtRust,
skin: M.skin
});
standardUser.root.position.set(-5.0, 0.08, -4.32);
standardUser.root.rotation.y = Math.PI;
standardUser.arms[1].rotation.x = -1.0;
scene.add(standardUser.root);
const wheelchair = makeWheelchairUser();
wheelchair.position.set(-2.6, 0.08, -4.14);
wheelchair.rotation.y = Math.PI;
scene.add(wheelchair);
const refillUser = makeStanding({
shirt: M.shirtBlue,
skin: M.skinLight,
hair: M.hair
});
refillUser.root.position.set(4.1, 0.08, -4.5);
refillUser.root.rotation.y = Math.PI;
refillUser.arms[1].rotation.x = -1.12;
scene.add(refillUser.root);
// Seated person in the rest bay.
const seated = makeSeated();
seated.position.set(2.0, 0.08, 5.25);
seated.rotation.y = Math.PI;
scene.add(seated);
// A moving walker demonstrates that the through-route remains usable.
const routeWalker = makeStanding({
shirt: M.shirtGold,
pants: M.pants,
skin: M.skin,
hair: M.hair
});
routeWalker.root.rotation.y = Math.PI / 2;
routeWalker.root.position.set(-18, 0.08, 0.15);
scene.add(routeWalker.root);
// ------------------------------------------------------------
// Voxel trees, shrubs, and grass accents
// ------------------------------------------------------------
function makeTree(x, z, scale = 1, colorIndex = 0) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
block(0.52, 2.55, 0.52, M.trunk, 0, 1.25, 0, tree);
block(0.34, 1.0, 0.34, M.trunk, 0.43, 2.4, 0, tree);
const foliage = M.foliage[colorIndex % M.foliage.length];
const foliage2 = M.foliage[(colorIndex + 1) % M.foliage.length];
block(2.35, 2.05, 2.25, foliage, 0, 3.3, 0, tree);
block(1.65, 1.65, 1.7, foliage2, -1.12, 3.0, 0.1, tree);
block(1.55, 1.7, 1.6, foliage2, 1.05, 3.15, -0.12, tree);
block(1.35, 1.35, 1.45, foliage, 0.18, 4.45, 0.05, tree);
}
const trees = [
[-18.2, -13.4, 1.08, 0],
[-8.4, -14.2, 0.92, 1],
[3.8, -15.3, 1.05, 2],
[18.1, -11.4, 1.02, 1],
[-18.2, 10.7, 1.0, 2],
[-8.7, 14.4, 1.12, 0],
[4.9, 15.2, 0.95, 3],
[18.0, 13.5, 1.08, 2],
[-18.0, 4.0, 0.9, 1],
[18.2, 3.7, 0.93, 0],
[-6.2, 9.4, 0.88, 2],
[8.8, 8.9, 0.86, 1]
];
trees.forEach((tree) => makeTree(...tree));
function makeShrub(x, z, size = 1) {
block(
size,
size * 0.55,
size,
M.foliage[2],
x,
size * 0.27,
z
);
block(
size * 0.62,
size * 0.45,
size * 0.65,
M.foliage[0],
x + size * 0.25,
size * 0.48,
z
);
}
makeShrub(-6.5, -6.8, 0.9);
makeShrub(6.45, -6.9, 0.85);
makeShrub(-3.3, 7.0, 0.8);
makeShrub(5.0, 6.9, 0.75);
makeShrub(-10.1, -5.5, 0.75);
makeShrub(14.7, 6.0, 0.8);
// Small grass blocks add voxel texture without cluttering the paths.
let seed = 713;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 75; i++) {
const x = -20.8 + random() * 41.6;
const z = -17.8 + random() * 35.6;
const onMain = Math.abs(z) < 3.1;
const onNorth = Math.abs(x + 12.5) < 3.1 && z < 0;
const onSouth = Math.abs(x - 12.5) < 3.1 && z > 0;
const onCourt = z < -2.7 && z > -8.2 && Math.abs(x) < 7.2;
const onRest = z > 2.7 && z < 7.8 && x > -3.7 && x < 5.2;
if (!onMain && !onNorth && !onSouth && !onCourt && !onRest) {
const h = 0.12 + random() * 0.2;
block(
0.12,
h,
0.12,
random() > 0.5 ? M.grassDark : M.foliage[0],
x,
h / 2,
z,
scene,
false
);
}
}
// ------------------------------------------------------------
// Camera controls implemented directly in this file
// ------------------------------------------------------------
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
cameraState.desiredTheta -= dx * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi - dy * 0.005,
0.12,
1.35
);
});
function stopDragging(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredZoom = THREE.MathUtils.clamp(
cameraState.desiredZoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.35
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.desiredTheta += 0.12;
break;
case "ArrowRight":
cameraState.desiredTheta -= 0.12;
break;
case "ArrowUp":
cameraState.desiredPhi = Math.max(0.12, cameraState.desiredPhi - 0.08);
break;
case "ArrowDown":
cameraState.desiredPhi = Math.min(1.35, cameraState.desiredPhi + 0.08);
break;
case "+":
case "=":
cameraState.desiredZoom = Math.min(2.35, cameraState.desiredZoom + 0.12);
break;
case "-":
case "_":
cameraState.desiredZoom = Math.max(0.65, cameraState.desiredZoom - 0.12);
break;
case "Home":
resetView();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
function updateCamera(dt) {
const smoothing = 1 - Math.pow(0.0008, dt);
cameraState.theta +=
(cameraState.desiredTheta - cameraState.theta) * smoothing;
cameraState.phi +=
(cameraState.desiredPhi - cameraState.phi) * smoothing;
cameraState.zoom +=
(cameraState.desiredZoom - cameraState.zoom) * smoothing;
const radius = 44;
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x + radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + radius * cosPhi,
cameraState.target.z + radius * sinPhi * Math.cos(cameraState.theta)
);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.lookAt(cameraState.target);
}
function resetView() {
cameraState.desiredTheta = 0.72;
cameraState.desiredPhi = 0.98;
cameraState.desiredZoom = 1;
status.textContent = "Isometric view selected.";
}
document.querySelector("#reset").addEventListener("click", resetView);
document.querySelector("#plan").addEventListener("click", () => {
cameraState.desiredTheta = 0;
cameraState.desiredPhi = 0.12;
cameraState.desiredZoom = 0.96;
status.textContent = "Plan view selected. The through-route is clearly visible.";
});
document.querySelector("#zoomIn").addEventListener("click", () => {
cameraState.desiredZoom = Math.min(2.35, cameraState.desiredZoom + 0.15);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
cameraState.desiredZoom = Math.max(0.65, cameraState.desiredZoom - 0.15);
});
const routeButton = document.querySelector("#route");
routeButton.addEventListener("click", () => {
const visible = !routeGuides.visible;
routeGuides.visible = visible;
routeButton.setAttribute("aria-pressed", String(visible));
status.textContent = visible
? "Tactile route-edge guides shown."
: "Tactile route-edge guides hidden.";
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
// Maintain the complete diorama in narrow portrait windows.
const frustumHeight = Math.max(29, 58 / aspect);
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const t = clock.elapsedTime;
updateCamera(dt);
// A slow walker crosses, rather than pauses in, the through-route.
const routeProgress = (t * 0.027) % 1;
routeWalker.root.position.x = -20 + routeProgress * 40;
const stride = Math.sin(t * 6.2) * 0.52;
routeWalker.legs[0].rotation.x = stride;
routeWalker.legs[1].rotation.x = -stride;
routeWalker.arms[0].rotation.x = -stride * 0.72;
routeWalker.arms[1].rotation.x = stride * 0.72;
// Gentle water animation.
waterStreams.forEach((stream, index) => {
stream.scale.y = 0.24 + Math.sin(t * 9 + index) * 0.025;
stream.position.y = (index === 0 ? 0.89 : 0.87) +
Math.sin(t * 9 + index) * 0.008;
});
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.remove();
}
}
animate();
</script>
</body>
</html>
```