Prompt specification
Build or customize the Three.js 3D scene "Xochimilco canal and chinampa fragment" 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: Xochimilco canal and chinampa fragment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/xochimilco-canal-and-chinampa-fragment-x2755
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a bounded voxel fragment of Xochimilco's canal landscape. Use reference-informed proportions for connected waterways and raised growing beds. Include two small landings, a few trees, paths along the bed edges, and one narrow boat so both cultivation and movement through the water are visible. Make the canal junction readable from above and keep every landing physically connected to a bank or path. Use stepped soil edges, planted rows, and quiet blue-green water. The camera should inspect the same fragment from ground level and overhead. Avoid turning the beds into isolated floating islands disconnected from the surrounding landscape.
Working Three.js Starter (xochimilco-canal-and-chinampa-fragment-x2755):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Xochimilco Canal Fragment</title>
<style>
:root {
color-scheme: light;
--ink: #173b3a;
--muted: #52706b;
--panel: rgba(244, 249, 246, 0.88);
--line: rgba(23, 59, 58, 0.16);
--accent: #2d746b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe8e3;
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: 20px;
left: 20px;
width: min(330px, calc(100vw - 40px));
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 14px 35px rgba(28, 69, 65, 0.11);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 6px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 31px;
font-weight: 500;
line-height: 1;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.view-panel {
position: fixed;
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 12px 30px rgba(28, 69, 65, 0.12);
backdrop-filter: blur(12px);
}
.view-panel button {
appearance: none;
border: 0;
border-radius: 9px;
padding: 10px 13px;
background: transparent;
color: var(--muted);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
.view-panel button:hover {
background: rgba(45, 116, 107, 0.08);
color: var(--ink);
}
.view-panel button:active {
transform: translateY(1px);
}
.view-panel button.active {
background: var(--accent);
color: #f7fffc;
box-shadow: 0 5px 12px rgba(45, 116, 107, 0.2);
}
.hint {
position: fixed;
left: 20px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(244, 249, 246, 0.72);
color: var(--muted);
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(8px);
}
.loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #dbe8e3;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 400ms ease;
z-index: 10;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
h1 {
font-size: 27px;
}
.subtitle {
max-width: 280px;
}
.view-panel {
right: 12px;
bottom: 12px;
}
.hint {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 235px);
}
}
</style>
</head>
<body>
<div class="loading" id="loading">Building canal fragment…</div>
<section class="title-card">
<p class="eyebrow">Canal landscape · fragment 07</p>
<h1>Xochimilco</h1>
<p class="subtitle">
A connected chinampa-like fragment with a branching canal, planted beds,
stepped banks, two working landings, and a narrow canoe.
</p>
</section>
<div class="hint">Drag to orbit · Wheel to zoom</div>
<nav class="view-panel" aria-label="Camera views">
<button type="button" data-view="ground">Ground level</button>
<button type="button" data-view="overhead" class="active">Overhead</button>
</nav>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe8e3);
scene.fog = new THREE.Fog(0xdbe8e3, 20, 34);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.08,
100
);
// ---------------------------------------------------------------------
// Scene lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xeaf6f0, 0x80684e, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d3, 3.0);
sun.position.set(-7, 12, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc7c0, 0.65);
fill.position.set(8, 5, -9);
scene.add(fill);
// ---------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------
const NX = 30;
const NZ = 24;
const CELL = 0.5;
const HALF_X = NX * CELL * 0.5;
const HALF_Z = NZ * CELL * 0.5;
const BASE_TOP = -0.28;
const clamp = THREE.MathUtils.clamp;
function closestOnSegment(px, pz, a, b) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const lengthSquared = dx * dx + dz * dz;
const t = lengthSquared > 0
? clamp(((px - a.x) * dx + (pz - a.z) * dz) / lengthSquared, 0, 1)
: 0;
return {
t,
x: a.x + dx * t,
z: a.z + dz * t,
dx: dx / Math.sqrt(lengthSquared),
dz: dz / Math.sqrt(lengthSquared)
};
}
// Three connected reaches forming a legible Y-junction.
const channels = [
{
a: { x: -1.25, z: 6.0 },
b: { x: -1.25, z: 1.15 },
width: 1.65
},
{
a: { x: -1.25, z: 1.15 },
b: { x: -6.0, z: -6.0 },
width: 1.45
},
{
a: { x: -1.25, z: 1.15 },
b: { x: 6.0, z: -6.0 },
width: 1.45
}
];
function channelDistance(x, z) {
let minimum = Infinity;
let nearest = null;
for (const channel of channels) {
const q = closestOnSegment(x, z, channel.a, channel.b);
const distance = Math.hypot(x - q.x, z - q.z) - channel.width * 0.5;
if (distance < minimum) {
minimum = distance;
nearest = { ...q, width: channel.width };
}
}
return { distance: minimum, nearest };
}
function isWater(x, z) {
return channelDistance(x, z).distance <= 0;
}
function isLand(x, z) {
return !isWater(x, z);
}
function terrainTopAt(x, z) {
if (!isLand(x, z)) return null;
const bankDistance = channelDistance(x, z).distance;
if (bankDistance < 0.46) return 0.10;
if (bankDistance < 1.06) return 0.27;
return 0.44;
}
function makeQuadGeometry(cells, y) {
const positions = [];
for (const cell of cells) {
const x0 = cell.x - CELL * 0.5;
const x1 = cell.x + CELL * 0.5;
const z0 = cell.z - CELL * 0.5;
const z1 = cell.z + CELL * 0.5;
positions.push(
x0, y, z0,
x0, y, z1,
x1, y, z1,
x0, y, z0,
x1, y, z1,
x1, y, z0
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return geometry;
}
// ---------------------------------------------------------------------
// Bounded soil base
// ---------------------------------------------------------------------
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xd4e1dc,
roughness: 1
})
);
backdrop.rotation.x = -Math.PI / 2;
backdrop.position.y = -0.94;
backdrop.receiveShadow = true;
scene.add(backdrop);
const lowerBase = new THREE.Mesh(
new THREE.BoxGeometry(HALF_X * 2 + 0.25, 0.18, HALF_Z * 2 + 0.25),
new THREE.MeshStandardMaterial({
color: 0x4d3e31,
roughness: 1
})
);
lowerBase.position.y = -0.80;
lowerBase.castShadow = true;
lowerBase.receiveShadow = true;
scene.add(lowerBase);
const upperBase = new THREE.Mesh(
new THREE.BoxGeometry(HALF_X * 2, 0.42, HALF_Z * 2),
new THREE.MeshStandardMaterial({
color: 0x67513b,
roughness: 1
})
);
upperBase.position.y = -0.49;
upperBase.castShadow = true;
upperBase.receiveShadow = true;
scene.add(upperBase);
// ---------------------------------------------------------------------
// Voxel terrain: stepped banks and solid, connected land
// ---------------------------------------------------------------------
const landCells = [];
const waterCells = [];
for (let iz = 0; iz < NZ; iz++) {
for (let ix = 0; ix < NX; ix++) {
const x = -HALF_X + (ix + 0.5) * CELL;
const z = -HALF_Z + (iz + 0.5) * CELL;
const cell = { x, z, ix, iz };
if (isWater(x, z)) waterCells.push(cell);
else landCells.push(cell);
}
}
const landGeometry = new THREE.BoxGeometry(1, 1, 1);
const landMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
});
const landMesh = new THREE.InstancedMesh(
landGeometry,
landMaterial,
landCells.length
);
landMesh.castShadow = true;
landMesh.receiveShadow = true;
const dummy = new THREE.Object3D();
const soilColor = new THREE.Color();
landCells.forEach((cell, index) => {
const top = terrainTopAt(cell.x, cell.z);
dummy.position.set(cell.x, (BASE_TOP + top) * 0.5, cell.z);
dummy.scale.set(CELL * 0.992, top - BASE_TOP, CELL * 0.992);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
landMesh.setMatrixAt(index, dummy.matrix);
if (top < 0.18) soilColor.set(0x776148);
else if (top < 0.36) soilColor.set(0x886b4d);
else soilColor.set(0x987957);
soilColor.multiplyScalar(0.95 + Math.random() * 0.10);
landMesh.setColorAt(index, soilColor);
});
landMesh.instanceMatrix.needsUpdate = true;
if (landMesh.instanceColor) landMesh.instanceColor.needsUpdate = true;
scene.add(landMesh);
// Silt and water occupy exactly the carved canal cells.
const silt = new THREE.Mesh(
makeQuadGeometry(waterCells, -0.19),
new THREE.MeshStandardMaterial({
color: 0x315b52,
roughness: 1,
side: THREE.DoubleSide
})
);
silt.receiveShadow = true;
scene.add(silt);
const water = new THREE.Mesh(
makeQuadGeometry(waterCells, -0.065),
new THREE.MeshStandardMaterial({
color: 0x4c9690,
roughness: 0.32,
metalness: 0.08,
transparent: true,
opacity: 0.88,
side: THREE.DoubleSide,
depthWrite: false
})
);
water.receiveShadow = true;
scene.add(water);
// Quiet current marks on the water surface.
const ripplePositions = [];
for (const cell of waterCells) {
if (Math.random() > 0.27) continue;
const { nearest } = channelDistance(cell.x, cell.z);
const length = 0.11 + Math.random() * 0.12;
const side = (Math.random() - 0.5) * 0.13;
ripplePositions.push(
cell.x - nearest.dx * length - nearest.dz * side,
-0.048,
cell.z - nearest.dz * length + nearest.dx * side,
cell.x + nearest.dx * length - nearest.dz * side,
-0.048,
cell.z + nearest.dz * length + nearest.dx * side
);
}
const rippleGeometry = new THREE.BufferGeometry();
rippleGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(ripplePositions, 3)
);
const ripples = new THREE.LineSegments(
rippleGeometry,
new THREE.LineBasicMaterial({
color: 0xb9ded3,
transparent: true,
opacity: 0.46,
depthWrite: false
})
);
scene.add(ripples);
// ---------------------------------------------------------------------
// Paths: continuous raised paving along bank edges
// ---------------------------------------------------------------------
const paverTransforms = [];
const supportTransforms = [];
const paverAngle = new Map();
const ne = channels[2];
const nw = channels[1];
const neDirection = {
x: ne.b.x - ne.a.x,
z: ne.b.z - ne.a.z
};
const neLength = Math.hypot(neDirection.x, neDirection.z);
neDirection.x /= neLength;
neDirection.z /= neLength;
const nwDirection = {
x: nw.b.x - nw.a.x,
z: nw.b.z - nw.a.z
};
const nwLength = Math.hypot(nwDirection.x, nwDirection.z);
nwDirection.x /= nwLength;
nwDirection.z /= nwLength;
const neCentralNormal = {
x: neDirection.z,
z: -neDirection.x
};
const nwCentralNormal = {
x: -nwDirection.z,
z: nwDirection.x
};
function branchPoint(channel, t, normal, offset) {
return {
x: channel.a.x + (channel.b.x - channel.a.x) * t +
normal.x * offset,
z: channel.a.z + (channel.b.z - channel.a.z) * t +
normal.z * offset
};
}
const pathSegments = [
{
a: { x: -2.55, z: 5.72 },
b: { x: -2.55, z: 1.72 }
},
{
a: { x: 0.05, z: 5.72 },
b: { x: 0.05, z: 2.02 }
},
{
a: branchPoint(ne, 0.12, neCentralNormal, 1.20),
b: branchPoint(ne, 0.82, neCentralNormal, 1.20)
},
{
a: branchPoint(nw, 0.12, nwCentralNormal, 1.20),
b: branchPoint(nw, 0.92, nwCentralNormal, 1.20)
}
];
for (const segment of pathSegments) {
const dx = segment.b.x - segment.a.x;
const dz = segment.b.z - segment.a.z;
const length = Math.hypot(dx, dz);
const count = Math.ceil(length / 0.22);
const angle = Math.atan2(-dz, dx);
for (let i = 0; i <= count; i++) {
const t = i / count;
const x = segment.a.x + dx * t;
const z = segment.a.z + dz * t;
const ground = terrainTopAt(x, z);
if (ground === null) continue;
paverTransforms.push({ x, z, angle });
paverAngle.set(`${x.toFixed(3)},${z.toFixed(3)}`, angle);
const supportHeight = Math.max(0.012, 0.287 - ground);
supportTransforms.push({
x,
z,
y: ground + supportHeight * 0.5,
height: supportHeight,
angle
});
}
}
const paverMaterial = new THREE.MeshStandardMaterial({
color: 0xc3aa7e,
roughness: 0.95
});
const pavers = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.34, 0.045, 0.34),
paverMaterial,
paverTransforms.length
);
paverTransforms.forEach((p, index) => {
dummy.position.set(p.x, 0.31, p.z);
dummy.rotation.set(0, p.angle, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
pavers.setMatrixAt(index, dummy.matrix);
});
pavers.instanceMatrix.needsUpdate = true;
pavers.castShadow = true;
pavers.receiveShadow = true;
scene.add(pavers);
const pathSupports = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.13, 1, 0.13),
new THREE.MeshStandardMaterial({
color: 0x796044,
roughness: 1
}),
supportTransforms.length
);
supportTransforms.forEach((p, index) => {
dummy.position.set(p.x, p.y, p.z);
dummy.rotation.set(0, p.angle, 0);
dummy.scale.set(1, p.height, 1);
dummy.updateMatrix();
pathSupports.setMatrixAt(index, dummy.matrix);
});
pathSupports.instanceMatrix.needsUpdate = true;
pathSupports.castShadow = true;
pathSupports.receiveShadow = true;
scene.add(pathSupports);
// ---------------------------------------------------------------------
// Wooden bridge connecting the central cultivated bed to the west bank
// ---------------------------------------------------------------------
const wood = new THREE.MeshStandardMaterial({
color: 0x8c633d,
roughness: 0.88
});
const woodLight = new THREE.MeshStandardMaterial({
color: 0xb18455,
roughness: 0.9
});
const darkWood = new THREE.MeshStandardMaterial({
color: 0x5e422c,
roughness: 0.95
});
function addBox(group, size, position, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
const bridgeT = 0.52;
const bridgeCenter = {
x: nw.a.x + (nw.b.x - nw.a.x) * bridgeT,
z: nw.a.z + (nw.b.z - nw.a.z) * bridgeT
};
const bridge = new THREE.Group();
bridge.position.set(bridgeCenter.x, 0, bridgeCenter.z);
bridge.rotation.y = Math.atan2(-nwDirection.z, nwDirection.x);
for (let i = 0; i < 13; i++) {
addBox(
bridge,
{ x: 1.16, y: 0.08, z: 0.215 },
new THREE.Vector3(0, 0.34, -1.30 + i * 0.216),
i % 2 ? wood : woodLight
);
}
for (const z of [-0.88, 0.88]) {
for (const x of [-0.42, 0.42]) {
addBox(
bridge,
{ x: 0.09, y: 0.52, z: 0.09 },
new THREE.Vector3(x, 0.07, z),
darkWood
);
}
}
addBox(
bridge,
{ x: 0.12, y: 0.12, z: 2.86 },
new THREE.Vector3(0, 0.27, 0),
darkWood
);
scene.add(bridge);
// ---------------------------------------------------------------------
// Two small landings, each touching a bank and its continuous path
// ---------------------------------------------------------------------
const landingOne = new THREE.Group();
landingOne.position.set(-2.25, 0, 3.52);
for (let i = 0; i < 8; i++) {
addBox(
landingOne,
{ x: 0.96, y: 0.08, z: 0.145 },
new THREE.Vector3(0, 0.285, -0.56 + i * 0.16),
i % 2 ? wood : woodLight
);
}
for (const x of [-0.35, 0.35]) {
addBox(
landingOne,
{ x: 0.10, y: 0.11, z: 1.28 },
new THREE.Vector3(x, 0.20, 0),
darkWood
);
}
for (const x of [-0.35, 0.35]) {
for (const z of [-0.48, 0.48]) {
addBox(
landingOne,
{ x: 0.09, y: 0.39, z: 0.09 },
new THREE.Vector3(x, 0.035, z),
darkWood
);
}
}
scene.add(landingOne);
const landingTwoT = 0.55;
const landingTwoCenter = branchPoint(
ne,
landingTwoT,
neCentralNormal,
0.72
);
const landingTwo = new THREE.Group();
landingTwo.position.set(landingTwoCenter.x, 0, landingTwoCenter.z);
landingTwo.rotation.y = Math.atan2(-neDirection.z, neDirection.x);
for (let i = 0; i < 6; i++) {
addBox(
landingTwo,
{ x: 1.20, y: 0.08, z: 0.165 },
new THREE.Vector3(0, 0.285, -0.45 + i * 0.18),
i % 2 ? woodLight : wood
);
}
for (const x of [-0.43, 0.43]) {
addBox(
landingTwo,
{ x: 0.10, y: 0.11, z: 1.08 },
new THREE.Vector3(x, 0.20, 0),
darkWood
);
}
for (const x of [-0.43, 0.43]) {
for (const z of [-0.40, 0.40]) {
addBox(
landingTwo,
{ x: 0.09, y: 0.39, z: 0.09 },
new THREE.Vector3(x, 0.035, z),
darkWood
);
}
}
scene.add(landingTwo);
// ---------------------------------------------------------------------
// Raised planted beds: low voxel soil tiles with visible crop rows
// ---------------------------------------------------------------------
const soilTiles = [];
const cropStems = [];
const cropLeaves = [];
const flowers = [];
function addRaisedBed(cx, cz, width, depth) {
const spacing = 0.40;
const columns = Math.floor(width / spacing);
const rows = Math.floor(depth / spacing);
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = cx + (column - (columns - 1) * 0.5) * spacing;
const z = cz + (row - (rows - 1) * 0.5) * spacing;
const corners = [
[x - 0.18, z - 0.18],
[x + 0.18, z - 0.18],
[x - 0.18, z + 0.18],
[x + 0.18, z + 0.18]
];
if (corners.some(([px, pz]) => !isLand(px, pz))) continue;
const top = terrainTopAt(x, z);
soilTiles.push({ x, y: top + 0.055, z });
// Alternate rows leave narrow furrows between the crop lines.
if (row % 2 === 0) {
cropStems.push({ x, y: top + 0.23, z });
cropLeaves.push({
x,
y: top + 0.34,
z,
color: (row + column) % 4 === 0 ? 0x4f8b42 : 0x3f733c
});
if ((row * columns + column) % 8 === 3) {
flowers.push({ x, y: top + 0.47, z });
}
}
}
}
}
addRaisedBed(-4.55, 3.74, 3.40, 1.80);
addRaisedBed(3.55, 3.76, 4.40, 2.00);
addRaisedBed(-0.90, -2.45, 1.80, 2.30);
addRaisedBed(-5.75, -3.70, 1.50, 1.80);
addRaisedBed(4.55, -3.42, 2.40, 1.80);
function createInstances(geometry, material, entries, useColor = false) {
if (!entries.length) return null;
const mesh = new THREE.InstancedMesh(geometry, material, entries.length);
const color = new THREE.Color();
entries.forEach((entry, index) => {
dummy.position.set(entry.x, entry.y, entry.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (useColor && entry.color !== undefined) {
color.setHex(entry.color);
mesh.setColorAt(index, color);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
createInstances(
new THREE.BoxGeometry(0.39, 0.11, 0.39),
new THREE.MeshStandardMaterial({
color: 0x72543b,
roughness: 1
}),
soilTiles
);
createInstances(
new THREE.BoxGeometry(0.035, 0.25, 0.035),
new THREE.MeshStandardMaterial({
color: 0x49683a,
roughness: 1
}),
cropStems
);
createInstances(
new THREE.BoxGeometry(0.18, 0.16, 0.18),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9
}),
cropLeaves,
true
);
createInstances(
new THREE.BoxGeometry(0.075, 0.075, 0.075),
new THREE.MeshStandardMaterial({
color: 0xd59b45,
roughness: 0.85
}),
flowers
);
// ---------------------------------------------------------------------
// A few rooted, blocky trees
// ---------------------------------------------------------------------
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x705039,
roughness: 1
});
const leafMaterials = [
new THREE.MeshStandardMaterial({ color: 0x52734a, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x66865a, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x3f6745, roughness: 1 })
];
function addTree(x, z, scale = 1) {
if (!isLand(x, z)) return;
const ground = terrainTopAt(x, z);
const group = new THREE.Group();
group.position.set(x, ground, z);
group.scale.setScalar(scale);
addBox(
group,
{ x: 0.18, y: 1.10, z: 0.18 },
new THREE.Vector3(0, 0.55, 0),
trunkMaterial
);
const blocks = [
[-0.22, 1.05, 0.02, 0.72, 0.62, 0.68],
[0.22, 1.12, 0.04, 0.76, 0.70, 0.72],
[0.00, 1.48, -0.08, 0.82, 0.66, 0.78],
[-0.24, 1.42, -0.20, 0.60, 0.54, 0.60],
[0.24, 1.39, 0.18, 0.62, 0.55, 0.58]
];
blocks.forEach((block, index) => {
addBox(
group,
{ x: block[3], y: block[4], z: block[5] },
new THREE.Vector3(block[0], block[1], block[2]),
leafMaterials[index % leafMaterials.length]
);
});
scene.add(group);
}
addTree(-6.25, 1.65, 0.94);
addTree(-6.18, -4.78, 1.04);
addTree(5.78, 0.72, 0.92);
addTree(5.88, -4.72, 1.08);
addTree(0.62, 5.10, 0.82);
addTree(-0.25, -5.22, 0.90);
// ---------------------------------------------------------------------
// Reeds at a few canal edges
// ---------------------------------------------------------------------
const reeds = [];
const reedLocations = [
[-2.17, 4.80], [-2.17, 4.42], [-2.18, 2.75],
[-2.17, 2.38], [-0.33, 4.94], [-0.34, 4.56],
[-0.34, 2.72], [-0.34, 2.32]
];
for (const [x, z] of reedLocations) {
const ground = terrainTopAt(x, z);
if (ground === null) continue;
for (let i = 0; i < 3; i++) {
reeds.push({
x: x + (Math.random() - 0.5) * 0.12,
y: ground + 0.16 + Math.random() * 0.05,
z: z + (Math.random() - 0.5) * 0.12
});
}
}
createInstances(
new THREE.BoxGeometry(0.025, 0.31, 0.025),
new THREE.MeshStandardMaterial({
color: 0x5f8c54,
roughness: 1
}),
reeds
);
// ---------------------------------------------------------------------
// One narrow canoe, slowly moving through the southern canal
// ---------------------------------------------------------------------
const boat = new THREE.Group();
const boatShape = new THREE.Shape();
boatShape.moveTo(0, 0.92);
boatShape.quadraticCurveTo(0.24, 0.46, 0.205, -0.05);
boatShape.quadraticCurveTo(0.16, -0.60, 0, -0.91);
boatShape.quadraticCurveTo(-0.16, -0.60, -0.205, -0.05);
boatShape.quadraticCurveTo(-0.24, 0.46, 0, 0.92);
const hullGeometry = new THREE.ExtrudeGeometry(boatShape, {
depth: 0.15,
bevelEnabled: true,
bevelThickness: 0.018,
bevelSize: 0.025,
bevelSegments: 1,
steps: 1
});
hullGeometry.rotateX(Math.PI / 2);
hullGeometry.translate(0, 0.075, 0);
const hull = new THREE.Mesh(
hullGeometry,
new THREE.MeshStandardMaterial({
color: 0x815333,
roughness: 0.72
})
);
hull.castShadow = true;
hull.receiveShadow = true;
boat.add(hull);
addBox(
boat,
{ x: 0.28, y: 0.055, z: 0.16 },
new THREE.Vector3(0, 0.035, -0.18),
new THREE.MeshStandardMaterial({
color: 0xb27b43,
roughness: 0.85
})
);
addBox(
boat,
{ x: 0.20, y: 0.16, z: 0.22 },
new THREE.Vector3(0, 0.105, -0.49),
new THREE.MeshStandardMaterial({
color: 0x6f7755,
roughness: 1
})
);
const wakePositions = [
-0.10, 0.018, -0.87, -0.14, 0.018, -1.22,
0.10, 0.018, -0.91, 0.14, 0.018, -1.28
];
const wakeGeometry = new THREE.BufferGeometry();
wakeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(wakePositions, 3)
);
boat.add(
new THREE.LineSegments(
wakeGeometry,
new THREE.LineBasicMaterial({
color: 0xc5e7dc,
transparent: true,
opacity: 0.52,
depthWrite: false
})
)
);
boat.position.set(-1.25, 0.025, 4.60);
boat.rotation.y = Math.PI;
scene.add(boat);
// ---------------------------------------------------------------------
// Custom orbit controls and camera presets
// ---------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 0.15, 0),
goalTarget: new THREE.Vector3(0, 0.15, 0),
radius: 16.7,
goalRadius: 16.7,
theta: 0.16,
goalTheta: 0.16,
phi: 0.09,
goalPhi: 0.09
};
function setView(name, instant = false) {
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
if (name === "ground") {
orbit.goalTarget.set(-0.72, 0.32, 2.35);
orbit.goalRadius = 6.15;
orbit.goalTheta = -0.38;
orbit.goalPhi = 1.38;
} else {
orbit.goalTarget.set(0, 0.12, 0);
orbit.goalRadius = 16.7;
orbit.goalTheta = 0.16;
orbit.goalPhi = 0.09;
}
if (instant) {
orbit.target.copy(orbit.goalTarget);
orbit.radius = orbit.goalRadius;
orbit.theta = orbit.goalTheta;
orbit.phi = orbit.goalPhi;
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.remove("active");
});
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.goalTheta -= dx * 0.0052;
orbit.goalPhi = clamp(orbit.goalPhi - dy * 0.0045, 0.07, 1.46);
});
function stopDragging(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.goalRadius = clamp(
orbit.goalRadius * Math.exp(event.deltaY * 0.001),
4.4,
25
);
}, { passive: false });
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let boatZ = 4.60;
let boatDirection = -1;
let boatHeading = Math.PI;
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
const damping = 1 - Math.exp(-dt * 6.5);
orbit.target.lerp(orbit.goalTarget, damping);
orbit.radius += (orbit.goalRadius - orbit.radius) * damping;
orbit.theta += (orbit.goalTheta - orbit.theta) * damping;
orbit.phi += (orbit.goalPhi - orbit.phi) * damping;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
// The canoe advances and turns gently in the main southern reach.
boatZ += boatDirection * 0.28 * dt;
if (boatZ <= 2.08) {
boatZ = 2.08;
boatDirection = 1;
} else if (boatZ >= 4.80) {
boatZ = 4.80;
boatDirection = -1;
}
const targetHeading = boatDirection < 0 ? Math.PI : 0;
const headingDifference = Math.atan2(
Math.sin(targetHeading - boatHeading),
Math.cos(targetHeading - boatHeading)
);
boatHeading += headingDifference * Math.min(1, dt * 2.4);
boat.position.z = boatZ;
boat.position.y = 0.025 + Math.sin(time * 1.8) * 0.012;
boat.rotation.y = boatHeading;
boat.rotation.z = Math.sin(time * 1.25) * 0.012;
boat.rotation.x = Math.sin(time * 1.55 + 1.2) * 0.007;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
setView("overhead", true);
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```