Waterfront visualization in Three.js

A section drawing tells you the landing is 30 cm above the water. From the quay itself, that edge looks much closer. Use one Three.js scene to compare those views and show what changes when you raise the water.

An elevated view of a concrete quay and its lower landing beside blue water
The overview makes the landing and main quay easy to compare. The walkway camera looks along the edge from eye level.

Set the elevations

Choose a common vertical datum. In this example, one unit is one metre and Y is up. The main quay is at 3.20 m and the landing at 2.30 m. Normal and high still-water levels are 2.00 m and 2.60 m. Subtract the water level from the landing height to get its clearance. Use the same datum for survey data and imported models.

For a client review, label each scenario with its source elevation. The two levels here are illustrative and the water animation is for presentation. Use measured levels and a separate hydraulic model if the decision depends on inundation or wave loads.

Build the quay

Create waterfront.html and waterfront.js next to src/ in the Tidewater download. Copy the import map from the download’s index.html into the head of a new document, then put this markup in its body.

<style>
  body { margin: 1rem; font: 1rem system-ui; }
  canvas { display: block; margin-top: .75rem; }
</style>
<nav aria-label="Water level">
  <a href="?level=normal">Normal water</a>
  <a href="?level=high">High water</a>
</nav>
<div role="group" aria-label="Viewpoint">
  <button id="overview" type="button" disabled>Overview</button>
  <button id="walkway" type="button" disabled>Walkway</button>
</div>
<p id="reading"></p>
<div id="view"></div>
<script type="module" src="./waterfront.js"></script>

Save this as waterfront.js. Run python3 -m http.server 8080 in the download folder and open http://localhost:8080/waterfront.html.

import * as THREE from "three/webgpu";
import { createRenderer } from "./src/renderer.js";
import { createWater } from "./src/Tidewater.js";

const high = new URLSearchParams(location.search).get("level") === "high";
const waterLevel = high ? 2.60 : 2.00;
const lowerLanding = 2.30;
const quayTop = 3.20;
const clearance = lowerLanding - waterLevel;

const host = document.querySelector("#view");
const overview = document.querySelector("#overview");
const walkway = document.querySelector("#walkway");
document.querySelector("#reading").textContent =
  `Water level: ${waterLevel.toFixed(2)} m. ` +
  `Landing: ${Math.abs(clearance).toFixed(2)} m ${clearance > 0 ? "above" : "below"} still water.`;

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(48, 1, 0.1, 5000);
const { renderer } = await createRenderer();
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.5));
host.append(renderer.domElement);

const resize = () => {
  const width = host.clientWidth;
  const height = Math.min(innerHeight * 0.68, 720);
  renderer.setSize(width, height);
  camera.aspect = width / height;
  camera.updateProjectionMatrix();
};
resize();
addEventListener("resize", resize);

function slab(x1, x2, top, length, color) {
  const base = 0;
  const mesh = new THREE.Mesh(
    new THREE.BoxGeometry(x2 - x1, top - base, length),
    new THREE.MeshStandardMaterial({ color, roughness: 0.82 }),
  );
  mesh.position.set((x1 + x2) / 2, (base + top) / 2, 0);
  scene.add(mesh);
}

slab(-100, 0, quayTop, 140, 0xb8b2a5);
slab(0, 2.4, lowerLanding, 46, 0x82786c);

const bollardGeometry = new THREE.CylinderGeometry(0.14, 0.20, 0.48, 12);
const bollardMaterial = new THREE.MeshStandardMaterial({ color: 0x333637 });
for (const z of [-20, -15, -10, -5, 0, 5, 10, 15, 20]) {
  const bollard = new THREE.Mesh(bollardGeometry, bollardMaterial);
  bollard.position.set(-0.50, quayTop + 0.24, z);
  scene.add(bollard);
}

function showOverview() {
  camera.position.set(11, 9, 17);
  camera.lookAt(-0.6, 2.1, 0);
}
function showWalkway() {
  camera.position.set(-1.4, quayTop + 1.65, 11);
  camera.lookAt(1.6, lowerLanding, -2);
}
overview.addEventListener("click", showOverview);
walkway.addEventListener("click", showWalkway);
showOverview();

const water = await createWater({
  scene, camera, renderer, mode: "tranquil", quality: "med", waterLevel,
});
overview.disabled = false;
walkway.disabled = false;

let last = performance.now();
renderer.setAnimationLoop((now) => {
  const dt = Math.min((now - last) / 1000, 0.05);
  last = now;
  water.update(dt);
  renderer.render(scene, camera);
});

Switch between Normal water and High water from the same viewpoint. At 2.00 m the lower step is exposed. At 2.60 m still water covers it, though the top of the quay stays clear. Then try Walkway for a view 1.65 m above the paving. Keep the lens and target the same for both elevations when you capture comparison images.

Bring in the site model

Replace the boxes with the quay and its retaining wall. Give that wall faces down past the lowest level so the water meets it cleanly. Keep a vertical wall for a hard quay edge. Use a depth field where the site slopes into the sea and you want shoaling waves or a wet-sand edge. Rebuild the field against the still-water level for each scenario. Add a sloping shoreline.

Keep water level and lighting as separate controls. For an evening walkthrough, use the same elevation and camera before and after adding dock lights. You can pass point lights to water.lighting.setLights() so they cast glints onto the water. Water lighting API · See the dock after dark.

Water materials

For a quay seen from the walkway, try the reflective water shader. For a view below the surface, use underwater fog and projected light to show how visibility changes with distance.

Use site data

If the survey includes a lake outline, use its GeoJSON rings to keep the water inside the shore and leave islands dry. For a tidal site, convert gauge readings to the model’s vertical datum before placing the water. Draw a GeoJSON lake · Work with tide gauge readings