Prompt specification
Build or customize the Three.js 3D scene "Pedestrians crossing a Georgetown canal footbridge" 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: Pedestrians crossing a Georgetown canal footbridge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pedestrians-crossing-a-georgetown-canal-footbridge-x2798
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the canal in Washington's Georgetown neighborhood. Create a compact canal vignette with towpath, footbridge, and brick facade. Animate one crossing route while preserving the separate continuous path along the water. Voxel style.
Working Three.js Starter (pedestrians-crossing-a-georgetown-canal-footbridge-x2798):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Georgetown Canal — Voxel Vignette</title>
<style>
:root {
--ink: #263d3b;
--muted: #627572;
--paper: rgba(250, 247, 236, 0.9);
--paper-solid: #faf7ec;
--line: rgba(38, 61, 59, 0.16);
--amber: #d59a32;
--aqua: #4ca7a1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7e5e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.7);
box-shadow:
0 16px 45px rgba(34, 57, 54, 0.13),
0 2px 8px rgba(34, 57, 54, 0.08);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.info {
top: 24px;
left: 24px;
width: 340px;
padding: 21px 22px 18px;
border-radius: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #58726d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 2px;
background: var(--amber);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.location {
margin-top: 9px;
color: var(--muted);
font-size: 12px;
font-weight: 650;
letter-spacing: 0.04em;
}
.description {
max-width: 280px;
margin: 15px 0 17px;
color: #596d69;
font-size: 12px;
line-height: 1.55;
}
.legend {
display: grid;
gap: 9px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: #506562;
font-size: 11px;
font-weight: 650;
}
.swatch {
width: 28px;
height: 4px;
border-radius: 1px;
flex: 0 0 auto;
}
.swatch.crossing {
background: repeating-linear-gradient(
90deg,
var(--amber) 0 7px,
transparent 7px 11px
);
}
.swatch.water {
height: 3px;
background: var(--aqua);
}
.journey {
left: 24px;
bottom: 24px;
width: 310px;
padding: 14px 16px;
border-radius: 4px;
}
.journey-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#journey-value {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.track {
position: relative;
height: 4px;
overflow: hidden;
background: rgba(38, 61, 59, 0.12);
}
#progress {
width: 0%;
height: 100%;
background: var(--amber);
}
.controls {
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 4px;
}
button {
appearance: none;
border: 1px solid rgba(38, 61, 59, 0.15);
border-radius: 2px;
background: rgba(255, 255, 255, 0.52);
color: var(--ink);
min-height: 34px;
padding: 0 12px;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
.hint {
position: fixed;
z-index: 8;
top: 27px;
right: 27px;
padding: 8px 11px;
border: 1px solid rgba(38, 61, 59, 0.11);
border-radius: 2px;
background: rgba(250, 247, 236, 0.68);
color: #56706b;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
backdrop-filter: blur(8px);
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #d7e5e2;
color: #48635f;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#loading span {
padding: 12px 16px;
border: 1px solid rgba(38, 61, 59, 0.16);
background: rgba(250, 247, 236, 0.65);
}
@media (max-width: 720px) {
.info {
top: 12px;
left: 12px;
width: min(300px, calc(100vw - 24px));
padding: 15px 16px;
}
.description,
.legend {
display: none;
}
.location {
margin-bottom: 0;
}
h1 {
font-size: 30px;
}
.journey {
left: 12px;
bottom: 66px;
width: min(270px, calc(100vw - 24px));
}
.controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="loading"><span>Building Georgetown…</span></div>
<section class="panel info">
<div class="eyebrow">Washington, D.C.</div>
<h1>Georgetown<br />Canal</h1>
<div class="location">C&O CANAL · 38.9047° N</div>
<p class="description">
A compact voxel study of the historic canal edge: towpath, wooden footbridge,
brick warehouse facade, and a single animated crossing.
</p>
<div class="legend">
<div class="legend-row">
<span class="swatch crossing"></span>
Animated pedestrian crossing
</div>
<div class="legend-row">
<span class="swatch water"></span>
Continuous waterway axis
</div>
</div>
</section>
<section class="panel journey">
<div class="journey-head">
<span>Crossing route</span>
<span id="journey-value">0%</span>
</div>
<div class="track"><div id="progress"></div></div>
</section>
<nav class="panel controls" aria-label="Scene controls">
<button id="toggle" type="button">Pause</button>
<button id="reset" type="button">Reset view</button>
</nav>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7e5e2);
scene.fog = new THREE.Fog(0xd7e5e2, 58, 105);
const camera = new THREE.OrthographicCamera(-18, 18, 10, -10, 0.1, 150);
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.04;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf8fbef, 0x49675f, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d3, 3.2);
sun.position.set(-13, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8d9dc, 0.85);
fill.position.set(15, 10, -16);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared materials and voxel construction helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
});
const M = {
base: material(0x344b46),
baseEdge: material(0x263d39),
groundNorth: material(0x8e9b78),
groundSouth: material(0x829176),
stone: material(0x777f77),
stoneLight: material(0xb0afa0),
stoneDark: material(0x626b66),
path: material(0xc4a779),
pathEdge: material(0x9b805d),
cobble: material(0xaaa991),
water: material(0x347f87, { roughness: 0.28, metalness: 0.06 }),
waterLight: material(0x75b9b7, { roughness: 0.32 }),
waterGuide: material(0x9de0d3, {
emissive: 0x4a9c94,
emissiveIntensity: 0.35,
roughness: 0.45
}),
wood: material(0x59483a),
woodLight: material(0x8b6c4d),
woodPale: material(0xb0946b),
rail: material(0x355b51),
brick: material(0x9f493a),
brickLight: material(0xb85a43),
brickDark: material(0x843c34),
mortar: material(0x68574b),
window: material(0x243e48, { roughness: 0.22, metalness: 0.16 }),
windowLight: material(0x7da9ad, { roughness: 0.3 }),
trim: material(0xd3c9ad),
roof: material(0x424a45),
leaf: material(0x54765b),
leafLight: material(0x6e8c62),
leafDark: material(0x405f4d),
trunk: material(0x69523d),
lamp: material(0x273e3c),
lampGlow: material(0xf4d783, {
emissive: 0xe7b85f,
emissiveIntensity: 0.55
}),
route: material(0xd59a32, {
emissive: 0x9b5d12,
emissiveIntensity: 0.24
}),
coat: material(0xdda63d),
pants: material(0x2d4b59),
skin: material(0xe3b286),
hat: material(0x274c50),
backpack: material(0x39766c),
boat: material(0x9c4938),
boatCream: material(0xe5dbc0)
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(parent, sx, sy, sz, x, y, z, mat, cast = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function instancedBoxes(parent, transforms, mat, cast = false) {
const mesh = new THREE.InstancedMesh(unitBox, mat, transforms.length);
const dummy = new THREE.Object3D();
transforms.forEach((t, index) => {
dummy.position.set(t.x, t.y, t.z);
dummy.scale.set(t.sx, t.sy, t.sz);
dummy.rotation.set(
t.rx || 0,
t.ry || 0,
t.rz || 0
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (t.color) {
mesh.setColorAt(index, new THREE.Color(t.color));
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Diorama base, banks, canal, and towpath
// -------------------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
box(world, 29.4, 0.75, 15.6, 0, -0.55, 0, M.base);
box(world, 29.7, 0.17, 15.9, 0, -0.91, 0, M.baseEdge);
// Continuous land masses and a single uninterrupted water volume.
box(world, 29, 0.58, 5.35, 0, 0.03, -5.025, M.groundNorth);
box(world, 29, 0.58, 5.35, 0, 0.03, 5.025, M.groundSouth);
box(world, 28.6, 0.18, 4.35, 0, 0.27, 0, M.water);
box(world, 28.7, 0.05, 4.52, 0, 0.12, 0, M.stoneDark, false);
// Canal retaining walls and pale stone coping.
for (const z of [-2.28, 2.28]) {
box(world, 28.6, 0.78, 0.24, 0, 0.43, z, M.stone);
box(world, 28.8, 0.14, 0.38, 0, 0.82, z, M.stoneLight);
}
// The towpath remains visually continuous along the north bank.
box(world, 27.4, 0.14, 1.62, 0, 0.39, -3.35, M.path);
box(world, 27.5, 0.09, 0.13, 0, 0.45, -4.11, M.pathEdge, false);
box(world, 27.5, 0.09, 0.13, 0, 0.45, -2.59, M.pathEdge, false);
// A quieter walking ledge on the south side.
box(world, 27.2, 0.12, 1.12, 0, 0.36, 3.55, M.stoneLight);
box(world, 27.2, 0.06, 0.12, 0, 0.42, 3.03, M.stoneDark, false);
const cobbles = [];
for (let x = -13.2; x <= 13.2; x += 0.72) {
for (const z of [-4.08, -2.61]) {
cobbles.push({
x,
y: 0.49,
z,
sx: 0.54,
sy: 0.075,
sz: 0.16
});
}
}
instancedBoxes(world, cobbles, M.cobble);
// A quiet graphic water-axis guide. It remains continuous beneath the bridge.
box(world, 27.4, 0.025, 0.065, 0, 0.372, 0, M.waterGuide, false);
// Static voxel ripple marks.
const ripples = [];
for (let i = 0; i < 26; i++) {
const x = -13 + i * 1.03 + (i % 3) * 0.08;
const z = -1.65 + ((i * 0.71) % 3.35);
ripples.push({
x,
y: 0.373,
z,
sx: 0.36 + (i % 3) * 0.12,
sy: 0.018,
sz: 0.055
});
}
instancedBoxes(world, ripples, M.waterLight, false);
// -------------------------------------------------------------------------
// Brick facade
// -------------------------------------------------------------------------
const facade = new THREE.Group();
world.add(facade);
box(facade, 14.8, 3.85, 1.5, -4.8, 2.28, -6.46, M.mortar);
box(facade, 15.15, 0.27, 1.76, -4.8, 4.27, -6.46, M.roof);
box(facade, 14.85, 0.19, 0.16, -4.8, 4.49, -5.67, M.stoneDark);
// Individual instanced bricks form the visible voxel facade.
const bricks = [];
const brickColors = [0xa84f3d, 0xb35842, 0x964437, 0xbd6046, 0x8e4036];
for (let row = 0; row < 12; row++) {
const offset = row % 2 === 0 ? 0 : 0.36;
for (let col = -10; col <= 10; col++) {
const x = -4.8 + col * 0.72 + offset;
if (x < -12.08 || x > 2.48) continue;
bricks.push({
x,
y: 0.66 + row * 0.3,
z: -5.67,
sx: 0.67,
sy: 0.255,
sz: 0.075,
color: brickColors[(row * 3 + col + 20) % brickColors.length]
});
}
}
instancedBoxes(facade, bricks, material(0xffffff), false);
// Windows and trim.
for (const x of [-10.1, -7.35, -4.6, -1.85]) {
for (const y of [1.22, 2.72]) {
box(facade, 1.18, 1.23, 0.12, x, y, -5.58, M.trim);
box(facade, 0.91, 0.96, 0.11, x, y, -5.49, M.window);
box(facade, 0.08, 0.98, 0.12, x, y, -5.42, M.trim);
box(facade, 0.93, 0.08, 0.12, x, y, -5.42, M.trim);
// Small reflected pane.
box(facade, 0.16, 0.48, 0.035, x - 0.28, y + 0.12, -5.405, M.windowLight, false);
}
}
// Ground-level door and a simple green canopy.
box(facade, 1.22, 2.12, 0.16, 1.03, 1.38, -5.53, M.trim);
box(facade, 0.96, 1.88, 0.14, 1.03, 1.38, -5.41, M.wood);
box(facade, 0.08, 0.07, 0.08, 1.32, 1.35, -5.31, M.lampGlow, false);
box(facade, 1.65, 0.14, 0.72, 1.03, 2.63, -5.27, M.rail);
// Roofline details.
box(facade, 0.78, 1.25, 0.82, -9.8, 4.83, -6.52, M.brickDark);
box(facade, 0.95, 0.18, 1.0, -9.8, 5.47, -6.52, M.stoneDark);
box(facade, 1.3, 0.38, 0.8, -1.9, 4.52, -6.45, M.roof);
// -------------------------------------------------------------------------
// Footbridge with stepped approaches
// -------------------------------------------------------------------------
const bridge = new THREE.Group();
world.add(bridge);
const bridgeX = 5.0;
// Main deck.
box(bridge, 2.02, 0.18, 4.72, bridgeX, 2.25, 0, M.wood);
const planks = [];
for (let i = 0; i < 13; i++) {
planks.push({
x: bridgeX,
y: 2.37,
z: -2.16 + i * 0.36,
sx: 1.94,
sy: 0.10,
sz: 0.31
});
}
instancedBoxes(bridge, planks, M.woodPale, true);
// Seven voxel steps on each bank.
const stairTops = [];
for (let side = -1; side <= 1; side += 2) {
for (let i = 0; i < 7; i++) {
const z = side * (3.72 - i * 0.21);
const top = 0.62 + i * 0.28;
const bottom = 0.35;
const height = top - bottom;
box(
bridge,
1.94,
height,
0.255,
bridgeX,
bottom + height / 2,
z,
i % 2 === 0 ? M.woodPale : M.woodLight
);
stairTops.push(new THREE.Vector3(bridgeX, top, z));
// Stepped side rails.
for (const railX of [bridgeX - 1.02, bridgeX + 1.02]) {
box(
bridge,
0.105,
0.11,
0.27,
railX,
top + 0.61,
z,
M.rail
);
if (i % 2 === 0) {
box(
bridge,
0.105,
0.68,
0.105,
railX,
top + 0.29,
z,
M.rail
);
}
}
}
}
// Deck railings and posts.
for (const x of [bridgeX - 1.02, bridgeX + 1.02]) {
box(bridge, 0.13, 0.13, 4.76, x, 3.18, 0, M.rail);
box(bridge, 0.10, 0.10, 4.76, x, 2.78, 0, M.rail);
for (let z = -2.1; z <= 2.2; z += 0.84) {
box(bridge, 0.13, 0.96, 0.13, x, 2.78, z, M.rail);
}
}
// Small cross beams visible from the side.
for (const z of [-1.65, 0, 1.65]) {
box(bridge, 2.18, 0.16, 0.15, bridgeX, 2.07, z, M.wood);
}
// -------------------------------------------------------------------------
// Route geometry and animated pedestrian
// -------------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(bridgeX, 0.51, -4.08),
new THREE.Vector3(bridgeX, 0.51, -3.92),
new THREE.Vector3(bridgeX, 0.64, -3.72),
new THREE.Vector3(bridgeX, 0.92, -3.51),
new THREE.Vector3(bridgeX, 1.20, -3.30),
new THREE.Vector3(bridgeX, 1.48, -3.09),
new THREE.Vector3(bridgeX, 1.76, -2.88),
new THREE.Vector3(bridgeX, 2.04, -2.67),
new THREE.Vector3(bridgeX, 2.32, -2.46),
new THREE.Vector3(bridgeX, 2.40, -2.28),
new THREE.Vector3(bridgeX, 2.40, -1.1),
new THREE.Vector3(bridgeX, 2.40, 0),
new THREE.Vector3(bridgeX, 2.40, 1.1),
new THREE.Vector3(bridgeX, 2.40, 2.28),
new THREE.Vector3(bridgeX, 2.32, 2.46),
new THREE.Vector3(bridgeX, 2.04, 2.67),
new THREE.Vector3(bridgeX, 1.76, 2.88),
new THREE.Vector3(bridgeX, 1.48, 3.09),
new THREE.Vector3(bridgeX, 1.20, 3.30),
new THREE.Vector3(bridgeX, 0.92, 3.51),
new THREE.Vector3(bridgeX, 0.64, 3.72),
new THREE.Vector3(bridgeX, 0.51, 3.92),
new THREE.Vector3(bridgeX, 0.51, 4.08)
];
const segmentLengths = [];
let totalRouteLength = 0;
for (let i = 0; i < routePoints.length - 1; i++) {
const length = routePoints[i].distanceTo(routePoints[i + 1]);
segmentLengths.push(length);
totalRouteLength += length;
}
function sampleRoute(distance, outPosition, outDirection) {
let remaining = THREE.MathUtils.clamp(distance, 0, totalRouteLength);
for (let i = 0; i < segmentLengths.length; i++) {
const length = segmentLengths[i];
if (remaining <= length || i === segmentLengths.length - 1) {
const a = routePoints[i];
const b = routePoints[i + 1];
const t = length > 0 ? remaining / length : 0;
outPosition.lerpVectors(a, b, t);
outDirection.subVectors(b, a).normalize();
return;
}
remaining -= length;
}
}
// Dashed amber route markers.
const markerTransforms = [];
const markerCount = Math.floor(totalRouteLength / 0.37);
const markerPosition = new THREE.Vector3();
const markerDirection = new THREE.Vector3();
for (let i = 0; i < markerCount; i++) {
sampleRoute(i * 0.37, markerPosition, markerDirection);
markerTransforms.push({
x: markerPosition.x,
y: markerPosition.y + 0.055,
z: markerPosition.z,
sx: 0.13,
sy: 0.045,
sz: 0.28,
ry: Math.atan2(markerDirection.x, markerDirection.z)
});
}
instancedBoxes(world, markerTransforms, M.route, false);
// Voxel pedestrian.
const walker = new THREE.Group();
world.add(walker);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftLeg.position.set(-0.105, 0.61, 0);
rightLeg.position.set(0.105, 0.61, 0);
leftArm.position.set(-0.29, 1.02, 0);
rightArm.position.set(0.29, 1.02, 0);
walker.add(leftLeg, rightLeg, leftArm, rightArm);
box(walker, 0.15, 0.42, 0.18, 0, -0.19, 0, M.pants);
box(walker, 0.15, 0.42, 0.18, 0, -0.19, 0, M.pants);
box(leftLeg, 0.15, 0.42, 0.18, 0, -0.19, 0, M.pants);
box(rightLeg, 0.15, 0.42, 0.18, 0, -0.19, 0, M.pants);
box(walker, 0.43, 0.57, 0.31, 0, 0.87, 0, M.coat);
box(walker, 0.34, 0.32, 0.31, 0, 1.29, 0, M.skin);
box(walker, 0.43, 0.12, 0.38, 0, 1.49, 0, M.hat);
box(walker, 0.32, 0.09, 0.18, 0, 1.40, 0.20, M.hat);
box(leftArm, 0.13, 0.42, 0.15, 0, -0.19, 0, M.coat);
box(rightArm, 0.13, 0.42, 0.15, 0, -0.19, 0, M.coat);
box(leftArm, 0.12, 0.12, 0.14, 0, -0.42, 0, M.skin);
box(rightArm, 0.12, 0.12, 0.14, 0, -0.42, 0, M.skin);
// Small square backpack.
box(walker, 0.37, 0.43, 0.18, 0, 0.88, -0.23, M.backpack);
const walkerShadow = box(
world,
0.58,
0.018,
0.43,
bridgeX,
0.54,
-4,
new THREE.MeshBasicMaterial({
color: 0x17302c,
transparent: true,
opacity: 0.18,
depthWrite: false
}),
false
);
// -------------------------------------------------------------------------
// Trees, lamps, bollards, bench, and moored boat
// -------------------------------------------------------------------------
function voxelTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.34, z);
tree.scale.setScalar(scale);
world.add(tree);
box(tree, 0.34, 1.45, 0.34, 0, 0.72, 0, M.trunk);
box(tree, 1.65, 1.35, 1.48, 0, 1.92, 0, M.leaf);
box(tree, 1.15, 1.2, 1.15, -0.45, 2.48, 0.05, M.leafLight);
box(tree, 1.0, 0.95, 1.0, 0.52, 2.28, -0.08, M.leafDark);
box(tree, 0.85, 0.82, 0.84, 0.05, 2.98, 0.02, M.leafLight);
}
voxelTree(-8.4, 5.55, 1.02);
voxelTree(8.55, 5.45, 0.92);
voxelTree(-10.55, -4.8, 0.82);
function lamp(x, z) {
box(world, 0.12, 0.22, 0.12, x, 0.48, z, M.lamp);
box(world, 0.09, 2.25, 0.09, x, 1.56, z, M.lamp);
box(world, 0.31, 0.33, 0.31, x, 2.76, z, M.lamp);
box(world, 0.22, 0.24, 0.22, x, 2.75, z, M.lampGlow, false);
box(world, 0.42, 0.1, 0.42, x, 2.98, z, M.lamp);
}
lamp(-8.9, -4.75);
lamp(-3.9, -4.75);
lamp(2.5, -4.78);
lamp(8.25, -4.7);
// Bench beside the towpath.
box(world, 1.75, 0.15, 0.46, -5.9, 0.78, -4.65, M.wood);
box(world, 1.75, 0.52, 0.12, -5.9, 1.07, -4.86, M.wood);
box(world, 0.13, 0.48, 0.38, -6.64, 0.55, -4.65, M.lamp);
box(world, 0.13, 0.48, 0.38, -5.16, 0.55, -4.65, M.lamp);
// Mooring bollards along both canal edges.
for (let x = -12; x <= 12; x += 3) {
box(world, 0.22, 0.48, 0.22, x, 0.91, -2.57, M.lamp);
box(world, 0.22, 0.48, 0.22, x + 0.3, 0.91, 2.57, M.lamp);
}
// Static, moored voxel boat; the water and guide remain continuous behind it.
const boat = new THREE.Group();
boat.position.set(-6.0, 0.36, 0.55);
world.add(boat);
box(boat, 2.75, 0.22, 0.86, 0, 0.14, 0, M.boat);
box(boat, 2.18, 0.35, 0.78, 0, 0.38, 0, M.boat);
box(boat, 0.55, 0.28, 0.55, 1.53, 0.27, 0, M.boat);
box(boat, 0.55, 0.28, 0.55, -1.53, 0.27, 0, M.boat);
box(boat, 1.25, 0.6, 0.67, -0.2, 0.81, 0, M.boatCream);
box(boat, 0.72, 0.31, 0.69, -0.2, 0.94, 0, M.window);
box(boat, 0.09, 0.63, 0.09, 0.3, 1.35, 0, M.lamp);
box(boat, 0.18, 0.15, 0.18, 0.3, 1.68, 0, M.lampGlow, false);
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
const cameraState = {
azimuth: 0.55,
elevation: 0.69,
zoom: 1,
target: new THREE.Vector3(0, 0.75, -0.45),
radius: 35
};
function updateCamera() {
const horizontal = Math.cos(cameraState.elevation) * cameraState.radius;
const x =
cameraState.target.x +
Math.sin(cameraState.azimuth) * horizontal;
const z =
cameraState.target.z +
Math.cos(cameraState.azimuth) * horizontal;
const y =
cameraState.target.y +
Math.sin(cameraState.elevation) * cameraState.radius;
camera.position.set(x, y, z);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const frustumHeight = Math.max(19.5, 36 / aspect);
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
function resetCamera() {
cameraState.azimuth = 0.55;
cameraState.elevation = 0.69;
cameraState.zoom = 1;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
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;
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.004,
0.3,
1.12
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.85
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Animation and UI
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const progressBar = document.getElementById("progress");
const journeyValue = document.getElementById("journey-value");
const toggleButton = document.getElementById("toggle");
const resetButton = document.getElementById("reset");
let playing = true;
let journeyTime = 0;
const journeyDuration = 18;
const currentRoutePosition = new THREE.Vector3();
const currentRouteDirection = new THREE.Vector3(0, 0, 1);
let currentWalkerAngle = 0;
let lastUiUpdate = 0;
toggleButton.addEventListener("click", () => {
playing = !playing;
toggleButton.textContent = playing ? "Pause" : "Play";
});
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
toggleButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
journeyTime = (journeyTime + dt) % journeyDuration;
}
const progress = journeyTime / journeyDuration;
sampleRoute(
progress * totalRouteLength,
currentRoutePosition,
currentRouteDirection
);
const targetAngle = Math.atan2(
currentRouteDirection.x,
currentRouteDirection.z
);
const angleDifference = Math.atan2(
Math.sin(targetAngle - currentWalkerAngle),
Math.cos(targetAngle - currentWalkerAngle)
);
currentWalkerAngle += angleDifference * 0.13;
const walkPhase = progress * totalRouteLength * 2.65;
const stride = Math.sin(walkPhase) * 0.52;
walker.position.copy(currentRoutePosition);
walker.rotation.y = currentWalkerAngle;
leftLeg.rotation.x = stride;
rightLeg.rotation.x = -stride;
leftArm.rotation.x = -stride * 0.72;
rightArm.rotation.x = stride * 0.72;
walker.position.y += Math.abs(Math.sin(walkPhase)) * 0.035;
walkerShadow.position.x = currentRoutePosition.x;
walkerShadow.position.z = currentRoutePosition.z;
walkerShadow.position.y = currentRoutePosition.y + 0.025;
walkerShadow.rotation.y = currentWalkerAngle;
if (performance.now() - lastUiUpdate > 80) {
const percent = Math.round(progress * 100);
progressBar.style.width = `${percent}%`;
journeyValue.textContent = `${percent}%`;
lastUiUpdate = performance.now();
}
renderer.render(scene, camera);
}
resize();
updateCamera();
loading.remove();
animate();
</script>
</body>
</html>
```