Prompt specification
Build or customize the Three.js 3D scene "Arrange activities while preserving a continuous cycle route" 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: Arrange activities while preserving a continuous cycle route
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/arrange-activities-while-preserving-a-continuous-cycle-x2824
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Superkilen's public activity spaces in Copenhagen. Let users add temporary community-event elements in a schematic park section. Highlight conflicts with the through-route and compare access to seating and play areas. Voxel style.
Working Three.js Starter (arrange-activities-while-preserving-a-continuous-cycle-x2824):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Superkilen — Public Life in Motion</title>
<style>
:root {
--ink: #18211d;
--muted: #69726c;
--paper: rgba(248, 245, 237, 0.92);
--paper-solid: #f8f5ed;
--line: rgba(31, 42, 36, 0.14);
--green: #31705a;
--green-light: #dce9df;
--teal: #278b91;
--route: #d7a735;
--coral: #dc564b;
--amber: #e29b43;
--blue: #456a9b;
--shadow: 0 16px 45px rgba(37, 43, 36, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9d4c8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.topbar {
position: absolute;
z-index: 5;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 24px;
padding: 25px 28px;
pointer-events: none;
}
.brand {
max-width: 560px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 6px;
color: #53635a;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 3px;
content: "";
background: var(--coral);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 480px;
margin: 10px 0 0;
color: #5d6861;
font-size: 13px;
line-height: 1.45;
}
.top-meta {
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 999px;
background: rgba(248, 245, 237, 0.72);
color: #526058;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.top-meta span {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(49, 112, 90, 0.12);
}
.panel {
position: absolute;
z-index: 10;
top: 116px;
width: 278px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.15);
}
.panel-left {
left: 22px;
}
.panel-right {
right: 22px;
width: 302px;
}
.panel h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.015em;
}
.panel-intro {
margin: 6px 0 15px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.section-rule {
height: 1px;
margin: 15px 0;
background: var(--line);
}
.section-label {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 9px;
color: #68736b;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-label span:last-child {
color: #929a95;
font-weight: 650;
letter-spacing: 0.03em;
text-transform: none;
}
.tool-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.tool {
position: relative;
min-height: 74px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.48);
cursor: pointer;
text-align: left;
transition:
transform 140ms ease,
border-color 140ms ease,
background 140ms ease,
box-shadow 140ms ease;
}
.tool:hover {
transform: translateY(-1px);
border-color: rgba(31, 42, 36, 0.28);
background: rgba(255, 255, 255, 0.82);
}
.tool.active {
border-color: var(--green);
background: var(--green-light);
box-shadow: inset 0 0 0 1px var(--green);
}
.tool-icon {
display: block;
width: 21px;
height: 15px;
margin-bottom: 8px;
border-radius: 3px;
background: var(--tool-color);
box-shadow:
5px -4px 0 -1px color-mix(in srgb, var(--tool-color), #fff 25%),
-5px 4px 0 -1px rgba(30, 40, 34, 0.23);
}
.tool strong {
display: block;
font-size: 11px;
font-weight: 760;
}
.tool small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.button-row {
display: flex;
gap: 8px;
margin-top: 10px;
}
.mini-button {
flex: 1;
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.54);
cursor: pointer;
font-size: 10px;
font-weight: 700;
transition: background 140ms ease;
}
.mini-button:hover {
background: #fff;
}
.mini-button.danger {
color: #a43e36;
}
.hint-box {
margin-top: 13px;
padding: 10px 11px;
border-left: 3px solid var(--route);
border-radius: 2px 9px 9px 2px;
background: rgba(215, 167, 53, 0.11);
color: #5f655e;
font-size: 10px;
line-height: 1.45;
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
cursor: pointer;
font-size: 11px;
font-weight: 650;
}
.toggle input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.toggle-track {
position: relative;
width: 34px;
height: 19px;
flex: 0 0 auto;
border-radius: 999px;
background: #c8cec9;
transition: background 160ms ease;
}
.toggle-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
content: "";
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
transition: transform 160ms ease;
}
.toggle input:checked + .toggle-track {
background: var(--green);
}
.toggle input:checked + .toggle-track::after {
transform: translateX(15px);
}
.legend {
display: grid;
gap: 7px;
color: #606a63;
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.legend-dot {
width: 15px;
height: 5px;
border-radius: 2px;
background: var(--dot);
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border-radius: 999px;
background: var(--green-light);
color: var(--green);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.status-pill::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: currentColor;
}
.status-pill.warning {
background: rgba(220, 86, 75, 0.12);
color: #b63d35;
}
.metric {
padding: 12px 0;
border-bottom: 1px solid var(--line);
}
.metric:last-of-type {
border-bottom: 0;
}
.metric-head {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
}
.metric-name {
font-size: 11px;
font-weight: 720;
}
.metric-score {
font-size: 21px;
font-weight: 800;
letter-spacing: -0.05em;
}
.metric-sub {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.bar {
height: 5px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: #dde0dc;
}
.bar > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--bar-color, var(--green));
transition:
width 300ms ease,
background 180ms ease;
}
.comparison {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.compare-card {
padding: 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.48);
}
.compare-card strong {
display: block;
margin-bottom: 5px;
font-size: 10px;
}
.compare-value {
font-size: 22px;
font-weight: 800;
letter-spacing: -0.05em;
}
.compare-value small {
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0;
}
.compare-state {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.event-list {
display: grid;
gap: 7px;
max-height: 178px;
overflow: auto;
}
.event-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 8px;
min-height: 39px;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.44);
}
.event-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--event-color);
}
.event-name {
overflow: hidden;
font-size: 10px;
font-weight: 730;
text-overflow: ellipsis;
white-space: nowrap;
}
.event-status {
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.event-status.conflict {
color: #b64037;
}
.event-status.warning {
color: #a66a25;
}
.remove-event {
width: 23px;
height: 23px;
padding: 0;
border: 0;
border-radius: 6px;
background: transparent;
color: #8a928d;
cursor: pointer;
font-size: 17px;
}
.remove-event:hover {
background: rgba(220, 86, 75, 0.1);
color: var(--coral);
}
.empty-state {
padding: 15px 10px;
border: 1px dashed var(--line);
border-radius: 9px;
color: var(--muted);
font-size: 10px;
text-align: center;
}
.bottom-bar {
position: absolute;
z-index: 8;
left: 50%;
bottom: 18px;
display: flex;
align-items: center;
gap: 12px;
transform: translateX(-50%);
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.64);
border-radius: 13px;
background: rgba(248, 245, 237, 0.86);
box-shadow: 0 8px 25px rgba(37, 43, 36, 0.11);
backdrop-filter: blur(12px);
}
.view-button {
min-width: 74px;
padding: 7px 10px;
border: 0;
border-radius: 8px;
background: transparent;
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.view-button:hover,
.view-button.active {
background: #e4e9e2;
}
.view-divider {
width: 1px;
height: 24px;
background: var(--line);
}
.control-hint {
padding: 0 8px 0 3px;
color: #68726c;
font-size: 9px;
white-space: nowrap;
}
#toast {
position: absolute;
z-index: 30;
left: 50%;
bottom: 88px;
max-width: min(420px, calc(100vw - 30px));
padding: 10px 14px;
transform: translate(-50%, 12px);
border-radius: 10px;
background: #20342b;
box-shadow: 0 10px 28px rgba(25, 40, 32, 0.25);
color: white;
font-size: 11px;
opacity: 0;
pointer-events: none;
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.visible {
transform: translate(-50%, 0);
opacity: 1;
}
#toast.error {
background: #9d3e37;
}
.disclaimer {
position: absolute;
z-index: 5;
right: 26px;
bottom: 24px;
max-width: 230px;
color: rgba(31, 42, 36, 0.58);
font-size: 8px;
line-height: 1.35;
text-align: right;
pointer-events: none;
}
@media (max-width: 1050px) {
.panel-left {
width: 245px;
}
.panel-right {
width: 270px;
}
.top-meta,
.disclaimer {
display: none;
}
.control-hint {
display: none;
}
}
@media (max-width: 760px) {
.topbar {
padding: 16px;
}
.subtitle {
display: none;
}
.panel {
top: auto;
bottom: 65px;
max-height: 40vh;
overflow: auto;
padding: 13px;
}
.panel-left {
left: 10px;
width: 210px;
}
.panel-right {
right: 10px;
width: 205px;
}
.tool-grid {
grid-template-columns: 1fr 1fr;
}
.tool {
min-height: 60px;
padding: 8px;
}
.tool small,
.legend,
.section-rule,
.hint-box {
display: none;
}
.bottom-bar {
bottom: 10px;
}
.view-button {
min-width: 62px;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive voxel model of Superkilen"></canvas>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Copenhagen · Public space study</div>
<h1>Superkilen, in motion</h1>
<p class="subtitle">
Test temporary community activations against the park’s through-route
and compare how they change access to seating and play.
</p>
</div>
<div class="top-meta"><span></span>Live spatial check</div>
</header>
<aside class="panel panel-left">
<div class="section-label">
<span>01 / Add activation</span>
<span>Click to place</span>
</div>
<h2>Temporary community elements</h2>
<p class="panel-intro">
Select a module, then click the lawn. Red indicates a conflict with the
main movement line; amber identifies an access pinch.
</p>
<div class="tool-grid" id="tools">
<button class="tool" data-tool="stage" style="--tool-color:#d65d58">
<span class="tool-icon"></span>
<strong>Mini stage</strong>
<small>3.6 × 2.4 m</small>
</button>
<button class="tool" data-tool="market" style="--tool-color:#e2aa39">
<span class="tool-icon"></span>
<strong>Market row</strong>
<small>2.8 × 2.2 m</small>
</button>
<button class="tool" data-tool="picnic" style="--tool-color:#4b9b72">
<span class="tool-icon"></span>
<strong>Picnic set</strong>
<small>2.2 × 1.8 m</small>
</button>
<button class="tool" data-tool="bike" style="--tool-color:#477ba5">
<span class="tool-icon"></span>
<strong>Bike workshop</strong>
<small>3.0 × 1.8 m</small>
</button>
</div>
<div class="button-row">
<button class="mini-button" id="rotateButton">Rotate 90° · R</button>
<button class="mini-button" id="finishButton">Finish</button>
</div>
<div class="section-rule"></div>
<div class="section-label">
<span>02 / Map layers</span>
<span>Visibility</span>
</div>
<label class="toggle">
Through-route
<input type="checkbox" id="routeToggle" checked />
<span class="toggle-track"></span>
</label>
<label class="toggle">
Access paths
<input type="checkbox" id="accessToggle" checked />
<span class="toggle-track"></span>
</label>
<div class="section-rule"></div>
<div class="section-label">
<span>Legend</span>
<span>Schematic</span>
</div>
<div class="legend">
<div class="legend-item">
<span class="legend-dot" style="--dot:#d7a735"></span>
East–west through-route
</div>
<div class="legend-item">
<span class="legend-dot" style="--dot:#278b91"></span>
Access to seating and play
</div>
<div class="legend-item">
<span class="legend-dot" style="--dot:#dc564b"></span>
Route conflict
</div>
<div class="legend-item">
<span class="legend-dot" style="--dot:#e29b43"></span>
Reduced amenity access
</div>
</div>
</aside>
<aside class="panel panel-right">
<div class="section-label">
<span>03 / Live analysis</span>
<span id="analysisStatus" class="status-pill">Clear</span>
</div>
<h2>Spatial consequences</h2>
<p class="panel-intro" id="analysisSummary">
Place an event to test movement and amenity access.
</p>
<div class="metric">
<div class="metric-head">
<span class="metric-name">Through-route continuity</span>
<span class="metric-score" id="routeScore">100</span>
</div>
<div class="metric-sub" id="routeState">All movement segments are clear</div>
<div class="bar">
<span id="routeBar" style="--bar-color:#31705a"></span>
</div>
</div>
<div class="comparison">
<div class="compare-card">
<strong>Seating access</strong>
<div class="compare-value">
<span id="seatScore">100</span><small> / 100</small>
</div>
<div class="compare-state" id="seatState">Both seating routes clear</div>
</div>
<div class="compare-card">
<strong>Play access</strong>
<div class="compare-value">
<span id="playScore">100</span><small> / 100</small>
</div>
<div class="compare-state" id="playState">Play meadow route clear</div>
</div>
</div>
<div class="section-rule"></div>
<div class="section-label">
<span>Temporary elements</span>
<span id="eventCount">0 placed</span>
</div>
<div class="event-list" id="eventList"></div>
<div class="button-row">
<button class="mini-button danger" id="clearButton">Clear all elements</button>
</div>
</aside>
<div class="bottom-bar">
<button class="view-button active" data-view="iso">Isometric</button>
<button class="view-button" data-view="plan">Plan view</button>
<div class="view-divider"></div>
<button class="view-button" id="resetButton">Reset view</button>
<div class="view-divider"></div>
<div class="control-hint">Drag to orbit · Wheel to zoom · R rotate · Esc cancel</div>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<div class="disclaimer">
Schematic interpretation inspired by Superkilen’s red square, green park
and surrounding public life. Not an architectural survey or official plan.
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// App state
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const toastElement = document.querySelector("#toast");
const toolDefinitions = {
stage: {
name: "Mini stage",
width: 3.6,
depth: 2.4,
color: "#d65d58"
},
market: {
name: "Market row",
width: 2.8,
depth: 2.2,
color: "#e2aa39"
},
picnic: {
name: "Picnic set",
width: 2.2,
depth: 1.8,
color: "#4b9b72"
},
bike: {
name: "Bike workshop",
width: 3.0,
depth: 1.8,
color: "#477ba5"
}
};
const events = [];
let eventId = 0;
let activeTool = null;
let placementRotation = 0;
let ghost = null;
let toastTimeout = null;
const routePoints = [
{ x: -18, z: 0 },
{ x: -11, z: 0 },
{ x: -5, z: 0 },
{ x: 0, z: 1.5 },
{ x: 10, z: 1.5 },
{ x: 18, z: 1.5 }
];
const accessPaths = [
{
id: "seat-a",
label: "North seating",
destination: { x: -6, z: -3.2 },
points: [
{ x: -6, z: 0 },
{ x: -6, z: -3.2 }
]
},
{
id: "seat-b",
label: "East seating",
destination: { x: 3, z: -3.4 },
points: [
{ x: 3, z: 1.5 },
{ x: 3, z: -3.4 }
]
},
{
id: "play",
label: "Play meadow",
destination: { x: 5, z: 4 },
points: [
{ x: 10, z: 1.5 },
{ x: 10, z: 4 },
{ x: 5, z: 4 }
]
}
];
const protectedAreas = [
{ x: -6, z: -5.35, width: 4.7, depth: 3.0 },
{ x: -6, z: -3.3, width: 3.6, depth: 1.9 },
{ x: 3, z: -3.6, width: 3.6, depth: 2.0 },
{ x: 5, z: 4, width: 5.1, depth: 4.0 },
{ x: 8, z: -5.0, width: 4.0, depth: 3.0 }
];
// -------------------------------------------------------------------------
// Renderer, scene and camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d4c8);
scene.fog = new THREE.Fog(0xd9d4c8, 55, 100);
const camera = new THREE.OrthographicCamera(-25, 25, 20, -20, 0.1, 180);
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
radius: 48,
phi: 0.86,
theta: 0.63,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xf8f2dd, 0x718174, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d5, 3.1);
sun.position.set(-18, 32, 19);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const world = new THREE.Group();
const routeGroup = new THREE.Group();
const accessGroup = new THREE.Group();
const eventGroup = new THREE.Group();
const permanentGroup = new THREE.Group();
scene.add(world, routeGroup, accessGroup, eventGroup, permanentGroup);
const placementPlane = new THREE.Mesh(
new THREE.PlaneGeometry(24, 16),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
placementPlane.rotation.x = -Math.PI / 2;
placementPlane.position.set(0, 0.37, 0);
scene.add(placementPlane);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
...options
});
}
function addBox(
parent,
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standardMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addSegmentBox(
parent,
start,
end,
width,
height,
y,
color,
options = {}
) {
const dx = end.x - start.x;
const dz = end.z - start.z;
const length = Math.hypot(dx, dz);
const mesh = addBox(
parent,
length,
height,
width,
color,
(start.x + end.x) / 2,
y,
(start.z + end.z) / 2,
options
);
mesh.rotation.y = -Math.atan2(dz, dx);
return mesh;
}
function makeLabel(
text,
x,
y,
z,
options = {}
) {
const canvasLabel = document.createElement("canvas");
const context = canvasLabel.getContext("2d");
context.font = "800 46px system-ui, sans-serif";
const measuredWidth = context.measureText(text).width;
const width = Math.max(180, Math.ceil(measuredWidth + 64));
const height = 100;
canvasLabel.width = width;
canvasLabel.height = height;
context.clearRect(0, 0, width, height);
const radius = 22;
const x0 = 3;
const y0 = 3;
const w = width - 6;
const h = height - 6;
context.beginPath();
context.moveTo(x0 + radius, y0);
context.lineTo(x0 + w - radius, y0);
context.quadraticCurveTo(x0 + w, y0, x0 + w, y0 + radius);
context.lineTo(x0 + w, y0 + h - radius);
context.quadraticCurveTo(
x0 + w,
y0 + h,
x0 + w - radius,
y0 + h
);
context.lineTo(x0 + radius, y0 + h);
context.quadraticCurveTo(x0, y0 + h, x0, y0 + h - radius);
context.lineTo(x0, y0 + radius);
context.quadraticCurveTo(x0, y0, x0 + radius, y0);
context.closePath();
context.fillStyle = options.background || "rgba(248,245,237,0.94)";
context.fill();
context.strokeStyle = options.border || "rgba(34,48,40,0.22)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = options.color || "#203229";
context.font = "800 46px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height / 2 + 2);
const texture = new THREE.CanvasTexture(canvasLabel);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const labelHeight = options.height || 0.9;
sprite.scale.set((width / height) * labelHeight, labelHeight, 1);
sprite.position.set(x, y, z);
sprite.renderOrder = 20;
return sprite;
}
function createTree(x, z, scale = 1, palette = 0) {
const tree = new THREE.Group();
const crownColors = ["#477a56", "#5e8a5f", "#3f7256", "#719261"];
addBox(tree, 0.32, 1.55, 0.32, "#72513c", 0, 0.78, 0);
addBox(
tree,
1.55,
1.05,
1.45,
crownColors[palette % crownColors.length],
0,
1.85,
0
);
addBox(
tree,
1.1,
0.75,
1.05,
crownColors[(palette + 1) % crownColors.length],
-0.22,
2.55,
0.08
);
addBox(
tree,
0.9,
0.65,
0.9,
crownColors[(palette + 2) % crownColors.length],
0.32,
2.42,
-0.16
);
tree.position.set(x, 0.18, z);
tree.scale.setScalar(scale);
world.add(tree);
}
function createBench(x, z, rotation = 0, color = "#8c6547") {
const bench = new THREE.Group();
addBox(bench, 2.35, 0.18, 0.62, color, 0, 0.55, 0);
addBox(bench, 2.35, 0.62, 0.14, color, 0, 0.91, -0.28);
addBox(bench, 0.15, 0.5, 0.5, "#46504a", -0.88, 0.25, 0);
addBox(bench, 0.15, 0.5, 0.5, "#46504a", 0.88, 0.25, 0);
bench.position.set(x, 0.18, z);
bench.rotation.y = rotation;
permanentGroup.add(bench);
return bench;
}
function createPerson(x, z, color, rotation = 0, scale = 1) {
const person = new THREE.Group();
addBox(person, 0.28, 0.62, 0.22, color, 0, 0.48, 0);
addBox(person, 0.25, 0.25, 0.25, "#d9ad84", 0, 0.93, 0);
addBox(person, 0.16, 0.38, 0.16, "#35454a", -0.09, 0.18, 0);
addBox(person, 0.16, 0.38, 0.16, "#35454a", 0.09, 0.18, 0);
person.position.set(x, 0.24, z);
person.rotation.y = rotation;
person.scale.setScalar(scale);
world.add(person);
}
// -------------------------------------------------------------------------
// Schematic city and Superkilen landscape
// -------------------------------------------------------------------------
addBox(world, 39.5, 0.9, 28.5, "#bfb5a2", 0, -0.53, 0);
addBox(world, 38.8, 0.18, 27.8, "#e6ded0", 0, -0.02, 0);
// Roads around the park block.
addBox(world, 38.4, 0.08, 2.25, "#8c918b", 0, 0.08, -12.1);
addBox(world, 38.4, 0.08, 2.25, "#8c918b", 0, 0.08, 12.1);
addBox(world, 2.2, 0.08, 24.5, "#8c918b", -18.2, 0.08, 0);
addBox(world, 2.2, 0.08, 24.5, "#8c918b", 18.2, 0.08, 0);
// Green park and the red square.
addBox(world, 24.2, 0.22, 16.2, "#91aa72", 0, 0.13, 0);
addBox(world, 5.6, 0.25, 10.2, "#b95148", -13.3, 0.25, 0);
addBox(world, 4.2, 0.18, 3.4, "#5c849b", 8, 0.28, -5);
// Sidewalk edging.
addBox(world, 24.6, 0.12, 0.25, "#d2c8b6", 0, 0.25, -8.1);
addBox(world, 24.6, 0.12, 0.25, "#d2c8b6", 0, 0.25, 8.1);
// Crosswalks.
for (let i = 0; i < 6; i++) {
addBox(world, 0.38, 0.04, 2.5, "#dedbd1", -15.9 + i * 0.55, 0.15, -12.1);
addBox(world, 0.38, 0.04, 2.5, "#dedbd1", 14.4 + i * 0.55, 0.15, 12.1);
}
// North-side city edge.
const buildingColors = ["#b7a997", "#a7a394", "#c3b6a5", "#9f9b90"];
const buildingHeights = [5.3, 7.2, 4.8, 6.4, 8.2, 5.7, 6.9];
for (let i = 0; i < 7; i++) {
const x = -15 + i * 5;
const height = buildingHeights[i];
const width = 4.35;
const depth = 3.8;
addBox(
world,
width,
height,
depth,
buildingColors[i % buildingColors.length],
x,
height / 2 + 0.15,
-11.3
);
addBox(
world,
width + 0.18,
0.25,
depth + 0.18,
"#8f897e",
x,
height + 0.24,
-11.3
);
for (let row = 0; row < Math.floor(height / 1.2); row++) {
for (let column = 0; column < 3; column++) {
addBox(
world,
0.52,
0.6,
0.04,
row % 2 === 0 ? "#d9d8bd" : "#84969a",
x - 1.15 + column * 1.15,
1.15 + row * 1.05,
-9.38
);
}
}
}
// A few low buildings on the near side preserve the park view.
addBox(world, 4.8, 3.2, 3.5, "#b6ac9b", -15.2, 1.75, 11.3);
addBox(world, 4.2, 2.7, 3.5, "#aaa596", 15.7, 1.5, 11.3);
// Trees along the park edges.
const treePositions = [
[-10.6, -7.1, 0.92, 0],
[-7.8, -7.2, 1.05, 1],
[-3.2, -7.25, 0.88, 2],
[0.1, -7.25, 1.02, 3],
[3.4, -7.25, 0.9, 0],
[10.8, -7.15, 1.0, 1],
[-10.6, 7.15, 0.93, 2],
[-7.8, 7.2, 1.04, 3],
[-3.2, 7.15, 0.88, 0],
[0.2, 7.2, 1.0, 1],
[3.5, 7.2, 0.92, 2],
[10.8, 7.1, 1.06, 3],
[-16.8, -7.5, 1.1, 1],
[-16.8, 7.4, 1.05, 2]
];
treePositions.forEach(([x, z, scale, palette]) =>
createTree(x, z, scale, palette)
);
// Permanent amphitheatre.
addBox(permanentGroup, 4.8, 0.45, 3.0, "#8f755c", -6, 0.46, -5.35);
addBox(permanentGroup, 4.3, 0.4, 1.8, "#b88862", -6, 0.85, -5.75);
addBox(permanentGroup, 4.4, 1.25, 0.22, "#8c4f48", -6, 1.55, -6.2);
addBox(permanentGroup, 4.9, 0.22, 2.2, "#4d5652", -6, 2.35, -5.55);
addBox(permanentGroup, 0.18, 1.9, 0.18, "#4d5652", -8.2, 1.45, -6.1);
addBox(permanentGroup, 0.18, 1.9, 0.18, "#4d5652", -3.8, 1.45, -6.1);
// Seating terrace.
addBox(permanentGroup, 4.2, 0.12, 2.7, "#cbb895", -6, 0.3, -3.3);
createBench(-6.7, -3.4, Math.PI / 2);
createBench(-5.3, -3.4, Math.PI / 2);
createBench(-6, -4.1, 0);
// East seating.
addBox(permanentGroup, 4.1, 0.12, 2.7, "#cbb895", 3, 0.3, -3.6);
createBench(2.2, -3.8, 0);
createBench(3.8, -3.8, 0);
// Play meadow.
addBox(permanentGroup, 5.3, 0.14, 4.2, "#d7bd83", 5, 0.31, 4);
addBox(permanentGroup, 1.7, 0.25, 1.5, "#d96b50", 4, 0.53, 4.8);
addBox(permanentGroup, 0.65, 0.9, 0.65, "#4c8da0", 4.4, 0.9, 4.8);
addBox(permanentGroup, 2.5, 0.2, 0.65, "#e0ae3f", 6.4, 0.78, 3.4);
addBox(permanentGroup, 0.2, 1.2, 0.2, "#47756a", 6.8, 0.8, 3.4);
addBox(permanentGroup, 0.2, 1.2, 0.2, "#47756a", 5.2, 0.8, 3.4);
// Sports strip.
addBox(permanentGroup, 3.7, 0.12, 2.7, "#6f94aa", 8, 0.4, -5);
addBox(permanentGroup, 0.09, 0.04, 2.6, "#d9d7c2", 8, 0.48, -5);
addBox(permanentGroup, 3.6, 0.04, 0.09, "#d9d7c2", 8, 0.48, -5);
// Red-square furniture and people.
createBench(-14.3, -2.8, Math.PI / 2, "#744b43");
createBench(-14.3, 1.8, Math.PI / 2, "#744b43");
createPerson(-13.7, 0.2, "#315f77", 0.4);
createPerson(-12.8, -0.6, "#d39a35", 1.8, 0.9);
createPerson(-13.2, 2.3, "#8f5147", 2.6, 1.05);
createPerson(-4.4, 2.5, "#4c7d67", 0.1, 0.93);
createPerson(2.2, 2.2, "#c36c49", 1.4, 0.85);
createPerson(6.3, 3.2, "#426d91", 2.5, 0.95);
// -------------------------------------------------------------------------
// Main route and access path layers
// -------------------------------------------------------------------------
const routeSegments = [];
for (let i = 0; i < routePoints.length - 1; i++) {
const start = routePoints[i];
const end = routePoints[i + 1];
addSegmentBox(
routeGroup,
start,
end,
2.0,
0.055,
0.32,
"#b9a66f"
);
const inner = addSegmentBox(
routeGroup,
start,
end,
1.38,
0.065,
0.37,
"#d7a735"
);
routeSegments.push({
start,
end,
mesh: inner,
conflict: false
});
}
const routeLabel = makeLabel(
"THROUGH-ROUTE →",
-2.5,
0.95,
1.5,
{
background: "rgba(248,241,212,0.95)",
border: "rgba(176,133,34,0.35)",
color: "#735616",
height: 0.72
}
);
routeGroup.add(routeLabel);
const accessSegments = [];
accessPaths.forEach((path) => {
for (let i = 0; i < path.points.length - 1; i++) {
const start = path.points[i];
const end = path.points[i + 1];
const mesh = addSegmentBox(
accessGroup,
start,
end,
0.72,
0.045,
0.405,
"#278b91",
{ castShadow: false }
);
accessSegments.push({
pathId: path.id,
start,
end,
mesh,
blocked: false
});
}
addBox(
accessGroup,
0.55,
0.04,
0.55,
"#278b91",
path.destination.x,
0.405,
path.destination.z,
{ castShadow: false }
);
});
// Spatial labels.
permanentGroup.add(
makeLabel("RED SQUARE", -13.5, 1.0, 0, {
background: "rgba(176,66,59,0.94)",
border: "rgba(118,45,42,0.4)",
color: "#fff8ec",
height: 0.85
})
);
permanentGroup.add(
makeLabel("GREEN PARK", -2.2, 1.2, -6.8, {
background: "rgba(39,73,51,0.92)",
border: "rgba(39,73,51,0.35)",
color: "#f8f4df",
height: 0.9
})
);
permanentGroup.add(
makeLabel("SEATING", -6, 1.55, -3.4, {
height: 0.65
})
);
permanentGroup.add(
makeLabel("PLAY MEADOW", 5, 1.7, 4, {
background: "rgba(252,243,207,0.95)",
border: "rgba(158,124,50,0.32)",
color: "#725821",
height: 0.72
})
);
permanentGroup.add(
makeLabel("SPORTS", 8, 1.55, -5, {
background: "rgba(222,235,240,0.95)",
border: "rgba(66,100,122,0.32)",
color: "#365d74",
height: 0.65
})
);
permanentGroup.add(
makeLabel("NØRREBRO", -17.1, 1.2, 0, {
height: 0.68
})
);
// -------------------------------------------------------------------------
// Temporary event geometry
// -------------------------------------------------------------------------
function createEventVisual(type) {
const group = new THREE.Group();
if (type === "stage") {
addBox(group, 3.6, 0.22, 2.4, "#56524e", 0, 0.12, 0);
addBox(group, 3.6, 1.25, 0.18, "#d65d58", 0, 0.85, -1.02);
addBox(group, 3.8, 0.18, 2.5, "#e5c260", 0, 1.62, 0);
addBox(group, 0.15, 1.55, 0.15, "#4b504c", -1.62, 0.92, -0.9);
addBox(group, 0.15, 1.55, 0.15, "#4b504c", 1.62, 0.92, -0.9);
addBox(group, 1.5, 0.12, 0.55, "#eee2c4", 0, 0.65, -0.45);
}
if (type === "market") {
addBox(group, 2.8, 0.1, 2.2, "#c5a66f", 0, 0.05, 0);
[-0.9, 0, 0.9].forEach((x, index) => {
const canopy = index % 2 === 0 ? "#e2aa39" : "#d65d58";
addBox(group, 0.72, 0.8, 0.75, "#8c6547", x, 0.48, -0.2);
addBox(group, 0.82, 0.16, 1.05, canopy, x, 1.15, -0.15);
addBox(group, 0.08, 1.05, 0.08, "#52544d", x - 0.32, 0.62, -0.48);
addBox(group, 0.08, 1.05, 0.08, "#52544d", x + 0.32, 0.62, -0.48);
if (index === 1) {
addBox(group, 0.25, 0.22, 0.25, "#719b5c", x - 0.2, 0.94, -0.2);
addBox(group, 0.25, 0.22, 0.25, "#c45f42", x + 0.18, 0.94, -0.2);
}
});
}
if (type === "picnic") {
addBox(group, 1.25, 0.15, 0.72, "#b47d52", 0, 0.76, 0);
addBox(group, 0.18, 0.7, 0.18, "#596059", -0.43, 0.38, 0);
addBox(group, 0.18, 0.7, 0.18, "#596059", 0.43, 0.38, 0);
addBox(group, 2.0, 0.15, 0.38, "#9b6947", 0, 0.42, -0.65);
addBox(group, 2.0, 0.15, 0.38, "#9b6947", 0, 0.42, 0.65);
addBox(group, 0.12, 0.35, 0.12, "#596059", -0.72, 0.2, -0.65);
addBox(group, 0.12, 0.35, 0.12, "#596059", 0.72, 0.2, -0.65);
addBox(group, 0.12, 0.35, 0.12, "#596059", -0.72, 0.2, 0.65);
addBox(group, 0.12, 0.35, 0.12, "#596059", 0.72, 0.2, 0.65);
addBox(group, 0.28, 0.28, 0.28, "#e0ad3d", 0.3, 0.98, 0);
}
if (type === "bike") {
addBox(group, 3.0, 0.1, 1.8, "#b8ac96", 0, 0.05, 0);
addBox(group, 0.8, 1.0, 0.7, "#477ba5", 1.05, 0.58, -0.48);
addBox(group, 0.62, 0.12, 0.55, "#d9cba9", 1.05, 1.14, -0.48);
[-0.75, 0.55].forEach((x, bikeIndex) => {
const z = bikeIndex === 0 ? 0.38 : -0.28;
const frameColor = bikeIndex === 0 ? "#d65d58" : "#e2aa39";
// Square voxel wheels.
[-1, 1].forEach((xDirection) => {
const wheelX = x + xDirection * 0.48;
addBox(group, 0.44, 0.07, 0.07, "#303936", wheelX, 0.43, z);
addBox(group, 0.44, 0.07, 0.07, "#303936", wheelX, 0.85, z);
addBox(group, 0.07, 0.42, 0.07, "#303936", wheelX - 0.2, 0.64, z);
addBox(group, 0.07, 0.42, 0.07, "#303936", wheelX + 0.2, 0.64, z);
});
addBox(group, 0.58, 0.07, 0.07, frameColor, x, 0.65, z);
addBox(group, 0.07, 0.48, 0.07, frameColor, x, 0.65, z);
addBox(group, 0.07, 0.42, 0.07, frameColor, x + 0.2, 0.74, z);
addBox(group, 0.4, 0.07, 0.07, "#303936", x + 0.18, 0.95, z);
});
}
return group;
}
function createMarker(color) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.04, 1),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.25,
depthWrite: false
})
);
marker.position.y = 0.025;
marker.visible = false;
return marker;
}
function getFootprint(event) {
const definition = toolDefinitions[event.type];
const rotated = Math.abs(Math.sin(event.rotation)) > 0.5;
return {
x: event.x,
z: event.z,
width: rotated ? definition.depth : definition.width,
depth: rotated ? definition.width : definition.depth
};
}
function addEvent(type, x, z, rotation = 0, customName = null) {
const definition = toolDefinitions[type];
if (!definition) return null;
const group = createEventVisual(type);
group.position.set(x, 0.28, z);
group.rotation.y = rotation;
group.userData.eventId = eventId;
const routeMarker = createMarker("#dc564b");
const accessMarker = createMarker("#e29b43");
group.add(routeMarker, accessMarker);
const event = {
id: eventId++,
type,
name: customName || definition.name,
x,
z,
rotation,
group,
routeMarker,
accessMarker,
routeConflict: false,
accessConflict: false
};
const footprint = getFootprint(event);
routeMarker.scale.set(footprint.width + 0.4, 1, footprint.depth + 0.4);
accessMarker.scale.set(footprint.width + 0.65, 1, footprint.depth + 0.65);
eventGroup.add(group);
events.push(event);
return event;
}
function removeEvent(event) {
event.group.traverse((child) => {
if (child.geometry) child.geometry.dispose();
});
eventGroup.remove(event.group);
events.splice(events.indexOf(event), 1);
updateAnalysis();
}
// -------------------------------------------------------------------------
// Collision and conflict mathematics
// -------------------------------------------------------------------------
function segmentIntersectsRect(start, end, rectangle, padding = 0) {
const minX = rectangle.x - rectangle.width / 2 - padding;
const maxX = rectangle.x + rectangle.width / 2 + padding;
const minZ = rectangle.z - rectangle.depth / 2 - padding;
const maxZ = rectangle.z + rectangle.depth / 2 + padding;
const dx = end.x - start.x;
const dz = end.z - start.z;
let t0 = 0;
let t1 = 1;
const p = [-dx, dx, -dz, dz];
const q = [
start.x - minX,
maxX - start.x,
start.z - minZ,
maxZ - start.z
];
for (let i = 0; i < 4; i++) {
if (p[i] === 0) {
if (q[i] < 0) return false;
} else {
const ratio = q[i] / p[i];
if (p[i] < 0) {
t0 = Math.max(t0, ratio);
} else {
t1 = Math.min(t1, ratio);
}
if (t0 > t1) return false;
}
}
return true;
}
function rectanglesOverlap(a, b, gap = 0) {
return (
Math.abs(a.x - b.x) <
(a.width + b.width) / 2 + gap &&
Math.abs(a.z - b.z) <
(a.depth + b.depth) / 2 + gap
);
}
function placementProblem(x, z, rotation) {
const definition = toolDefinitions[activeTool];
const rotated = Math.abs(Math.sin(rotation)) > 0.5;
const footprint = {
x,
z,
width: rotated ? definition.depth : definition.width,
depth: rotated ? definition.width : definition.depth
};
if (
x - footprint.width / 2 < -11.4 ||
x + footprint.width / 2 > 11.4 ||
z - footprint.depth / 2 < -7.45 ||
z + footprint.depth / 2 > 7.45
) {
return "Keep the element inside the green park boundary.";
}
for (const protectedArea of protectedAreas) {
if (rectanglesOverlap(footprint, protectedArea, 0.12)) {
return "That space is occupied by a permanent park feature.";
}
}
for (const event of events) {
if (rectanglesOverlap(footprint, getFootprint(event), 0.12)) {
return "That footprint overlaps another temporary element.";
}
}
return null;
}
// -------------------------------------------------------------------------
// Analysis and interface
// -------------------------------------------------------------------------
function statusForScore(score) {
if (score >= 90) {
return {
label: "Clear",
color: "#31705a"
};
}
if (score >= 65) {
return {
label: "Reduced",
color: "#d39137"
};
}
return {
label: "Constrained",
color: "#c64d43"
};
}
function setText(id, value) {
document.querySelector(`#${id}`).textContent = value;
}
function updateAnalysis() {
routeSegments.forEach((segment) => {
segment.conflict = false;
});
accessSegments.forEach((segment) => {
segment.blocked = false;
});
events.forEach((event) => {
const footprint = getFootprint(event);
event.routeConflict = false;
event.accessConflict = false;
routeSegments.forEach((segment) => {
if (
segmentIntersectsRect(
segment.start,
segment.end,
footprint,
0.7
)
) {
segment.conflict = true;
event.routeConflict = true;
}
});
accessSegments.forEach((segment) => {
if (
segmentIntersectsRect(
segment.start,
segment.end,
footprint,
0.42
)
) {
segment.blocked = true;
event.accessConflict = true;
}
});
event.routeMarker.visible = event.routeConflict;
event.accessMarker.visible = event.accessConflict && !event.routeConflict;
});
routeSegments.forEach((segment) => {
segment.mesh.material.color.set(
segment.conflict ? "#dc564b" : "#d7a735"
);
});
accessSegments.forEach((segment) => {
segment.mesh.material.color.set(
segment.blocked ? "#e29b43" : "#278b91"
);
});
const routeConflictSegments = routeSegments.filter(
(segment) => segment.conflict
).length;
const routeConflictEvents = events.filter(
(event) => event.routeConflict
).length;
const routeScore = Math.max(
20,
100 - routeConflictSegments * 18 - routeConflictEvents * 12
);
const scoresByPath = {};
accessPaths.forEach((path) => {
const segments = accessSegments.filter(
(segment) => segment.pathId === path.id
);
const blockedCount = segments.filter(
(segment) => segment.blocked
).length;
scoresByPath[path.id] = Math.max(20, 100 - blockedCount * 34);
});
const seatScore = Math.round(
(scoresByPath["seat-a"] + scoresByPath["seat-b"]) / 2
);
const playScore = scoresByPath.play;
setText("routeScore", routeScore);
setText("seatScore", seatScore);
setText("playScore", playScore);
document.querySelector("#routeBar").style.width = `${routeScore}%`;
document.querySelector("#routeBar").style.setProperty(
"--bar-color",
routeScore >= 90 ? "#31705a" : routeScore >= 65 ? "#d39137" : "#dc564b"
);
const seatStatus = statusForScore(seatScore);
const playStatus = statusForScore(playScore);
document.querySelector("#seatState").textContent =
seatStatus.label === "Clear"
? "Both seating routes clear"
: "One or more seating routes obstructed";
document.querySelector("#playState").textContent =
playStatus.label === "Clear"
? "Play meadow route clear"
: "Play meadow access is narrowed";
if (routeConflictEvents > 0) {
setText(
"routeState",
`${routeConflictEvents} element${routeConflictEvents === 1 ? "" : "s"} interrupt the movement line`
);
} else {
setText("routeState", "All movement segments are clear");
}
const analysisStatus = document.querySelector("#analysisStatus");
const hasProblem = routeConflictEvents > 0 || seatScore < 90 || playScore < 90;
analysisStatus.classList.toggle("warning", hasProblem);
analysisStatus.textContent = hasProblem ? "Coordination needed" : "Clear";
if (events.length === 0) {
setText(
"analysisSummary",
"No temporary elements yet. Add one to test movement and amenity access."
);
} else {
const accessIssues = events.filter(
(event) => event.accessConflict
).length;
setText(
"analysisSummary",
`${events.length} temporary element${events.length === 1 ? "" : "s"} · ${routeConflictEvents} route conflict${routeConflictEvents === 1 ? "" : "s"} · ${accessIssues} access pinch${accessIssues === 1 ? "" : "es"}`
);
}
setText("eventCount", `${events.length} placed`);
renderEventList();
}
function renderEventList() {
const list = document.querySelector("#eventList");
list.replaceChildren();
if (events.length === 0) {
const empty = document.createElement("div");
empty.className = "empty-state";
empty.textContent = "The park is currently unprogrammed.";
list.append(empty);
return;
}
events.forEach((event) => {
const row = document.createElement("div");
row.className = "event-row";
const dot = document.createElement("span");
dot.className = "event-dot";
dot.style.setProperty("--event-color", toolDefinitions[event.type].color);
const details = document.createElement("div");
const name = document.createElement("div");
name.className = "event-name";
name.textContent = event.name;
const status = document.createElement("div");
status.className = "event-status";
if (event.routeConflict) {
status.textContent = "Conflicts with through-route";
status.classList.add("conflict");
} else if (event.accessConflict) {
status.textContent = "Creates an access pinch";
status.classList.add("warning");
} else {
status.textContent = "No direct conflict";
}
details.append(name, status);
const remove = document.createElement("button");
remove.className = "remove-event";
remove.textContent = "×";
remove.title = `Remove ${event.name}`;
remove.setAttribute("aria-label", `Remove ${event.name}`);
remove.addEventListener("click", () => {
removeEvent(event);
showToast(`${event.name} removed`);
});
row.append(dot, details, remove);
list.append(row);
});
}
function showToast(message, isError = false) {
toastElement.textContent = message;
toastElement.classList.toggle("error", isError);
toastElement.classList.add("visible");
clearTimeout(toastTimeout);
toastTimeout = setTimeout(() => {
toastElement.classList.remove("visible");
}, 2600);
}
// -------------------------------------------------------------------------
// Placement tools and preview
// -------------------------------------------------------------------------
function disposeGhost() {
if (!ghost) return;
ghost.traverse((child) => {
if (child.geometry) child.geometry.dispose();
});
scene.remove(ghost);
ghost = null;
}
function createGhost() {
disposeGhost();
if (!activeTool) return;
ghost = createEventVisual(activeTool);
ghost.traverse((child) => {
if (!child.isMesh) return;
child.material.transparent = true;
child.material.opacity = 0.5;
child.material.depthWrite = false;
child.castShadow = false;
child.receiveShadow = false;
});
const pad = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.035, 1),
new THREE.MeshBasicMaterial({
color: "#4c9b71",
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
pad.name = "ghost-pad";
ghost.add(pad);
ghost.visible = false;
scene.add(ghost);
}
function setActiveTool(tool) {
activeTool = tool;
placementRotation = 0;
document.querySelectorAll(".tool").forEach((button) => {
button.classList.toggle("active", button.dataset.tool === activeTool);
});
createGhost();
if (activeTool) {
showToast(`${toolDefinitions[activeTool].name} selected — click the park to place`);
}
}
document.querySelectorAll(".tool").forEach((button) => {
button.addEventListener("click", () => {
setActiveTool(button.dataset.tool);
});
});
document.querySelector("#rotateButton").addEventListener("click", () => {
if (!activeTool) {
showToast("Select an element before rotating", true);
return;
}
placementRotation = (placementRotation + Math.PI / 2) % Math.PI;
createGhost();
showToast("Next placement rotated 90°");
});
document.querySelector("#finishButton").addEventListener("click", () => {
setActiveTool(null);
});
document.querySelector("#clearButton").addEventListener("click", () => {
[...events].forEach(removeEvent);
showToast("All temporary elements cleared");
});
document.querySelector("#routeToggle").addEventListener("change", (event) => {
routeGroup.visible = event.target.checked;
});
document.querySelector("#accessToggle").addEventListener("change", (event) => {
accessGroup.visible = event.target.checked;
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
document.querySelector("#rotateButton").click();
}
if (event.key === "Escape") {
setActiveTool(null);
}
});
// -------------------------------------------------------------------------
// Raycasting, placement and camera interaction
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: false,
button: 0,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0
};
function updatePointerCoordinates(event) {
const bounds = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y = -((event.clientY - bounds.top) / bounds.height) * 2 + 1;
}
function getGroundHit() {
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObject(placementPlane, false)[0];
return hit ? hit.point : null;
}
function updateGhost(event) {
if (!activeTool || !ghost || pointerState.down) {
if (ghost) ghost.visible = false;
return;
}
updatePointerCoordinates(event);
const hit = getGroundHit();
if (!hit) {
ghost.visible = false;
return;
}
const x = Math.round(hit.x * 2) / 2;
const z = Math.round(hit.z * 2) / 2;
const problem = placementProblem(x, z, placementRotation);
const definition = toolDefinitions[activeTool];
const rotated = Math.abs(Math.sin(placementRotation)) > 0.5;
const width = rotated ? definition.depth : definition.width;
const depth = rotated ? definition.width : definition.depth;
ghost.visible = true;
ghost.position.set(x, 0.29, z);
ghost.rotation.y = placementRotation;
const pad = ghost.getObjectByName("ghost-pad");
pad.scale.set(width + 0.35, 1, depth + 0.35);
pad.material.color.set(problem ? "#dc564b" : "#4c9b71");
pad.material.opacity = problem ? 0.38 : 0.25;
}
function tryPlaceEvent() {
if (!activeTool) return;
const hit = getGroundHit();
if (!hit) return;
const x = Math.round(hit.x * 2) / 2;
const z = Math.round(hit.z * 2) / 2;
const problem = placementProblem(x, z, placementRotation);
if (problem) {
showToast(problem, true);
return;
}
if (events.length >= 10) {
showToast("The test supports up to ten temporary elements", true);
return;
}
const event = addEvent(activeTool, x, z, placementRotation);
updateAnalysis();
showToast(
event.routeConflict
? `${event.name} added — through-route conflict detected`
: event.accessConflict
? `${event.name} added — access pinch detected`
: `${event.name} added — no direct conflict`
);
}
function findEventFromPointer() {
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(eventGroup.children, true);
for (const hit of hits) {
let object = hit.object;
while (object && object !== eventGroup) {
if (object.userData.eventId !== undefined) {
return events.find(
(event) => event.id === object.userData.eventId
);
}
object = object.parent;
}
}
return null;
}
canvas.addEventListener("pointerdown", (event) => {
pointerState.down = true;
pointerState.moved = false;
pointerState.button = event.button;
pointerState.startX = event.clientX;
pointerState.startY = event.clientY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (pointerState.down) {
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
if (
Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
) > 5
) {
pointerState.moved = true;
}
if (pointerState.button === 2 || event.shiftKey) {
const scale = 0.035 / cameraState.zoom;
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3(
forward.z,
0,
-forward.x
);
cameraState.target.addScaledVector(
right,
-dx * scale
);
cameraState.target.addScaledVector(
forward,
dy * scale
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.08,
1.35
);
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
updateCamera();
}
updateGhost(event);
});
canvas.addEventListener("pointerup", (event) => {
if (pointerState.down && !pointerState.moved) {
updatePointerCoordinates(event);
if (activeTool) {
tryPlaceEvent();
} else {
const selectedEvent = findEventFromPointer();
if (selectedEvent) {
showToast(
selectedEvent.routeConflict
? `${selectedEvent.name}: through-route conflict`
: selectedEvent.accessConflict
? `${selectedEvent.name}: access pinch`
: `${selectedEvent.name}: no direct conflict`
);
}
}
}
pointerState.down = false;
updateGhost(event);
});
canvas.addEventListener("pointerleave", () => {
if (ghost) ghost.visible = false;
});
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (event.deltaY > 0 ? 0.91 : 1.1),
0.65,
1.8
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Camera presets and responsive projection
// -------------------------------------------------------------------------
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const frustumHeight = Math.max(29, 42 / aspect) / cameraState.zoom;
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateProjectionMatrix();
}
function setView(view) {
if (view === "plan") {
cameraState.phi = 0.09;
cameraState.theta = 0;
cameraState.zoom = 1;
} else {
cameraState.phi = 0.86;
cameraState.theta = 0.63;
cameraState.zoom = 1;
}
cameraState.target.set(0, 0, 0);
updateCamera();
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === view);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
document.querySelector("#resetButton").addEventListener("click", () => {
setView("iso");
});
function onResize() {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
updateCamera();
}
window.addEventListener("resize", onResize);
// -------------------------------------------------------------------------
// Initial scenario and animation
// -------------------------------------------------------------------------
// A small sample makes the conflict and access comparison visible immediately.
addEvent("market", 0, 1.5, 0, "Saturday market");
addEvent("bike", 10, 3.2, 0, "Bike workshop");
updateAnalysis();
updateCamera();
renderer.setAnimationLoop((time) => {
const pulse = 0.21 + Math.sin(time * 0.004) * 0.07;
events.forEach((event) => {
if (event.routeMarker.visible) {
event.routeMarker.material.opacity = pulse + 0.08;
}
if (event.accessMarker.visible) {
event.accessMarker.material.opacity = pulse + 0.05;
}
});
if (ghost && ghost.visible) {
ghost.position.y = 0.3 + Math.sin(time * 0.003) * 0.025;
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```