Prompt specification
Build or customize the Three.js 3D scene "Delta channel bank and raised homestead platform" 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: Delta channel bank and raised homestead platform
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/delta-channel-bank-and-raised-homestead-platform-x3065
Scene Description Prompt:
A voxel Ganges–Brahmaputra delta channel beside a raised homestead platform, with modest elevation differences. Three.js from cdnjs, one HTML file.
Working Three.js Starter (delta-channel-bank-and-raised-homestead-platform-x3065):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Delta Homestead</title>
<style>
:root {
color-scheme: light;
--ink: #213b3b;
--muted: #58716d;
--paper: rgba(248, 244, 226, 0.88);
--line: rgba(42, 77, 73, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 18%, rgba(255, 250, 218, 0.72), transparent 30%),
linear-gradient(155deg, #d9e8e4 0%, #c8d9d2 55%, #b7cbc4 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 2;
pointer-events: none;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 12px 36px rgba(37, 63, 57, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.title {
top: 22px;
left: 22px;
max-width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 4px;
}
.eyebrow {
margin: 0 0 7px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
color: #6e7c59;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3.2vw, 39px);
font-weight: 500;
line-height: 1.03;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 330px;
margin: 9px 0 0;
font-size: 12px;
line-height: 1.5;
color: var(--muted);
}
.survey {
top: 22px;
right: 22px;
padding: 11px 13px;
border-radius: 4px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #4c6762;
}
.survey span {
display: block;
margin-top: 3px;
color: #819089;
font-size: 9px;
font-weight: 650;
}
.controls {
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 13px;
padding: 10px 12px;
border-radius: 4px;
color: #506863;
font-size: 10px;
line-height: 1.3;
}
.controls b {
color: #294744;
font-weight: 800;
}
.divider {
width: 1px;
height: 22px;
background: var(--line);
}
button {
pointer-events: auto;
border: 1px solid rgba(45, 78, 73, 0.22);
border-radius: 3px;
padding: 7px 10px;
background: rgba(255, 255, 255, 0.55);
color: #2e504b;
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.95);
}
button:active {
transform: translateY(1px);
}
.corner {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 2;
width: 34px;
height: 34px;
border: 1px solid rgba(42, 77, 73, 0.18);
border-radius: 50%;
background: rgba(248, 244, 226, 0.72);
color: #365650;
pointer-events: none;
display: grid;
place-items: center;
font-family: Georgia, serif;
font-size: 19px;
}
.corner::before {
content: "N";
position: absolute;
top: -13px;
font: 800 8px ui-sans-serif, system-ui, sans-serif;
}
.corner::after {
content: "";
position: absolute;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 17px solid #4e746c;
transform: translateY(-3px) rotate(18deg);
transform-origin: 50% 70%;
}
@media (max-width: 700px) {
.title {
top: 14px;
left: 14px;
padding: 13px 15px;
}
.subtitle {
max-width: 280px;
font-size: 11px;
}
.survey {
display: none;
}
.controls {
left: 14px;
bottom: 14px;
right: 14px;
justify-content: center;
}
.controls .desktop {
display: none;
}
.corner {
display: none;
}
}
</style>
</head>
<body>
<div class="panel title">
<p class="eyebrow">Floodplain study · Bengal delta</p>
<h1>Beside the<br>braided water</h1>
<p class="subtitle">
A voxel homestead perched a modest step above a distributary channel,
with silt banks, paddy plots, bamboo and river traffic.
</p>
</div>
<div class="panel survey">
Ganges–Brahmaputra delta
<span>Low relief · monsoon channel · raised homestead</span>
</div>
<div class="panel controls">
<span><b>Drag</b> orbit</span>
<span class="desktop"><b>Shift-drag</b> pan</span>
<span class="desktop"><b>Wheel</b> zoom</span>
<span class="divider desktop"></span>
<button id="reset" type="button">Reset view</button>
</div>
<div class="corner" aria-hidden="true"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, scene, lighting
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xd8e5df, 1);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive voxel delta landscape");
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e5df);
scene.fog = new THREE.Fog(0xd8e5df, 62, 105);
const camera = new THREE.OrthographicCamera(-20, 20, 12, -12, 0.1, 160);
const hemisphere = new THREE.HemisphereLight(0xe9f3e9, 0x7d7054, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0c7, 3.25);
sun.position.set(-16, 28, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -27;
sun.shadow.camera.right = 27;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc9cf, 0.72);
fill.position.set(18, 10, -16);
scene.add(fill);
const materialCache = new Map();
function material(color) {
if (color instanceof THREE.Material) return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Studio-like ground catches the diorama shadow.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
new THREE.MeshStandardMaterial({
color: 0xd5dfd7,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.28;
ground.receiveShadow = true;
scene.add(ground);
// ---------------------------------------------------------------------
// Delta layout and channel geometry
// ---------------------------------------------------------------------
const CELL = 0.5;
const NX = 60;
const NZ = 42;
const rivers = [
{
width: 1.45,
growth: 0.065,
points: [
[-1.2, -12],
[-1.8, -8],
[-1.0, -5],
[0.0, -2],
[0.5, 0],
[-0.3, 2],
[1.5, 5],
[3.0, 7],
[5.0, 9],
[7.0, 11]
]
},
{
width: 0.82,
growth: 0.018,
points: [
[7.0, 11],
[8.0, 8],
[8.0, 5],
[6.0, 3],
[4.0, 1],
[0.5, 0],
[0.0, -2],
[-0.2, -5]
]
},
{
width: 0.70,
growth: 0.012,
points: [
[3.0, 7],
[0.0, 6],
[-2.0, 4],
[-4.0, 2],
[-2.0, 0],
[0.0, -2]
]
},
{
width: 0.60,
growth: 0,
points: [
[-8.5, 10],
[-6.0, 8],
[-4.0, 6],
[-4.0, 2]
]
},
{
width: 0.52,
growth: 0,
points: [
[-5.0, 10.5],
[-3.0, 8.5],
[0.0, 6]
]
}
];
function hash2(i, j) {
const n = Math.sin(i * 127.1 + j * 311.7) * 43758.5453123;
return n - Math.floor(n);
}
function riverInfo(x, z) {
let bestGap = Infinity;
let best = null;
for (const river of rivers) {
const width =
river.width + Math.max(0, z - 3) * river.growth;
for (let k = 0; k < river.points.length - 1; k++) {
const a = river.points[k];
const b = river.points[k + 1];
const vx = b[0] - a[0];
const vz = b[1] - a[1];
const lenSq = vx * vx + vz * vz;
const t = Math.max(
0,
Math.min(1, ((x - a[0]) * vx + (z - a[1]) * vz) / lenSq)
);
const px = a[0] + t * vx;
const pz = a[1] + t * vz;
const dx = x - px;
const dz = z - pz;
const d = Math.hypot(dx, dz);
const gap = d - width;
if (gap < bestGap) {
bestGap = gap;
const length = Math.sqrt(lenSq);
best = {
d,
width,
gap,
tx: vx / length,
tz: vz / length
};
}
}
}
return best;
}
function cellPosition(i, j) {
return {
x: (i - (NX - 1) / 2) * CELL,
z: (j - (NZ - 1) / 2) * CELL
};
}
const waterGrid = new Uint8Array(NX * NZ);
const topGrid = new Float32Array(NX * NZ);
const riverGrid = new Array(NX * NZ);
const waterCells = [];
const terrainMatrices = [];
const terrainColors = [];
const streakMatrices = [];
const dummy = new THREE.Object3D();
const tempColor = new THREE.Color();
const dryField = [0xa7a260, 0xb8a85d, 0x92975a, 0xc0ad66];
const greenField = [0x71895a, 0x7f965d, 0x657e55, 0x8c9b65];
const silt = [0xafa078, 0xb9aa7d, 0xc0b185, 0xa99a73];
const bedColors = [0x686b4e, 0x727457, 0x5f674e];
for (let j = 0; j < NZ; j++) {
for (let i = 0; i < NX; i++) {
const index = j * NX + i;
const { x, z } = cellPosition(i, j);
const river = riverInfo(x, z);
riverGrid[index] = river;
const isWater = river.gap <= 0;
waterGrid[index] = isWater ? 1 : 0;
if (isWater) {
topGrid[index] = -0.22;
waterCells.push({ x, z, river, index });
dummy.position.set(x, (-0.80 - 0.22) / 2, z);
dummy.scale.set(1, 0.58, 1);
dummy.updateMatrix();
terrainMatrices.push(dummy.matrix.clone());
const bed = bedColors[Math.floor(hash2(i, j) * bedColors.length)];
tempColor.set(bed);
terrainColors.push(tempColor.clone());
continue;
}
const patch =
Math.sin(x * 0.57 + z * 0.31) +
Math.cos(z * 0.49 - x * 0.17);
let top = 0.28 + Math.round(patch * 1.18) * 0.06;
top += (hash2(i + 31, j - 17) - 0.5) * 0.035;
if (x > 3.0 && z > -6.6 && z < 0.8) {
top = 0.34;
}
topGrid[index] = top;
dummy.position.set(x, (-0.80 + top) / 2, z);
dummy.scale.set(1, top + 0.80, 1);
dummy.updateMatrix();
terrainMatrices.push(dummy.matrix.clone());
let palette;
if (river.gap < 0.55) {
palette = silt;
} else if (x > 8.2 && z < -5.2) {
palette = dryField;
} else if (x < -7.4 && z < -1.2) {
palette = greenField;
} else {
palette = greenField;
}
const c = palette[Math.floor(hash2(i + 3, j + 9) * palette.length)];
tempColor.set(c);
terrainColors.push(tempColor.clone());
}
}
// Exposed earth base makes the scene read as a lifted terrain model.
box(
scene,
NX * CELL + 0.18,
0.46,
NZ * CELL + 0.18,
0x6e634d,
0,
-1.03,
0
);
const terrain = new THREE.InstancedMesh(
new THREE.BoxGeometry(CELL * 0.985, 1, CELL * 0.985),
material(0xffffff),
terrainMatrices.length
);
terrain.castShadow = true;
terrain.receiveShadow = true;
terrain.instanceMatrix.setUsage(THREE.StaticDrawUsage);
terrainMatrices.forEach((matrix, index) => {
terrain.setMatrixAt(index, matrix);
terrain.setColorAt(index, terrainColors[index]);
});
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
scene.add(terrain);
// ---------------------------------------------------------------------
// Water tiles and small current marks
// ---------------------------------------------------------------------
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.28,
metalness: 0.05,
transparent: true,
opacity: 0.88
});
const water = new THREE.InstancedMesh(
new THREE.BoxGeometry(CELL * 0.99, 0.22, CELL * 0.99),
waterMaterial,
waterCells.length
);
water.receiveShadow = true;
waterCells.forEach((cell, index) => {
dummy.position.set(cell.x, -0.11, cell.z);
dummy.scale.set(1, 1, 1);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
water.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color(0x4d9296);
color.offsetHSL(
(hash2(cell.index, 7) - 0.5) * 0.025,
(hash2(cell.index, 13) - 0.5) * 0.08,
(hash2(cell.index, 21) - 0.5) * 0.08
);
water.setColorAt(index, color);
if (hash2(cell.index + 52, cell.index * 3) > 0.87) {
dummy.position.set(cell.x, 0.016, cell.z);
dummy.rotation.set(
0,
-Math.atan2(cell.river.tz, cell.river.tx),
0
);
dummy.scale.set(0.68, 1, 0.72);
dummy.updateMatrix();
streakMatrices.push(dummy.matrix.clone());
}
});
water.instanceMatrix.needsUpdate = true;
water.instanceColor.needsUpdate = true;
scene.add(water);
const streaks = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.42, 0.012, 0.045),
new THREE.MeshStandardMaterial({
color: 0xc3e3df,
roughness: 0.45,
transparent: true,
opacity: 0.58
}),
streakMatrices.length
);
streakMatrices.forEach((matrix, index) => streaks.setMatrixAt(index, matrix));
streaks.instanceMatrix.needsUpdate = true;
scene.add(streaks);
// ---------------------------------------------------------------------
// Bank reeds and crop details
// ---------------------------------------------------------------------
const reedMatrices = [];
const seedMatrices = [];
const cropMatrices = [];
const cropHeadMatrices = [];
function nearestCell(x, z) {
const i = Math.max(
0,
Math.min(NX - 1, Math.round(x / CELL + (NX - 1) / 2))
);
const j = Math.max(
0,
Math.min(NZ - 1, Math.round(z / CELL + (NZ - 1) / 2))
);
return { i, j, index: j * NX + i };
}
function groundTop(x, z) {
const { index } = nearestCell(x, z);
return waterGrid[index] ? 0 : topGrid[index];
}
for (let j = 0; j < NZ; j++) {
for (let i = 0; i < NX; i++) {
const index = j * NX + i;
if (waterGrid[index]) continue;
const { x, z } = cellPosition(i, j);
const river = riverGrid[index];
if (river.gap > 0 && river.gap < 0.42 && hash2(i + 4, j) > 0.69) {
const top = topGrid[index];
dummy.position.set(x + 0.06, top + 0.18, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
reedMatrices.push(dummy.matrix.clone());
dummy.position.set(x + 0.06, top + 0.39, z);
dummy.updateMatrix();
seedMatrices.push(dummy.matrix.clone());
}
const onHousePlatform =
x > 3.0 && x < 11.5 && z > -6.6 && z < 0.8;
const inGoldenPlot = x > 9.0 && z < -5.6 && !onHousePlatform;
const inGreenPlot = x < -8.1 && z < -1.5 && !onHousePlatform;
if (
(inGoldenPlot || inGreenPlot) &&
hash2(i + 91, j + 37) > 0.48
) {
const top = topGrid[index];
const offset = (hash2(i, j) - 0.5) * 0.12;
dummy.position.set(x + offset, top + 0.11, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
cropMatrices.push(dummy.matrix.clone());
dummy.position.set(x + offset, top + 0.25, z);
dummy.updateMatrix();
cropHeadMatrices.push(dummy.matrix.clone());
}
}
}
const reeds = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.045, 0.36, 0.045),
material(0x6f7e49),
reedMatrices.length
);
reedMatrices.forEach((m, i) => reeds.setMatrixAt(i, m));
reeds.castShadow = true;
scene.add(reeds);
const reedSeeds = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.075, 0.12, 0.075),
material(0x88744b),
seedMatrices.length
);
seedMatrices.forEach((m, i) => reedSeeds.setMatrixAt(i, m));
scene.add(reedSeeds);
const crops = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.055, 0.22, 0.055),
material(0x708348),
cropMatrices.length
);
cropMatrices.forEach((m, i) => crops.setMatrixAt(i, m));
crops.castShadow = true;
scene.add(crops);
const cropHeads = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.085, 0.10, 0.075),
material(0xc3ad63),
cropHeadMatrices.length
);
cropHeadMatrices.forEach((m, i) => cropHeads.setMatrixAt(i, m));
scene.add(cropHeads);
// ---------------------------------------------------------------------
// Raised homestead platform
// ---------------------------------------------------------------------
const platformX = 7.1;
const platformZ = -3.0;
box(scene, 7.55, 0.36, 6.40, 0x927d59, platformX, 0.48, platformZ);
box(scene, 7.10, 0.34, 6.00, 0xa08b62, platformX, 0.83, platformZ);
box(scene, 6.80, 0.12, 5.75, 0x82925c, platformX, 1.06, platformZ);
// Pixel-like edge blocks.
for (let n = 0; n < 12; n++) {
const z = platformZ - 2.75 + n * 0.5;
box(scene, 0.14, 0.12, 0.47, 0x74824f, 3.76, 1.04, z);
}
// ---------------------------------------------------------------------
// Homestead
// ---------------------------------------------------------------------
const house = new THREE.Group();
house.position.set(7.1, 1.12, -3.25);
scene.add(house);
const wallColor = 0xd9c49a;
const timber = 0x75533a;
const roofColor = 0x9d4f37;
box(house, 3.35, 0.16, 2.30, 0x8b7759, 0, 0.08, 0);
box(house, 3.10, 1.46, 2.10, wallColor, 0, 0.88, 0);
// Corner posts and lintel.
for (const x of [-1.48, 1.48]) {
for (const z of [-0.98, 0.98]) {
box(house, 0.17, 1.63, 0.17, timber, x, 0.86, z);
}
}
box(house, 3.28, 0.16, 0.18, timber, 0, 1.52, 1.0);
box(house, 0.18, 0.16, 2.18, timber, -1.5, 1.52, 0);
box(house, 0.18, 0.16, 2.18, timber, 1.5, 1.52, 0);
// Door and front windows.
box(house, 0.58, 1.10, 0.055, 0x574333, 0, 0.72, 1.066);
box(house, 0.52, 0.48, 0.055, 0x354b46, -1.02, 0.94, 1.069);
box(house, 0.52, 0.48, 0.055, 0x354b46, 1.02, 0.94, 1.069);
// East-facing window is visible from the opening camera.
box(house, 0.055, 0.50, 0.58, 0x354b46, 1.565, 0.94, 0.12);
// Stepped voxel roof.
for (let layer = 0; layer < 7; layer++) {
const width = 4.05 - layer * 0.46;
box(
house,
width,
0.22,
2.66,
layer % 2 ? 0xa9583d : roofColor,
0,
1.64 + layer * 0.22,
0
);
}
box(house, 0.48, 0.19, 2.78, 0x7e3f31, 0, 3.10, 0);
box(house, 0.26, 0.42, 0.28, 0x775648, 0.76, 3.02, -0.48);
// Veranda and posts.
box(house, 3.78, 0.12, 1.08, 0x8e7652, 0, 0.16, 1.48);
for (const x of [-1.55, 1.55]) {
box(house, 0.12, 1.38, 0.12, timber, x, 0.86, 2.0);
}
box(house, 3.70, 0.13, 0.13, timber, 0, 1.48, 2.0);
// Veranda steps.
box(house, 1.25, 0.14, 0.38, 0x9a7e55, 0, 0.07, 2.20);
box(house, 1.55, 0.14, 0.38, 0x9a7e55, 0, -0.02, 2.56);
// Courtyard objects.
box(house, 0.46, 0.34, 0.46, 0x9e7847, 1.18, 0.29, 1.75);
box(house, 0.38, 0.28, 0.38, 0xb59452, -1.22, 0.26, 1.72);
box(house, 0.34, 0.06, 0.34, 0x6c8b70, 1.18, 0.49, 1.75);
// ---------------------------------------------------------------------
// Landing steps and timber jetty reaching toward the channel
// ---------------------------------------------------------------------
box(scene, 0.60, 0.48, 1.05, 0x9b8058, 3.24, 0.86, -2.42);
box(scene, 0.60, 0.30, 1.05, 0x9b8058, 2.78, 0.64, -2.42);
box(scene, 0.60, 0.16, 1.05, 0x9b8058, 2.34, 0.49, -2.42);
box(scene, 1.65, 0.14, 0.72, 0x76573b, 1.58, 0.43, -2.42);
for (const x of [1.05, 2.05]) {
for (const z of [-2.70, -2.13]) {
box(scene, 0.11, 0.68, 0.11, 0x5f4933, x, 0.20, z);
}
}
// ---------------------------------------------------------------------
// Trees and bamboo
// ---------------------------------------------------------------------
function voxelTree(x, z, scale = 1) {
const river = riverInfo(x, z);
if (river.gap < 0.45) return;
const base = groundTop(x, z);
const group = new THREE.Group();
group.position.set(x, base, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, 0.25, 1.25, 0.25, 0x705039, 0, 0.63, 0);
box(group, 0.92, 0.72, 0.88, 0x526f47, 0, 1.40, 0);
box(group, 0.70, 0.65, 0.66, 0x66804e, -0.43, 1.54, 0.08);
box(group, 0.66, 0.62, 0.65, 0x5b7649, 0.43, 1.52, -0.08);
box(group, 0.61, 0.58, 0.60, 0x758b51, 0.02, 1.88, 0.02);
}
const treePositions = [
[-11.4, -7.6, 1.05],
[-12.2, -1.5, 0.90],
[-11.1, 5.7, 1.15],
[-7.0, -8.4, 0.90],
[-6.2, -6.2, 1.00],
[-8.4, 8.1, 0.82],
[11.3, -7.6, 1.02],
[12.0, -3.7, 0.85],
[12.1, 3.8, 1.10],
[10.2, 7.4, 0.88],
[3.9, -8.5, 0.72],
[-1.0, 9.1, 0.74],
[0.8, -8.8, 0.72]
];
treePositions.forEach(([x, z, s]) => voxelTree(x, z, s));
function bambooCluster(x, z, count = 8) {
const base = groundTop(x, z);
for (let n = 0; n < count; n++) {
const angle = n * 2.399;
const radius = Math.sqrt(n / count) * 0.65;
const bx = x + Math.cos(angle) * radius;
const bz = z + Math.sin(angle) * radius;
const height = 1.65 + (n % 3) * 0.28;
box(
scene,
0.10,
height,
0.10,
n % 2 ? 0x7b8f50 : 0x92a15b,
bx,
base + height / 2,
bz
);
box(
scene,
0.42,
0.08,
0.18,
0x5e7749,
bx + 0.15,
base + height * 0.73,
bz
);
}
}
bambooCluster(10.0, -5.6, 9);
bambooCluster(9.9, -0.8, 7);
bambooCluster(-5.0, -8.9, 7);
// ---------------------------------------------------------------------
// People and boats
// ---------------------------------------------------------------------
function person(parent, x, y, z, shirt, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
box(group, 0.105, 0.36, 0.13, 0x40534e, -0.085, 0.18, 0);
box(group, 0.105, 0.36, 0.13, 0x40534e, 0.085, 0.18, 0);
box(group, 0.35, 0.43, 0.23, shirt, 0, 0.58, 0);
box(group, 0.27, 0.27, 0.26, 0xb77e56, 0, 0.94, 0);
box(group, 0.29, 0.08, 0.28, 0x3b3730, 0, 1.09, 0);
box(group, 0.09, 0.35, 0.10, shirt, -0.235, 0.57, 0);
box(group, 0.09, 0.35, 0.10, shirt, 0.235, 0.57, 0);
return group;
}
person(scene, 9.25, 1.12, -1.35, 0xb85e43, 0.92);
person(scene, 4.2, groundTop(4.2, -7.3), -7.3, 0x527d83, 0.82);
const boats = [];
function makeBoat(x, z, scale = 1) {
const river = riverInfo(x, z);
const group = new THREE.Group();
group.position.set(x, 0.04, z);
group.rotation.y = -Math.atan2(river.tz, river.tx);
group.scale.setScalar(scale);
scene.add(group);
box(group, 1.05, 0.18, 0.43, 0x5f432e, 0, 0.06, 0);
box(group, 0.34, 0.21, 0.48, 0x694a31, 0.66, 0.08, 0);
box(group, 0.34, 0.21, 0.48, 0x694a31, -0.66, 0.08, 0);
box(group, 0.73, 0.055, 0.28, 0xa17d4e, 0, 0.18, 0);
person(group, 0.03, 0.18, 0, 0xc27a43, 0.72);
boats.push(group);
return group;
}
makeBoat(-1.0, -6.55, 1.0);
makeBoat(1.15, 4.45, 0.86);
// A few floating water hyacinth clusters.
const hyacinthMatrices = [];
for (const cell of waterCells) {
if (hash2(cell.index + 404, cell.index) > 0.975) {
dummy.position.set(cell.x, 0.025, cell.z);
dummy.rotation.set(0, hash2(cell.index, 2) * Math.PI, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
hyacinthMatrices.push(dummy.matrix.clone());
}
}
const hyacinths = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.22, 0.055, 0.16),
material(0x668b4f),
hyacinthMatrices.length
);
hyacinthMatrices.forEach((m, i) => hyacinths.setMatrixAt(i, m));
hyacinths.castShadow = true;
scene.add(hyacinths);
// ---------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, touch pinch, keyboard
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0.5, 0.35, 0);
const spherical = {
radius: 43,
theta: 0.69,
phi: 0.94
};
const homeView = {
radius: 43,
theta: 0.69,
phi: 0.94,
target: target.clone()
};
function updateCamera() {
const sinPhi = Math.sin(spherical.phi);
camera.position.set(
target.x + spherical.radius * sinPhi * Math.sin(spherical.theta),
target.y + spherical.radius * Math.cos(spherical.phi),
target.z + spherical.radius * sinPhi * Math.cos(spherical.theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetView() {
spherical.radius = homeView.radius;
spherical.theta = homeView.theta;
spherical.phi = homeView.phi;
target.copy(homeView.target);
camera.zoom = 1;
camera.updateProjectionMatrix();
updateCamera();
}
function clampOrbit() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.40, 1.38);
spherical.theta = THREE.MathUtils.clamp(spherical.theta, -1.55, 1.55);
}
function panCamera(dx, dy) {
const rect = renderer.domElement.getBoundingClientRect();
const worldPerPixel = (camera.top - camera.bottom) /
camera.zoom /
rect.height;
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3()
.subVectors(target, camera.position);
forward.y = 0;
forward.normalize();
target.addScaledVector(right, -dx * worldPerPixel);
target.addScaledVector(forward, dy * worldPerPixel);
target.x = THREE.MathUtils.clamp(target.x, -9, 9);
target.z = THREE.MathUtils.clamp(target.z, -8, 8);
target.y = 0.35;
updateCamera();
}
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
shift: event.shiftKey
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size === 1) {
if (pointer.shift || event.shiftKey) {
panCamera(dx, dy);
} else {
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.0055;
clampOrbit();
updateCamera();
}
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * (distance / pinchDistance),
0.62,
2.5
);
camera.updateProjectionMatrix();
}
pinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.5
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetView();
} else if (key === "arrowleft") {
spherical.theta += 0.08;
updateCamera();
} else if (key === "arrowright") {
spherical.theta -= 0.08;
updateCamera();
} else if (key === "arrowup") {
spherical.phi -= 0.06;
clampOrbit();
updateCamera();
} else if (key === "arrowdown") {
spherical.phi += 0.06;
clampOrbit();
updateCamera();
} else if (key === "+" || key === "=") {
camera.zoom = Math.min(2.5, camera.zoom * 1.08);
camera.updateProjectionMatrix();
} else if (key === "-") {
camera.zoom = Math.max(0.62, camera.zoom / 1.08);
camera.updateProjectionMatrix();
}
});
// ---------------------------------------------------------------------
// Responsive orthographic framing
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(10.6, 17.2 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const t = clock.getElapsedTime();
const wave = Math.sin(t * 0.75) * 0.009;
water.position.y = wave;
streaks.position.y = wave * 1.2;
hyacinths.position.y = wave * 0.8;
boats.forEach((boat, index) => {
boat.position.y = 0.035 + Math.sin(t * 1.05 + index * 1.7) * 0.025;
boat.rotation.z = Math.sin(t * 0.9 + index) * 0.018;
boat.rotation.x = Math.cos(t * 0.72 + index) * 0.012;
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```