Prompt specification
Build or customize the Three.js 3D scene "Mekong footbridge plank and irrigation-channel tile" 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: Mekong footbridge plank and irrigation-channel tile
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mekong-footbridge-plank-and-irrigation-channel-tile-x3089
Scene Description Prompt:
Build a stylized Mekong Delta footbridge over an irrigation channel, separating foot traffic from flowing water. One HTML file with Three.js from cdnjs.
Working Three.js Starter (mekong-footbridge-plank-and-irrigation-channel-tile-x3089):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mekong Delta — Irrigation Footbridge</title>
<style>
:root {
--ink: #173c3b;
--paper: rgba(247, 242, 222, 0.92);
--accent: #e67845;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfe6df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 26px;
left: 28px;
z-index: 10;
width: min(360px, calc(100vw - 56px));
padding: 18px 20px 17px;
border: 1px solid rgba(23, 60, 59, 0.15);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 16px 45px rgba(27, 64, 58, 0.13);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #4d6f66;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
border-radius: 2px;
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 42px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 11px 0 0;
max-width: 290px;
color: #496760;
font-size: 12px;
line-height: 1.5;
}
.scene-tag {
position: fixed;
right: 26px;
top: 28px;
z-index: 10;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 14px;
border: 1px solid rgba(23, 60, 59, 0.12);
border-radius: 999px;
background: rgba(247, 242, 222, 0.82);
color: #315d55;
box-shadow: 0 9px 25px rgba(27, 64, 58, 0.1);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
pointer-events: none;
}
.scene-tag span {
width: 7px;
height: 7px;
border-radius: 50%;
background: #e67845;
box-shadow: 0 0 0 4px rgba(230, 120, 69, 0.16);
}
.controls {
position: fixed;
left: 28px;
bottom: 26px;
z-index: 10;
display: flex;
align-items: center;
gap: 10px;
pointer-events: none;
}
.hint {
padding: 10px 13px;
border: 1px solid rgba(23, 60, 59, 0.12);
border-radius: 999px;
background: rgba(247, 242, 222, 0.8);
color: #496760;
box-shadow: 0 8px 25px rgba(27, 64, 58, 0.09);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
}
button {
padding: 10px 14px;
border: 0;
border-radius: 999px;
background: var(--ink);
color: #f7f2de;
box-shadow: 0 8px 25px rgba(27, 64, 58, 0.15);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
background: #245551;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #d7e8df;
color: #315d55;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
.title-card {
top: 16px;
left: 16px;
padding: 15px 16px;
}
.subtitle {
display: none;
}
.scene-tag {
top: auto;
right: 16px;
bottom: 68px;
}
.controls {
left: 16px;
bottom: 16px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<section class="title-card">
<div class="eyebrow">Mekong Delta · Vietnam</div>
<h1>Across the<br />Irrigation Channel</h1>
<p class="subtitle">
A raised timber footbridge keeps village foot traffic safely above the
seasonal flow of the delta.
</p>
</section>
<div class="scene-tag"><span></span>Foot traffic above flowing water</div>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom</div>
<button id="resetView" type="button">Reset view</button>
</div>
<div id="loading">Preparing the delta…</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 loading = document.getElementById("loading");
// ---------------------------------------------------------------------
// Renderer, camera, and lighting
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfe6df);
scene.fog = new THREE.Fog(0xcfe6df, 31, 72);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
160
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
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 hemisphere = new THREE.HemisphereLight(0xfff4d3, 0x486a4d, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe5b0, 3.25);
sun.position.set(-13, 25, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ed4d0, 0.65);
fill.position.set(16, 8, -18);
scene.add(fill);
// ---------------------------------------------------------------------
// Shared materials
// ---------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
const M = {
earth: material(0x8c7450),
soil: material(0x695c40),
grass: material(0x6f8c54),
grassLight: material(0x8aa363),
grassDark: material(0x4d7049),
path: material(0xc4a979),
sand: material(0xcbb27a),
wood: material(0x6d4630),
woodLight: material(0x9b6840),
woodDark: material(0x493227),
roof: material(0x744a39),
wall: material(0xa9794f),
wallBlue: material(0x6f9184),
water: material(0x3d9996, {
roughness: 0.28,
metalness: 0.08,
transparent: true,
opacity: 0.96
}),
current: new THREE.MeshBasicMaterial({
color: 0xd9f0df,
transparent: true,
opacity: 0.42,
depthWrite: false,
side: THREE.DoubleSide
}),
leaf: material(0x315f3d, { side: THREE.DoubleSide }),
leafLight: material(0x5c8647, { side: THREE.DoubleSide }),
leafDark: material(0x244c37, { side: THREE.DoubleSide }),
trunk: material(0x8b6846),
stone: material(0x8d9581),
black: material(0x293d37),
white: material(0xf4ead0),
window: material(0xf4c76e, {
emissive: 0x7f4a12,
emissiveIntensity: 0.25,
roughness: 0.45
})
};
// ---------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
rTop,
rBottom,
h,
mat,
x = 0,
y = 0,
z = 0,
segments = 9
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(parent, radius, mat, x = 0, y = 0, z = 0, detail = 1) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 10, 7),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam(parent, a, b, radius, mat, radialSegments = 8) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function randomBetween(min, max) {
return min + Math.random() * (max - min);
}
// ---------------------------------------------------------------------
// Delta terrain and irrigation channel
// ---------------------------------------------------------------------
const terrain = new THREE.Group();
scene.add(terrain);
box(terrain, 62, 1.2, 62, M.soil, 0, -1.25, 0, false);
box(terrain, 62, 1.2, 30, M.grass, 0, 0, 19, false);
box(terrain, 62, 1.2, 30, M.grass, 0, 0, -19, false);
// Sandy edges and narrow grassy verges.
box(terrain, 62, 0.16, 0.85, M.sand, 0, 0.65, 4.1, false);
box(terrain, 62, 0.16, 0.85, M.sand, 0, 0.65, -4.1, false);
box(terrain, 62, 0.12, 1.15, M.grassLight, 0, 0.7, 4.95, false);
box(terrain, 62, 0.12, 1.15, M.grassLight, 0, 0.7, -4.95, false);
const water = new THREE.Mesh(new THREE.PlaneGeometry(62, 8), M.water);
water.rotation.x = -Math.PI / 2;
water.position.y = 0.03;
water.receiveShadow = true;
scene.add(water);
// Approach paths continue on both banks.
box(terrain, 2.9, 0.09, 27, M.path, 0, 0.69, 18.5, false);
box(terrain, 2.9, 0.09, 27, M.path, 0, 0.69, -18.5, false);
// ---------------------------------------------------------------------
// Rice and vegetable fields
// ---------------------------------------------------------------------
const fieldColors = [
material(0x8fa663),
material(0xa7aa65),
material(0x688c51),
material(0x7b9a58),
material(0xb1a56c)
];
function addField(x, z, w, d, colorIndex, rowCount = 7) {
box(terrain, w, 0.06, d, fieldColors[colorIndex % fieldColors.length], x, 0.67, z, false);
for (let i = 0; i < rowCount; i++) {
const rowZ = z - d / 2 + ((i + 0.5) * d) / rowCount;
box(
terrain,
w - 0.35,
0.035,
0.065,
M.grassDark,
x,
0.72,
rowZ,
false
);
}
}
addField(-16, -11, 8, 7, 0, 8);
addField(-6, -13, 7, 6, 2, 7);
addField(7, -12, 8, 8, 1, 9);
addField(18, -13, 8, 7, 3, 8);
addField(-18, 15, 8, 7, 1, 8);
addField(-7, 14, 7, 8, 4, 9);
addField(9, 14, 8, 7, 0, 8);
addField(19, 15, 7, 8, 2, 8);
// Small irrigation cuts within the fields.
box(terrain, 13, 0.035, 0.36, M.water, -13, 0.73, -8.1, false);
box(terrain, 0.36, 0.035, 9, M.water, 2.5, 0.73, -13, false);
box(terrain, 11, 0.035, 0.36, M.water, 14.5, 0.73, 11.2, false);
// ---------------------------------------------------------------------
// Timber footbridge
// ---------------------------------------------------------------------
const bridge = new THREE.Group();
scene.add(bridge);
function deckY(z) {
return 1.05 + 0.7 * (1 - Math.pow(z / 5, 2));
}
const plankMaterials = [
material(0x9b6840),
material(0x875536),
material(0xa97649),
material(0x79503a)
];
// Individual curved deck planks.
const plankCount = 29;
for (let i = 0; i < plankCount; i++) {
const z = -4.85 + (i * 9.7) / (plankCount - 1);
const plank = box(
bridge,
2.7,
0.16,
0.32,
plankMaterials[i % plankMaterials.length],
0,
deckY(z),
z
);
plank.rotation.x = Math.sin(z * 0.6) * 0.006;
}
// Structural stringers.
const stringerZ = [-4.8, -3.2, -1.6, 0, 1.6, 3.2, 4.8];
for (const x of [-1.08, 1.08]) {
for (let i = 0; i < stringerZ.length - 1; i++) {
const z1 = stringerZ[i];
const z2 = stringerZ[i + 1];
beam(
bridge,
[x, deckY(z1) - 0.22, z1],
[x, deckY(z2) - 0.22, z2],
0.13,
M.woodDark
);
}
}
// Piles and cross beams descending into the channel.
const supportZ = [-4.45, -2.85, -1.25, 0.4, 2, 3.6, 4.45];
for (const z of supportZ) {
const top = deckY(z) - 0.12;
const bottom = -0.65;
const height = top - bottom;
cylinder(
bridge,
0.13,
0.17,
height,
M.woodDark,
-1.08,
bottom + height / 2,
z,
8
);
cylinder(
bridge,
0.13,
0.17,
height,
M.woodDark,
1.08,
bottom + height / 2,
z,
8
);
box(
bridge,
2.55,
0.18,
0.2,
M.wood,
0,
top - 0.1,
z
);
}
// Rail posts.
const railZ = [-4.9, -3.65, -2.4, -1.15, 0.1, 1.35, 2.6, 3.85, 4.9];
for (const x of [-1.42, 1.42]) {
for (const z of railZ) {
cylinder(
bridge,
0.075,
0.095,
1.38,
M.woodDark,
x,
deckY(z) + 0.7,
z,
8
);
sphere(bridge, 0.105, M.woodLight, x, deckY(z) + 1.4, z, 0);
}
// Continuous upper and lower handrails, following the bridge arch.
for (let i = 0; i < railZ.length - 1; i++) {
const z1 = railZ[i];
const z2 = railZ[i + 1];
beam(
bridge,
[x, deckY(z1) + 1.36, z1],
[x, deckY(z2) + 1.36, z2],
0.075,
M.woodLight
);
beam(
bridge,
[x, deckY(z1) + 0.68, z1],
[x, deckY(z2) + 0.68, z2],
0.055,
M.wood
);
}
}
// Small timber approach steps at both ends.
for (const side of [-1, 1]) {
for (let i = 0; i < 3; i++) {
const z = side * (5.18 + i * 0.34);
const top = 0.76 + i * 0.12;
box(
bridge,
2.55,
top - 0.61,
0.37,
M.woodLight,
0,
(top + 0.61) / 2,
z
);
}
}
// ---------------------------------------------------------------------
// Flowing current, wakes, and water plants
// ---------------------------------------------------------------------
const currentLines = [];
for (let i = 0; i < 44; i++) {
const line = new THREE.Mesh(
new THREE.PlaneGeometry(randomBetween(0.7, 2.5), randomBetween(0.035, 0.085)),
M.current
);
line.rotation.x = -Math.PI / 2;
line.position.set(randomBetween(-30, 30), 0.08, randomBetween(-3.6, 3.6));
line.rotation.z = randomBetween(-0.05, 0.05);
line.renderOrder = 2;
line.userData.speed = randomBetween(0.55, 1.35);
scene.add(line);
currentLines.push(line);
}
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xc9eadc,
transparent: true,
opacity: 0.26,
depthWrite: false,
side: THREE.DoubleSide
});
const ripples = [];
for (let i = 0; i < 18; i++) {
const ripple = new THREE.Mesh(
new THREE.RingGeometry(0.32, 0.37, 32),
rippleMaterial.clone()
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(
randomBetween(-25, 25),
0.095,
randomBetween(-3.5, 3.5)
);
ripple.scale.set(randomBetween(0.8, 2), randomBetween(0.35, 0.8), 1);
ripple.userData.phase = Math.random() * Math.PI * 2;
scene.add(ripple);
ripples.push(ripple);
}
function addLilyPad(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.105, z);
const pad = new THREE.Mesh(
new THREE.CircleGeometry(randomBetween(0.22, 0.42), 12),
M.leafLight
);
pad.rotation.x = -Math.PI / 2;
pad.rotation.z = Math.random() * Math.PI * 2;
pad.receiveShadow = true;
group.add(pad);
if (Math.random() > 0.45) {
const flower = sphere(
group,
0.07,
material(0x9b72b0),
0.05,
0.07,
0.02,
0
);
flower.scale.y = 0.65;
}
scene.add(group);
}
for (let i = 0; i < 18; i++) {
addLilyPad(
randomBetween(-28, 28),
(Math.random() > 0.5 ? 1 : -1) * randomBetween(2.9, 3.65)
);
}
// ---------------------------------------------------------------------
// Stilt houses
// ---------------------------------------------------------------------
function addGableEnd(parent, x, eaveY, ridgeY, halfDepth, mat) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
x, eaveY, -halfDepth,
x, eaveY, halfDepth,
x, ridgeY, 0
], 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, mat);
mesh.material.side = THREE.DoubleSide;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
}
function createStiltHouse(x, z, scale, rotation, roofMaterial, wallMaterial) {
const house = new THREE.Group();
house.position.set(x, 0.62, z);
house.rotation.y = rotation;
house.scale.setScalar(scale);
scene.add(house);
// Stilts and cross braces.
for (const sx of [-1.8, 1.8]) {
for (const sz of [-1.35, 1.35]) {
cylinder(house, 0.11, 0.15, 1.9, M.woodDark, sx, 0.95, sz, 8);
}
}
beam(house, [-1.8, 0.35, -1.35], [1.8, 1.65, -1.35], 0.07, M.wood);
beam(house, [1.8, 0.35, 1.35], [-1.8, 1.65, 1.35], 0.07, M.wood);
box(house, 4.8, 0.22, 3.9, M.woodLight, 0, 1.8, 0);
box(house, 4.35, 2.35, 3.2, wallMaterial, 0, 3.04, 0);
// Gabled roof made from two thick slabs.
const roofRise = 1.15;
const halfDepth = 1.95;
const slopeLength = Math.sqrt(halfDepth * halfDepth + roofRise * roofRise);
const roofAngle = Math.atan2(roofRise, halfDepth);
const leftRoof = box(
house,
5.2,
0.16,
slopeLength,
roofMaterial,
0,
4.22 + roofRise / 2,
-halfDepth / 2
);
leftRoof.rotation.x = -roofAngle;
const rightRoof = box(
house,
5.2,
0.16,
slopeLength,
roofMaterial,
0,
4.22 + roofRise / 2,
halfDepth / 2
);
rightRoof.rotation.x = roofAngle;
beam(
house,
[-2.65, 5.39, 0],
[2.65, 5.39, 0],
0.08,
M.woodDark
);
addGableEnd(house, -2.18, 4.2, 5.37, 1.6, wallMaterial);
addGableEnd(house, 2.18, 4.2, 5.37, 1.6, wallMaterial);
// Front balcony.
box(house, 4.65, 0.14, 1.45, M.woodLight, 0, 1.83, 2.4);
for (const sx of [-2, 2]) {
for (const sz of [1.85, 2.9]) {
cylinder(house, 0.055, 0.065, 1.05, M.wood, sx, 2.38, sz, 7);
}
}
beam(house, [-2.05, 2.9, 2.9], [2.05, 2.9, 2.9], 0.055, M.wood);
// Door and glowing windows.
box(house, 0.85, 1.75, 0.08, M.woodDark, -0.55, 2.83, 1.63);
box(house, 0.9, 0.85, 0.08, M.window, 0.9, 3.2, 1.63);
box(house, 0.8, 0.8, 0.08, M.window, -2.21, 3.2, 0.3);
box(house, 0.08, 0.85, 0.85, M.window, 2.21, 3.2, -0.3);
// Ladder down to the bank.
beam(house, [-1.25, 0.1, 2.25], [-1.25, 1.8, 1.95], 0.05, M.wood);
beam(house, [-0.65, 0.1, 2.25], [-0.65, 1.8, 1.95], 0.05, M.wood);
for (let i = 0; i < 5; i++) {
const t = i / 4;
beam(
house,
[-1.25, 0.2 + t * 1.5, 2.22 - t * 0.25],
[-0.65, 0.2 + t * 1.5, 2.22 - t * 0.25],
0.035,
M.woodLight
);
}
return house;
}
createStiltHouse(-9.3, 9.2, 0.9, 0.08, M.roof, M.wall);
createStiltHouse(11.8, -9.5, 0.83, -0.12, M.wallBlue, M.wall);
// ---------------------------------------------------------------------
// Palms and low vegetation
// ---------------------------------------------------------------------
function createPalm(x, z, scale = 1, lean = 0.2) {
const palm = new THREE.Group();
palm.position.set(x, 0.62, z);
palm.scale.setScalar(scale);
palm.rotation.y = Math.random() * Math.PI * 2;
scene.add(palm);
const points = [
[0, 0, 0],
[lean * 0.25, 1.05, 0.04],
[lean * 0.55, 2.05, 0.1],
[lean * 0.82, 3.05, 0.15],
[lean, 4.05, 0.17]
];
for (let i = 0; i < points.length - 1; i++) {
beam(palm, points[i], points[i + 1], 0.19 - i * 0.02, M.trunk, 8);
}
const top = points[points.length - 1];
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2 + Math.random() * 0.18;
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0, 0,
0.75, 0.2, 0,
1.85, 0.05, 0,
3.05, -0.55, 0,
0.8, -0.32, 0
], 3)
);
geometry.setIndex([
0, 1, 4,
1, 2, 4,
2, 3, 4,
2, 3, 0
]);
geometry.computeVertexNormals();
const frond = new THREE.Mesh(
geometry,
i % 2 ? M.leaf : M.leafLight
);
frond.position.set(top[0], top[1], top[2]);
frond.rotation.y = angle;
frond.rotation.z = randomBetween(-0.08, 0.1);
frond.castShadow = true;
frond.receiveShadow = true;
palm.add(frond);
}
for (let i = 0; i < 3; i++) {
sphere(
palm,
0.17,
M.woodDark,
top[0] + randomBetween(-0.18, 0.18),
top[1] - 0.18,
top[2] + randomBetween(-0.18, 0.18),
0
);
}
}
const palmPositions = [
[-15, 7.5, 1.1],
[-19, -8, 1.18],
[-12.5, -18, 0.92],
[7, -18, 1.03],
[16, -7.5, 1.12],
[21, 8, 1.0],
[16, 18, 1.2],
[4.2, 21, 0.88],
[-5.2, -21.5, 1.05],
[-23, 19, 0.95]
];
palmPositions.forEach(([x, z, s], i) => {
createPalm(x, z, s, i % 2 ? 0.25 : -0.18);
});
function createBush(x, z, scale = 1) {
const bush = new THREE.Group();
bush.position.set(x, 0.7, z);
bush.scale.setScalar(scale);
scene.add(bush);
for (let i = 0; i < 4; i++) {
const leaf = new THREE.Mesh(
new THREE.IcosahedronGeometry(randomBetween(0.35, 0.58), 0),
i % 2 ? M.leafLight : M.leaf
);
leaf.position.set(
randomBetween(-0.45, 0.45),
randomBetween(0.15, 0.5),
randomBetween(-0.4, 0.4)
);
leaf.scale.y = randomBetween(0.65, 1.1);
leaf.castShadow = true;
leaf.receiveShadow = true;
bush.add(leaf);
}
}
const bushPositions = [
[-5, 7, 1], [-5.8, -7, 0.9], [5.7, 7, 1.1], [6, -7, 0.8],
[-12, 5.8, 0.9], [12, 5.8, 1], [-20, 11, 1.1], [20, -11, 1],
[-17, -19, 0.9], [12, 20, 1.05], [22, 17, 0.9], [-22, -17, 1.1],
[4, -6, 0.55], [-4, 6, 0.55]
];
bushPositions.forEach(([x, z, s]) => createBush(x, z, s));
// ---------------------------------------------------------------------
// People
// ---------------------------------------------------------------------
const skinMaterials = [
material(0xc88f61),
material(0xe0ad7e),
material(0x9f6744)
];
function createPerson(shirtColor, pantsColor, hatColor, skinIndex = 0) {
const person = new THREE.Group();
const skin = skinMaterials[skinIndex % skinMaterials.length];
const shirt = material(shirtColor);
const pants = material(pantsColor);
const hat = material(hatColor);
cylinder(person, 0.17, 0.23, 0.63, shirt, 0, 1.02, 0, 8);
sphere(person, 0.205, skin, 0, 1.53, 0, 1);
cylinder(person, 0.28, 0.32, 0.055, hat, 0, 1.72, 0, 10);
cylinder(person, 0.16, 0.21, 0.18, hat, 0, 1.82, 0, 9);
const legPivots = [];
for (const x of [-0.11, 0.11]) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.73, 0);
cylinder(pivot, 0.075, 0.085, 0.62, pants, 0, -0.31, 0, 7);
box(pivot, 0.16, 0.09, 0.26, M.woodDark, 0, -0.64, 0.04);
person.add(pivot);
legPivots.push(pivot);
}
const armPivots = [];
for (const x of [-0.25, 0.25]) {
const pivot = new THREE.Group();
pivot.position.set(x, 1.27, 0);
cylinder(pivot, 0.055, 0.065, 0.53, skin, 0, -0.26, 0, 7);
person.add(pivot);
armPivots.push(pivot);
}
person.userData.legs = legPivots;
person.userData.arms = armPivots;
person.castShadow = true;
scene.add(person);
return person;
}
const walkers = [];
const peopleSpecs = [
[0xe37c4f, 0x344c52, 0xe6d6a6, 0],
[0x4e8790, 0x6e5a42, 0xd1b273, 1],
[0xf0c45c, 0x43574b, 0x9a5a3a, 2],
[0xd4d7b2, 0x5a6970, 0xdac898, 0]
];
peopleSpecs.forEach((spec, i) => {
const person = createPerson(...spec);
person.userData.x = i % 2 === 0 ? -0.52 : 0.53;
person.userData.direction = i < 2 ? 1 : -1;
person.userData.speed = 0.25 + i * 0.018;
person.userData.offset = i * 0.27;
person.userData.phase = i * 1.7;
walkers.push(person);
});
// A person resting beside the field path.
const farmer = createPerson(0x78935d, 0x584b3b, 0xb98a4f, 1);
farmer.position.set(2.4, 0.72, 7.6);
farmer.rotation.y = 0.6;
farmer.scale.setScalar(0.95);
// ---------------------------------------------------------------------
// Sampan in the channel
// ---------------------------------------------------------------------
function createSampan() {
const boat = new THREE.Group();
const topOutline = [
[-3.1, 0],
[-2.2, -0.64],
[1.85, -0.64],
[3.05, 0],
[1.85, 0.64],
[-2.2, 0.64]
];
const positions = [];
const indices = [];
for (const [x, z] of topOutline) {
positions.push(x, 0.42, z);
}
for (const [x, z] of topOutline) {
positions.push(x * 0.84, -0.05, z * 0.48);
}
// Sides.
for (let i = 0; i < topOutline.length; i++) {
const next = (i + 1) % topOutline.length;
indices.push(i, next, i + 6);
indices.push(next, next + 6, i + 6);
}
// Top deck fan.
for (let i = 0; i < topOutline.length; i++) {
const next = (i + 1) % topOutline.length;
indices.push(12, next, i);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const hull = new THREE.Mesh(geometry, M.woodDark);
hull.castShadow = true;
hull.receiveShadow = true;
boat.add(hull);
box(boat, 3.1, 0.11, 0.8, M.woodLight, -0.25, 0.43, 0);
beam(boat, [-1.4, 0.65, 0], [1.4, 0.65, 0], 0.04, M.wood);
const passenger = createPerson(0xd56f45, 0x3e5355, 0xd7bb72, 1);
passenger.scale.setScalar(0.72);
passenger.position.set(-0.55, 0.49, 0);
passenger.rotation.y = Math.PI / 2;
// A low basket and pole in the bow.
cylinder(boat, 0.28, 0.22, 0.34, material(0xb28a50), 1.25, 0.61, 0, 10);
beam(boat, [-1.4, 0.55, 0.35], [2.2, 0.65, -0.25], 0.025, M.woodLight);
boat.position.set(-8.2, 0.08, 1.35);
boat.rotation.y = 0.03;
boat.userData.baseY = boat.position.y;
scene.add(boat);
return boat;
}
const boat = createSampan();
// ---------------------------------------------------------------------
// Rocks, clouds, and birds
// ---------------------------------------------------------------------
for (let i = 0; i < 18; i++) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(randomBetween(0.12, 0.3), 0),
M.stone
);
rock.position.set(
randomBetween(-28, 28),
0.74,
(Math.random() > 0.5 ? 1 : -1) * randomBetween(4.25, 4.75)
);
rock.scale.set(1.4, 0.7, 1);
rock.rotation.set(
Math.random(),
Math.random(),
Math.random()
);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
function createCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
const cloudMaterial = material(0xf2eedb, {
roughness: 1,
transparent: true,
opacity: 0.83,
depthWrite: false
});
const positions = [
[-1.1, 0, 0],
[-0.35, 0.25, 0],
[0.45, 0.15, 0],
[1.1, -0.05, 0]
];
positions.forEach(([px, py, pz], i) => {
const puff = sphere(cloud, i === 1 ? 0.9 : 0.68, cloudMaterial, px, py, pz, 1);
puff.scale.set(1.25, 0.65, 0.8);
puff.castShadow = false;
});
scene.add(cloud);
}
createCloud(-13, 12.5, -27, 1.35);
createCloud(11, 15, -34, 1.8);
createCloud(25, 10.5, -25, 1.1);
createCloud(-28, 9.5, -18, 0.9);
const birds = [];
const birdMaterial = new THREE.LineBasicMaterial({
color: 0x3a5855,
transparent: true,
opacity: 0.75
});
for (let i = 0; i < 5; i++) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.38, 0.16, 0),
new THREE.Vector3(0, -0.03, 0),
new THREE.Vector3(0.38, 0.16, 0)
]);
const bird = new THREE.Line(geometry, birdMaterial);
bird.position.set(-10 + i * 4.5, 8 + (i % 2) * 1.2, -13 - i * 1.8);
bird.scale.setScalar(0.65 + (i % 3) * 0.12);
bird.userData.offset = i * 1.4;
scene.add(bird);
birds.push(bird);
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, and reset
// ---------------------------------------------------------------------
const defaultView = {
yaw: 0.68,
pitch: 0.5,
radius: 23.5
};
const view = {
yaw: defaultView.yaw,
pitch: defaultView.pitch,
radius: defaultView.radius
};
const target = new THREE.Vector3(0, 1.25, 0);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
view.yaw -= dx * 0.006;
view.pitch = THREE.MathUtils.clamp(
view.pitch + dy * 0.004,
0.16,
1.18
);
});
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();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
12,
43
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") view.yaw -= 0.12;
if (event.key === "ArrowRight") view.yaw += 0.12;
if (event.key === "ArrowUp") {
view.pitch = THREE.MathUtils.clamp(view.pitch + 0.08, 0.16, 1.18);
}
if (event.key === "ArrowDown") {
view.pitch = THREE.MathUtils.clamp(view.pitch - 0.08, 0.16, 1.18);
}
if (event.key === "+" || event.key === "=") {
view.radius = Math.max(12, view.radius - 1.5);
}
if (event.key === "-") {
view.radius = Math.min(43, view.radius + 1.5);
}
});
document.getElementById("resetView").addEventListener("click", () => {
view.yaw = defaultView.yaw;
view.pitch = defaultView.pitch;
view.radius = defaultView.radius;
});
renderer.domElement.addEventListener("dblclick", () => {
view.yaw = defaultView.yaw;
view.pitch = defaultView.pitch;
view.radius = defaultView.radius;
});
function updateCamera() {
const horizontal = Math.cos(view.pitch) * view.radius;
camera.position.set(
target.x + Math.sin(view.yaw) * horizontal,
target.y + Math.sin(view.pitch) * view.radius,
target.z + Math.cos(view.yaw) * horizontal
);
camera.lookAt(target);
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
updateCamera();
// Current streaks move from west to east.
for (const line of currentLines) {
line.position.x += delta * line.userData.speed;
if (line.position.x > 31) {
line.position.x = -31;
line.position.z = randomBetween(-3.55, 3.55);
}
}
// Expanding water rings.
for (const ripple of ripples) {
const cycle = (elapsed * 0.16 + ripple.userData.phase) % 1;
const scale = 0.6 + cycle * 1.7;
ripple.scale.x = scale * 1.3;
ripple.scale.y = scale * 0.55;
ripple.material.opacity = 0.3 * (1 - cycle);
}
// Walkers move independently across the bridge.
for (const person of walkers) {
const data = person.userData;
const span = 8.5;
const travel = (elapsed * data.speed + data.offset) % span;
const z = data.direction > 0
? -4.25 + travel
: 4.25 - travel;
person.position.set(data.x, deckY(z) + 0.11, z);
person.rotation.y = data.direction > 0 ? 0 : Math.PI;
const stride = Math.sin(elapsed * 5.4 + data.phase) * 0.32;
person.userData.legs[0].rotation.x = stride;
person.userData.legs[1].rotation.x = -stride;
person.userData.arms[0].rotation.x = -stride * 0.75;
person.userData.arms[1].rotation.x = stride * 0.75;
}
// Gentle bobbing of the sampan.
boat.position.y = boat.userData.baseY + Math.sin(elapsed * 1.25) * 0.035;
boat.rotation.z = Math.sin(elapsed * 0.8) * 0.015;
// Birds glide slowly across the distant sky.
for (const bird of birds) {
bird.position.x += delta * 0.32;
bird.position.y += Math.sin(elapsed * 0.8 + bird.userData.offset) * delta * 0.08;
if (bird.position.x > 30) bird.position.x = -30;
}
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
setTimeout(() => loading.classList.add("hidden"), 180);
}
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
animate();
</script>
</body>
</html>
```