Prompt specification
Build or customize the Three.js 3D scene "Connect a waterfront event to nearby streets" 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: Connect a waterfront event to nearby streets
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/connect-a-waterfront-event-to-nearby-streets-x2764
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Montréal's Old Port. Let users place a fictional event zone on the modeled pier. Trace entrances, service deliveries, and public through-routes, showing where shared space becomes constrained. Low-poly.
Working Three.js Starter (connect-a-waterfront-event-to-nearby-streets-x2764):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Montréal Old Port — Shared Space Study</title>
<style>
:root {
--ink: #f4f8f6;
--muted: #9eb3b7;
--panel: rgba(13, 29, 36, 0.91);
--line: rgba(255, 255, 255, 0.12);
--public: #32c9b5;
--service: #ff7a55;
--entrance: #f4c453;
--event: #a98be8;
--conflict: #ff416c;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e6e6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
outline: none;
}
#scene:active { cursor: grabbing; }
#scene.placing { cursor: crosshair; }
#labelLayer {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 2;
}
.world-label {
position: absolute;
left: 0;
top: 0;
white-space: nowrap;
transform: translate(-50%, -50%);
border: 1px solid rgba(255,255,255,.22);
border-radius: 999px;
padding: 5px 9px;
color: white;
background: rgba(17, 36, 43, .78);
box-shadow: 0 4px 18px rgba(0,0,0,.14);
font-size: 10px;
font-weight: 750;
letter-spacing: .055em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.world-label.landmark {
color: #173039;
background: rgba(247, 250, 245, .86);
border-color: rgba(23,48,57,.12);
font-size: 9px;
}
.world-label.route-label {
font-size: 9px;
padding: 4px 8px;
}
.world-label.route-label.public { border-color: var(--public); }
.world-label.route-label.service { border-color: var(--service); }
.world-label.route-label.entrance { border-color: var(--entrance); }
.world-label.event-label {
color: #251b3b;
background: rgba(236, 222, 255, .94);
border-color: rgba(119, 78, 192, .5);
box-shadow: 0 6px 22px rgba(61, 35, 101, .2);
}
.world-label.conflict-label {
color: white;
background: rgba(225, 33, 79, .94);
border-color: rgba(255,255,255,.65);
font-size: 9px;
}
#panel {
position: fixed;
z-index: 5;
left: 18px;
top: 18px;
width: min(326px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(11, 25, 31, .27);
backdrop-filter: blur(18px) saturate(120%);
scrollbar-width: thin;
}
.eyebrow {
color: #79d7c8;
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 7px;
font-size: 25px;
line-height: 1.05;
letter-spacing: -.035em;
}
.intro {
margin: 0 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.section {
padding-top: 14px;
margin-top: 14px;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: .09em;
text-transform: uppercase;
}
.section-title span:last-child {
color: var(--muted);
font-size: 9px;
letter-spacing: .05em;
}
.field { margin: 10px 0; }
.field label {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: #c9d7d8;
font-size: 11px;
}
.field output {
color: white;
font-variant-numeric: tabular-nums;
}
input[type="text"] {
width: 100%;
border: 1px solid var(--line);
border-radius: 9px;
padding: 9px 10px;
color: white;
background: rgba(255,255,255,.055);
outline: none;
}
input[type="text"]:focus {
border-color: var(--event);
box-shadow: 0 0 0 3px rgba(169,139,232,.12);
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 3px 0;
accent-color: var(--event);
cursor: pointer;
}
.button-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 10px;
}
button {
border: 1px solid var(--line);
border-radius: 9px;
padding: 9px 11px;
color: white;
background: rgba(255,255,255,.07);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: background .16s, border-color .16s, transform .16s;
}
button:hover {
background: rgba(255,255,255,.13);
border-color: rgba(255,255,255,.24);
}
button:active { transform: translateY(1px); }
button.primary {
color: #251b3b;
border-color: transparent;
background: #c8b4f5;
}
button.primary:hover { background: #d8c8fa; }
button.active {
color: #251b3b;
border-color: #c8b4f5;
background: #c8b4f5;
}
.route-toggle {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 9px;
padding: 8px 0;
cursor: pointer;
font-size: 11px;
}
.route-toggle input {
width: 13px;
height: 13px;
margin: 0;
accent-color: currentColor;
}
.route-toggle small {
color: #849a9f;
font-size: 9px;
}
.route-toggle.public { color: var(--public); }
.route-toggle.service { color: var(--service); }
.route-toggle.entrance { color: var(--entrance); }
.route-toggle .name { color: #d9e4e5; }
.metric-card {
display: grid;
grid-template-columns: 1fr auto;
align-items: end;
gap: 8px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.045);
}
.metric-card strong {
display: block;
font-size: 20px;
letter-spacing: -.03em;
}
.metric-card small {
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.metric-number {
color: #7be0d1;
font-size: 28px;
font-weight: 800;
line-height: 1;
}
.pressure-track {
height: 5px;
margin-top: 10px;
overflow: hidden;
border-radius: 99px;
background: rgba(255,255,255,.09);
}
#pressureFill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--conflict);
transition: width .2s, background .2s;
}
.note {
margin: 10px 0 0;
color: #8fa4a8;
font-size: 10px;
line-height: 1.45;
}
#interactionHint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 18px;
max-width: calc(100vw - 36px);
transform: translateX(-50%);
padding: 9px 14px;
border: 1px solid rgba(255,255,255,.22);
border-radius: 999px;
color: #eef5f3;
background: rgba(17,36,43,.78);
box-shadow: 0 10px 30px rgba(0,0,0,.16);
backdrop-filter: blur(10px);
font-size: 10px;
text-align: center;
pointer-events: none;
}
#toast {
position: fixed;
z-index: 8;
left: 50%;
top: 20px;
transform: translate(-50%, -12px);
padding: 9px 14px;
border-radius: 999px;
color: #142b32;
background: #dff8f2;
box-shadow: 0 10px 35px rgba(0,0,0,.18);
font-size: 11px;
font-weight: 750;
opacity: 0;
pointer-events: none;
transition: opacity .2s, transform .2s;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#cameraTools {
position: fixed;
z-index: 4;
top: 18px;
right: 18px;
display: flex;
gap: 6px;
}
#cameraTools button {
width: 36px;
height: 36px;
padding: 0;
border-color: rgba(255,255,255,.28);
color: white;
background: rgba(17,36,43,.78);
box-shadow: 0 8px 24px rgba(0,0,0,.12);
backdrop-filter: blur(10px);
font-size: 17px;
}
#north {
position: fixed;
z-index: 4;
top: 66px;
right: 21px;
width: 30px;
height: 30px;
display: grid;
place-items: center;
border-radius: 50%;
color: #19353d;
background: rgba(247,250,245,.8);
font-size: 9px;
font-weight: 850;
pointer-events: none;
}
#north::after {
content: "";
position: absolute;
top: 3px;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 6px solid #e65368;
}
@media (max-width: 700px) {
#panel {
left: 10px;
top: auto;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 48vh;
padding: 14px;
}
h1 { font-size: 21px; }
.intro { margin-bottom: 10px; }
#interactionHint { display: none; }
#cameraTools { top: 10px; right: 10px; }
#north { top: 58px; right: 13px; }
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive low-poly model of Montréal's Old Port"></canvas>
<div id="labelLayer"></div>
<aside id="panel">
<div class="eyebrow">Shared-space field study · 04</div>
<h1>Montréal · Vieux-Port</h1>
<p class="intro">
Place a fictional event footprint on the pier, then inspect how access,
deliveries, and public movement compete for the same deck.
</p>
<div class="section-title">
<span>Fictional event</span>
<span id="zoneDimensions">10 × 10 m</span>
</div>
<div class="field">
<label for="eventName">Event label</label>
<input id="eventName" type="text" value="Harbour Sessions" maxlength="40">
</div>
<div class="field">
<label for="zoneWidth">Zone width <output id="widthValue">10 m</output></label>
<input id="zoneWidth" type="range" min="4" max="14" step="1" value="10">
</div>
<div class="field">
<label for="zoneDepth">Zone depth <output id="depthValue">10 m</output></label>
<input id="zoneDepth" type="range" min="4" max="12" step="1" value="10">
</div>
<div class="field">
<label for="zoneRotation">Rotation <output id="rotationValue">0°</output></label>
<input id="zoneRotation" type="range" min="0" max="180" step="15" value="0">
</div>
<div class="button-row">
<button id="placeButton" class="primary">Relocate event zone</button>
<button id="clearButton" title="Clear event zone">Clear</button>
</div>
<div class="section">
<div class="section-title"><span>Mobility traces</span><span>Toggle visibility</span></div>
<label class="route-toggle entrance">
<input type="checkbox" data-route="entrance" checked>
<span class="name">Entrances & access</span>
<small>2</small>
</label>
<label class="route-toggle service">
<input type="checkbox" data-route="service" checked>
<span class="name">Service deliveries</span>
<small>1</small>
</label>
<label class="route-toggle public">
<input type="checkbox" data-route="public" checked>
<span class="name">Public through-routes</span>
<small>2</small>
</label>
</div>
<div class="section">
<div class="metric-card">
<div>
<strong id="metricTitle">Checking shared space</strong>
<small id="metricDetail">Red segments identify route conflicts.</small>
</div>
<div id="metricNumber" class="metric-number">0</div>
</div>
<div class="pressure-track"><div id="pressureFill"></div></div>
<p class="note">
Expand or rotate the event footprint to test how much circulation width
remains. A red pulse marks a constrained shared-space crossing.
</p>
</div>
</aside>
<div id="cameraTools" aria-label="Camera controls">
<button id="zoomIn" title="Zoom in">+</button>
<button id="zoomOut" title="Zoom out">−</button>
<button id="resetView" title="Reset camera">⌂</button>
</div>
<div id="north" title="North"></div>
<div id="interactionHint">
Drag the zone to move it · Drag the scene to orbit · Right-drag to pan · Scroll to zoom
</div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = id => document.getElementById(id);
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
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.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e7);
scene.fog = new THREE.Fog(0xdce8e7, 105, 205);
const camera = new THREE.PerspectiveCamera(
42, window.innerWidth / window.innerHeight, 0.1, 300
);
const world = new THREE.Group();
const routeRoot = new THREE.Group();
const conflictRoot = new THREE.Group();
scene.add(world, routeRoot, conflictRoot);
const hemi = new THREE.HemisphereLight(0xe8f6f2, 0x49626a, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d3, 3.2);
sun.position.set(-34, 62, 38);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -78;
sun.shadow.camera.right = 78;
sun.shadow.camera.top = 78;
sun.shadow.camera.bottom = -78;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 170;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const palette = {
concrete: new THREE.MeshStandardMaterial({
color: 0xb4b4aa, roughness: 0.95, flatShading: true
}),
concreteDark: new THREE.MeshStandardMaterial({
color: 0x747e7b, roughness: 0.96, flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x9b7650, roughness: 0.92, flatShading: true
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x59483b, roughness: 0.95, flatShading: true
}),
brick: new THREE.MeshStandardMaterial({
color: 0xa5523e, roughness: 0.94, flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xe2d5b4, roughness: 0.9, flatShading: true
}),
roof: new THREE.MeshStandardMaterial({
color: 0x3c5157, roughness: 0.85, flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x25363c, roughness: 0.8, flatShading: true
}),
glass: new THREE.MeshStandardMaterial({
color: 0x345d69, roughness: 0.3, metalness: 0.12, flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x718285, roughness: 0.58, metalness: 0.35, flatShading: true
}),
greenery: new THREE.MeshStandardMaterial({
color: 0x527b5e, roughness: 1, flatShading: true
}),
orange: new THREE.MeshStandardMaterial({
color: 0xe86f42, roughness: 0.8, flatShading: true
}),
white: new THREE.MeshStandardMaterial({
color: 0xf1eee2, roughness: 0.82, flatShading: true
})
};
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 6);
const unitCone = new THREE.ConeGeometry(1, 1, 6);
const unitSphere = new THREE.IcosahedronGeometry(1, 0);
const yAxis = new THREE.Vector3(0, 1, 0);
function box(parent, w, h, d, x, y, z, material, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, material, radialSegments = 6) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, radialSegments),
material
);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
mesh.scale.y = length;
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function coneBetween(parent, a, b, radius, height, material) {
const mesh = new THREE.Mesh(unitCone, material);
const direction = new THREE.Vector3().subVectors(b, a).normalize();
mesh.position.copy(a).lerp(b, 0.72);
mesh.quaternion.setFromUnitVectors(yAxis, direction);
mesh.scale.set(radius, height, radius);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
// Low-poly water.
const waterGeometry = new THREE.PlaneGeometry(210, 210, 28, 28);
const waterPositions = waterGeometry.attributes.position;
const waterColors = [];
const waterColor = new THREE.Color();
for (let i = 0; i < waterPositions.count; i++) {
const x = waterPositions.getX(i);
const y = waterPositions.getY(i);
const wave =
Math.sin(x * 0.31) * 0.10 +
Math.sin(y * 0.24 + x * 0.07) * 0.08 +
Math.cos((x + y) * 0.16) * 0.05;
waterPositions.setZ(i, wave);
const variation = Math.sin(x * 0.13 + y * 0.19) * 0.05;
waterColor.setHSL(0.53, 0.25, 0.43 + variation);
waterColors.push(waterColor.r, waterColor.g, waterColor.b);
}
waterGeometry.setAttribute(
"color", new THREE.Float32BufferAttribute(waterColors, 3)
);
waterGeometry.computeVertexNormals();
const waterMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.42,
metalness: 0.12,
flatShading: true
});
const water = new THREE.Mesh(waterGeometry, waterMaterial);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.62;
water.receiveShadow = true;
world.add(water);
// Quayside land and the long wooden pier.
box(world, 132, 2.5, 38, 0, -0.88, -28, palette.concrete);
box(world, 132, 0.16, 1.1, 0, 0.42, -9.35, palette.concreteDark, false);
const deck = new THREE.Mesh(
new THREE.BoxGeometry(18, 1.2, 55),
palette.woodDark
);
deck.position.set(0, 0.04, 18.5);
deck.castShadow = true;
deck.receiveShadow = true;
world.add(deck);
const plankGeometry = new THREE.BoxGeometry(17.65, 0.09, 0.88);
for (let z = -8.55; z < 46; z += 1.04) {
const plank = new THREE.Mesh(plankGeometry, palette.wood);
plank.position.set(0, 0.685, z);
plank.receiveShadow = true;
world.add(plank);
}
// Edge beams and mooring bollards.
box(world, 0.36, 0.8, 55, -8.8, 0.36, 18.5, palette.woodDark);
box(world, 0.36, 0.8, 55, 8.8, 0.36, 18.5, palette.woodDark);
const bollardGeometry = new THREE.CylinderGeometry(0.25, 0.34, 0.72, 8);
for (let z = -6; z <= 43; z += 7) {
for (const x of [-8.25, 8.25]) {
const bollard = new THREE.Mesh(bollardGeometry, palette.dark);
bollard.position.set(x, 1.02, z);
bollard.castShadow = true;
world.add(bollard);
}
}
// Quayside warehouses.
function makeWarehouse(x, z, width, depth, height, brickMaterial) {
const group = new THREE.Group();
group.position.set(x, 0.5, z);
world.add(group);
box(group, width, height, depth, 0, height / 2, 0, brickMaterial);
const shape = new THREE.Shape();
shape.moveTo(-width / 2 - 0.45, 0);
shape.lineTo(0, 2.15);
shape.lineTo(width / 2 + 0.45, 0);
shape.closePath();
const roofGeometry = new THREE.ExtrudeGeometry(shape, {
depth: depth + 0.7,
bevelEnabled: false,
steps: 1
});
roofGeometry.translate(0, 0, -(depth + 0.7) / 2);
const roof = new THREE.Mesh(roofGeometry, palette.roof);
roof.position.y = height;
roof.castShadow = true;
group.add(roof);
const windowMaterial = palette.glass;
const windowCount = Math.max(3, Math.floor(width / 3.1));
for (let i = 0; i < windowCount; i++) {
const wx = -width / 2 + (i + 0.5) * width / windowCount;
box(
group, 1.65, 1.7, 0.08, wx, height * 0.57,
depth / 2 + 0.05, windowMaterial, false
);
box(
group, 0.09, 1.78, 0.12, wx, height * 0.57,
depth / 2 + 0.11, palette.cream, false
);
}
for (let i = 0; i < Math.floor(width / 5); i++) {
box(
group, 0.22, height, 0.12,
-width / 2 + i * 5, height / 2,
depth / 2 + 0.12, palette.cream, false
);
}
box(
group, 2.4, 3.2, 0.16, width * 0.32, 1.6,
depth / 2 + 0.12, palette.dark, false
);
}
makeWarehouse(-30, -27, 23, 12, 6.5, palette.brick);
makeWarehouse(-4, -29, 20, 13, 7.2, palette.cream);
makeWarehouse(18, -29, 19, 12, 6.2, palette.brick);
makeWarehouse(48, -31, 22, 14, 8.2, palette.cream);
// Montréal Clock Tower landmark.
const clockTower = new THREE.Group();
clockTower.position.set(-12.5, 0.45, -14.8);
world.add(clockTower);
box(clockTower, 6.2, 0.7, 6.2, 0, 0.35, 0, palette.concreteDark);
box(clockTower, 4.4, 12.5, 4.4, 0, 6.7, 0, palette.cream);
for (const y of [3.3, 6.1, 8.9]) {
box(clockTower, 4.65, 0.28, 4.65, 0, y, 0, palette.concrete);
}
const clockFace = new THREE.Mesh(
new THREE.CircleGeometry(1.22, 16),
palette.white
);
clockFace.position.set(0, 10.15, 2.23);
clockTower.add(clockFace);
const clockRing = new THREE.Mesh(
new THREE.TorusGeometry(1.22, 0.1, 6, 20),
palette.dark
);
clockRing.position.copy(clockFace.position);
clockTower.add(clockRing);
const handMaterial = new THREE.MeshBasicMaterial({ color: 0x25363c });
const handA = new THREE.Mesh(unitCylinder, handMaterial);
handA.scale.set(0.045, 0.78, 0.045);
handA.position.set(-0.16, 10.35, 2.35);
handA.rotation.z = -0.65;
clockTower.add(handA);
const handB = new THREE.Mesh(unitCylinder, handMaterial);
handB.scale.set(0.045, 0.98, 0.045);
handB.position.set(0.31, 10.03, 2.35);
handB.rotation.z = 1.02;
clockTower.add(handB);
const towerRoof = new THREE.Mesh(
new THREE.ConeGeometry(3.5, 4.1, 4),
palette.roof
);
towerRoof.position.y = 15;
towerRoof.rotation.y = Math.PI / 4;
towerRoof.castShadow = true;
clockTower.add(towerRoof);
const spire = new THREE.Mesh(
new THREE.ConeGeometry(0.22, 2.5, 6),
palette.dark
);
spire.position.y = 18;
clockTower.add(spire);
// Low-poly Ferris wheel behind the quay.
const wheel = new THREE.Group();
wheel.position.set(33, 0.5, -29);
world.add(wheel);
const wheelRing = new THREE.Mesh(
new THREE.TorusGeometry(9, 0.22, 6, 32),
palette.white
);
wheelRing.position.y = 13;
wheelRing.castShadow = true;
wheel.add(wheelRing);
const innerRing = new THREE.Mesh(
new THREE.TorusGeometry(7.7, 0.12, 5, 28),
palette.metal
);
innerRing.position.y = 13;
wheel.add(innerRing);
for (let i = 0; i < 12; i++) {
const angle = i / 12 * Math.PI * 2;
const a = new THREE.Vector3(0, 13, 0);
const b = new THREE.Vector3(
Math.cos(angle) * 9,
13 + Math.sin(angle) * 9,
0
);
cylinderBetween(wheel, a, b, 0.08, palette.metal, 5);
const cabin = new THREE.Group();
cabin.position.copy(b);
box(cabin, 1.15, 0.9, 0.9, 0, -0.55, 0, i % 2 ? palette.orange : palette.cream);
wheel.add(cabin);
}
for (const x of [-4.5, 4.5]) {
cylinderBetween(
wheel,
new THREE.Vector3(x, 0.5, 0),
new THREE.Vector3(x, 13, 0),
0.35, palette.metal, 6
);
}
// Distant skyline.
const skylineMaterial = new THREE.MeshStandardMaterial({
color: 0x9aa9a7, roughness: 1, flatShading: true
});
for (let i = 0; i < 18; i++) {
const height = 4 + ((i * 7) % 13);
const width = 4 + (i % 4) * 1.7;
box(
world, width, height, 5,
-58 + i * 7, height / 2 - 0.3, -58 - (i % 3) * 3,
skylineMaterial, false
);
}
// Trees, lamps, service crates, and a low-poly boat.
const treeTrunkMaterial = palette.woodDark;
for (const [x, z] of [[-42,-14], [-39,-14], [27,-14], [31,-14], [53,-15]]) {
cylinderBetween(
world,
new THREE.Vector3(x, 0.5, z),
new THREE.Vector3(x, 3.1, z),
0.22, treeTrunkMaterial, 6
);
const crown = new THREE.Mesh(unitSphere, palette.greenery);
crown.scale.set(1.8, 2.4, 1.8);
crown.position.set(x, 4.1, z);
crown.castShadow = true;
world.add(crown);
}
for (const x of [-19, -1, 18, 49]) {
cylinderBetween(
world,
new THREE.Vector3(x, 0.5, -10.6),
new THREE.Vector3(x, 5.3, -10.6),
0.09, palette.dark, 6
);
box(world, 0.7, 0.15, 0.7, x, 5.3, -10.6, palette.cream);
}
const crateMaterial = new THREE.MeshStandardMaterial({
color: 0xc17a43, roughness: 0.95, flatShading: true
});
box(world, 1.8, 1.4, 1.8, 7.7, 1.35, 33, crateMaterial);
box(world, 1.4, 1.0, 1.4, 7.5, 2.5, 33, palette.cream);
const boat = new THREE.Group();
boat.position.set(14.5, -0.2, 33);
boat.rotation.y = -0.22;
world.add(boat);
const hull = new THREE.Mesh(
new THREE.BoxGeometry(2.8, 0.8, 6.7),
palette.dark
);
hull.position.y = 0.45;
hull.castShadow = true;
boat.add(hull);
const bow = new THREE.Mesh(new THREE.ConeGeometry(1.4, 2.6, 4), palette.dark);
bow.rotation.x = Math.PI / 2;
bow.rotation.z = Math.PI / 4;
bow.position.set(0, 0.45, 4.25);
boat.add(bow);
box(boat, 2.15, 1.2, 2.3, 0, 1.25, -0.6, palette.white);
box(boat, 1.8, 0.55, 0.08, 0, 1.42, 0.58, palette.glass, false);
// Route definitions in the XZ plane.
const routeDefinitions = [
{
id: "main-entrance",
category: "entrance",
name: "Main entrance",
points: [[-1, -8.5], [-1, 1.5]],
label: [-1, 1.5]
},
{
id: "west-entrance",
category: "entrance",
name: "West entrance",
points: [[-7, -8.5], [-7, -0.5]],
label: [-7, -0.5]
},
{
id: "service-route",
category: "service",
name: "Service delivery",
points: [[7.6, -8.5], [7.6, 29.5], [5.7, 35]],
label: [7.6, 22]
},
{
id: "public-promenade",
category: "public",
name: "Public promenade",
points: [[-5.5, -8.5], [-5.5, 10], [-4.2, 28], [-4.2, 44]],
label: [-4.8, 28]
},
{
id: "public-crossing",
category: "public",
name: "Public crossing",
points: [[-8.7, 12.8], [8.7, 12.8]],
label: [3.8, 12.8]
}
].map(route => ({
...route,
points: route.points.map(([x, z]) => new THREE.Vector3(x, 0.96, z))
}));
const routeColors = {
entrance: 0xf4c453,
service: 0xff7a55,
public: 0x32c9b5
};
const routeMaterials = {
entrance: new THREE.MeshStandardMaterial({
color: routeColors.entrance, roughness: 0.55, emissive: 0x6a4b00,
emissiveIntensity: 0.22, flatShading: true
}),
service: new THREE.MeshStandardMaterial({
color: routeColors.service, roughness: 0.55, emissive: 0x661b00,
emissiveIntensity: 0.2, flatShading: true
}),
public: new THREE.MeshStandardMaterial({
color: routeColors.public, roughness: 0.55, emissive: 0x004d45,
emissiveIntensity: 0.2, flatShading: true
})
};
const routeGroups = new Map();
const routeLabels = [];
const labels = [];
function makeLabel(text, className, position, visible = () => true) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.textContent = text;
$("labelLayer").appendChild(element);
const item = { element, position, visible };
labels.push(item);
return item;
}
for (const route of routeDefinitions) {
const group = new THREE.Group();
routeRoot.add(group);
routeGroups.set(route.id, group);
for (let i = 0; i < route.points.length - 1; i++) {
const a = route.points[i];
const b = route.points[i + 1];
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
if (route.category === "entrance") {
for (let d = 0; d < length; d += 1.7) {
const end = Math.min(d + 0.95, length);
const p0 = a.clone().lerp(b, d / length);
const p1 = a.clone().lerp(b, end / length);
cylinderBetween(group, p0, p1, 0.095, routeMaterials[route.category]);
}
} else {
cylinderBetween(
group, a, b,
route.category === "public" ? 0.115 : 0.095,
routeMaterials[route.category]
);
}
coneBetween(
group, a, b,
route.category === "public" ? 0.27 : 0.23,
0.82,
routeMaterials[route.category]
);
}
for (const point of route.points) {
const node = new THREE.Mesh(unitSphere, routeMaterials[route.category]);
node.scale.setScalar(0.23);
node.position.copy(point);
group.add(node);
}
const [lx, lz] = route.label;
const label = makeLabel(
route.name,
`route-label ${route.category}`,
new THREE.Vector3(lx, 1.45, lz),
() => routeVisibility[route.category]
);
routeLabels.push({ label, category: route.category });
}
// Small animated delivery van.
const van = new THREE.Group();
const vanBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xf0a13c, roughness: 0.75, flatShading: true
});
box(van, 1.55, 1.25, 2.8, 0, 0.85, -0.25, vanBodyMaterial);
box(van, 1.4, 0.75, 1.2, 0, 1.55, 0.85, palette.white);
box(van, 1.22, 0.46, 0.08, 0, 1.58, 1.48, palette.glass, false);
const wheelGeometry = new THREE.CylinderGeometry(0.32, 0.32, 0.22, 8);
for (const x of [-0.77, 0.77]) {
for (const z of [-0.9, 1.0]) {
const wheel = new THREE.Mesh(wheelGeometry, palette.dark);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.36, z);
van.add(wheel);
}
}
world.add(van);
function samplePolyline(points, t) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
let distance = ((t % 1) + 1) % 1 * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i]) {
const localT = distance / lengths[i];
return {
position: points[i].clone().lerp(points[i + 1], localT),
tangent: points[i + 1].clone().sub(points[i]).normalize()
};
}
distance -= lengths[i];
}
return {
position: points.at(-1).clone(),
tangent: points.at(-1).clone().sub(points.at(-2)).normalize()
};
}
// A few tiny pedestrians make the public traces legible.
const walkers = [];
const walkerColors = [0xe95f55, 0xf0c44f, 0x5cb9c6, 0xe08db2];
for (let i = 0; i < 4; i++) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: walkerColors[i], roughness: 0.85, flatShading: true
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.2, 0.65, 5),
bodyMaterial
);
body.position.y = 0.48;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(unitSphere, palette.cream);
head.scale.setScalar(0.2);
head.position.y = 0.93;
group.add(head);
world.add(group);
walkers.push(group);
}
// Event-zone object.
const zoneGroup = new THREE.Group();
zoneGroup.position.set(0, 0.66, 17.5);
world.add(zoneGroup);
const zoneFillMaterial = new THREE.MeshStandardMaterial({
color: 0xa98be8,
transparent: true,
opacity: 0.34,
roughness: 0.5,
depthWrite: false,
side: THREE.DoubleSide
});
const zoneFill = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.14, 1),
zoneFillMaterial
);
zoneFill.position.y = 0.1;
zoneFill.renderOrder = 2;
zoneGroup.add(zoneFill);
const zoneBorder = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(1, 0.15, 1)),
new THREE.LineBasicMaterial({ color: 0xd8c7ff })
);
zoneBorder.position.y = 0.1;
zoneGroup.add(zoneBorder);
const zoneHit = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.55, 1),
new THREE.MeshBasicMaterial({
transparent: true, opacity: 0, depthWrite: false
})
);
zoneHit.position.y = 0.3;
zoneGroup.add(zoneHit);
const zonePosts = [];
for (let i = 0; i < 4; i++) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.13, 0.72, 6),
new THREE.MeshStandardMaterial({
color: 0xd6c3fa, roughness: 0.7, flatShading: true
})
);
zonePosts.push(post);
zoneGroup.add(post);
}
const zoneAnchor = new THREE.Vector3();
const zoneLabel = makeLabel(
"Harbour Sessions",
"event-label",
zoneAnchor,
() => zoneState.active
);
makeLabel(
"Quai de l'Est",
"landmark",
new THREE.Vector3(19, 1.5, -10)
);
makeLabel(
"Clock Tower",
"landmark",
new THREE.Vector3(-12.5, 18, -14.8)
);
makeLabel(
"Old Port Ferris Wheel",
"landmark",
new THREE.Vector3(33, 24, -29)
);
// Zone state.
const zoneState = {
active: true,
x: 0,
z: 17.5,
width: 10,
depth: 10,
rotation: 0,
placementMode: false
};
function zoneHalfExtents() {
const c = Math.abs(Math.cos(zoneState.rotation));
const s = Math.abs(Math.sin(zoneState.rotation));
return {
x: c * zoneState.width / 2 + s * zoneState.depth / 2,
z: s * zoneState.width / 2 + c * zoneState.depth / 2
};
}
function clampZonePosition() {
const extents = zoneHalfExtents();
const minX = -8.65 + extents.x;
const maxX = 8.65 - extents.x;
const minZ = -8.6 + extents.z;
const maxZ = 45 - extents.z;
zoneState.x = THREE.MathUtils.clamp(zoneState.x, minX, Math.max(minX, maxX));
zoneState.z = THREE.MathUtils.clamp(zoneState.z, minZ, Math.max(minZ, maxZ));
}
function updateZoneGeometry() {
const { width, depth, rotation } = zoneState;
zoneGroup.position.set(zoneState.x, 0.66, zoneState.z);
zoneGroup.rotation.y = rotation;
zoneFill.scale.set(width, 1, depth);
zoneBorder.scale.set(width, 1, depth);
zoneHit.scale.set(width, 1, depth);
const corners = [
[-width / 2, -depth / 2],
[ width / 2, -depth / 2],
[ width / 2, depth / 2],
[-width / 2, depth / 2]
];
zonePosts.forEach((post, index) => {
post.position.set(corners[index][0], 0.36, corners[index][1]);
});
zoneAnchor.set(zoneState.x, 2.6, zoneState.z);
zoneLabel.element.textContent = $("eventName").value.trim() || "Fictional event";
$("zoneDimensions").textContent = `${width} × ${depth} m`;
}
// Convert world points into the event zone's local coordinates.
function worldToZone(point) {
const dx = point.x - zoneState.x;
const dz = point.z - zoneState.z;
const c = Math.cos(zoneState.rotation);
const s = Math.sin(zoneState.rotation);
return new THREE.Vector2(
c * dx - s * dz,
s * dx + c * dz
);
}
function zoneToWorld(point) {
const c = Math.cos(zoneState.rotation);
const s = Math.sin(zoneState.rotation);
return new THREE.Vector3(
zoneState.x + c * point.x + s * point.y,
0.96,
zoneState.z - s * point.x + c * point.y
);
}
// Liang–Barsky clipping of a line segment against the rotated zone.
function clipSegmentToZone(a, b) {
const p = worldToZone(a);
const q = worldToZone(b);
const dx = q.x - p.x;
const dy = q.y - p.y;
let t0 = 0;
let t1 = 1;
const halfWidth = zoneState.width / 2;
const halfDepth = zoneState.depth / 2;
const epsilon = 1e-7;
const clips = [
[-dx, p.x + halfWidth],
[ dx, halfWidth - p.x],
[-dy, p.y + halfDepth],
[ dy, halfDepth - p.y]
];
for (const [num, den] of clips) {
if (Math.abs(num) < epsilon) {
if (den < 0) return null;
continue;
}
const t = den / num;
if (num < 0) {
if (t > t1) return null;
if (t > t0) t0 = t;
} else {
if (t < t0) return null;
if (t < t1) t1 = t;
}
}
if (t1 - t0 < 0.002) return null;
return {
start: zoneToWorld(new THREE.Vector2(
p.x + t0 * dx, p.y + t0 * dy
)),
end: zoneToWorld(new THREE.Vector2(
p.x + t1 * dx, p.y + t1 * dy
))
};
}
const conflictMaterial = new THREE.MeshStandardMaterial({
color: 0xff416c,
emissive: 0x9d0d35,
emissiveIntensity: 0.5,
roughness: 0.5,
flatShading: true
});
const conflictRingGeometry = new THREE.TorusGeometry(0.72, 0.09, 6, 22);
let conflictLabels = [];
function clearConflicts() {
while (conflictRoot.children.length) {
conflictRoot.remove(conflictRoot.children[0]);
}
for (const item of conflictLabels) {
item.element.remove();
labels.splice(labels.indexOf(item), 1);
}
conflictLabels = [];
}
function updateConflicts() {
clearConflicts();
if (!zoneState.active) {
$("metricTitle").textContent = "Awaiting placement";
$("metricDetail").textContent = "Place a footprint to test the pier.";
$("metricNumber").textContent = "—";
$("pressureFill").style.width = "0%";
return;
}
const constrainedRoutes = new Set();
let crossingCount = 0;
for (const route of routeDefinitions) {
if (!routeVisibility[route.category]) continue;
let firstConflict = true;
for (let i = 0; i < route.points.length - 1; i++) {
const clipped = clipSegmentToZone(route.points[i], route.points[i + 1]);
if (!clipped) continue;
crossingCount++;
constrainedRoutes.add(route.id);
const conflictLine = cylinderBetween(
conflictRoot,
clipped.start,
clipped.end,
0.19,
conflictMaterial,
8
);
conflictLine.castShadow = false;
const midpoint = clipped.start.clone().lerp(clipped.end, 0.5);
const ring = new THREE.Mesh(conflictRingGeometry, conflictMaterial);
ring.rotation.x = Math.PI / 2;
ring.position.set(midpoint.x, 1.06, midpoint.z);
ring.userData.pulse = true;
conflictRoot.add(ring);
if (firstConflict) {
const anchor = new THREE.Vector3(midpoint.x, 2.45, midpoint.z);
const label = makeLabel(
"Shared-space pinch",
"conflict-label",
anchor
);
conflictLabels.push(label);
firstConflict = false;
}
}
}
const count = constrainedRoutes.size;
$("metricTitle").textContent = count
? "Shared space constrained"
: "Routes remain clear";
$("metricDetail").textContent = count
? `${count} route${count === 1 ? "" : "s"} · ${crossingCount} crossing segment${crossingCount === 1 ? "" : "s"}`
: "No visible route intersects the event footprint.";
$("metricNumber").textContent = count;
$("metricNumber").style.color = count ? "#ff6f8e" : "#7be0d1";
const pressure = Math.min(100, crossingCount * 22 + count * 13);
$("pressureFill").style.width = `${pressure}%`;
$("pressureFill").style.background = pressure > 65 ? "#ff416c" : "#f4c453";
}
// Custom camera controls: orbit, pan, and zoom without add-ons.
const cameraState = {
target: new THREE.Vector3(0, 0, 10),
radius: 84,
theta: 0.70,
phi: 0.94
};
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.set(0, 0, 10);
cameraState.radius = 84;
cameraState.theta = 0.70;
cameraState.phi = 0.94;
updateCamera();
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.66);
const planePoint = new THREE.Vector3();
let pointerState = null;
let dragOffset = new THREE.Vector2();
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function pickDeck(event) {
setPointer(event);
const hits = raycaster.intersectObject(deck, false);
if (!hits.length) return null;
const point = hits[0].point;
if (Math.abs(point.x) > 8.8 || point.z < -8.8 || point.z > 45.2) return null;
return point;
}
function showToast(message) {
const toast = $("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(showToast.timeout);
showToast.timeout = setTimeout(() => toast.classList.remove("show"), 1800);
}
function enterPlacementMode() {
zoneState.placementMode = true;
canvas.classList.add("placing");
$("placeButton").classList.add("active");
$("placeButton").textContent = "Click the pier…";
$("interactionHint").textContent =
"Click a location on the pier to place the event zone · Esc to cancel";
}
function exitPlacementMode() {
zoneState.placementMode = false;
canvas.classList.remove("placing");
$("placeButton").classList.remove("active");
$("placeButton").textContent = zoneState.active ? "Relocate event zone" : "Place event zone";
$("interactionHint").textContent =
"Drag the zone to move it · Drag the scene to orbit · Right-drag to pan · Scroll to zoom";
}
canvas.addEventListener("pointerdown", event => {
canvas.focus();
canvas.setPointerCapture(event.pointerId);
setPointer(event);
if (event.button === 0 && zoneState.placementMode) {
const point = pickDeck(event);
if (!point) {
showToast("Choose a location on the pier itself.");
return;
}
zoneState.active = true;
zoneState.x = point.x;
zoneState.z = point.z;
zoneGroup.visible = true;
updateZoneGeometry();
updateConflicts();
exitPlacementMode();
showToast("Event zone placed. Drag it to refine the footprint.");
return;
}
pointerState = {
button: event.button,
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false,
mode: "orbit"
};
if (event.button === 0 && zoneState.active && zoneGroup.visible) {
const hit = raycaster.intersectObject(zoneHit, false);
if (hit.length && raycaster.ray.intersectPlane(dragPlane, planePoint)) {
pointerState.mode = "zone";
dragOffset.set(zoneState.x - planePoint.x, zoneState.z - planePoint.z);
canvas.style.cursor = "grabbing";
}
}
if (event.button === 2 || event.shiftKey) {
pointerState.mode = "pan";
}
});
canvas.addEventListener("pointermove", event => {
if (!pointerState) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
if (Math.abs(event.clientX - pointerState.x) + Math.abs(event.clientY - pointerState.y) > 3) {
pointerState.moved = true;
}
if (pointerState.mode === "zone") {
setPointer(event);
if (raycaster.ray.intersectPlane(dragPlane, planePoint)) {
zoneState.x = planePoint.x + dragOffset.x;
zoneState.z = planePoint.z + dragOffset.y;
clampZonePosition();
updateZoneGeometry();
updateConflicts();
}
} else if (pointerState.mode === "orbit") {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.28,
1.40
);
updateCamera();
} else if (pointerState.mode === "pan") {
const right = new THREE.Vector3();
camera.getWorldDirection(right);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3().subVectors(cameraState.target, camera.position);
forward.y = 0;
forward.normalize();
const panScale = cameraState.radius * 0.0012;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(forward, dy * panScale);
updateCamera();
}
});
function releasePointer(event) {
pointerState = null;
canvas.style.cursor = zoneState.placementMode ? "crosshair" : "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
31,
135
);
updateCamera();
}, { passive: false });
// Route visibility.
const routeVisibility = {
entrance: true,
service: true,
public: true
};
document.querySelectorAll("[data-route]").forEach(input => {
input.addEventListener("change", () => {
const category = input.dataset.route;
routeVisibility[category] = input.checked;
for (const route of routeDefinitions) {
if (route.category === category) {
routeGroups.get(route.id).visible = input.checked;
}
}
updateConflicts();
});
});
// Event controls.
$("placeButton").addEventListener("click", enterPlacementMode);
$("clearButton").addEventListener("click", () => {
zoneState.active = false;
zoneGroup.visible = false;
updateConflicts();
$("placeButton").textContent = "Place event zone";
showToast("Event zone cleared.");
});
$("eventName").addEventListener("input", () => {
zoneLabel.element.textContent = $("eventName").value.trim() || "Fictional event";
});
$("zoneWidth").addEventListener("input", event => {
zoneState.width = Number(event.target.value);
$("widthValue").textContent = `${zoneState.width} m`;
clampZonePosition();
updateZoneGeometry();
updateConflicts();
});
$("zoneDepth").addEventListener("input", event => {
zoneState.depth = Number(event.target.value);
$("depthValue").textContent = `${zoneState.depth} m`;
clampZonePosition();
updateZoneGeometry();
updateConflicts();
});
$("zoneRotation").addEventListener("input", event => {
zoneState.rotation = THREE.MathUtils.degToRad(Number(event.target.value));
$("rotationValue").textContent = `${event.target.value}°`;
clampZonePosition();
updateZoneGeometry();
updateConflicts();
});
$("zoomIn").addEventListener("click", () => {
cameraState.radius = Math.max(31, cameraState.radius * 0.86);
updateCamera();
});
$("zoomOut").addEventListener("click", () => {
cameraState.radius = Math.min(135, cameraState.radius * 1.16);
updateCamera();
});
$("resetView").addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
if (event.key === "Escape") exitPlacementMode();
if (event.key.toLowerCase() === "r" && document.activeElement !== $("eventName")) {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
// Labels are projected directly, without an external renderer/add-on.
const projected = new THREE.Vector3();
const viewDirection = new THREE.Vector3();
const toPoint = new THREE.Vector3();
function updateLabels() {
camera.getWorldDirection(viewDirection);
for (const item of labels) {
if (!item.visible()) {
item.element.style.display = "none";
continue;
}
toPoint.copy(item.position).sub(camera.position);
if (toPoint.dot(viewDirection) <= 0) {
item.element.style.display = "none";
continue;
}
projected.copy(item.position).project(camera);
if (projected.z < -1 || projected.z > 1) {
item.element.style.display = "none";
continue;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
item.element.style.display = "block";
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const child of conflictRoot.children) {
if (child.userData.pulse) {
const pulse = 1 + Math.sin(elapsed * 4.2) * 0.12;
child.scale.setScalar(pulse);
child.rotation.z = elapsed * 0.25;
}
}
if (routeVisibility.service) {
const route = routeDefinitions.find(r => r.id === "service-route");
const sample = samplePolyline(route.points, elapsed * 0.026);
van.position.set(sample.position.x, 0.65, sample.position.z);
van.rotation.y = Math.atan2(sample.tangent.x, sample.tangent.z);
}
van.visible = routeVisibility.service;
if (routeVisibility.public) {
const promenade = routeDefinitions.find(r => r.id === "public-promenade");
const crossing = routeDefinitions.find(r => r.id === "public-crossing");
const samples = [
samplePolyline(promenade.points, elapsed * 0.017),
samplePolyline(promenade.points, elapsed * 0.017 + 0.46),
samplePolyline(crossing.points, elapsed * 0.025),
samplePolyline(crossing.points, elapsed * 0.025 + 0.51)
];
walkers.forEach((walker, index) => {
const sample = samples[index];
walker.position.set(sample.position.x, 0.73, sample.position.z);
walker.rotation.y = Math.atan2(sample.tangent.x, sample.tangent.z);
});
}
walkers.forEach(walker => {
walker.visible = routeVisibility.public;
});
updateLabels();
renderer.render(scene, camera);
}
updateZoneGeometry();
updateConflicts();
updateCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```