Prompt specification
Build or customize the Three.js 3D scene "Saharan oasis settlement and desert margin" 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: Saharan oasis settlement and desert margin
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/saharan-oasis-settlement-and-desert-margin-x3115
Scene Description Prompt:
A low-poly Saharan oasis combines cultivated land, compact settlement, water distribution, and surrounding desert. Build standalone HTML with Three.js from cdnjs.
Working Three.js Starter (saharan-oasis-settlement-and-desert-margin-x3115):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Saharan Oasis — Low-Poly Study</title>
<style>
:root {
--ink: #2b241b;
--paper: #fff4dc;
--water: #2f9da0;
--leaf: #647643;
--adobe: #c98754;
--sand: #d9ad68;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 28% 18%, rgba(255, 239, 190, 0.96), transparent 30%),
linear-gradient(180deg, #efd39b 0%, #e8b86f 48%, #c9804c 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 44%, rgba(83, 43, 22, 0.14) 100%),
linear-gradient(180deg, rgba(255,255,255,0.06), transparent 30%);
z-index: 2;
}
.ui {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.masthead {
position: absolute;
top: clamp(20px, 4vw, 42px);
left: clamp(20px, 4vw, 48px);
max-width: 390px;
text-shadow: 0 1px 12px rgba(255, 238, 198, 0.6);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: rgba(55, 42, 29, 0.72);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 26px;
height: 2px;
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 76px);
font-weight: 500;
line-height: 0.9;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 330px;
margin: 15px 0 0;
color: rgba(55, 42, 29, 0.76);
font-size: 12px;
line-height: 1.6;
}
.study-badge {
position: absolute;
top: clamp(20px, 4vw, 42px);
right: clamp(20px, 4vw, 48px);
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid rgba(65, 46, 29, 0.22);
border-radius: 999px;
background: rgba(255, 244, 220, 0.34);
backdrop-filter: blur(8px);
color: rgba(55, 42, 29, 0.72);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.study-badge span {
width: 6px;
height: 6px;
border-radius: 50%;
background: #547852;
box-shadow: 0 0 0 4px rgba(84, 120, 82, 0.14);
}
.legend {
position: absolute;
left: clamp(20px, 4vw, 48px);
bottom: clamp(20px, 4vw, 42px);
padding: 14px 16px;
border: 1px solid rgba(65, 46, 29, 0.18);
border-radius: 12px;
background: rgba(255, 244, 220, 0.4);
backdrop-filter: blur(9px);
box-shadow: 0 10px 30px rgba(78, 43, 20, 0.08);
}
.legend-title {
margin-bottom: 10px;
color: rgba(55, 42, 29, 0.56);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.legend-items {
display: flex;
gap: 16px;
flex-wrap: wrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
font-size: 10px;
font-weight: 650;
color: rgba(55, 42, 29, 0.8);
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.controls {
position: absolute;
right: clamp(20px, 4vw, 48px);
bottom: clamp(20px, 4vw, 42px);
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.hint {
margin-right: 6px;
color: rgba(55, 42, 29, 0.66);
font-size: 10px;
font-weight: 600;
letter-spacing: 0.02em;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(65, 46, 29, 0.2);
border-radius: 999px;
background: rgba(255, 244, 220, 0.62);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
cursor: pointer;
backdrop-filter: blur(10px);
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
transform: translateY(-2px);
background: rgba(255, 248, 229, 0.88);
}
button.active {
background: var(--ink);
color: var(--paper);
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
transition: opacity 180ms ease;
}
body.labels-off #labels {
opacity: 0;
}
.pin {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
transform: translate(-4px, -4px);
will-change: transform;
}
.pin-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border: 2px solid rgba(255, 248, 225, 0.9);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 10px rgba(48, 31, 16, 0.28);
}
.pin-tag {
padding: 6px 9px;
border: 1px solid rgba(255, 244, 220, 0.24);
border-radius: 5px;
background: rgba(43, 36, 27, 0.77);
color: #fff1d0;
box-shadow: 0 5px 16px rgba(48, 31, 16, 0.14);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
white-space: nowrap;
text-transform: uppercase;
backdrop-filter: blur(5px);
}
@media (max-width: 720px) {
.masthead {
top: 20px;
left: 20px;
}
h1 {
font-size: 42px;
}
.subtitle,
.study-badge,
.legend,
.hint {
display: none;
}
.controls {
right: 16px;
bottom: 16px;
}
button {
min-height: 36px;
padding: 0 12px;
}
.pin-tag {
font-size: 7px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly Saharan oasis"></canvas>
<div class="vignette"></div>
<div id="labels" aria-hidden="true">
<div class="pin" id="pin-fields"><span class="pin-dot"></span><span class="pin-tag">01 · Cultivated terraces</span></div>
<div class="pin" id="pin-spring"><span class="pin-dot"></span><span class="pin-tag">02 · Natural spring</span></div>
<div class="pin" id="pin-village"><span class="pin-dot"></span><span class="pin-tag">03 · Adobe settlement</span></div>
<div class="pin" id="pin-palms"><span class="pin-dot"></span><span class="pin-tag">04 · Date grove</span></div>
</div>
<main class="ui">
<header class="masthead">
<div class="eyebrow">Procedural landscape · No. 01</div>
<h1>Saharan<br />Oasis</h1>
<p class="subtitle">
A compact study of water, shade, cultivation and settlement at the edge of the desert.
</p>
</header>
<div class="study-badge"><span></span> Low-poly field study</div>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Landscape elements</div>
<div class="legend-items">
<div class="legend-item"><i class="swatch" style="background:#647643"></i> Cultivation</div>
<div class="legend-item"><i class="swatch" style="background:#2f9da0"></i> Water</div>
<div class="legend-item"><i class="swatch" style="background:#c98754"></i> Settlement</div>
<div class="legend-item"><i class="swatch" style="background:#d9ad68"></i> Desert</div>
</div>
</aside>
<nav class="controls" aria-label="Scene controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
<button id="toggle-labels" class="active" type="button" aria-pressed="true">Labels</button>
<button id="toggle-orbit" type="button" aria-pressed="false">Auto orbit</button>
</nav>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe5b875, 52, 118);
const camera = new THREE.PerspectiveCamera(
window.innerWidth < 720 ? 52 : 40,
window.innerWidth / window.innerHeight,
0.1,
180
);
let seed = 74129;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const smooth = (value, min, max) => {
const t = THREE.MathUtils.clamp((value - min) / (max - min), 0, 1);
return t * t * (3 - 2 * t);
};
const palette = {
sand: 0xd9a960,
paleSand: 0xe8c783,
darkSand: 0xb87b47,
earth: 0x95613e,
adobe: 0xc98a58,
adobeLight: 0xdda776,
adobeDark: 0xae7048,
leaf: 0x5f7540,
leafLight: 0x78894a,
leafDark: 0x40583a,
trunk: 0x8b613c,
water: 0x2f9da0,
deepWater: 0x237b7d,
stone: 0xa8875f,
dark: 0x3c3027
};
const mat = (color, extra = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
flatShading: true,
...extra
});
const sandMaterial = mat(palette.sand);
const darkSandMaterial = mat(palette.darkSand);
const stoneMaterial = mat(palette.stone);
const earthMaterial = mat(palette.earth);
const woodMaterial = mat(palette.trunk);
const darkMaterial = mat(palette.dark);
const leafMaterial = mat(palette.leaf, { side: THREE.DoubleSide });
const leafLightMaterial = mat(palette.leafLight, { side: THREE.DoubleSide });
const leafDarkMaterial = mat(palette.leafDark, { side: THREE.DoubleSide });
const hemi = new THREE.HemisphereLight(0xffe8b6, 0x875333, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0c2, 3.25);
sun.position.set(-24, 34, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const warmFill = new THREE.DirectionalLight(0xe89451, 0.75);
warmFill.position.set(28, 12, -24);
scene.add(warmFill);
// Surrounding desert floor.
const desertFloor = new THREE.Mesh(
new THREE.PlaneGeometry(220, 220),
mat(0xd19b5b)
);
desertFloor.rotation.x = -Math.PI / 2;
desertFloor.position.y = -1.49;
desertFloor.receiveShadow = true;
scene.add(desertFloor);
// Low-poly elliptical terrain generated as an indexed polar grid.
function terrainHeight(x, z) {
const r = Math.sqrt((x / 28) ** 2 + (z / 21) ** 2);
const duneBand = smooth(r, 0.68, 0.81) * (1 - smooth(r, 0.9, 1.02));
const wave = 0.58 + 0.22 * Math.sin(x * 0.23 + z * 0.08) + 0.12 * Math.cos(z * 0.31);
const moundA = Math.exp(-(((x + 20) / 6.2) ** 2 + ((z + 10) / 4.1) ** 2)) * 1.45;
const moundB = Math.exp(-(((x - 22) / 5.7) ** 2 + ((z + 12) / 3.8) ** 2)) * 1.2;
const moundC = Math.exp(-(((x + 9) / 7.5) ** 2 + ((z - 17) / 3.2) ** 2)) * 0.95;
return 0.14 + duneBand * wave + (moundA + moundB + moundC) * smooth(r, 0.66, 0.88);
}
function createTerrain() {
const rings = 19;
const segments = 64;
const positions = [0, terrainHeight(0, 0), 0];
const indices = [];
for (let ring = 1; ring <= rings; ring++) {
const t = ring / rings;
for (let segment = 0; segment < segments; segment++) {
const angle = (segment / segments) * Math.PI * 2;
const irregularity =
1 +
(0.027 * Math.sin(angle * 5 + 0.4) +
0.018 * Math.cos(angle * 3 - 0.7) +
0.01 * Math.sin(angle * 9)) * t ** 3;
const x = Math.cos(angle) * 28 * t * irregularity;
const z = Math.sin(angle) * 21 * t * irregularity;
positions.push(x, terrainHeight(x, z), z);
}
}
for (let segment = 0; segment < segments; segment++) {
const next = (segment + 1) % segments;
indices.push(0, 1 + next, 1 + segment);
}
for (let ring = 1; ring < rings; ring++) {
const innerStart = 1 + (ring - 1) * segments;
const outerStart = 1 + ring * segments;
for (let segment = 0; segment < segments; segment++) {
const next = (segment + 1) % segments;
const a = innerStart + segment;
const b = innerStart + next;
const c = outerStart + segment;
const d = outerStart + next;
indices.push(a, b, c, b, d, c);
}
}
const indexed = new THREE.BufferGeometry();
indexed.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
indexed.setIndex(indices);
indexed.computeVertexNormals();
const geometry = indexed.toNonIndexed();
const flatPositions = geometry.getAttribute("position");
const colors = [];
const lowColor = new THREE.Color(0xca8d50);
const highColor = new THREE.Color(0xedca83);
for (let i = 0; i < flatPositions.count; i += 3) {
const height =
(flatPositions.getY(i) +
flatPositions.getY(i + 1) +
flatPositions.getY(i + 2)) / 3;
const color = lowColor.clone().lerp(highColor, smooth(height, 0.15, 1.65));
color.offsetHSL((random() - 0.5) * 0.018, (random() - 0.5) * 0.05, (random() - 0.5) * 0.055);
for (let j = 0; j < 3; j++) colors.push(color.r, color.g, color.b);
}
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
mesh.castShadow = true;
scene.add(mesh);
}
createTerrain();
const terrainBase = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1.5, 64),
mat(0xb87b46)
);
terrainBase.scale.set(28, 1, 21);
terrainBase.position.y = -0.72;
terrainBase.receiveShadow = true;
scene.add(terrainBase);
// Distant faceted dunes.
const duneMaterials = [mat(0xd9a45f), mat(0xe0b06c), mat(0xc98b50)];
const duneData = [
[-43, -25, 11, 4.6, 6],
[42, -31, 13, 5.8, 7],
[47, 22, 10, 4.4, 6],
[-37, 29, 12, 5.3, 7],
[-50, 7, 8, 3.8, 5],
[18, -43, 10, 4.2, 6],
[-15, 43, 9, 3.7, 5],
[53, -4, 8, 3.5, 5]
];
duneData.forEach(([x, z, sx, sy, sz], index) => {
const dune = new THREE.Mesh(
new THREE.SphereGeometry(1, 9, 5),
duneMaterials[index % duneMaterials.length]
);
dune.position.set(x, -1.46 + sy * 0.18, z);
dune.scale.set(sx, sy, sz);
dune.rotation.y = random() * Math.PI;
dune.receiveShadow = true;
scene.add(dune);
});
function addRock(x, y, z, scale, material = stoneMaterial) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(1, 0),
material
);
rock.position.set(x, y, z);
rock.scale.set(
scale * (0.8 + random() * 0.5),
scale * (0.55 + random() * 0.45),
scale * (0.75 + random() * 0.5)
);
rock.rotation.set(random(), random() * Math.PI, random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
return rock;
}
[
[-22, -1.05, -15, 1.2],
[24, -1.0, 14, 1.45],
[-29, -1.15, 8, 0.9],
[31, -1.1, -13, 1.1],
[-5, -1.05, -19, 0.65],
[12, -1.1, 20, 0.8]
].forEach(args => addRock(...args));
// Irregular spring and dark shoreline.
const poolPoints = [
[-4.6, -1.8],
[-2.5, -4.1],
[1.7, -4.8],
[5.0, -3.1],
[7.1, 0.1],
[5.8, 3.7],
[2.4, 5.2],
[-2.1, 4.6],
[-5.1, 1.9]
];
function scalePolygon(points, scale, centerX = 1, centerZ = 0) {
return points.map(([x, z]) => [
centerX + (x - centerX) * scale,
centerZ + (z - centerZ) * scale
]);
}
function polygonMesh(points, height, material) {
const shape = new THREE.Shape();
shape.moveTo(points[0][0], -points[0][1]);
points.slice(1).forEach(([x, z]) => shape.lineTo(x, -z));
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape);
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = height;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
polygonMesh(scalePolygon(poolPoints, 1.15), 0.17, mat(0xa67a49));
const waterMaterial = new THREE.MeshStandardMaterial({
color: palette.water,
roughness: 0.22,
metalness: 0.06,
transparent: true,
opacity: 0.9,
flatShading: true
});
const water = polygonMesh(poolPoints, 0.235, waterMaterial);
const deepWater = polygonMesh(scalePolygon(poolPoints, 0.78), 0.239, new THREE.MeshStandardMaterial({
color: palette.deepWater,
roughness: 0.32,
transparent: true,
opacity: 0.28,
flatShading: true
}));
// Stones around the waterline.
for (let i = 0; i < poolPoints.length; i++) {
const a = poolPoints[i];
const b = poolPoints[(i + 1) % poolPoints.length];
for (let j = 0; j < 3; j++) {
const t = (j + 0.2 + random() * 0.55) / 3;
const x = THREE.MathUtils.lerp(a[0], b[0], t);
const z = THREE.MathUtils.lerp(a[1], b[1], t);
const rock = addRock(x, 0.24, z, 0.22 + random() * 0.25, stoneMaterial);
rock.scale.y *= 0.72;
}
}
// Water highlights.
const shimmerMaterial = new THREE.MeshBasicMaterial({
color: 0xc9f0df,
transparent: true,
opacity: 0.18,
depthWrite: false,
side: THREE.DoubleSide
});
const shimmerPieces = [];
for (let i = 0; i < 12; i++) {
const shimmer = new THREE.Mesh(new THREE.CircleGeometry(0.12 + random() * 0.16, 6), shimmerMaterial.clone());
shimmer.rotation.x = -Math.PI / 2;
shimmer.rotation.z = random() * Math.PI;
shimmer.position.set(-2 + random() * 6, 0.248, -3 + random() * 6);
shimmer.userData.phase = random() * Math.PI * 2;
shimmer.userData.baseX = shimmer.position.x;
shimmer.userData.baseZ = shimmer.position.z;
scene.add(shimmer);
shimmerPieces.push(shimmer);
}
// Irrigation channels.
function channel(x1, z1, x2, z2, width = 0.38) {
const length = Math.hypot(x2 - x1, z2 - z1);
const angle = Math.atan2(x2 - x1, z2 - z1);
const middleX = (x1 + x2) / 2;
const middleZ = (z1 + z2) / 2;
const bed = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.24, 0.12, length),
earthMaterial
);
bed.position.set(middleX, 0.22, middleZ);
bed.rotation.y = angle;
bed.receiveShadow = true;
scene.add(bed);
const waterStrip = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.055, length),
waterMaterial
);
waterStrip.position.set(middleX, 0.295, middleZ);
waterStrip.rotation.y = angle;
scene.add(waterStrip);
const bankGeometry = new THREE.BoxGeometry(0.09, 0.13, length);
const perpendicularX = Math.cos(angle) * (width / 2 + 0.13);
const perpendicularZ = -Math.sin(angle) * (width / 2 + 0.13);
[-1, 1].forEach(side => {
const bank = new THREE.Mesh(bankGeometry, stoneMaterial);
bank.position.set(
middleX + perpendicularX * side,
0.25,
middleZ + perpendicularZ * side
);
bank.rotation.y = angle;
bank.castShadow = true;
bank.receiveShadow = true;
scene.add(bank);
});
}
channel(-4.8, 0.4, -7.4, 0.4);
channel(-7.4, 0.4, -7.4, -5.1);
channel(-7.4, 0.4, -7.4, 5.1);
channel(-7.4, -5.1, -6.6, -5.1);
channel(-7.4, 5.1, -6.6, 5.1);
channel(-7.4, 0.4, -18.4, 0.4, 0.3);
// Cultivated plots.
const cropGeometry = new THREE.ConeGeometry(0.16, 0.5, 5);
cropGeometry.translate(0, 0.25, 0);
function addField(cx, cz, width, depth, rotation = 0) {
const group = new THREE.Group();
group.position.set(cx, 0, cz);
group.rotation.y = rotation;
scene.add(group);
const soil = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.2, depth),
earthMaterial
);
soil.position.y = 0.24;
soil.receiveShadow = true;
group.add(soil);
const bermGeometryX = new THREE.BoxGeometry(width + 0.4, 0.16, 0.22);
const bermGeometryZ = new THREE.BoxGeometry(0.22, 0.16, depth + 0.4);
[1, -1].forEach(side => {
const bermX = new THREE.Mesh(bermGeometryX, darkSandMaterial);
bermX.position.set(0, 0.26, side * (depth / 2 + 0.1));
bermX.castShadow = true;
bermX.receiveShadow = true;
group.add(bermX);
const bermZ = new THREE.Mesh(bermGeometryZ, darkSandMaterial);
bermZ.position.set(side * (width / 2 + 0.1), 0.26, 0);
bermZ.castShadow = true;
bermZ.receiveShadow = true;
group.add(bermZ);
});
const rowCount = Math.floor((width - 0.7) / 0.62);
const plantsPerRow = Math.floor((depth - 0.55) / 0.55);
const crops = new THREE.InstancedMesh(cropGeometry, leafMaterial, rowCount * plantsPerRow);
crops.castShadow = true;
crops.receiveShadow = true;
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const position = new THREE.Vector3();
const scale = new THREE.Vector3();
const cropColor = new THREE.Color();
let instance = 0;
for (let row = 0; row < rowCount; row++) {
const x = -width / 2 + 0.62 + row * 0.62;
const furrow = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.035, depth - 0.65),
darkSandMaterial
);
furrow.position.set(x, 0.355, 0);
group.add(furrow);
for (let plant = 0; plant < plantsPerRow; plant++) {
const z = -depth / 2 + 0.48 + plant * 0.55 + (random() - 0.5) * 0.12;
position.set(
x + (random() - 0.5) * 0.12,
0.35,
z + (random() - 0.5) * 0.08
);
quaternion.setFromEuler(new THREE.Euler(0, random() * Math.PI, (random() - 0.5) * 0.12));
const s = 0.75 + random() * 0.55;
scale.set(s, s * (0.9 + random() * 0.35), s);
matrix.compose(position, quaternion, scale);
crops.setMatrixAt(instance, matrix);
cropColor.setHSL(0.22 + random() * 0.025, 0.27 + random() * 0.12, 0.31 + random() * 0.11);
crops.setColorAt(instance, cropColor);
instance++;
}
}
crops.instanceMatrix.needsUpdate = true;
if (crops.instanceColor) crops.instanceColor.needsUpdate = true;
group.add(crops);
}
addField(-11.8, -5.4, 9.1, 6.5, -0.035);
addField(-11.5, 5.4, 8.8, 6.4, 0.025);
addField(-21.1, 0.1, 4.5, 9.2, 0.02);
// Adobe village platform and paths.
const villagePlatform = new THREE.Mesh(
new THREE.BoxGeometry(14.3, 0.13, 17.7),
mat(0xd5a66d)
);
villagePlatform.position.set(14.1, 0.22, 0);
villagePlatform.receiveShadow = true;
scene.add(villagePlatform);
const pathMaterial = mat(0xc89a61);
const path = new THREE.Mesh(new THREE.BoxGeometry(7.3, 0.055, 2.0), pathMaterial);
path.position.set(7.8, 0.205, 2.7);
path.receiveShadow = true;
scene.add(path);
const villageRoad = new THREE.Mesh(new THREE.BoxGeometry(1.8, 0.055, 14.4), pathMaterial);
villageRoad.position.set(13.2, 0.205, 0);
villageRoad.receiveShadow = true;
scene.add(villageRoad);
const adobeMaterials = [
mat(palette.adobe),
mat(palette.adobeLight),
mat(palette.adobeDark),
mat(0xc27d4f)
];
function addWaterJar(x, y, z, scale = 1) {
const jar = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.34, 0.65, 8),
mat(0x9c5f3e)
);
body.position.y = 0.325;
body.castShadow = true;
jar.add(body);
const rim = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.12, 8),
mat(0x77452f)
);
rim.position.y = 0.69;
rim.castShadow = true;
jar.add(rim);
jar.position.set(x, y, z);
jar.scale.setScalar(scale);
scene.add(jar);
}
function addHouse(x, z, width, depth, height, options = {}) {
const group = new THREE.Group();
group.position.set(x, 0.25, z);
scene.add(group);
const wallMaterial = options.material || adobeMaterials[Math.floor(random() * adobeMaterials.length)];
const walls = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
wallMaterial
);
walls.position.y = height / 2;
walls.castShadow = true;
walls.receiveShadow = true;
group.add(walls);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.24, 0.18, depth + 0.24),
mat(options.roofColor || 0xb98257)
);
roof.position.y = height + 0.08;
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
if (options.dome) {
const dome = new THREE.Mesh(
new THREE.SphereGeometry(width * 0.31, 10, 4, 0, Math.PI * 2, 0, Math.PI / 2),
mat(0xc78a5b)
);
dome.position.y = height + 0.16;
dome.castShadow = true;
group.add(dome);
const finial = new THREE.Mesh(
new THREE.ConeGeometry(0.08, 0.38, 5),
darkSandMaterial
);
finial.position.y = height + width * 0.31 + 0.38;
group.add(finial);
} else {
const parapetHeight = 0.34;
const parapetY = height + 0.33;
const frontBackGeometry = new THREE.BoxGeometry(width + 0.22, parapetHeight, 0.18);
[-1, 1].forEach(side => {
const parapet = new THREE.Mesh(frontBackGeometry, wallMaterial);
parapet.position.set(0, parapetY, side * (depth / 2 + 0.02));
parapet.castShadow = true;
group.add(parapet);
});
const sideGeometry = new THREE.BoxGeometry(0.18, parapetHeight, depth - 0.2);
[-1, 1].forEach(side => {
const parapet = new THREE.Mesh(sideGeometry, wallMaterial);
parapet.position.set(side * (width / 2 + 0.02), parapetY, 0);
parapet.castShadow = true;
group.add(parapet);
});
}
const door = new THREE.Mesh(
new THREE.BoxGeometry(0.78, 1.38, 0.09),
mat(0x4e3a2a)
);
door.position.set(options.doorX || 0, 0.69, depth / 2 + 0.055);
door.castShadow = true;
group.add(door);
const doorTop = new THREE.Mesh(
new THREE.CircleGeometry(0.39, 8, 0, Math.PI),
mat(0x4e3a2a)
);
doorTop.rotation.z = Math.PI;
doorTop.position.set(options.doorX || 0, 1.38, depth / 2 + 0.061);
group.add(doorTop);
[-1, 1].forEach(side => {
if (random() > 0.18) {
const window = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.5, 0.075),
mat(0x465f59)
);
window.position.set(side * width * 0.27, height * 0.58, depth / 2 + 0.06);
group.add(window);
}
});
if (width > 3.8 && random() > 0.25) {
const sideWindow = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.54, 0.58),
mat(0x465f59)
);
sideWindow.position.set(width / 2 + 0.055, height * 0.56, -depth * 0.16);
group.add(sideWindow);
}
const stair = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.12, 0.45),
mat(0xb47c50)
);
stair.position.set(options.doorX || 0, 0.1, depth / 2 + 0.25);
stair.castShadow = true;
group.add(stair);
if (options.jar !== false) {
addWaterJar(width * 0.28, height + 0.18, -depth * 0.2, 0.75 + random() * 0.25);
}
return group;
}
addHouse(9.2, -6.0, 3.8, 4.4, 3.15, { doorX: -0.4 });
addHouse(13.8, -6.8, 4.6, 4.0, 3.65, { dome: true, jar: false });
addHouse(18.6, -5.5, 3.4, 4.3, 2.9, { material: adobeMaterials[2] });
addHouse(9.0, -0.1, 4.0, 4.4, 2.8, { doorX: 0.6 });
addHouse(14.0, -0.5, 4.8, 4.6, 3.45, { material: adobeMaterials[1] });
addHouse(19.0, 0.2, 3.5, 4.6, 3.05, { dome: true, jar: false });
addHouse(9.3, 6.0, 3.7, 4.2, 2.65, { material: adobeMaterials[3] });
addHouse(14.1, 6.1, 4.2, 4.0, 3.0, { jar: false });
addHouse(18.7, 6.0, 3.3, 4.1, 2.65, { material: adobeMaterials[2] });
// A shaded market awning in the settlement courtyard.
const awning = new THREE.Mesh(
new THREE.PlaneGeometry(3.5, 2.3, 8, 2),
new THREE.MeshStandardMaterial({
color: 0x397b79,
roughness: 0.85,
side: THREE.DoubleSide,
flatShading: true
})
);
awning.rotation.x = -Math.PI / 2 + 0.12;
awning.rotation.z = -0.08;
awning.position.set(16.1, 3.05, 3.35);
awning.castShadow = true;
scene.add(awning);
[
[14.55, 2.5],
[17.65, 2.5],
[14.55, 4.2],
[17.65, 4.2]
].forEach(([x, z]) => {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.075, 2.7, 6),
woodMaterial
);
post.position.set(x, 1.55, z);
post.castShadow = true;
scene.add(post);
});
// A traditional well near the spring.
const well = new THREE.Group();
well.position.set(7.6, 0.22, 3.2);
scene.add(well);
const wellRing = new THREE.Mesh(
new THREE.CylinderGeometry(0.82, 0.9, 0.55, 10, 1, true),
stoneMaterial
);
wellRing.position.y = 0.28;
wellRing.castShadow = true;
wellRing.receiveShadow = true;
well.add(wellRing);
const wellWater = new THREE.Mesh(
new THREE.CircleGeometry(0.68, 10),
waterMaterial
);
wellWater.rotation.x = -Math.PI / 2;
wellWater.position.y = 0.37;
well.add(wellWater);
[-0.62, 0.62].forEach(x => {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.08, 1.85, 6),
woodMaterial
);
post.position.set(x, 1.15, 0);
post.castShadow = true;
well.add(post);
});
const beam = new THREE.Mesh(
new THREE.BoxGeometry(1.55, 0.12, 0.13),
woodMaterial
);
beam.position.y = 2.02;
beam.castShadow = true;
well.add(beam);
const bucket = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.17, 0.32, 7),
mat(0x805236)
);
bucket.position.set(0.22, 1.2, 0);
bucket.castShadow = true;
well.add(bucket);
// Palm trees.
const palmCrowns = [];
function cylinderBetween(a, b, bottomRadius, topRadius, material, segments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(topRadius, bottomRadius, length, segments);
const mesh = new THREE.Mesh(geometry, material);
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;
return mesh;
}
function frondGeometry(length, width) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute([
0, 0, 0,
length * 0.38, -0.18, width,
length, -0.62, 0,
length * 0.38, -0.18, -width,
length * 0.43, -0.32, 0
], 3));
geometry.setIndex([
0, 1, 4,
1, 2, 4,
2, 3, 4,
3, 0, 4
]);
geometry.computeVertexNormals();
return geometry;
}
function addPalm(x, z, scale = 1, height = 6.2, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.14, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
const points = [];
for (let i = 0; i <= 6; i++) {
const t = i / 6;
points.push(new THREE.Vector3(
Math.sin(t * 1.55) * 0.28,
t * height,
Math.sin(t * 2.3) * 0.13
));
}
for (let i = 0; i < points.length - 1; i++) {
const bottom = 0.22 * (1 - i / 7);
const top = 0.22 * (1 - (i + 1) / 7);
group.add(cylinderBetween(points[i], points[i + 1], bottom, top, woodMaterial));
}
const crown = new THREE.Group();
crown.position.copy(points[points.length - 1]);
crown.userData.phase = random() * Math.PI * 2;
group.add(crown);
const frondCount = 8;
for (let i = 0; i < frondCount; i++) {
const angle = (i / frondCount) * Math.PI * 2 + random() * 0.16;
const frond = new THREE.Mesh(
frondGeometry(2.15 + random() * 0.55, 0.42 + random() * 0.12),
i % 3 === 0 ? leafLightMaterial : i % 3 === 1 ? leafMaterial : leafDarkMaterial
);
frond.rotation.y = angle;
frond.rotation.z = (random() - 0.5) * 0.14;
frond.castShadow = true;
crown.add(frond);
}
for (let i = 0; i < 3; i++) {
const date = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.12, 0),
mat(0x8b5a2d)
);
date.position.set(
Math.cos(i * 2.1) * 0.18,
-0.12,
Math.sin(i * 2.1) * 0.18
);
date.castShadow = true;
crown.add(date);
}
palmCrowns.push(crown);
return group;
}
[
[-5.7, -4.9, 1.05], [-7.1, -0.8, 0.92], [-5.9, 4.6, 1.08],
[-3.2, 7.0, 0.9], [3.9, 7.1, 1.04], [8.0, 4.8, 0.95],
[9.0, 0.2, 1.1], [7.7, -5.5, 0.92], [2.0, -6.8, 1.08],
[-1.5, -6.2, 0.86], [-7.0, -9.0, 1.02], [-6.8, 9.0, 0.93],
[-17.0, -9.3, 0.88], [-16.7, 9.4, 0.92], [-23.4, -7.5, 0.8],
[-23.4, 7.7, 0.83], [6.4, -9.1, 0.9], [22.0, -8.2, 0.86]
].forEach(([x, z, scale], i) => {
addPalm(x, z, scale, 5.5 + random() * 1.5, random() * Math.PI * 2);
});
// Dry desert shrubs.
function addShrub(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.15, z);
group.scale.setScalar(scale);
scene.add(group);
for (let i = 0; i < 5; i++) {
const branch = new THREE.Mesh(
new THREE.ConeGeometry(0.08, 0.55 + random() * 0.3, 4),
mat(i % 2 ? 0x776044 : 0x8e7650)
);
branch.position.set(
Math.cos(i * 2.4) * 0.17,
0.24,
Math.sin(i * 2.4) * 0.17
);
branch.rotation.z = Math.cos(i * 2.4) * 0.35;
branch.rotation.x = Math.sin(i * 2.4) * 0.35;
branch.castShadow = true;
group.add(branch);
}
}
[
[-15, -15], [18, -15], [23, 13], [-20, 14], [-4, -17],
[8, 17], [-24, -2], [25, 3], [-10, 17], [13, -17]
].forEach(([x, z]) => addShrub(x, z, 0.7 + random() * 0.55));
// A small desert tent on the outer dune.
const tent = new THREE.Group();
tent.position.set(24, 0.15, -13);
tent.rotation.y = -0.35;
scene.add(tent);
const tentBody = new THREE.Mesh(
new THREE.ConeGeometry(1.35, 2.3, 4),
mat(0xb9774e)
);
tentBody.rotation.y = Math.PI / 4;
tentBody.position.y = 1.1;
tentBody.castShadow = true;
tent.add(tentBody);
const tentDoor = new THREE.Mesh(
new THREE.ConeGeometry(0.65, 1.25, 3),
darkMaterial
);
tentDoor.rotation.y = Math.PI / 4;
tentDoor.position.set(0, 0.56, 0.92);
tent.add(tentDoor);
// Distant birds.
const birds = [];
for (let i = 0; i < 4; i++) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.42, 0, 0),
new THREE.Vector3(0, 0.16, 0),
new THREE.Vector3(0.42, 0, 0)
]);
const bird = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color: 0x574735, transparent: true, opacity: 0.65 })
);
bird.position.set(-9 + i * 4, 11 + i * 0.7, -13 - i * 2);
bird.userData.baseX = bird.position.x;
bird.userData.phase = random() * Math.PI * 2;
scene.add(bird);
birds.push(bird);
}
// A stylized sun disc in the sky.
const sunDisc = new THREE.Mesh(
new THREE.SphereGeometry(3.4, 16, 8),
new THREE.MeshBasicMaterial({ color: 0xffe6a1, fog: false })
);
sunDisc.position.set(-48, 43, -70);
scene.add(sunDisc);
// Fine airborne dust.
const dustPositions = [];
for (let i = 0; i < 180; i++) {
dustPositions.push(
(random() - 0.5) * 78,
0.5 + random() * 9,
(random() - 0.5) * 62
);
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.Float32BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffe4ae,
size: 0.065,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
scene.add(dust);
// Custom orbit, zoom, keyboard, and touch-pinch controls.
const view = {
theta: 0.72,
phi: 1.02,
radius: window.innerWidth < 720 ? 61 : 49,
target: new THREE.Vector3(0, 0.7, 0)
};
let autoOrbit = false;
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
updateCamera();
const pointers = new Map();
let lastPointer = null;
let pinchDistance = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && lastPointer) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi - dy * 0.005, 0.52, 1.38);
lastPointer = { x: event.clientX, y: event.clientY };
} 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 (pinchDistance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * (pinchDistance / Math.max(distance, 1)),
22,
78
);
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastPointer = { x: remaining.x, y: remaining.y };
} else {
lastPointer = null;
pinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
22,
78
);
}, { passive: false });
window.addEventListener("keydown", event => {
const step = 0.08;
if (event.key === "ArrowLeft") view.theta += step;
if (event.key === "ArrowRight") view.theta -= step;
if (event.key === "ArrowUp") view.phi = Math.max(0.52, view.phi - 0.05);
if (event.key === "ArrowDown") view.phi = Math.min(1.38, view.phi + 0.05);
if (event.key === "+" || event.key === "=") view.radius = Math.max(22, view.radius - 2);
if (event.key === "-") view.radius = Math.min(78, view.radius + 2);
if (event.key.toLowerCase() === "r") resetView();
});
function resetView() {
view.theta = 0.72;
view.phi = 1.02;
view.radius = window.innerWidth < 720 ? 61 : 49;
view.target.set(0, 0.7, 0);
}
document.querySelector("#reset").addEventListener("click", resetView);
const labelsButton = document.querySelector("#toggle-labels");
labelsButton.addEventListener("click", () => {
const enabled = document.body.classList.toggle("labels-off");
labelsButton.classList.toggle("active", !enabled);
labelsButton.setAttribute("aria-pressed", String(!enabled));
});
const orbitButton = document.querySelector("#toggle-orbit");
orbitButton.addEventListener("click", () => {
autoOrbit = !autoOrbit;
orbitButton.classList.toggle("active", autoOrbit);
orbitButton.setAttribute("aria-pressed", String(autoOrbit));
});
// Projected map annotations.
const annotations = [
{ element: document.querySelector("#pin-fields"), point: new THREE.Vector3(-12, 1.0, -2) },
{ element: document.querySelector("#pin-spring"), point: new THREE.Vector3(1, 0.8, 1) },
{ element: document.querySelector("#pin-village"), point: new THREE.Vector3(14, 4.1, -3) },
{ element: document.querySelector("#pin-palms"), point: new THREE.Vector3(-3.5, 6.4, 6.3) }
];
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
annotations.forEach(annotation => {
const projected = annotation.point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.display = visible ? "flex" : "none";
annotation.element.style.transform = `translate(${(projected.x * 0.5 + 0.5) * width}px, ${(-projected.y * 0.5 + 0.5) * height}px)`;
});
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 720 ? 52 : 40;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
if (autoOrbit) {
view.theta += delta * 0.055;
}
updateCamera();
waterMaterial.opacity = 0.86 + Math.sin(elapsed * 0.9) * 0.035;
deepWater.material.opacity = 0.25 + Math.sin(elapsed * 0.7 + 1.2) * 0.035;
shimmerPieces.forEach(shimmer => {
const phase = shimmer.userData.phase;
shimmer.position.x = shimmer.userData.baseX + Math.sin(elapsed * 0.55 + phase) * 0.12;
shimmer.position.z = shimmer.userData.baseZ + Math.cos(elapsed * 0.43 + phase) * 0.1;
shimmer.scale.x = 0.75 + (Math.sin(elapsed * 1.2 + phase) + 1) * 0.35;
shimmer.material.opacity = 0.08 + (Math.sin(elapsed * 1.15 + phase) + 1) * 0.07;
});
palmCrowns.forEach(crown => {
crown.rotation.z = Math.sin(elapsed * 1.25 + crown.userData.phase) * 0.026;
crown.rotation.x = Math.cos(elapsed * 0.9 + crown.userData.phase) * 0.018;
});
birds.forEach((bird, index) => {
bird.position.x = bird.userData.baseX + Math.sin(elapsed * 0.18 + index) * 4;
bird.position.y += Math.sin(elapsed * 0.7 + bird.userData.phase) * 0.002;
bird.rotation.z = Math.sin(elapsed * 1.4 + index) * 0.1;
});
dust.rotation.y = elapsed * 0.007;
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```