Prompt specification
Build or customize the Three.js 3D scene "Neighborhood play garden" 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: Neighborhood play garden
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-play-garden-x0443
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring inclusive playground access. Compose ground-level games, ramped platforms, quiet seating, and planting; visitors with different movement styles participate in shared activities connected by continuous paths. Stylized solid forms.
Working Three.js Starter (neighborhood-play-garden-x0443):
```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="#173f3b">
<title>Together at Play — Inclusive Playground</title>
<style>
:root {
--ink: #173f3b;
--muted: #55716c;
--paper: rgba(255, 252, 243, 0.9);
--coral: #ec7869;
--teal: #269d98;
--gold: #efc45e;
--blue: #79b5cf;
--lavender: #a990c4;
--shadow: 0 16px 45px rgba(31, 69, 62, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #dceef0;
font-family:
Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible,
canvas:focus-visible {
outline: 3px solid #247fba;
outline-offset: 3px;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas.dragging {
cursor: grabbing;
}
#interface {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.72);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.intro {
position: absolute;
top: max(22px, env(safe-area-inset-top));
left: max(22px, env(safe-area-inset-left));
width: min(405px, calc(100vw - 44px));
padding: 23px 25px 21px;
border-radius: 25px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--teal);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 5px rgba(236, 120, 105, 0.14);
content: "";
}
h1 {
margin: 0;
font-size: clamp(2rem, 4vw, 3.1rem);
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro p {
max-width: 34rem;
margin: 13px 0 17px;
color: var(--muted);
font-size: 0.94rem;
line-height: 1.52;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.badge {
padding: 7px 10px;
border-radius: 999px;
background: rgba(38, 157, 152, 0.1);
color: #286f6c;
font-size: 0.72rem;
font-weight: 750;
}
.directory {
position: absolute;
top: max(22px, env(safe-area-inset-top));
right: max(22px, env(safe-area-inset-right));
width: 282px;
padding: 18px;
border-radius: 22px;
}
.directory h2 {
margin: 0 0 12px;
font-size: 0.8rem;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.activity-list {
display: grid;
gap: 6px;
margin-bottom: 13px;
}
.activity {
display: flex;
align-items: center;
gap: 10px;
width: 100%;
padding: 8px;
border: 0;
border-radius: 13px;
color: var(--ink);
background: transparent;
text-align: left;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
.activity:hover,
.activity.active {
background: rgba(23, 63, 59, 0.07);
}
.activity:hover {
transform: translateX(2px);
}
.activity .swatch {
flex: 0 0 auto;
width: 12px;
height: 34px;
border-radius: 999px;
}
.activity b,
.activity small {
display: block;
}
.activity b {
font-size: 0.86rem;
}
.activity small {
margin-top: 2px;
color: var(--muted);
font-size: 0.68rem;
}
.swatch.coral { background: var(--coral); }
.swatch.teal { background: var(--teal); }
.swatch.gold { background: var(--gold); }
.swatch.blue { background: var(--blue); }
.swatch.lavender { background: var(--lavender); }
.toggle-row {
display: grid;
gap: 7px;
padding-top: 12px;
border-top: 1px solid rgba(23, 63, 59, 0.1);
}
.toggle-button {
display: flex;
align-items: center;
gap: 9px;
width: 100%;
padding: 10px 11px;
border: 1px solid rgba(23, 63, 59, 0.12);
border-radius: 13px;
color: var(--ink);
background: rgba(255, 255, 255, 0.48);
font-size: 0.76rem;
font-weight: 750;
cursor: pointer;
}
.toggle-button.active {
color: white;
border-color: var(--teal);
background: var(--teal);
}
.toggle-icon {
display: grid;
width: 23px;
height: 23px;
place-items: center;
border-radius: 8px;
background: rgba(23, 63, 59, 0.08);
}
.active .toggle-icon {
background: rgba(255, 255, 255, 0.18);
}
.toolbar {
position: absolute;
bottom: max(22px, env(safe-area-inset-bottom));
left: 50%;
display: flex;
gap: 6px;
max-width: calc(100vw - 44px);
padding: 7px;
overflow-x: auto;
border-radius: 18px;
transform: translateX(-50%);
scrollbar-width: none;
}
.toolbar::-webkit-scrollbar {
display: none;
}
.toolbar button {
flex: 0 0 auto;
padding: 10px 14px;
border: 0;
border-radius: 12px;
color: var(--ink);
background: transparent;
font-size: 0.78rem;
font-weight: 750;
white-space: nowrap;
cursor: pointer;
}
.toolbar button:hover {
background: rgba(23, 63, 59, 0.07);
}
.toolbar button.active {
color: white;
background: var(--ink);
}
.hint {
position: absolute;
bottom: max(28px, env(safe-area-inset-bottom));
left: max(24px, env(safe-area-inset-left));
padding: 9px 12px;
border-radius: 12px;
color: rgba(23, 63, 59, 0.72);
background: rgba(255, 252, 243, 0.68);
font-size: 0.7rem;
font-weight: 650;
backdrop-filter: blur(9px);
}
#hotspots {
position: absolute;
inset: 0;
pointer-events: none;
}
.hotspot {
position: absolute;
pointer-events: auto;
padding: 5px 10px 5px 5px;
border: 1px solid rgba(255, 255, 255, 0.86);
border-radius: 999px;
color: var(--ink);
background: rgba(255, 252, 243, 0.92);
box-shadow: 0 8px 25px rgba(23, 63, 59, 0.16);
white-space: nowrap;
transform: translate(-50%, -100%);
cursor: pointer;
backdrop-filter: blur(10px);
}
.hotspot .pin {
display: inline-grid;
width: 24px;
height: 24px;
margin-right: 5px;
place-items: center;
border-radius: 50%;
color: white;
background: var(--coral);
font-size: 0.7rem;
font-weight: 850;
}
.hotspot .label {
font-size: 0.72rem;
font-weight: 800;
}
.hotspot .detail {
position: absolute;
bottom: calc(100% + 9px);
left: 50%;
display: none;
width: max-content;
max-width: 220px;
padding: 8px 10px;
border-radius: 10px;
color: white;
background: var(--ink);
font-size: 0.68rem;
font-weight: 600;
transform: translateX(-50%);
}
.hotspot:hover .detail,
.hotspot:focus-visible .detail {
display: block;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--ink);
background: #dceef0;
font-weight: 800;
letter-spacing: 0.05em;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 860px) {
.intro {
width: min(365px, calc(100vw - 44px));
}
.directory {
top: auto;
right: max(14px, env(safe-area-inset-right));
bottom: 82px;
width: 205px;
padding: 12px;
}
.directory h2,
.activity-list {
display: none;
}
.toggle-row {
padding-top: 0;
border-top: 0;
}
.hint {
display: none;
}
.toolbar {
left: max(12px, env(safe-area-inset-left));
right: max(12px, env(safe-area-inset-right));
max-width: none;
transform: none;
}
}
@media (max-width: 560px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 17px 18px;
border-radius: 20px;
}
.intro p {
display: none;
}
.intro h1 {
font-size: 2rem;
}
.badges {
margin-top: 12px;
}
.badge {
padding: 5px 8px;
font-size: 0.64rem;
}
.directory {
right: 12px;
bottom: 76px;
}
.hotspot .detail {
display: none !important;
}
.hotspot .label {
font-size: 0.65rem;
}
.toolbar button {
padding: 9px 11px;
font-size: 0.7rem;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="loading">Building the playground…</div>
<div id="interface">
<header class="panel intro">
<div class="eyebrow">Inclusive playground</div>
<h1>Together<br>at Play</h1>
<p>
A shared landscape of ground-level games, gently sloped platforms,
sensory planting, and quiet places to pause.
</p>
<div class="badges">
<span class="badge">Continuous step-free paths</span>
<span class="badge">Ways to move</span>
<span class="badge">Shared play</span>
</div>
</header>
<aside class="panel directory" aria-label="Playground directory">
<h2>Find your way</h2>
<div class="activity-list">
<button class="activity" data-view="share">
<span class="swatch coral"></span>
<span><b>Share circle</b><small>Low table and open seating</small></span>
</button>
<button class="activity" data-view="make">
<span class="swatch teal"></span>
<span><b>Make together</b><small>Reachable collaborative games</small></span>
</button>
<button class="activity" data-view="reach">
<span class="swatch gold"></span>
<span><b>Reach together</b><small>Ramped activity platform</small></span>
</button>
<button class="activity" data-view="roll">
<span class="swatch blue"></span>
<span><b>Roll & flow</b><small>Rolling and balance play</small></span>
</button>
<button class="activity" data-view="quiet">
<span class="swatch lavender"></span>
<span><b>Quiet grove</b><small>Shade, seating, and sensory breaks</small></span>
</button>
</div>
<div class="toggle-row">
<button id="route-toggle" class="toggle-button" aria-pressed="false">
<span class="toggle-icon">↝</span>
Highlight step-free route
</button>
<button id="motion-toggle" class="toggle-button" aria-pressed="false">
<span class="toggle-icon">Ⅱ</span>
<span id="motion-label">Pause ambient motion</span>
</button>
</div>
</aside>
<div id="hotspots"></div>
<div id="scene-help" class="hint">
Drag to orbit · Scroll to zoom · Keys 1–6 for views
</div>
<nav class="panel toolbar" aria-label="Camera views">
<button data-view="overview" class="active">Overview</button>
<button data-view="share">Share</button>
<button data-view="make">Make</button>
<button data-view="reach">Reach</button>
<button data-view="roll">Roll</button>
<button data-view="quiet">Quiet</button>
</nav>
<div id="status" class="sr-only" aria-live="polite"></div>
</div>
<noscript>This playground requires JavaScript to render.</noscript>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const viewport = document.getElementById("viewport");
const status = document.getElementById("status");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.id = "scene-canvas";
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional inclusive playground"
);
renderer.domElement.setAttribute("aria-describedby", "scene-help");
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dceef0");
scene.fog = new THREE.Fog("#dceef0", 34, 68);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight("#eaf8ff", "#79976d", 2.35);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff1d1", 3.2);
sun.position.set(-9, 16, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.0007;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9ddf0", 0.85);
fill.position.set(10, 8, -12);
scene.add(fill);
const palette = {
ink: "#173f3b",
coral: "#ec7869",
teal: "#269d98",
gold: "#efc45e",
blue: "#79b5cf",
lavender: "#a990c4",
green: "#8fb37b",
deepGreen: "#557b59",
grass: "#a9ca98",
sand: "#f2dfc1",
cream: "#fff8e8",
soil: "#765844",
bark: "#8b6246"
};
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0
})
);
}
return materialCache.get(color);
}
function addMesh(geometry, color, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(geometry, material(color));
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, color, x = 0, y = 0, z = 0, parent = scene) {
return addMesh(
new THREE.BoxGeometry(w, h, d),
color,
x,
y,
z,
parent
);
}
function cylinder(
rt,
rb,
h,
color,
x = 0,
y = 0,
z = 0,
parent = scene,
segments = 24
) {
return addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
color,
x,
y,
z,
parent
);
}
function ball(r, color, x = 0, y = 0, z = 0, parent = scene) {
return addMesh(
new THREE.SphereGeometry(r, 16, 12),
color,
x,
y,
z,
parent
);
}
function torus(
radius,
tube,
color,
x = 0,
y = 0,
z = 0,
parent = scene,
arc = Math.PI * 2
) {
return addMesh(
new THREE.TorusGeometry(radius, tube, 8, 32, arc),
color,
x,
y,
z,
parent
);
}
function cylinderBetween(
a,
b,
radius,
color,
parent = scene,
segments = 10
) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const delta = end.clone().sub(start);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = cylinder(
radius,
radius,
delta.length(),
color,
midpoint.x,
midpoint.y,
midpoint.z,
parent,
segments
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
delta.normalize()
);
return mesh;
}
function roundedShape(w, d, r) {
const s = new THREE.Shape();
s.moveTo(-w / 2 + r, -d / 2);
s.lineTo(w / 2 - r, -d / 2);
s.quadraticCurveTo(w / 2, -d / 2, w / 2, -d / 2 + r);
s.lineTo(w / 2, d / 2 - r);
s.quadraticCurveTo(w / 2, d / 2, w / 2 - r, d / 2);
s.lineTo(-w / 2 + r, d / 2);
s.quadraticCurveTo(-w / 2, d / 2, -w / 2, d / 2 - r);
s.lineTo(-w / 2, -d / 2 + r);
s.quadraticCurveTo(-w / 2, -d / 2, -w / 2 + r, -d / 2);
return s;
}
function roundedPad(w, d, r, color, x, z, y = 0.035) {
const geometry = new THREE.ShapeGeometry(roundedShape(w, d, r), 12);
geometry.rotateX(-Math.PI / 2);
const mesh = addMesh(geometry, color, x, y, z);
mesh.castShadow = false;
return mesh;
}
// ------------------------------------------------------------
// Landscape and continuous paths
// ------------------------------------------------------------
const landscape = new THREE.Mesh(
new THREE.CircleGeometry(60, 64),
material("#c7dfc1")
);
landscape.rotation.x = -Math.PI / 2;
landscape.position.y = -0.72;
landscape.receiveShadow = true;
scene.add(landscape);
cylinder(17, 17, 0.7, palette.grass, 0, -0.35, 0, scene, 64);
// The loop is built from touching path sections so there are no
// disconnected areas between play zones.
roundedPad(18, 2.2, 0.28, palette.sand, 0, -7.2);
roundedPad(18, 2.2, 0.28, palette.sand, 0, 5.5);
roundedPad(2.2, 10.5, 0.28, palette.sand, -8, -0.85);
roundedPad(2.2, 10.5, 0.28, palette.sand, 8, -0.85);
roundedPad(13.8, 2.2, 0.28, palette.sand, 0, 1.2);
// Colored activity ground surfaces.
roundedPad(5.2, 3.35, 0.55, "#efd1b5", -4.8, -1.2, 0.045);
roundedPad(4.5, 3.0, 0.5, "#d4e9ba", -5.25, 5.2, 0.045);
roundedPad(4.8, 3.5, 0.55, "#ded3e8", 5.15, 5.25, 0.045);
const centralDisc = cylinder(
3.15,
3.15,
0.12,
"#fff4dd",
0,
0.06,
0,
scene,
64
);
centralDisc.castShadow = false;
const centralRing = torus(
2.65,
0.045,
palette.coral,
0,
0.14,
0
);
centralRing.rotation.x = Math.PI / 2;
// ------------------------------------------------------------
// Highlighted accessible route
// ------------------------------------------------------------
const routeGroup = new THREE.Group();
routeGroup.visible = false;
scene.add(routeGroup);
const routeMaterial = new THREE.MeshBasicMaterial({
color: "#00a7c4",
transparent: true,
opacity: 0.9,
depthWrite: false
});
function routeTube(points, closed = false, radius = 0.055) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
closed,
"catmullrom",
0.18
);
const geometry = new THREE.TubeGeometry(
curve,
closed ? 160 : 70,
radius,
7,
closed
);
const mesh = new THREE.Mesh(geometry, routeMaterial);
mesh.renderOrder = 4;
routeGroup.add(mesh);
}
routeTube([
[-8, 0.11, 5.5],
[-8, 0.11, -7.2],
[0, 0.11, -7.2],
[8, 0.11, -7.2],
[8, 0.11, 5.5],
[0, 0.11, 5.5]
], true);
routeTube([
[0, 0.12, -5.4],
[-0.2, 0.12, -5.4],
[-2.5, 0.67, -5.4],
[-6.1, 0.67, -5.4]
]);
routeTube([
[0, 0.12, -5.4],
[0.6, 0.12, -5.4],
[3.9, 0.67, -5.4],
[6.2, 0.67, -5.4]
]);
// ------------------------------------------------------------
// Shared circle: a reachable table with tactile play pieces
// ------------------------------------------------------------
cylinder(0.43, 0.48, 0.65, palette.teal, 0, 0.45, 0);
cylinder(1.06, 1.06, 0.16, palette.cream, 0, 0.82, 0, scene, 48);
box(0.48, 0.12, 0.4, palette.coral, -0.28, 0.96, 0.1);
cylinder(0.2, 0.2, 0.12, palette.gold, 0.4, 0.96, -0.1);
box(0.3, 0.12, 0.55, palette.lavender, 0.03, 0.96, 0.42);
ball(0.15, palette.blue, -0.53, 0.97, -0.39);
// Low circular seats around the shared table.
[
[-1.95, 0.05, 0.25, palette.coral],
[1.75, 0.15, -0.05, palette.blue],
[-0.35, -1.95, 0.1, palette.gold]
].forEach(([x, z, r, color]) => {
cylinder(r, r, 0.42, color, x, 0.27, z);
cylinder(r * 0.82, r * 0.82, 0.08, palette.cream, x, 0.52, z);
});
// ------------------------------------------------------------
// Make Together: low collaborative work table and activity wall
// ------------------------------------------------------------
const makeGroup = new THREE.Group();
makeGroup.position.set(-4.8, 0, -1.2);
scene.add(makeGroup);
box(3.15, 0.16, 1.35, "#fff4dc", 0, 0.79, 0, makeGroup);
[-1.25, 1.25].forEach((x) => {
[-0.43, 0.43].forEach((z) => {
box(0.12, 0.72, 0.12, palette.teal, x, 0.38, z, makeGroup);
});
});
// A deliberately open center provides wheelchair knee clearance.
cylinder(0.18, 0.18, 0.16, palette.coral, -0.78, 0.96, 0.18, makeGroup);
box(0.42, 0.13, 0.36, palette.gold, 0.1, 0.96, -0.25, makeGroup);
cylinder(0.16, 0.16, 0.14, palette.blue, 0.83, 0.95, 0.12, makeGroup);
// Reachable activity wall.
box(3.05, 1.45, 0.12, "#fff4dc", 0, 1.23, -1.25, makeGroup);
[-1.35, 1.35].forEach((x) => {
cylinder(0.07, 0.07, 1.9, palette.teal, x, 0.95, -1.29, makeGroup);
});
[
[-1.05, 1.38, palette.coral],
[-0.4, 0.98, palette.gold],
[0.35, 1.43, palette.teal],
[1.05, 0.92, palette.lavender]
].forEach(([x, y, color]) => {
cylinder(0.14, 0.14, 0.12, color, x, y, -1.12, makeGroup);
});
// ------------------------------------------------------------
// Raised platforms and ramps
// ------------------------------------------------------------
function makeRamp(xLow, xHigh, width, z, yLow, yHigh, color) {
const bottom = 0.07;
const positions = new Float32Array([
xLow, yLow, z - width / 2,
xHigh, yHigh, z - width / 2,
xHigh, yHigh, z + width / 2,
xLow, yLow, z + width / 2,
xLow, bottom, z - width / 2,
xHigh, bottom, z - width / 2,
xHigh, bottom, z + width / 2,
xLow, bottom, z + width / 2
]);
const indices = [
0, 2, 1, 0, 3, 2,
4, 5, 6, 4, 6, 7,
0, 1, 4, 1, 5, 4,
1, 2, 5, 2, 6, 5,
2, 3, 6, 3, 7, 6,
3, 0, 7, 0, 4, 7
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const rampMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.87,
side: THREE.DoubleSide
});
const ramp = new THREE.Mesh(geometry, rampMaterial);
ramp.castShadow = true;
ramp.receiveShadow = true;
scene.add(ramp);
// Low contrast edge strips make the ramp boundary easy to see.
cylinderBetween(
[xLow, yLow + 0.035, z - width / 2 + 0.07],
[xHigh, yHigh + 0.035, z - width / 2 + 0.07],
0.035,
"#fff5df"
);
cylinderBetween(
[xLow, yLow + 0.035, z + width / 2 - 0.07],
[xHigh, yHigh + 0.035, z + width / 2 - 0.07],
0.035,
"#fff5df"
);
return ramp;
}
// Reach Together deck.
box(4.5, 0.58, 3.2, "#e5b962", -4.75, 0.29, -5.4);
box(4.55, 0.08, 3.25, palette.gold, -4.75, 0.62, -5.4);
makeRamp(-0.2, -2.5, 1.9, -5.4, 0.08, 0.66, "#e5b962");
// Back safety rail with open visual rhythm.
cylinderBetween([-7, 1.35, -6.92], [-2.55, 1.35, -6.92], 0.055, palette.ink);
[-6.8, -5.4, -4.0, -2.75].forEach((x) => {
cylinder(0.055, 0.055, 0.78, palette.ink, x, 0.96, -6.92);
});
// Tactile play panels on the platform.
box(1.3, 0.85, 0.13, palette.coral, -5.9, 1.08, -6.72);
box(1.15, 0.72, 0.13, palette.teal, -4.45, 1.0, -6.72);
box(0.9, 1.0, 0.13, palette.lavender, -3.2, 1.13, -6.72);
// Roll & Flow deck.
box(3.2, 0.58, 3.2, "#78afc6", 5.5, 0.29, -5.4);
box(3.25, 0.08, 3.25, palette.blue, 5.5, 0.62, -5.4);
makeRamp(0.6, 3.9, 1.85, -5.4, 0.08, 0.66, "#78afc6");
// A broad arch and rollers encourage movement across the deck.
const arch = torus(
1.03,
0.13,
palette.coral,
5.45,
0.73,
-5.35,
scene,
Math.PI
);
arch.rotation.y = Math.PI / 2;
cylinder(0.16, 0.16, 2.0, palette.gold, 6.45, 0.82, -5.4).rotation.x =
Math.PI / 2;
cylinder(0.13, 0.13, 1.7, palette.lavender, 4.65, 0.79, -4.75).rotation.x =
Math.PI / 2;
// ------------------------------------------------------------
// Quiet grove: shade structure and benches
// ------------------------------------------------------------
const quietX = 5.15;
const quietZ = 5.25;
[-2.05, 2.05].forEach((dx) => {
[-1.4, 1.4].forEach((dz) => {
cylinder(
0.075,
0.09,
2.5,
"#70594b",
quietX + dx,
1.25,
quietZ + dz
);
});
});
box(4.55, 0.16, 3.35, palette.lavender, quietX, 2.56, quietZ);
for (let i = -1.5; i <= 1.5; i += 0.5) {
box(0.14, 0.13, 3.42, "#c9b5da", quietX + i, 2.68, quietZ);
}
function makeBench(x, z, rotation = 0, color = palette.teal) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
[-0.19, 0, 0.19].forEach((offset) => {
box(2.15, 0.08, 0.15, color, 0, 0.57, offset, group);
});
box(2.15, 0.14, 0.08, color, 0, 0.86, -0.26, group);
box(2.15, 0.14, 0.08, color, 0, 1.08, -0.26, group);
[-0.82, 0.82].forEach((legX) => {
box(0.1, 0.54, 0.5, "#70594b", legX, 0.27, 0, group);
});
return group;
}
makeBench(4.05, 4.85, 0, palette.teal);
makeBench(6.25, 4.85, Math.PI, palette.blue);
// ------------------------------------------------------------
// Planting and sensory garden
// ------------------------------------------------------------
function makePlanter(x, z, w = 2.7, d = 1.05) {
box(w, 0.46, d, "#d8a277", x, 0.25, z);
box(w - 0.16, 0.08, d - 0.16, palette.soil, x, 0.52, z);
}
function makePlant(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.5, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.035, 0.05, 0.62, palette.deepGreen, 0, 0.31, 0, group, 8);
const leaf = addMesh(
new THREE.DodecahedronGeometry(0.34, 0),
palette.deepGreen,
0,
0.67,
0,
group
);
leaf.scale.set(1, 1.3, 0.75);
const leaf2 = addMesh(
new THREE.DodecahedronGeometry(0.24, 0),
"#74a76b",
0.2,
0.47,
0.05,
group
);
leaf2.scale.set(0.8, 1.2, 0.7);
return group;
}
makePlanter(-5.2, 5.15, 3.35, 1.15);
makePlant(-6.15, 5.15, 1.05);
makePlant(-5.35, 5.15, 0.9);
makePlant(-4.55, 5.15, 1.1);
makePlanter(-6.5, 4.0, 1.65, 0.8);
makePlant(-6.8, 4.0, 0.75);
makePlant(-6.25, 4.0, 0.9);
// Quiet grove planters.
makePlanter(3.05, 6.35, 1.7, 0.72);
makePlant(2.7, 6.35, 0.78);
makePlant(3.35, 6.35, 0.9);
makePlanter(7.25, 6.35, 1.7, 0.72);
makePlant(6.9, 6.35, 0.9);
makePlant(7.55, 6.35, 0.78);
// Perimeter trees.
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.17, 0.24, 2.4, palette.bark, 0, 1.2, 0, group, 10);
const crown = addMesh(
new THREE.DodecahedronGeometry(1.12, 1),
"#6f9b68",
0,
3.05,
0,
group
);
crown.scale.set(1.05, 1.12, 1);
const crown2 = addMesh(
new THREE.DodecahedronGeometry(0.82, 1),
"#84ad71",
0.56,
2.7,
0.2,
group
);
crown2.scale.set(1, 0.9, 1);
}
[
[-12.5, -6.5, 1.1],
[-12.8, 1.8, 0.95],
[-9.4, 10.8, 1.15],
[-2.5, 12.8, 0.92],
[4.8, 12.5, 1.08],
[10.6, 10.5, 1.0],
[13.2, 3.3, 1.12],
[12.6, -6.9, 0.95],
[4.1, -12.6, 1.0],
[-4.7, -12.8, 1.12]
].forEach(([x, z, s]) => makeTree(x, z, s));
// Low shrubs around the park edge.
[
[-10.8, 8.2], [-8.4, 9.3], [8.9, 9.2],
[10.8, 6.2], [10.8, -2.5], [-11.1, -2.6]
].forEach(([x, z], index) => {
const shrub = addMesh(
new THREE.DodecahedronGeometry(0.65 + (index % 2) * 0.12, 1),
index % 2 ? "#78a66f" : "#8db37b",
x,
0.52,
z
);
shrub.scale.y = 0.8;
});
// ------------------------------------------------------------
// Visitors
// ------------------------------------------------------------
function addFace(group, y, xOffset = 0) {
ball(0.022, palette.ink, xOffset - 0.052, y, 0.145, group);
ball(0.022, palette.ink, xOffset + 0.052, y, 0.145, group);
}
function makeStanding({
x,
z,
rotation = 0,
shirt = palette.coral,
pants = palette.ink,
skin = "#b97855",
hair = "#49352e",
child = false,
cane = false,
reaching = false
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
if (child) group.scale.setScalar(0.73);
scene.add(group);
[-0.12, 0.12].forEach((legX) => {
cylinderBetween(
[legX, 0.16, 0],
[legX, 0.7, 0],
0.075,
pants,
group,
8
);
box(0.18, 0.11, 0.3, "#344d4b", legX, 0.08, 0.07, group);
});
cylinder(0.21, 0.17, 0.48, shirt, 0, 0.98, 0, group, 12);
ball(0.22, shirt, 0, 1.16, 0, group);
cylinder(0.07, 0.07, 0.12, skin, 0, 1.3, 0, group, 8);
ball(0.165, skin, 0, 1.49, 0, group);
addFace(group, 1.51);
const hairCap = addMesh(
new THREE.DodecahedronGeometry(0.17, 1),
hair,
0,
1.585,
-0.008,
group
);
hairCap.scale.set(1, 0.62, 1);
[-0.22, 0.22].forEach((shoulderX) => {
const handZ = reaching ? 0.34 : 0.08;
const handX = reaching ? shoulderX * 0.72 : shoulderX * 1.35;
cylinderBetween(
[shoulderX, 1.17, 0],
[handX, 0.74, handZ],
0.06,
shirt,
group,
8
);
ball(0.075, skin, handX, 0.74, handZ, group);
});
if (cane) {
cylinderBetween(
[0.35, 0.04, 0.2],
[0.35, 0.92, 0.2],
0.025,
"#70594b",
group,
8
);
cylinderBetween(
[0.35, 0.92, 0.2],
[0.35, 0.92, 0.38],
0.028,
"#70594b",
group,
8
);
}
return group;
}
function makeWheelchair({
x,
z,
rotation = 0,
shirt = palette.teal,
skin = "#7f4d37",
hair = "#2e2927"
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
// Large rear wheels and front casters.
[-0.43, 0.43].forEach((wheelX) => {
torus(0.36, 0.045, "#344d4b", wheelX, 0.4, -0.12, group);
const hub = cylinder(
0.055,
0.055,
0.09,
"#9eb1ad",
wheelX,
0.4,
-0.12,
group,
12
);
hub.rotation.x = Math.PI / 2;
for (let i = 0; i < 4; i++) {
const angle = (i / 4) * Math.PI;
cylinderBetween(
[wheelX, 0.4, -0.12],
[
wheelX + Math.cos(angle) * 0.31,
0.4 + Math.sin(angle) * 0.31,
-0.12
],
0.012,
"#a9b9b6",
group,
6
);
}
});
[-0.28, 0.28].forEach((casterX) => {
ball(0.105, "#344d4b", casterX, 0.13, 0.43, group);
});
box(0.65, 0.12, 0.62, "#526c69", 0, 0.57, 0.02, group);
box(0.65, 0.52, 0.09, "#526c69", 0, 0.88, -0.27, group);
box(0.44, 0.05, 0.27, "#526c69", 0, 0.18, 0.48, group);
cylinderBetween(
[-0.27, 0.66, -0.2],
[-0.27, 0.98, -0.2],
0.025,
"#a9b9b6",
group,
8
);
cylinderBetween(
[0.27, 0.66, -0.2],
[0.27, 0.98, -0.2],
0.025,
"#a9b9b6",
group,
8
);
// Seated visitor.
cylinder(0.19, 0.16, 0.44, shirt, 0, 0.94, 0.01, group, 12);
ball(0.22, shirt, 0, 1.12, 0.01, group);
cylinder(0.07, 0.07, 0.1, skin, 0, 1.25, 0.01, group, 8);
ball(0.16, skin, 0, 1.43, 0.01, group);
addFace(group, 1.45);
const hairCap = addMesh(
new THREE.DodecahedronGeometry(0.165, 1),
hair,
0,
1.52,
0,
group
);
hairCap.scale.set(1, 0.62, 1);
[-0.12, 0.12].forEach((legX) => {
cylinderBetween(
[legX, 0.62, 0.06],
[legX, 0.55, 0.37],
0.075,
"#405c69",
group,
8
);
cylinderBetween(
[legX, 0.55, 0.37],
[legX, 0.22, 0.43],
0.065,
"#405c69",
group,
8
);
box(0.17, 0.1, 0.27, "#344d4b", legX, 0.16, 0.49, group);
});
[-0.2, 0.2].forEach((shoulderX) => {
cylinderBetween(
[shoulderX, 1.08, 0.02],
[shoulderX * 0.75, 0.78, 0.35],
0.055,
shirt,
group,
8
);
ball(0.07, skin, shoulderX * 0.75, 0.78, 0.35, group);
});
return group;
}
function makeScooter({ x, y = 0, z, rotation = 0 }) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
group.scale.setScalar(0.8);
scene.add(group);
box(0.28, 0.07, 0.72, palette.coral, 0, 0.2, 0.02, group);
const frontWheel = cylinder(
0.12,
0.12,
0.08,
palette.ink,
0,
0.13,
0.38,
group,
16
);
frontWheel.rotation.z = Math.PI / 2;
const rearWheel = cylinder(
0.1,
0.1,
0.08,
palette.ink,
0,
0.12,
-0.28,
group,
16
);
rearWheel.rotation.z = Math.PI / 2;
cylinderBetween(
[0, 0.2, 0.1],
[0, 1.03, 0.34],
0.035,
"#8ea3a0",
group,
8
);
cylinderBetween(
[-0.22, 1.03, 0.34],
[0.22, 1.03, 0.34],
0.035,
palette.ink,
group,
8
);
cylinder(0.17, 0.14, 0.38, palette.gold, 0, 1.0, 0.05, group, 12);
ball(0.2, palette.gold, 0, 1.16, 0.05, group);
cylinder(0.06, 0.06, 0.1, "#9a6247", 0, 1.29, 0.05, group, 8);
ball(0.15, "#9a6247", 0, 1.46, 0.05, group);
addFace(group, 1.48);
[-0.1, 0.1].forEach((legX) => {
cylinderBetween(
[legX, 0.83, 0.03],
[legX, 0.46, 0.2],
0.06,
"#405c69",
group,
8
);
cylinderBetween(
[legX, 0.46, 0.2],
[legX, 0.28, 0.06],
0.055,
"#405c69",
group,
8
);
});
[-0.18, 0.18].forEach((armX) => {
cylinderBetween(
[armX, 1.1, 0.05],
[armX, 0.98, 0.34],
0.05,
palette.gold,
group,
8
);
});
return group;
}
function makeSeated({ x, z, rotation = 0 }) {
const group = new THREE.Group();
group.position.set(x, 0.57, z);
group.rotation.y = rotation;
scene.add(group);
cylinder(0.18, 0.15, 0.42, palette.coral, 0, 0.52, 0, group, 12);
ball(0.21, palette.coral, 0, 0.7, 0, group);
cylinder(0.065, 0.065, 0.1, "#d39b75", 0, 0.84, 0, group, 8);
ball(0.155, "#d39b75", 0, 1.0, 0, group);
addFace(group, 1.02);
const hair = addMesh(
new THREE.DodecahedronGeometry(0.16, 1),
"#6a4634",
0,
1.08,
-0.01,
group
);
hair.scale.set(1, 0.6, 1);
[-0.11, 0.11].forEach((legX) => {
cylinderBetween(
[legX, 0.15, 0.02],
[legX, 0.1, 0.38],
0.07,
"#405c69",
group,
8
);
cylinderBetween(
[legX, 0.1, 0.38],
[legX, -0.4, 0.44],
0.06,
"#405c69",
group,
8
);
});
[-0.19, 0.19].forEach((armX) => {
cylinderBetween(
[armX, 0.66, 0],
[armX * 0.8, 0.22, 0.18],
0.055,
palette.coral,
group,
8
);
});
return group;
}
// Shared play at the center.
makeStanding({
x: -1.65,
z: 0.6,
rotation: 0.85,
shirt: palette.coral,
skin: "#d79b76",
hair: "#4b352c",
reaching: true
});
makeStanding({
x: 1.35,
z: -1.45,
rotation: -1.65,
shirt: palette.gold,
pants: "#405c69",
skin: "#8b5a40",
hair: "#2f2926",
child: true
});
// A wheelchair user and a cane user collaborate at the low table.
makeWheelchair({
x: -3.18,
z: -1.2,
rotation: -Math.PI / 2,
shirt: palette.teal,
skin: "#6d4636",
hair: "#292524"
});
makeStanding({
x: -6.18,
z: -1.2,
rotation: Math.PI / 2,
shirt: palette.lavender,
skin: "#e0aa84",
hair: "#7b5b46",
cane: true,
reaching: true
});
// Shared movement on the two accessible platforms.
makeWheelchair({
x: -1.2,
y: 0,
z: -5.4,
rotation: -Math.PI / 2,
shirt: palette.coral,
skin: "#b97855",
hair: "#49352e"
}).position.y = 0.3;
makeStanding({
x: -4.15,
z: -5.35,
rotation: Math.PI,
shirt: palette.blue,
skin: "#6d4636",
hair: "#252220",
child: true,
reaching: true
});
makeScooter({
x: 2.25,
y: 0.36,
z: -5.4,
rotation: Math.PI / 2
});
makeStanding({
x: 6.35,
z: -4.65,
rotation: -Math.PI / 2,
shirt: palette.teal,
skin: "#d79b76",
hair: "#664737",
reaching: true
});
// Resting in the quiet grove.
makeSeated({
x: 4.05,
z: 4.83,
rotation: 0
});
// ------------------------------------------------------------
// Decorative flags with restrained ambient movement
// ------------------------------------------------------------
const flags = [];
function makeFlag(x, z, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
cylinder(0.025, 0.035, 2.6, "#9b8067", 0, 1.3, 0, group, 8);
const shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.lineTo(0.72, -0.13);
shape.lineTo(0, -0.36);
shape.closePath();
const flagMesh = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
side: THREE.DoubleSide
})
);
flagMesh.position.set(0.02, 2.45, 0);
flagMesh.castShadow = true;
group.add(flagMesh);
flags.push({ group, phase: flags.length * 1.7 });
}
makeFlag(-1.95, -6.75, palette.coral);
makeFlag(7.45, -6.75, palette.blue);
makeFlag(-7.35, 7.0, palette.gold);
// ------------------------------------------------------------
// Soft distant hills and clouds
// ------------------------------------------------------------
[
[-15, -0.7, -18, 5.5, "#b2cda9"],
[0, -1.3, -22, 7.5, "#bdd4b1"],
[15, -0.8, -17, 6.0, "#a9c6a5"],
[-20, -1.1, 5, 7.0, "#b8d1ad"]
].forEach(([x, y, z, s, color]) => {
const hill = addMesh(
new THREE.DodecahedronGeometry(s, 1),
color,
x,
y,
z
);
hill.scale.set(1.5, 0.45, 1);
hill.castShadow = false;
});
const clouds = [];
function makeCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
[
[-0.75, 0, 0, 0.72],
[-0.2, 0.2, 0, 0.9],
[0.45, 0.05, 0, 0.72],
[0.95, -0.02, 0, 0.48]
].forEach(([cx, cy, cz, r]) => {
const puff = ball(r, "#f7fbf7", cx, cy, cz, group);
puff.castShadow = false;
puff.receiveShadow = false;
});
clouds.push({ group, baseX: x, phase: x * 0.2 });
}
makeCloud(-9, 8.5, -15, 1.2);
makeCloud(5, 9.8, -18, 0.95);
makeCloud(13, 7.5, -9, 0.8);
// ------------------------------------------------------------
// Projected HTML labels
// ------------------------------------------------------------
const hotspotDefinitions = [
{
id: "share",
number: 1,
label: "Share circle",
detail: "Low collaborative table with open ground-level play",
position: new THREE.Vector3(0, 1.75, 0)
},
{
id: "make",
number: 2,
label: "Make together",
detail: "Reachable tools, colorful panels, and open knee space",
position: new THREE.Vector3(-4.8, 1.9, -1.2)
},
{
id: "reach",
number: 3,
label: "Reach together",
detail: "A gently sloped platform with shared sensory panels",
position: new THREE.Vector3(-4.9, 1.85, -5.4)
},
{
id: "roll",
number: 4,
label: "Roll & flow",
detail: "Rolling, balance, and arch play on a ramped deck",
position: new THREE.Vector3(5.45, 1.95, -5.4)
},
{
id: "quiet",
number: 5,
label: "Quiet grove",
detail: "Shade, comfortable seating, planting, and a place to pause",
position: new THREE.Vector3(5.15, 3.25, 5.25)
}
];
const hotspotElements = [];
hotspotDefinitions.forEach((definition) => {
const button = document.createElement("button");
button.className = "hotspot";
button.dataset.view = definition.id;
button.setAttribute(
"aria-label",
`Focus on ${definition.label}: ${definition.detail}`
);
button.innerHTML = `
<span class="pin">${definition.number}</span>
<span class="label">${definition.label}</span>
<span class="detail">${definition.detail}</span>
`;
button.addEventListener("click", () => setView(definition.id));
document.getElementById("hotspots").appendChild(button);
hotspotElements.push({ element: button, position: definition.position });
});
function updateHotspots() {
const width = window.innerWidth;
const height = window.innerHeight;
hotspotElements.forEach(({ element, position }) => {
const projected = position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.05 &&
projected.x < 1.05 &&
projected.y > -1.05 &&
projected.y < 1.05;
element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
});
}
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, and focus views
// ------------------------------------------------------------
const views = {
overview: {
target: new THREE.Vector3(0, 0.25, -0.4),
theta: 0.64,
phi: 1.02,
radius: 29
},
share: {
target: new THREE.Vector3(0, 0.7, 0),
theta: 0.48,
phi: 1.03,
radius: 9.2
},
make: {
target: new THREE.Vector3(-4.8, 0.85, -1.25),
theta: 0.28,
phi: 1.02,
radius: 9.5
},
reach: {
target: new THREE.Vector3(-3.9, 0.9, -5.25),
theta: -0.34,
phi: 1.06,
radius: 12.5
},
roll: {
target: new THREE.Vector3(3.8, 0.9, -5.3),
theta: 0.38,
phi: 1.04,
radius: 12.4
},
quiet: {
target: new THREE.Vector3(5.1, 0.85, 5.15),
theta: 0.25,
phi: 1.0,
radius: 11.6
}
};
const initial = views.overview;
const cameraState = {
target: initial.target.clone(),
desiredTarget: initial.target.clone(),
theta: initial.theta,
desiredTheta: initial.theta,
phi: initial.phi,
desiredPhi: initial.phi,
radius: initial.radius,
desiredRadius: initial.radius
};
let activeView = "overview";
const motionQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
let ambientMotion = !motionQuery.matches;
function syncViewButtons() {
document.querySelectorAll(".view-button").forEach((button) => {
button.classList.toggle("active", button.dataset.view === activeView);
});
}
function setView(name, announce = true) {
const view = views[name];
if (!view) return;
cameraState.desiredTarget.copy(view.target);
cameraState.desiredTheta = view.theta;
cameraState.desiredPhi = view.phi;
cameraState.desiredRadius = view.radius;
activeView = name;
syncViewButtons();
if (announce) {
status.textContent = `${name} view selected.`;
}
}
document.querySelectorAll(".view-button").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
// The toolbar and directory use the same data-view mechanism.
document.querySelectorAll(".activity, .toolbar button").forEach((button) => {
button.classList.add("view-button");
button.addEventListener("click", () => setView(button.dataset.view));
});
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.desiredTheta -= dx * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi - dy * 0.005,
0.58,
1.34
);
activeView = "custom";
syncViewButtons();
});
function endDrag(event) {
if (!dragging) return;
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
pointerId !== null &&
renderer.domElement.hasPointerCapture(pointerId)
) {
renderer.domElement.releasePointerCapture(pointerId);
}
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
6.5,
40
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.desiredTheta += 0.1;
break;
case "ArrowRight":
cameraState.desiredTheta -= 0.1;
break;
case "ArrowUp":
cameraState.desiredPhi = Math.max(
0.58,
cameraState.desiredPhi - 0.08
);
break;
case "ArrowDown":
cameraState.desiredPhi = Math.min(
1.34,
cameraState.desiredPhi + 0.08
);
break;
case "+":
case "=":
cameraState.desiredRadius = Math.max(
6.5,
cameraState.desiredRadius - 0.8
);
break;
case "-":
cameraState.desiredRadius = Math.min(
40,
cameraState.desiredRadius + 0.8
);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
activeView = "custom";
syncViewButtons();
}
});
// Global keyboard shortcuts.
window.addEventListener("keydown", (event) => {
if (event.ctrlKey || event.metaKey || event.altKey) return;
if (event.target.matches("input, textarea, select")) return;
const keys = ["overview", "share", "make", "reach", "roll", "quiet"];
const number = Number(event.key);
if (number >= 1 && number <= keys.length) {
setView(keys[number - 1]);
} else if (event.key.toLowerCase() === "r") {
setView("overview");
}
});
// Route and motion controls.
const routeToggle = document.getElementById("route-toggle");
const motionToggle = document.getElementById("motion-toggle");
const motionLabel = document.getElementById("motion-label");
routeToggle.addEventListener("click", () => {
routeGroup.visible = !routeGroup.visible;
routeToggle.classList.toggle("active", routeGroup.visible);
routeToggle.setAttribute("aria-pressed", String(routeGroup.visible));
status.textContent = routeGroup.visible
? "Step-free route highlighted."
: "Route highlight hidden.";
});
function updateMotionControl() {
motionToggle.classList.toggle("active", !ambientMotion);
motionToggle.setAttribute("aria-pressed", String(!ambientMotion));
motionLabel.textContent = ambientMotion
? "Pause ambient motion"
: "Resume ambient motion";
}
motionToggle.addEventListener("click", () => {
ambientMotion = !ambientMotion;
updateMotionControl();
status.textContent = ambientMotion
? "Ambient motion resumed."
: "Ambient motion paused.";
});
motionQuery.addEventListener("change", (event) => {
ambientMotion = !event.matches;
updateMotionControl();
});
updateMotionControl();
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const spherical = new THREE.Spherical();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const damping = motionQuery.matches
? 1
: 1 - Math.exp(-dt * 6.2);
cameraState.target.lerp(cameraState.desiredTarget, damping);
cameraState.theta +=
(cameraState.desiredTheta - cameraState.theta) * damping;
cameraState.phi +=
(cameraState.desiredPhi - cameraState.phi) * damping;
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * damping;
spherical.set(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
if (ambientMotion) {
flags.forEach(({ group, phase }) => {
group.rotation.y = Math.sin(elapsed * 0.65 + phase) * 0.07;
});
clouds.forEach(({ group, baseX, phase }) => {
group.position.x =
baseX + Math.sin(elapsed * 0.08 + phase) * 0.8;
});
}
updateHotspots();
renderer.render(scene, camera);
}
document.getElementById("loading").remove();
animate();
</script>
</body>
</html>
```