Prompt specification
Build or customize the Three.js 3D scene "Canal-linked farming and market district" 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: Canal-linked farming and market district
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/canal-linked-farming-and-market-district-x2295
Scene Description Prompt:
A voxel Mesoamerican chinampa farming district with raised beds, canals, and a market landing. One HTML file using Three.js from cdnjs.
Working Three.js Starter (canal-linked-farming-and-market-district-x2295):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chinampa — The Floating Gardens</title>
<style>
:root {
--cream: #fff4d6;
--ink: #263c32;
--mint: #86c9a6;
--gold: #f3c969;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d5c5;
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;
max-width: 360px;
padding: 18px 20px 17px;
color: var(--ink);
background: rgba(255, 244, 214, 0.9);
border: 1px solid rgba(38, 60, 50, 0.16);
border-radius: 4px;
box-shadow: 0 12px 36px rgba(38, 60, 50, 0.14);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: #587461;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 5vw, 49px);
line-height: 0.92;
letter-spacing: -0.055em;
}
.subtitle {
margin: 10px 0 0;
color: #52685b;
font-size: 12px;
line-height: 1.45;
}
.controls {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 10;
padding: 10px 13px;
color: var(--ink);
background: rgba(255, 244, 214, 0.86);
border: 1px solid rgba(38, 60, 50, 0.13);
border-radius: 999px;
box-shadow: 0 8px 24px rgba(38, 60, 50, 0.12);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.legend {
position: fixed;
left: 28px;
bottom: 25px;
z-index: 10;
display: flex;
gap: 15px;
color: rgba(38, 60, 50, 0.8);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 1px;
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.45);
}
.dot.green { background: #5b9d52; }
.dot.blue { background: #56b7b0; }
.dot.gold { background: #df8d42; }
@media (max-width: 650px) {
.title-card {
top: 14px;
left: 14px;
max-width: 250px;
padding: 13px 15px;
}
.subtitle,
.legend {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div class="title-card">
<p class="eyebrow">Mesoamerican wetland district</p>
<h1>CHINAMPA</h1>
<p class="subtitle">
Raised fertile islands, working canals, and a lively market landing
on the lake.
</p>
</div>
<div class="legend">
<span><i class="dot green"></i> Chinampa</span>
<span><i class="dot blue"></i> Canal</span>
<span><i class="dot gold"></i> Market</span>
</div>
<div class="controls">Drag to orbit · Scroll to zoom</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(0xb9d5c5);
scene.fog = new THREE.Fog(0xb9d5c5, 30, 68);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.12;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xd8f2e2, 0x687253, 2.25);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xffe3a1, 3.15);
sunLight.position.set(-16, 25, 16);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -30;
sunLight.shadow.camera.right = 30;
sunLight.shadow.camera.top = 28;
sunLight.shadow.camera.bottom = -28;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 70;
sunLight.shadow.bias = -0.00035;
scene.add(sunLight);
// -------------------------------------------------------------------------
// Materials and voxel helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
flatShading: true,
...options
});
const M = {
water: material(0x55aaa6, {
roughness: 0.38,
metalness: 0.08,
transparent: true,
opacity: 0.94
}),
deepWater: material(0x2c6c69),
ripple: material(0xa1ded1, {
transparent: true,
opacity: 0.5,
depthWrite: false,
emissive: 0x244e4a,
emissiveIntensity: 0.18
}),
stone: material(0x6f7661),
stoneLight: material(0x93927a),
stoneDark: material(0x515c4c),
soil: material(0x694735),
soilLight: material(0x8a6040),
soilDark: material(0x4d382b),
wood: material(0x9a6437),
woodLight: material(0xc48a4f),
woodDark: material(0x553b2c),
leaf: material(0x477c43),
leafLight: material(0x78a94f),
leafDark: material(0x2e623d),
maize: material(0xd8b64c),
flower: material(0xe16c51),
cream: material(0xf1dca9),
coral: material(0xd96b4d),
turquoise: material(0x4c9f9c),
yellow: material(0xe9b84f),
blue: material(0x4f7eaa),
skinA: material(0xa96743),
skinB: material(0x75452f),
skinC: material(0xc4875d),
black: material(0x27372f),
white: material(0xfff3d1),
pyramid: material(0xb98d62),
pyramidDark: material(0x8b674d),
temple: material(0xd8b278),
templeAccent: material(0xa44835),
cloud: material(0xf6f0d9, {
emissive: 0xe9e1c8,
emissiveIntensity: 0.12
}),
sun: new THREE.MeshBasicMaterial({
color: 0xffe7a0,
fog: false
})
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(w, h, d, x, y, z, mat, parent = scene, shadows = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = shadows;
mesh.receiveShadow = shadows;
parent.add(mesh);
return mesh;
}
function group(x = 0, y = 0, z = 0, parent = scene) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
let seed = 1347;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
// -------------------------------------------------------------------------
// Lake, distant land, mountains, and sky
// -------------------------------------------------------------------------
box(46, 0.65, 39, 0, -0.2, 0, M.deepWater, scene, false);
const water = new THREE.Mesh(new THREE.PlaneGeometry(46, 39), M.water);
water.rotation.x = -Math.PI / 2;
water.position.y = 0.24;
water.receiveShadow = true;
scene.add(water);
box(34, 1.25, 5.5, -1, 0.38, -15.1, M.leafDark);
box(35, 0.35, 6.2, -1, 0.93, -15.1, M.leaf);
function mountain(x, z, width, height, mat) {
const g = group(x, 0, z);
const levels = 5;
for (let i = 0; i < levels; i++) {
const w = width * (1 - i * 0.15);
const d = w * 0.72;
box(
w,
height / levels + 0.25,
d,
0,
0.5 + (height / levels) * (i + 0.5),
0,
i % 2 ? mat : M.stoneDark,
g
);
}
}
mountain(-22, -27, 13, 8, M.stoneDark);
mountain(-8, -30, 17, 11, M.stone);
mountain(10, -29, 14, 8, M.stoneDark);
mountain(24, -25, 11, 6.5, M.stone);
const sun = box(3.2, 3.2, 1.3, -19, 18, -29, M.sun, scene, false);
sun.rotation.y = -0.25;
// -------------------------------------------------------------------------
// Trees and temple
// -------------------------------------------------------------------------
function tree(x, y, z, scale = 1, parent = scene) {
const g = group(x, y, z, parent);
g.scale.setScalar(scale);
box(0.38, 1.8, 0.38, 0, 0.9, 0, M.woodDark, g);
box(1.55, 1.0, 1.35, 0, 2.05, 0, M.leafDark, g);
box(1.12, 0.9, 1.05, -0.25, 2.75, 0.08, M.leaf, g);
box(0.85, 0.8, 0.9, 0.45, 2.65, -0.15, M.leafLight, g);
return g;
}
for (let i = 0; i < 20; i++) {
const x = -16 + random() * 31;
const z = -16.8 + random() * 2.8;
tree(x, 1.1, z, 0.7 + random() * 0.65);
}
const pyramid = group(-10.5, 1.1, -15.1);
const pyramidLevels = [
[8.2, 1.35],
[6.6, 1.35],
[5.0, 1.35],
[3.4, 1.35]
];
let currentY = 0;
pyramidLevels.forEach(([size, height], index) => {
box(
size,
height,
size * 0.72,
0,
currentY + height / 2,
0,
index % 2 ? M.pyramid : M.pyramidDark,
pyramid
);
currentY += height;
});
box(2.4, 1.65, 2.0, 0, currentY + 0.825, 0, M.temple, pyramid);
box(2.85, 0.3, 2.35, 0, currentY + 1.8, 0, M.templeAccent, pyramid);
box(0.65, 0.9, 0.12, 0, currentY + 0.85, 1.05, M.black, pyramid);
box(0.16, 1.05, 0.18, -0.9, currentY + 2.2, 0.75, M.woodDark, pyramid);
box(0.16, 1.05, 0.18, 0.9, currentY + 2.2, 0.75, M.woodDark, pyramid);
box(2.1, 0.38, 0.14, 0, currentY + 2.25, 0.75, M.templeAccent, pyramid);
// -------------------------------------------------------------------------
// Chinampa islands and crops
// -------------------------------------------------------------------------
const plots = [];
const plotXs = [-10, -2, 6];
const plotZs = [-7, 1.5];
plotXs.forEach((x) => {
plotZs.forEach((z) => plots.push({ x, z, size: 6.35 }));
});
const stemMatrices = [];
const leafMatrices = [];
const topMatrices = [];
const stemColors = [];
const leafColors = [];
const topColors = [];
function buildPlot(plot) {
const { x, z, size } = plot;
box(size, 0.58, size, x, 0.53, z, M.stoneDark);
box(size + 0.12, 0.16, size + 0.12, x, 0.86, z, M.stone);
// Voxel retaining blocks around the perimeter.
const blockCount = 12;
const step = size / blockCount;
for (let i = 0; i < blockCount; i++) {
const p = -size / 2 + step * (i + 0.5);
const stone = choose([M.stone, M.stoneLight, M.stoneDark]);
box(step + 0.03, 0.46, 0.23, x + p, 0.71, z - size / 2, stone);
box(step + 0.03, 0.46, 0.23, x + p, 0.71, z + size / 2, stone);
box(0.23, 0.46, step + 0.03, x - size / 2, 0.71, z + p, stone);
box(0.23, 0.46, step + 0.03, x + size / 2, 0.71, z + p, stone);
}
// Timber corner posts.
[
[-1, -1],
[1, -1],
[-1, 1],
[1, 1]
].forEach(([sx, sz]) => {
box(
0.3,
1.35,
0.3,
x + sx * (size / 2 - 0.12),
0.72,
z + sz * (size / 2 - 0.12),
M.woodDark
);
});
// Three raised planting beds separated by miniature irrigation channels.
[-1.85, 0, 1.85].forEach((offset, bedIndex) => {
const soilMat = bedIndex === 1 ? M.soilLight : M.soil;
box(
1.38,
0.58,
5.42,
x + offset,
1.13,
z,
soilMat
);
box(
1.48,
0.1,
5.5,
x + offset,
1.45,
z,
M.soilDark
);
for (let row = 0; row < 7; row++) {
const pz = z - 2.38 + row * 0.79;
const px = x + offset + (random() - 0.5) * 0.22;
stemMatrices.push({
x: px,
y: 1.76,
z: pz,
sx: 0.15,
sy: 0.58,
sz: 0.15
});
leafMatrices.push({
x: px,
y: 1.91,
z: pz,
sx: 0.62,
sy: 0.22,
sz: 0.39,
ry: random() > 0.5 ? 0 : Math.PI / 2
});
const isCorn = random() > 0.56;
topMatrices.push({
x: px,
y: isCorn ? 2.14 : 2.08,
z: pz,
sx: isCorn ? 0.27 : 0.34,
sy: isCorn ? 0.42 : 0.3,
sz: isCorn ? 0.27 : 0.34
});
stemColors.push(new THREE.Color(0x356f3e));
leafColors.push(
new THREE.Color(
choose([0x5e9847, 0x78aa4e, 0x447f43, 0x8daf54])
)
);
topColors.push(
new THREE.Color(
isCorn ? 0xd9b74f : choose([0xe16b4f, 0xf0d26b, 0xd996a1])
)
);
}
});
// Small shade tree and stacked tools at the corner.
tree(x + 2.65, 0.92, z + 2.65, 0.48);
box(0.18, 1.25, 0.18, x - 2.75, 1.48, z - 2.72, M.woodDark);
box(0.9, 0.16, 0.18, x - 2.45, 2.0, z - 2.72, M.woodLight);
}
plots.forEach(buildPlot);
function makeInstances(matrices, colors, mat, castShadow = true) {
const mesh = new THREE.InstancedMesh(unitBox, mat, matrices.length);
const dummy = new THREE.Object3D();
matrices.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, item.ry || 0, 0);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, colors[index]);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
makeInstances(
stemMatrices,
stemColors,
material(0xffffff, { roughness: 1 })
);
makeInstances(
leafMatrices,
leafColors,
material(0xffffff, { roughness: 1 })
);
makeInstances(
topMatrices,
topColors,
material(0xffffff, { roughness: 0.82 })
);
// -------------------------------------------------------------------------
// Bridges and docks
// -------------------------------------------------------------------------
function bridge(x, z, orientation = "x") {
const g = group(x, 1.48, z);
const length = 2.65;
const width = 1.35;
if (orientation === "x") {
box(length, 0.22, width, 0, 0, 0, M.woodDark, g);
for (let i = 0; i < 8; i++) {
box(0.28, 0.14, width - 0.05, -length / 2 + 0.2 + i * 0.34, 0.17, 0, M.woodLight, g);
}
[-0.45, 0.45].forEach((dz) => {
box(length, 0.13, 0.13, 0, 0.77, dz, M.wood, g);
[-1.08, 1.08].forEach((dx) => {
box(0.16, 0.9, 0.16, dx, 0.38, dz, M.woodDark, g);
});
});
} else {
box(width, 0.22, length, 0, 0, 0, M.woodDark, g);
for (let i = 0; i < 8; i++) {
box(width - 0.05, 0.14, 0.28, 0, 0.17, -length / 2 + 0.2 + i * 0.34, M.woodLight, g);
}
[-0.45, 0.45].forEach((dx) => {
box(0.13, 0.13, length, dx, 0.77, 0, M.wood, g);
[-1.08, 1.08].forEach((dz) => {
box(0.16, 0.9, 0.16, dx, 0.38, dz, M.woodDark, g);
});
});
}
return g;
}
plotZs.forEach((z) => {
bridge(-6, z, "x");
bridge(2, z, "x");
});
[-10, -2, 6].forEach((x) => {
bridge(x, -2.75, "z");
});
// -------------------------------------------------------------------------
// Market landing
// -------------------------------------------------------------------------
const market = group(14.3, 0, 4);
box(7.2, 0.35, 13.2, 0, 1.2, 0, M.woodDark, market);
for (let i = 0; i < 24; i++) {
box(0.28, 0.09, 13.05, -3.3 + i * 0.29, 1.42, 0, i % 3 ? M.wood : M.woodLight, market);
}
[-3.2, 3.2].forEach((x) => {
[-5.8, -2, 2, 5.8].forEach((z) => {
box(0.42, 1.55, 0.42, x, 0.58, z, M.woodDark, market);
box(0.62, 0.18, 0.62, x, 1.32, z, M.wood, market);
});
});
// Dock connecting the market to the easternmost chinampa.
box(2.6, 0.32, 1.65, -4.55, 1.22, 0, M.wood, market);
for (let i = 0; i < 8; i++) {
box(0.28, 0.1, 1.6, -5.65 + i * 0.31, 1.43, 0, M.woodLight, market);
}
function stall(x, z, canopyMat, accentMat) {
const g = group(x, 1.45, z, market);
[-1.1, 1.1].forEach((px) => {
[-0.9, 0.9].forEach((pz) => {
box(0.16, 2.55, 0.16, px, 1.28, pz, M.woodDark, g);
});
});
box(2.55, 0.28, 2.18, 0, 2.58, 0, canopyMat, g);
box(2.85, 0.18, 2.42, 0, 2.78, 0, accentMat, g);
box(2.95, 0.12, 0.2, 0, 2.7, -1.24, canopyMat, g);
box(2.95, 0.12, 0.2, 0, 2.7, 1.24, canopyMat, g);
box(2.2, 0.75, 1.0, 0, 0.95, -0.18, M.woodLight, g);
box(2.35, 0.13, 1.12, 0, 1.39, -0.18, M.wood, g);
const produce = [M.coral, M.yellow, M.leafLight, M.turquoise, M.flower];
for (let i = 0; i < 12; i++) {
box(
0.23,
0.2,
0.23,
-0.88 + (i % 4) * 0.55,
1.56,
-0.48 + Math.floor(i / 4) * 0.28,
produce[i % produce.length],
g
);
}
// Hanging banner.
box(0.12, 1.1, 0.12, 1.1, 1.85, -0.95, M.woodDark, g);
box(0.42, 0.85, 0.08, 1.1, 1.72, -0.95, accentMat, g);
}
stall(-2.15, -3.65, M.coral, M.yellow);
stall(2.15, -3.65, M.turquoise, M.cream);
stall(-2.15, 1.35, M.yellow, M.coral);
stall(2.15, 1.35, M.blue, M.cream);
// Crates, pottery, sacks, and stacked gourds.
function crate(x, y, z, size = 0.7) {
box(size, size * 0.7, size, x, y + size * 0.35, z, M.woodLight, market);
box(size + 0.04, 0.09, size + 0.04, x, y + size * 0.72, z, M.wood, market);
}
crate(-2.8, 1.46, -0.2, 0.72);
crate(-2.65, 2.02, -0.2, 0.55);
crate(2.8, 1.46, 4.55, 0.8);
crate(2.7, 2.08, 4.5, 0.58);
box(0.65, 0.8, 0.65, 2.75, 1.86, 3.3, M.soilLight, market);
box(0.48, 0.4, 0.48, 2.75, 2.43, 3.3, M.soilDark, market);
box(0.75, 0.55, 0.65, -2.75, 1.74, 4.4, M.cream, market);
// Tall market banner.
box(0.18, 4.2, 0.18, 3.1, 3.55, 5.8, M.woodDark, market);
box(1.15, 2.0, 0.12, 3.1, 4.1, 5.8, M.coral, market);
box(0.75, 0.25, 0.15, 3.1, 4.55, 5.8, M.cream, market);
box(0.75, 0.25, 0.15, 3.1, 3.75, 5.8, M.cream, market);
box(0.25, 0.75, 0.15, 3.1, 4.15, 5.8, M.turquoise, market);
// -------------------------------------------------------------------------
// People
// -------------------------------------------------------------------------
const animatedPeople = [];
function person(x, y, z, shirt, scale = 1, parent = scene) {
const g = group(x, y, z, parent);
g.scale.setScalar(scale);
box(0.48, 0.78, 0.36, 0, 1.2, 0, shirt, g);
box(0.42, 0.42, 0.4, 0, 1.91, 0, choose([M.skinA, M.skinB, M.skinC]), g);
box(0.47, 0.18, 0.45, 0, 2.12, 0, M.black, g);
box(0.16, 0.58, 0.18, -0.14, 0.31, 0, M.woodDark, g);
box(0.16, 0.58, 0.18, 0.14, 0.31, 0, M.woodDark, g);
box(0.16, 0.68, 0.18, -0.34, 1.18, 0, M.skinA, g);
box(0.16, 0.68, 0.18, 0.34, 1.18, 0, M.skinA, g);
animatedPeople.push({
group: g,
phase: random() * Math.PI * 2,
baseY: y
});
return g;
}
[
[-2.9, -3.7, M.blue],
[-1.2, -3.1, M.coral],
[1.35, -3.25, M.cream],
[2.8, -2.9, M.turquoise],
[-2.7, 1.3, M.yellow],
[-1.2, 2.45, M.white],
[1.35, 1.1, M.coral],
[2.75, 2.25, M.blue]
].forEach(([x, z, shirt]) => {
person(x, 1.46, z, shirt, 0.82 + random() * 0.18, market);
});
person(-6.0, 1.63, -7.35, M.cream, 0.82);
person(-5.55, 1.63, -6.55, M.blue, 0.74);
person(2.0, 1.63, -7.3, M.coral, 0.82);
person(6.0, 1.63, 1.0, M.yellow, 0.78);
// -------------------------------------------------------------------------
// Canoes
// -------------------------------------------------------------------------
const boats = [];
function boat(x, z, angle, color) {
const g = group(x, 0.48, z);
g.rotation.y = angle;
box(1.25, 0.35, 2.8, 0, 0, 0, M.woodDark, g);
box(0.94, 0.37, 2.42, 0, 0.07, 0, M.water, g);
box(1.32, 0.18, 0.24, 0, 0.2, -0.95, color, g);
box(1.32, 0.18, 0.24, 0, 0.2, 0.95, color, g);
box(1.18, 0.14, 0.35, 0, 0.22, 0, M.woodLight, g);
boats.push({
group: g,
phase: random() * Math.PI * 2,
baseY: g.position.y
});
}
boat(-6.0, -1.9, 0.05, M.coral);
boat(1.95, -7.2, Math.PI / 2, M.turquoise);
boat(10.3, 8.1, -0.18, M.yellow);
boat(-6.1, 7.4, 0.2, M.blue);
// -------------------------------------------------------------------------
// Water highlights
// -------------------------------------------------------------------------
const rippleData = [];
for (let i = 0; i < 85; i++) {
rippleData.push({
x: (random() - 0.5) * 40,
z: (random() - 0.5) * 33,
length: 0.35 + random() * 0.9,
phase: random() * Math.PI * 2
});
}
const rippleMesh = new THREE.InstancedMesh(
unitBox,
M.ripple,
rippleData.length
);
rippleMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
rippleMesh.renderOrder = 2;
scene.add(rippleMesh);
const rippleDummy = new THREE.Object3D();
function updateRipples(time) {
rippleData.forEach((r, index) => {
const pulse = 0.82 + Math.sin(time * 1.4 + r.phase) * 0.18;
rippleDummy.position.set(
r.x + Math.sin(time * 0.32 + r.phase) * 0.12,
0.285,
r.z
);
rippleDummy.rotation.set(0, 0, 0);
rippleDummy.scale.set(r.length * pulse, 0.018, 0.045);
rippleDummy.updateMatrix();
rippleMesh.setMatrixAt(index, rippleDummy.matrix);
});
rippleMesh.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Fireflies
// -------------------------------------------------------------------------
const fireflyData = [];
const fireflyMaterial = material(0xffe780, {
emissive: 0xffc83d,
emissiveIntensity: 2.1
});
for (let i = 0; i < 28; i++) {
fireflyData.push({
x: -13 + random() * 25,
y: 1.5 + random() * 2.3,
z: -9 + random() * 18,
phase: random() * Math.PI * 2
});
}
const fireflies = new THREE.InstancedMesh(
unitBox,
fireflyMaterial,
fireflyData.length
);
fireflies.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(fireflies);
const fireflyDummy = new THREE.Object3D();
// -------------------------------------------------------------------------
// Clouds
// -------------------------------------------------------------------------
const clouds = [];
function cloud(x, y, z, scale) {
const g = group(x, y, z);
g.scale.setScalar(scale);
box(3.8, 0.8, 1.5, 0, 0, 0, M.cloud, g, false);
box(2.4, 1.0, 1.7, -1.15, 0.55, 0, M.cloud, g, false);
box(2.0, 0.9, 1.5, 1.1, 0.45, 0, M.cloud, g, false);
box(1.4, 0.7, 1.2, 0, 1.1, 0, M.cloud, g, false);
clouds.push({ group: g, speed: 0.12 + random() * 0.12 });
}
cloud(-17, 12, -15, 1.25);
cloud(7, 14.5, -21, 1.65);
cloud(22, 10.5, -8, 0.95);
cloud(-5, 10.5, 17, 0.8);
// -------------------------------------------------------------------------
// Camera controls — implemented directly without addons
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.74,
phi: 1.02,
radius: 36,
target: new THREE.Vector3(1.2, 1.25, 0.5),
thetaTarget: 0.74,
phiTarget: 1.02,
radiusTarget: 36
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * s * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * s * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraState.thetaTarget -= dx * 0.006;
cameraState.phiTarget = THREE.MathUtils.clamp(
cameraState.phiTarget - dy * 0.005,
0.38,
1.38
);
previousX = event.clientX;
previousY = event.clientY;
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radiusTarget = THREE.MathUtils.clamp(
cameraState.radiusTarget + event.deltaY * 0.025,
17,
53
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.thetaTarget = 0.74;
cameraState.phiTarget = 1.02;
cameraState.radiusTarget = 36;
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
cameraState.theta += (cameraState.thetaTarget - cameraState.theta) * 0.075;
cameraState.phi += (cameraState.phiTarget - cameraState.phi) * 0.075;
cameraState.radius += (cameraState.radiusTarget - cameraState.radius) * 0.08;
updateCamera();
animatedPeople.forEach((p) => {
p.group.position.y =
p.baseY + Math.sin(time * 2.2 + p.phase) * 0.025;
p.group.rotation.y = Math.sin(time * 0.55 + p.phase) * 0.08;
});
boats.forEach((b) => {
b.group.position.y =
b.baseY + Math.sin(time * 1.35 + b.phase) * 0.055;
b.group.rotation.z = Math.sin(time * 1.05 + b.phase) * 0.018;
});
clouds.forEach((c) => {
c.group.position.x += c.speed * 0.01;
if (c.group.position.x > 27) c.group.position.x = -27;
});
fireflyData.forEach((f, index) => {
const brightness = 0.65 + Math.sin(time * 2.8 + f.phase) * 0.35;
fireflyDummy.position.set(
f.x + Math.sin(time * 0.7 + f.phase) * 0.35,
f.y + Math.sin(time * 1.3 + f.phase) * 0.22,
f.z + Math.cos(time * 0.6 + f.phase) * 0.28
);
fireflyDummy.scale.setScalar(0.07 * brightness);
fireflyDummy.updateMatrix();
fireflies.setMatrixAt(index, fireflyDummy.matrix);
});
fireflies.instanceMatrix.needsUpdate = true;
updateRipples(time);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateCamera();
animate();
</script>
</body>
</html>
```