Prompt specification
Build or customize the Three.js 3D scene "Tide-window route planning diorama" 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: Tide-window route planning diorama
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tide-window-route-planning-diorama-x1260
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Offer several walking routes across a stylized intertidal area; mark submerged segments from terrain height and water level, explicitly avoiding real navigation or safety advice.
Working Three.js Starter (tide-window-route-planning-diorama-x1260):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intertidal — Low-Poly Route Study</title>
<style>
:root {
color-scheme: dark;
--ink: #f4f1e8;
--muted: #acb9b7;
--panel: rgba(17, 29, 32, 0.88);
--panel-edge: rgba(224, 242, 237, 0.14);
--cyan: #4cecff;
--sand: #e8d29c;
--shadow: 0 18px 60px rgba(0, 0, 0, 0.26);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aec9cd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.glass {
background: var(--panel);
border: 1px solid var(--panel-edge);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(125%);
-webkit-backdrop-filter: blur(18px) saturate(125%);
}
header {
position: fixed;
top: 18px;
left: 18px;
z-index: 5;
max-width: min(520px, calc(100vw - 410px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: #d4e3df;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 42px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 0.98;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.35);
}
.subtitle {
margin-top: 9px;
color: rgba(247, 251, 247, 0.82);
font-size: 12px;
line-height: 1.45;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}
.badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 11px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.17);
border-radius: 999px;
background: rgba(15, 30, 33, 0.55);
color: #d8e7e3;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
content: "";
}
#panel {
position: fixed;
top: 18px;
right: 18px;
z-index: 6;
width: 348px;
max-height: calc(100vh - 92px);
overflow: auto;
border-radius: 18px;
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.panel-section {
padding: 16px;
border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}
.panel-section:last-child {
border-bottom: 0;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.section-heading h2 {
margin: 0;
color: #e8efeb;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.value {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-size: 12px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 7px 0 3px;
border-radius: 99px;
appearance: none;
background: linear-gradient(90deg, #294e58, #4cecff);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #15272b;
border-radius: 50%;
appearance: none;
background: #dffcff;
box-shadow: 0 0 0 1px rgba(76, 236, 255, 0.8), 0 0 18px rgba(76, 236, 255, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #15272b;
border-radius: 50%;
background: #dffcff;
box-shadow: 0 0 0 1px rgba(76, 236, 255, 0.8);
}
.range-labels {
display: flex;
justify-content: space-between;
color: #829895;
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.helper {
margin: 9px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
#route-list {
display: grid;
gap: 8px;
}
.route-card {
position: relative;
display: grid;
grid-template-columns: 34px 1fr;
gap: 10px;
align-items: start;
padding: 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}
.route-card:hover {
transform: translateY(-1px);
border-color: rgba(255, 255, 255, 0.18);
background: rgba(255, 255, 255, 0.055);
}
.route-card.selected {
border-color: rgba(76, 236, 255, 0.38);
background: rgba(76, 236, 255, 0.065);
}
.route-swatch {
width: 30px;
height: 30px;
border: 2px solid var(--route-color);
border-radius: 50%;
background:
linear-gradient(90deg, transparent 43%, var(--route-color) 44%, var(--route-color) 56%, transparent 57%),
rgba(255, 255, 255, 0.04);
box-shadow: inset 0 0 0 6px rgba(0, 0, 0, 0.13);
}
.route-name {
margin: 0 0 4px;
color: #f1f4ed;
font-size: 12px;
font-weight: 720;
}
.route-description {
margin: 0 0 7px;
color: #91a5a2;
font-size: 10px;
line-height: 1.4;
}
.route-meta {
color: #c1d0cc;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.route-meta .wet {
color: var(--cyan);
}
.route-card input {
position: absolute;
top: 10px;
right: 10px;
width: 13px;
height: 13px;
accent-color: var(--route-color);
cursor: pointer;
}
#route-detail {
margin-top: 12px;
padding: 13px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.035);
}
#route-detail h3 {
margin: 0;
font-size: 15px;
font-weight: 700;
}
#route-detail p {
margin: 7px 0 11px;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 11px;
}
.metric {
padding: 9px;
border-radius: 9px;
background: rgba(0, 0, 0, 0.14);
}
.metric-label {
color: #7f9591;
font-size: 8px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.metric-value {
margin-top: 3px;
color: #eef3ec;
font-size: 12px;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
button {
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
padding: 8px 10px;
background: rgba(255, 255, 255, 0.065);
color: #e8efea;
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(76, 236, 255, 0.38);
background: rgba(76, 236, 255, 0.1);
}
#probe-readout {
min-height: 37px;
color: #a9bbb7;
font-size: 10px;
line-height: 1.55;
}
#legend {
position: fixed;
left: 18px;
bottom: 60px;
z-index: 5;
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
max-width: 510px;
padding: 10px 12px;
border-radius: 12px;
color: #d4dfda;
font-size: 9px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.legend-line {
width: 22px;
height: 4px;
border-radius: 99px;
background: #f2c35c;
}
.legend-line.flooded {
background: var(--cyan);
box-shadow: 0 0 9px rgba(76, 236, 255, 0.6);
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #f4ead0;
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18);
}
#controls {
position: fixed;
right: 18px;
bottom: 60px;
z-index: 5;
display: flex;
gap: 7px;
}
#controls button {
background: rgba(17, 29, 32, 0.84);
backdrop-filter: blur(12px);
}
#disclaimer {
position: fixed;
right: 18px;
bottom: 16px;
left: 18px;
z-index: 7;
display: flex;
justify-content: space-between;
gap: 18px;
color: rgba(238, 246, 240, 0.86);
font-size: 9px;
line-height: 1.45;
text-shadow: 0 1px 8px rgba(0, 0, 0, 0.65);
pointer-events: none;
}
#disclaimer strong {
color: #fff3cf;
font-weight: 800;
letter-spacing: 0.08em;
}
#control-hint {
flex-shrink: 0;
color: rgba(239, 245, 240, 0.7);
text-align: right;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #15282c;
color: #c9dad5;
font-size: 11px;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
header {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
}
h1 {
font-size: 26px;
}
.subtitle {
display: none;
}
#panel {
top: auto;
right: 12px;
bottom: 54px;
width: min(350px, calc(100vw - 24px));
max-height: 47vh;
}
#legend {
display: none;
}
#controls {
top: 12px;
right: 12px;
bottom: auto;
}
#controls button {
padding: 7px 8px;
font-size: 9px;
}
#disclaimer {
right: 12px;
bottom: 10px;
left: 12px;
font-size: 8px;
}
#control-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly intertidal visualization"></div>
<header>
<div class="badge">Fictional procedural terrain</div>
<div class="eyebrow">Low-poly field study</div>
<h1>Intertidal Routes</h1>
<div class="subtitle">
Explore several illustrative walking-route concepts. Change the visual water
level to reveal terrain-based submerged segments.
</div>
</header>
<aside id="panel" class="glass" aria-label="Scene controls">
<section class="panel-section">
<div class="section-heading">
<h2>Visual water level</h2>
<span id="water-readout" class="value">+0.0</span>
</div>
<input
id="water-slider"
type="range"
min="-2"
max="3.5"
step="0.1"
value="0"
aria-label="Visual water level"
>
<div class="range-labels">
<span>Lower</span>
<span>Model units</span>
<span>Higher</span>
</div>
<p class="helper">
Cyan route segments are sampled where terrain elevation is below the
selected visual water level.
</p>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Illustrative routes</h2>
<span class="value">4 concepts</span>
</div>
<div id="route-list"></div>
<div id="route-detail"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Elevation probe</h2>
<span class="value">Click terrain</span>
</div>
<div id="probe-readout">
Select a point on the terrain to compare its model elevation with the
current visual water level.
</div>
</section>
</aside>
<div id="legend" class="glass" aria-label="Legend">
<div class="legend-item">
<span class="legend-line"></span>
<span>Route above current water</span>
</div>
<div class="legend-item">
<span class="legend-line flooded"></span>
<span>Terrain below current water</span>
</div>
<div class="legend-item">
<span class="legend-dot"></span>
<span>Route endpoint</span>
</div>
</div>
<div id="controls">
<button id="view-reset" type="button">Reset view</button>
<button id="view-top" type="button">Plan view</button>
</div>
<footer id="disclaimer">
<span>
<strong>Fictional visualization only.</strong>
Not for navigation, access planning, tide prediction, hazard assessment,
or safety decisions.
</span>
<span id="control-hint">Drag to orbit · Shift/right-drag to pan · Wheel/pinch to zoom</span>
</footer>
<div id="loading">Building intertidal terrain…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const WORLD = {
width: 110,
depth: 78,
segmentsX: 55,
segmentsZ: 39
};
let waterLevel = 0;
let selectedRoute = null;
let probeHeight = null;
let waterUpdateQueued = false;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaecbd0);
scene.fog = new THREE.Fog(0xaecbd0, 92, 185);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
350
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.getElementById("scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe2f5f4, 0x536151, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd0, 3.2);
sun.position.set(-38, 62, 31);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -70;
sun.shadow.camera.right = 70;
sun.shadow.camera.top = 58;
sun.shadow.camera.bottom = -58;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
sun.shadow.bias = -0.0004;
scene.add(sun);
// ------------------------------------------------------------
// Deterministic procedural terrain
// ------------------------------------------------------------
function terrainHeight(x, z) {
const shoreline =
3.1 * Math.tanh(
(z + 8 + 4.5 * Math.sin(x * 0.11) + 3 * Math.cos(x * 0.23)) / 8
);
const westSandbar =
3.2 * Math.exp(
-(
Math.pow((x + 23) / 20, 2) +
Math.pow((z - 7) / 14, 2)
)
);
const eastSandbar =
2.5 * Math.exp(
-(
Math.pow((x - 16) / 15, 2) +
Math.pow((z + 3) / 12, 2)
)
);
const northShelf =
2.1 * Math.exp(
-(
Math.pow((x - 4) / 28, 2) +
Math.pow((z - 26) / 10, 2)
)
);
const channel =
1.7 * Math.exp(
-(
Math.pow((x + 2) / 8, 2) +
Math.pow((z - 7) / 30, 2)
)
);
const smallRelief =
0.18 * Math.sin(x * 0.34 + z * 0.21) +
0.12 * Math.cos(x * 0.17 - z * 0.29);
return shoreline + westSandbar + eastSandbar + northShelf - channel + smallRelief;
}
function hashNoise(n) {
const v = Math.sin(n * 12.9898 + 78.233) * 43758.5453;
return v - Math.floor(v);
}
function terrainColor(height) {
const deep = new THREE.Color(0x28586c);
const wet = new THREE.Color(0x648780);
const sand = new THREE.Color(0xb8aa7b);
const marsh = new THREE.Color(0x788f69);
if (height < -1.5) {
return deep.clone().lerp(wet, THREE.MathUtils.clamp((height + 4) / 2.5, 0, 1));
}
if (height < 0.7) {
return wet.clone().lerp(sand, THREE.MathUtils.clamp((height + 1.5) / 2.2, 0, 1));
}
if (height < 2.2) {
return sand.clone().lerp(marsh, (height - 0.7) / 1.5);
}
return marsh.clone();
}
function createTerrain() {
const positions = [];
const colors = [];
const dx = WORLD.width / WORLD.segmentsX;
const dz = WORLD.depth / WORLD.segmentsZ;
function point(x, z) {
return new THREE.Vector3(x, terrainHeight(x, z), z);
}
function pushTriangle(a, b, c, color) {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
let triangleIndex = 0;
for (let iz = 0; iz < WORLD.segmentsZ; iz++) {
const z0 = -WORLD.depth / 2 + iz * dz;
const z1 = z0 + dz;
for (let ix = 0; ix < WORLD.segmentsX; ix++) {
const x0 = -WORLD.width / 2 + ix * dx;
const x1 = x0 + dx;
const a = point(x0, z0);
const b = point(x1, z0);
const c = point(x1, z1);
const d = point(x0, z1);
const averageHeight = (a.y + b.y + c.y + d.y) / 4;
const variation = 0.91 + hashNoise(ix * 71 + iz * 173) * 0.17;
const color = terrainColor(averageHeight).multiplyScalar(variation);
if ((ix + iz) % 2 === 0) {
pushTriangle(a, c, b, color);
pushTriangle(a, d, c, color.clone().multiplyScalar(0.985));
} else {
pushTriangle(a, d, b, color);
pushTriangle(b, d, c, color.clone().multiplyScalar(0.985));
}
triangleIndex += 2;
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.97,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const terrainMesh = createTerrain();
// ------------------------------------------------------------
// Water surface, decorative wave lines, and shoreline contour
// ------------------------------------------------------------
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x38aac4,
transparent: true,
opacity: 0.54,
roughness: 0.22,
metalness: 0.03,
depthWrite: false,
side: THREE.DoubleSide
});
const waterMesh = new THREE.Mesh(
new THREE.PlaneGeometry(145, 112),
waterMaterial
);
waterMesh.rotation.x = -Math.PI / 2;
waterMesh.position.y = waterLevel;
waterMesh.renderOrder = 1;
scene.add(waterMesh);
const waveGroup = new THREE.Group();
const waveMaterial = new THREE.LineBasicMaterial({
color: 0xe5ffff,
transparent: true,
opacity: 0.16,
depthWrite: false
});
for (let row = 0; row < 11; row++) {
const points = [];
const baseZ = -42 + row * 8.5;
for (let i = 0; i <= 70; i++) {
const x = -70 + (i / 70) * 140;
const z =
baseZ +
Math.sin(i * 0.32 + row * 1.4) * 0.55 +
Math.cos(i * 0.14 + row) * 0.28;
points.push(new THREE.Vector3(x, 0, z));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
waveGroup.add(new THREE.Line(geometry, waveMaterial));
}
waveGroup.position.y = waterLevel + 0.09;
waveGroup.renderOrder = 3;
scene.add(waveGroup);
const contourMaterial = new THREE.LineBasicMaterial({
color: 0xe6fff2,
transparent: true,
opacity: 0.52,
depthWrite: false
});
let contourLine = new THREE.LineSegments(
new THREE.BufferGeometry(),
contourMaterial
);
contourLine.renderOrder = 4;
scene.add(contourLine);
function rebuildShorelineContour() {
const positions = [];
const nx = 80;
const nz = 58;
const dx = WORLD.width / nx;
const dz = WORLD.depth / nz;
function intersection(a, b, ha, hb) {
if ((ha < 0) === (hb < 0)) return null;
const t = -ha / (hb - ha);
return new THREE.Vector3(
THREE.MathUtils.lerp(a[0], b[0], t),
waterLevel + 0.12,
THREE.MathUtils.lerp(a[1], b[1], t)
);
}
for (let iz = 0; iz < nz; iz++) {
const z0 = -WORLD.depth / 2 + iz * dz;
const z1 = z0 + dz;
for (let ix = 0; ix < nx; ix++) {
const x0 = -WORLD.width / 2 + ix * dx;
const x1 = x0 + dx;
const p = [
[x0, z0],
[x1, z0],
[x1, z1],
[x0, z1]
];
const h = p.map(([x, z]) => terrainHeight(x, z) - waterLevel);
const hits = [];
for (let edge = 0; edge < 4; edge++) {
const next = (edge + 1) % 4;
const hit = intersection(p[edge], p[next], h[edge], h[next]);
if (hit) hits.push(hit);
}
if (hits.length >= 2) {
positions.push(
hits[0].x, hits[0].y, hits[0].z,
hits[1].x, hits[1].y, hits[1].z
);
if (hits.length >= 4) {
positions.push(
hits[2].x, hits[2].y, hits[2].z,
hits[3].x, hits[3].y, hits[3].z
);
}
}
}
}
contourLine.geometry.dispose();
contourLine.geometry = new THREE.BufferGeometry();
contourLine.geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
}
// ------------------------------------------------------------
// Low-poly rocks and reed tufts
// ------------------------------------------------------------
function createDecorations() {
let seed = 918273;
const random = () => {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
};
const rockGeometry = new THREE.DodecahedronGeometry(1, 0);
const rockMaterials = [
new THREE.MeshStandardMaterial({
color: 0x66716b,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x857d69,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x52645f,
roughness: 1,
flatShading: true
})
];
for (let i = 0; i < 92; i++) {
const x = (random() - 0.5) * WORLD.width * 0.94;
const z = (random() - 0.5) * WORLD.depth * 0.94;
const h = terrainHeight(x, z);
const size = 0.38 + random() * 1.55;
const rock = new THREE.Mesh(
rockGeometry,
rockMaterials[Math.floor(random() * rockMaterials.length)]
);
rock.position.set(x, h + size * 0.38, z);
rock.scale.set(size * (0.8 + random() * 0.5), size * 0.68, size);
rock.rotation.set(random() * 0.4, random() * Math.PI, random() * 0.25);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
const grassPositions = [];
for (let i = 0; i < 260; i++) {
const x = (random() - 0.5) * WORLD.width * 0.92;
const z = (random() - 0.5) * WORLD.depth * 0.92;
const h = terrainHeight(x, z);
if (h > 1.05) {
grassPositions.push({
x,
z,
h,
rotation: random() * Math.PI * 2,
scale: 0.65 + random() * 0.95
});
}
}
const grassGeometry = new THREE.ConeGeometry(0.23, 1.4, 5);
grassGeometry.translate(0, 0.7, 0);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0x486b53,
roughness: 1,
flatShading: true
});
const grass = new THREE.InstancedMesh(
grassGeometry,
grassMaterial,
grassPositions.length
);
const dummy = new THREE.Object3D();
grassPositions.forEach((item, index) => {
dummy.position.set(item.x, item.h, item.z);
dummy.rotation.set(0, item.rotation, 0);
dummy.scale.set(1, item.scale, 1);
dummy.updateMatrix();
grass.setMatrixAt(index, dummy.matrix);
});
grass.instanceMatrix.needsUpdate = true;
grass.castShadow = true;
scene.add(grass);
}
createDecorations();
// ------------------------------------------------------------
// Route definitions and geometry
// ------------------------------------------------------------
const routes = [
{
id: "promenade",
name: "Tidal Promenade Loop",
color: 0xf2c35c,
description: "A looping concept crossing open flats, low bars, and a central channel.",
points: [
[-38, -22], [-30, -11], [-18, -7], [-6, -10],
[5, -4], [18, -6], [28, -16], [19, -26],
[2, -29], [-18, -27], [-38, -22]
]
},
{
id: "sandbar",
name: "Glass Sandbar",
color: 0xff9167,
description: "A transverse route following two separate raised sand forms.",
points: [
[-41, 7], [-28, 2], [-14, -1], [0, 2],
[14, 4], [29, 0], [40, 9]
]
},
{
id: "ribbon",
name: "Ribbon Cut",
color: 0xd894ff,
description: "A north–south visual path that repeatedly crosses the model's drainage line.",
points: [
[-9, -35], [-5, -23], [1, -12], [7, -3],
[11, 8], [7, 21], [14, 33]
]
},
{
id: "shelf",
name: "North Shelf Arc",
color: 0x7ee0aa,
description: "A broad arc across the higher northern terrain and marsh-like edge.",
points: [
[-38, 21], [-21, 27], [-2, 25], [16, 21],
[34, 24], [43, 33]
]
}
];
const routeCylinderGeometry = new THREE.CylinderGeometry(1, 1, 1, 8, 1, false);
const routeSphereGeometry = new THREE.IcosahedronGeometry(0.55, 1);
const routeRingGeometry = new THREE.TorusGeometry(0.72, 0.09, 6, 20);
const floodColumnGeometry = new THREE.CylinderGeometry(1, 1, 1, 7, 1, false);
const floodRingGeometry = new THREE.TorusGeometry(0.9, 0.075, 6, 24);
const floodMaterial = new THREE.MeshBasicMaterial({
color: 0x4cecff,
transparent: true,
opacity: 0.97,
depthTest: false,
depthWrite: false
});
const floodColumnMaterial = new THREE.MeshBasicMaterial({
color: 0x4cecff,
transparent: true,
opacity: 0.3,
depthTest: false,
depthWrite: false
});
const up = new THREE.Vector3(0, 1, 0);
function setCylinderBetween(mesh, a, b, radius) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
if (length < 0.001) return false;
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
mesh.scale.set(radius, length, radius);
return true;
}
routes.forEach((route) => {
route.visible = true;
route.group = new THREE.Group();
route.group.name = route.name;
route.material = new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.72,
depthTest: false,
depthWrite: false
});
scene.add(route.group);
});
function sampleRoute(route) {
const samples = [];
for (let i = 0; i < route.points.length - 1; i++) {
const a = route.points[i];
const b = route.points[i + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const steps = Math.max(1, Math.ceil(length / 3));
for (let j = 0; j < steps; j++) {
const t = j / steps;
const x = THREE.MathUtils.lerp(a[0], b[0], t);
const z = THREE.MathUtils.lerp(a[1], b[1], t);
samples.push(
new THREE.Vector3(x, terrainHeight(x, z) + 0.34, z)
);
}
}
const last = route.points[route.points.length - 1];
samples.push(
new THREE.Vector3(
last[0],
terrainHeight(last[0], last[1]) + 0.34,
last[1]
)
);
return samples;
}
function addRouteMarker(group, point, material) {
const height = point.y - 0.34;
const post = new THREE.Mesh(routeCylinderGeometry, material);
post.position.set(point.x, height + 0.85, point.z);
post.scale.set(0.13, 1.7, 0.13);
post.renderOrder = 9;
group.add(post);
const cap = new THREE.Mesh(routeSphereGeometry, material);
cap.position.set(point.x, height + 1.8, point.z);
cap.renderOrder = 9;
group.add(cap);
const ring = new THREE.Mesh(routeRingGeometry, material);
ring.rotation.x = Math.PI / 2;
ring.position.set(point.x, height + 0.16, point.z);
ring.renderOrder = 9;
group.add(ring);
}
function rebuildRoute(route) {
route.group.clear();
const samples = sampleRoute(route);
route.samples = samples;
let totalLength = 0;
let floodedLength = 0;
let floodedSegments = 0;
for (let i = 0; i < samples.length - 1; i++) {
const a = samples[i];
const b = samples[i + 1];
const midpointX = (a.x + b.x) * 0.5;
const midpointZ = (a.z + b.z) * 0.5;
const terrainAtMidpoint = terrainHeight(midpointX, midpointZ);
const segmentLength = Math.hypot(b.x - a.x, b.z - a.z);
const submerged = terrainAtMidpoint < waterLevel;
totalLength += segmentLength;
if (submerged) {
floodedLength += segmentLength;
floodedSegments++;
}
const radius = route === selectedRoute ? 0.46 : 0.31;
const material = submerged ? floodMaterial : route.material;
const segment = new THREE.Mesh(routeCylinderGeometry, material);
setCylinderBetween(segment, a, b, radius);
segment.renderOrder = submerged ? 12 : 10;
route.group.add(segment);
if (submerged && i % 3 === 0) {
const low = Math.min(terrainAtMidpoint, waterLevel);
const high = Math.max(terrainAtMidpoint, waterLevel);
if (high - low > 0.02) {
const column = new THREE.Mesh(
floodColumnGeometry,
floodColumnMaterial
);
column.position.set(midpointX, (low + high) * 0.5, midpointZ);
column.scale.set(0.09, high - low, 0.09);
column.renderOrder = 11;
route.group.add(column);
}
const ring = new THREE.Mesh(floodRingGeometry, floodMaterial);
ring.rotation.x = Math.PI / 2;
ring.position.set(midpointX, waterLevel + 0.14, midpointZ);
ring.renderOrder = 11;
route.group.add(ring);
}
}
route.stats = {
length: totalLength,
floodedLength,
floodedSegments,
floodedPercent: totalLength > 0 ? (floodedLength / totalLength) * 100 : 0
};
route.group.visible = route.visible;
addRouteMarker(route.group, samples[0], route.material);
addRouteMarker(route.group, samples[samples.length - 1], route.material);
}
function rebuildAllRoutes() {
routes.forEach(rebuildRoute);
updateRouteStatistics();
}
// ------------------------------------------------------------
// UI
// ------------------------------------------------------------
const routeList = document.getElementById("route-list");
const routeDetail = document.getElementById("route-detail");
const waterSlider = document.getElementById("water-slider");
const waterReadout = document.getElementById("water-readout");
function colorToCSS(color) {
return `#${color.toString(16).padStart(6, "0")}`;
}
routeList.innerHTML = routes
.map(
(route) => `
<article class="route-card" data-route="${route.id}">
<div class="route-swatch" style="--route-color: ${colorToCSS(route.color)}"></div>
<div>
<h3 class="route-name">${route.name}</h3>
<p class="route-description">${route.description}</p>
<div class="route-meta"></div>
</div>
<input
type="checkbox"
checked
aria-label="Show ${route.name}"
data-visibility="${route.id}"
>
</article>
`
)
.join("");
function selectRoute(route) {
selectedRoute = route;
routes.forEach((item) => {
item.material.opacity = item === route ? 1 : 0.62;
});
document.querySelectorAll(".route-card").forEach((card) => {
card.classList.toggle(
"selected",
card.dataset.route === route.id
);
});
rebuildAllRoutes();
renderRouteDetail();
}
function updateRouteStatistics() {
routes.forEach((route) => {
const card = routeList.querySelector(
`.route-card[data-route="${route.id}"]`
);
const meta = card.querySelector(".route-meta");
meta.innerHTML = `
${Math.round(route.stats.length)} model units ·
<span class="wet">${route.stats.floodedPercent.toFixed(0)}% below visual water</span>
`;
});
}
function renderRouteDetail() {
if (!selectedRoute) return;
routeDetail.innerHTML = `
<div class="eyebrow">Selected route concept</div>
<h3>${selectedRoute.name}</h3>
<p>${selectedRoute.description} This is a generated visual path with no real-world location or access interpretation.</p>
<div class="metrics">
<div class="metric">
<div class="metric-label">Path length</div>
<div class="metric-value">${Math.round(selectedRoute.stats.length)} units</div>
</div>
<div class="metric">
<div class="metric-label">Below water</div>
<div class="metric-value">${selectedRoute.stats.floodedPercent.toFixed(0)}%</div>
</div>
</div>
<button id="focus-route" type="button">Focus this route</button>
`;
document
.getElementById("focus-route")
.addEventListener("click", focusSelectedRoute);
}
document.querySelectorAll(".route-card").forEach((card) => {
card.addEventListener("click", (event) => {
if (event.target.matches('input[type="checkbox"]')) return;
const route = routes.find((item) => item.id === card.dataset.route);
selectRoute(route);
});
});
document.querySelectorAll("[data-visibility]").forEach((checkbox) => {
checkbox.addEventListener("change", () => {
const route = routes.find(
(item) => item.id === checkbox.dataset.visibility
);
route.visible = checkbox.checked;
route.group.visible = route.visible;
});
});
// ------------------------------------------------------------
// Water-level updates
// ------------------------------------------------------------
function updateWaterLevel() {
waterUpdateQueued = false;
waterReadout.textContent =
`${waterLevel >= 0 ? "+" : ""}${waterLevel.toFixed(1)}`;
waterMesh.position.y = waterLevel;
waveGroup.position.y = waterLevel + 0.09;
rebuildShorelineContour();
rebuildAllRoutes();
if (probeHeight !== null) updateProbeVisuals();
}
waterSlider.addEventListener("input", () => {
waterLevel = Number(waterSlider.value);
if (!waterUpdateQueued) {
waterUpdateQueued = true;
requestAnimationFrame(updateWaterLevel);
}
});
// ------------------------------------------------------------
// Elevation probe
// ------------------------------------------------------------
const probeGroup = new THREE.Group();
probeGroup.visible = false;
scene.add(probeGroup);
const probeSphereMaterial = new THREE.MeshBasicMaterial({
color: 0xf5d36c,
depthTest: false
});
const probeColumnMaterial = new THREE.MeshBasicMaterial({
color: 0xf5d36c,
transparent: true,
opacity: 0.5,
depthTest: false,
depthWrite: false
});
const probeRingMaterial = new THREE.MeshBasicMaterial({
color: 0xf5d36c,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const probeSphere = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.55, 1),
probeSphereMaterial
);
const probeColumn = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.1, 1, 7),
probeColumnMaterial
);
const probeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.9, 0.08, 6, 24),
probeRingMaterial
);
probeRing.rotation.x = Math.PI / 2;
probeGroup.add(probeSphere, probeColumn, probeRing);
let probePosition = null;
function updateProbeVisuals() {
if (probeHeight === null || !probePosition) return;
const above = probeHeight >= waterLevel;
const color = above ? 0xf5d36c : 0x4cecff;
probeSphereMaterial.color.setHex(color);
probeColumnMaterial.color.setHex(color);
probeRingMaterial.color.setHex(color);
probeSphere.position.set(
probePosition.x,
probeHeight + 0.42,
probePosition.z
);
const low = Math.min(probeHeight, waterLevel);
const high = Math.max(probeHeight, waterLevel);
probeColumn.position.set(
probePosition.x,
(low + high) * 0.5,
probePosition.z
);
probeColumn.scale.y = Math.max(0.02, high - low);
probeRing.position.set(
probePosition.x,
waterLevel + 0.15,
probePosition.z
);
const difference = Math.abs(probeHeight - waterLevel);
const relation = above ? "above" : "below";
document.getElementById("probe-readout").innerHTML = `
Terrain model elevation:
<strong>${probeHeight >= 0 ? "+" : ""}${probeHeight.toFixed(2)}</strong><br>
${difference.toFixed(2)} model units ${relation} the current visual water level.
`;
}
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
function probeTerrainAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x =
((clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y =
-((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const hit = raycaster.intersectObject(terrainMesh, false)[0];
if (!hit) return;
probePosition = hit.point.clone();
probeHeight = hit.point.y;
probeGroup.visible = true;
updateProbeVisuals();
}
// ------------------------------------------------------------
// Custom camera controls — no external controls addon
// ------------------------------------------------------------
const desiredTarget = new THREE.Vector3(0, 0, 0);
const currentTarget = new THREE.Vector3(0, 0, 0);
let desiredTheta = -0.68;
let desiredPhi = 0.96;
let desiredRadius = 91;
let currentTheta = desiredTheta;
let currentPhi = desiredPhi;
let currentRadius = desiredRadius;
const pointers = new Map();
let dragDistance = 0;
let panMode = false;
let lastPinchDistance = 0;
function pointerDistance() {
const values = Array.from(pointers.values());
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function panCamera(dx, dy) {
camera.updateMatrixWorld();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(
camera.position.x - currentTarget.x,
0,
camera.position.z - currentTarget.z
).normalize();
const scale = desiredRadius * 0.00125;
desiredTarget
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, dy * scale);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
event.preventDefault();
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragDistance = 0;
panMode = event.shiftKey || event.button === 2;
}
if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size === 1) {
dragDistance += Math.hypot(dx, dy);
if (panMode) {
panCamera(dx, dy);
} else {
desiredTheta -= dx * 0.005;
desiredPhi = THREE.MathUtils.clamp(
desiredPhi - dy * 0.005,
0.12,
1.46
);
}
} else if (pointers.size >= 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * (lastPinchDistance / distance),
32,
150
);
}
lastPinchDistance = distance;
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick =
pointers.size === 1 &&
dragDistance < 6 &&
event.button === 0;
pointers.delete(event.pointerId);
if (pointers.size < 2) {
lastPinchDistance = 0;
}
if (wasClick) {
probeTerrainAt(event.clientX, event.clientY);
}
});
renderer.domElement.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
32,
150
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLTextAreaElement
) {
return;
}
if (event.key === "+" || event.key === "=") {
desiredRadius = Math.max(32, desiredRadius * 0.9);
}
if (event.key === "-" || event.key === "_") {
desiredRadius = Math.min(150, desiredRadius * 1.1);
}
const cameraRight = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
cameraRight.y = 0;
cameraRight.normalize();
const cameraForward = new THREE.Vector3(
camera.position.x - currentTarget.x,
0,
camera.position.z - currentTarget.z
).normalize();
const panStep = desiredRadius * 0.025;
if (event.key === "ArrowLeft") {
desiredTarget.addScaledVector(cameraRight, -panStep);
}
if (event.key === "ArrowRight") {
desiredTarget.addScaledVector(cameraRight, panStep);
}
if (event.key === "ArrowUp") {
desiredTarget.addScaledVector(cameraForward, panStep);
}
if (event.key === "ArrowDown") {
desiredTarget.addScaledVector(cameraForward, -panStep);
}
});
function resetView() {
desiredTarget.set(0, 0, 0);
desiredTheta = -0.68;
desiredPhi = 0.96;
desiredRadius = 91;
}
function topView() {
desiredTarget.set(0, 0, 0);
desiredPhi = 0.08;
desiredTheta = -Math.PI / 2;
desiredRadius = 88;
}
function focusSelectedRoute() {
if (!selectedRoute || !selectedRoute.samples) return;
const center = new THREE.Vector3();
selectedRoute.samples.forEach((point) => center.add(point));
center.divideScalar(selectedRoute.samples.length);
center.y = 0;
desiredTarget.copy(center);
desiredRadius = 54;
desiredPhi = 0.92;
}
document
.getElementById("view-reset")
.addEventListener("click", resetView);
document
.getElementById("view-top")
.addEventListener("click", topView);
// ------------------------------------------------------------
// Animation and responsive rendering
// ------------------------------------------------------------
function dampAngle(current, target, amount) {
const difference =
((target - current + Math.PI) % (Math.PI * 2) +
Math.PI * 2) %
(Math.PI * 2) -
Math.PI;
return current + difference * amount;
}
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-delta * 9);
currentTheta = dampAngle(
currentTheta,
desiredTheta,
smoothing
);
currentPhi = THREE.MathUtils.lerp(
currentPhi,
desiredPhi,
smoothing
);
currentRadius = THREE.MathUtils.lerp(
currentRadius,
desiredRadius,
smoothing
);
currentTarget.lerp(desiredTarget, smoothing);
const sinPhi = Math.sin(currentPhi);
camera.position.set(
currentTarget.x +
currentRadius * sinPhi * Math.sin(currentTheta),
currentTarget.y + currentRadius * Math.cos(currentPhi),
currentTarget.z +
currentRadius * sinPhi * Math.cos(currentTheta)
);
camera.lookAt(currentTarget);
camera.updateMatrixWorld();
waveGroup.position.x = Math.sin(clock.elapsedTime * 0.16) * 0.28;
waveGroup.position.z = Math.cos(clock.elapsedTime * 0.12) * 0.22;
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
selectRoute(routes[0]);
updateWaterLevel();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```