Prompt specification
Build or customize the Three.js 3D scene "Inspect exposed and sheltered walking routes" 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: Inspect exposed and sheltered walking routes
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/inspect-exposed-and-sheltered-walking-routes-x2744
Scene Description Prompt:
Compare voxel walking routes along Havana’s Malecón and inland under a schematic wave-exposure overlay. Make standalone HTML using Three.js from cdnjs.
Working Three.js Starter (inspect-exposed-and-sheltered-walking-routes-x2744):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Havana: Malecón vs. Inland Walking Routes</title>
<style>
:root {
--ink: #10282f;
--muted: #789198;
--panel: rgba(12, 32, 39, 0.9);
--panel-border: rgba(255, 255, 255, 0.12);
--waterfront: #20dfc0;
--inland: #ffb45f;
--white: #f4faf9;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe7e5;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 30px;
left: 34px;
max-width: 460px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #42636b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 27px;
height: 2px;
background: #e07d53;
}
h1 {
margin: 0;
max-width: 430px;
color: #102b33;
font-size: clamp(34px, 4.3vw, 66px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.95;
}
.brand p {
max-width: 390px;
margin: 16px 0 0;
color: #4f6e75;
font-size: 13px;
line-height: 1.55;
}
.compare-panel {
position: absolute;
top: 26px;
right: 26px;
width: 344px;
padding: 17px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
color: var(--white);
box-shadow: 0 18px 50px rgba(11, 32, 39, 0.2);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.panel-heading strong {
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.text-button {
padding: 0;
border: 0;
background: none;
color: #9ab0b5;
font-size: 11px;
cursor: pointer;
}
.text-button:hover {
color: white;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 4px;
margin-bottom: 12px;
padding: 4px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.055);
}
.segmented button {
padding: 8px 5px;
border: 0;
border-radius: 7px;
background: transparent;
color: #9fb2b7;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: 160ms ease;
}
.segmented button.active {
background: rgba(255, 255, 255, 0.13);
color: white;
}
.metric-card {
position: relative;
margin-top: 9px;
padding: 14px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 13px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.metric-card:hover,
.metric-card.active {
transform: translateY(-1px);
border-color: rgba(255, 255, 255, 0.19);
background: rgba(255, 255, 255, 0.075);
}
.metric-card::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
background: var(--route-color);
}
.route-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.route-title h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.015em;
}
.route-subtitle {
margin-top: 4px;
color: #849da3;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.route-dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--route-color);
box-shadow: 0 0 16px color-mix(in srgb, var(--route-color), transparent 45%);
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 0.9fr 0.9fr;
gap: 10px;
margin-top: 15px;
}
.metric-label {
color: #829ba1;
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric-value {
margin-top: 4px;
color: white;
font-size: 19px;
font-weight: 730;
letter-spacing: -0.035em;
}
.metric-value small {
color: #8fa5aa;
font-size: 10px;
font-weight: 600;
letter-spacing: 0;
}
.meter {
height: 3px;
margin-top: 14px;
overflow: hidden;
border-radius: 4px;
background: rgba(255, 255, 255, 0.08);
}
.meter span {
display: block;
height: 100%;
width: var(--meter-width);
border-radius: inherit;
background: var(--route-color);
}
.overlay-toggle {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
margin-top: 12px;
padding: 12px 13px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
color: #d9e6e8;
font-size: 11px;
font-weight: 700;
cursor: pointer;
}
.switch {
position: relative;
width: 32px;
height: 18px;
border-radius: 20px;
background: #41565c;
transition: 180ms ease;
}
.switch::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 12px;
height: 12px;
border-radius: 50%;
background: white;
transition: 180ms ease;
}
.overlay-toggle.active .switch {
background: #20bfae;
}
.overlay-toggle.active .switch::after {
transform: translateX(14px);
}
.panel-note {
margin: 11px 2px 0;
color: #789197;
font-size: 10px;
line-height: 1.5;
}
.comparison {
margin-top: 12px;
padding: 12px;
border-radius: 10px;
background: rgba(0, 0, 0, 0.14);
color: #a8bcc1;
font-size: 11px;
line-height: 1.5;
}
.comparison strong {
color: white;
font-weight: 720;
}
.legend {
position: absolute;
bottom: 29px;
left: 34px;
display: flex;
align-items: center;
gap: 20px;
padding: 11px 14px;
border: 1px solid rgba(16, 40, 47, 0.1);
border-radius: 11px;
background: rgba(239, 246, 245, 0.84);
box-shadow: 0 8px 28px rgba(28, 60, 65, 0.08);
backdrop-filter: blur(10px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #48666d;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
}
.legend-line {
width: 18px;
height: 4px;
border-radius: 4px;
background: var(--legend-color);
}
.exposure-gradient {
width: 55px;
height: 7px;
border-radius: 5px;
background: linear-gradient(90deg, #62d9e7, #e8d46f, #f06c5e);
}
.help {
position: absolute;
right: 31px;
bottom: 29px;
color: rgba(34, 64, 71, 0.66);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
}
.north {
position: absolute;
top: 31px;
left: 50%;
display: grid;
place-items: center;
width: 42px;
height: 42px;
border: 1px solid rgba(16, 40, 47, 0.12);
border-radius: 50%;
background: rgba(239, 246, 245, 0.72);
color: #31535c;
font-size: 10px;
font-weight: 850;
backdrop-filter: blur(8px);
}
.north::after {
content: "";
position: absolute;
top: 8px;
border-right: 4px solid transparent;
border-bottom: 8px solid #e07d53;
border-left: 4px solid transparent;
}
.world-labels {
position: fixed;
inset: 0;
pointer-events: none;
}
.world-label {
position: absolute;
top: 0;
left: 0;
white-space: nowrap;
transform: translate(-50%, -50%);
will-change: transform;
}
.route-label {
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 7px;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 5px 18px rgba(28, 59, 65, 0.12);
color: var(--label-color);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.place-label {
color: rgba(35, 67, 74, 0.68);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.tooltip {
position: fixed;
z-index: 10;
display: none;
max-width: 220px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 8px;
background: rgba(9, 27, 33, 0.92);
color: white;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
font-size: 11px;
line-height: 1.4;
pointer-events: none;
}
@media (max-width: 820px) {
.brand {
top: 20px;
left: 20px;
max-width: calc(100vw - 40px);
}
h1 {
font-size: 38px;
}
.brand p {
display: none;
}
.compare-panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 12px;
border-radius: 15px;
}
.panel-heading {
margin-bottom: 8px;
}
.segmented {
float: right;
width: 190px;
margin: -35px 0 0;
}
.metric-grid {
grid-template-columns: repeat(3, 1fr);
}
.metric-value {
font-size: 16px;
}
.metric-label {
font-size: 8px;
}
.route-subtitle,
.meter,
.comparison,
.panel-note {
display: none;
}
.metric-card {
padding: 11px;
}
.overlay-toggle {
margin-top: 8px;
padding: 9px 11px;
}
.legend,
.help,
.north {
display: none;
}
}
@media (max-width: 500px) {
.eyebrow {
font-size: 9px;
}
h1 {
font-size: 31px;
}
.segmented {
width: 170px;
}
.metric-card {
padding: 9px;
}
.route-title h2 {
font-size: 12px;
}
.route-dot {
width: 7px;
height: 7px;
}
.metric-value {
font-size: 14px;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="ui">
<header class="brand">
<div class="eyebrow">Havana · Walking route study</div>
<h1>Malecón<br />vs. Inland</h1>
<p>
A voxel comparison of waterfront exposure, route length, and shade along
Havana’s coastal edge and a sheltered inland alternative.
</p>
</header>
<aside class="compare-panel" aria-label="Route comparison">
<div class="panel-heading">
<strong>Route comparison</strong>
<button class="text-button" id="resetView">Reset view</button>
</div>
<div class="segmented" role="group" aria-label="Camera focus">
<button class="active" data-focus="both">Both</button>
<button data-focus="malecon">Waterfront</button>
<button data-focus="inland">Inland</button>
</div>
<article class="metric-card" data-focus="malecon" style="--route-color: var(--waterfront)">
<div class="route-title">
<div>
<h2>Malecón</h2>
<div class="route-subtitle">Open waterfront promenade</div>
</div>
<span class="route-dot"></span>
</div>
<div class="metric-grid">
<div>
<div class="metric-label">Distance</div>
<div class="metric-value"><span id="distanceMalecon">—</span> <small>km</small></div>
</div>
<div>
<div class="metric-label">Exposure</div>
<div class="metric-value"><span id="exposureMalecon">—</span><small>%</small></div>
</div>
<div>
<div class="metric-label">Shade</div>
<div class="metric-value"><span id="shadeMalecon">—</span><small>%</small></div>
</div>
</div>
<div class="meter" style="--meter-width: 82%"><span></span></div>
</article>
<article class="metric-card" data-focus="inland" style="--route-color: var(--inland)">
<div class="route-title">
<div>
<h2>Inland route</h2>
<div class="route-subtitle">Residential blocks and trees</div>
</div>
<span class="route-dot"></span>
</div>
<div class="metric-grid">
<div>
<div class="metric-label">Distance</div>
<div class="metric-value"><span id="distanceInland">—</span> <small>km</small></div>
</div>
<div>
<div class="metric-label">Exposure</div>
<div class="metric-value"><span id="exposureInland">—</span><small>%</small></div>
</div>
<div>
<div class="metric-label">Shade</div>
<div class="metric-value"><span id="shadeInland">—</span><small>%</small></div>
</div>
</div>
<div class="meter" style="--meter-width: 24%"><span></span></div>
</article>
<button class="overlay-toggle active" id="overlayToggle" aria-pressed="true">
Wave-exposure overlay
<span class="switch"></span>
</button>
<p class="panel-note">
Exposure and shade are schematic model scores, not live coastal or
meteorological measurements.
</p>
<div class="comparison" id="comparisonSummary"></div>
</aside>
<div class="legend" aria-label="Legend">
<div class="legend-item">
<span class="legend-line" style="--legend-color: var(--waterfront)"></span>
Malecón
</div>
<div class="legend-item">
<span class="legend-line" style="--legend-color: var(--inland)"></span>
Inland
</div>
<div class="legend-item">
<span class="exposure-gradient"></span>
Low → high exposure
</div>
</div>
<div class="help">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div class="north">N</div>
</div>
<div class="world-labels" id="worldLabels">
<div class="world-label route-label" id="maleconLabel" style="--label-color: #008f7b">
Malecón
</div>
<div class="world-label route-label" id="inlandLabel" style="--label-color: #b66b16">
Inland route
</div>
<div class="world-label place-label" id="havanaLabel">Havana</div>
<div class="world-label place-label" id="waterLabel">Florida Strait</div>
</div>
<div class="tooltip" id="tooltip"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe7e5);
scene.fog = new THREE.Fog(0xdbe7e5, 72, 115);
const camera = new THREE.OrthographicCamera(-30, 30, 20, -20, 0.1, 180);
const hemisphere = new THREE.HemisphereLight(0xf4fffd, 0x6c7770, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.3);
sun.position.set(-18, 42, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -40;
sun.shadow.camera.right = 40;
sun.shadow.camera.top = 40;
sun.shadow.camera.bottom = -40;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const cameraState = {
theta: 0.58,
phi: 0.87,
radius: 60,
zoom: 0.95,
target: new THREE.Vector3(3, 0, 0),
desiredTarget: new THREE.Vector3(3, 0, 0),
desiredZoom: 0.95
};
const clock = new THREE.Clock();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const routeMeshes = [];
const worldLabels = [];
const walkers = [];
let overlayVisible = true;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function mulberry32(seed) {
return function random() {
let value = (seed += 0x6d2b79f5);
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(20250308);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
}
function addBox(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material(color, options)
);
mesh.position.copy(position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
// Ground and base platforms.
const shadow = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
material(0xd6e2df)
);
shadow.rotation.x = -Math.PI / 2;
shadow.position.y = -0.7;
shadow.receiveShadow = true;
scene.add(shadow);
addBox(
scene,
new THREE.Vector3(20, 0.6, 44),
new THREE.Vector3(10, 0, 0),
0xd8c7a4
);
addBox(
scene,
new THREE.Vector3(20, 0.38, 44),
new THREE.Vector3(-10, -0.32, 0),
0x287f91
);
// Promenade and street network.
addBox(
scene,
new THREE.Vector3(3.2, 0.12, 40),
new THREE.Vector3(1.55, 0.34, 0),
0xe7d9bc
);
addBox(
scene,
new THREE.Vector3(3.6, 0.035, 36),
new THREE.Vector3(8.1, 0.315, 0),
0xc6baa0
);
for (const x of [3.5, 11.8, 20.0]) {
addBox(
scene,
new THREE.Vector3(x === 20 ? 0.3 : 2.7, 0.025, 42),
new THREE.Vector3(x, 0.318, 0),
0xb8b4a7
);
}
for (let z = -18; z <= 18; z += 6) {
addBox(
scene,
new THREE.Vector3(20, 0.025, 2.1),
new THREE.Vector3(10, 0.318, z),
0xb8b4a7
);
}
// Seawall blocks.
for (let z = -21; z <= 21; z += 2.1) {
addBox(
scene,
new THREE.Vector3(0.34, 0.62, 1.9),
new THREE.Vector3(0.02, 0.15, z),
0x8f958d
);
}
// Voxel ocean surface.
const oceanGeometry = new THREE.BoxGeometry(1.95, 0.12, 1.95);
const oceanMaterial = material(0xffffff, {
roughness: 0.65,
metalness: 0.03
});
const oceanTiles = new THREE.InstancedMesh(oceanGeometry, oceanMaterial, 220);
oceanTiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const oceanColor = new THREE.Color();
let oceanIndex = 0;
for (let ix = 0; ix < 10; ix++) {
for (let iz = 0; iz < 22; iz++) {
dummy.position.set(-19 + ix * 2, -0.08, -21 + iz * 2);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
oceanTiles.setMatrixAt(oceanIndex, dummy.matrix);
const variation = (random() - 0.5) * 0.09;
oceanColor.set(0x398fa0).offsetHSL(0, 0, variation);
oceanTiles.setColorAt(oceanIndex, oceanColor);
oceanIndex++;
}
}
oceanTiles.instanceMatrix.needsUpdate = true;
oceanTiles.instanceColor.needsUpdate = true;
scene.add(oceanTiles);
// City blocks, roofs, and street furniture.
const buildingPalette = [
0xe8ad78,
0xe9ca83,
0xb9d8c4,
0x8eb9c6,
0xd9907d,
0xe7dfc4,
0xc4b1ca
];
function addBuilding(x, z, width, depth, height) {
const color = buildingPalette[
Math.floor(random() * buildingPalette.length)
];
const building = addBox(
scene,
new THREE.Vector3(width, height, depth),
new THREE.Vector3(x, 0.43 + height / 2, z),
color
);
const roofColor = new THREE.Color(color).offsetHSL(0, -0.04, 0.07);
addBox(
scene,
new THREE.Vector3(width + 0.12, 0.14, depth + 0.12),
new THREE.Vector3(x, 0.48 + height, z),
roofColor.getHex()
);
if (random() > 0.55) {
addBox(
scene,
new THREE.Vector3(width * 0.38, 0.38, depth * 0.4),
new THREE.Vector3(x + width * 0.12, 0.7 + height, z),
0xa7b3ad
);
}
return building;
}
for (const x of [4.8, 13.5, 18.0]) {
for (const z of [-16, -10, -4, 2, 8, 14, 20]) {
if (x === 4.8 && z >= 14) continue;
const width = 1.7 + random() * 0.8;
const depth = 2.2 + random() * 1.2;
const height = 1.1 + random() * 4.1;
addBuilding(x, z, width, depth, height);
if (random() > 0.45) {
addBuilding(
x + (x === 18 ? -2.1 : 2.2),
z + (random() - 0.5) * 0.6,
1.25 + random() * 0.55,
1.6 + random() * 0.7,
0.9 + random() * 2.2
);
}
}
}
function addTree(x, z, scale = 1) {
addBox(
scene,
new THREE.Vector3(0.18 * scale, 0.8 * scale, 0.18 * scale),
new THREE.Vector3(x, 0.78 * scale, z),
0x84674b
);
addBox(
scene,
new THREE.Vector3(0.82 * scale, 0.82 * scale, 0.82 * scale),
new THREE.Vector3(x, 1.4 * scale, z),
0x5e9270
);
addBox(
scene,
new THREE.Vector3(0.58 * scale, 0.56 * scale, 0.58 * scale),
new THREE.Vector3(x + 0.12 * scale, 1.85 * scale, z),
0x79a57a
);
}
for (let z = -18; z <= 18; z += 5.5) {
addTree(3.05, z, 0.8 + random() * 0.15);
}
for (let z = -15; z <= 15; z += 7) {
addTree(10.7, z, 0.72);
}
function addLamp(x, z) {
addBox(
scene,
new THREE.Vector3(0.1, 1.25, 0.1),
new THREE.Vector3(x, 1.0, z),
0x4e6264
);
addBox(
scene,
new THREE.Vector3(0.36, 0.12, 0.36),
new THREE.Vector3(x, 1.66, z),
0xf3dfaa,
{ emissive: 0x5b4320, emissiveIntensity: 0.25 }
);
}
for (let z = -17; z <= 17; z += 6) {
addLamp(2.7, z);
}
// Schematic exposure overlay: translucent voxel cells near the coast.
const exposureColumns = [-8, -5, -2, 1, 4];
const exposureRows = 19;
const exposureGeometry = new THREE.BoxGeometry(2.45, 0.035, 1.72);
const exposureMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.29,
depthWrite: false
});
const exposureMesh = new THREE.InstancedMesh(
exposureGeometry,
exposureMaterial,
exposureColumns.length * exposureRows
);
exposureMesh.renderOrder = 2;
const lowExposure = new THREE.Color(0x62d9e7);
const midExposure = new THREE.Color(0xe8d46f);
const highExposure = new THREE.Color(0xf06c5e);
const exposureColor = new THREE.Color();
let exposureIndex = 0;
for (const x of exposureColumns) {
for (let row = 0; row < exposureRows; row++) {
const z = -20.5 + row * 2.3;
const baseExposure = THREE.MathUtils.clamp((x + 10) / 14, 0, 1);
const localVariation = Math.sin(row * 0.83 + x) * 0.055;
const exposure = THREE.MathUtils.clamp(
baseExposure + localVariation,
0,
1
);
dummy.position.set(x, x < 0 ? 0.06 : 0.345, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
exposureMesh.setMatrixAt(exposureIndex, dummy.matrix);
if (exposure < 0.5) {
exposureColor
.copy(lowExposure)
.lerp(midExposure, exposure / 0.5);
} else {
exposureColor
.copy(midExposure)
.lerp(highExposure, (exposure - 0.5) / 0.5);
}
exposureMesh.setColorAt(exposureIndex, exposureColor);
exposureIndex++;
}
}
exposureMesh.instanceMatrix.needsUpdate = true;
exposureMesh.instanceColor.needsUpdate = true;
scene.add(exposureMesh);
// Animated wave chevrons.
const waveGroup = new THREE.Group();
scene.add(waveGroup);
const waveMaterial = new THREE.LineBasicMaterial({
color: 0xbaf4ff,
transparent: true,
opacity: 0.66,
depthWrite: false
});
const waveGlyphs = [];
for (let band = 0; band < 3; band++) {
for (let i = 0; i < 7; i++) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.7, 0, -0.55),
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(-0.7, 0, 0.55)
]);
const line = new THREE.Line(geometry, waveMaterial);
line.position.set(
-15.5 + band * 4.8,
0.13,
-19 + i * 6.2 + band * 0.55
);
line.userData.baseX = line.position.x;
line.userData.band = band;
line.userData.offset = i * 0.33;
waveGroup.add(line);
waveGlyphs.push(line);
}
}
// Route definitions.
const routeDefinitions = {
malecon: {
name: "Malecón",
color: 0x20dfc0,
points: [
[1.05, -18],
[1.2, -12],
[0.82, -6],
[1.15, 0],
[0.88, 6],
[1.25, 12],
[1.0, 18]
],
exposure: 82,
shade: 18
},
inland: {
name: "Inland route",
color: 0xffb45f,
points: [
[1.05, -18],
[5.6, -16.6],
[8.9, -12.5],
[7.7, -7.2],
[9.3, -2],
[7.9, 3.1],
[9.4, 8.3],
[7.4, 13.5],
[1.0, 18]
],
exposure: 24,
shade: 71
}
};
const routeGeometry = new THREE.BoxGeometry(0.34, 0.12, 0.62);
for (const [key, definition] of Object.entries(routeDefinitions)) {
const curve = new THREE.CatmullRomCurve3(
definition.points.map(
([x, z]) => new THREE.Vector3(x, 0.52, z)
),
false,
"catmullrom",
0.25
);
definition.curve = curve;
const routeMaterial = material(definition.color, {
emissive: definition.color,
emissiveIntensity: 0.32,
roughness: 0.58
});
const samples = 155;
const routeMesh = new THREE.InstancedMesh(
routeGeometry,
routeMaterial,
samples
);
routeMesh.castShadow = true;
routeMesh.receiveShadow = true;
routeMesh.userData.routeKey = key;
for (let i = 0; i < samples; i++) {
const t = i / (samples - 1);
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
dummy.position.copy(point);
dummy.rotation.set(0, Math.atan2(tangent.x, tangent.z), 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
routeMesh.setMatrixAt(i, dummy.matrix);
}
routeMesh.instanceMatrix.needsUpdate = true;
scene.add(routeMesh);
routeMeshes.push(routeMesh);
// Shared start and finish markers.
for (const z of [-18, 18]) {
addBox(
scene,
new THREE.Vector3(0.85, 0.24, 0.85),
new THREE.Vector3(1.02, 0.58, z),
0xf7f4e9
);
addBox(
scene,
new THREE.Vector3(0.34, 0.28, 0.34),
new THREE.Vector3(0.82, 0.8, z),
definition.color,
{ emissive: definition.color, emissiveIntensity: 0.18 }
);
}
}
// Small animated voxel pedestrians.
function createWalker(color) {
const group = new THREE.Group();
const torso = addBox(
group,
new THREE.Vector3(0.3, 0.42, 0.24),
new THREE.Vector3(0, 0.53, 0),
color,
{ emissive: color, emissiveIntensity: 0.12 }
);
const head = addBox(
group,
new THREE.Vector3(0.25, 0.25, 0.25),
new THREE.Vector3(0, 0.88, 0),
0xe6b48e
);
addBox(
group,
new THREE.Vector3(0.11, 0.34, 0.12),
new THREE.Vector3(-0.09, 0.16, 0),
0x344b54
);
addBox(
group,
new THREE.Vector3(0.11, 0.34, 0.12),
new THREE.Vector3(0.09, 0.16, 0),
0x344b54
);
group.userData.torso = torso;
group.userData.head = head;
scene.add(group);
return group;
}
const walkerDefinitions = [
["malecon", 0.18],
["malecon", 0.66],
["inland", 0.38],
["inland", 0.82]
];
for (const [key, offset] of walkerDefinitions) {
const group = createWalker(routeDefinitions[key].color);
walkers.push({ group, key, offset });
}
// Route statistics. World units are converted with a schematic scale.
const KM_PER_WORLD_UNIT = 0.13;
for (const [key, definition] of Object.entries(routeDefinitions)) {
const distance = definition.curve.getLength() * KM_PER_WORLD_UNIT;
definition.distance = distance;
document.getElementById(`distance${key === "malecon" ? "Malecon" : "Inland"}`)
.textContent = distance.toFixed(1);
document.getElementById(`exposure${key === "malecon" ? "Malecon" : "Inland"}`)
.textContent = definition.exposure;
document.getElementById(`shade${key === "malecon" ? "Malecon" : "Inland"}`)
.textContent = definition.shade;
}
const distanceDifference = Math.abs(
routeDefinitions.malecon.distance - routeDefinitions.inland.distance
);
document.getElementById("comparisonSummary").innerHTML =
`The waterfront path is approximately <strong>${distanceDifference.toFixed(1)} km shorter</strong>, ` +
`but has substantially greater modeled wave exposure.`;
// DOM labels projected from 3D positions.
function registerLabel(elementId, position) {
worldLabels.push({
element: document.getElementById(elementId),
position
});
}
registerLabel("maleconLabel", new THREE.Vector3(1.1, 1.15, 8.8));
registerLabel("inlandLabel", new THREE.Vector3(9.0, 1.15, -4.8));
registerLabel("havanaLabel", new THREE.Vector3(15.0, 2.5, -22.2));
registerLabel("waterLabel", new THREE.Vector3(-12.0, 0.5, 22.0));
// Custom camera controls: no external controls module.
function updateCamera() {
cameraState.target.lerp(cameraState.desiredTarget, 0.075);
cameraState.zoom +=
(cameraState.desiredZoom - cameraState.zoom) * 0.08;
const { theta, phi, radius, target, zoom } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const frustumHeight = 36;
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
function focusView(route) {
document.querySelectorAll("[data-focus]").forEach((element) => {
element.classList.toggle(
"active",
element.dataset.focus === route
);
});
if (route === "malecon") {
cameraState.desiredTarget.set(1.5, 0, 0);
cameraState.desiredZoom = 1.65;
} else if (route === "inland") {
cameraState.desiredTarget.set(7.6, 0, 0);
cameraState.desiredZoom = 1.45;
} else {
cameraState.desiredTarget.set(3, 0, 0);
cameraState.desiredZoom = 0.95;
}
}
document.querySelectorAll("[data-focus]").forEach((element) => {
element.addEventListener("click", () => focusView(element.dataset.focus));
});
document.getElementById("resetView").addEventListener("click", () => {
focusView("both");
cameraState.theta = 0.58;
cameraState.phi = 0.87;
});
document.getElementById("overlayToggle").addEventListener("click", (event) => {
overlayVisible = !overlayVisible;
event.currentTarget.classList.toggle("active", overlayVisible);
event.currentTarget.setAttribute("aria-pressed", String(overlayVisible));
exposureMesh.visible = overlayVisible;
waveGroup.visible = overlayVisible;
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener("pointermove", (event) => {
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
if (dragging) {
if (event.shiftKey || event.buttons === 2) {
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
const towardCamera = new THREE.Vector3(
Math.sin(cameraState.theta),
0,
Math.cos(cameraState.theta)
);
const scale = 28 / cameraState.zoom / window.innerHeight;
cameraState.desiredTarget.addScaledVector(right, -dx * scale);
cameraState.desiredTarget.addScaledVector(towardCamera, dy * scale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.45,
1.22
);
}
pointerX = event.clientX;
pointerY = event.clientY;
}
updatePointer(event);
updateTooltip();
});
canvas.addEventListener("pointerleave", () => {
document.getElementById("tooltip").style.display = "none";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredZoom = THREE.MathUtils.clamp(
cameraState.desiredZoom * Math.exp(-event.deltaY * 0.001),
0.55,
2.5
);
},
{ passive: false }
);
function updatePointer(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;
}
const tooltip = document.getElementById("tooltip");
function updateTooltip() {
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(routeMeshes, false);
if (intersections.length) {
const routeKey = intersections[0].object.userData.routeKey;
const route = routeDefinitions[routeKey];
tooltip.innerHTML =
`<strong>${route.name}</strong><br>` +
`${route.distance.toFixed(1)} km · ${route.exposure}% modeled exposure`;
tooltip.style.display = "block";
tooltip.style.left =
`${Math.min(window.innerWidth - 235, pointer.x + 0)}px`;
tooltip.style.top = "18px";
} else {
tooltip.style.display = "none";
}
}
function updateWorldLabels() {
for (const label of worldLabels) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
}
}
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
for (const walker of walkers) {
const route = routeDefinitions[walker.key];
const t = (elapsed * 0.028 + walker.offset) % 1;
const point = route.curve.getPointAt(t);
const tangent = route.curve.getTangentAt(t);
walker.group.position.copy(point);
walker.group.position.y = 0.49;
walker.group.rotation.y = Math.atan2(tangent.x, tangent.z);
const stride = Math.sin(elapsed * 10 + walker.offset * 12) * 0.13;
walker.group.userData.torso.rotation.z = stride * 0.18;
walker.group.userData.head.position.y = 0.88 + Math.abs(stride) * 0.06;
}
for (const wave of waveGlyphs) {
wave.position.x =
wave.userData.baseX +
((elapsed * 0.62 + wave.userData.offset) % 2.2);
}
waveMaterial.opacity = 0.56 + Math.sin(elapsed * 1.7) * 0.08;
updateWorldLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```