Prompt specification
Build or customize the Three.js 3D scene "Nile farming household through seasonal stages" 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: Nile farming household through seasonal stages
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/nile-farming-household-through-seasonal-stages-x2303
Scene Description Prompt:
Nile farming household through seasonal stages. Arrange a modest dwelling, grain store, field, and river edge. Switch documented seasonal farming stages while preserving the same terrain and clearly labeling reconstruction choices. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (nile-farming-household-through-seasonal-stages-x2303):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nile Farming Household — Seasonal Voxel Reconstruction</title>
<style>
:root {
--ink: #26342f;
--muted: #647169;
--paper: rgba(255, 253, 246, 0.9);
--line: rgba(43, 64, 53, 0.16);
--accent: #527f88;
--shadow: 0 16px 45px rgba(57, 48, 32, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8dfcc;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
summary {
font: inherit;
}
button {
color: inherit;
}
#app {
position: fixed;
inset: 0;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.glass {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
box-shadow: var(--shadow);
backdrop-filter: blur(15px) saturate(1.05);
-webkit-backdrop-filter: blur(15px) saturate(1.05);
}
.title-card {
position: absolute;
z-index: 5;
top: 20px;
left: 20px;
max-width: 350px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: #52665b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 25px;
height: 3px;
content: "";
border-radius: 3px;
background: var(--accent);
transition: background 300ms ease;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 300px;
margin: 10px 0 0;
color: #5e6b64;
font-size: 12px;
line-height: 1.45;
}
.interpretive-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 11px;
padding: 6px 9px;
border: 1px solid rgba(56, 73, 64, 0.18);
border-radius: 999px;
background: rgba(255, 253, 246, 0.68);
color: #526159;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.interpretive-badge::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: #b2803e;
}
.season-switcher {
position: absolute;
z-index: 7;
bottom: 22px;
left: 50%;
display: flex;
gap: 6px;
width: min(570px, calc(100vw - 32px));
padding: 6px;
transform: translateX(-50%);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 17px;
background: rgba(255, 253, 246, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.season-button {
position: relative;
display: flex;
flex: 1;
align-items: center;
justify-content: center;
gap: 10px;
min-width: 0;
padding: 10px 12px;
border: 0;
border-radius: 12px;
background: transparent;
cursor: pointer;
transition:
background 220ms ease,
color 220ms ease,
transform 160ms ease;
}
.season-button:hover {
background: rgba(54, 77, 65, 0.06);
}
.season-button:active {
transform: translateY(1px);
}
.season-button[aria-selected="true"] {
background: var(--accent);
color: white;
box-shadow: 0 6px 16px rgba(40, 57, 49, 0.17);
}
.season-button .roman {
display: grid;
flex: 0 0 28px;
width: 28px;
height: 28px;
place-items: center;
border: 1px solid currentColor;
border-radius: 50%;
font-family: Georgia, serif;
font-size: 12px;
opacity: 0.7;
}
.season-button strong,
.season-button small {
display: block;
text-align: left;
}
.season-button strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-weight: 600;
}
.season-button small {
margin-top: 1px;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
opacity: 0.68;
text-transform: uppercase;
}
.stage-info {
position: absolute;
z-index: 6;
bottom: 104px;
left: 20px;
width: min(380px, calc(100vw - 40px));
max-height: 43vh;
padding: 18px 19px;
overflow: auto;
border-radius: 16px;
transition: border-color 300ms ease;
}
.stage-info::before {
display: block;
width: 36px;
height: 4px;
margin-bottom: 12px;
content: "";
border-radius: 4px;
background: var(--accent);
transition: background 300ms ease;
}
.stage-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.fixed-chip {
padding: 4px 7px;
border-radius: 999px;
background: rgba(82, 127, 136, 0.1);
color: #4c716e;
white-space: nowrap;
}
.stage-title {
margin: 7px 0 1px;
font-family: Georgia, "Times New Roman", serif;
font-size: 29px;
font-weight: 500;
letter-spacing: -0.025em;
}
.stage-subtitle {
margin: 0 0 12px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: color 300ms ease;
}
.stage-description {
margin: 0;
color: #526158;
font-size: 12px;
line-height: 1.58;
}
.visible-changes {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.visible-changes span {
display: block;
margin-bottom: 4px;
color: #879087;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.visible-changes p {
margin: 0;
color: #48584f;
font-size: 11px;
line-height: 1.5;
}
.calendar-note {
margin: 10px 0 0;
color: #899087;
font-size: 9px;
line-height: 1.4;
}
.choices {
position: absolute;
z-index: 8;
top: 20px;
right: 20px;
width: min(320px, calc(100vw - 40px));
border-radius: 15px;
overflow: hidden;
}
.choices summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 13px 15px;
cursor: pointer;
list-style: none;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.choices summary::-webkit-details-marker {
display: none;
}
.choices summary::after {
content: "+";
color: #8b948e;
font-size: 16px;
font-weight: 400;
}
.choices[open] summary::after {
content: "−";
}
.choice-tag {
margin-left: auto;
color: #9a6a31;
font-size: 8px;
letter-spacing: 0.08em;
}
.choices-body {
padding: 0 15px 14px;
border-top: 1px solid var(--line);
}
.choices-body ul {
margin: 12px 0;
padding-left: 16px;
}
.choices-body li {
margin: 0 0 9px;
color: #59665e;
font-size: 10px;
line-height: 1.5;
}
.choices-body li::marker {
color: #ad7b3d;
}
.choices-body b {
color: #35453d;
}
.basis {
padding: 9px 10px;
border-radius: 9px;
background: rgba(91, 106, 96, 0.07);
color: #657068;
font-size: 9px;
line-height: 1.5;
}
.view-controls {
position: absolute;
z-index: 7;
right: 20px;
bottom: 104px;
display: flex;
gap: 7px;
}
.view-controls button {
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 10px;
background: rgba(255, 253, 246, 0.85);
box-shadow: 0 8px 22px rgba(57, 48, 32, 0.1);
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.view-controls button:hover {
background: #fffdf6;
}
#labels {
position: absolute;
z-index: 3;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 7px;
background: rgba(255, 253, 246, 0.87);
box-shadow: 0 6px 16px rgba(45, 49, 40, 0.12);
color: #35483e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
white-space: nowrap;
transition: opacity 160ms ease;
}
.scene-label::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--accent);
}
.scene-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
content: "";
background: linear-gradient(rgba(53, 72, 62, 0.55), transparent);
}
.loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e8dfcc;
color: #53635a;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 850px) {
.choices {
width: 260px;
}
.choice-tag {
display: none;
}
}
@media (max-width: 620px) {
.title-card {
top: 12px;
left: 12px;
max-width: 260px;
}
.title-card .subtitle,
.interpretive-badge {
display: none;
}
.choices {
top: 92px;
right: 10px;
width: 220px;
}
.stage-info {
right: 10px;
bottom: 94px;
left: 10px;
width: auto;
max-height: 39vh;
padding: 14px 15px;
}
.stage-title {
font-size: 24px;
}
.stage-description {
font-size: 11px;
}
.season-switcher {
bottom: 12px;
width: calc(100vw - 20px);
gap: 3px;
padding: 5px;
}
.season-button {
gap: 5px;
padding: 8px 5px;
}
.season-button .roman {
display: none;
}
.season-button strong {
font-size: 14px;
text-align: center;
}
.season-button small {
font-size: 7px;
text-align: center;
}
.view-controls {
top: 144px;
right: 10px;
bottom: auto;
}
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive voxel reconstruction of a Nile farming household"></canvas>
<header class="title-card">
<div class="eyebrow">Nile agricultural calendar</div>
<h1>A farming household,<br />through the year</h1>
<p class="subtitle">
A fixed landscape observed through inundation, crop growth, and harvest.
</p>
<div class="interpretive-badge">Interpretive voxel reconstruction</div>
</header>
<nav class="season-switcher" role="tablist" aria-label="Choose agricultural season">
<button
class="season-button"
role="tab"
data-stage="0"
aria-selected="true"
>
<span class="roman">I</span>
<span>
<strong>Akhet</strong>
<small>Inundation</small>
</span>
</button>
<button
class="season-button"
role="tab"
data-stage="1"
aria-selected="false"
>
<span class="roman">II</span>
<span>
<strong>Peret</strong>
<small>Growth</small>
</span>
</button>
<button
class="season-button"
role="tab"
data-stage="2"
aria-selected="false"
>
<span class="roman">III</span>
<span>
<strong>Shemu</strong>
<small>Harvest</small>
</span>
</button>
</nav>
<aside class="stage-info glass" aria-live="polite">
<div class="stage-meta">
<span id="stageCounter">Season I of III</span>
<span class="fixed-chip">Landform fixed</span>
</div>
<h2 class="stage-title" id="stageTitle">Akhet</h2>
<div class="stage-subtitle" id="stageSubtitle">Inundation and sowing</div>
<p class="stage-description" id="stageDescription"></p>
<div class="visible-changes">
<span>Visible changes</span>
<p id="visibleChanges"></p>
</div>
<p class="calendar-note">
Months are approximate. Ancient dates and regional agricultural calendars varied.
</p>
</aside>
<aside class="choices glass">
<details id="choicesDetails" open>
<summary>
Reconstruction choices
<span class="choice-tag">Interpretive</span>
</summary>
<div class="choices-body">
<ul>
<li>
<b>Not a site-specific excavation.</b> The household, buildings, field,
and terrain form a schematic teaching reconstruction rather than a
surveyed Nile Valley property.
</li>
<li>
<b>Calendar basis.</b> Akhet, Peret, and Shemu follow the conventional
Egyptian three-season agricultural sequence and broad modern-month labels.
</li>
<li>
<b>Crop choice.</b> Stylized sorghum-like plants represent commonly
cultivated Nile Valley cereals; the exact grain mixture is omitted.
</li>
<li>
<b>Terrain.</b> One cutaway floodplain terrace, a simplified bank, and
one irrigation channel are used to make seasonal water legible.
</li>
<li>
<b>Buildings and objects.</b> Mud-brick forms, the stepped grain silo,
tools, jars, sacks, and the contextual palm are interpretive details.
</li>
</ul>
<div class="basis">
<b>Interpretive basis:</b> the three named agricultural stages and their
broad activities are historically conventional; the voxel forms and
spatial arrangement are deliberately simplified for clarity.
</div>
</div>
</details>
</aside>
<div id="labels" aria-hidden="true">
<div class="scene-label" data-world="house">Mud-brick dwelling</div>
<div class="scene-label" data-world="store">Grain store</div>
<div class="scene-label" data-world="field">Cereal field</div>
<div class="scene-label" data-world="river">Nile river edge</div>
</div>
<div class="view-controls">
<button id="resetView" type="button">Reset view</button>
<button id="toggleLabels" type="button" aria-pressed="true">Labels on</button>
</div>
<div class="loading" id="loading">Building the voxel floodplain…</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Stage data
// ---------------------------------------------------------------------
const stageData = [
{
name: "Akhet",
subtitle: "Inundation and sowing",
months: "≈ June–September",
accent: "#527f88",
description:
"The Nile rises and spreads across the floodplain. As basin plots drain, " +
"farmers prepare the soil and begin sowing; the river remains high and the field is largely without standing crop.",
visible:
"High river water, a schematic sheet of floodwater over the field, and no mature crop rows."
},
{
name: "Peret",
subtitle: "Emergence and irrigation",
months: "≈ October–February",
accent: "#66884b",
description:
"Crops emerge and grow while irrigation water is directed through field channels. " +
"The river is lower, exposing more of its bed, and cultivation becomes the dominant visual feature.",
visible:
"Green crop rows, a stronger irrigation channel, lower river water, and the same fixed buildings."
},
{
name: "Shemu",
subtitle: "Harvest and storage",
months: "≈ March–May",
accent: "#b57b2d",
description:
"Mature cereals are cut, gathered, threshed, and prepared for storage. " +
"The field turns gold, sacks appear near the grain store, and the river reaches its lowest depicted level.",
visible:
"Golden grain heads, harvest sacks, reduced irrigation, and the lowest river level."
}
];
const $ = (id) => document.getElementById(id);
const canvas = $("scene");
const loading = $("loading");
// ---------------------------------------------------------------------
// Renderer, scene, lighting
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdde5df);
scene.fog = new THREE.Fog(0xdde5df, 48, 100);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
160
);
const hemisphere = new THREE.HemisphereLight(0xeaf3f0, 0x77634b, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4b4, 3.2);
sun.position.set(-24, 35, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 32;
sun.shadow.camera.bottom = -32;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
scene.add(sun.target);
const ambient = new THREE.AmbientLight(0xffffff, 0.22);
scene.add(ambient);
// ---------------------------------------------------------------------
// Utilities and deterministic randomness
// ---------------------------------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(73421);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function smooth01(value) {
const t = clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
function setInstance(mesh, index, position, scale, rotation = [0, 0, 0]) {
dummy.position.set(position[0], position[1], position[2]);
dummy.rotation.set(rotation[0], rotation[1], rotation[2]);
dummy.scale.set(scale[0], scale[1], scale[2]);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
}
function makeBlocks(name, blocks, options = {}) {
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: options.roughness ?? 0.86,
metalness: options.metalness ?? 0,
transparent: Boolean(options.transparent),
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true
});
const mesh = new THREE.InstancedMesh(unitBox, material, blocks.length);
mesh.name = name;
blocks.forEach((block, index) => {
setInstance(
mesh,
index,
[block.x, block.y, block.z],
[block.sx ?? 1, block.sy ?? 1, block.sz ?? 1],
[block.rx ?? 0, block.ry ?? 0, block.rz ?? 0]
);
mesh.setColorAt(index, new THREE.Color(block.color ?? 0xffffff));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
mesh.frustumCulled = options.frustumCulled ?? false;
scene.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Fixed terrain: a 36 × 26 block grid
// ---------------------------------------------------------------------
const GRID_MIN_X = -18;
const GRID_MAX_X = 17;
const GRID_MIN_Z = -13;
const GRID_MAX_Z = 12;
const terrainBlocks = [];
const riverTiles = [];
const canalTiles = [];
const fieldCells = [];
const baseColors = [0x705944, 0x78604a, 0x67533f, 0x80674e];
const landColors = [0x9b895e, 0xa18e63, 0x91815a, 0xa7966c];
const fieldColors = [0x876442, 0x906a45, 0x805f42, 0x98704a];
const pathColors = [0xb59a6c, 0xbaa071, 0xaa9064];
const yardColors = [0xa88c61, 0xb09469, 0x9d8259];
function isFieldCell(x, z) {
return x >= -1 && x <= 6 && z >= -7 && z <= 5;
}
function surfaceColor(x, z) {
if (isFieldCell(x, z)) return choose(fieldColors);
const onPath =
(x === -7 && z >= -8 && z <= 8) ||
(z === 7 && x >= -15 && x <= 7);
if (onPath) return choose(pathColors);
const inYard = x >= -15 && x <= -8 && z >= -1 && z <= 6;
if (inYard) return choose(yardColors);
return choose(landColors);
}
for (let x = GRID_MIN_X; x <= GRID_MAX_X; x++) {
for (let z = GRID_MIN_Z; z <= GRID_MAX_Z; z++) {
// Continuous block foundation.
terrainBlocks.push({
x,
y: -2.5,
z,
sx: 0.97,
sy: 1,
sz: 0.97,
color: choose(baseColors)
});
if (x <= 8) {
// Ordinary land has two visible soil courses.
terrainBlocks.push({
x,
y: -1.5,
z,
sx: 0.97,
sy: 1,
sz: 0.97,
color: choose(baseColors)
});
let top = 0;
let height = 1;
let color = surfaceColor(x, z);
if (x === -2 && z >= -7 && z <= 5) {
// Fixed recessed irrigation channel.
top = -0.45;
height = 0.55;
color = 0x806649;
}
terrainBlocks.push({
x,
y: top - height / 2,
z,
sx: 0.97,
sy: height,
sz: 0.97,
color
});
} else if (x === 9) {
// Low bank at the edge of the river.
terrainBlocks.push({
x,
y: -1.5,
z,
sx: 0.97,
sy: 1,
sz: 0.97,
color: 0x80684b
});
terrainBlocks.push({
x,
y: -0.65,
z,
sx: 0.97,
sy: 0.7,
sz: 0.97,
color: choose([0x9a8057, 0xa68b60, 0x8d7550])
});
} else {
// Lower river bed.
terrainBlocks.push({
x,
y: -1.5,
z,
sx: 0.97,
sy: 1,
sz: 0.97,
color: choose([0x75664e, 0x806f54, 0x6d604c])
});
}
if (x >= 9) {
riverTiles.push({
x,
z,
color: choose([0x4c9ca5, 0x57a5aa, 0x438f9c, 0x69adb0])
});
}
if (x === -2 && z >= -7 && z <= 5) {
canalTiles.push({ x, z });
}
if (isFieldCell(x, z)) {
fieldCells.push({ x, z });
}
}
}
const terrain = makeBlocks("Fixed voxel terrain", terrainBlocks, {
castShadow: false,
receiveShadow: true,
roughness: 0.96
});
// A broad receiving block beneath the floating diorama.
makeBlocks(
"Background ground",
[
{
x: 0,
y: -3.3,
z: 0,
sx: 140,
sy: 0.6,
sz: 140,
color: 0xe7ddc7
}
],
{ castShadow: false, receiveShadow: true, roughness: 1 }
);
// ---------------------------------------------------------------------
// Water tiles
// ---------------------------------------------------------------------
const riverWater = makeBlocks(
"River water blocks",
riverTiles.map((tile) => ({
x: tile.x,
y: 0,
z: tile.z,
sx: 0.96,
sy: 0.12,
sz: 0.96,
color: tile.color
})),
{
castShadow: false,
transparent: true,
opacity: 0.88,
depthWrite: false,
roughness: 0.24
}
);
riverWater.renderOrder = 2;
const canalWater = makeBlocks(
"Irrigation channel water",
canalTiles.map((tile) => ({
x: tile.x,
y: -0.19,
z: tile.z,
sx: 0.92,
sy: 0.08,
sz: 0.96,
color: 0x5c9e93
})),
{
castShadow: false,
transparent: true,
opacity: 0.85,
depthWrite: false,
roughness: 0.3
}
);
canalWater.renderOrder = 2;
const floodOverlay = makeBlocks(
"Schematic flooded field",
fieldCells.map((cell) => ({
x: cell.x,
y: 0.025,
z: cell.z,
sx: 0.965,
sy: 0.035,
sz: 0.965,
color: 0x639ca0
})),
{
castShadow: false,
transparent: true,
opacity: 0.45,
depthWrite: false,
roughness: 0.35
}
);
floodOverlay.renderOrder = 1;
const foamTiles = [];
for (let i = 0; i < 24; i++) {
foamTiles.push({
x: 10 + Math.floor(random() * 7),
z: GRID_MIN_Z + random() * (GRID_MAX_Z - GRID_MIN_Z),
length: 0.25 + random() * 0.55,
offset: random() * 0.18
});
}
const foam = makeBlocks(
"River highlights",
foamTiles.map((tile) => ({
x: tile.x,
y: 0.05,
z: tile.z,
sx: tile.length,
sy: 0.045,
sz: 0.11,
color: choose([0xb6d7cf, 0x9fc9c5, 0xc6dfd7])
})),
{
castShadow: false,
transparent: true,
opacity: 0.68,
depthWrite: false,
roughness: 0.5
}
);
foam.renderOrder = 3;
// ---------------------------------------------------------------------
// Dwelling: individually visible mud-brick blocks
// ---------------------------------------------------------------------
const houseBlocks = [];
const adobeColors = [0xc28c5e, 0xc99666, 0xb98258, 0xd09c6d, 0xbb8658];
const roofColors = [0xb98157, 0xc08a5d, 0xad7952, 0xc79264];
function addHouseBlock(x, y, z, sx, sy, sz, color) {
houseBlocks.push({ x, y, z, sx, sy, sz, color });
}
// Six-by-six floor.
for (let x = -14; x <= -9; x++) {
for (let z = -6; z <= -1; z++) {
addHouseBlock(
x,
0.07,
z,
0.94,
0.14,
0.94,
choose([0x98734f, 0xa17a52, 0x8e6c4c])
);
}
}
// Three courses of walls.
for (let level = 0; level < 3; level++) {
const y = 0.25 + level * 0.5;
for (let x = -14; x <= -9; x++) {
const isDoorOpening =
level < 2 && (x === -12 || x === -11);
if (!isDoorOpening) {
addHouseBlock(
x,
y,
-6,
0.93,
0.48,
0.93,
choose(adobeColors)
);
}
addHouseBlock(
x,
y,
-1,
0.93,
0.48,
0.93,
choose(adobeColors)
);
}
for (let z = -5; z <= -2; z++) {
addHouseBlock(
-14,
y,
z,
0.93,
0.48,
0.93,
choose(adobeColors)
);
addHouseBlock(
-9,
y,
z,
0.93,
0.48,
0.93,
choose(adobeColors)
);
}
}
// Dark block-built doorway set behind the missing wall blocks.
for (const x of [-12, -11]) {
addHouseBlock(x, 0.67, -1.34, 0.91, 1.25, 0.14, 0x49372a);
}
// Flat roof terrace with slight block-to-block variation.
for (let x = -14; x <= -9; x++) {
for (let z = -6; z <= -1; z++) {
addHouseBlock(
x,
1.68,
z,
0.95,
0.3,
0.95,
choose(roofColors)
);
}
}
// Low roof parapet.
for (let x = -14; x <= -9; x++) {
addHouseBlock(x, 1.98, -6, 0.94, 0.31, 0.93, choose(adobeColors));
addHouseBlock(x, 1.98, -1, 0.94, 0.31, 0.93, choose(adobeColors));
}
for (let z = -5; z <= -2; z++) {
addHouseBlock(-14, 1.98, z, 0.94, 0.31, 0.93, choose(adobeColors));
addHouseBlock(-9, 1.98, z, 0.94, 0.31, 0.93, choose(adobeColors));
}
makeBlocks("Modest mud-brick dwelling", houseBlocks);
// ---------------------------------------------------------------------
// Stepped grain store
// ---------------------------------------------------------------------
const storeBlocks = [];
const storeX = -5.35;
const storeZ = -6.1;
const storeSpacing = 0.64;
// Square base.
for (let dx = -2; dx <= 2; dx++) {
for (let dz = -2; dz <= 2; dz++) {
storeBlocks.push({
x: storeX + dx * 0.73,
y: 0.17,
z: storeZ + dz * 0.73,
sx: 0.7,
sy: 0.3,
sz: 0.7,
color: choose([0xbd8557, 0xc18a5c, 0xb47d52])
});
}
}
// Stepped, voxelized approximation of a rounded mud-brick silo.
const domeRadii = [2.0, 1.7, 1.38, 1.03, 0.68];
domeRadii.forEach((radius, level) => {
for (let dx = -2; dx <= 2; dx++) {
for (let dz = -2; dz <= 2; dz++) {
const distance = Math.sqrt(dx * dx + dz * dz);
if (distance > radius) continue;
const omitDoor = level === 0 && dz === 1 && Math.abs(dx) <= 0.7;
if (omitDoor) continue;
storeBlocks.push({
x: storeX + dx * storeSpacing,
y: 0.55 + level * 0.54,
z: storeZ + dz * storeSpacing,
sx: 0.61,
sy: 0.51,
sz: 0.61,
color: choose([0xc68e5d, 0xbb8256, 0xd09663, 0xb97e54])
});
}
}
});
// Door panel.
storeBlocks.push({
x: storeX,
y: 0.53,
z: storeZ + 1.04,
sx: 1.05,
sy: 1.05,
sz: 0.16,
color: 0x4d3829
});
makeBlocks("Stepped grain store", storeBlocks);
// ---------------------------------------------------------------------
// Courtyard wall, jars, loom, and baskets
// ---------------------------------------------------------------------
const householdBlocks = [];
// Low courtyard wall.
for (let z = -1; z <= 7; z++) {
householdBlocks.push({
x: -16,
y: 0.35,
z,
sx: 0.75,
sy: 0.7,
sz: 0.94,
color: choose(adobeColors)
});
}
for (let x = -15; x <= -9; x++) {
householdBlocks.push({
x,
y: 0.35,
z: 7,
sx: 0.94,
sy: 0.7,
sz: 0.75,
color: choose(adobeColors)
});
}
// Block-shaped water jars.
const jarColors = [0x76523a, 0x684733, 0x805b40];
householdBlocks.push(
{ x: -7.35, y: 0.23, z: 1.1, sx: 0.45, sy: 0.46, sz: 0.45, color: choose(jarColors) },
{ x: -7.35, y: 0.62, z: 1.1, sx: 0.65, sy: 0.42, sz: 0.65, color: choose(jarColors) },
{ x: -7.35, y: 0.93, z: 1.1, sx: 0.3, sy: 0.22, sz: 0.3, color: choose(jarColors) },
{ x: -6.55, y: 0.2, z: 1.4, sx: 0.38, sy: 0.4, sz: 0.38, color: choose(jarColors) },
{ x: -6.55, y: 0.52, z: 1.4, sx: 0.54, sy: 0.36, sz: 0.54, color: choose(jarColors) },
{ x: -6.55, y: 0.78, z: 1.4, sx: 0.26, sy: 0.2, sz: 0.26, color: choose(jarColors) }
);
// Simple wooden loom.
const wood = 0x705037;
householdBlocks.push(
{ x: -7.7, y: 0.9, z: -2.9, sx: 0.16, sy: 1.8, sz: 0.16, color: wood },
{ x: -6.6, y: 0.9, z: -2.9, sx: 0.16, sy: 1.8, sz: 0.16, color: wood },
{ x: -7.15, y: 1.78, z: -2.9, sx: 1.35, sy: 0.16, sz: 0.16, color: wood },
{ x: -7.15, y: 0.32, z: -2.9, sx: 1.35, sy: 0.16, sz: 0.16, color: wood },
{ x: -7.15, y: 1.03, z: -2.87, sx: 0.86, sy: 1.12, sz: 0.08, color: 0xb26a45 }
);
// Woven baskets near the store.
householdBlocks.push(
{ x: -3.7, y: 0.22, z: -3.8, sx: 0.7, sy: 0.44, sz: 0.7, color: 0xb1814e },
{ x: -3.7, y: 0.48, z: -3.8, sx: 0.82, sy: 0.12, sz: 0.82, color: 0xc0935c },
{ x: -4.4, y: 0.18, z: -3.5, sx: 0.55, sy: 0.36, sz: 0.55, color: 0xa97948 }
);
makeBlocks("Household courtyard objects", householdBlocks);
// Harvest sacks become visible only during Shemu.
const harvestSackBlocks = [];
const sackPositions = [
[-4.25, -3.0],
[-3.55, -2.55],
[-4.55, -2.35],
[-3.35, -3.35],
[-4.15, -1.75]
];
sackPositions.forEach(([x, z], index) => {
harvestSackBlocks.push({
x,
y: 0.28,
z,
sx: 0.62,
sy: 0.56,
sz: 0.52,
color: choose([0xc9a45c, 0xd1ad64, 0xbe9850])
});
harvestSackBlocks.push({
x: x + 0.08,
y: 0.68,
z: z - 0.03,
sx: 0.38,
sy: 0.25,
sz: 0.32,
color: choose([0xd2af69, 0xc6a158, 0xdab976])
});
});
const harvestSacks = makeBlocks("Harvest grain sacks", harvestSackBlocks, {
transparent: true,
opacity: 0,
depthWrite: false
});
harvestSacks.visible = false;
// ---------------------------------------------------------------------
// Contextual date palm and reeds
// ---------------------------------------------------------------------
const palmBlocks = [];
const palmX = 7.4;
const palmZ = -9.2;
for (let i = 0; i < 7; i++) {
palmBlocks.push({
x: palmX,
y: 0.24 + i * 0.43,
z: palmZ,
sx: 0.4 - i * 0.018,
sy: 0.4,
sz: 0.4 - i * 0.018,
color: choose([0x805d39, 0x8e6940, 0x765335])
});
}
const frondColors = [0x55783c, 0x638746, 0x4d7137, 0x6f8c48];
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
palmBlocks.push({
x: palmX + cos * 0.58,
y: 3.13,
z: palmZ + sin * 0.58,
sx: 1.35,
sy: 0.18,
sz: 0.32,
ry: -angle,
rz: 0.08,
color: choose(frondColors)
});
palmBlocks.push({
x: palmX + cos * 1.3,
y: 2.94,
z: palmZ + sin * 1.3,
sx: 1.18,
sy: 0.16,
sz: 0.28,
ry: -angle,
rz: -0.15,
color: choose(frondColors)
});
}
palmBlocks.push(
{ x: palmX - 0.17, y: 3.02, z: palmZ, sx: 0.3, sy: 0.3, sz: 0.3, color: 0x8b6335 },
{ x: palmX + 0.17, y: 3.02, z: palmZ, sx: 0.3, sy: 0.3, sz: 0.3, color: 0x8b6335 }
);
makeBlocks("Contextual date palm", palmBlocks);
const reedBlocks = [];
for (const z of [-11, -6, -1, 4, 9]) {
for (let i = 0; i < 4; i++) {
const x = 8.25 + random() * 0.55;
reedBlocks.push({
x,
y: 0.02 + i * 0.28,
z: z + random() * 0.45,
sx: 0.13,
sy: 0.33,
sz: 0.13,
color: choose([0x647943, 0x72864b, 0x536c38])
});
}
}
makeBlocks("River-edge reeds", reedBlocks);
// ---------------------------------------------------------------------
// Crop blocks
// ---------------------------------------------------------------------
const cropData = fieldCells.map((cell) => ({
x: cell.x,
z: cell.z,
baseHeight: 0.42 + random() * 0.4,
leafAngle: random() * Math.PI * 2
}));
const cropStems = makeBlocks(
"Crop stems",
cropData.map((crop) => ({
x: crop.x,
y: 0.2,
z: crop.z,
sx: 0.11,
sy: 0.4,
sz: 0.11,
color: 0x587d3c
})),
{ castShadow: true, roughness: 0.92 }
);
const cropLeaves = makeBlocks(
"Crop leaves",
cropData.flatMap((crop) => [
{
x: crop.x,
y: 0.25,
z: crop.z,
sx: 0.4,
sy: 0.08,
sz: 0.14,
color: 0x638c43
},
{
x: crop.x,
y: 0.25,
z: crop.z,
sx: 0.4,
sy: 0.08,
sz: 0.14,
color: 0x587e39
}
]),
{ castShadow: true, roughness: 0.92 }
);
const cropHeads = makeBlocks(
"Grain heads",
cropData.map((crop) => ({
x: crop.x,
y: 0.4,
z: crop.z,
sx: 0.2,
sy: 0.34,
sz: 0.2,
color: 0xd0a448
})),
{ castShadow: true, roughness: 0.9 }
);
const greenStem = new THREE.Color(0x557b39);
const goldStem = new THREE.Color(0xb88a38);
const greenLeaf = new THREE.Color(0x628d40);
const goldLeaf = new THREE.Color(0xb99b42);
const goldHead = new THREE.Color(0xd7ad4d);
const temporaryColor = new THREE.Color();
function updateCrops(seasonValue) {
const growth = seasonValue <= 1 ? smooth01(seasonValue) : 1;
const harvest = seasonValue <= 1 ? 0 : smooth01(seasonValue - 1);
cropData.forEach((crop, index) => {
const height = Math.max(
0.001,
crop.baseHeight * growth * (1 + harvest * 0.12)
);
setInstance(
cropStems,
index,
[crop.x, height / 2 + 0.01, crop.z],
[0.105, height, 0.105]
);
temporaryColor.copy(greenStem).lerp(goldStem, harvest);
cropStems.setColorAt(index, temporaryColor);
for (let side = 0; side < 2; side++) {
const leafIndex = index * 2 + side;
const direction = side === 0 ? 1 : -1;
const angle = crop.leafAngle + direction * 0.95;
const offset = 0.12 + side * 0.08;
setInstance(
cropLeaves,
leafIndex,
[
crop.x + Math.cos(angle) * offset,
Math.max(0.04, height * (0.48 + side * 0.12)),
crop.z + Math.sin(angle) * offset
],
[
Math.max(0.001, 0.43 * growth),
Math.max(0.001, 0.08 * growth),
Math.max(0.001, 0.15 * growth)
],
[0, -angle, direction * 0.15]
);
temporaryColor.copy(greenLeaf).lerp(goldLeaf, harvest);
cropLeaves.setColorAt(leafIndex, temporaryColor);
}
setInstance(
cropHeads,
index,
[crop.x, height + 0.16 * harvest + 0.01, crop.z],
[
Math.max(0.001, 0.21 * harvest),
Math.max(0.001, 0.34 * harvest),
Math.max(0.001, 0.21 * harvest)
]
);
cropHeads.setColorAt(index, goldHead);
});
cropStems.instanceMatrix.needsUpdate = true;
cropLeaves.instanceMatrix.needsUpdate = true;
cropHeads.instanceMatrix.needsUpdate = true;
if (cropStems.instanceColor) cropStems.instanceColor.needsUpdate = true;
if (cropLeaves.instanceColor) cropLeaves.instanceColor.needsUpdate = true;
if (cropHeads.instanceColor) cropHeads.instanceColor.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Seasonal animation
// ---------------------------------------------------------------------
const stageBackgrounds = [
new THREE.Color(0xdde5df),
new THREE.Color(0xe8eadb),
new THREE.Color(0xead8b8)
];
let season = 0;
let targetSeason = 0;
let transition = null;
let previousRenderedSeason = -1;
function updateDynamicScene(seasonValue) {
const waterLevel =
seasonValue <= 1
? lerp(0.02, -0.55, seasonValue)
: lerp(-0.55, -0.86, seasonValue - 1);
riverTiles.forEach((tile, index) => {
setInstance(
riverWater,
index,
[tile.x, waterLevel - 0.06, tile.z],
[0.96, 0.12, 0.96]
);
});
riverWater.instanceMatrix.needsUpdate = true;
foamTiles.forEach((tile, index) => {
setInstance(
foam,
index,
[tile.x, waterLevel + 0.055, tile.z + tile.offset],
[tile.length, 0.045, 0.11]
);
});
foam.instanceMatrix.needsUpdate = true;
const canalOpacity =
seasonValue <= 1
? lerp(0.82, 0.95, seasonValue)
: lerp(0.95, 0.24, seasonValue - 1);
canalWater.material.opacity = canalOpacity;
floodOverlay.material.opacity =
seasonValue <= 1 ? 0.46 * (1 - seasonValue) : 0;
updateCrops(seasonValue);
const harvestAmount =
seasonValue <= 1 ? 0 : smooth01(seasonValue - 1);
harvestSacks.visible = harvestAmount > 0.01;
harvestSacks.material.opacity = harvestAmount;
const background =
seasonValue <= 1
? stageBackgrounds[0].clone().lerp(stageBackgrounds[1], seasonValue)
: stageBackgrounds[1].clone().lerp(stageBackgrounds[2], seasonValue - 1);
scene.background.copy(background);
scene.fog.color.copy(background);
sun.intensity =
seasonValue <= 1
? lerp(2.8, 3.15, seasonValue)
: lerp(3.15, 3.55, seasonValue - 1);
sun.color.set(
seasonValue <= 1
? 0xffe7c2
: 0xffd18f
);
}
function updateStageUI(index) {
const stage = stageData[index];
document.documentElement.style.setProperty("--accent", stage.accent);
$("stageCounter").textContent = `Season ${["I", "II", "III"][index]} of III`;
$("stageTitle").textContent = stage.name;
$("stageSubtitle").textContent = `${stage.subtitle} · ${stage.months}`;
$("stageDescription").textContent = stage.description;
$("visibleChanges").textContent = stage.visible;
document.querySelectorAll(".season-button").forEach((button) => {
const active = Number(button.dataset.stage) === index;
button.setAttribute("aria-selected", String(active));
});
}
function selectStage(index) {
index = clamp(index, 0, stageData.length - 1);
targetSeason = index;
transition = {
from: season,
to: index,
started: performance.now(),
duration: 1450
};
updateStageUI(index);
}
document.querySelectorAll(".season-button").forEach((button) => {
button.addEventListener("click", () => {
selectStage(Number(button.dataset.stage));
});
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") selectStage(0);
if (event.key === "2") selectStage(1);
if (event.key === "3") selectStage(2);
if (event.key === "ArrowLeft") {
selectStage(Math.round(targetSeason) - 1);
}
if (event.key === "ArrowRight") {
selectStage(Math.round(targetSeason) + 1);
}
});
if (window.innerWidth < 850) {
$("choicesDetails").open = false;
}
// ---------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, and reset
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-1, 0.2, -1);
let azimuth = 0.68;
let polar = 0.76;
let distance = 48;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + distance * sinPolar * Math.sin(azimuth),
cameraTarget.y + distance * Math.cos(polar),
cameraTarget.z + distance * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTarget.set(-1, 0.2, -1);
azimuth = 0.68;
polar = 0.76;
distance = 48;
updateCamera();
}
$("resetView").addEventListener("click", resetCamera);
let labelsVisible = true;
$("toggleLabels").addEventListener("click", () => {
labelsVisible = !labelsVisible;
$("toggleLabels").textContent = labelsVisible ? "Labels on" : "Labels off";
$("toggleLabels").setAttribute("aria-pressed", String(labelsVisible));
$("labels").style.opacity = labelsVisible ? "1" : "0";
});
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const scale = distance * 0.0015;
const right = new THREE.Vector3(
Math.cos(azimuth),
0,
-Math.sin(azimuth)
);
const forward = new THREE.Vector3(
-Math.sin(azimuth),
0,
-Math.cos(azimuth)
);
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(forward, -dy * scale);
cameraTarget.x = clamp(cameraTarget.x, -11, 10);
cameraTarget.z = clamp(cameraTarget.z, -9, 9);
} else {
azimuth -= dx * 0.006;
polar = clamp(polar + dy * 0.005, 0.35, 1.22);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
distance = clamp(distance * Math.exp(event.deltaY * 0.001), 27, 76);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// ---------------------------------------------------------------------
// Projected scene labels, using no additional renderer or addon
// ---------------------------------------------------------------------
const labelAnchors = {
house: new THREE.Vector3(-11.5, 2.75, -3.2),
store: new THREE.Vector3(-5.3, 3.35, -6.1),
field: new THREE.Vector3(2.5, 1.4, -0.5),
river: new THREE.Vector3(13.2, 0.85, 7.3)
};
const labelElements = new Map();
document.querySelectorAll(".scene-label").forEach((element) => {
labelElements.set(element.dataset.world, element);
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
Object.entries(labelAnchors).forEach(([key, anchor]) => {
const element = labelElements.get(key);
if (!element) return;
projected.copy(anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
element.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
});
}
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
updateStageUI(0);
updateDynamicScene(0);
updateCamera();
function animate(now) {
requestAnimationFrame(animate);
if (transition) {
const progress = clamp(
(now - transition.started) / transition.duration,
0,
1
);
const eased = smooth01(progress);
season = lerp(transition.from, transition.to, eased);
if (progress >= 1) {
season = transition.to;
transition = null;
}
}
if (Math.abs(season - previousRenderedSeason) > 0.0001) {
updateDynamicScene(season);
previousRenderedSeason = season;
}
updateLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```