Prompt specification
Build or customize the Three.js 3D scene "Compare shaded walking routes from a Creek landing" 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: Compare shaded walking routes from a Creek landing
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-shaded-walking-routes-from-a-creek-landing-x2908
Scene Description Prompt:
Compare shaded voxel walking routes through Dubai's Al Fahidi district toward the Creek. Display distance and shade separately. Three.js from cdnjs, one HTML file.
Working Three.js Starter (compare-shaded-walking-routes-from-a-creek-landing-x2908):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Al Fahidi to the Creek — Voxel Route Comparison</title>
<style>
:root {
--ink: #262722;
--muted: #716f67;
--paper: rgba(255, 252, 245, 0.94);
--line: #d9d2c6;
--shadow: 0 18px 55px rgba(54, 48, 38, 0.14);
--distance: #343936;
--shade: #557b60;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e3d8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app {
position: fixed;
inset: 0;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.glass {
background: var(--paper);
border: 1px solid rgba(117, 108, 94, 0.22);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.hero {
position: absolute;
top: 24px;
left: 24px;
z-index: 10;
width: 360px;
padding: 23px;
border-radius: 22px;
pointer-events: auto;
}
.eyebrow {
margin: 0 0 7px;
color: #8a6a45;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 3vw, 39px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 760;
}
.intro {
margin: 11px 0 19px;
max-width: 310px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.selected-header {
display: flex;
align-items: center;
gap: 9px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.route-dot {
width: 10px;
height: 10px;
border-radius: 50%;
flex: 0 0 auto;
box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.04);
}
#selectedName {
font-size: 13px;
font-weight: 760;
}
#selectedTag {
margin-left: auto;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.summary-metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 13px;
}
.summary-metric {
min-width: 0;
padding: 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.45);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 23px;
font-weight: 760;
letter-spacing: -0.04em;
white-space: nowrap;
}
.metric-sub {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.meter {
position: relative;
height: 4px;
margin-top: 10px;
overflow: hidden;
border-radius: 99px;
background: #ddd7cd;
}
.meter > span {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
transition: width 350ms ease;
}
#selectedDistanceBar {
background: var(--distance);
}
#selectedShadeBar {
background: var(--shade);
}
.hero-footer {
display: flex;
justify-content: space-between;
gap: 15px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.panel {
position: absolute;
top: 24px;
right: 24px;
z-index: 10;
width: 366px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 20px;
border-radius: 22px;
pointer-events: auto;
scrollbar-width: thin;
}
.panel-title {
display: flex;
align-items: end;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
}
.panel-title h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.025em;
}
.panel-title span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#routeList {
display: grid;
gap: 9px;
}
.route-card {
width: 100%;
padding: 13px;
border: 1px solid var(--line);
border-radius: 14px;
color: var(--ink);
background: rgba(255, 255, 255, 0.45);
text-align: left;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.route-card:hover {
transform: translateY(-1px);
border-color: #aaa193;
}
.route-card.active {
border-color: var(--route-color);
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 7px 20px rgba(53, 47, 38, 0.09);
}
.route-card-head {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
}
.route-card-head strong {
font-size: 13px;
}
.route-card-head small {
margin-left: auto;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.card-metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 14px;
}
.card-metric {
min-width: 0;
}
.card-metric .metric-label {
margin-bottom: 3px;
font-size: 8px;
}
.card-metric strong {
display: block;
font-size: 15px;
letter-spacing: -0.025em;
}
.card-meter {
height: 3px;
margin-top: 7px;
overflow: hidden;
border-radius: 99px;
background: #ddd7cd;
}
.card-meter span {
display: block;
height: 100%;
border-radius: inherit;
}
.distance-meter {
background: var(--distance);
}
.shade-meter {
background: var(--shade);
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 16px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.legend-block {
min-width: 0;
padding: 11px;
border-radius: 12px;
background: rgba(232, 226, 216, 0.55);
}
.legend-title {
margin-bottom: 9px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scale-line {
display: flex;
align-items: center;
gap: 6px;
color: #5f5e58;
font-size: 8px;
}
.scale-line i {
position: relative;
display: block;
width: 100%;
height: 3px;
border-radius: 99px;
background: var(--distance);
}
.scale-line i::after {
position: absolute;
top: -3px;
right: 0;
width: 1px;
height: 9px;
background: #6e6c65;
content: "";
}
.shade-scale {
display: flex;
align-items: center;
gap: 4px;
}
.shade-scale i {
height: 10px;
flex: 1;
border-radius: 2px;
background: #d6cdbd;
}
.shade-scale i:nth-child(2) {
background: #849b7e;
}
.shade-scale i:nth-child(3) {
background: #557b60;
}
.legend-note {
margin: 9px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.tools {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.toggle {
display: flex;
align-items: center;
gap: 8px;
color: #5c5a53;
font-size: 10px;
font-weight: 700;
cursor: pointer;
}
.toggle input {
width: 15px;
height: 15px;
margin: 0;
accent-color: var(--shade);
}
.camera-buttons {
display: flex;
gap: 5px;
}
.camera-buttons button {
min-width: 29px;
height: 28px;
padding: 0 8px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--ink);
background: rgba(255, 255, 255, 0.7);
cursor: pointer;
}
.camera-buttons button:hover {
background: #fff;
}
.disclaimer {
margin: 11px 0 0;
color: #8a877f;
font-size: 8px;
line-height: 1.45;
}
.scene-hint {
position: absolute;
left: 25px;
bottom: 24px;
z-index: 6;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border: 1px solid rgba(117, 108, 94, 0.18);
border-radius: 11px;
color: #5e5c55;
background: rgba(255, 252, 245, 0.76);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 650;
pointer-events: none;
}
.scene-hint b {
color: #292a26;
}
.compass {
position: absolute;
right: 28px;
bottom: 28px;
z-index: 6;
width: 48px;
height: 48px;
display: grid;
place-items: center;
border: 1px solid rgba(117, 108, 94, 0.22);
border-radius: 50%;
color: #3e413c;
background: rgba(255, 252, 245, 0.78);
backdrop-filter: blur(10px);
pointer-events: none;
}
.compass span {
position: absolute;
top: 3px;
font-size: 8px;
font-weight: 900;
}
.compass::after {
width: 0;
height: 0;
border-right: 5px solid transparent;
border-bottom: 18px solid #485149;
border-left: 5px solid transparent;
content: "";
transform: translateY(4px);
}
.map-label {
position: absolute;
z-index: 4;
padding: 7px 10px;
border: 1px solid rgba(117, 108, 94, 0.22);
border-radius: 9px;
color: #353630;
background: rgba(255, 252, 245, 0.88);
box-shadow: 0 6px 20px rgba(54, 48, 38, 0.1);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.035em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
}
.map-label small {
display: block;
margin-top: 2px;
color: #89857c;
font-size: 7px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.label-pin {
position: absolute;
z-index: 3;
width: 8px;
height: 8px;
border: 2px solid #fff;
border-radius: 50%;
background: #385d55;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
pointer-events: none;
transform: translate(-50%, -50%);
}
#loading {
position: absolute;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
color: #5e5b53;
background: #e9e3d8;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 980px) {
.hero {
top: 14px;
left: 14px;
width: 315px;
padding: 18px;
}
.intro {
display: none;
}
.panel {
top: auto;
right: 14px;
bottom: 14px;
width: min(430px, calc(100vw - 28px));
max-height: 46vh;
padding: 15px;
}
.scene-hint,
.compass {
display: none;
}
}
@media (max-width: 620px) {
.hero {
right: 14px;
width: auto;
}
h1 {
font-size: 27px;
}
.selected-header {
padding-top: 11px;
}
.summary-metrics {
margin-top: 10px;
}
.summary-metric {
padding: 9px;
}
.metric-value {
font-size: 19px;
}
.hero-footer {
display: none;
}
.panel {
max-height: 43vh;
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive voxel map of walking routes from Al Fahidi to Dubai Creek"></canvas>
<section class="hero glass" aria-label="Selected route details">
<p class="eyebrow">Dubai · Al Fahidi</p>
<h1>Walk to the Creek.</h1>
<p class="intro">
Compare three voxel walking routes through the heritage district.
Distance and shade are measured independently.
</p>
<div class="selected-header" aria-live="polite">
<span id="selectedDot" class="route-dot"></span>
<span id="selectedName">Heritage Lane</span>
<span id="selectedTag">Most direct</span>
</div>
<div class="summary-metrics">
<div class="summary-metric">
<span class="metric-label">Distance</span>
<strong id="selectedDistance" class="metric-value">640 m</strong>
<span id="selectedTime" class="metric-sub">About 9 min</span>
<div class="meter"><span id="selectedDistanceBar"></span></div>
</div>
<div class="summary-metric">
<span class="metric-label">Shade</span>
<strong id="selectedShade" class="metric-value">38%</strong>
<span class="metric-sub">Canopy coverage</span>
<div class="meter"><span id="selectedShadeBar"></span></div>
</div>
</div>
<div class="hero-footer">
<span id="selectedNote">A direct eastbound street crossing.</span>
<span>Illustrative route</span>
</div>
</section>
<aside class="panel glass" aria-label="Compare walking routes">
<div class="panel-title">
<h2>Compare routes</h2>
<span>Select to focus</span>
</div>
<div id="routeList"></div>
<div class="legend" aria-label="Separate distance and shade legends">
<div class="legend-block">
<div class="legend-title">Distance</div>
<div class="scale-line">
<span>0</span>
<i></i>
<span>1.5 km</span>
</div>
</div>
<div class="legend-block">
<div class="legend-title">Shade</div>
<div class="shade-scale">
<i></i><i></i><i></i>
</div>
</div>
</div>
<p class="legend-note">
Shading represents tree-canopy coverage. Darker route voxels and green
canopy blocks mark shaded sections; distance is shown separately.
</p>
<div class="tools">
<label class="toggle">
<input id="showCanopy" type="checkbox" checked />
Show canopy
</label>
<div class="camera-buttons" aria-label="Camera controls">
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button id="resetView" title="Reset view" aria-label="Reset view">↺</button>
</div>
</div>
<p class="disclaimer">
Conceptual district model. Distances, shade estimates and walking times
are illustrative and should not be used for live navigation.
</p>
</aside>
<div class="scene-hint">
<b>Drag</b> to orbit
<span>·</span>
<b>Scroll</b> to zoom
<span>·</span>
<b>Shift-drag</b> to pan
</div>
<div class="compass" aria-label="North indicator"><span>N</span></div>
<div id="startLabel" class="map-label">
Al Fahidi
<small>Starting point</small>
</div>
<div id="creekLabel" class="map-label">
Dubai Creek
<small>Destination</small>
</div>
<div id="startPin" class="label-pin"></div>
<div id="creekPin" class="label-pin"></div>
<div id="loading">Building the voxel district…</div>
</main>
<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 loading = document.querySelector("#loading");
const routes = [
{
id: "heritage",
name: "Heritage Lane",
tag: "Most direct",
color: 0xe26448,
shadeColor: 0x913c2c,
distance: 640,
shade: 38,
time: 9,
note: "A direct eastbound street crossing.",
points: [
[-38, 17],
[42, 17],
[53, 16]
]
},
{
id: "courtyard",
name: "Courtyard Meander",
tag: "More shade",
color: 0x16858c,
shadeColor: 0x0d555c,
distance: 980,
shade: 64,
time: 14,
note: "Passes the shaded courtyard streets.",
points: [
[-38, 17],
[-38, 0],
[42, 0],
[42, 16],
[53, 16]
]
},
{
id: "promenade",
name: "Creek Promenade",
tag: "Longest & coolest",
color: 0xd19b2d,
shadeColor: 0x85621c,
distance: 1420,
shade: 81,
time: 20,
note: "A longer southern loop with the most canopy.",
points: [
[-38, 17],
[-38, -24],
[42, -24],
[42, 16],
[53, 16]
]
}
];
const maxDistance = 1500;
let selectedRoute = 0;
const routeList = document.querySelector("#routeList");
const selectedDot = document.querySelector("#selectedDot");
const selectedName = document.querySelector("#selectedName");
const selectedTag = document.querySelector("#selectedTag");
const selectedDistance = document.querySelector("#selectedDistance");
const selectedTime = document.querySelector("#selectedTime");
const selectedShade = document.querySelector("#selectedShade");
const selectedDistanceBar = document.querySelector("#selectedDistanceBar");
const selectedShadeBar = document.querySelector("#selectedShadeBar");
const selectedNote = document.querySelector("#selectedNote");
const showCanopy = document.querySelector("#showCanopy");
function formatDistance(meters) {
return meters >= 1000
? `${(meters / 1000).toFixed(2)} km`
: `${Math.round(meters)} m`;
}
function hex(color) {
return `#${color.toString(16).padStart(6, "0")}`;
}
function buildRouteCards() {
routeList.innerHTML = routes
.map(
(route, index) => `
<button
class="route-card ${index === selectedRoute ? "active" : ""}"
data-route="${index}"
style="--route-color:${hex(route.color)}"
aria-pressed="${index === selectedRoute}"
>
<span class="route-card-head">
<span class="route-dot" style="background:${hex(route.color)}"></span>
<strong>${route.name}</strong>
<small>${route.tag}</small>
</span>
<span class="card-metrics">
<span class="card-metric">
<span class="metric-label">Distance</span>
<strong>${formatDistance(route.distance)}</strong>
<span class="card-meter">
<span
class="distance-meter"
style="width:${(route.distance / maxDistance) * 100}%"
></span>
</span>
</span>
<span class="card-metric">
<span class="metric-label">Shade</span>
<strong>${route.shade}%</strong>
<span class="card-meter">
<span
class="shade-meter"
style="width:${route.shade}%"
></span>
</span>
</span>
</span>
</button>
`
)
.join("");
routeList.querySelectorAll(".route-card").forEach((card) => {
card.addEventListener("click", () => {
selectRoute(Number(card.dataset.route));
});
});
}
function selectRoute(index) {
selectedRoute = index;
const route = routes[index];
routeList.querySelectorAll(".route-card").forEach((card, cardIndex) => {
card.classList.toggle("active", cardIndex === index);
card.setAttribute("aria-pressed", String(cardIndex === index));
});
selectedDot.style.background = hex(route.color);
selectedName.textContent = route.name;
selectedTag.textContent = route.tag;
selectedDistance.textContent = formatDistance(route.distance);
selectedTime.textContent = `About ${route.time} min`;
selectedShade.textContent = `${route.shade}%`;
selectedDistanceBar.style.width = `${(route.distance / maxDistance) * 100}%`;
selectedShadeBar.style.width = `${route.shade}%`;
selectedNote.textContent = route.note;
updateRouteEmphasis();
}
buildRouteCards();
// ---------------------------------------------------------------------
// Renderer, camera and lighting
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e3d8);
scene.fog = new THREE.Fog(0xe9e3d8, 145, 245);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
400
);
const cameraTarget = new THREE.Vector3(5, 0, 1);
const spherical = {
radius: 121,
phi: 0.73,
theta: 0.61
};
function updateCamera() {
const sinPhi = Math.sin(spherical.phi);
camera.position.set(
cameraTarget.x + spherical.radius * sinPhi * Math.sin(spherical.theta),
cameraTarget.y + spherical.radius * Math.cos(spherical.phi),
cameraTarget.z + spherical.radius * sinPhi * Math.cos(spherical.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff7e7, 0x8d9788, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcf, 3.25);
sun.position.set(-58, 95, 48);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -100;
sun.shadow.camera.right = 100;
sun.shadow.camera.top = 100;
sun.shadow.camera.bottom = -100;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 240;
sun.shadow.bias = -0.0007;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbdd4d3, 0.85);
fill.position.set(65, 35, -55);
scene.add(fill);
// ---------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------
let randomSeed = 72941;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function randomBetween(min, max) {
return min + (max - min) * random();
}
function makeInstancedBoxes(items, material) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const mesh = new THREE.InstancedMesh(
geometry,
material,
Math.max(items.length, 1)
);
const dummy = new THREE.Object3D();
items.forEach((item, index) => {
dummy.position.set(...item.position);
dummy.scale.set(...item.scale);
dummy.rotation.set(0, item.rotation || 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (item.color !== undefined) {
mesh.setColorAt(index, new THREE.Color(item.color));
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
return mesh;
}
function addBox(parent, size, position, color, options = {}) {
const geometry = new THREE.BoxGeometry(size[0], size[1], size[2]);
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Ground, streets and creek
// ---------------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
addBox(
world,
[158, 1, 120],
[2, -0.55, 0],
0xe7dccb,
{ castShadow: false }
);
const roadMaterial = new THREE.MeshStandardMaterial({
color: 0xd5cbbd,
roughness: 0.95
});
const roadXs = [-62, -38, -14, 12, 42];
const roadZs = [-45, -24, 0, 17, 38, 51];
roadZs.forEach((z) => {
addBox(
world,
[120, 0.08, 4.8],
[-4, 0.015, z],
roadMaterial.color,
{ castShadow: false, roughness: 0.95 }
);
});
roadXs.forEach((x) => {
addBox(
world,
[4.8, 0.08, 108],
[x, 0.025, 0],
roadMaterial.color,
{ castShadow: false, roughness: 0.95 }
);
});
// Small center marks emphasize the road grid.
const roadMarkItems = [];
[-45, -24, 0, 17, 38].forEach((z) => {
for (let x = -58; x < 49; x += 7) {
roadMarkItems.push({
position: [x, 0.085, z],
scale: [2.3, 0.035, 0.18],
color: 0xeee6d9
});
}
});
const roadMarks = makeInstancedBoxes(
roadMarkItems,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95
})
);
roadMarks.receiveShadow = true;
world.add(roadMarks);
// Creek polygon.
const shoreShape = new THREE.Shape();
shoreShape.moveTo(53, -60);
shoreShape.lineTo(78, -60);
shoreShape.lineTo(78, 60);
shoreShape.lineTo(54, 60);
shoreShape.lineTo(52, 42);
shoreShape.lineTo(55, 27);
shoreShape.lineTo(52, 10);
shoreShape.lineTo(55, -8);
shoreShape.lineTo(52, -31);
shoreShape.lineTo(53, -60);
const shoreGeometry = new THREE.ShapeGeometry(shoreShape);
shoreGeometry.rotateX(-Math.PI / 2);
const shore = new THREE.Mesh(
shoreGeometry,
new THREE.MeshStandardMaterial({
color: 0xd5c6a8,
roughness: 0.9
})
);
shore.position.y = -0.015;
shore.receiveShadow = true;
world.add(shore);
const waterShape = new THREE.Shape();
waterShape.moveTo(56, -60);
waterShape.lineTo(78, -60);
waterShape.lineTo(78, 60);
waterShape.lineTo(57, 60);
waterShape.lineTo(55, 42);
waterShape.lineTo(58, 27);
waterShape.lineTo(55, 10);
waterShape.lineTo(58, -8);
waterShape.lineTo(55, -31);
waterShape.lineTo(56, -60);
const waterGeometry = new THREE.ShapeGeometry(waterShape);
waterGeometry.rotateX(-Math.PI / 2);
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
color: 0x5c9ca0,
roughness: 0.28,
metalness: 0.04,
transparent: true,
opacity: 0.94
})
);
water.position.y = 0.01;
water.receiveShadow = true;
world.add(water);
// Voxel water tiles.
const waterTiles = [];
for (let x = 58; x <= 75; x += 3.1) {
for (let z = -55; z <= 55; z += 4.2) {
waterTiles.push({
position: [x, 0.055 + random() * 0.025, z],
scale: [2.75, 0.055, 3.65],
color: new THREE.Color(0x5c9ca0)
.offsetHSL(0, 0, randomBetween(-0.055, 0.045))
.getHex()
});
}
}
const waterTileMesh = makeInstancedBoxes(
waterTiles,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.34,
transparent: true,
opacity: 0.48
})
);
world.add(waterTileMesh);
// Creek-side quay blocks.
const quayItems = [];
for (let z = -54; z <= 54; z += 3) {
quayItems.push({
position: [54.4, 0.24, z],
scale: [2.2, 0.48, 2.75],
color: z % 2 === 0 ? 0xcbbd9f : 0xd5c7a9
});
}
const quay = makeInstancedBoxes(
quayItems,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88
})
);
quay.castShadow = true;
quay.receiveShadow = true;
world.add(quay);
// ---------------------------------------------------------------------
// Voxel architecture
// ---------------------------------------------------------------------
const buildingItems = [];
const roofItems = [];
const windowItems = [];
const detailItems = [];
function addBuilding(x, z, width, depth, height, color, options = {}) {
buildingItems.push({
position: [x, height / 2 + 0.08, z],
scale: [width, height, depth],
color
});
roofItems.push({
position: [x, height + 0.2, z],
scale: [width + 0.35, 0.24, depth + 0.35],
color: new THREE.Color(color).lerp(new THREE.Color(0xfff5df), 0.2).getHex()
});
const windowCount = Math.max(1, Math.floor(width / 1.9));
const windowWidth = Math.min(0.75, (width - 1) / windowCount - 0.45);
for (let i = 0; i < windowCount; i++) {
const wx =
x - width / 2 + 0.8 + (i * (width - 1.6)) / Math.max(1, windowCount - 1);
const floors = options.floors || Math.max(1, Math.floor(height / 3));
for (let floor = 0; floor < floors; floor++) {
const wy = 1.1 + floor * 2.25;
if (wy + 0.5 < height) {
windowItems.push({
position: [wx, wy, z + depth / 2 + 0.035],
scale: [windowWidth, 0.78, 0.07],
color: options.windowColor || 0x5a5148
});
windowItems.push({
position: [wx, wy, z - depth / 2 - 0.035],
scale: [windowWidth, 0.78, 0.07],
color: options.windowColor || 0x5a5148
});
}
}
}
if (options.windTower) {
detailItems.push({
position: [x + width * 0.28, height + 1.5, z],
scale: [0.9, 3.2, 0.9],
color: 0xbfa987
});
detailItems.push({
position: [x + width * 0.28, height + 3.15, z],
scale: [1.35, 0.25, 1.35],
color: 0xd4c19d
});
}
}
const heritagePalette = [
0xc9aa7f,
0xd2b98e,
0xbda17b,
0xd7c39d,
0xc4ad88,
0xb79b76
];
// Six traditional courtyard compounds.
const compoundCenters = [
[-26, 7],
[-2, 7],
[23, 7],
[-26, 27],
[-2, 27],
[23, 27]
];
compoundCenters.forEach(([cx, cz], compoundIndex) => {
const baseColor =
heritagePalette[(compoundIndex + 1) % heritagePalette.length];
const h = randomBetween(2.8, 4.2);
addBuilding(cx, cz - 4.25, 11.8, 3.7, h, baseColor, {
floors: 1,
windTower: compoundIndex % 2 === 0
});
addBuilding(cx, cz + 4.25, 11.8, 3.7, h * 0.92, baseColor, {
floors: 1
});
addBuilding(cx - 4.8, cz, 3.7, 5.2, h * 0.86, baseColor, {
floors: 1
});
addBuilding(cx + 4.8, cz, 3.7, 5.2, h * 0.95, baseColor, {
floors: 1,
windTower: compoundIndex % 3 === 0
});
});
// Smaller perimeter buildings.
const smallBlocks = [
[-34, -17, -20, -6],
[-11, 9, -20, -6],
[15, 39, -20, -6],
[-34, -17, 40, 49],
[-11, 9, 40, 49],
[15, 39, 40, 49],
[-62, -43, -18, -7],
[-62, -43, 3, 13],
[-62, -43, 21, 34]
];
smallBlocks.forEach(([x1, x2, z1, z2]) => {
const columns = Math.max(1, Math.floor((x2 - x1) / 8));
const rows = Math.max(1, Math.floor((z2 - z1) / 8));
for (let column = 0; column < columns; column++) {
for (let row = 0; row < rows; row++) {
if (random() < 0.22) continue;
const x = randomBetween(x1 + 1, x2 - 1);
const z = randomBetween(z1 + 1, z2 - 1);
const width = randomBetween(3.5, 6.5);
const depth = randomBetween(3.5, 6);
const height = randomBetween(2.2, 5.7);
addBuilding(
x,
z,
width,
depth,
height,
heritagePalette[Math.floor(random() * heritagePalette.length)],
{ floors: Math.max(1, Math.floor(height / 3)) }
);
}
}
});
// Contemporary skyline around the old district.
const towerPalette = [
0xb9b5aa,
0xc7c1b5,
0xaaa9a2,
0xd1c9b9,
0xb5beb9
];
for (let i = 0; i < 24; i++) {
const x = randomBetween(-60, 48);
const z = randomBetween(-42, -31);
const width = randomBetween(3.8, 7.2);
const depth = randomBetween(3.8, 7.2);
const height = randomBetween(10, 30);
addBuilding(
x,
z,
width,
depth,
height,
towerPalette[Math.floor(random() * towerPalette.length)],
{
floors: Math.floor(height / 2.6),
windowColor: 0x687476
}
);
}
for (let i = 0; i < 10; i++) {
const x = randomBetween(-60, -45);
const z = randomBetween(-18, 35);
const width = randomBetween(4.5, 7);
const depth = randomBetween(4.5, 7.5);
const height = randomBetween(11, 27);
addBuilding(
x,
z,
width,
depth,
height,
towerPalette[Math.floor(random() * towerPalette.length)],
{
floors: Math.floor(height / 2.6),
windowColor: 0x687476
}
);
}
const buildingMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.86
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9
});
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.42,
metalness: 0.05
});
const detailMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.84
});
const buildingMesh = makeInstancedBoxes(buildingItems, buildingMaterial);
buildingMesh.castShadow = true;
buildingMesh.receiveShadow = true;
world.add(buildingMesh);
const roofMesh = makeInstancedBoxes(roofItems, roofMaterial);
roofMesh.castShadow = true;
roofMesh.receiveShadow = true;
world.add(roofMesh);
const windowMesh = makeInstancedBoxes(windowItems, windowMaterial);
windowMesh.castShadow = false;
windowMesh.receiveShadow = true;
world.add(windowMesh);
const detailMesh = makeInstancedBoxes(detailItems, detailMaterial);
detailMesh.castShadow = true;
detailMesh.receiveShadow = true;
world.add(detailMesh);
// ---------------------------------------------------------------------
// Route sampling and voxel routes
// ---------------------------------------------------------------------
function samplePolyline(points, spacing = 1.15) {
const samples = [];
let cumulative = 0;
for (let segment = 0; segment < points.length - 1; segment++) {
const [x1, z1] = points[segment];
const [x2, z2] = points[segment + 1];
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const steps = Math.max(1, Math.ceil(length / spacing));
for (let step = 0; step < steps; step++) {
const t = step / steps;
const x = x1 + dx * t;
const z = z1 + dz * t;
samples.push({
x,
z,
dx: dx / length,
dz: dz / length,
cumulative
});
cumulative += length / steps;
}
}
const last = points[points.length - 1];
samples.push({
x: last[0],
z: last[1],
dx: 0,
dz: 1,
cumulative
});
samples.total = cumulative;
return samples;
}
function sampleAt(samples, normalized) {
const target = THREE.MathUtils.clamp(normalized, 0, 1) * samples.total;
let low = 0;
let high = samples.length - 1;
while (low < high) {
const middle = Math.floor((low + high) / 2);
if (samples[middle].cumulative < target) low = middle + 1;
else high = middle;
}
const index = Math.max(1, low);
const previous = samples[index - 1];
const current = samples[index];
const span = current.cumulative - previous.cumulative || 1;
const t = (target - previous.cumulative) / span;
return {
x: THREE.MathUtils.lerp(previous.x, current.x, t),
z: THREE.MathUtils.lerp(previous.z, current.z, t),
dx: current.dx,
dz: current.dz
};
}
const routeMeshes = [];
const routeGroups = [];
routes.forEach((route, routeIndex) => {
const samples = samplePolyline(route.points);
const shadeCount = Math.round((samples.length * route.shade) / 100);
const scored = samples.map((sample, index) => ({
index,
score: random()
}));
scored.sort((a, b) => a.score - b.score);
const shadedIndices = new Set(
scored.slice(0, shadeCount).map((entry) => entry.index)
);
const lightItems = [];
const darkItems = [];
const canopyItems = [];
const trunkItems = [];
samples.forEach((sample, index) => {
const y = 0.18 + routeIndex * 0.025;
const item = {
position: [sample.x, y, sample.z],
scale: [0.72, 0.16, 0.72]
};
if (shadedIndices.has(index)) {
darkItems.push(item);
if (index % 2 === 0) {
const side = index % 4 < 2 ? 1 : -1;
const perpendicularX = -sample.dz * side * 3.05;
const perpendicularZ = sample.dx * side * 3.05;
canopyItems.push({
position: [
sample.x + perpendicularX,
1.75 + randomBetween(-0.12, 0.2),
sample.z + perpendicularZ
],
scale: [
randomBetween(1.15, 1.55),
randomBetween(1.05, 1.45),
randomBetween(1.15, 1.55)
],
color: random() > 0.5 ? 0x668469 : 0x789371
});
trunkItems.push({
position: [
sample.x + perpendicularX,
0.78,
sample.z + perpendicularZ
],
scale: [0.22, 1.45, 0.22],
color: 0x79624d
});
}
} else {
lightItems.push(item);
}
});
const lightMaterial = new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.98,
depthWrite: false
});
const darkMaterial = new THREE.MeshBasicMaterial({
color: route.shadeColor,
transparent: true,
opacity: 0.98,
depthWrite: false
});
const lightMesh = makeInstancedBoxes(lightItems, lightMaterial);
const darkMesh = makeInstancedBoxes(darkItems, darkMaterial);
lightMesh.userData.routeIndex = routeIndex;
darkMesh.userData.routeIndex = routeIndex;
routeMeshes.push(lightMesh, darkMesh);
world.add(lightMesh, darkMesh);
const canopyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
transparent: true,
opacity: 0.88,
depthWrite: false
});
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9,
transparent: true,
opacity: 0.88,
depthWrite: false
});
const canopyMesh = makeInstancedBoxes(canopyItems, canopyMaterial);
const trunkMesh = makeInstancedBoxes(trunkItems, trunkMaterial);
canopyMesh.castShadow = true;
trunkMesh.castShadow = true;
world.add(canopyMesh, trunkMesh);
routeGroups.push({
samples,
lightMaterial,
darkMaterial,
canopyMaterial,
trunkMaterial,
canopyMesh,
trunkMesh
});
});
function updateRouteEmphasis() {
routeGroups.forEach((group, index) => {
const active = index === selectedRoute;
group.lightMaterial.opacity = active ? 0.99 : 0.19;
group.darkMaterial.opacity = active ? 0.99 : 0.15;
group.canopyMaterial.opacity = active ? 0.88 : 0.08;
group.trunkMaterial.opacity = active ? 0.88 : 0.08;
group.lightMaterial.depthWrite = active;
group.darkMaterial.depthWrite = active;
});
}
updateRouteEmphasis();
// ---------------------------------------------------------------------
// Start and destination markers
// ---------------------------------------------------------------------
const startMarker = new THREE.Group();
startMarker.position.set(-38, 0.18, 17);
const startBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.55, 1.55, 0.28, 24),
new THREE.MeshStandardMaterial({ color: 0xf8f1df, roughness: 0.75 })
);
startBase.position.y = 0.14;
startBase.castShadow = true;
startMarker.add(startBase);
const startCore = new THREE.Mesh(
new THREE.CylinderGeometry(0.62, 0.62, 0.34, 24),
new THREE.MeshStandardMaterial({ color: 0x3c5149, roughness: 0.75 })
);
startCore.position.y = 0.38;
startCore.castShadow = true;
startMarker.add(startCore);
world.add(startMarker);
const endMarker = new THREE.Group();
endMarker.position.set(54.1, 0.2, 16);
const endStem = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 3.1, 0.32),
new THREE.MeshStandardMaterial({ color: 0x334640, roughness: 0.8 })
);
endStem.position.y = 1.55;
endStem.castShadow = true;
endMarker.add(endStem);
const endCube = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 1.35, 1.35),
new THREE.MeshStandardMaterial({ color: 0xe56a4d, roughness: 0.68 })
);
endCube.position.y = 3.25;
endCube.rotation.y = Math.PI / 4;
endCube.castShadow = true;
endMarker.add(endCube);
world.add(endMarker);
// ---------------------------------------------------------------------
// Small walking figures
// ---------------------------------------------------------------------
const walkers = [];
function createWalker(color, offset) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.85, 0.36),
new THREE.MeshStandardMaterial({ color, roughness: 0.7 })
);
body.position.y = 1.03;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.BoxGeometry(0.4, 0.4, 0.4),
new THREE.MeshStandardMaterial({ color: 0xd6a77e, roughness: 0.85 })
);
head.position.y = 1.68;
head.castShadow = true;
group.add(head);
const legMaterial = new THREE.MeshStandardMaterial({
color: 0x35413d,
roughness: 0.8
});
const leftLeg = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.62, 0.18),
legMaterial
);
leftLeg.position.set(-0.14, 0.38, 0);
leftLeg.castShadow = true;
group.add(leftLeg);
const rightLeg = leftLeg.clone();
rightLeg.position.x = 0.14;
group.add(rightLeg);
world.add(group);
walkers.push({ group, leftLeg, rightLeg, offset });
}
createWalker(0xe26448, 0.08);
createWalker(0x2d6470, 0.48);
createWalker(0xd8b35f, 0.79);
// ---------------------------------------------------------------------
// Camera controls implemented without add-ons
// ---------------------------------------------------------------------
const pointer = {
down: false,
moved: false,
button: 0,
x: 0,
y: 0,
startX: 0,
startY: 0
};
canvas.addEventListener("pointerdown", (event) => {
pointer.down = true;
pointer.moved = false;
pointer.button = event.button;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.down) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
if (
Math.abs(event.clientX - pointer.startX) +
Math.abs(event.clientY - pointer.startY) >
4
) {
pointer.moved = true;
}
if (pointer.button === 2 || event.shiftKey) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.setY(0)
.normalize();
const forward = cameraTarget
.clone()
.sub(camera.position)
.setY(0)
.normalize();
const scale = spherical.radius * 0.00135;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(forward, -dy * scale);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -55, 55);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -45, 45);
} else {
spherical.theta -= dx * 0.0055;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.0048,
0.35,
1.23
);
}
pointer.x = event.clientX;
pointer.y = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
pointer.down = false;
canvas.releasePointerCapture(event.pointerId);
if (!pointer.moved) {
const rect = canvas.getBoundingClientRect();
const pointerNdc = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(pointerNdc, camera);
const hits = raycaster.intersectObjects(routeMeshes, false);
if (hits.length) {
selectRoute(hits[0].object.userData.routeIndex);
}
}
});
canvas.addEventListener("pointercancel", () => {
pointer.down = false;
});
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
58,
185
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#zoomIn").addEventListener("click", () => {
spherical.radius = Math.max(58, spherical.radius * 0.86);
updateCamera();
});
document.querySelector("#zoomOut").addEventListener("click", () => {
spherical.radius = Math.min(185, spherical.radius * 1.16);
updateCamera();
});
document.querySelector("#resetView").addEventListener("click", () => {
cameraTarget.set(5, 0, 1);
spherical.radius = 121;
spherical.phi = 0.73;
spherical.theta = 0.61;
updateCamera();
});
showCanopy.addEventListener("change", () => {
routeGroups.forEach((group) => {
group.canopyMesh.visible = showCanopy.checked;
group.trunkMesh.visible = showCanopy.checked;
});
});
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const startLabel = document.querySelector("#startLabel");
const creekLabel = document.querySelector("#creekLabel");
const startPin = document.querySelector("#startPin");
const creekPin = document.querySelector("#creekPin");
function projectLabel(element, pin, worldPosition, offsetY = 0) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
element.style.display = visible ? "block" : "none";
pin.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y + offsetY}px`;
pin.style.left = `${x}px`;
pin.style.top = `${y}px`;
}
const startWorld = new THREE.Vector3(-38, 1, 17);
const creekWorld = new THREE.Vector3(56, 2.6, 16);
function updateLabels() {
projectLabel(startLabel, startPin, startWorld, -29);
projectLabel(creekLabel, creekPin, creekWorld, -27);
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const activeSamples = routeGroups[selectedRoute].samples;
const motionTime = reducedMotion ? elapsed * 0.25 : elapsed;
walkers.forEach((walker, index) => {
const t = (motionTime * 0.027 + walker.offset) % 1;
const sample = sampleAt(activeSamples, t);
walker.group.position.set(sample.x, 0.05, sample.z);
walker.group.rotation.y = Math.atan2(sample.dx, sample.dz);
const stride = reducedMotion ? 0 : Math.sin(motionTime * 8 + index) * 0.3;
walker.leftLeg.rotation.x = stride;
walker.rightLeg.rotation.x = -stride;
});
const waterOffset = reducedMotion ? 0 : Math.sin(elapsed * 0.35) * 0.012;
water.position.y = 0.01 + waterOffset;
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
}
window.addEventListener("resize", resize);
selectRoute(0);
renderer.render(scene, camera);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
animate();
</script>
</body>
</html>
```