Prompt specification
Build or customize the Three.js 3D scene "Tidal island causeway scene" 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: Tidal island causeway scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/tidal-island-causeway-scene-x1259
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: tidal island causeway scene. Build a short causeway between mainland and an island village; a water-level slider progressively covers low sections with a visible reference to the illustrative tide range. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (tidal-island-causeway-scene-x1259):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tidal Island — Voxel Causeway</title>
<style>
:root {
color-scheme: light;
--panel: rgba(13, 30, 37, 0.88);
--panel-border: rgba(255, 255, 255, 0.16);
--text: #f4fbfc;
--muted: #b9d0d5;
--low: #efb45b;
--mid: #45abc0;
--high: #dc675c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8e2e8;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(350px, calc(100vw - 36px));
padding: 18px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 18px;
box-shadow: 0 18px 50px rgba(14, 37, 46, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
user-select: none;
}
.eyebrow {
margin-bottom: 5px;
color: #81d4df;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 24px;
line-height: 1.05;
letter-spacing: -0.03em;
}
.subtitle {
margin: 8px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.tide-readout {
display: flex;
align-items: end;
justify-content: space-between;
gap: 14px;
margin-bottom: 13px;
}
.tide-readout output {
color: #8ce2ea;
font-size: 30px;
font-weight: 800;
letter-spacing: -0.045em;
line-height: 1;
}
.status {
max-width: 145px;
color: #d7e8eb;
font-size: 11px;
line-height: 1.35;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 8px;
margin: 4px 0 10px;
border-radius: 999px;
appearance: none;
-webkit-appearance: none;
background: linear-gradient(
90deg,
var(--low) 0%,
var(--mid) 50%,
var(--high) 100%
);
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 21px;
height: 21px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: #193e49;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 15px;
height: 15px;
border: 3px solid white;
border-radius: 50%;
background: #193e49;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}
input[type="range"]:focus-visible {
outline: 3px solid rgba(118, 219, 232, 0.55);
outline-offset: 5px;
}
.range-labels {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.range-labels span:first-child {
color: var(--low);
}
.range-labels span:last-child {
color: #ef8b81;
}
.note {
margin: 15px 0 0;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.12);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.note strong {
color: #e9f6f8;
font-weight: 700;
}
.controls-hint {
position: fixed;
z-index: 10;
right: 18px;
bottom: 17px;
padding: 9px 12px;
color: rgba(244, 251, 252, 0.86);
background: rgba(13, 30, 37, 0.68);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
font-size: 11px;
letter-spacing: 0.02em;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 600px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px;
}
h1 {
font-size: 21px;
}
.subtitle {
margin-bottom: 12px;
}
.controls-hint {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<section class="panel" aria-label="Tide controls">
<div class="eyebrow">Interactive coastal study</div>
<h1>Tidal Island Causeway</h1>
<p class="subtitle">
Raise the tide to cover the low stone sections between the mainland
and island village.
</p>
<div class="tide-readout">
<output id="tideValue" for="tideSlider">+0.65 m</output>
<div id="tideStatus" class="status">Low causeway stones emerging</div>
</div>
<input
id="tideSlider"
type="range"
min="0.35"
max="2.45"
step="0.01"
value="0.65"
aria-label="Water level"
>
<div class="range-labels">
<span>Low · 0.35 m</span>
<span>High · 2.45 m</span>
</div>
<p class="note">
<strong>Illustrative tide range, not survey or navigational data.</strong>
The fixed gauge beside the mainland shows the low and high references.
</p>
</section>
<div class="controls-hint">Drag to orbit · Scroll or pinch to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const MIN_TIDE = 0.35;
const MAX_TIDE = 2.45;
let waterLevel = 0.65;
const slider = document.getElementById("tideSlider");
const tideValue = document.getElementById("tideValue");
const tideStatus = document.getElementById("tideStatus");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc8e2e8);
scene.fog = new THREE.Fog(0xc8e2e8, 64, 125);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel island and tidal causeway scene"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-25, 25, 18, -18, 0.1, 180);
const target = new THREE.Vector3(0.5, 1.0, 0);
let azimuth = 0.66;
let polar = 0.84;
const cameraRadius = 52;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + cameraRadius * sinPolar * Math.sin(azimuth),
target.y + cameraRadius * Math.cos(polar),
target.z + cameraRadius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(32, 50 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Direct camera controls: no examples/addons are used.
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar + dy * 0.004, 0.36, 1.28);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.35
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") azimuth += 0.08;
if (event.key === "ArrowRight") azimuth -= 0.08;
if (event.key === "ArrowUp") polar = Math.max(0.36, polar - 0.06);
if (event.key === "ArrowDown") polar = Math.min(1.28, polar + 0.06);
if (event.key === "+" || event.key === "=") {
camera.zoom = Math.min(2.35, camera.zoom * 1.1);
}
if (event.key === "-" || event.key === "_") {
camera.zoom = Math.max(0.65, camera.zoom / 1.1);
}
camera.updateProjectionMatrix();
updateCamera();
});
const hemisphere = new THREE.HemisphereLight(0xeafaff, 0x61715a, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d6, 3.25);
sun.position.set(-24, 36, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -38;
sun.shadow.camera.right = 38;
sun.shadow.camera.top = 32;
sun.shadow.camera.bottom = -32;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (typeof color === "object") return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function box(width, height, depth, x, y, z, color, parent = scene) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, color = "#efffff", scale = 1) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(13, 30, 37, 0.82)";
context.beginPath();
context.roundRect(5, 8, 758, 112, 24);
context.fill();
context.strokeStyle = "rgba(255,255,255,0.22)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = color;
context.font = "800 43px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 384, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(4.2 * scale, 0.7 * scale, 1);
sprite.renderOrder = 30;
scene.add(sprite);
return sprite;
}
let randomSeed = 1847;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function hash(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453;
return value - Math.floor(value);
}
// Voxel terrain made from individual one-metre columns.
const terrainHeights = new Map();
const terrainCells = [];
for (let x = -24; x <= -10; x++) {
for (let z = -8; z <= 8; z++) {
const distanceInland = -10 - x;
let height =
0.67 +
distanceInland * 0.105 +
(hash(x, z) - 0.5) * 0.2;
height += Math.max(0, 6 - Math.abs(z)) * 0.012;
terrainCells.push({ x, z, height, island: false });
}
}
for (let x = 8; x <= 24; x++) {
for (let z = -8; z <= 8; z++) {
const distanceInland = x - 8;
let height =
0.66 +
Math.min(distanceInland, 7) * 0.12 +
Math.max(0, distanceInland - 7) * 0.1 +
(hash(x + 7, z) - 0.5) * 0.18;
height += Math.max(0, 6 - Math.abs(z)) * 0.012;
terrainCells.push({ x, z, height, island: true });
}
}
const terrain = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
}),
terrainCells.length
);
terrain.castShadow = true;
terrain.receiveShadow = true;
const dummy = new THREE.Object3D();
const terrainColor = new THREE.Color();
const sandColor = new THREE.Color(0xc6ad72);
const grassColor = new THREE.Color(0x668e68);
const highGrassColor = new THREE.Color(0x78966a);
terrainCells.forEach((cell, index) => {
dummy.position.set(cell.x, -1 + cell.height / 2, cell.z);
dummy.scale.set(1, cell.height, 1);
dummy.updateMatrix();
terrain.setMatrixAt(index, dummy.matrix);
if (cell.height < 1.05) {
terrainColor.copy(sandColor).offsetHSL(0, 0, (random() - 0.5) * 0.08);
} else {
terrainColor
.copy(grassColor)
.lerp(highGrassColor, random() * 0.65)
.offsetHSL(0, 0, (random() - 0.5) * 0.045);
}
terrain.setColorAt(index, terrainColor);
terrainHeights.set(`${cell.x},${cell.z}`, cell.height);
});
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
scene.add(terrain);
function groundHeight(x, z) {
return terrainHeights.get(`${Math.round(x)},${Math.round(z)}`) ?? 1.2;
}
// Low, stepped causeway sections.
const causewayStart = -9.5;
const causewayEnd = 7.5;
const causewayLength = causewayEnd - causewayStart;
const sectionCount = 14;
const sectionLength = causewayLength / sectionCount;
const sectionHeights = [
1.45, 1.25, 0.96, 1.10, 0.73, 0.91, 0.55,
0.79, 0.62, 1.02, 0.68, 1.26, 0.96, 1.50
];
const stoneColors = [0x8e8b80, 0x9a9588, 0x827f76, 0xaaa294];
for (let i = 0; i < sectionCount; i++) {
const x = causewayStart + sectionLength * (i + 0.5);
const top = sectionHeights[i];
const bottom = -0.8;
const height = top - bottom;
box(
sectionLength * 0.985,
height,
2.85,
x,
bottom + height / 2,
0,
stoneColors[i % stoneColors.length]
);
box(
sectionLength * 0.91,
0.12,
1.15,
x,
top + 0.055,
0,
i % 2 ? 0xb0a996 : 0xc0b8a4
);
// Low voxel kerbs make the changing water coverage easy to read.
for (const z of [-1.48, 1.48]) {
box(
sectionLength * 0.78,
0.23,
0.18,
x,
top + 0.12,
z,
0x686960
);
}
}
// Short navigation posts along one edge of the causeway.
for (let i = 1; i < sectionCount; i += 3) {
const x = causewayStart + sectionLength * (i + 0.5);
const top = sectionHeights[i];
box(0.24, 0.72, 0.24, x, top + 0.36, 1.34, 0x5e625f);
box(0.31, 0.12, 0.31, x, top + 0.76, 1.34, 0xe8d8ad);
}
function makeTree(x, z, size = 1) {
const ground = groundHeight(x, z);
const trunkHeight = 1.35 * size;
box(
0.32 * size,
trunkHeight,
0.32 * size,
x,
ground + trunkHeight / 2,
z,
0x70513a
);
const foliage = [0x466f52, 0x537d58, 0x62895d];
box(
1.35 * size,
0.8 * size,
1.35 * size,
x,
ground + trunkHeight + 0.28 * size,
z,
foliage[0]
);
box(
1.05 * size,
0.72 * size,
1.05 * size,
x,
ground + trunkHeight + 0.83 * size,
z,
foliage[1]
);
box(
0.67 * size,
0.62 * size,
0.67 * size,
x,
ground + trunkHeight + 1.3 * size,
z,
foliage[2]
);
}
const mainlandTrees = [
[-13, 5], [-17, 4], [-21, 3], [-12, -5],
[-18, -6], [-22, -5], [-16, 7], [-20, -7]
];
const islandTrees = [
[9, 5], [13, 6], [16, 5], [21, 5],
[9, -6], [14, -6], [18, -6], [22, 0]
];
mainlandTrees.forEach(([x, z], index) => makeTree(x, z, 0.85 + (index % 3) * 0.12));
islandTrees.forEach(([x, z], index) => makeTree(x, z, 0.75 + (index % 4) * 0.1));
const wallColors = [0xe9dfc7, 0xd7d0b9, 0xefe4c9, 0xc7c8b8];
const roofColors = [0xa9553f, 0x8c4a3c, 0xb46743, 0x6e6970];
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xffd66b,
emissive: 0xf2a72e,
emissiveIntensity: 0.75,
roughness: 0.5
});
const doorMaterial = new THREE.MeshStandardMaterial({
color: 0x4c4438,
roughness: 0.95
});
function makeHouse(x, z, index) {
const ground = groundHeight(x, z);
const foundationHeight = ground + 0.9;
box(
2.45,
foundationHeight,
2.35,
x,
-0.9 + foundationHeight / 2,
z,
0x77766c
);
const width = 2.05 + (index % 2) * 0.18;
const depth = 1.95;
const wallHeight = 1.62;
box(
width,
wallHeight,
depth,
x,
ground + wallHeight / 2,
z,
wallColors[index % wallColors.length]
);
const roofColor = roofColors[index % roofColors.length];
box(
width + 0.42,
0.36,
depth + 0.4,
x,
ground + 1.78,
z,
roofColor
);
box(
width - 0.05,
0.26,
depth - 0.08,
x,
ground + 2.08,
z,
roofColor
);
box(
width - 0.55,
0.22,
depth - 0.48,
x,
ground + 2.31,
z,
roofColor
);
const front = z + depth / 2 + 0.035;
box(0.55, 0.9, 0.07, x, ground + 0.46, front, doorMaterial);
box(
0.42,
0.42,
0.07,
x - 0.64,
ground + 0.95,
front,
windowMaterial
);
box(
0.42,
0.42,
0.07,
x + 0.64,
ground + 0.95,
front,
windowMaterial
);
box(
0.07,
0.42,
0.42,
x + width / 2 + 0.035,
ground + 0.95,
z,
windowMaterial
);
box(
0.26,
0.62,
0.28,
x + 0.45,
ground + 2.53,
z - 0.28,
0x74675c
);
}
const houses = [
[10.8, -3.6],
[14.1, -4.1],
[18.0, -3.7],
[11.5, 2.6],
[15.3, 1.4],
[19.0, 3.2]
];
houses.forEach(([x, z], index) => makeHouse(x, z, index));
// Voxel lighthouse on the island.
const lighthouseGround = groundHeight(21, -3);
box(2.0, lighthouseGround + 0.9, 2.0, 21, -0.9 + (lighthouseGround + 0.9) / 2, -3, 0x77766c);
for (let level = 0; level < 6; level++) {
const width = 1.55 - level * 0.065;
box(
width,
0.64,
width,
21,
lighthouseGround + 0.32 + level * 0.64,
-3,
level === 2 || level === 4 ? 0xc75f4d : 0xeee7d4
);
}
box(1.38, 0.16, 1.38, 21, lighthouseGround + 3.92, -3, 0x414b50);
box(
0.88,
0.62,
0.88,
21,
lighthouseGround + 4.3,
-3,
new THREE.MeshStandardMaterial({
color: 0xffd77e,
emissive: 0xffb52e,
emissiveIntensity: 1.2,
roughness: 0.35
})
);
box(1.1, 0.22, 1.1, 21, lighthouseGround + 4.72, -3, 0x9f493f);
// Small village details.
for (let i = 0; i < 5; i++) {
box(
0.32,
0.34,
0.32,
12.6 + i * 0.48,
groundHeight(12.6 + i * 0.48, 4.6) + 0.17,
4.6,
i % 2 ? 0xb47a45 : 0x78966a
);
}
// Fixed tide gauge on the mainland edge.
const gaugeX = -9.8;
const gaugeZ = -3.0;
const gaugeCenter = (MIN_TIDE + MAX_TIDE) / 2;
const gaugeHeight = MAX_TIDE - MIN_TIDE + 0.72;
box(
0.16,
gaugeHeight + 0.35,
0.18,
gaugeX,
gaugeCenter,
gaugeZ - 0.12,
0x4d5554
);
box(
0.72,
gaugeHeight,
0.16,
gaugeX,
gaugeCenter,
gaugeZ,
0xf0eee2
);
for (let level = MIN_TIDE; level <= MAX_TIDE + 0.001; level += 0.25) {
const isEndpoint = Math.abs(level - MIN_TIDE) < 0.001 || Math.abs(level - MAX_TIDE) < 0.001;
box(
isEndpoint ? 0.66 : 0.42,
0.045,
0.055,
gaugeX,
level,
gaugeZ + 0.11,
isEndpoint ? 0xd6584f : 0x596c6f
);
}
const lowLabel = makeLabel("LOW · 0.35 m", "#ffd28c", 0.76);
lowLabel.position.set(-8.35, MIN_TIDE, gaugeZ);
const highLabel = makeLabel("HIGH · 2.45 m", "#ffaaa0", 0.76);
highLabel.position.set(-8.35, MAX_TIDE, gaugeZ);
const tideMarker = box(
1.05,
0.14,
0.3,
gaugeX,
waterLevel,
gaugeZ + 0.2,
new THREE.MeshStandardMaterial({
color: 0xf05d4f,
emissive: 0x8d1f18,
emissiveIntensity: 0.35,
roughness: 0.5,
transparent: true,
opacity: 1
})
);
tideMarker.renderOrder = 20;
const villageLabel = makeLabel("ISLAND VILLAGE", "#d9fbff", 0.95);
villageLabel.position.set(15.2, 6.2, -1.5);
const mainlandLabel = makeLabel("MAINLAND", "#e8f6ee", 0.82);
mainlandLabel.position.set(-17.0, 4.7, 0);
const causewayLabel = makeLabel("TIDAL CAUSEWAY", "#ffe0a6", 0.72);
causewayLabel.position.set(-7.5, 3.3, -2.8);
// Main water surface.
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x4aa7b5,
transparent: true,
opacity: 0.7,
roughness: 0.32,
metalness: 0.04,
clearcoat: 0.22,
clearcoatRoughness: 0.38,
depthWrite: false,
side: THREE.DoubleSide
});
const water = new THREE.Mesh(
new THREE.PlaneGeometry(140, 110, 1, 1),
waterMaterial
);
water.rotation.x = -Math.PI / 2;
water.position.y = waterLevel;
water.renderOrder = 2;
scene.add(water);
// Voxel foam flecks, kept clear of the causeway center.
const foamCount = 58;
const foam = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({
color: 0xe8ffff,
transparent: true,
opacity: 0.58,
depthWrite: false
}),
foamCount
);
foam.renderOrder = 5;
foam.frustumCulled = false;
const foamData = [];
for (let i = 0; i < foamCount; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = -12 + random() * 26;
const z = side * (2.35 + random() * 5.8);
foamData.push({
x,
z,
sx: 0.18 + random() * 0.5,
sz: 0.055 + random() * 0.09,
phase: random() * Math.PI * 2
});
}
scene.add(foam);
const lowWaterColor = new THREE.Color(0x58b6c0);
const highWaterColor = new THREE.Color(0x286f88);
function setTide(level) {
waterLevel = THREE.MathUtils.clamp(level, MIN_TIDE, MAX_TIDE);
water.position.y = waterLevel;
tideMarker.position.y = waterLevel;
const colorMix = (waterLevel - MIN_TIDE) / (MAX_TIDE - MIN_TIDE);
waterMaterial.color.copy(lowWaterColor).lerp(highWaterColor, colorMix);
tideValue.textContent = `+${waterLevel.toFixed(2)} m`;
if (waterLevel < 0.72) {
tideStatus.textContent = "Low stones exposed at low water";
} else if (waterLevel < 1.35) {
tideStatus.textContent = "Low causeway sections submerged";
} else if (waterLevel < 1.85) {
tideStatus.textContent = "Most of the causeway is submerged";
} else {
tideStatus.textContent = "High water covers the causeway";
}
}
slider.addEventListener("input", () => {
setTide(Number(slider.value));
});
setTide(Number(slider.value));
// A subtle dark underside helps the causeway remain legible underwater.
const causewayShadowMaterial = new THREE.MeshBasicMaterial({
color: 0x355d63,
transparent: true,
opacity: 0.12,
depthWrite: false
});
const underwaterOverlay = new THREE.Mesh(
new THREE.PlaneGeometry(causewayLength, 3.0),
causewayShadowMaterial
);
underwaterOverlay.rotation.x = -Math.PI / 2;
underwaterOverlay.position.set(-1, -0.79, 0);
underwaterOverlay.renderOrder = 1;
scene.add(underwaterOverlay);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
foamData.forEach((piece, index) => {
dummy.position.set(
piece.x + Math.sin(time * 0.42 + piece.phase) * 0.08,
waterLevel + 0.045,
piece.z + Math.cos(time * 0.31 + piece.phase) * 0.035
);
dummy.scale.set(piece.sx, 0.025, piece.sz);
dummy.updateMatrix();
foam.setMatrixAt(index, dummy.matrix);
});
foam.instanceMatrix.needsUpdate = true;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```