Prompt specification
Build or customize the Three.js 3D scene "Cyclist passing a Montréal waterfront kiosk" 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: Cyclist passing a Montréal waterfront kiosk
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cyclist-passing-a-montr-al-waterfront-kiosk-x2762
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a compact Old Port vignette with an original kiosk, cycle route, and pedestrian seating. Keep the two movement paths legible and source local background forms. Voxel style.
Working Three.js Starter (cyclist-passing-a-montr-al-waterfront-kiosk-x2762):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Old Port — Harbour Loop</title>
<style>
:root {
--ink: #18363d;
--muted: #60777a;
--paper: rgba(248, 246, 235, 0.92);
--line: rgba(24, 54, 61, 0.14);
--cycle: #35d1bd;
--walk: #ef6e61;
--accent: #f3bd55;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 3;
width: min(340px, calc(100vw - 48px));
padding: 18px 19px 16px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 4px;
box-shadow: 0 14px 40px rgba(38, 66, 68, 0.12);
backdrop-filter: blur(12px);
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #557075;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 19px;
height: 3px;
content: "";
background: var(--accent);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
display: grid;
gap: 8px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
font-size: 11px;
font-weight: 700;
}
.swatch {
width: 24px;
height: 7px;
border-radius: 1px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.cycle {
background: var(--cycle);
}
.swatch.walk {
background: var(--walk);
}
.swatch.kiosk {
width: 11px;
height: 11px;
background: var(--accent);
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 4;
display: flex;
gap: 7px;
padding: 7px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 4px;
box-shadow: 0 10px 30px rgba(38, 66, 68, 0.12);
backdrop-filter: blur(10px);
}
button {
min-width: 36px;
height: 34px;
padding: 0 11px;
border: 0;
border-radius: 2px;
background: #e7ebe4;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition:
background 140ms ease,
transform 140ms ease;
}
button:hover {
background: #d8e4dc;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.hint {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 3;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.56);
border-radius: 3px;
background: rgba(248, 246, 235, 0.72);
color: #526d71;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.025em;
backdrop-filter: blur(8px);
pointer-events: none;
}
.edition {
position: fixed;
top: 25px;
right: 25px;
z-index: 3;
color: rgba(24, 54, 61, 0.54);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
padding: 14px 15px 13px;
}
.subtitle {
display: none;
}
.legend {
grid-template-columns: 1fr 1fr;
gap: 7px 12px;
}
.legend-row:last-child {
display: none;
}
.hint {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
}
.edition {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel model of an Old Port waterfront"></main>
<section class="title-card" aria-label="Project information">
<div class="eyebrow">Old Port / Study 01</div>
<h1>Harbour<br>Loop</h1>
<p class="subtitle">
A compact waterfront vignette with a cycle circuit, pedestrian
promenade, and the locally sourced “Tide Bites” kiosk.
</p>
<div class="legend">
<div class="legend-row">
<span class="swatch cycle"></span>
<span>Cycle loop</span>
</div>
<div class="legend-row">
<span class="swatch walk"></span>
<span>Pedestrian route</span>
</div>
<div class="legend-row">
<span class="swatch kiosk"></span>
<span>Original kiosk</span>
</div>
</div>
</section>
<div class="edition">Voxel waterfront / local forms</div>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<nav class="controls" aria-label="Camera controls">
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button id="reset" type="button">Reset view</button>
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
</nav>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7e3);
scene.fog = new THREE.Fog(0xdce7e3, 36, 68);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mount.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel Old Port model. Drag to orbit, shift-drag to pan, and scroll to zoom."
);
const camera = new THREE.OrthographicCamera(-15, 15, 11, -11, 0.1, 120);
const hemisphere = new THREE.HemisphereLight(0xf7f3dc, 0x4d747a, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4b5, 3.1);
sun.position.set(-11, 21, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ed8df, 0.8);
fill.position.set(16, 9, -12);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function barBetween(parent, a, b, thickness, color) {
const direction = new THREE.Vector3().subVectors(b, a);
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(thickness, direction.length(), thickness);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let seed = 8417;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// ---------------------------------------------------------------------
// Diorama base, quay, and paving
// ---------------------------------------------------------------------
box(24.2, 0.7, 22.2, 0x35525b, 0, -1.32, 3.55);
box(22.9, 1.38, 14, 0xb8ad91, 0, -0.7, 0);
box(23.0, 0.55, 0.38, 0x7e8d83, 0, -0.42, 7.08);
box(23.0, 0.16, 0.22, 0xd6cbb0, 0, -0.08, 7.12);
const tileCountX = 22;
const tileCountZ = 14;
const paving = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
}),
tileCountX * tileCountZ
);
const dummy = new THREE.Object3D();
const pavingPalette = [0xd8cdb6, 0xe1d7c2, 0xcfc6b0, 0xded2b9];
let pavingIndex = 0;
for (let z = 0; z < tileCountZ; z++) {
for (let x = 0; x < tileCountX; x++) {
dummy.position.set(-10.5 + x, 0.015, -6.5 + z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.965, 0.035, 0.965);
dummy.updateMatrix();
paving.setMatrixAt(pavingIndex, dummy.matrix);
const tint = new THREE.Color(
pavingPalette[Math.floor(random() * pavingPalette.length)]
);
tint.offsetHSL(0, 0, (random() - 0.5) * 0.035);
paving.setColorAt(pavingIndex, tint);
pavingIndex++;
}
}
paving.receiveShadow = true;
paving.instanceMatrix.needsUpdate = true;
paving.instanceColor.needsUpdate = true;
scene.add(paving);
// Water is made from shallow square tiles to preserve the voxel language.
const waterGroup = new THREE.Group();
scene.add(waterGroup);
const waterColumns = 24;
const waterRows = 7;
const water = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.28,
metalness: 0.12
}),
waterColumns * waterRows
);
const waterPalette = [0x4c9fa8, 0x5aabb0, 0x438f9c, 0x65b5b5];
let waterIndex = 0;
for (let z = 0; z < waterRows; z++) {
for (let x = 0; x < waterColumns; x++) {
const height = 0.12 + random() * 0.09;
dummy.position.set(
-11.5 + x,
-0.38 + height * 0.5,
7.5 + z
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.97, height, 0.97);
dummy.updateMatrix();
water.setMatrixAt(waterIndex, dummy.matrix);
const tint = new THREE.Color(
waterPalette[Math.floor(random() * waterPalette.length)]
);
tint.offsetHSL(0, 0, (random() - 0.5) * 0.045);
water.setColorAt(waterIndex, tint);
waterIndex++;
}
}
water.receiveShadow = true;
water.instanceMatrix.needsUpdate = true;
water.instanceColor.needsUpdate = true;
waterGroup.add(water);
for (let i = 0; i < 13; i++) {
const ripple = box(
0.7 + random() * 1.4,
0.025,
0.08,
i % 3 === 0 ? 0xb5ddda : 0x8bc8ca,
-10 + random() * 20,
-0.26,
8 + random() * 5.2,
waterGroup
);
ripple.castShadow = false;
}
// ---------------------------------------------------------------------
// Local port forms: warehouses, townhouses, crane, containers and boats
// ---------------------------------------------------------------------
function makeBuilding({
x,
z,
width,
depth,
height,
color,
roof = 0x6c7772,
windowRows = 2
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(width, height, depth, color, 0, height / 2, 0, group);
box(width + 0.22, 0.22, depth + 0.2, roof, 0, height + 0.1, 0, group);
box(width + 0.08, 0.28, 0.18, 0xe6d7b8, 0, 0.18, depth / 2 + 0.02, group);
const columns = Math.max(2, Math.floor(width / 1.25));
const rows = windowRows;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const wx =
-width / 2 +
0.72 +
column * ((width - 1.35) / Math.max(1, columns - 1));
const wy = 1.35 + row * 1.25;
box(0.58, 0.68, 0.08, 0x395e68, wx, wy, depth / 2 + 0.055, group);
box(
0.44,
0.5,
0.09,
row === 0 && column % 2 === 0 ? 0xa7d2cf : 0x294b56,
wx,
wy,
depth / 2 + 0.105,
group
);
box(0.58, 0.08, 0.12, 0xd9c9a7, wx, wy - 0.36, depth / 2 + 0.08, group);
}
}
const doorWidth = Math.min(1.05, width * 0.25);
box(
doorWidth,
1.55,
0.1,
0x34545a,
0,
0.78,
depth / 2 + 0.06,
group
);
box(0.05, 0.05, 0.06, 0xf3c261, doorWidth * 0.25, 0.75, depth / 2 + 0.13, group);
return group;
}
makeBuilding({
x: -7.0,
z: -5.0,
width: 5.4,
depth: 3.15,
height: 3.65,
color: 0xc58b62,
roof: 0x786f67,
windowRows: 2
});
makeBuilding({
x: -0.65,
z: -5.55,
width: 3.45,
depth: 3.05,
height: 5.15,
color: 0xe0b878,
roof: 0x8a5e55,
windowRows: 3
});
makeBuilding({
x: 5.65,
z: -5.1,
width: 5.6,
depth: 3.2,
height: 4.05,
color: 0x6f9b98,
roof: 0x4e6667,
windowRows: 2
});
// Stepped warehouse roof.
for (let i = 0; i < 4; i++) {
box(
1.2,
0.28,
3.05,
i % 2 === 0 ? 0x6f7873 : 0x7e837b,
-8.7 + i * 1.25,
3.95,
-5.0
);
}
// Roof details.
box(0.7, 1.25, 0.72, 0x9c715c, -0.2, 5.95, -5.85);
box(0.86, 0.18, 0.86, 0x635c57, -0.2, 6.65, -5.85);
box(1.1, 0.75, 1.1, 0xa9b1aa, 7.2, 4.65, -5.45);
box(1.42, 0.17, 1.42, 0x516867, 7.2, 5.12, -5.45);
// Voxel crane.
const crane = new THREE.Group();
crane.position.set(-10.0, 0, -2.8);
scene.add(crane);
box(0.38, 6.3, 0.42, 0xd5a24e, 0, 3.15, 0, crane);
box(4.8, 0.32, 0.42, 0xd5a24e, 1.55, 6.15, 0, crane);
box(1.25, 0.28, 0.3, 0x4d686a, 3.45, 5.78, 0, crane);
box(0.08, 2.15, 0.08, 0x3c5559, 3.45, 4.7, 0, crane);
box(0.42, 0.28, 0.4, 0x3c5559, 3.45, 3.55, 0, crane);
box(0.8, 0.25, 0.8, 0x8b6849, 3.45, 3.3, 0, crane);
// Stacked shipping containers.
const containerColors = [0xc96d50, 0x4f8f91, 0xd3a34e];
for (let stack = 0; stack < 3; stack++) {
const cx = 8.9 + stack * 1.02;
const levels = stack === 1 ? 2 : 1;
for (let level = 0; level < levels; level++) {
box(
0.94,
0.82,
1.35,
containerColors[(stack + level) % containerColors.length],
cx,
0.45 + level * 0.85,
-3.1
);
for (let rib = 0; rib < 4; rib++) {
box(
0.055,
0.68,
0.055,
0x695f55,
cx - 0.34 + rib * 0.22,
0.45 + level * 0.85,
-2.405
);
}
}
}
function makeBoat(x, z, hullColor, mast = false) {
const boat = new THREE.Group();
boat.position.set(x, -0.18, z);
scene.add(boat);
box(2.45, 0.42, 0.9, hullColor, 0, 0.05, 0, boat);
box(1.75, 0.32, 0.72, 0xf1dfbd, -0.12, 0.34, 0, boat);
box(0.8, 0.55, 0.64, 0xe8d4ae, 0.55, 0.65, 0, boat);
box(0.9, 0.12, 0.72, 0x466f79, 0.55, 0.98, 0, boat);
if (mast) {
box(0.09, 2.3, 0.09, 0x6a5547, -0.65, 1.25, 0, boat);
box(1.3, 0.08, 0.08, 0x6a5547, -0.1, 2.25, 0, boat);
box(0.72, 0.5, 0.04, 0xf5ebcf, -0.1, 1.85, 0.02, boat);
}
return boat;
}
makeBoat(-6.2, 10.7, 0xe66e52, true);
makeBoat(5.5, 11.8, 0xe2b65b, false);
// Mooring bollards along the quay.
for (let x = -10; x <= 10; x += 4) {
box(0.24, 0.62, 0.24, 0x37565c, x, 0.3, 6.65);
box(0.4, 0.16, 0.4, 0x37565c, x, 0.66, 6.65);
}
// ---------------------------------------------------------------------
// Original kiosk: Tide Bites
// ---------------------------------------------------------------------
function labelTexture(lines, background, foreground, width = 512, height = 192) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.imageSmoothingEnabled = false;
context.fillStyle = background;
context.fillRect(0, 0, width, height);
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = `900 ${lines.length > 1 ? 58 : 66}px monospace`;
if (lines.length === 1) {
context.fillText(lines[0], width / 2, height / 2 + 3);
} else {
context.fillText(lines[0], width / 2, height * 0.35);
context.fillText(lines[1], width / 2, height * 0.7);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
texture.generateMipmaps = false;
return texture;
}
const kiosk = new THREE.Group();
kiosk.position.set(-1.0, 0, 0.15);
scene.add(kiosk);
box(3.15, 0.22, 2.45, 0x2c5056, 0, 0.11, 0, kiosk);
box(2.85, 2.25, 2.15, 0xf0d49b, 0, 1.28, 0, kiosk);
box(2.92, 0.18, 2.22, 0x365b5c, 0, 0.38, 0, kiosk);
box(1.92, 0.95, 0.08, 0x254850, -0.28, 1.55, 1.105, kiosk);
box(0.82, 0.82, 0.09, 0x8fc7c3, 0.82, 1.55, 1.11, kiosk);
box(1.85, 0.12, 0.48, 0xf2b45d, -0.25, 0.98, 1.28, kiosk);
// Counter details.
box(0.55, 0.12, 0.08, 0x304d50, -0.95, 1.45, 1.16, kiosk);
box(0.18, 0.18, 0.18, 0xf4dfad, -0.95, 1.58, 1.21, kiosk);
// Striped voxel awning.
for (let i = 0; i < 8; i++) {
const stripe = i % 2 === 0 ? 0xe96550 : 0xf7e6ba;
box(
0.43,
0.2,
1.22,
stripe,
-1.49 + i * 0.425,
2.5,
1.38,
kiosk
);
box(
0.43,
0.4,
0.15,
stripe,
-1.49 + i * 0.425,
2.34,
1.94,
kiosk
);
}
box(3.25, 0.2, 2.2, 0x395f5d, 0, 2.7, 0, kiosk);
// Hanging sign.
box(2.3, 0.86, 0.12, 0x25474b, 0, 3.02, 1.64, kiosk);
const kioskSign = new THREE.Mesh(
new THREE.PlaneGeometry(2.08, 0.7),
new THREE.MeshBasicMaterial({
map: labelTexture(["TIDE", "BITES"], "#25474b", "#f3c65d")
})
);
kioskSign.position.set(0, 3.02, 1.71);
kiosk.add(kioskSign);
// Menu board.
box(0.68, 1.15, 0.12, 0x365a59, 1.62, 1.15, 1.15, kiosk);
for (let i = 0; i < 4; i++) {
box(
0.42 - (i % 2) * 0.08,
0.06,
0.05,
i === 3 ? 0xed755e : 0xf0dfb8,
1.62,
1.5 - i * 0.2,
1.225,
kiosk
);
}
// Crates, fruit, and a small service shelf.
box(0.78, 0.48, 0.7, 0xa46d46, -1.73, 0.4, 1.46, kiosk);
box(0.68, 0.12, 0.61, 0xc18a55, -1.73, 0.69, 1.46, kiosk);
const fruitColors = [0xe56848, 0xe8ad3c, 0x6da76e];
for (let i = 0; i < 9; i++) {
box(
0.15,
0.15,
0.15,
fruitColors[i % fruitColors.length],
-1.96 + (i % 3) * 0.2,
0.83,
1.27 + Math.floor(i / 3) * 0.18,
kiosk
);
}
// ---------------------------------------------------------------------
// Routes
// ---------------------------------------------------------------------
const routeGroup = new THREE.Group();
const lifeGroup = new THREE.Group();
scene.add(routeGroup, lifeGroup);
const cyclePoints = [
new THREE.Vector3(-8.8, 0.13, 2.55),
new THREE.Vector3(-5.0, 0.13, 2.55),
new THREE.Vector3(-0.8, 0.13, 2.55),
new THREE.Vector3(3.8, 0.13, 2.55),
new THREE.Vector3(8.25, 0.13, 1.9),
new THREE.Vector3(8.35, 0.13, -0.3),
new THREE.Vector3(6.1, 0.13, -2.0),
new THREE.Vector3(1.2, 0.13, -2.05),
new THREE.Vector3(-4.2, 0.13, -2.05),
new THREE.Vector3(-8.0, 0.13, -1.35),
new THREE.Vector3(-8.9, 0.13, 0.65)
];
const cycleRoute = new THREE.CatmullRomCurve3(
cyclePoints,
true,
"centripetal"
);
const walkRoute = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-10.8, 0.13, 5.62),
new THREE.Vector3(-6.2, 0.13, 5.7),
new THREE.Vector3(-2.0, 0.13, 5.58),
new THREE.Vector3(2.1, 0.13, 5.68),
new THREE.Vector3(6.1, 0.13, 5.56),
new THREE.Vector3(10.8, 0.13, 5.66)
],
false,
"centripetal"
);
function ribbon(curve, width, color, y, segments = 120, closed = false) {
const mesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color,
roughness: 0.9
}),
segments
);
const transform = new THREE.Object3D();
for (let i = 0; i < segments; i++) {
const t0 = i / segments;
const t1 = (i + 1) / segments;
const p0 = curve.getPointAt(t0);
const p1 = curve.getPointAt(t1);
const dx = p1.x - p0.x;
const dz = p1.z - p0.z;
const length = Math.hypot(dx, dz);
transform.position.set(
(p0.x + p1.x) / 2,
y,
(p0.z + p1.z) / 2
);
transform.rotation.set(0, Math.atan2(dx, dz), 0);
transform.scale.set(width, 0.055, length + 0.035);
transform.updateMatrix();
mesh.setMatrixAt(i, transform.matrix);
}
mesh.receiveShadow = true;
mesh.instanceMatrix.needsUpdate = true;
routeGroup.add(mesh);
return mesh;
}
// Dark cycle lane and luminous aqua center.
ribbon(cycleRoute, 1.18, 0x31565a, 0.075, 150, true);
ribbon(cycleRoute, 0.78, 0x35d1bd, 0.115, 150, true);
// Pedestrian promenade and coral route.
ribbon(walkRoute, 1.48, 0xf0dfbd, 0.072, 100);
ribbon(walkRoute, 0.57, 0xef6e61, 0.115, 100);
// Dashed cycle center markings.
const cycleLength = cycleRoute.getLength();
const dashCount = Math.floor(cycleLength / 1.25);
const dashes = new THREE.InstancedMesh(
unitBox,
material(0xe8fff4),
dashCount
);
const dashTransform = new THREE.Object3D();
for (let i = 0; i < dashCount; i++) {
const distance = 0.35 + i * 1.25;
const p0 = cycleRoute.getPointAt(distance / cycleLength);
const p1 = cycleRoute.getPointAt(
Math.min(1, (distance + 0.56) / cycleLength)
);
const dx = p1.x - p0.x;
const dz = p1.z - p0.z;
dashTransform.position.set(
(p0.x + p1.x) / 2,
0.16,
(p0.z + p1.z) / 2
);
dashTransform.rotation.set(0, Math.atan2(dx, dz), 0);
dashTransform.scale.set(0.105, 0.035, Math.hypot(dx, dz) + 0.02);
dashTransform.updateMatrix();
dashes.setMatrixAt(i, dashTransform.matrix);
}
dashes.instanceMatrix.needsUpdate = true;
routeGroup.add(dashes);
// Direction arrows on the cycle loop.
function addArrow(curve, t, color, scale = 1) {
const arrow = new THREE.Group();
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
arrow.position.set(point.x, 0.18, point.z);
arrow.rotation.y = Math.atan2(tangent.x, tangent.z);
arrow.scale.setScalar(scale);
box(0.12, 0.035, 0.78, color, 0, 0, 0.22, arrow);
box(0.12, 0.035, 0.55, color, -0.18, 0, -0.06, arrow).rotation.y = -0.7;
box(0.12, 0.035, 0.55, color, 0.18, 0, -0.06, arrow).rotation.y = 0.7;
routeGroup.add(arrow);
}
[0.02, 0.22, 0.43, 0.64, 0.84].forEach((t) =>
addArrow(cycleRoute, t, 0xffffff, 0.9)
);
// Pedestrian footprints.
const footprintCount = 25;
const footprints = new THREE.InstancedMesh(
unitBox,
material(0xffc4a7),
footprintCount
);
const footTransform = new THREE.Object3D();
const walkLength = walkRoute.getLength();
for (let i = 0; i < footprintCount; i++) {
const t = (i + 0.35) / footprintCount;
const point = walkRoute.getPointAt(t);
const tangent = walkRoute.getTangentAt(t);
const perpendicular = new THREE.Vector3(-tangent.z, 0, tangent.x);
const side = i % 2 === 0 ? 0.13 : -0.13;
footTransform.position.set(
point.x + perpendicular.x * side,
0.18,
point.z + perpendicular.z * side
);
footTransform.rotation.set(0, Math.atan2(tangent.x, tangent.z), 0);
footTransform.scale.set(0.12, 0.03, 0.25);
footTransform.updateMatrix();
footprints.setMatrixAt(i, footTransform.matrix);
}
footprints.instanceMatrix.needsUpdate = true;
routeGroup.add(footprints);
// ---------------------------------------------------------------------
// Pedestrian seating, trees, lamps and local quay details
// ---------------------------------------------------------------------
function makeBench(x, z, color = 0xb9774c, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
scene.add(bench);
for (let i = 0; i < 4; i++) {
box(
2.0,
0.12,
0.13,
color,
0,
0.58,
-0.24 + i * 0.16,
bench
);
}
for (let i = 0; i < 3; i++) {
box(
2.0,
0.12,
0.12,
color,
0,
0.82 + i * 0.16,
0.28,
bench
);
}
box(0.12, 0.58, 0.58, 0x36565b, -0.78, 0.29, 0, bench);
box(0.12, 0.58, 0.58, 0x36565b, 0.78, 0.29, 0, bench);
box(0.1, 0.62, 0.1, 0x36565b, -0.78, 0.86, 0.3, bench);
box(0.1, 0.62, 0.1, 0x36565b, 0.78, 0.86, 0.3, bench);
}
makeBench(3.3, 4.32);
makeBench(6.35, 4.32);
makeBench(8.9, 4.32, 0xc68a55);
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
box(0.28, 1.65, 0.28, 0x775b43, 0, 0.82, 0, tree);
box(0.92, 0.78, 0.9, 0x5d9274, 0, 1.86, 0, tree);
box(0.72, 0.75, 0.75, 0x72a37a, -0.56, 1.73, 0.08, tree);
box(0.72, 0.76, 0.74, 0x4f846c, 0.53, 1.8, 0.06, tree);
box(0.58, 0.55, 0.62, 0x7cab7e, 0.05, 2.35, -0.05, tree);
}
makeTree(-8.8, 4.55, 0.85);
makeTree(-6.25, 6.38, 0.76);
makeTree(1.15, 4.45, 0.8);
makeTree(4.85, 6.45, 0.72);
makeTree(10.05, 4.55, 0.86);
function makeLamp(x, z) {
const lamp = new THREE.Group();
lamp.position.set(x, 0, z);
scene.add(lamp);
box(0.42, 0.12, 0.42, 0x3c595d, 0, 0.06, 0, lamp);
box(0.13, 2.75, 0.13, 0x36565a, 0, 1.4, 0, lamp);
box(0.48, 0.55, 0.48, 0xf2d889, 0, 2.83, 0, lamp);
box(0.65, 0.12, 0.65, 0x36565a, 0, 3.13, 0, lamp);
}
makeLamp(-4.8, 4.6);
makeLamp(2.75, 4.55);
makeLamp(7.8, 6.45);
// Small waste bins and bollards.
for (const x of [-5.8, 0.3, 5.4]) {
box(0.48, 0.75, 0.48, 0x496f6e, x, 0.38, 4.35);
box(0.54, 0.12, 0.54, 0x2f5558, x, 0.79, 4.35);
}
// Wayfinding signs.
function makeWayfindingSign(x, z, color, text) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(0.13, 1.55, 0.13, 0x3a585b, 0, 0.78, 0, group);
box(1.45, 0.52, 0.13, color, 0, 1.55, 0, group);
const texture = labelTexture([text], "#ffffff", "#18363d", 384, 128);
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(1.32, 0.4),
new THREE.MeshBasicMaterial({ map: texture })
);
plane.position.set(0, 1.55, 0.075);
group.add(plane);
}
makeWayfindingSign(-8.85, 2.95, 0x35d1bd, "CYCLE");
makeWayfindingSign(9.15, 5.85, 0xef6e61, "WALK");
// ---------------------------------------------------------------------
// Animated voxel cyclists and pedestrians
// ---------------------------------------------------------------------
function makeBike(frameColor, riderColor) {
const bike = new THREE.Group();
// Pixel wheel rings.
for (const wheelZ of [-0.58, 0.58]) {
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
box(
0.13,
0.13,
0.13,
0x263d42,
0,
0.4 + Math.sin(angle) * 0.27,
wheelZ + Math.cos(angle) * 0.27,
bike
);
}
}
const rear = new THREE.Vector3(0, 0.4, -0.58);
const front = new THREE.Vector3(0, 0.4, 0.58);
const crank = new THREE.Vector3(0, 0.43, 0.02);
const saddle = new THREE.Vector3(0, 0.92, -0.24);
const handle = new THREE.Vector3(0, 0.95, 0.42);
barBetween(bike, rear, crank, 0.08, frameColor);
barBetween(bike, crank, saddle, 0.08, frameColor);
barBetween(bike, saddle, crank, 0.08, frameColor);
barBetween(bike, saddle, handle, 0.08, frameColor);
barBetween(bike, handle, front, 0.08, frameColor);
box(0.12, 0.09, 0.34, 0x304b4d, 0, 1.0, -0.24, bike);
box(0.12, 0.08, 0.12, 0x304b4d, 0, 1.0, 0.45, bike);
// Rider.
box(0.42, 0.56, 0.28, riderColor, 0, 1.3, -0.05, bike);
box(0.28, 0.28, 0.28, 0xe2b27f, 0, 1.7, 0.02, bike);
box(0.48, 0.15, 0.33, riderColor, 0, 1.79, 0.02, bike);
barBetween(
bike,
new THREE.Vector3(0, 1.43, 0.1),
new THREE.Vector3(0, 1.08, 0.43),
0.11,
riderColor
);
barBetween(
bike,
new THREE.Vector3(0, 1.35, -0.08),
new THREE.Vector3(0, 0.66, -0.32),
0.12,
0x344f57
);
barBetween(
bike,
new THREE.Vector3(0, 1.35, -0.08),
new THREE.Vector3(0, 0.66, 0.3),
0.12,
0x344f57
);
return bike;
}
function makePerson(shirtColor, skinColor) {
const person = new THREE.Group();
box(0.4, 0.52, 0.28, shirtColor, 0, 0.95, 0, person);
box(0.29, 0.29, 0.29, skinColor, 0, 1.39, 0, person);
box(0.34, 0.12, 0.32, 0x3e5555, 0, 1.56, 0, person);
box(0.14, 0.54, 0.16, 0x36535a, -0.11, 0.42, 0, person);
box(0.14, 0.54, 0.16, 0x36535a, 0.11, 0.42, 0, person);
box(0.16, 0.1, 0.28, 0x2f4b51, -0.11, 0.1, 0.04, person);
box(0.16, 0.1, 0.28, 0x2f4b51, 0.11, 0.1, 0.04, person);
box(0.12, 0.46, 0.13, shirtColor, -0.27, 0.94, 0, person);
box(0.12, 0.46, 0.13, shirtColor, 0.27, 0.94, 0, person);
return person;
}
const cyclists = [
{
object: makeBike(0xf3b94f, 0xe66d52),
offset: 0.04,
speed: 0.026
},
{
object: makeBike(0x315c65, 0x68a9a4),
offset: 0.53,
speed: -0.021
}
];
const walkers = [
{
object: makePerson(0xde6d5e, 0xd7a475),
offset: 0.08,
speed: 0.012
},
{
object: makePerson(0x477d87, 0xa97254),
offset: 0.44,
speed: -0.009
},
{
object: makePerson(0xe2b553, 0xe1b68c),
offset: 0.71,
speed: 0.010
}
];
cyclists.forEach((cyclist) => lifeGroup.add(cyclist.object));
walkers.forEach((walker) => lifeGroup.add(walker.object));
// Voxel gulls above the water.
const gulls = [];
for (let i = 0; i < 4; i++) {
const gull = new THREE.Group();
gull.position.set(-6 + i * 3.5, 5.4 + (i % 2) * 0.9, 9.5 + (i % 2));
box(0.18, 0.15, 0.42, 0xf5f1d9, 0, 0, 0, gull);
box(0.75, 0.08, 0.16, 0xf5f1d9, -0.35, 0.03, 0, gull);
box(0.75, 0.08, 0.16, 0xf5f1d9, 0.35, 0.03, 0, gull);
scene.add(gull);
gulls.push(gull);
}
// ---------------------------------------------------------------------
// Direct camera controls implemented without addons
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0, 0.1, 1.0);
const spherical = new THREE.Spherical(36, 0.91, 0.72);
let zoom = 1;
let dragging = false;
let dragMode = "orbit";
let pointerX = 0;
let pointerY = 0;
const cameraRight = new THREE.Vector3();
const cameraForward = new THREE.Vector3();
function updateCamera() {
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(target).add(offset);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
target.set(0, 0.1, 1.0);
spherical.set(36, 0.91, 0.72);
zoom = 1;
updateCamera();
updateProjection();
}
function updateProjection() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight = Math.max(10.7, 13.6 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function panCamera(dx, dy) {
camera.updateMatrixWorld();
cameraRight.setFromMatrixColumn(camera.matrixWorld, 0);
cameraRight.y = 0;
cameraRight.normalize();
camera.getWorldDirection(cameraForward);
cameraForward.y = 0;
cameraForward.normalize();
const worldPerPixel =
(camera.top - camera.bottom) /
camera.zoom /
renderer.domElement.clientHeight;
target.addScaledVector(cameraRight, -dx * worldPerPixel);
target.addScaledVector(cameraForward, -dy * worldPerPixel);
target.x = THREE.MathUtils.clamp(target.x, -8, 8);
target.z = THREE.MathUtils.clamp(target.z, -4, 8);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragMode = event.shiftKey || event.button === 2 ? "pan" : "orbit";
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (dragMode === "pan") {
panCamera(dx, dy);
} else {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.005,
0.38,
1.32
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.85
);
updateProjection();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.querySelector("#reset").addEventListener("click", resetCamera);
document.querySelector("#zoom-in").addEventListener("click", () => {
zoom = THREE.MathUtils.clamp(zoom * 1.12, 0.68, 1.85);
updateProjection();
});
document.querySelector("#zoom-out").addEventListener("click", () => {
zoom = THREE.MathUtils.clamp(zoom / 1.12, 0.68, 1.85);
updateProjection();
});
window.addEventListener("keydown", (event) => {
if (event.key === "r" || event.key === "R") {
resetCamera();
}
if (event.key === "ArrowLeft") spherical.theta -= 0.08;
if (event.key === "ArrowRight") spherical.theta += 0.08;
if (event.key === "ArrowUp") {
spherical.phi = THREE.MathUtils.clamp(spherical.phi - 0.06, 0.38, 1.32);
}
if (event.key === "ArrowDown") {
spherical.phi = THREE.MathUtils.clamp(spherical.phi + 0.06, 0.38, 1.32);
}
if (event.key === "+" || event.key === "=") {
zoom = THREE.MathUtils.clamp(zoom * 1.08, 0.68, 1.85);
updateProjection();
}
if (event.key === "-") {
zoom = THREE.MathUtils.clamp(zoom / 1.08, 0.68, 1.85);
updateProjection();
}
updateCamera();
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateProjection();
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
waterGroup.position.y = Math.sin(elapsed * 0.75) * 0.018;
for (const cyclist of cyclists) {
const t = (elapsed * cyclist.speed + cyclist.offset + 1) % 1;
const point = cycleRoute.getPointAt(t);
const tangent = cycleRoute.getTangentAt(t);
cyclist.object.position.set(point.x, point.y + 0.01, point.z);
cyclist.object.rotation.y = Math.atan2(tangent.x, tangent.z);
}
for (const walker of walkers) {
const t = (elapsed * walker.speed + walker.offset + 1) % 1;
const point = walkRoute.getPointAt(t);
const tangent = walkRoute.getTangentAt(t);
walker.object.position.set(
point.x,
point.y + Math.sin(elapsed * 7 + walker.offset * 10) * 0.018,
point.z
);
walker.object.rotation.y = Math.atan2(tangent.x, tangent.z);
}
gulls.forEach((gull, index) => {
gull.position.x += Math.sin(elapsed * 0.45 + index) * 0.003;
gull.position.y += Math.cos(elapsed * 1.2 + index) * 0.0015;
});
renderer.render(scene, camera);
}
resetCamera();
animate();
</script>
</body>
</html>
```