Prompt specification
Build or customize the Three.js 3D scene "Irrigation channel dividing water inside an oasis" 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: Irrigation channel dividing water inside an oasis
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/irrigation-channel-dividing-water-inside-an-oasis-x3114
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Create a compact oasis vignette with well or spring source, distribution channel, and two planted plots. Use a specific regional reference and keep water paths physically connected.
Working Three.js Starter (irrigation-channel-dividing-water-inside-an-oasis-x3114):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Al Ain Oasis Falaj Vignette</title>
<style>
:root {
--ink: #26382f;
--paper: rgba(248, 242, 224, 0.91);
--accent: #167f91;
--line: rgba(38, 56, 47, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d5bf;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
canvas {
width: 100%;
height: 100%;
display: block;
}
canvas {
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 22px;
left: 24px;
width: min(430px, calc(100vw - 48px));
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(65, 52, 31, 0.12);
backdrop-filter: blur(9px);
}
.eyebrow {
margin: 0 0 5px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 35px);
font-weight: 500;
line-height: 1.03;
}
.subtitle {
margin: 8px 0 0;
font-size: 13px;
line-height: 1.45;
}
.connection-note {
display: flex;
gap: 9px;
align-items: flex-start;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #45564d;
font-size: 11.5px;
line-height: 1.4;
}
.connection-note strong {
color: var(--ink);
}
.water-dot {
flex: 0 0 auto;
width: 9px;
height: 9px;
margin-top: 3px;
border-radius: 50%;
background: #2a9bb3;
box-shadow: 0 0 0 4px rgba(42, 155, 179, 0.13);
}
.toolbar {
position: absolute;
right: 22px;
top: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(38, 56, 47, 0.18);
border-radius: 999px;
padding: 9px 13px;
background: rgba(248, 242, 224, 0.91);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 5px 18px rgba(65, 52, 31, 0.09);
backdrop-filter: blur(8px);
}
button:hover {
background: #fff9e9;
transform: translateY(-1px);
}
button[aria-pressed="false"] {
opacity: 0.62;
}
.legend {
position: absolute;
left: 24px;
bottom: 24px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(248, 242, 224, 0.88);
box-shadow: 0 8px 26px rgba(65, 52, 31, 0.1);
backdrop-filter: blur(8px);
font-size: 11.5px;
line-height: 1.55;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 18px;
height: 5px;
border-radius: 3px;
}
.swatch.water {
background: #2a9bb3;
}
.swatch.soil {
background: #765338;
}
.swatch.palm {
background: #3f7049;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
color: rgba(38, 56, 47, 0.72);
font-size: 11px;
text-align: right;
line-height: 1.45;
}
#labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(38, 56, 47, 0.16);
border-radius: 7px;
background: rgba(251, 246, 229, 0.88);
color: #31463a;
font-size: 10.5px;
font-weight: 750;
letter-spacing: 0.01em;
white-space: nowrap;
box-shadow: 0 4px 12px rgba(45, 40, 26, 0.1);
transition: opacity 120ms linear;
}
.world-label::before {
content: "";
display: inline-block;
width: 5px;
height: 5px;
margin-right: 5px;
border-radius: 50%;
background: #2a9bb3;
vertical-align: 1px;
}
.world-label.land::before {
background: #526d4b;
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle,
.connection-note {
font-size: 11px;
}
.toolbar {
top: auto;
right: 12px;
bottom: 65px;
}
button {
padding: 8px 11px;
font-size: 11px;
}
.legend {
left: 12px;
bottom: 12px;
padding: 9px 11px;
}
.controls {
display: none;
}
.world-label {
font-size: 9px;
padding: 4px 6px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<section class="title-card">
<p class="eyebrow">Regional reference · Al Ain, UAE</p>
<h1>Al Ain Oasis<br />Falaj Garden</h1>
<p class="subtitle">
A stylized low-poly interpretation of Al Ain Oasis in the Emirate of Abu Dhabi:
a stone wellhead, date-palm plantings, a watchtower, and the Al Hajar foothills.
</p>
<div class="connection-note">
<span class="water-dot"></span>
<span>
<strong>Connected water route:</strong>
wellhead spillway → main falaj → branch channel → plot header → irrigation furrows.
</span>
</div>
</section>
<nav class="toolbar" aria-label="Scene controls">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-labels" type="button" aria-pressed="true">Labels on</button>
<button id="toggle-flow" type="button" aria-pressed="true">Flow on</button>
</nav>
<div id="labels"></div>
<div class="legend">
<div class="legend-row">
<span class="swatch water"></span>
<span>Continuous falaj water path</span>
</div>
<div class="legend-row">
<span class="swatch soil"></span>
<span>Planting beds and furrows</span>
</div>
<div class="legend-row">
<span class="swatch palm"></span>
<span>Date palms and low-poly crops</span>
</div>
</div>
<div class="controls">
Drag to orbit · Scroll or pinch to zoom<br />
Arrow keys rotate · + / − zoom
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const labelLayer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d5bf);
scene.fog = new THREE.Fog(0xd8d5bf, 20, 43);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff4d4, 0x80694e, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0a1, 3.1);
sun.position.set(-7, 12, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d9e0, 0.55);
fill.position.set(8, 5, -7);
scene.add(fill);
const materials = {
sandTop: new THREE.MeshStandardMaterial({
color: 0xcba875,
roughness: 0.95,
flatShading: true
}),
sandSide: new THREE.MeshStandardMaterial({
color: 0x896344,
roughness: 1,
flatShading: true
}),
floor: new THREE.MeshStandardMaterial({
color: 0xb9ae8e,
roughness: 1
}),
stone: new THREE.MeshStandardMaterial({
color: 0xa68b68,
roughness: 0.9,
flatShading: true
}),
stoneLight: new THREE.MeshStandardMaterial({
color: 0xc1aa82,
roughness: 0.9,
flatShading: true
}),
stoneDark: new THREE.MeshStandardMaterial({
color: 0x6d5d49,
roughness: 1,
flatShading: true
}),
channelBed: new THREE.MeshStandardMaterial({
color: 0x5d5344,
roughness: 1
}),
water: new THREE.MeshStandardMaterial({
color: 0x2699b4,
emissive: 0x0d6076,
emissiveIntensity: 0.33,
roughness: 0.22,
metalness: 0.06,
transparent: true,
opacity: 0.91
}),
wellWater: new THREE.MeshStandardMaterial({
color: 0x1d8aa7,
emissive: 0x0c5061,
emissiveIntensity: 0.22,
roughness: 0.18,
metalness: 0.08,
transparent: true,
opacity: 0.94
}),
soil: new THREE.MeshStandardMaterial({
color: 0x765238,
roughness: 1,
flatShading: true
}),
soilLight: new THREE.MeshStandardMaterial({
color: 0x957047,
roughness: 1
}),
mud: new THREE.MeshStandardMaterial({
color: 0xb27b4e,
roughness: 1,
flatShading: true
}),
mudDark: new THREE.MeshStandardMaterial({
color: 0x815537,
roughness: 1
}),
wood: new THREE.MeshStandardMaterial({
color: 0x5e412b,
roughness: 1
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x7a5735,
roughness: 1,
flatShading: true
}),
leafDark: new THREE.MeshStandardMaterial({
color: 0x315d3d,
roughness: 1,
side: THREE.DoubleSide,
flatShading: true
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x4d7b49,
roughness: 1,
side: THREE.DoubleSide,
flatShading: true
}),
crop: new THREE.MeshStandardMaterial({
color: 0x638747,
roughness: 1,
flatShading: true
}),
cropLight: new THREE.MeshStandardMaterial({
color: 0x8aa354,
roughness: 1,
flatShading: true
}),
date: new THREE.MeshStandardMaterial({
color: 0x9a5b25,
roughness: 1,
flatShading: true
}),
black: new THREE.MeshStandardMaterial({
color: 0x273129,
roughness: 1
})
};
function addBox(
width,
height,
depth,
material,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
segments,
material,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addFlatPolygon(
radius,
segments,
material,
x,
y,
z,
scaleX = 1,
scaleZ = 1
) {
const mesh = new THREE.Mesh(
new THREE.CircleGeometry(radius, segments),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.scale.set(scaleX, scaleZ, 1);
mesh.position.set(x, y, z);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
let seed = 7419;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
// ---------------------------------------------------------------------
// Compact faceted plinth and distant Al Hajar-inspired mountain forms.
// ---------------------------------------------------------------------
const basePoints = [
[-6.25, -4.55],
[-5.75, -4.9],
[5.8, -4.78],
[6.28, -4.18],
[6.12, 4.5],
[5.55, 4.88],
[-5.72, 4.84],
[-6.3, 4.25]
];
function createPrism(points, depth, topMaterial, sideMaterial, y) {
const shape = new THREE.Shape();
points.forEach(([x, z], index) => {
if (index === 0) shape.moveTo(x, z);
else shape.lineTo(x, z);
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
steps: 1,
curveSegments: 1
});
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(
geometry,
[topMaterial, sideMaterial]
);
mesh.position.y = y;
mesh.receiveShadow = true;
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
createPrism(
basePoints,
0.62,
materials.sandSide,
materials.sandSide,
-0.7
);
createPrism(
basePoints,
0.08,
materials.sandTop,
materials.sandTop,
-0.08
);
const floor = addBox(
60,
0.15,
60,
materials.floor,
0,
-0.82,
0
);
floor.castShadow = false;
const mountainMaterials = [
new THREE.MeshStandardMaterial({
color: 0x817d70,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x938b78,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x716f68,
roughness: 1,
flatShading: true
})
];
for (let i = 0; i < 10; i++) {
const height = 2.8 + random() * 3.4;
const radius = 1.6 + random() * 2.3;
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 4 + (i % 2)),
mountainMaterials[i % mountainMaterials.length]
);
mountain.position.set(-10 + i * 2.25, -0.75 + height / 2, -10.5);
mountain.rotation.y = random() * Math.PI;
mountain.scale.x = 1.1 + random() * 0.8;
mountain.receiveShadow = true;
scene.add(mountain);
}
// ---------------------------------------------------------------------
// The wellhead: faceted stone ring with a south-facing outlet and timber
// lifting frame. Its water physically meets the descending spillway.
// ---------------------------------------------------------------------
const wellX = -4;
const wellZ = -3.25;
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
// Leave the +Z wedge open for the outlet.
if (i === 2) continue;
const stone = addBox(
0.54,
0.68,
0.24,
i % 2 ? materials.stone : materials.stoneLight,
wellX + Math.cos(angle) * 0.69,
0.37,
wellZ + Math.sin(angle) * 0.69
);
stone.rotation.y = Math.PI / 2 - angle;
const coping = addBox(
0.56,
0.16,
0.28,
i % 2 ? materials.stoneLight : materials.stone,
wellX + Math.cos(angle) * 0.69,
0.77,
wellZ + Math.sin(angle) * 0.69
);
coping.rotation.y = Math.PI / 2 - angle;
}
const wellWater = new THREE.Mesh(
new THREE.CircleGeometry(0.59, 18),
materials.wellWater
);
wellWater.rotation.x = -Math.PI / 2;
wellWater.position.set(wellX, 0.61, wellZ);
wellWater.receiveShadow = true;
scene.add(wellWater);
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xa8e4e5,
transparent: true,
opacity: 0.45,
depthWrite: false
});
const ripples = [];
for (let i = 0; i < 2; i++) {
const ripple = new THREE.Mesh(
new THREE.TorusGeometry(0.18 + i * 0.13, 0.012, 4, 24),
rippleMaterial.clone()
);
ripple.rotation.x = Math.PI / 2;
ripple.position.set(wellX, 0.625, wellZ);
scene.add(ripple);
ripples.push(ripple);
}
addBox(0.13, 1.65, 0.13, materials.wood, -4.62, 0.86, -3.55);
addBox(0.13, 1.65, 0.13, materials.wood, -4.28, 0.86, -3.55);
addBox(1.1, 0.14, 0.14, materials.wood, -4.45, 1.69, -3.55);
addBox(0.035, 0.78, 0.035, materials.wood, -4.18, 1.25, -3.55);
// ---------------------------------------------------------------------
// Continuous falaj network.
//
// Main:
// well outlet (-4,-2.05) -> (-4,-0.2) -> (1.2,-0.2)
//
// Branch A:
// (-2.2,-0.2) -> (-2.2,1.45) -> header -> two furrows
//
// Branch B:
// (1.2,-0.2) -> (1.2,1.45) -> header -> two furrows
// ---------------------------------------------------------------------
function addWaterSegment(
x1,
z1,
x2,
z2,
width = 0.32,
y = 0.066
) {
const horizontal = Math.abs(z2 - z1) < 0.0001;
const length = horizontal
? Math.abs(x2 - x1)
: Math.abs(z2 - z1);
addBox(
horizontal ? length : width + 0.13,
0.035,
horizontal ? width + 0.13 : length,
materials.channelBed,
(x1 + x2) / 2,
0.027,
(z1 + z2) / 2
);
addBox(
horizontal ? length : width,
0.022,
horizontal ? width : length,
materials.water,
(x1 + x2) / 2,
y,
(z1 + z2) / 2
);
}
function addCurb(
x1,
z1,
x2,
z2,
width = 0.11,
height = 0.17
) {
const horizontal = Math.abs(z2 - z1) < 0.0001;
const length = horizontal
? Math.abs(x2 - x1)
: Math.abs(z2 - z1);
addBox(
horizontal ? length : width,
height,
horizontal ? width : length,
materials.stoneLight,
(x1 + x2) / 2,
0.105,
(z1 + z2) / 2
);
}
function addRibbon(
a,
b,
width,
material,
thickness = 0.03
) {
const direction = new THREE.Vector3().subVectors(b, a);
const perpendicular = new THREE.Vector3(
-direction.z,
0,
direction.x
).normalize();
const aLeft = a.clone().addScaledVector(perpendicular, width / 2);
const aRight = a.clone().addScaledVector(perpendicular, -width / 2);
const bLeft = b.clone().addScaledVector(perpendicular, width / 2);
const bRight = b.clone().addScaledVector(perpendicular, -width / 2);
const vertices = [
aLeft.x, aLeft.y, aLeft.z,
aRight.x, aRight.y, aRight.z,
bLeft.x, bLeft.y, bLeft.z,
bRight.x, bRight.y, bRight.z,
aLeft.x, aLeft.y - thickness, aLeft.z,
aRight.x, aRight.y - thickness, aRight.z,
bLeft.x, bLeft.y - thickness, bLeft.z,
bRight.x, bRight.y - thickness, bRight.z
];
const indices = [
0, 1, 2,
1, 3, 2,
4, 6, 5,
5, 6, 7,
0, 4, 1,
1, 4, 5,
1, 5, 3,
3, 5, 7,
2, 6, 3,
3, 6, 7
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addBeamBetween(a, b, thickness, height, material) {
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const direction = b.clone().sub(a);
const length = direction.length();
const beam = new THREE.Mesh(
new THREE.BoxGeometry(thickness, height, length),
material
);
beam.position.copy(midpoint);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
beam.castShadow = true;
beam.receiveShadow = true;
scene.add(beam);
return beam;
}
// Sloping outlet from the elevated well water into the flat falaj.
const spillStart = new THREE.Vector3(wellX, 0.54, -2.61);
const spillEnd = new THREE.Vector3(wellX, 0.09, -2.06);
addRibbon(
spillStart.clone().add(new THREE.Vector3(0, -0.055, 0)),
spillEnd.clone().add(new THREE.Vector3(0, -0.055, 0)),
0.34,
materials.channelBed,
0.075
);
addRibbon(spillStart, spillEnd, 0.28, materials.water, 0.018);
for (const offset of [-0.19, 0.19]) {
addBeamBetween(
spillStart.clone().add(new THREE.Vector3(offset, 0.055, 0)),
spillEnd.clone().add(new THREE.Vector3(offset, 0.055, 0)),
0.09,
0.16,
materials.stoneLight
);
}
// Main and branch water surfaces.
addWaterSegment(-4, -2.08, -4, -0.2, 0.32, 0.066);
addWaterSegment(-4, -0.2, 1.2, -0.2, 0.32, 0.064);
addWaterSegment(-2.2, -0.2, -2.2, 1.45, 0.32, 0.068);
addWaterSegment(1.2, -0.2, 1.2, 1.45, 0.32, 0.068);
// Plot A and B header channels.
addWaterSegment(-3.65, 1.45, -0.75, 1.45, 0.28, 0.071);
addWaterSegment(0, 1.45, 2.8, 1.45, 0.28, 0.071);
// Narrow furrows remain visibly connected to the headers.
for (const x of [-3.1, -1.3, 0.45, 2.35]) {
addWaterSegment(x, 1.45, x, 3.3, 0.075, 0.073);
}
// Stone channel walls. Openings are deliberately left at every branch,
// corner, and furrow outlet so no curb interrupts the water route.
addCurb(-4.21, -2.29, -4.21, -0.42);
addCurb(-3.79, -2.29, -3.79, -0.42);
addCurb(-4.21, -0.41, 1.43, -0.41);
addCurb(-3.79, 0.01, -2.42, 0.01);
addCurb(-1.98, 0.01, 0.97, 0.01);
addCurb(-2.42, 0.01, -2.42, 1.28);
addCurb(-1.98, 0.01, -1.98, 1.28);
addCurb(0.97, 0.01, 0.97, 1.28);
addCurb(1.43, 0.01, 1.43, 1.28);
// Plot A header banks, with openings for the branch and furrows.
addCurb(-3.65, 1.29, -2.42, 1.29, 0.09);
addCurb(-1.98, 1.29, -0.75, 1.29, 0.09);
addCurb(-3.65, 1.61, -3.19, 1.61, 0.09);
addCurb(-3.01, 1.61, -1.39, 1.61, 0.09);
addCurb(-1.21, 1.61, -0.75, 1.61, 0.09);
// Plot B header banks.
addCurb(0, 1.29, 0.97, 1.29, 0.09);
addCurb(1.43, 1.29, 2.8, 1.29, 0.09);
addCurb(0, 1.61, 0.36, 1.61, 0.09);
addCurb(0.54, 1.61, 2.26, 1.61, 0.09);
addCurb(2.44, 1.61, 2.8, 1.61, 0.09);
// ---------------------------------------------------------------------
// Two raised, visibly irrigated planting plots.
// ---------------------------------------------------------------------
function createPlot(cx, cz, width, depth) {
addBox(
width,
0.11,
depth,
materials.soil,
cx,
0.055,
cz
);
const berm = 0.13;
const wallHeight = 0.17;
addBox(width + berm, wallHeight, berm, materials.soilLight,
cx, 0.1, cz - depth / 2 - berm / 2);
addBox(width + berm, wallHeight, berm, materials.soilLight,
cx, 0.1, cz + depth / 2 + berm / 2);
addBox(berm, wallHeight, depth, materials.soilLight,
cx - width / 2 - berm / 2, 0.1, cz);
addBox(berm, wallHeight, depth, materials.soilLight,
cx + width / 2 + berm / 2, 0.1, cz);
}
createPlot(-2.2, 2.72, 3.15, 2.02);
createPlot(1.35, 2.72, 3.15, 2.02);
// ---------------------------------------------------------------------
// Low-poly date palms.
// ---------------------------------------------------------------------
const frondGeometry = (() => {
const positions = [];
const indices = [];
const samples = [0, 0.25, 0.5, 0.75, 1];
for (const t of samples) {
const x = t * 1.55;
const y = Math.sin(t * Math.PI) * 0.3 - t * 0.24;
const w = Math.sin(t * Math.PI) * 0.21;
positions.push(
x, y, -w,
x, y + 0.04, 0,
x, y, w
);
}
for (let i = 0; i < samples.length - 1; i++) {
const a = i * 3;
const b = (i + 1) * 3;
indices.push(a, b, a + 1);
indices.push(b, b + 1, a + 1);
indices.push(a + 1, b + 1, b + 2);
indices.push(a + 1, b + 2, a + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
})();
const swayPalms = [];
function createPalm(x, z, height = 2.8, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.scale.setScalar(scale);
scene.add(group);
const segmentCount = 4;
const segmentHeight = height / segmentCount;
for (let i = 0; i < segmentCount; i++) {
const t = i / segmentCount;
const segment = addCylinder(
0.095 - t * 0.02,
0.13 - t * 0.02,
segmentHeight + 0.035,
6,
materials.trunk,
Math.sin(t * 1.6) * 0.07,
segmentHeight * (i + 0.5),
0,
group
);
segment.rotation.z = Math.sin(t * 2.0) * 0.025;
}
const crown = new THREE.Group();
crown.position.set(
Math.sin(1.6) * 0.07,
height,
0
);
group.add(crown);
for (let i = 0; i < 8; i++) {
const frond = new THREE.Mesh(
frondGeometry,
i % 2 ? materials.leafDark : materials.leafLight
);
frond.rotation.y = (i / 8) * Math.PI * 2 + 0.18;
frond.rotation.z = (random() - 0.5) * 0.15;
frond.scale.setScalar(0.88 + random() * 0.22);
frond.castShadow = true;
crown.add(frond);
}
const dateGeometry = new THREE.DodecahedronGeometry(0.075, 0);
for (let i = 0; i < 4; i++) {
const date = new THREE.Mesh(dateGeometry, materials.date);
date.position.set(
0.08 + random() * 0.11,
-0.13 - random() * 0.1,
-0.06 + random() * 0.12
);
date.castShadow = true;
crown.add(date);
}
swayPalms.push({
crown,
phase: random() * Math.PI * 2,
amount: 0.012 + random() * 0.012
});
}
const perimeterPalms = [
[-5.3, -3.75, 2.65, 1.05],
[-5.45, -1.85, 2.45, 0.92],
[-5.35, 0.35, 2.8, 1.02],
[-5.25, 2.35, 2.55, 0.95],
[-4.65, 3.95, 2.7, 1.0],
[-2.2, -4.05, 2.7, 0.96],
[1.25, -4.1, 2.65, 0.96],
[2.75, -4.05, 2.5, 0.9],
[4.25, -3.6, 2.75, 1.03],
[5.1, -2.25, 2.45, 0.95],
[5.25, -0.45, 2.7, 1.0],
[5.05, 1.85, 2.6, 0.95],
[4.45, 3.8, 2.7, 1.0]
];
perimeterPalms.forEach(([x, z, height, scale]) =>
createPalm(x, z, height, scale)
);
// ---------------------------------------------------------------------
// Crop rows and small date-palm planting inside each plot.
// ---------------------------------------------------------------------
function createVegetable(x, z, alternate = false) {
const group = new THREE.Group();
group.position.set(x, 0.12, z);
scene.add(group);
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 0),
alternate ? materials.cropLight : materials.crop
);
core.scale.set(1, 0.7, 1);
core.castShadow = true;
group.add(core);
for (let i = 0; i < 4; i++) {
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(0.09, 0.29, 4),
i % 2 ? materials.cropLight : materials.crop
);
leaf.position.set(
Math.cos((i / 4) * Math.PI * 2) * 0.09,
0.13,
Math.sin((i / 4) * Math.PI * 2) * 0.09
);
leaf.rotation.z = Math.cos((i / 4) * Math.PI * 2) * 0.42;
leaf.rotation.x = Math.sin((i / 4) * Math.PI * 2) * 0.42;
leaf.castShadow = true;
group.add(leaf);
}
}
const plotAX = [-3.48, -2.82, -2.2, -1.58, -0.98];
const plotAZ = [2.15, 2.72, 3.22];
plotAX.forEach((x, xi) => {
plotAZ.forEach((z, zi) => {
createVegetable(x, z, (xi + zi) % 2 === 0);
});
});
const plotBX = [0.23, 0.72, 1.2, 1.68, 2.47];
const plotBZ = [2.15, 2.72, 3.2];
plotBX.forEach((x, xi) => {
plotBZ.forEach((z, zi) => {
createVegetable(x, z, (xi + zi) % 2 !== 0);
});
});
createPalm(-3.55, 3.42, 1.45, 0.55);
createPalm(-0.88, 3.42, 1.4, 0.53);
createPalm(0.28, 3.42, 1.5, 0.56);
createPalm(2.52, 3.42, 1.43, 0.54);
// ---------------------------------------------------------------------
// Al Ain-inspired mud-brick watchtower and small settlement elements.
// ---------------------------------------------------------------------
function createWatchtower(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
scene.add(group);
addBox(1.18, 1.65, 1.18, materials.mud, 0, 0.825, 0, group);
addBox(1.02, 0.48, 1.02, materials.mudDark, 0, 1.92, 0, group);
// Horizontal brick bands.
for (let i = 0; i < 3; i++) {
addBox(
1.205,
0.055,
1.205,
materials.mudDark,
0,
0.4 + i * 0.43,
0,
group
);
}
// Crenellations.
for (const dx of [-0.38, 0, 0.38]) {
addBox(0.25, 0.3, 0.25, materials.mud, dx, 2.29, -0.38, group);
addBox(0.25, 0.3, 0.25, materials.mud, dx, 2.29, 0.38, group);
}
for (const dz of [-0.38, 0.38]) {
addBox(0.25, 0.3, 0.25, materials.mud, -0.38, 2.29, dz, group);
addBox(0.25, 0.3, 0.25, materials.mud, 0.38, 2.29, dz, group);
}
// Door and shaded opening.
addBox(0.34, 0.61, 0.025, materials.black, 0, 0.33, 0.602, group);
addBox(0.18, 0.26, 0.026, materials.black, 0, 1.57, 0.604, group);
}
createWatchtower(-0.25, -3.85);
function createMudHouse(x, z, w, d, h) {
addBox(w, h, d, materials.mud, x, h / 2, z);
addBox(w + 0.12, 0.14, d + 0.12, materials.mudDark, x, h, z);
addBox(0.3, 0.52, 0.025, materials.black, x, 0.27, z + d / 2 + 0.015);
for (let i = 0; i < 2; i++) {
addBox(
w + 0.14,
0.04,
d + 0.14,
materials.mudDark,
x,
0.25 + i * 0.3,
z
);
}
}
createMudHouse(3.55, -3.75, 1.2, 1.05, 0.78);
createMudHouse(4.55, -3.55, 0.9, 1.1, 0.62);
createMudHouse(4.25, -2.55, 1.35, 0.95, 0.84);
// ---------------------------------------------------------------------
// Small stones, low shrubs, and ground variation.
// ---------------------------------------------------------------------
const stoneGeometry = new THREE.DodecahedronGeometry(0.1, 0);
const shrubGeometry = new THREE.IcosahedronGeometry(0.18, 0);
function isCoreArea(x, z) {
return (
(x > -4.9 && x < 5.3 && z > -3.8 && z < 3.9) &&
!(
(x < -3.55 && z > 1.7) ||
(x > -0.65 && z > 1.7)
)
);
}
for (let i = 0; i < 58; i++) {
const x = -5.8 + random() * 11.6;
const z = -4.5 + random() * 9;
if (isCoreArea(x, z)) continue;
const stone = new THREE.Mesh(stoneGeometry, materials.stone);
stone.position.set(x, 0.075, z);
stone.scale.set(
0.7 + random() * 1.6,
0.45 + random() * 0.8,
0.7 + random() * 1.4
);
stone.rotation.set(random(), random(), random());
stone.castShadow = true;
scene.add(stone);
}
for (let i = 0; i < 22; i++) {
const x = -5.8 + random() * 11.6;
const z = -4.45 + random() * 8.9;
if (isCoreArea(x, z)) continue;
const shrub = new THREE.Mesh(
shrubGeometry,
i % 3 ? materials.leafDark : materials.leafLight
);
shrub.position.set(x, 0.17, z);
shrub.scale.set(
0.7 + random(),
0.55 + random() * 0.8,
0.7 + random()
);
shrub.rotation.y = random() * Math.PI;
shrub.castShadow = true;
scene.add(shrub);
}
// ---------------------------------------------------------------------
// Flow markers follow the exact same connected paths as the water.
// ---------------------------------------------------------------------
const flowMaterial = new THREE.MeshBasicMaterial({
color: 0xb6f1ef
});
const flowGeometry = new THREE.BoxGeometry(0.12, 0.018, 0.05);
const flowMeshes = [];
const routes = [];
function createFlowRoute(points, count) {
const routePoints = points.map(([x, y, z]) => new THREE.Vector3(x, y, z));
const lengths = [];
let total = 0;
for (let i = 0; i < routePoints.length - 1; i++) {
const length = routePoints[i].distanceTo(routePoints[i + 1]);
lengths.push(length);
total += length;
}
const route = {
points: routePoints,
lengths,
total
};
routes.push(route);
for (let i = 0; i < count; i++) {
const mesh = new THREE.Mesh(flowGeometry, flowMaterial);
mesh.castShadow = false;
scene.add(mesh);
flowMeshes.push({
mesh,
route,
offset: (i / count) * route.total + random() * 0.25
});
}
}
const commonSupply = [
[-4, 0.5, -2.6],
[-4, 0.1, -2.06],
[-4, 0.09, -0.2]
];
createFlowRoute(
[
...commonSupply,
[-2.2, 0.09, -0.2],
[-2.2, 0.09, 1.45],
[-3.1, 0.09, 1.45],
[-3.1, 0.09, 3.25]
],
3
);
createFlowRoute(
[
...commonSupply,
[-2.2, 0.09, -0.2],
[-2.2, 0.09, 1.45],
[-1.3, 0.09, 1.45],
[-1.3, 0.09, 3.25]
],
3
);
createFlowRoute(
[
...commonSupply,
[1.2, 0.09, -0.2],
[1.2, 0.09, 1.45],
[0.45, 0.09, 1.45],
[0.45, 0.09, 3.25]
],
3
);
createFlowRoute(
[
...commonSupply,
[1.2, 0.09, -0.2],
[1.2, 0.09, 1.45],
[2.35, 0.09, 1.45],
[2.35, 0.09, 3.25]
],
3
);
function sampleRoute(route, distance) {
let remaining = distance;
for (let i = 0; i < route.lengths.length; i++) {
const length = route.lengths[i];
if (remaining <= length || i === route.lengths.length - 1) {
const t = length === 0 ? 0 : remaining / length;
const start = route.points[i];
const end = route.points[i + 1];
const position = start.clone().lerp(end, Math.min(1, t));
const direction = end.clone().sub(start).normalize();
return { position, direction };
}
remaining -= length;
}
return {
position: route.points[0].clone(),
direction: new THREE.Vector3(1, 0, 0)
};
}
// ---------------------------------------------------------------------
// Projected labels.
// ---------------------------------------------------------------------
const labels = [];
function addLabel(text, position, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(...position)
});
}
addLabel("Stone wellhead", [-4, 1.75, -3.25]);
addLabel("Main falaj", [-0.15, 0.45, -0.2]);
addLabel("Palm & herb plot", [-2.2, 0.85, 2.65]);
addLabel("Date-palm plot", [1.35, 0.85, 2.65]);
addLabel("Al Ain watchtower", [-0.25, 2.75, -3.85], "land");
let labelsVisible = true;
function updateLabels() {
const width = innerWidth;
const height = innerHeight;
labels.forEach((label) => {
const projected = label.position.clone().project(camera);
const visible =
labelsVisible &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
label.element.style.display = visible ? "block" : "none";
if (visible) {
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
label.element.style.opacity = String(
THREE.MathUtils.clamp(1 - (projected.z - 0.72) * 1.7, 0.12, 1)
);
}
});
}
// ---------------------------------------------------------------------
// Direct camera controls: no external controls addon is used.
// ---------------------------------------------------------------------
const orbit = {
theta: 0.72,
phi: 0.82,
radius: innerWidth < 700 ? 17 : 14.7
};
const desiredOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
const cameraTarget = new THREE.Vector3(0, 0.65, 0.2);
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = { x: event.clientX, y: event.clientY };
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
desiredOrbit.theta -= dx * 0.006;
desiredOrbit.phi = THREE.MathUtils.clamp(
desiredOrbit.phi - dy * 0.005,
0.34,
1.35
);
} else if (pointers.size >= 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius * (previousPinchDistance / distance),
8.5,
23
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius * Math.exp(event.deltaY * 0.001),
8.5,
23
);
},
{ passive: false }
);
addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") desiredOrbit.theta += 0.08;
if (event.key === "ArrowRight") desiredOrbit.theta -= 0.08;
if (event.key === "ArrowUp") {
desiredOrbit.phi = Math.max(0.34, desiredOrbit.phi - 0.06);
}
if (event.key === "ArrowDown") {
desiredOrbit.phi = Math.min(1.35, desiredOrbit.phi + 0.06);
}
if (event.key === "+" || event.key === "=") {
desiredOrbit.radius = Math.max(8.5, desiredOrbit.radius - 0.6);
}
if (event.key === "-" || event.key === "_") {
desiredOrbit.radius = Math.min(23, desiredOrbit.radius + 0.6);
}
});
document.getElementById("reset-view").addEventListener("click", () => {
desiredOrbit.theta = 0.72;
desiredOrbit.phi = 0.82;
desiredOrbit.radius = innerWidth < 700 ? 17 : 14.7;
});
const labelsButton = document.getElementById("toggle-labels");
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsButton.textContent = labelsVisible ? "Labels on" : "Labels off";
labelsButton.setAttribute("aria-pressed", String(labelsVisible));
});
const flowButton = document.getElementById("toggle-flow");
let flowVisible = true;
flowButton.addEventListener("click", () => {
flowVisible = !flowVisible;
flowMeshes.forEach(({ mesh }) => {
mesh.visible = flowVisible;
});
flowButton.textContent = flowVisible ? "Flow on" : "Flow off";
flowButton.setAttribute("aria-pressed", String(flowVisible));
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// ---------------------------------------------------------------------
// Animation.
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
orbit.theta += (desiredOrbit.theta - orbit.theta) * 0.12;
orbit.phi += (desiredOrbit.phi - orbit.phi) * 0.12;
orbit.radius += (desiredOrbit.radius - orbit.radius) * 0.12;
updateCamera();
flowMeshes.forEach(({ mesh, route, offset }) => {
const distance = (elapsed * 1.12 + offset) % route.total;
const sample = sampleRoute(route, distance);
mesh.position.copy(sample.position);
mesh.rotation.y = -Math.atan2(
sample.direction.z,
sample.direction.x
);
});
ripples.forEach((ripple, index) => {
const phase = (elapsed * 0.42 + index * 0.5) % 1;
ripple.scale.setScalar(0.72 + phase * 0.65);
ripple.material.opacity = 0.42 * (1 - phase);
});
swayPalms.forEach(({ crown, phase, amount }) => {
crown.rotation.z = Math.sin(elapsed * 1.05 + phase) * amount;
crown.rotation.x = Math.cos(elapsed * 0.83 + phase) * amount * 0.55;
});
materials.water.emissiveIntensity =
0.29 + Math.sin(elapsed * 1.5) * 0.035;
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```