Prompt specification
Build or customize the Three.js 3D scene "Change pasture availability in a fictional seasonal cycle" 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: Change pasture availability in a fictional seasonal cycle
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/change-pasture-availability-in-a-fictional-seasonal-cy-x2628
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows seasonal pastoral mobility on the steppe. Let users adjust one grazing area's availability and choose an alternative route. Track distance and water access under stated assumptions without reducing real communities to a deterministic model. Low-poly.
Working Three.js Starter (change-pasture-availability-in-a-fictional-seasonal-cy-x2628):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Seasonal Mobility — Steppe Passage</title>
<style>
:root {
--ink: #263029;
--muted: #647064;
--paper: rgba(246, 241, 224, 0.94);
--paper-solid: #f6f1e0;
--line: rgba(57, 70, 58, 0.18);
--green: #607d54;
--green-dark: #3f6548;
--gold: #b7823c;
--blue: #4d8293;
--danger: #9b633e;
--shadow: 0 18px 50px rgba(39, 46, 35, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7c9a7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.map-label {
position: absolute;
left: 0;
top: 0;
padding: 5px 9px;
border: 1px solid rgba(45, 58, 48, 0.16);
border-radius: 999px;
background: rgba(249, 245, 229, 0.9);
box-shadow: 0 4px 14px rgba(45, 51, 42, 0.12);
color: #344138;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
white-space: nowrap;
will-change: transform;
transition: opacity 120ms ease;
}
.map-label.water {
color: #285f70;
border-color: rgba(54, 115, 134, 0.25);
}
.map-label.meadow {
color: #3d6945;
border-color: rgba(67, 111, 73, 0.24);
}
.map-label.camp {
color: #6e4c2d;
border-color: rgba(119, 80, 43, 0.23);
}
#panel {
position: fixed;
top: 18px;
left: 18px;
z-index: 10;
width: min(382px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
overscroll-behavior: contain;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 20px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(15px) saturate(1.08);
-webkit-backdrop-filter: blur(15px) saturate(1.08);
}
.eyebrow {
margin: 0 0 7px;
color: var(--green-dark);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 31px;
font-weight: 500;
line-height: 1.03;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.48;
}
.section {
padding: 16px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type {
border-top: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.section-title h2 {
margin: 0;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.field-label {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 13px;
font-weight: 750;
}
output {
color: var(--green-dark);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 5px 0 9px;
border-radius: 999px;
accent-color: var(--green);
cursor: pointer;
}
.help {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
select {
width: 100%;
min-height: 42px;
padding: 9px 34px 9px 11px;
border: 1px solid rgba(56, 72, 59, 0.23);
border-radius: 10px;
background: rgba(255, 255, 255, 0.58);
color: var(--ink);
font-size: 13px;
cursor: pointer;
}
.status {
display: flex;
align-items: flex-start;
gap: 8px;
margin-top: 11px;
padding: 10px 11px;
border-radius: 10px;
background: rgba(99, 127, 86, 0.11);
color: #486447;
font-size: 11px;
line-height: 1.4;
}
.status::before {
content: "";
flex: 0 0 auto;
width: 7px;
height: 7px;
margin-top: 4px;
border-radius: 50%;
background: currentColor;
}
.status.caution {
background: rgba(166, 108, 55, 0.12);
color: #86562f;
}
.status.neutral {
background: rgba(73, 104, 113, 0.1);
color: #416c79;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
button {
min-height: 39px;
border: 1px solid rgba(56, 72, 59, 0.23);
border-radius: 10px;
background: rgba(255, 255, 255, 0.56);
color: var(--ink);
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.86);
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: var(--green-dark);
background: var(--green-dark);
color: #fbf7e9;
}
button.primary:hover {
background: #365b40;
}
button.active {
border-color: var(--blue);
background: rgba(77, 130, 147, 0.15);
color: #315d6b;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.metric {
min-height: 124px;
padding: 14px;
border: 1px solid rgba(56, 72, 59, 0.15);
border-radius: 14px;
background: rgba(255, 255, 255, 0.43);
}
.metric-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
margin: 8px 0 2px;
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
font-weight: 500;
font-variant-numeric: tabular-nums;
letter-spacing: -0.035em;
}
.metric-note {
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.4;
}
.metric strong {
color: var(--ink);
font-weight: 750;
}
.mini-stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.mini-stat {
padding: 9px 10px;
border-radius: 10px;
background: rgba(72, 87, 71, 0.07);
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.mini-stat strong {
display: block;
margin-top: 3px;
color: var(--ink);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
margin-top: 12px;
color: var(--muted);
font-size: 10.5px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 15px;
height: 4px;
border-radius: 999px;
background: var(--green);
}
.swatch.bypass {
background: var(--gold);
}
.swatch.water {
background: var(--blue);
}
details {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
summary {
cursor: pointer;
color: var(--green-dark);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
details ul {
margin: 11px 0 0;
padding-left: 17px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
details li + li {
margin-top: 6px;
}
.disclaimer {
margin: 13px 0 0;
padding: 11px 12px;
border-left: 3px solid var(--gold);
background: rgba(183, 130, 60, 0.08);
color: #695c4b;
font-size: 10.5px;
line-height: 1.48;
}
#hint {
position: fixed;
right: 18px;
bottom: 16px;
z-index: 5;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 999px;
background: rgba(248, 244, 229, 0.75);
color: rgba(48, 59, 49, 0.78);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.02em;
pointer-events: none;
backdrop-filter: blur(10px);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #d7c9a7;
color: #52634d;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 700px) {
#panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 53vh;
padding: 16px;
border-radius: 16px;
}
h1 {
font-size: 26px;
}
.intro {
margin-bottom: 12px;
}
.section {
padding: 13px 0;
}
#hint {
top: 10px;
right: 10px;
bottom: auto;
}
.map-label {
font-size: 9px;
padding: 4px 7px;
}
.map-label.secondary {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly steppe landscape"></canvas>
<div id="labels" aria-hidden="true"></div>
<aside id="panel">
<p class="eyebrow">Seasonal mobility · scenario aid</p>
<h1>Pasture, water & passage</h1>
<p class="intro">
Explore one illustrative migration leg. Change a grazing-area scenario
and manually select a route; the scene tracks progress toward mapped
water points.
</p>
<section class="section">
<div class="section-title">
<h2>Plan a passage</h2>
<span class="eyebrow" style="margin: 0">Spring → autumn</span>
</div>
<label class="field-label" for="availability">
<span>Blue Meadow availability</span>
<output id="availabilityValue" for="availability">72%</output>
</label>
<input
id="availability"
type="range"
min="0"
max="100"
step="1"
value="72"
aria-describedby="availabilityHelp"
/>
<p id="availabilityHelp" class="help">
A user-set scenario value, not a measurement. For the north route,
values below 40% trigger an assumed bypass.
</p>
<label class="field-label" for="route" style="margin-top: 14px">
<span>Alternative route</span>
</label>
<select id="route">
<option value="north">North meadow + North Cistern</option>
<option value="south">South well route</option>
</select>
<div id="scenarioStatus" class="status">
Blue Meadow is included in the selected north route.
</div>
<div class="button-row">
<button id="play" class="primary" type="button">Play movement</button>
<button id="reset" type="button">Reset journey</button>
<button id="follow" type="button">Follow herd</button>
</div>
</section>
<section class="section">
<div class="section-title">
<h2>Route tracking</h2>
<span id="eta" class="help"></span>
</div>
<div class="metrics">
<article class="metric">
<div class="metric-label">Planned distance</div>
<div id="distanceValue" class="metric-value">—</div>
<p id="distanceRange" class="metric-note"></p>
<p class="metric-note" style="margin-top: 7px">
Traveled: <strong id="traveledValue">0.0 km</strong>
</p>
</article>
<article class="metric">
<div class="metric-label">Potential water reached</div>
<div id="waterValue" class="metric-value">0 / 2</div>
<p id="waterStatus" class="metric-note"></p>
<p class="metric-note" style="margin-top: 7px">
These are mapped sources, not guaranteed access.
</p>
</article>
</div>
<div class="mini-stats">
<div class="mini-stat">
Since last mapped water
<strong id="sinceWater">0.0 km</strong>
</div>
<div class="mini-stat">
Longest planned interval
<strong id="longestGap">—</strong>
</div>
</div>
<div class="legend" aria-label="Map legend">
<span><i class="swatch"></i> Selected north route</span>
<span><i class="swatch bypass"></i> Assumed bypass</span>
<span><i class="swatch water"></i> Water route</span>
</div>
</section>
<details>
<summary>Assumptions & limits</summary>
<ul>
<li>
Illustrative scale: 10 scene units represent 1 km. Distances are
straight-segment estimates with a ±15% planning band.
</li>
<li>
The 40% meadow threshold, the 12 km water-planning interval, and the
bypass alignment are illustrative assumptions, not local rules.
</li>
<li>
A rough moving-time estimate uses 4 km/h plus 30 minutes per mapped
water stop. The animation itself is time-compressed.
</li>
<li>
“Potential water” means a source shown on this fictional map.
Permissions, maintenance, weather, fees, and seasonal availability
are not known here.
</li>
<li>
The model omits herd health, labor, camp needs, social
relationships, contracts, land tenure, and changing conditions.
A plan may be revised at any point.
</li>
</ul>
</details>
<p class="disclaimer">
<strong>Scenario aid, not a prediction or recommendation.</strong>
This fictional landscape does not represent a named community or a
deterministic model of pastoral life. Local knowledge, negotiation,
and pastoralists’ own decisions remain central.
</p>
</aside>
<div id="hint">Drag to orbit · scroll to zoom · double-click to reset view</div>
<div id="loading">Loading the steppe…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// DOM references and shared state
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const availabilityInput = document.querySelector("#availability");
const availabilityValue = document.querySelector("#availabilityValue");
const routeInput = document.querySelector("#route");
const scenarioStatus = document.querySelector("#scenarioStatus");
const playButton = document.querySelector("#play");
const resetButton = document.querySelector("#reset");
const followButton = document.querySelector("#follow");
const distanceValue = document.querySelector("#distanceValue");
const distanceRange = document.querySelector("#distanceRange");
const traveledValue = document.querySelector("#traveledValue");
const waterValue = document.querySelector("#waterValue");
const waterStatus = document.querySelector("#waterStatus");
const sinceWater = document.querySelector("#sinceWater");
const longestGap = document.querySelector("#longestGap");
const eta = document.querySelector("#eta");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d9cbaa");
scene.fog = new THREE.Fog("#d9cbaa", 68, 145);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: 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 camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
300
);
const hemiLight = new THREE.HemisphereLight("#fff4cf", "#667052", 2.05);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight("#fff1c7", 2.6);
sun.position.set(-28, 48, 26);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -62;
sun.shadow.camera.right = 62;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 130;
sun.shadow.bias = -0.0004;
scene.add(sun);
const WORLD = {
unitsPerKm: 10,
waterPlanningIntervalKm: 12,
meadowThreshold: 40,
distanceUncertainty: 0.15,
movingSpeedKmPerHour: 4,
minutesPerWaterStop: 30
};
const locations = {
start: new THREE.Vector2(-34, 14),
meadow: new THREE.Vector2(-9, 7),
bypass: new THREE.Vector2(-3, 13),
northWater: new THREE.Vector2(3, -14),
southWater: new THREE.Vector2(-15, -22),
end: new THREE.Vector2(31, -7)
};
const routeColors = {
north: 0x507650,
bypass: 0xb57b37,
south: 0x467d90
};
let routeState = null;
let progress = 0;
let playing = false;
let followHerd = false;
let herdLeaderPosition = new THREE.Vector3();
// ------------------------------------------------------------
// Deterministic scene helpers
// ------------------------------------------------------------
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
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(82471);
function terrainHeight(x, z) {
return (
0.36 * Math.sin(x * 0.09) * Math.cos(z * 0.11) +
0.17 * Math.sin((x + z) * 0.16) +
0.28 * Math.exp(-((x - 22) ** 2 + (z + 19) ** 2) / 520)
);
}
function terrainColor(x, z) {
const meadowInfluence = Math.exp(
-(((x - locations.meadow.x) / 17) ** 2 +
((z - locations.meadow.y) / 12) ** 2)
);
const variation =
Math.sin(x * 0.23 + z * 0.12) * 0.5 +
Math.cos(z * 0.31 - x * 0.08) * 0.5;
const dry = new THREE.Color("#b9a461");
const olive = new THREE.Color("#8f9a58");
const green = new THREE.Color("#6f8b59");
const color = dry.clone().lerp(olive, 0.28 + variation * 0.12);
color.lerp(green, meadowInfluence * 0.72);
return color;
}
function groundPoint(x, z, lift = 0) {
return new THREE.Vector3(x, terrainHeight(x, z) + lift, z);
}
function pathLength(points) {
let length = 0;
for (let i = 1; i < points.length; i++) {
length += points[i].distanceTo(points[i - 1]);
}
return length;
}
function cumulativeLengths(points) {
const result = [0];
for (let i = 1; i < points.length; i++) {
result.push(result[i - 1] + points[i].distanceTo(points[i - 1]));
}
return result;
}
function densifyPath(points, subdivisions = 10) {
const result = [];
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
for (let step = 0; step < subdivisions; step++) {
const t = step / subdivisions;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.z, b.z, t);
result.push(groundPoint(x, z, 0.42));
}
}
result.push(groundPoint(points.at(-1).x, points.at(-1).z, 0.42));
return result;
}
function replaceRouteMesh(mesh, points) {
const dense = densifyPath(points);
const curve = new THREE.CurvePath();
for (let i = 1; i < dense.length; i++) {
curve.add(new THREE.LineCurve3(dense[i - 1], dense[i]));
}
const geometry = new THREE.TubeGeometry(
curve,
Math.max(80, dense.length * 2),
0.13,
5,
false
);
mesh.geometry.dispose();
mesh.geometry = geometry;
}
function makeGroundRibbon(points, width, material) {
const vertices = [];
const indices = [];
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const direction = b.clone().sub(a).normalize();
const perpendicular = new THREE.Vector3(-direction.z, 0, direction.x);
const half = width / 2;
const aLeft = a.clone().addScaledVector(perpendicular, half);
const aRight = a.clone().addScaledVector(perpendicular, -half);
const bLeft = b.clone().addScaledVector(perpendicular, half);
const bRight = b.clone().addScaledVector(perpendicular, -half);
const base = vertices.length / 3;
for (const p of [aLeft, aRight, bLeft, bRight]) {
vertices.push(p.x, terrainHeight(p.x, p.z) + 0.12, p.z);
}
indices.push(
base, base + 2, base + 1,
base + 2, base + 3, base + 1
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return new THREE.Mesh(geometry, material);
}
// ------------------------------------------------------------
// Low-poly terrain
// ------------------------------------------------------------
const terrainGeometry = new THREE.PlaneGeometry(120, 90, 36, 28);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPosition = terrainGeometry.attributes.position;
for (let i = 0; i < terrainPosition.count; i++) {
const x = terrainPosition.getX(i);
const z = terrainPosition.getZ(i);
terrainPosition.setY(i, terrainHeight(x, z));
}
const facetedTerrain = terrainGeometry.toNonIndexed();
terrainGeometry.dispose();
const terrainColors = [];
const terrainPositionNonIndexed = facetedTerrain.attributes.position;
for (let i = 0; i < terrainPositionNonIndexed.count; i += 3) {
const x =
(terrainPositionNonIndexed.getX(i) +
terrainPositionNonIndexed.getX(i + 1) +
terrainPositionNonIndexed.getX(i + 2)) /
3;
const z =
(terrainPositionNonIndexed.getZ(i) +
terrainPositionNonIndexed.getZ(i + 1) +
terrainPositionNonIndexed.getZ(i + 2)) /
3;
const color = terrainColor(x, z);
for (let j = 0; j < 3; j++) {
terrainColors.push(color.r, color.g, color.b);
}
}
facetedTerrain.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
facetedTerrain.computeVertexNormals();
const terrain = new THREE.Mesh(
facetedTerrain,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true
})
);
terrain.receiveShadow = true;
scene.add(terrain);
// A muted seasonal stream provides geographic context.
const streamMaterial = new THREE.MeshStandardMaterial({
color: "#719498",
roughness: 0.82,
metalness: 0.02,
side: THREE.DoubleSide
});
const stream = makeGroundRibbon(
[
new THREE.Vector3(3, 0, -14),
new THREE.Vector3(9, 0, -22),
new THREE.Vector3(25, 0, -31),
new THREE.Vector3(48, 0, -38)
],
1.5,
streamMaterial
);
// Correct the mixed Vector2/Vector3 stream points into Vector3 objects.
stream.geometry.dispose();
const correctedStream = makeGroundRibbon(
[
new THREE.Vector3(3, 0, -14),
new THREE.Vector3(9, 0, -22),
new THREE.Vector3(25, 0, -31),
new THREE.Vector3(48, 0, -38)
],
1.5,
streamMaterial
);
scene.add(correctedStream);
// ------------------------------------------------------------
// Grazing areas, water, camps, vegetation
// ------------------------------------------------------------
function makeEllipsePatch(center, radiusX, radiusZ, color, opacity = 0.38) {
const geometry = new THREE.CircleGeometry(1, 36);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI / 2;
mesh.scale.set(radiusX, radiusZ, 1);
mesh.position.copy(groundPoint(center.x, center.y, 0.09));
scene.add(mesh);
return mesh;
}
const meadowPatch = makeEllipsePatch(
locations.meadow,
13,
8,
0x5d8656,
0.42
);
makeEllipsePatch(
new THREE.Vector2(23, 18),
14,
9,
0xa18d50,
0.22
);
function makeWater(center, radiusX, radiusZ) {
const group = new THREE.Group();
group.position.copy(groundPoint(center.x, center.y, 0.16));
const pool = new THREE.Mesh(
new THREE.CircleGeometry(1, 11),
new THREE.MeshStandardMaterial({
color: "#4f8b9d",
roughness: 0.42,
metalness: 0.08,
flatShading: true,
side: THREE.DoubleSide
})
);
pool.rotation.x = -Math.PI / 2;
pool.scale.set(radiusX, radiusZ, 1);
pool.receiveShadow = true;
group.add(pool);
const stoneMaterial = new THREE.MeshStandardMaterial({
color: "#777465",
roughness: 1,
flatShading: true
});
for (let i = 0; i < 13; i++) {
const angle = (i / 13) * Math.PI * 2;
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.38 + random() * 0.23, 0),
stoneMaterial
);
stone.position.set(
Math.cos(angle) * radiusX * 1.05,
0.12,
Math.sin(angle) * radiusZ * 1.08
);
stone.scale.y = 0.55 + random() * 0.35;
stone.rotation.set(random(), random(), random());
stone.castShadow = true;
group.add(stone);
}
scene.add(group);
return group;
}
makeWater(locations.northWater, 3.3, 2.2);
makeWater(locations.southWater, 2.6, 1.9);
function makeYurt(position, roofColor) {
const group = new THREE.Group();
group.position.copy(groundPoint(position.x, position.y, 0));
const wall = new THREE.Mesh(
new THREE.CylinderGeometry(2.05, 2.05, 1.55, 8),
new THREE.MeshStandardMaterial({
color: "#e5dcc0",
roughness: 0.96,
flatShading: true
})
);
wall.position.y = 0.78;
wall.castShadow = true;
wall.receiveShadow = true;
group.add(wall);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.45, 1.35, 8),
new THREE.MeshStandardMaterial({
color: roofColor,
roughness: 0.9,
flatShading: true
})
);
roof.position.y = 2.18;
roof.castShadow = true;
group.add(roof);
const door = new THREE.Mesh(
new THREE.BoxGeometry(0.65, 1.05, 0.12),
new THREE.MeshStandardMaterial({
color: "#554636",
roughness: 1
})
);
door.position.set(0, 0.56, 1.99);
group.add(door);
scene.add(group);
return group;
}
makeYurt(locations.start, "#ad7145");
makeYurt(locations.end, "#547d83");
function makeShrub(x, z, scale = 1) {
const group = new THREE.Group();
group.position.copy(groundPoint(x, z, 0));
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.08, 0.12, 1.2, 5),
new THREE.MeshStandardMaterial({
color: "#66513b",
roughness: 1,
flatShading: true
})
);
trunk.position.y = 0.6;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.62, 0),
new THREE.MeshStandardMaterial({
color: random() > 0.5 ? "#61704d" : "#78805a",
roughness: 1,
flatShading: true
})
);
crown.position.y = 1.35;
crown.scale.set(1, 0.8, 1);
crown.castShadow = true;
group.add(crown);
group.scale.setScalar(scale);
scene.add(group);
}
for (let i = 0; i < 28; i++) {
const x = -55 + random() * 110;
const z = -39 + random() * 76;
const nearWater =
xzDistance(x, z, locations.northWater) < 7 ||
xzDistance(x, z, locations.southWater) < 6;
if (!nearWater && random() > 0.22) {
makeShrub(x, z, 0.7 + random() * 0.65);
}
}
function xzDistance(x, z, point) {
return Math.hypot(x - point.x, z - point.y);
}
const grassMaterial = new THREE.MeshStandardMaterial({
color: "#87905b",
roughness: 1,
flatShading: true
});
const grass = new THREE.InstancedMesh(
new THREE.ConeGeometry(0.12, 0.8, 3),
grassMaterial,
220
);
grass.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
const dummy = new THREE.Object3D();
const grassColor = new THREE.Color();
for (let i = 0; i < 220; i++) {
const x = -58 + random() * 116;
const z = -42 + random() * 84;
const scale = 0.45 + random() * 0.75;
dummy.position.set(x, terrainHeight(x, z) + 0.35 * scale, z);
dummy.rotation.set(0, random() * Math.PI, (random() - 0.5) * 0.25);
dummy.scale.set(scale, scale, scale);
dummy.updateMatrix();
grass.setMatrixAt(i, dummy.matrix);
grassColor.set(random() > 0.5 ? "#9a9b64" : "#7d8955");
grass.setColorAt(i, grassColor);
}
grass.instanceMatrix.needsUpdate = true;
if (grass.instanceColor) grass.instanceColor.needsUpdate = true;
scene.add(grass);
// Low-poly horizon mountains.
const mountainMaterials = [
new THREE.MeshStandardMaterial({
color: "#81775d",
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: "#91866a",
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: "#756e58",
roughness: 1,
flatShading: true
})
];
for (let i = 0; i < 13; i++) {
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(
7 + random() * 8,
5 + random() * 11,
5 + Math.floor(random() * 2)
),
mountainMaterials[i % mountainMaterials.length]
);
mountain.position.set(-58 + i * 9.4, 2.4, -43 - random() * 6);
mountain.rotation.y = random() * Math.PI;
mountain.scale.z = 0.65 + random() * 0.55;
mountain.castShadow = true;
scene.add(mountain);
}
// Sparse angular clouds.
const cloudMaterial = new THREE.MeshStandardMaterial({
color: "#f3edda",
roughness: 1,
flatShading: true
});
for (let cloudIndex = 0; cloudIndex < 4; cloudIndex++) {
const cloud = new THREE.Group();
cloud.position.set(-36 + cloudIndex * 24, 18 + random() * 7, -30);
for (let i = 0; i < 4; i++) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.4 + random() * 1.3, 0),
cloudMaterial
);
puff.position.set(i * 1.7 + random(), random(), random() * 0.8);
puff.scale.y = 0.55;
cloud.add(puff);
}
scene.add(cloud);
}
// ------------------------------------------------------------
// Routes
// ------------------------------------------------------------
function makeRouteMesh(color, opacity) {
const mesh = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
})
);
mesh.renderOrder = 2;
scene.add(mesh);
return mesh;
}
const northRouteMesh = makeRouteMesh(routeColors.north, 0.9);
const bypassRouteMesh = makeRouteMesh(routeColors.bypass, 0.15);
const southRouteMesh = makeRouteMesh(routeColors.south, 0.15);
const northDirectPoints = [
groundPoint(locations.start.x, locations.start.y),
groundPoint(locations.meadow.x, locations.meadow.y),
groundPoint(locations.northWater.x, locations.northWater.y),
groundPoint(locations.end.x, locations.end.y)
];
const northBypassPoints = [
groundPoint(locations.start.x, locations.start.y),
groundPoint(locations.bypass.x, locations.bypass.y),
groundPoint(locations.northWater.x, locations.northWater.y),
groundPoint(locations.end.x, locations.end.y)
];
const southRoutePoints = [
groundPoint(locations.start.x, locations.start.y),
groundPoint(locations.southWater.x, locations.southWater.y),
groundPoint(locations.end.x, locations.end.y)
];
replaceRouteMesh(northRouteMesh, northDirectPoints);
replaceRouteMesh(bypassRouteMesh, northBypassPoints);
replaceRouteMesh(southRouteMesh, southRoutePoints);
// ------------------------------------------------------------
// Herd
// ------------------------------------------------------------
const sheep = [];
const sheepBodyGeometry = new THREE.IcosahedronGeometry(0.58, 0);
const sheepHeadGeometry = new THREE.BoxGeometry(0.42, 0.38, 0.48);
const sheepLegGeometry = new THREE.CylinderGeometry(0.055, 0.07, 0.5, 5);
for (let i = 0; i < 13; i++) {
const animal = new THREE.Group();
const cream = new THREE.MeshStandardMaterial({
color: i % 4 === 0 ? "#9b8060" : "#e5ddc5",
roughness: 1,
flatShading: true
});
const dark = new THREE.MeshStandardMaterial({
color: "#4b4539",
roughness: 1,
flatShading: true
});
const body = new THREE.Mesh(sheepBodyGeometry, cream);
body.position.y = 0.72;
body.scale.set(1, 0.82, 1.22);
body.castShadow = true;
animal.add(body);
const head = new THREE.Mesh(sheepHeadGeometry, dark);
head.position.set(0, 0.8, 0.68);
head.castShadow = true;
animal.add(head);
for (const x of [-0.23, 0.23]) {
for (const z of [-0.3, 0.3]) {
const leg = new THREE.Mesh(sheepLegGeometry, dark);
leg.position.set(x, 0.27, z);
leg.castShadow = true;
animal.add(leg);
}
}
animal.scale.setScalar(0.86 + random() * 0.22);
scene.add(animal);
sheep.push(animal);
}
function sampleRoute(distanceAlongPath) {
const points = routeState.path;
const distance = clamp(distanceAlongPath, 0, routeState.length);
for (let i = 0; i < points.length - 1; i++) {
const segmentStart = routeState.cumulative[i];
const segmentEnd = routeState.cumulative[i + 1];
if (distance <= segmentEnd) {
const segmentLength = segmentEnd - segmentStart;
const t =
segmentLength === 0
? 0
: (distance - segmentStart) / segmentLength;
const point = points[i].clone().lerp(points[i + 1], t);
const tangent = points[i + 1]
.clone()
.sub(points[i])
.normalize();
return { point, tangent };
}
}
return {
point: points.at(-1).clone(),
tangent: points.at(-1).clone().sub(points.at(-2)).normalize()
};
}
function positionHerd() {
if (!routeState) return;
const traveledUnits = progress * routeState.length;
const sample = sampleRoute(traveledUnits);
herdLeaderPosition.copy(sample.point);
sheep.forEach((animal, index) => {
const behind = index * 0.88;
const individual = sampleRoute(traveledUnits - behind);
const side = ((index % 3) - 1) * 0.72;
const jitter = (index % 2 === 0 ? 0.12 : -0.12) * Math.sin(index * 2.7);
const perpendicular = new THREE.Vector3(
-individual.tangent.z,
0,
individual.tangent.x
);
animal.position.copy(individual.point);
animal.position.addScaledVector(perpendicular, side + jitter);
animal.position.y = terrainHeight(animal.position.x, animal.position.z) + 0.04;
animal.rotation.y = Math.atan2(
individual.tangent.x,
individual.tangent.z
);
});
}
// ------------------------------------------------------------
// Map labels
// ------------------------------------------------------------
const labelDefinitions = [
{
text: "Blue Meadow",
className: "meadow",
position: groundPoint(locations.meadow.x, locations.meadow.y, 2.4),
secondary: false
},
{
text: "North Cistern",
className: "water",
position: groundPoint(
locations.northWater.x,
locations.northWater.y,
2.4
),
secondary: false
},
{
text: "South Well",
className: "water",
position: groundPoint(
locations.southWater.x,
locations.southWater.y,
2.4
),
secondary: true
},
{
text: "Spring camp",
className: "camp",
position: groundPoint(locations.start.x, locations.start.y, 3),
secondary: false
},
{
text: "Autumn camp",
className: "camp",
position: groundPoint(locations.end.x, locations.end.y, 3),
secondary: false
}
];
const labels = labelDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = `map-label ${definition.className}`;
if (definition.secondary) element.classList.add("secondary");
element.textContent = definition.text;
document.querySelector("#labels").appendChild(element);
return { ...definition, element };
});
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
Math.abs(projected.x) > 1.15 ||
Math.abs(projected.y) > 1.15
) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.opacity = "1";
label.element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
}
// ------------------------------------------------------------
// Plan calculation and UI
// ------------------------------------------------------------
function updatePlan() {
const availability = Number(availabilityInput.value);
const selectedRoute = routeInput.value;
const bypassMeadow = availability < WORLD.meadowThreshold;
let path;
let waterEvents;
let note;
let statusClass = "";
if (selectedRoute === "north") {
path = bypassMeadow ? northBypassPoints : northDirectPoints;
const waterIndex = 2;
waterEvents = [
{
name: "Spring camp trough",
pathIndex: 0,
cumulative: 0
},
{
name: "North Cistern",
pathIndex: waterIndex,
cumulative: 0
},
{
name: "Autumn camp trough",
pathIndex: path.length - 1,
cumulative: 0
}
];
if (bypassMeadow) {
note =
"Blue Meadow is constrained under this scenario; the north route adds an assumed bypass around the meadow.";
statusClass = "caution";
} else {
note =
"Blue Meadow is included as a grazing stop on the selected north route.";
}
} else {
path = southRoutePoints;
waterEvents = [
{
name: "Spring camp trough",
pathIndex: 0,
cumulative: 0
},
{
name: "South Well",
pathIndex: 1,
cumulative: 0
},
{
name: "Autumn camp trough",
pathIndex: 2,
cumulative: 0
}
];
note =
"The south route avoids Blue Meadow, so the meadow slider does not change this path's distance.";
statusClass = "neutral";
}
const cumulative = cumulativeLengths(path);
const length = cumulative.at(-1);
for (const event of waterEvents) {
event.cumulative = cumulative[event.pathIndex];
}
routeState = {
path,
cumulative,
length,
waterEvents,
availability,
selectedRoute,
bypassMeadow
};
availabilityValue.value = `${availability}%`;
scenarioStatus.textContent = note;
scenarioStatus.className = `status ${statusClass}`;
northRouteMesh.material.opacity =
selectedRoute === "north" && !bypassMeadow ? 0.95 : 0.16;
bypassRouteMesh.material.opacity =
selectedRoute === "north" && bypassMeadow ? 0.95 : 0.12;
southRouteMesh.material.opacity =
selectedRoute === "south" ? 0.95 : 0.16;
meadowPatch.material.opacity =
selectedRoute === "south" ? 0.26 : 0.42 + availability * 0.0012;
updateMetrics();
positionHerd();
}
function updateMetrics() {
if (!routeState) return;
const distanceKm =
routeState.length / WORLD.unitsPerKm;
const low = distanceKm * (1 - WORLD.distanceUncertainty);
const high = distanceKm * (1 + WORLD.distanceUncertainty);
const traveledKm =
(progress * routeState.length) / WORLD.unitsPerKm;
const reachedEvents = routeState.waterEvents.filter(
(event, index) =>
index > 0 && event.cumulative <= progress * routeState.length
);
const nextEvent = routeState.waterEvents.find(
(event) => event.cumulative > progress * routeState.length
);
const previousEvents = routeState.waterEvents.filter(
(event) => event.cumulative <= progress * routeState.length
);
const lastWater =
previousEvents.length > 0
? previousEvents.at(-1).cumulative
: 0;
const sinceWaterKm =
(progress * routeState.length - lastWater) / WORLD.unitsPerKm;
let maximumGapUnits = 0;
for (let i = 1; i < routeState.waterEvents.length; i++) {
maximumGapUnits = Math.max(
maximumGapUnits,
routeState.waterEvents[i].cumulative -
routeState.waterEvents[i - 1].cumulative
);
}
const maximumGapKm = maximumGapUnits / WORLD.unitsPerKm;
const potentialStops = routeState.waterEvents.length - 1;
distanceValue.textContent = `${distanceKm.toFixed(1)} km`;
distanceRange.textContent =
`±15% planning band: ${low.toFixed(1)}–${high.toFixed(1)} km`;
traveledValue.textContent = `${traveledKm.toFixed(1)} km`;
waterValue.textContent = `${reachedEvents.length} / ${potentialStops}`;
if (nextEvent) {
const remainingKm =
(nextEvent.cumulative - progress * routeState.length) /
WORLD.unitsPerKm;
waterStatus.textContent =
`Next: ${nextEvent.name}, ${remainingKm.toFixed(1)} km ahead`;
} else {
waterStatus.textContent = "All mapped potential stops reached";
}
sinceWater.textContent = `${sinceWaterKm.toFixed(1)} km`;
longestGap.textContent =
`${maximumGapKm.toFixed(1)} / ${WORLD.waterPlanningIntervalKm} km`;
const movingHours = distanceKm / WORLD.movingSpeedKmPerHour;
const totalHours =
movingHours +
(potentialStops * WORLD.minutesPerWaterStop) / 60;
eta.textContent = `Rough estimate: ${totalHours.toFixed(1)} h incl. stops`;
}
// ------------------------------------------------------------
// Direct camera controls — no external control addon
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-2, 0, -3);
let cameraYaw = 0.62;
let cameraPitch = 0.69;
let cameraDistance = 88;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function resetCamera() {
cameraYaw = 0.62;
cameraPitch = 0.69;
cameraDistance = 88;
cameraTarget.set(-2, 0, -3);
followHerd = false;
followButton.classList.remove("active");
followButton.textContent = "Follow herd";
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraYaw -= dx * 0.005;
cameraPitch = clamp(cameraPitch + dy * 0.004, 0.28, 1.35);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
function endDrag(event) {
dragging = 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(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = clamp(
cameraDistance + event.deltaY * 0.045,
35,
125
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
function updateCamera(dt) {
if (followHerd) {
const desired = herdLeaderPosition.clone();
desired.y = 0;
cameraTarget.lerp(desired, 1 - Math.pow(0.001, dt));
}
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraDistance,
cameraPitch,
cameraYaw
);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
// ------------------------------------------------------------
// Interaction
// ------------------------------------------------------------
availabilityInput.addEventListener("input", updatePlan);
routeInput.addEventListener("change", updatePlan);
playButton.addEventListener("click", () => {
if (progress >= 1) progress = 0;
playing = !playing;
playButton.textContent = playing
? "Pause movement"
: "Play movement";
});
resetButton.addEventListener("click", () => {
progress = 0;
playing = false;
playButton.textContent = "Play movement";
updateMetrics();
positionHerd();
});
followButton.addEventListener("click", () => {
followHerd = !followHerd;
followButton.classList.toggle("active", followHerd);
followButton.textContent = followHerd
? "Following herd"
: "Follow herd";
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
let metricAccumulator = 0;
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (playing && routeState) {
// Time-compressed visual movement.
progress += (dt * routeState.length * 0.055) / routeState.length;
if (progress >= 1) {
progress = 1;
playing = false;
playButton.textContent = "Play movement";
}
}
positionHerd();
updateCamera(dt);
updateLabels();
metricAccumulator += dt;
if (metricAccumulator > 0.12) {
updateMetrics();
metricAccumulator = 0;
}
renderer.render(scene, camera);
}
updatePlan();
resetCamera();
loading.remove();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```