Prompt specification
Build or customize the Three.js 3D scene "Raised planting bed between canals" 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: Raised planting bed between canals
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/raised-planting-bed-between-canals-x2293
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Mesoamerican chinampa farming between canals. Build a rectangular raised planting bed bordered by narrow water channels. Show the bed's elevation above water and leave enough channel width for a small boat. Stylized solid forms.
Working Three.js Starter (raised-planting-bed-between-canals-x2293):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chinampa — Mesoamerican Raised-Field Farming</title>
<style>
:root {
--ink: #173b35;
--paper: rgba(255, 252, 239, 0.92);
--line: rgba(23, 59, 53, 0.16);
--accent: #d9783d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d9d2;
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%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 10;
width: min(350px, calc(100vw - 48px));
padding: 20px 22px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 16px 45px rgba(31, 64, 58, 0.16);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #b85e31;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 46px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.035em;
}
.subtitle {
margin: 12px 0 0;
color: rgba(23, 59, 53, 0.72);
font-size: 13px;
line-height: 1.5;
}
.facts {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 15px;
}
.fact {
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.44);
color: rgba(23, 59, 53, 0.76);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
}
.legend {
position: fixed;
top: 24px;
right: 24px;
z-index: 10;
display: grid;
gap: 9px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 14px;
background: rgba(255, 252, 239, 0.84);
box-shadow: 0 10px 30px rgba(31, 64, 58, 0.12);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.soil {
background: #9b633d;
}
.swatch.crop {
background: #4f8d43;
}
.swatch.water {
background: #3b9e9b;
}
.scene-label {
position: fixed;
z-index: 8;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 9px;
background: rgba(255, 252, 239, 0.9);
box-shadow: 0 7px 20px rgba(21, 56, 51, 0.16);
color: #244a43;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.055em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, calc(-100% - 22px));
pointer-events: none;
}
.scene-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 22px;
background: rgba(255, 252, 239, 0.9);
box-shadow: 0 0 0 1px rgba(23, 59, 53, 0.1);
}
.scene-label::before {
content: "";
position: absolute;
top: calc(100% + 19px);
left: calc(50% - 3px);
width: 7px;
height: 7px;
border: 2px solid rgba(255, 252, 239, 0.95);
border-radius: 50%;
background: #d9783d;
}
.controls {
position: fixed;
right: 24px;
bottom: 22px;
z-index: 10;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 13px;
background: rgba(255, 252, 239, 0.88);
box-shadow: 0 10px 30px rgba(31, 64, 58, 0.14);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.controls span {
color: rgba(23, 59, 53, 0.7);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
}
.controls kbd {
display: inline-block;
margin: 0 2px;
padding: 3px 5px;
border: 1px solid var(--line);
border-bottom-width: 2px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.62);
color: var(--ink);
font-family: inherit;
font-size: 9px;
}
button {
padding: 8px 11px;
border: 0;
border-radius: 8px;
background: var(--ink);
color: #fff9e9;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
background: #285d54;
transform: translateY(-1px);
}
@media (max-width: 720px) {
.title-card {
top: 14px;
left: 14px;
width: min(310px, calc(100vw - 28px));
padding: 16px 17px;
}
.legend,
.scene-label {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
justify-content: space-between;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<section class="title-card">
<div class="eyebrow">Xochimilco-inspired wetland agriculture</div>
<h1>Chinampa</h1>
<p class="subtitle">
A fertile raised field built between freshwater canals, using layered soil,
timber reinforcement, and mixed maize, bean, and squash cultivation.
</p>
<div class="facts">
<span class="fact">1.7 m ABOVE WATER</span>
<span class="fact">3.2 m NAVIGABLE CANAL</span>
<span class="fact">MIXED CROPS</span>
</div>
</section>
<aside class="legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch soil"></span>
Raised earth bed
</div>
<div class="legend-item">
<span class="swatch crop"></span>
Polyculture crops
</div>
<div class="legend-item">
<span class="swatch water"></span>
Canal water
</div>
</aside>
<div id="label-bed" class="scene-label">Raised planting bed</div>
<div id="label-canal" class="scene-label">Navigable water channel</div>
<div id="label-boat" class="scene-label">Small wooden canoe</div>
<div class="controls">
<span>
<kbd>Drag</kbd> orbit <kbd>Shift-drag</kbd> pan
<kbd>Scroll</kbd> zoom
</span>
<button id="reset-view" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d9d2);
scene.fog = new THREE.Fog(0xb9d9d2, 48, 105);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe9fbf4, 0x79563c, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe0ae, 3.1);
sun.position.set(-22, 32, 19);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -35;
sun.shadow.camera.right = 35;
sun.shadow.camera.top = 35;
sun.shadow.camera.bottom = -35;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 85;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x9ad8de, 0.65);
coolFill.position.set(22, 12, -24);
scene.add(coolFill);
// ---------------------------------------------------------------------
// Materials and reusable geometry
// ---------------------------------------------------------------------
const material = {
water: new THREE.MeshStandardMaterial({
color: 0x3a9d99,
roughness: 0.33,
metalness: 0.04
}),
wetEarth: new THREE.MeshStandardMaterial({
color: 0x71452f,
roughness: 0.95
}),
earth: new THREE.MeshStandardMaterial({
color: 0xa66f43,
roughness: 0.92
}),
earthLight: new THREE.MeshStandardMaterial({
color: 0xc28b55,
roughness: 0.9
}),
topsoil: new THREE.MeshStandardMaterial({
color: 0x563821,
roughness: 1
}),
ridge: new THREE.MeshStandardMaterial({
color: 0x68462d,
roughness: 1
}),
grass: new THREE.MeshStandardMaterial({
color: 0x6f8d4c,
roughness: 0.94
}),
grassLight: new THREE.MeshStandardMaterial({
color: 0x8ca65b,
roughness: 0.95
}),
timber: new THREE.MeshStandardMaterial({
color: 0x5b3825,
roughness: 0.88
}),
timberLight: new THREE.MeshStandardMaterial({
color: 0x815436,
roughness: 0.86
}),
cornStem: new THREE.MeshStandardMaterial({
color: 0x4d8439,
roughness: 0.85
}),
leafDark: new THREE.MeshStandardMaterial({
color: 0x376f37,
roughness: 0.86
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x6b9d47,
roughness: 0.84
}),
vine: new THREE.MeshStandardMaterial({
color: 0x3b7135,
roughness: 0.9
}),
pumpkin: new THREE.MeshStandardMaterial({
color: 0xe79528,
roughness: 0.74
}),
pumpkinLight: new THREE.MeshStandardMaterial({
color: 0xf4b13b,
roughness: 0.72
}),
bean: new THREE.MeshStandardMaterial({
color: 0xa64632,
roughness: 0.8
}),
bamboo: new THREE.MeshStandardMaterial({
color: 0x9c8645,
roughness: 0.86
}),
rock: new THREE.MeshStandardMaterial({
color: 0x8e8b78,
roughness: 1
}),
ripple: new THREE.MeshBasicMaterial({
color: 0xb9e8dc,
transparent: true,
opacity: 0.56,
depthWrite: false
}),
hull: new THREE.MeshStandardMaterial({
color: 0x6c3826,
roughness: 0.8,
flatShading: true
}),
hullDark: new THREE.MeshStandardMaterial({
color: 0x3d241c,
roughness: 0.9
}),
basket: new THREE.MeshStandardMaterial({
color: 0xa9793f,
roughness: 0.9
}),
shirt: new THREE.MeshStandardMaterial({
color: 0xe8d9ae,
roughness: 0.9
}),
skin: new THREE.MeshStandardMaterial({
color: 0x9b6546,
roughness: 0.86
}),
hat: new THREE.MeshStandardMaterial({
color: 0xc7a560,
roughness: 0.95
})
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const leafShape = new THREE.Shape();
leafShape.moveTo(0, 0);
leafShape.quadraticCurveTo(0.34, 0.18, 0.24, 0.72);
leafShape.quadraticCurveTo(0.16, 1.08, 0, 1.28);
leafShape.quadraticCurveTo(-0.22, 1.05, -0.24, 0.72);
leafShape.quadraticCurveTo(-0.32, 0.2, 0, 0);
const leafGeometry = new THREE.ExtrudeGeometry(leafShape, {
depth: 0.035,
bevelEnabled: false,
curveSegments: 3
});
leafGeometry.translate(0, 0, -0.0175);
const unitSphere = new THREE.SphereGeometry(1, 10, 7);
const unitIco = new THREE.IcosahedronGeometry(1, 1);
function addBox(w, h, d, x, y, z, mat, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
return mesh;
}
function addMesh(geometry, mat, parent = scene) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, mat, parent = scene, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 0.86, length, radialSegments),
mat
);
mesh.position.copy(a).add(b).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 seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
const random = seededRandom(48291);
// ---------------------------------------------------------------------
// Water, outer banks, and the raised field
// ---------------------------------------------------------------------
const BED_WIDTH = 18;
const BED_DEPTH = 10;
const CANAL_WIDTH = 3.2;
const outerX = BED_WIDTH / 2 + CANAL_WIDTH;
const outerZ = BED_DEPTH / 2 + CANAL_WIDTH;
const bankThickness = 1.6;
const water = new THREE.Mesh(
new THREE.PlaneGeometry(160, 160),
material.water
);
water.rotation.x = -Math.PI / 2;
water.position.y = 0;
water.receiveShadow = true;
scene.add(water);
// Four outer banks leave a continuous canal around the chinampa.
for (const sign of [-1, 1]) {
addBox(
outerX * 2 + bankThickness,
0.7,
bankThickness,
0,
0.35,
sign * (outerZ + bankThickness / 2),
material.earthLight
);
addBox(
outerX * 2 + bankThickness - 0.12,
0.09,
bankThickness - 0.1,
0,
0.745,
sign * (outerZ + bankThickness / 2),
material.grass
);
addBox(
bankThickness,
0.7,
outerZ * 2,
sign * (outerX + bankThickness / 2),
0.35,
0,
material.earthLight
);
addBox(
bankThickness - 0.1,
0.09,
outerZ * 2 - 0.12,
sign * (outerX + bankThickness / 2),
0.745,
0,
material.grass
);
}
// Wet foundation and main earthen body make the elevation readable.
addBox(18.18, 0.48, 10.18, 0, 0.24, 0, material.wetEarth);
addBox(18, 1.05, 10, 0, 1.005, 0, material.earth);
addBox(17.62, 0.17, 9.62, 0, 1.615, 0, material.topsoil);
// Erosion-resistant clay bands along the bed sides.
for (const sign of [-1, 1]) {
addBox(
17.9,
0.16,
0.1,
0,
0.82,
sign * 5.025,
material.earthLight,
false,
true
);
addBox(
0.1,
0.16,
9.9,
sign * 9.025,
0.82,
0,
material.earthLight,
false,
true
);
}
// Timber retaining stakes around the raised bed.
for (let x = -8.4; x <= 8.4; x += 1.4) {
for (const sign of [-1, 1]) {
const h = 1.03 + random() * 0.18;
addBox(
0.18,
h,
0.18,
x,
1.38 + h / 2,
sign * 5.04,
random() > 0.5 ? material.timber : material.timberLight
);
}
}
for (let z = -4.2; z <= 4.2; z += 1.4) {
for (const sign of [-1, 1]) {
const h = 1.03 + random() * 0.18;
addBox(
0.18,
h,
0.18,
sign * 9.04,
1.38 + h / 2,
z,
random() > 0.5 ? material.timber : material.timberLight
);
}
}
// Horizontal branches tie the retaining stakes together.
cylinderBetween(
new THREE.Vector3(-9.04, 1.72, -5.07),
new THREE.Vector3(9.04, 1.72, -5.07),
0.075,
material.timber
);
cylinderBetween(
new THREE.Vector3(-9.04, 1.72, 5.07),
new THREE.Vector3(9.04, 1.72, 5.07),
0.075,
material.timber
);
cylinderBetween(
new THREE.Vector3(-9.07, 1.72, -4.9),
new THREE.Vector3(-9.07, 1.72, 4.9),
0.075,
material.timber
);
cylinderBetween(
new THREE.Vector3(9.07, 1.72, -4.9),
new THREE.Vector3(9.07, 1.72, 4.9),
0.075,
material.timber
);
// Cultivated soil ridges.
for (const z of [-3.3, -1.65, 0, 1.65, 3.3]) {
addBox(16.1, 0.16, 0.72, 0, 1.77, z, material.ridge);
}
// ---------------------------------------------------------------------
// Maize plants
// ---------------------------------------------------------------------
const cropBase = 1.79;
function makeCorn(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, cropBase, z);
group.rotation.y = random() * Math.PI * 2;
scene.add(group);
const height = (1.65 + random() * 0.5) * scale;
const stem = addMesh(
new THREE.CylinderGeometry(0.07, 0.095, height, 6),
material.cornStem,
group
);
stem.position.y = height / 2;
for (let i = 0; i < 5; i++) {
const radial = new THREE.Group();
radial.rotation.y = (i / 5) * Math.PI * 2 + random() * 0.35;
group.add(radial);
const leaf = addMesh(leafGeometry, i % 2 ? material.leafLight : material.leafDark, radial);
leaf.position.y = 0.25 + i * 0.18;
leaf.rotation.z = i % 2 === 0 ? 0.8 : -0.72;
leaf.rotation.x = (random() - 0.5) * 0.16;
leaf.scale.setScalar(0.78 + random() * 0.22);
}
const tassel = addMesh(
new THREE.ConeGeometry(0.13, 0.42, 5),
material.leafLight,
group
);
tassel.position.y = height + 0.18;
const ear = addMesh(unitSphere, material.pumpkinLight, group);
ear.position.set(0.18, height * 0.53, 0.03);
ear.scale.set(0.13, 0.32, 0.13);
ear.rotation.z = -0.18;
const leafCap = addMesh(leafGeometry, material.leafLight, group);
leafCap.position.y = height - 0.12;
leafCap.rotation.z = -0.28;
leafCap.scale.setScalar(0.68);
}
for (const z of [-3.3, 0, 3.3]) {
for (const x of [-7, -3.5, 0, 3.5, 7]) {
makeCorn(x, z, 0.9 + random() * 0.2);
}
}
// ---------------------------------------------------------------------
// Bean trellises
// ---------------------------------------------------------------------
function makeBeanTrellis(x, z) {
const group = new THREE.Group();
group.position.set(x, cropBase, z);
group.rotation.y = (random() - 0.5) * 0.12;
scene.add(group);
cylinderBetween(
new THREE.Vector3(-0.68, 0, 0),
new THREE.Vector3(-0.42, 2.05, 0),
0.055,
material.bamboo,
group
);
cylinderBetween(
new THREE.Vector3(0.68, 0, 0),
new THREE.Vector3(0.42, 2.05, 0),
0.055,
material.bamboo,
group
);
cylinderBetween(
new THREE.Vector3(-0.55, 1.72, 0),
new THREE.Vector3(0.55, 1.72, 0),
0.045,
material.bamboo,
group
);
for (let vineIndex = -1; vineIndex <= 1; vineIndex++) {
const vineX = vineIndex * 0.32;
cylinderBetween(
new THREE.Vector3(vineX * 0.9, 0, 0),
new THREE.Vector3(vineX, 1.82, 0),
0.025,
material.vine,
group
);
for (let leafIndex = 0; leafIndex < 4; leafIndex++) {
const leaf = addMesh(
leafGeometry,
leafIndex % 2 ? material.leafLight : material.leafDark,
group
);
leaf.position.set(vineX, 0.35 + leafIndex * 0.38, 0);
leaf.rotation.z = leafIndex % 2 ? 0.85 : -0.85;
leaf.scale.setScalar(0.58);
}
for (let podIndex = 0; podIndex < 3; podIndex++) {
const pod = addMesh(unitSphere, material.bean, group);
pod.position.set(vineX + 0.06, 0.55 + podIndex * 0.42, 0.045);
pod.scale.set(0.065, 0.22, 0.055);
pod.rotation.z = 0.15;
}
}
}
for (const z of [-1.65, 1.65]) {
for (const x of [-5.4, 0, 5.4]) {
makeBeanTrellis(x, z);
}
}
// ---------------------------------------------------------------------
// Squash plants and ribbed pumpkins
// ---------------------------------------------------------------------
function makeSquash(x, z) {
const group = new THREE.Group();
group.position.set(x, cropBase, z);
group.rotation.y = random() * Math.PI * 2;
scene.add(group);
const vinePoints = [
new THREE.Vector3(0, 0.08, 0),
new THREE.Vector3(0.48, 0.09, 0.14),
new THREE.Vector3(0.84, 0.08, -0.18),
new THREE.Vector3(1.05, 0.07, -0.05)
];
for (let i = 0; i < vinePoints.length - 1; i++) {
cylinderBetween(
vinePoints[i],
vinePoints[i + 1],
0.025,
material.vine,
group,
5
);
}
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2 + random() * 0.4;
const leaf = addMesh(unitIco, i % 2 ? material.leafLight : material.leafDark, group);
leaf.position.set(
Math.cos(angle) * (0.35 + random() * 0.48),
0.16 + random() * 0.08,
Math.sin(angle) * (0.35 + random() * 0.48)
);
leaf.scale.set(0.42 + random() * 0.13, 0.09, 0.34 + random() * 0.12);
leaf.rotation.y = angle;
}
const pumpkin = new THREE.Group();
pumpkin.position.set(0.38 + random() * 0.15, 0.02, 0.25 + random() * 0.2);
group.add(pumpkin);
const center = addMesh(unitSphere, material.pumpkin, pumpkin);
center.scale.set(0.22, 0.28, 0.22);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const lobe = addMesh(unitSphere, i % 2 ? material.pumpkin : material.pumpkinLight, pumpkin);
lobe.position.set(Math.cos(angle) * 0.17, 0.02, Math.sin(angle) * 0.17);
lobe.scale.set(0.105, 0.27, 0.105);
}
const stem = addMesh(
new THREE.CylinderGeometry(0.045, 0.065, 0.19, 5),
material.vine,
pumpkin
);
stem.position.y = 0.34;
stem.rotation.z = 0.1;
}
for (const z of [-3.3, 0, 3.3]) {
for (const x of [-5.25, -1.75, 1.75, 5.25]) {
makeSquash(x, z);
}
}
// ---------------------------------------------------------------------
// Willow trees and reeds along the outer canal banks
// ---------------------------------------------------------------------
function makeWillow(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.79, z);
group.scale.setScalar(scale);
scene.add(group);
const trunk = addMesh(
new THREE.CylinderGeometry(0.16, 0.28, 2.7, 6),
material.timber,
group
);
trunk.position.y = 1.35;
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI * 0.5 + 0.3;
cylinderBetween(
new THREE.Vector3(0, 1.55, 0),
new THREE.Vector3(
Math.cos(angle) * 1.25,
2.8 + random() * 0.4,
Math.sin(angle) * 1.25
),
0.095,
material.timber,
group
);
}
const canopyColors = [
material.leafDark,
material.leafLight,
material.grass,
material.leafLight
];
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const canopy = addMesh(unitIco, canopyColors[i % canopyColors.length], group);
canopy.position.set(
Math.cos(angle) * 0.85,
3.0 + (i % 2) * 0.35,
Math.sin(angle) * 0.85
);
canopy.scale.set(1.15, 0.9, 1.05);
canopy.rotation.y = random() * Math.PI;
}
}
makeWillow(-10.4, 9.1, 1.0);
makeWillow(1.2, 9.15, 0.85);
makeWillow(10.4, -9.1, 0.95);
makeWillow(-13.1, -3.4, 0.8);
makeWillow(13.1, 3.5, 0.78);
const reedGeometry = new THREE.ConeGeometry(0.045, 0.65, 4);
const reeds = new THREE.InstancedMesh(reedGeometry, material.vine, 58);
reeds.castShadow = true;
const dummy = new THREE.Object3D();
for (let i = 0; i < 58; i++) {
let x;
let z;
if (i % 2 === 0) {
x = -12 + random() * 24;
z = (i % 4 < 2 ? 1 : -1) * (outerZ + 0.12);
} else {
x = (i % 4 < 2 ? 1 : -1) * (outerX + 0.12);
z = -7.9 + random() * 15.8;
}
dummy.position.set(x, 1.02, z);
dummy.rotation.set((random() - 0.5) * 0.14, random() * Math.PI, (random() - 0.5) * 0.18);
dummy.scale.setScalar(0.7 + random() * 0.75);
dummy.updateMatrix();
reeds.setMatrixAt(i, dummy.matrix);
}
scene.add(reeds);
// A few faceted rocks at the waterline.
for (let i = 0; i < 12; i++) {
const rock = addMesh(unitIco, material.rock);
const side = random() > 0.5 ? 1 : -1;
rock.position.set(
-11.5 + random() * 23,
0.14,
side * (8.25 + random() * 0.35)
);
rock.scale.set(
0.2 + random() * 0.3,
0.16 + random() * 0.2,
0.2 + random() * 0.3
);
rock.rotation.set(random(), random(), random());
}
// ---------------------------------------------------------------------
// Stylized ripples confined to the canal
// ---------------------------------------------------------------------
const rippleCount = 72;
const ripples = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 0.012, 0.035),
material.ripple,
rippleCount
);
for (let i = 0; i < rippleCount; i++) {
let x;
let z;
if (i % 2 === 0) {
x = (i % 4 < 2 ? 1 : -1) * (9.18 + random() * 2.78);
z = -8.05 + random() * 16.1;
} else {
x = -12.05 + random() * 24.1;
z = (i % 4 < 2 ? 1 : -1) * (5.18 + random() * 2.78);
}
// Keep the immediate area around the canoe visually clear.
if (Math.abs(x - 10.6) < 1.25 && Math.abs(z - 1.2) < 2.2) {
x -= 1.8;
}
dummy.position.set(x, 0.025, z);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.scale.set(0.28 + random() * 0.85, 1, 1);
dummy.updateMatrix();
ripples.setMatrixAt(i, dummy.matrix);
}
scene.add(ripples);
// ---------------------------------------------------------------------
// Wooden canoe
// ---------------------------------------------------------------------
function createCanoeHull() {
const segments = 14;
const vertices = [];
const indices = [];
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
vertices.push(Math.cos(angle) * 0.65, 0.43, Math.sin(angle) * 1.9);
}
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
vertices.push(Math.cos(angle) * 0.43, 0.03, Math.sin(angle) * 1.62);
}
for (let i = 0; i < segments; i++) {
const next = (i + 1) % segments;
indices.push(i, next, segments + next);
indices.push(i, segments + next, segments + i);
}
const centerIndex = vertices.length / 3;
vertices.push(0, 0.0, 0);
for (let i = 0; i < segments; i++) {
const next = (i + 1) % segments;
indices.push(segments + i, segments + next, centerIndex);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const boat = new THREE.Group();
boat.position.set(10.6, 0.02, 1.15);
boat.rotation.y = -0.16;
scene.add(boat);
const hull = addMesh(createCanoeHull(), material.hull, boat);
const rim = addMesh(
new THREE.TorusGeometry(1, 0.065, 6, 36),
material.timberLight,
boat
);
rim.rotation.x = Math.PI / 2;
rim.scale.set(0.65, 1.9, 0.65);
rim.position.y = 0.43;
const interior = new THREE.Mesh(
new THREE.CircleGeometry(1, 36),
material.hullDark
);
interior.rotation.x = -Math.PI / 2;
interior.scale.set(0.53, 1.68, 1);
interior.position.y = 0.365;
interior.receiveShadow = true;
boat.add(interior);
// Cargo basket.
const basket = addMesh(unitBox, material.basket, boat);
basket.position.set(0, 0.53, -0.92);
basket.scale.set(0.55, 0.32, 0.56);
for (let i = -1; i <= 1; i++) {
const stripe = addMesh(unitBox, material.timberLight, boat);
stripe.position.set(i * 0.16, 0.53, -0.92);
stripe.scale.set(0.035, 0.34, 0.58);
}
const vegetables = addMesh(unitIco, material.leafLight, boat);
vegetables.position.set(0, 0.75, -0.92);
vegetables.scale.set(0.25, 0.15, 0.23);
// Small seated farmer provides scale.
const farmer = new THREE.Group();
farmer.position.set(0, 0.37, 0.52);
boat.add(farmer);
const torso = addMesh(
new THREE.CylinderGeometry(0.17, 0.23, 0.55, 7),
material.shirt,
farmer
);
torso.position.y = 0.48;
const head = addMesh(unitSphere, material.skin, farmer);
head.position.y = 0.92;
head.scale.setScalar(0.18);
const hat = addMesh(
new THREE.ConeGeometry(0.34, 0.2, 9),
material.hat,
farmer
);
hat.position.y = 1.12;
cylinderBetween(
new THREE.Vector3(-0.16, 0.6, 0),
new THREE.Vector3(-0.34, 0.22, 0.12),
0.055,
material.skin,
farmer
);
cylinderBetween(
new THREE.Vector3(0.16, 0.6, 0),
new THREE.Vector3(0.33, 0.3, 0.16),
0.055,
material.skin,
farmer
);
// Paddle resting across the starboard side.
cylinderBetween(
new THREE.Vector3(0.25, 1.12, 0.22),
new THREE.Vector3(1.03, -0.05, 0.86),
0.028,
material.timberLight,
boat
);
const paddleBlade = addMesh(unitBox, material.timberLight, boat);
paddleBlade.position.set(1.08, -0.08, 0.91);
paddleBlade.scale.set(0.18, 0.035, 0.45);
paddleBlade.rotation.y = -0.45;
// ---------------------------------------------------------------------
// Custom camera controls — no external controls addon
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0, 1.35, 0);
const spherical = new THREE.Spherical(44, 1.04, 0.72);
const initialTarget = target.clone();
const initialSpherical = spherical.clone();
function updateCamera() {
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(target).add(offset);
camera.lookAt(target);
}
updateCamera();
const activePointers = new Map();
let lastPinchDistance = 0;
let activePan = false;
function pointerDistance() {
const values = [...activePointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
function panCamera(dx, dy) {
const scale = spherical.radius * 0.00145;
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
target.addScaledVector(right, -dx * scale);
target.addScaledVector(forward, dy * scale);
target.x = THREE.MathUtils.clamp(target.x, -14, 14);
target.z = THREE.MathUtils.clamp(target.z, -14, 14);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
activePan = event.shiftKey || event.button === 2;
renderer.domElement.classList.add("dragging");
if (activePointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = activePointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (activePointers.size >= 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * (lastPinchDistance / distance),
22,
72
);
}
lastPinchDistance = distance;
updateCamera();
return;
}
if (activePan || event.shiftKey) {
panCamera(dx, dy);
} else {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.005,
0.32,
1.46
);
}
updateCamera();
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) lastPinchDistance = 0;
if (activePointers.size === 0) {
renderer.domElement.classList.remove("dragging");
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
22,
72
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
target.copy(initialTarget);
spherical.copy(initialSpherical);
updateCamera();
}
if (event.key === "+" || event.key === "=") {
spherical.radius = Math.max(22, spherical.radius - 2);
updateCamera();
}
if (event.key === "-") {
spherical.radius = Math.min(72, spherical.radius + 2);
updateCamera();
}
});
document.getElementById("reset-view").addEventListener("click", () => {
target.copy(initialTarget);
spherical.copy(initialSpherical);
updateCamera();
});
// ---------------------------------------------------------------------
// Labels
// ---------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-bed"),
position: new THREE.Vector3(-2.1, 3.35, -2.8)
},
{
element: document.getElementById("label-canal"),
position: new THREE.Vector3(11.0, 0.42, 5.65)
},
{
element: document.getElementById("label-boat"),
position: new THREE.Vector3(),
followBoat: true
}
];
function updateLabels() {
const width = innerWidth;
const height = innerHeight;
for (const label of labels) {
let point;
if (label.followBoat) {
point = boat.localToWorld(new THREE.Vector3(0, 1.78, 0));
} else {
point = label.position.clone();
}
const projected = point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
// Gentle bobbing keeps the canoe and ripples alive without distracting.
boat.position.y = 0.025 + Math.sin(time * 1.25) * 0.028;
boat.rotation.z = Math.sin(time * 1.05) * 0.011;
boat.rotation.x = Math.sin(time * 0.8 + 0.7) * 0.007;
material.ripple.opacity = 0.49 + Math.sin(time * 0.7) * 0.07;
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```