Prompt specification
Build or customize the Three.js 3D scene "Canoe reaching a riverside home at changing water levels" 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: Canoe reaching a riverside home at changing water levels
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/canoe-reaching-a-riverside-home-at-changing-water-leve-x3042
Scene Description Prompt:
Please use Three.js from cdnjs for a cutaway scene based on this idea: canoe reaching a riverside home at changing water levels. Create a compact Amazon floodplain vignette with raised access, canoe, and forest edge. Show how the landing connection changes as a schematic river level rises. Return one self-contained HTML file.
Working Three.js Starter (canoe-reaching-a-riverside-home-at-changing-water-leve-x3042):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Rising River — Amazon Floodplain Vignette</title>
<style>
:root {
--ink: #173f43;
--muted: #5f716d;
--paper: #f4f0df;
--orange: #e46f43;
--blue: #248da0;
--line: rgba(23, 63, 67, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8dacb;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app, #app canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-block {
position: absolute;
top: 24px;
left: 28px;
max-width: 430px;
text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--orange);
font-size: 11px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 2px;
background: var(--orange);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
line-height: .98;
letter-spacing: -.045em;
font-weight: 760;
}
.subtitle {
max-width: 370px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: absolute;
top: 24px;
right: 24px;
width: 205px;
padding: 15px 16px;
border: 1px solid rgba(23,63,67,.13);
border-radius: 15px;
background: rgba(247,244,232,.84);
box-shadow: 0 12px 35px rgba(43,54,47,.08);
backdrop-filter: blur(10px);
pointer-events: auto;
}
.legend-title {
margin-bottom: 11px;
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
color: #6f7b73;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 8px 0;
font-size: 11px;
color: #415d5d;
}
.swatch {
width: 19px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.swatch.water { background: #3ba5b4; }
.swatch.fixed { background: #75523b; }
.swatch.float { background: #e46f43; }
.swatch.clay { background: #8b684e; }
.swatch.silt { background: #c79b69; }
.swatch.soil { background: #67503a; }
.legend-note {
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #798078;
font-size: 9px;
line-height: 1.45;
letter-spacing: .02em;
}
.control-wrap {
position: absolute;
left: 50%;
bottom: 23px;
width: min(650px, calc(100vw - 32px));
transform: translateX(-50%);
pointer-events: auto;
}
.control-panel {
padding: 15px 17px 13px;
border: 1px solid rgba(23,63,67,.14);
border-radius: 18px;
background: rgba(248,245,234,.92);
box-shadow: 0 18px 50px rgba(34,46,39,.15);
backdrop-filter: blur(14px);
}
.control-top {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
margin-bottom: 11px;
}
.control-label {
font-size: 11px;
font-weight: 800;
letter-spacing: .13em;
text-transform: uppercase;
color: #64756e;
}
.level-readout {
display: flex;
align-items: baseline;
gap: 7px;
color: var(--ink);
}
#levelValue {
font-size: 25px;
line-height: 1;
font-weight: 760;
letter-spacing: -.04em;
}
#levelValue small {
font-size: 12px;
font-weight: 650;
letter-spacing: 0;
color: #6d7c75;
}
.range-row {
display: grid;
grid-template-columns: repeat(3, auto) 1fr;
align-items: center;
gap: 9px;
}
button {
appearance: none;
border: 1px solid rgba(23,63,67,.17);
border-radius: 9px;
background: rgba(255,255,255,.44);
color: #42605f;
font: inherit;
font-size: 10px;
font-weight: 760;
letter-spacing: .06em;
text-transform: uppercase;
padding: 8px 10px;
cursor: pointer;
transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
button:hover {
transform: translateY(-1px);
background: #fffdf5;
border-color: rgba(23,63,67,.3);
}
button:active { transform: translateY(0); }
#resetButton {
min-width: 43px;
padding-inline: 11px;
color: var(--orange);
}
input[type="range"] {
width: 100%;
height: 22px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 6px;
border-radius: 10px;
background: linear-gradient(90deg, #68b7bd 0%, #2c91a3 50%, #e07149 100%);
box-shadow: inset 0 0 0 1px rgba(23,63,67,.12);
}
input[type="range"]::-moz-range-track {
height: 6px;
border-radius: 10px;
background: linear-gradient(90deg, #68b7bd 0%, #2c91a3 50%, #e07149 100%);
box-shadow: inset 0 0 0 1px rgba(23,63,67,.12);
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 21px;
height: 21px;
margin-top: -7.5px;
border: 3px solid #fff8e7;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 2px 8px rgba(23,63,67,.25);
}
input[type="range"]::-moz-range-thumb {
width: 16px;
height: 16px;
border: 3px solid #fff8e7;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 2px 8px rgba(23,63,67,.25);
}
.status-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin-top: 9px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: #66756e;
font-size: 10px;
line-height: 1.35;
}
#statusText { color: #3e5d5b; }
.camera-hint {
flex: 0 0 auto;
color: #8a9188;
letter-spacing: .04em;
}
#gaugeLabel {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -125%);
padding: 5px 8px;
border: 1px solid rgba(23,63,67,.16);
border-radius: 8px;
background: rgba(255,250,235,.92);
color: var(--ink);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
box-shadow: 0 5px 16px rgba(23,63,67,.12);
}
@media (max-width: 760px) {
.title-block {
top: 17px;
left: 18px;
max-width: calc(100vw - 36px);
}
h1 { font-size: 34px; }
.subtitle { display: none; }
.legend { display: none; }
.control-wrap {
bottom: 13px;
width: calc(100vw - 20px);
}
.control-panel { padding: 13px 13px 11px; }
.range-row { grid-template-columns: repeat(3, auto) 1fr; gap: 6px; }
button { padding: 7px 8px; font-size: 9px; }
.camera-hint { display: none; }
.status-row { font-size: 9px; }
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<header class="title-block">
<div class="eyebrow">Amazon floodplain · interactive section</div>
<h1>Rising River</h1>
<p class="subtitle">
A canoe approaches a raised riverside home while the floodplain stage changes.
Move the water level to see the floating landing rise and the gangway connection change.
</p>
</header>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Reading the vignette</div>
<div class="legend-row"><i class="swatch water"></i> Schematic river level</div>
<div class="legend-row"><i class="swatch fixed"></i> Fixed landing</div>
<div class="legend-row"><i class="swatch float"></i> Floating landing</div>
<div class="legend-row"><i class="swatch clay"></i> Alluvial clay</div>
<div class="legend-row"><i class="swatch silt"></i> Oxbow silt</div>
<div class="legend-row"><i class="swatch soil"></i> Forest topsoil</div>
<div class="legend-note">
Vertical dimensions and stage change are exaggerated for clarity.
</div>
</aside>
<div id="gaugeLabel">0.52 m</div>
<section class="control-wrap">
<div class="control-panel">
<div class="control-top">
<div>
<div class="control-label">Schematic river stage</div>
</div>
<div class="level-readout">
<span id="levelValue">0.52 <small>m</small></span>
</div>
</div>
<div class="range-row">
<button data-level="0.12" aria-label="Set low river level">Low</button>
<button data-level="0.58" aria-label="Set middle river level">Mid</button>
<button data-level="1.18" aria-label="Set high river level">High</button>
<input id="levelRange" type="range" min="0" max="1.2" step="0.01" value="0.52" />
<button id="resetButton" aria-label="Reset camera" title="Reset camera">↺</button>
</div>
<div class="status-row">
<span id="statusText">Rising stage — the float and canoe rise as the gangway eases.</span>
<span class="camera-hint">Drag to orbit · scroll to zoom</span>
</div>
</div>
</section>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8dacb);
scene.fog = new THREE.Fog(0xd8dacb, 18, 36);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 80);
const cameraTarget = new THREE.Vector3(0.15, 1.05, 0.05);
let azimuth = 0.68;
let polar = 0.86;
let cameraZoom = 1.0;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
const hemi = new THREE.HemisphereLight(0xfff7dc, 0x4b5e48, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0cc, 3.15);
sun.position.set(-6, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ad4d7, 0.65);
fill.position.set(8, 5, -6);
scene.add(fill);
const mat = {
plinth: new THREE.MeshStandardMaterial({ color: 0x4b4b40, roughness: 0.92 }),
clay: new THREE.MeshStandardMaterial({ color: 0x8b684e, roughness: 1 }),
silt: new THREE.MeshStandardMaterial({ color: 0xc79b69, roughness: 1 }),
topsoil: new THREE.MeshStandardMaterial({ color: 0x67503a, roughness: 1 }),
turf: new THREE.MeshStandardMaterial({ color: 0x78934d, roughness: 1 }),
riverbed: new THREE.MeshStandardMaterial({ color: 0x705b42, roughness: 1 }),
wood: new THREE.MeshStandardMaterial({ color: 0x79543a, roughness: 0.88 }),
woodLight: new THREE.MeshStandardMaterial({ color: 0xa77a4e, roughness: 0.82 }),
woodDark: new THREE.MeshStandardMaterial({ color: 0x49372b, roughness: 0.92 }),
orange: new THREE.MeshStandardMaterial({ color: 0xe46f43, roughness: 0.72 }),
orangeDark: new THREE.MeshStandardMaterial({ color: 0xb94f31, roughness: 0.85 }),
wall: new THREE.MeshStandardMaterial({ color: 0xd2b986, roughness: 0.9 }),
wallLine: new THREE.MeshStandardMaterial({ color: 0x9b805b, roughness: 0.95 }),
roof: new THREE.MeshStandardMaterial({ color: 0x315d54, roughness: 0.72 }),
window: new THREE.MeshStandardMaterial({
color: 0xb8d8cf,
emissive: 0x6ca49a,
emissiveIntensity: 0.24,
roughness: 0.35
}),
leaf: new THREE.MeshStandardMaterial({ color: 0x4e7f3d, roughness: 0.95, flatShading: true }),
leafLight: new THREE.MeshStandardMaterial({ color: 0x6f9948, roughness: 0.95, flatShading: true }),
leafDark: new THREE.MeshStandardMaterial({ color: 0x315f3b, roughness: 1, flatShading: true }),
path: new THREE.MeshStandardMaterial({ color: 0xb49a68, roughness: 1 }),
rope: new THREE.MeshStandardMaterial({ color: 0x4e4636, roughness: 1 }),
canoe: new THREE.MeshStandardMaterial({
color: 0xc87838,
roughness: 0.74,
side: THREE.DoubleSide
}),
canoeInside: new THREE.MeshStandardMaterial({
color: 0x70401f,
roughness: 0.92,
side: THREE.DoubleSide
}),
shirt: new THREE.MeshStandardMaterial({ color: 0xb84f36, roughness: 0.9 }),
skin: new THREE.MeshStandardMaterial({ color: 0x9c6847, roughness: 0.9 }),
hat: new THREE.MeshStandardMaterial({ color: 0xd8b967, roughness: 0.9 }),
water: new THREE.MeshStandardMaterial({
color: 0x2d9ead,
roughness: 0.22,
metalness: 0.03,
transparent: true,
opacity: 0.44,
depthWrite: false
}),
waterSurface: new THREE.MeshStandardMaterial({
color: 0x58bdc3,
roughness: 0.18,
metalness: 0.03,
transparent: true,
opacity: 0.58,
depthWrite: false,
side: THREE.DoubleSide
}),
flood: new THREE.MeshStandardMaterial({
color: 0x51aeb5,
roughness: 0.25,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
})
};
function box(parent, w, h, d, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, rTop, rBottom, h, material, x = 0, y = 0, z = 0, segments = 10) {
const mesh = new THREE.Mesh(new THREE.CylinderGeometry(rTop, rBottom, h, segments), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const up = new THREE.Vector3(0, 1, 0);
const forward = new THREE.Vector3(0, 0, 1);
function setCylinderBetween(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(1, length, 1);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
}
function cylinderBetween(parent, a, b, radius, material, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, segments),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
setCylinderBetween(mesh, a, b);
return mesh;
}
function setBeamBetween(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.z = length;
mesh.quaternion.setFromUnitVectors(forward, direction.normalize());
}
function beamBetween(parent, a, b, width, thickness, material) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, thickness, 1), material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
setBeamBetween(mesh, a, b);
return mesh;
}
// Ground and cutaway strata.
box(scene, 10.2, 0.18, 6.2, mat.plinth, 0, -1.34, 0);
const bankOutline = [
[0.00, -3.00],
[5.00, -3.00],
[5.00, 3.00],
[0.00, 3.00],
[0.14, 2.55],
[-0.08, 1.90],
[0.12, 1.20],
[-0.09, 0.42],
[0.10, -0.38],
[-0.08, -1.18],
[0.13, -2.10],
[0.00, -3.00]
];
function bankLayer(bottom, depth, material) {
const shape = new THREE.Shape();
bankOutline.forEach(([x, z], index) => {
if (index === 0) shape.moveTo(x, -z);
else shape.lineTo(x, -z);
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
steps: 1,
curveSegments: 1
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = bottom;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 28),
new THREE.LineBasicMaterial({
color: 0x4d3d30,
transparent: true,
opacity: 0.18
})
);
edges.position.copy(mesh.position);
scene.add(edges);
return mesh;
}
bankLayer(-1.22, 1.02, mat.clay);
bankLayer(-0.20, 0.70, mat.silt);
bankLayer( 0.50, 0.35, mat.topsoil);
bankLayer( 0.85, 0.08, mat.turf);
box(scene, 5.1, 1.16, 6.02, mat.riverbed, -2.5, -0.64, 0);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({ color: 0xc9cbbb, roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.44;
floor.receiveShadow = true;
scene.add(floor);
// River water volume and animated surface.
const waterBottom = -0.055;
const waterVolume = box(scene, 5.1, 1, 6.02, mat.water, -2.5, 0.3, 0);
waterVolume.castShadow = false;
waterVolume.renderOrder = 2;
const waterSurface = new THREE.Mesh(new THREE.PlaneGeometry(5.1, 6.02), mat.waterSurface);
waterSurface.rotation.x = -Math.PI / 2;
waterSurface.position.set(-2.5, 0.52, 0);
waterSurface.receiveShadow = false;
waterSurface.renderOrder = 3;
scene.add(waterSurface);
const waveGroup = new THREE.Group();
scene.add(waveGroup);
const waveMaterial = new THREE.LineBasicMaterial({
color: 0xd9f4e9,
transparent: true,
opacity: 0.34
});
for (let row = 0; row < 8; row++) {
const x = -4.65 + row * 0.58;
const points = [];
for (let i = 0; i < 12; i++) {
const t = i / 11;
points.push(new THREE.Vector3(
x + Math.sin(t * Math.PI * 2 + row) * 0.10,
0,
-2.65 + t * 5.3
));
}
const curve = new THREE.CatmullRomCurve3(points);
const line = new THREE.Line(new THREE.BufferGeometry().setFromPoints(curve.getPoints(24)), waveMaterial);
waveGroup.add(line);
}
// A translucent overflow sheet appears as the water overtops the bank.
const floodGeometry = new THREE.BufferGeometry();
const floodPositions = [];
const floodRows = 28;
const floodIndices = [];
for (let i = 0; i < floodRows; i++) {
const z = -3 + (i / (floodRows - 1)) * 6;
floodPositions.push(0.015, 0, z, 0.015, 0, z);
}
for (let i = 0; i < floodRows - 1; i++) {
const a = i * 2;
floodIndices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
floodGeometry.setAttribute("position", new THREE.Float32BufferAttribute(floodPositions, 3));
floodGeometry.setIndex(floodIndices);
const floodMesh = new THREE.Mesh(floodGeometry, mat.flood);
floodMesh.position.y = 1;
floodMesh.renderOrder = 4;
scene.add(floodMesh);
// Fixed landing at the bank.
box(scene, 1.1, 0.14, 1.05, mat.woodDark, 0.15, 1.23, 0.90);
box(scene, 1.1, 0.055, 0.12, mat.orange, 0.15, 1.32, 0.48);
box(scene, 0.10, 0.44, 0.10, mat.woodDark, 0.53, 1.04, 0.55);
box(scene, 0.10, 0.44, 0.10, mat.woodDark, 0.53, 1.04, 1.25);
// Floating landing.
const floatingLanding = new THREE.Group();
scene.add(floatingLanding);
box(floatingLanding, 1.16, 0.11, 1.04, mat.orangeDark, 0, 0.105, 0);
for (let i = 0; i < 7; i++) {
box(
floatingLanding,
1.08,
0.07,
0.115,
mat.orange,
0,
0.18,
-0.43 + i * 0.143
);
}
const floatA = cylinder(floatingLanding, 0.12, 0.12, 1.06, mat.woodDark, -0.28, -0.02, 0);
floatA.rotation.x = Math.PI / 2;
const floatB = cylinder(floatingLanding, 0.12, 0.12, 1.06, mat.woodDark, 0.28, -0.02, 0);
floatB.rotation.x = Math.PI / 2;
floatingLanding.position.set(-1.55, 0.52, 0.90);
// Guide piles and ropes.
const pilePositions = [
new THREE.Vector3(-2.22, 1.72, 0.48),
new THREE.Vector3(-2.22, 1.72, 1.32)
];
for (const p of pilePositions) {
cylinder(scene, 0.065, 0.075, 1.82, mat.woodDark, p.x, 0.86, p.z, 8);
const cap = cylinder(scene, 0.085, 0.085, 0.07, mat.orange, p.x, p.y, p.z, 8);
cap.castShadow = false;
}
const ropeMeshes = [
cylinderBetween(scene, pilePositions[0], new THREE.Vector3(-2.03, 0.18, 0.48), 0.021, mat.rope, 6),
cylinderBetween(scene, pilePositions[1], new THREE.Vector3(-2.03, 0.18, 1.32), 0.021, mat.rope, 6)
];
// Adjustable gangway from the fixed landing to the float.
const gangway = new THREE.Group();
scene.add(gangway);
const gangwayDeck = box(gangway, 0.72, 0.075, 1, mat.woodLight, 0, 0, 0);
const gangwaySlats = [];
for (let i = 0; i < 6; i++) {
gangwaySlats.push(box(gangway, 0.82, 0.07, 0.085, mat.orange, 0, 0.055, 0));
}
// Small stair from the fixed landing to the house porch.
for (let i = 0; i < 5; i++) {
const top = 1.39 + i * 0.14;
box(scene, 0.21, 0.11, 0.84, i % 2 ? mat.woodLight : mat.wood, 0.75 + i * 0.18, top - 0.055, 0.90);
}
beamBetween(
scene,
new THREE.Vector3(0.68, 1.27, 0.48),
new THREE.Vector3(1.58, 1.91, 0.48),
0.09, 0.13, mat.woodDark
);
beamBetween(
scene,
new THREE.Vector3(0.68, 1.27, 1.32),
new THREE.Vector3(1.58, 1.91, 1.32),
0.09, 0.13, mat.woodDark
);
// Raised home.
const houseX = 2.80;
const houseZ = -0.45;
const floorY = 1.95;
for (const sx of [1.85, 3.75]) {
for (const sz of [-1.10, 0.18]) {
cylinder(scene, 0.13, 0.15, 1.03, mat.woodDark, sx, 1.44, sz, 8);
}
}
beamBetween(scene, new THREE.Vector3(1.85, 1.10, -1.10), new THREE.Vector3(3.75, 1.78, 0.18), 0.08, 0.08, mat.wood);
beamBetween(scene, new THREE.Vector3(3.75, 1.10, -1.10), new THREE.Vector3(1.85, 1.78, 0.18), 0.08, 0.08, mat.wood);
box(scene, 2.30, 1.50, 1.75, mat.wall, houseX, floorY + 0.75, houseZ);
box(scene, 2.36, 0.12, 1.82, mat.woodDark, houseX, floorY - 0.02, houseZ);
for (let i = 0; i < 7; i++) {
box(scene, 2.27, 0.012, 0.012, mat.wallLine, houseX, floorY + 0.12 + i * 0.20, houseZ + 0.882);
}
// Front porch.
box(scene, 2.80, 0.12, 0.82, mat.wood, houseX, floorY - 0.05, 0.83);
box(scene, 2.80, 0.08, 0.10, mat.orange, houseX, floorY + 0.03, 1.23);
// Raised ground access stairs.
for (let i = 0; i < 7; i++) {
const top = 1.84 - i * 0.14;
box(scene, 1.16, 0.10, 0.25, i % 2 ? mat.woodLight : mat.wood, houseX, top - 0.05, 1.37 + i * 0.24);
}
beamBetween(
scene,
new THREE.Vector3(houseX - 0.48, 0.96, 2.88),
new THREE.Vector3(houseX - 0.48, 1.89, 1.28),
0.10, 0.15, mat.woodDark
);
beamBetween(
scene,
new THREE.Vector3(houseX + 0.48, 0.96, 2.88),
new THREE.Vector3(houseX + 0.48, 1.89, 1.28),
0.10, 0.15, mat.woodDark
);
for (const x of [houseX - 0.56, houseX + 0.56]) {
cylinder(scene, 0.035, 0.04, 0.93, mat.woodDark, x, 1.39, 2.76, 7);
cylinder(scene, 0.035, 0.04, 0.95, mat.woodDark, x, 1.86, 1.41, 7);
cylinderBetween(
scene,
new THREE.Vector3(x, 1.84, 2.76),
new THREE.Vector3(x, 2.36, 1.41),
0.033, mat.woodDark, 7
);
}
// Door and windows.
box(scene, 0.58, 1.05, 0.055, mat.woodDark, houseX, floorY + 0.53, houseZ + 0.91);
box(scene, 0.035, 0.035, 0.04, mat.orange, houseX + 0.18, floorY + 0.53, houseZ + 0.95);
for (const x of [2.10, 3.50]) {
box(scene, 0.62, 0.57, 0.055, mat.woodDark, x, floorY + 0.94, houseZ + 0.92);
box(scene, 0.49, 0.44, 0.065, mat.window, x, floorY + 0.94, houseZ + 0.955);
box(scene, 0.035, 0.46, 0.035, mat.woodDark, x, floorY + 0.94, houseZ + 0.99);
}
// Gabled roof, ridge parallel to the river bank.
const roofAngle = Math.atan2(0.60, 1.20);
const roofLength = Math.hypot(1.20, 0.60);
const frontRoof = box(scene, 2.94, 0.12, roofLength, mat.roof, houseX, 3.85, 0.15);
frontRoof.rotation.x = roofAngle;
const backRoof = box(scene, 2.94, 0.12, roofLength, mat.roof, houseX, 3.85, -1.05);
backRoof.rotation.x = -roofAngle;
const ridge = cylinder(scene, 0.085, 0.085, 3.05, mat.roofDark || mat.roof, houseX, 4.16, -0.45, 10);
ridge.rotation.z = Math.PI / 2;
// A small painted house sign.
function signTexture(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "#e7d8a9";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#3e5f57";
context.lineWidth = 10;
context.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
context.fillStyle = "#315b54";
context.font = "700 42px system-ui";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(0.94, 0.235),
new THREE.MeshBasicMaterial({ map: signTexture("CASA RIVA") })
);
sign.position.set(houseX, 3.28, houseZ + 0.945);
scene.add(sign);
// Forest floor path.
const pathPoints = [
[2.80, 2.92], [3.10, 2.70], [3.46, 2.43], [3.85, 2.18],
[4.18, 1.83], [4.35, 1.35], [4.45, 0.82], [4.55, 0.20]
];
for (let i = 0; i < pathPoints.length; i++) {
const [x, z] = pathPoints[i];
const patch = new THREE.Mesh(new THREE.CircleGeometry(1, 18), mat.path);
patch.rotation.x = -Math.PI / 2;
patch.scale.set(0.28 + (i % 2) * 0.06, 0.42, 1);
patch.position.set(x, 0.941, z);
patch.receiveShadow = true;
scene.add(patch);
}
// Broadleaf forest edge.
function tree(x, z, scale = 1, variant = 0) {
const group = new THREE.Group();
group.position.set(x, 0.93, z);
group.scale.setScalar(scale);
scene.add(group);
const trunkHeight = 1.40 + (variant % 2) * 0.25;
cylinder(group, 0.12, 0.20, trunkHeight, mat.woodDark, 0, trunkHeight / 2, 0, 8);
const crown = new THREE.Mesh(new THREE.IcosahedronGeometry(0.72, 1), mat.leaf);
crown.position.set(0, trunkHeight + 0.42, 0);
crown.scale.set(1.05, 0.84, 0.92);
crown.castShadow = true;
group.add(crown);
const lobe1 = new THREE.Mesh(new THREE.IcosahedronGeometry(0.52, 1), mat.leafLight);
lobe1.position.set(-0.42, trunkHeight + 0.20, 0.08);
lobe1.scale.set(1.05, 0.8, 1.0);
lobe1.castShadow = true;
group.add(lobe1);
const lobe2 = new THREE.Mesh(new THREE.IcosahedronGeometry(0.50, 1), mat.leafDark);
lobe2.position.set(0.38, trunkHeight + 0.31, -0.12);
lobe2.scale.set(1.0, 0.78, 0.95);
lobe2.castShadow = true;
group.add(lobe2);
const lobe3 = new THREE.Mesh(new THREE.IcosahedronGeometry(0.43, 1), mat.leaf);
lobe3.position.set(0.10, trunkHeight + 0.78, -0.08);
lobe3.scale.set(1.05, 0.78, 0.94);
lobe3.castShadow = true;
group.add(lobe3);
}
tree(0.78, -2.46, 0.83, 0);
tree(1.68, -2.57, 0.93, 1);
tree(3.25, -2.48, 0.88, 2);
tree(4.44, -2.13, 1.00, 3);
tree(4.66, -0.87, 0.82, 0);
tree(4.63, 0.62, 0.72, 1);
// Understory leaves.
function shrub(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.94, z);
group.scale.setScalar(scale);
scene.add(group);
for (let i = 0; i < 5; i++) {
const leaf = new THREE.Mesh(new THREE.IcosahedronGeometry(0.28, 0), i % 2 ? mat.leafLight : mat.leaf);
const a = i / 5 * Math.PI * 2;
leaf.position.set(Math.cos(a) * 0.18, 0.18 + (i % 2) * 0.08, Math.sin(a) * 0.18);
leaf.scale.set(0.7, 1.25, 0.42);
leaf.rotation.z = Math.cos(a) * 0.45;
leaf.castShadow = true;
group.add(leaf);
}
}
shrub(0.55, -1.65, 1.1);
shrub(4.08, -1.73, 0.8);
shrub(4.30, 1.64, 0.72);
shrub(1.28, -2.62, 0.70);
// Driftwood, roots, and stones along the exposed bank.
const log = cylinder(scene, 0.10, 0.13, 1.55, mat.woodDark, 0.37, 1.01, 2.38, 8);
log.rotation.z = Math.PI / 2;
log.rotation.y = -0.24;
cylinderBetween(
scene,
new THREE.Vector3(0.18, 0.96, -1.38),
new THREE.Vector3(-0.22, 0.98, -1.02),
0.055, mat.woodDark, 7
);
cylinderBetween(
scene,
new THREE.Vector3(0.18, 0.96, -1.38),
new THREE.Vector3(0.34, 1.01, -1.67),
0.045, mat.woodDark, 7
);
const stoneMaterial = new THREE.MeshStandardMaterial({ color: 0x8a8d78, roughness: 1, flatShading: true });
[
[0.35, 2.77, 0.12], [-0.12, 2.32, 0.09], [0.48, -0.25, 0.11],
[0.33, -2.45, 0.08], [4.37, 1.85, 0.10]
].forEach(([x, z, s]) => {
const stone = new THREE.Mesh(new THREE.IcosahedronGeometry(s, 0), stoneMaterial);
stone.position.set(x, 0.97, z);
stone.scale.y = 0.65;
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
});
// Custom open canoe hull.
function makeCanoeHull(length = 2.45, maxWidth = 0.76) {
const positions = [];
const rowCount = 16;
const cross = [
[-1, 0.27, 0],
[-0.76, 0.015, 0],
[0, -0.17, 0],
[0.76, 0.015, 0],
[1, 0.27, 0]
];
for (let i = 0; i < rowCount; i++) {
const t = i / (rowCount - 1);
const z = -length / 2 + t * length;
const width = Math.max(0.018, Math.pow(Math.sin(Math.PI * t), 0.68) * maxWidth / 2);
for (const [x, y] of cross) {
positions.push(x * width, y, z);
}
}
const indices = [];
for (let i = 0; i < rowCount - 1; i++) {
for (let j = 0; j < 4; j++) {
const a = i * 5 + j;
const b = a + 5;
indices.push(a, b, a + 1, b, b + 1, a + 1);
}
}
for (const row of [0, rowCount - 1]) {
const a = row * 5;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2, a + 2, a + 3, a + 4);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const canoe = new THREE.Group();
canoe.position.set(-2.48, 0.58, 2.00);
canoe.rotation.y = -0.07;
scene.add(canoe);
const hullGeometry = makeCanoeHull();
const hull = new THREE.Mesh(hullGeometry, mat.canoe);
hull.castShadow = true;
hull.receiveShadow = true;
canoe.add(hull);
const innerHull = new THREE.Mesh(hullGeometry.clone(), mat.canoeInside);
innerHull.scale.set(0.81, 0.72, 0.965);
innerHull.position.y = 0.07;
canoe.add(innerHull);
// Rims.
for (const side of [-1, 1]) {
const points = [];
for (let i = 0; i < 18; i++) {
const t = i / 17;
const z = -1.225 + t * 2.45;
const width = Math.max(0.018, Math.pow(Math.sin(Math.PI * t), 0.68) * 0.38);
points.push(new THREE.Vector3(side * width, 0.275, z));
}
const rim = new THREE.Mesh(
new THREE.TubeGeometry(new THREE.CatmullRomCurve3(points), 36, 0.022, 6, false),
mat.woodLight
);
rim.castShadow = true;
canoe.add(rim);
}
box(canoe, 0.53, 0.06, 0.13, mat.woodLight, 0, 0.21, -0.42);
box(canoe, 0.53, 0.06, 0.13, mat.woodLight, 0, 0.21, 0.40);
// Small paddler.
const torso = new THREE.Mesh(new THREE.SphereGeometry(0.20, 10, 8), mat.shirt);
torso.scale.set(0.78, 1.25, 0.70);
torso.position.set(0, 0.62, -0.10);
torso.castShadow = true;
canoe.add(torso);
const head = new THREE.Mesh(new THREE.SphereGeometry(0.115, 10, 8), mat.skin);
head.position.set(0, 0.92, -0.10);
head.castShadow = true;
canoe.add(head);
const hat = cylinder(canoe, 0.13, 0.17, 0.08, mat.hat, 0, 1.02, -0.10, 12);
hat.castShadow = true;
cylinderBetween(canoe, new THREE.Vector3(-0.10, 0.72, -0.06), new THREE.Vector3(-0.40, 0.52, 0.18), 0.045, mat.skin, 7);
cylinderBetween(canoe, new THREE.Vector3(0.10, 0.72, -0.06), new THREE.Vector3(0.34, 0.49, -0.25), 0.045, mat.skin, 7);
const paddle = cylinderBetween(
canoe,
new THREE.Vector3(-0.70, 0.68, 0.32),
new THREE.Vector3(0.62, 0.43, -0.32),
0.022, mat.woodLight, 7
);
paddle.castShadow = true;
const paddleBlade = new THREE.Mesh(new THREE.SphereGeometry(0.12, 8, 6), mat.wood);
paddleBlade.scale.set(0.35, 1.25, 0.22);
paddleBlade.position.set(0.63, 0.43, -0.33);
paddleBlade.rotation.z = -0.5;
canoe.add(paddleBlade);
// Floating river plants.
const riverPlants = new THREE.Group();
scene.add(riverPlants);
const plantLeafMat = new THREE.MeshStandardMaterial({ color: 0x5f9148, roughness: 0.95, side: THREE.DoubleSide });
const flowerMat = new THREE.MeshStandardMaterial({ color: 0xdba6b2, roughness: 0.9 });
[
[-4.12, -1.58], [-3.55, -0.72], [-4.28, 0.92], [-2.92, -2.15]
].forEach(([x, z], clusterIndex) => {
for (let i = 0; i < 4; i++) {
const leaf = new THREE.Mesh(new THREE.CircleGeometry(0.095 + (i % 2) * 0.025, 10), plantLeafMat);
leaf.rotation.x = -Math.PI / 2;
leaf.rotation.z = i * 0.9;
leaf.position.set(x + Math.cos(i * 2.1) * 0.14, 0.018, z + Math.sin(i * 2.1) * 0.14);
riverPlants.add(leaf);
}
if (clusterIndex % 2 === 0) {
const flower = new THREE.Mesh(new THREE.ConeGeometry(0.05, 0.15, 7), flowerMat);
flower.position.set(x, 0.095, z);
riverPlants.add(flower);
}
});
// River-level gauge.
const gaugeX = -4.38;
const gaugeZ = 2.36;
cylinder(scene, 0.055, 0.065, 1.72, mat.woodDark, gaugeX, 0.80, gaugeZ, 8);
for (let i = 0; i <= 12; i++) {
const y = i * 0.1;
const width = i % 5 === 0 ? 0.39 : 0.24;
box(scene, width, 0.027, 0.035, i % 5 === 0 ? mat.orange : mat.woodLight, gaugeX + 0.17, y, gaugeZ);
}
const gaugeMarker = box(scene, 0.48, 0.095, 0.10, mat.orange, gaugeX + 0.12, 0.52, gaugeZ);
const gaugePointer = new THREE.Mesh(new THREE.ConeGeometry(0.105, 0.22, 3), mat.orange);
gaugePointer.rotation.z = Math.PI / 2;
gaugePointer.rotation.y = Math.PI / 2;
gaugePointer.position.set(gaugeX - 0.25, 0.52, gaugeZ);
scene.add(gaugePointer);
let waterLevel = 0.52;
function updateFlood() {
const overflow = THREE.MathUtils.clamp((waterLevel - 0.88) / 0.32, 0, 1);
const positions = floodGeometry.attributes.position.array;
for (let i = 0; i < floodRows; i++) {
const z = -3 + (i / (floodRows - 1)) * 6;
const rightEdge = 1.45 + Math.sin(i * 0.83) * 0.14 + Math.sin(i * 1.91) * 0.06;
const x = 0.015 + (rightEdge - 0.015) * overflow;
positions[i * 6 + 3] = x;
}
floodGeometry.attributes.position.needsUpdate = true;
floodGeometry.computeVertexNormals();
floodMesh.position.y = waterLevel + 0.012;
mat.flood.opacity = overflow * 0.46;
floodMesh.visible = overflow > 0.005;
}
function updateConnections() {
const floatY = floatingLanding.position.y;
const fixedPoint = new THREE.Vector3(-0.40, 1.32, 0.90);
const floatPoint = new THREE.Vector3(-0.98, floatY + 0.22, 0.90);
const direction = new THREE.Vector3().subVectors(floatPoint, fixedPoint);
const length = direction.length();
gangway.position.copy(fixedPoint).add(floatPoint).multiplyScalar(0.5);
gangway.quaternion.setFromUnitVectors(forward, direction.normalize());
gangwayDeck.scale.z = length;
for (let i = 0; i < gangwaySlats.length; i++) {
const t = gangwaySlats.length === 1 ? 0.5 : i / (gangwaySlats.length - 1);
gangwaySlats[i].position.z = (t - 0.5) * length;
}
setCylinderBetween(
ropeMeshes[0],
pilePositions[0],
new THREE.Vector3(-2.03, floatY + 0.18, 0.48)
);
setCylinderBetween(
ropeMeshes[1],
pilePositions[1],
new THREE.Vector3(-2.03, floatY + 0.18, 1.32)
);
}
function updateLevel(value) {
waterLevel = THREE.MathUtils.clamp(value, 0, 1.2);
const height = Math.max(0.025, waterLevel - waterBottom);
waterVolume.scale.y = height;
waterVolume.position.y = waterBottom + height / 2;
waterSurface.position.y = waterLevel + 0.006;
waveGroup.position.y = waterLevel + 0.018;
riverPlants.position.y = waterLevel + 0.014;
floatingLanding.position.y = waterLevel;
canoe.position.y = waterLevel + 0.065;
gaugeMarker.position.y = waterLevel;
gaugePointer.position.y = waterLevel;
updateFlood();
updateConnections();
document.getElementById("levelValue").innerHTML = `${waterLevel.toFixed(2)} <small>m</small>`;
document.getElementById("gaugeLabel").textContent = `${waterLevel.toFixed(2)} m`;
let status;
if (waterLevel < 0.36) {
status = "Low stage — the landing sits below the porch and the gangway is steep.";
} else if (waterLevel < 0.90) {
status = "Rising stage — the float and canoe rise as the gangway eases.";
} else {
status = "High stage — the bank begins to flood and the landing nearly meets the porch.";
}
document.getElementById("statusText").textContent = status;
}
const range = document.getElementById("levelRange");
range.addEventListener("input", (event) => updateLevel(parseFloat(event.target.value)));
document.querySelectorAll("[data-level]").forEach((button) => {
button.addEventListener("click", () => {
const value = parseFloat(button.dataset.level);
range.value = value;
updateLevel(value);
});
});
document.getElementById("resetButton").addEventListener("click", () => {
azimuth = 0.68;
polar = 0.86;
cameraZoom = 1;
updateCamera();
});
// Manual orthographic orbit controls, implemented without external addons.
function updateCamera() {
const distance = 16;
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + distance * sinPolar * Math.sin(azimuth),
cameraTarget.y + distance * Math.cos(polar),
cameraTarget.z + distance * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(8.8, 11.2 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar - dy * 0.005, 0.38, 1.35);
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();
cameraZoom = THREE.MathUtils.clamp(cameraZoom * Math.exp(-event.deltaY * 0.001), 0.72, 1.65);
updateCamera();
}, { passive: false });
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
});
const projectedGauge = new THREE.Vector3();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
const floatBob = Math.sin(time * 1.15) * 0.008;
floatingLanding.position.y = waterLevel + floatBob;
canoe.position.y = waterLevel + 0.065 + Math.sin(time * 1.32) * 0.018;
canoe.rotation.z = Math.sin(time * 0.83) * 0.012;
canoe.rotation.x = Math.sin(time * 0.61 + 1.4) * 0.007;
waveGroup.position.y = waterLevel + 0.018 + Math.sin(time * 0.8) * 0.003;
updateConnections();
projectedGauge.set(gaugeX + 0.05, waterLevel, gaugeZ + 0.06).project(camera);
const gaugeLabel = document.getElementById("gaugeLabel");
gaugeLabel.style.left = `${(projectedGauge.x * 0.5 + 0.5) * window.innerWidth}px`;
gaugeLabel.style.top = `${(-projectedGauge.y * 0.5 + 0.5) * window.innerHeight}px`;
gaugeLabel.style.visibility = projectedGauge.z < 1 ? "visible" : "hidden";
renderer.render(scene, camera);
}
updateCamera();
updateLevel(0.52);
animate();
</script>
</body>
</html>
```