Prompt specification
Build or customize the Three.js 3D scene "Seasonal grazing circuit across a steppe landscape" 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: Seasonal grazing circuit across a steppe landscape
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/seasonal-grazing-circuit-across-a-steppe-landscape-x2627
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: Seasonal grazing circuit across a steppe landscape. Build a schematic regional landscape with winter shelter, summer pasture, water points, and return routes. Use sourced context and distinguish recurring mobility from a one-way migration.
Working Three.js Starter (seasonal-grazing-circuit-across-a-steppe-landscape-x2627):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Steppe — Seasonal Grazing Circuit</title>
<style>
:root {
--ink: #172521;
--paper: #f2efe2;
--muted: #b8c0b1;
--cyan: #48d7cf;
--gold: #ffd166;
--coral: #ff7163;
--panel: rgba(19, 32, 28, 0.9);
--line: rgba(242, 239, 226, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8dacb;
color: var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
a {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 3;
}
.map-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: max-content;
padding: 7px 10px 7px 7px;
border: 1px solid rgba(255, 255, 255, 0.36);
border-radius: 5px;
background: rgba(24, 35, 31, 0.84);
box-shadow: 0 7px 22px rgba(28, 34, 27, 0.18);
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
white-space: nowrap;
}
.map-label .number {
display: grid;
place-items: center;
width: 23px;
height: 23px;
border-radius: 3px;
background: var(--gold);
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.03em;
}
.map-label b {
display: block;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.03em;
}
.map-label small {
display: block;
margin-top: 1px;
color: #c8cec1;
font-size: 9px;
letter-spacing: 0.035em;
}
.map-label.water .number {
background: #76c7e3;
}
.map-label.oneway .number {
background: var(--coral);
}
.ui {
position: fixed;
z-index: 5;
}
.brand {
top: 24px;
left: 28px;
max-width: 480px;
pointer-events: none;
text-shadow: 0 1px 18px rgba(255, 255, 255, 0.35);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: #33433c;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 34px;
height: 2px;
background: var(--cyan);
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}
.brand h1 {
margin: 8px 0 7px;
color: var(--ink);
font-size: clamp(26px, 3.8vw, 52px);
font-weight: 820;
line-height: 0.96;
letter-spacing: -0.045em;
}
.brand p {
max-width: 470px;
margin: 0;
color: #3e4a44;
font-size: 12px;
line-height: 1.5;
}
.schematic-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 6px 8px;
border: 1px solid rgba(23, 37, 33, 0.25);
border-radius: 3px;
background: rgba(242, 239, 226, 0.66);
color: #34433d;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.schematic-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--coral);
}
.panel {
top: 22px;
right: 22px;
width: 326px;
max-height: calc(100vh - 44px);
overflow: auto;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 10px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(23, 30, 25, 0.26);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
scrollbar-width: thin;
scrollbar-color: #52645c transparent;
}
.panel-section {
padding: 17px 18px;
border-bottom: 1px solid var(--line);
}
.panel-section:last-child {
border-bottom: 0;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
}
.panel h2 {
margin: 0;
color: #f5f0df;
font-size: 10px;
font-weight: 820;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.overview-button {
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 3px;
background: transparent;
color: #d9dfd2;
font-size: 9px;
font-weight: 700;
cursor: pointer;
}
.overview-button:hover {
background: rgba(255, 255, 255, 0.08);
}
.season-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.season-button {
position: relative;
min-height: 62px;
padding: 10px 10px 9px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 6px;
background: rgba(255, 255, 255, 0.035);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.season-button::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
background: var(--season-color);
opacity: 0.7;
}
.season-button:hover,
.season-button.active {
border-color: color-mix(in srgb, var(--season-color) 70%, white 10%);
background: color-mix(in srgb, var(--season-color) 13%, transparent);
transform: translateY(-1px);
}
.season-button b {
display: block;
color: #f5f0df;
font-size: 11px;
font-weight: 760;
}
.season-button span {
display: block;
margin-top: 4px;
color: #b9c2b7;
font-size: 9px;
line-height: 1.35;
}
.season-copy {
margin: 12px 0 0;
color: #cbd1c5;
font-size: 10px;
line-height: 1.55;
}
.season-copy strong {
color: #f3efdf;
font-weight: 760;
}
.legend-row {
display: grid;
grid-template-columns: 40px 1fr;
align-items: center;
gap: 8px;
margin-top: 9px;
color: #d6dbd1;
font-size: 10px;
line-height: 1.35;
}
.legend-row:first-of-type {
margin-top: 0;
}
.legend-symbol {
position: relative;
height: 18px;
}
.legend-symbol.circuit::before {
content: "";
position: absolute;
top: 8px;
left: 0;
right: 0;
height: 3px;
border-radius: 3px;
background: var(--cyan);
box-shadow: 0 0 8px rgba(72, 215, 207, 0.4);
}
.legend-symbol.circuit::after {
content: "";
position: absolute;
top: 3px;
right: 1px;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 9px solid var(--cyan);
}
.legend-symbol.one-way::before {
content: "";
position: absolute;
top: 8px;
left: 0;
right: 0;
border-top: 3px dashed var(--coral);
}
.legend-symbol.one-way::after {
content: "";
position: absolute;
top: 3px;
right: 1px;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 9px solid var(--coral);
}
.legend-symbol.water::before {
content: "";
position: absolute;
top: 5px;
left: 2px;
width: 32px;
height: 9px;
border-radius: 50% 40% 48% 35%;
background: #68bad5;
transform: rotate(-5deg);
}
.legend-symbol.return::before {
content: "↩";
position: absolute;
left: 4px;
top: -2px;
color: var(--gold);
font-size: 20px;
font-weight: 800;
}
.context-copy {
margin: 0;
color: #bdc6ba;
font-size: 10px;
line-height: 1.55;
}
.context-copy strong {
color: #f0eddd;
}
.sources {
margin: 10px 0 0;
padding: 0;
list-style: none;
}
.sources li {
margin: 7px 0;
}
.sources a {
color: #b9e6dc;
font-size: 9px;
line-height: 1.35;
text-decoration: none;
border-bottom: 1px solid rgba(185, 230, 220, 0.28);
}
.sources a:hover {
color: #ffffff;
border-bottom-color: #ffffff;
}
.source-note {
margin-top: 10px;
color: #8f9c91;
font-size: 8.5px;
line-height: 1.45;
}
.legend-card {
left: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 18px;
padding: 12px 15px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 8px;
background: rgba(20, 32, 28, 0.87);
box-shadow: 0 10px 35px rgba(26, 32, 26, 0.2);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.legend-card .legend-row {
grid-template-columns: 32px auto;
margin: 0;
white-space: nowrap;
}
.legend-divider {
width: 1px;
height: 35px;
background: var(--line);
}
.compass {
position: relative;
display: grid;
place-items: center;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
color: #f4efdf;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
}
.compass::before {
content: "";
position: absolute;
top: 5px;
width: 1px;
height: 7px;
background: var(--gold);
transform-origin: 50% 14px;
}
#compassNeedle {
position: absolute;
top: 5px;
width: 1px;
height: 14px;
background: var(--gold);
transform-origin: 50% 100%;
}
.controls {
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 6px;
background: rgba(20, 32, 28, 0.84);
color: #c9d0c4;
font-size: 9px;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.controls span {
white-space: nowrap;
}
.controls b {
color: #f3efdf;
font-weight: 700;
}
.key {
display: inline-grid;
place-items: center;
min-width: 19px;
height: 19px;
margin: 0 2px;
padding: 0 4px;
border: 1px solid rgba(255, 255, 255, 0.28);
border-bottom-width: 2px;
border-radius: 3px;
color: #f4efdf;
font-size: 8px;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d8dacb;
color: #263a32;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-inner {
text-align: center;
}
.loading-ring {
width: 34px;
height: 34px;
margin: 0 auto 13px;
border: 3px solid rgba(38, 58, 50, 0.18);
border-top-color: var(--cyan);
border-radius: 50%;
animation: spin 0.9s linear infinite;
}
.loading-inner strong {
display: block;
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.loading-inner small {
display: block;
margin-top: 6px;
color: #637069;
font-size: 9px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@media (max-width: 960px) {
.brand {
top: 16px;
left: 17px;
max-width: 55vw;
}
.brand p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 60px;
width: min(330px, calc(100vw - 24px));
max-height: 48vh;
}
.legend-card {
left: 12px;
bottom: 12px;
gap: 10px;
padding: 9px 10px;
}
.legend-card .legend-row:nth-of-type(3) {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
.controls span:last-child {
display: none;
}
}
@media (max-width: 620px) {
.brand h1 {
font-size: 27px;
}
.schematic-badge {
display: none;
}
.panel {
max-height: 42vh;
}
.panel-section {
padding: 13px 14px;
}
.legend-card {
max-width: 205px;
}
.legend-card .legend-row:nth-of-type(2),
.legend-card .legend-divider {
display: none;
}
.controls {
padding: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly schematic of a seasonal steppe grazing circuit"></canvas>
<div id="labels" aria-hidden="true"></div>
<header class="brand ui">
<div class="eyebrow">Steppe mobility atlas · 01</div>
<h1>Seasonal Grazing<br>Circuit</h1>
<p>
A schematic regional landscape connecting sheltered winter ground,
seasonal pasture, and dependable water before returning to winter range.
</p>
<div class="schematic-badge">Illustrative · not to scale</div>
</header>
<aside class="panel ui" aria-label="Scene information">
<section class="panel-section">
<div class="panel-heading">
<h2>Seasonal sequence</h2>
<button class="overview-button" id="overview">Overview</button>
</div>
<div class="season-grid">
<button class="season-button" data-season="winter" style="--season-color:#e49a71">
<b>01 · Winter</b>
<span>Sheltered basin and stored fodder</span>
</button>
<button class="season-button" data-season="spring" style="--season-color:#65c5ba">
<b>02 · Spring</b>
<span>Water points and pasture recovery</span>
</button>
<button class="season-button" data-season="summer" style="--season-color:#f3c85e">
<b>03 · Summer</b>
<span>Open upland pasture</span>
</button>
<button class="season-button" data-season="autumn" style="--season-color:#bd91c8">
<b>04 · Autumn</b>
<span>Descent and return movement</span>
</button>
</div>
<p class="season-copy" id="seasonCopy">
<strong>Overview:</strong> select a season to inspect its role in the closed circuit.
</p>
</section>
<section class="panel-section">
<div class="panel-heading">
<h2>Reading the routes</h2>
</div>
<div class="legend-row">
<div class="legend-symbol circuit"></div>
<div><strong>Recurring circuit</strong><br>Seasonal movement that reconnects with winter range.</div>
</div>
<div class="legend-row">
<div class="legend-symbol return"></div>
<div><strong>Return movement</strong><br>Gold chevrons indicate the return along the closed route.</div>
</div>
<div class="legend-row">
<div class="legend-symbol water"></div>
<div><strong>Water point</strong><br>River, well, pond, and trough form the seasonal network.</div>
</div>
<div class="legend-row">
<div class="legend-symbol one-way"></div>
<div><strong>One-way migration</strong><br>Coral comparator only; it ends away from its origin.</div>
</div>
</section>
<section class="panel-section">
<div class="panel-heading">
<h2>Context & limits</h2>
</div>
<p class="context-copy">
This is a synthesized teaching diagram of steppe pastoral mobility,
not a surveyed route map. Its logic follows broad features described
for Eurasian and Mongolian pastoral systems: seasonal movement responds
to variable forage and water, with recurring links among camps,
pasture, and dependable water points.
</p>
<p class="context-copy" style="margin-top:10px">
The turquoise line is a <strong>closed, recurring circuit</strong>.
The coral dashed line is a deliberate <strong>one-way contrast</strong>,
not a second documented local corridor.
</p>
<ul class="sources">
<li>
<a href="https://www.fao.org/livestockagriculture/en/pastoralism/" target="_blank" rel="noopener">
FAO · Pastoralism and mobility in rangeland systems
</a>
</li>
<li>
<a href="https://www.fao.org/4/i1520e/i1520e00.htm" target="_blank" rel="noopener">
FAO · Pastoralism in the global land use perspective (2009)
</a>
</li>
<li>
<a href="https://www.worldwildlife.org/ecoregions/mongolian-steppe" target="_blank" rel="noopener">
WWF · Mongolian Steppe ecoregion context
</a>
</li>
</ul>
<p class="source-note">
Route geometry, camp placement, boundaries, and animal positions are
diagrammatic. The regional scene is inspired by, but does not reproduce,
a specific community, herd, or documented journey.
</p>
</section>
</aside>
<div class="legend-card ui" aria-label="Map legend">
<div class="compass" aria-hidden="true">
N
<i id="compassNeedle"></i>
</div>
<div class="legend-row">
<div class="legend-symbol circuit"></div>
<div>Recurring seasonal circuit</div>
</div>
<div class="legend-divider"></div>
<div class="legend-row">
<div class="legend-symbol water"></div>
<div>Water network</div>
</div>
<div class="legend-divider"></div>
<div class="legend-row">
<div class="legend-symbol one-way"></div>
<div>One-way comparator</div>
</div>
</div>
<div class="controls ui" aria-label="Camera controls">
<span><b>Drag</b> orbit</span>
<span><span class="key">⇅</span> zoom</span>
<span><span class="key">R</span> reset</span>
</div>
<div id="loading">
<div class="loading-inner">
<div class="loading-ring"></div>
<strong>Building the steppe</strong>
<small>Terrain, routes, camps and seasonal markers</small>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
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);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d8dacb");
scene.fog = new THREE.Fog("#d8dacb", 80, 165);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
300
);
const hemi = new THREE.HemisphereLight("#fff7d8", "#69755d", 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0ca", 3.0);
sun.position.set(-30, 55, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
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 rim = new THREE.DirectionalLight("#b8ddd8", 0.85);
rim.position.set(32, 22, -35);
scene.add(rim);
const world = new THREE.Group();
scene.add(world);
const W = 90;
const D = 68;
const up = new THREE.Vector3(0, 1, 0);
// Deterministic pseudo-random helper keeps the scene stable.
let seed = 74391;
function rand() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function clamp(v, min, max) {
return Math.max(min, Math.min(max, v));
}
function terrainHeight(x, z) {
let h =
0.72 * Math.sin(x * 0.095) * Math.cos(z * 0.11) +
0.38 * Math.cos((x + z) * 0.17);
h += 5.6 * Math.exp(
-((x - 25) ** 2) / 520 - ((z + 18) ** 2) / 330
);
h += 2.1 * Math.exp(
-((x - 7) ** 2) / 440 - ((z - 8) ** 2) / 300
);
h -= 1.25 * Math.exp(
-((x + 25) ** 2) / 300 - ((z - 18) ** 2) / 240
);
h += (z + 30) * 0.006;
return h;
}
function distanceToSegment2D(px, pz, ax, az, bx, bz) {
const abx = bx - ax;
const abz = bz - az;
const apx = px - ax;
const apz = pz - az;
const denom = abx * abx + abz * abz;
const t = denom === 0 ? 0 : clamp((apx * abx + apz * abz) / denom, 0, 1);
const x = ax + abx * t;
const z = az + abz * t;
return Math.hypot(px - x, pz - z);
}
const riverGroundPoints = [
[-11, 30],
[-8, 23],
[-4, 15],
[0, 7],
[5, 0],
[12, -7],
[21, -15],
[31, -20],
[40, -19]
];
function distanceToRiver(x, z) {
let d = Infinity;
for (let i = 0; i < riverGroundPoints.length - 1; i++) {
const a = riverGroundPoints[i];
const b = riverGroundPoints[i + 1];
d = Math.min(d, distanceToSegment2D(x, z, a[0], a[1], b[0], b[1]));
}
return d;
}
// -------------------------------------------------------------------------
// Terrain
// -------------------------------------------------------------------------
let terrainGeometry = new THREE.PlaneGeometry(W, D, 30, 22);
terrainGeometry.rotateX(-Math.PI / 2);
let terrainPositions = terrainGeometry.attributes.position;
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const z = terrainPositions.getZ(i);
terrainPositions.setY(i, terrainHeight(x, z));
}
terrainGeometry = terrainGeometry.toNonIndexed();
terrainPositions = terrainGeometry.attributes.position;
const terrainColors = [];
const terrainColor = new THREE.Color();
for (let i = 0; i < terrainPositions.count; i += 3) {
const cx = (
terrainPositions.getX(i) +
terrainPositions.getX(i + 1) +
terrainPositions.getX(i + 2)
) / 3;
const cz = (
terrainPositions.getZ(i) +
terrainPositions.getZ(i + 1) +
terrainPositions.getZ(i + 2)
) / 3;
const h = terrainHeight(cx, cz);
const moisture = clamp(1 - distanceToRiver(cx, cz) / 14, 0, 1);
if (h > 4.3) {
terrainColor.set("#7f8c57").lerp(new THREE.Color("#64734c"), moisture * 0.35);
} else if (moisture > 0.58) {
terrainColor.set("#899663").lerp(new THREE.Color("#66875a"), 0.34);
} else {
terrainColor.set("#b2a269").lerp(new THREE.Color("#8e9b61"), moisture * 0.58);
}
if (cx < -17 && cz > 10) {
terrainColor.lerp(new THREE.Color("#c0ae7b"), 0.24);
}
const shade = 0.88 + rand() * 0.22;
terrainColor.multiplyScalar(shade);
for (let j = 0; j < 3; j++) {
terrainColors.push(terrainColor.r, terrainColor.g, terrainColor.b);
}
}
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
terrain.receiveShadow = true;
world.add(terrain);
// A dark plinth makes the diagram read as a physical landscape model.
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(W + 0.5, 3.2, D + 0.5),
new THREE.MeshStandardMaterial({
color: "#655d46",
roughness: 0.94,
flatShading: true
})
);
plinth.position.y = -3.55;
plinth.receiveShadow = true;
world.add(plinth);
// Terrain edge walls.
const perimeter = [];
const edgeSteps = 12;
function addEdge(x1, z1, x2, z2) {
for (let i = 0; i < edgeSteps; i++) {
const t = i / edgeSteps;
perimeter.push([
THREE.MathUtils.lerp(x1, x2, t),
THREE.MathUtils.lerp(z1, z2, t)
]);
}
}
addEdge(-W / 2, -D / 2, W / 2, -D / 2);
addEdge(W / 2, -D / 2, W / 2, D / 2);
addEdge(W / 2, D / 2, -W / 2, D / 2);
addEdge(-W / 2, D / 2, -W / 2, -D / 2);
const edgePositions = [];
const edgeIndices = [];
for (const [x, z] of perimeter) {
edgePositions.push(x, terrainHeight(x, z), z, x, -3.15, z);
}
for (let i = 0; i < perimeter.length; i++) {
const a = i * 2;
const b = ((i + 1) % perimeter.length) * 2;
edgeIndices.push(a, b, a + 1, b, b + 1, a + 1);
}
const edgeGeometry = new THREE.BufferGeometry();
edgeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(edgePositions, 3)
);
edgeGeometry.setIndex(edgeIndices);
edgeGeometry.computeVertexNormals();
const edges = new THREE.Mesh(
edgeGeometry,
new THREE.MeshStandardMaterial({
color: "#756a4c",
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
edges.castShadow = true;
edges.receiveShadow = true;
world.add(edges);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(260, 260),
new THREE.MeshStandardMaterial({
color: "#c9c8ae",
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -5.2;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Region patches, water and boundary lines
// -------------------------------------------------------------------------
function createPatch(cx, cz, rx, rz, color, opacity, irregular = false, water = false) {
const segments = 18;
const rings = water ? 3 : 4;
const positions = [cx, terrainHeight(cx, cz) + 0.075, cz];
const indices = [];
for (let ring = 1; ring <= rings; ring++) {
const t = ring / rings;
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const wobble = irregular
? 0.88 + 0.12 * Math.sin(i * 12.73 + ring * 1.9)
: 1;
const x = cx + Math.cos(angle) * rx * t * wobble;
const z = cz + Math.sin(angle) * rz * t * wobble;
positions.push(x, terrainHeight(x, z) + 0.075, z);
}
}
for (let i = 0; i < segments; i++) {
indices.push(0, 1 + i, 1 + ((i + 1) % segments));
}
for (let ring = 0; ring < rings - 1; ring++) {
const a = 1 + ring * segments;
const b = a + segments;
for (let i = 0; i < segments; i++) {
const next = (i + 1) % segments;
indices.push(a + i, b + i, a + next);
indices.push(a + next, b + i, b + next);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = water
? new THREE.MeshStandardMaterial({
color,
roughness: 0.28,
metalness: 0.05,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
})
: new THREE.MeshStandardMaterial({
color,
roughness: 1,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
world.add(mesh);
return mesh;
}
function createPatchBoundary(cx, cz, rx, rz, color) {
const points = [];
for (let i = 0; i < 40; i++) {
const a = (i / 40) * Math.PI * 2;
const x = cx + Math.cos(a) * rx;
const z = cz + Math.sin(a) * rz;
points.push(new THREE.Vector3(x, terrainHeight(x, z) + 0.13, z));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.LineLoop(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.62
})
);
world.add(line);
}
createPatch(-25, 18, 8.4, 6.3, "#e49a71", 0.20);
createPatch(-3, 7, 7.0, 5.2, "#65c5ba", 0.19);
createPatch(24, -17, 9.4, 6.8, "#f3c85e", 0.19);
createPatch(10, 18, 7.4, 5.5, "#bd91c8", 0.18);
createPatchBoundary(-25, 18, 8.4, 6.3, "#f1b58b");
createPatchBoundary(-3, 7, 7.0, 5.2, "#95e1d8");
createPatchBoundary(24, -17, 9.4, 6.8, "#f8d982");
createPatchBoundary(10, 18, 7.4, 5.5, "#d5addf");
// River ribbon.
const riverCurve = new THREE.CatmullRomCurve3(
riverGroundPoints.map(([x, z]) => new THREE.Vector3(x, 0, z)),
false,
"catmullrom",
0.25
);
const riverPositions = [];
const riverIndices = [];
const riverSamples = 90;
for (let i = 0; i <= riverSamples; i++) {
const t = i / riverSamples;
const p = riverCurve.getPoint(t);
const tangent = riverCurve.getTangent(t).setY(0).normalize();
const perpendicular = new THREE.Vector3(-tangent.z, 0, tangent.x);
const width = 0.72 + 0.15 * Math.sin(i * 0.37);
const left = p.clone().addScaledVector(perpendicular, width);
const right = p.clone().addScaledVector(perpendicular, -width);
riverPositions.push(
left.x, terrainHeight(left.x, left.z) + 0.10, left.z,
right.x, terrainHeight(right.x, right.z) + 0.10, right.z
);
if (i < riverSamples) {
const a = i * 2;
riverIndices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const riverGeometry = new THREE.BufferGeometry();
riverGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(riverPositions, 3)
);
riverGeometry.setIndex(riverIndices);
riverGeometry.computeVertexNormals();
const river = new THREE.Mesh(
riverGeometry,
new THREE.MeshStandardMaterial({
color: "#64b5cd",
roughness: 0.34,
metalness: 0.04,
transparent: true,
opacity: 0.92,
side: THREE.DoubleSide
})
);
river.receiveShadow = true;
world.add(river);
createPatch(2.1, 1.2, 2.4, 1.55, "#70bdd1", 0.96, true, true);
createPatch(-12.4, 19.7, 1.25, 0.9, "#70bdd1", 0.96, true, true);
createPatch(9.0, -6.0, 1.1, 0.85, "#70bdd1", 0.96, true, true);
// -------------------------------------------------------------------------
// Route geometry
// -------------------------------------------------------------------------
const circuitGroundPoints = [
[-25, 18],
[-17, 12],
[-3, 7],
[5, 0],
[13, -8],
[24, -17],
[20, -4],
[10, 18],
[-1, 22],
[-13, 20],
[-25, 18]
];
const circuitCurve = new THREE.CatmullRomCurve3(
circuitGroundPoints.map(([x, z]) =>
new THREE.Vector3(x, terrainHeight(x, z) + 0.34, z)
),
true,
"catmullrom",
0.32
);
const circuitMaterial = new THREE.MeshStandardMaterial({
color: "#48d7cf",
emissive: "#1b807a",
emissiveIntensity: 0.45,
roughness: 0.62
});
const circuit = new THREE.Mesh(
new THREE.TubeGeometry(circuitCurve, 180, 0.14, 6, true),
circuitMaterial
);
circuit.castShadow = true;
world.add(circuit);
function addDirectionArrow(point, tangent, color, size = 1) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.38 * size, 1.05 * size, 3),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.28,
roughness: 0.6,
flatShading: true
})
);
arrow.position.copy(point);
arrow.quaternion.setFromUnitVectors(up, tangent.clone().normalize());
arrow.castShadow = true;
world.add(arrow);
}
// Gold arrows distinguish the descending / return movement.
const returnArrowIndices = [0.63, 0.70, 0.77, 0.84, 0.91, 0.97];
for (const t of returnArrowIndices) {
const point = circuitCurve.getPointAt(t);
const tangent = circuitCurve.getTangentAt(t);
addDirectionArrow(point, tangent, "#ffd166", 1.0);
}
// Cyan arrows distinguish the spring / summer ascent.
for (const t of [0.05, 0.13, 0.21, 0.29, 0.37, 0.45]) {
const point = circuitCurve.getPointAt(t);
const tangent = circuitCurve.getTangentAt(t);
addDirectionArrow(point, tangent, "#48d7cf", 0.82);
}
// Junctions.
for (const [x, z] of [[-25, 18], [-3, 7], [24, -17], [10, 18]]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.075, 6, 22),
new THREE.MeshStandardMaterial({
color: "#f6f0d9",
emissive: "#776f43",
emissiveIntensity: 0.25,
roughness: 0.65
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, terrainHeight(x, z) + 0.43, z);
world.add(ring);
}
// One-way movement comparator: deliberately dashed, coral, and non-returning.
const oneWayGround = [
[-39, 27],
[-27, 28.5],
[-11, 28],
[7, 28.5],
[24, 27.5],
[38, 25.5]
];
const oneWayCurve = new THREE.CatmullRomCurve3(
oneWayGround.map(([x, z]) =>
new THREE.Vector3(x, terrainHeight(x, z) + 0.31, z)
),
false,
"catmullrom",
0.25
);
const dashMaterial = new THREE.MeshStandardMaterial({
color: "#ff7163",
emissive: "#a52c24",
emissiveIntensity: 0.3,
roughness: 0.65
});
let dashStart = 0;
while (dashStart < 0.94) {
const dashEnd = Math.min(dashStart + 0.026, 1);
const p1 = oneWayCurve.getPointAt(dashStart);
const p2 = oneWayCurve.getPointAt(dashEnd);
const direction = p2.clone().sub(p1);
const length = direction.length();
const dash = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.11, length, 6),
dashMaterial
);
dash.position.copy(p1).add(p2).multiplyScalar(0.5);
dash.quaternion.setFromUnitVectors(up, direction.normalize());
world.add(dash);
dashStart += 0.043;
}
const oneWayEnd = oneWayCurve.getPointAt(1);
const oneWayTangent = oneWayCurve.getTangentAt(1);
addDirectionArrow(oneWayEnd, oneWayTangent, "#ff7163", 1.25);
// -------------------------------------------------------------------------
// Low-poly camps, structures and markers
// -------------------------------------------------------------------------
function makeGer(x, z, roofColor = "#e6dfcb", scale = 1) {
const group = new THREE.Group();
const baseY = terrainHeight(x, z);
const wall = new THREE.Mesh(
new THREE.CylinderGeometry(1.06, 1.08, 1.25, 8),
new THREE.MeshStandardMaterial({
color: "#eee8d7",
roughness: 0.94,
flatShading: true
})
);
wall.position.y = 0.63;
wall.castShadow = true;
wall.receiveShadow = true;
group.add(wall);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(1.38, 0.78, 8),
new THREE.MeshStandardMaterial({
color: roofColor,
roughness: 0.92,
flatShading: true
})
);
roof.position.y = 1.62;
roof.castShadow = true;
group.add(roof);
const doorway = new THREE.Mesh(
new THREE.BoxGeometry(0.55, 0.9, 0.12),
new THREE.MeshStandardMaterial({
color: "#5b4435",
roughness: 1
})
);
doorway.position.set(0, 0.48, 1.04);
group.add(doorway);
const finial = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.45, 5),
new THREE.MeshStandardMaterial({ color: "#9b7547", roughness: 0.8 })
);
finial.position.y = 2.18;
group.add(finial);
group.position.set(x, baseY, z);
group.scale.setScalar(scale);
world.add(group);
return group;
}
function makeHaystack(x, z, scale = 1) {
const group = new THREE.Group();
const baseY = terrainHeight(x, z);
const hay = new THREE.Mesh(
new THREE.CylinderGeometry(0.55, 0.72, 1.15, 7),
new THREE.MeshStandardMaterial({
color: "#d6b963",
roughness: 1,
flatShading: true
})
);
hay.position.y = 0.58;
hay.castShadow = true;
group.add(hay);
const cap = new THREE.Mesh(
new THREE.ConeGeometry(0.67, 0.45, 7),
new THREE.MeshStandardMaterial({
color: "#e3c978",
roughness: 1,
flatShading: true
})
);
cap.position.y = 1.35;
group.add(cap);
group.position.set(x, baseY, z);
group.scale.setScalar(scale);
world.add(group);
}
function makeFence(x, z, width, depth, color = "#8d7048") {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.95,
flatShading: true
});
const postGeometry = new THREE.CylinderGeometry(0.075, 0.09, 1.2, 5);
const corners = [
[x - width / 2, z - depth / 2],
[x + width / 2, z - depth / 2],
[x + width / 2, z + depth / 2],
[x - width / 2, z + depth / 2]
];
for (const [px, pz] of corners) {
const post = new THREE.Mesh(postGeometry, material);
post.position.set(px, terrainHeight(px, pz) + 0.55, pz);
post.castShadow = true;
world.add(post);
}
for (let side = 0; side < 4; side++) {
const a = corners[side];
const b = corners[(side + 1) % 4];
const midX = (a[0] + b[0]) / 2;
const midZ = (a[1] + b[1]) / 2;
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
for (const h of [0.45, 0.9]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.11, 0.11),
material
);
rail.position.set(midX, terrainHeight(midX, midZ) + h, midZ);
rail.rotation.y = Math.atan2(
-(b[1] - a[1]),
b[0] - a[0]
);
rail.castShadow = true;
world.add(rail);
}
}
}
function makeWindbreak(x, z) {
const material = new THREE.MeshStandardMaterial({
color: "#d0bd8d",
roughness: 1,
flatShading: true
});
for (let i = 0; i < 5; i++) {
const px = x + i * 1.25;
const panel = new THREE.Mesh(
new THREE.BoxGeometry(1.3, 1.35, 0.18),
material
);
panel.position.set(px, terrainHeight(px, z) + 0.65, z);
panel.rotation.y = (rand() - 0.5) * 0.08;
panel.castShadow = true;
world.add(panel);
}
}
function makeWell(x, z) {
const group = new THREE.Group();
const baseY = terrainHeight(x, z);
const stone = new THREE.Mesh(
new THREE.CylinderGeometry(0.78, 0.85, 0.85, 9),
new THREE.MeshStandardMaterial({
color: "#9a9586",
roughness: 1,
flatShading: true
})
);
stone.position.y = 0.43;
stone.castShadow = true;
group.add(stone);
const water = new THREE.Mesh(
new THREE.CylinderGeometry(0.62, 0.62, 0.05, 16),
new THREE.MeshStandardMaterial({
color: "#5eb3d0",
roughness: 0.22,
metalness: 0.08
})
);
water.position.y = 0.88;
group.add(water);
const postMaterial = new THREE.MeshStandardMaterial({
color: "#70583d",
roughness: 1
});
for (const dx of [-0.75, 0.75]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.06, 0.08, 1.5, 5),
postMaterial
);
post.position.set(dx, 1.1, 0);
group.add(post);
}
const roof = new THREE.Mesh(
new THREE.ConeGeometry(1.12, 0.52, 4),
new THREE.MeshStandardMaterial({
color: "#876b47",
roughness: 1,
flatShading: true
})
);
roof.position.y = 1.94;
roof.rotation.y = Math.PI / 4;
group.add(roof);
group.position.set(x, baseY, z);
world.add(group);
}
function makeTrough(x, z) {
const group = new THREE.Group();
const baseY = terrainHeight(x, z);
const trough = new THREE.Mesh(
new THREE.BoxGeometry(1.8, 0.48, 0.75),
new THREE.MeshStandardMaterial({
color: "#806b4c",
roughness: 1,
flatShading: true
})
);
trough.position.y = 0.25;
trough.castShadow = true;
group.add(trough);
const water = new THREE.Mesh(
new THREE.BoxGeometry(1.56, 0.06, 0.54),
new THREE.MeshStandardMaterial({
color: "#63b6cf",
roughness: 0.2
})
);
water.position.y = 0.51;
group.add(water);
group.position.set(x, baseY, z);
world.add(group);
}
function makeSign(x, z, color) {
const group = new THREE.Group();
const baseY = terrainHeight(x, z);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.07, 1.55, 5),
new THREE.MeshStandardMaterial({
color: "#5b4a36",
roughness: 1
})
);
pole.position.y = 0.75;
group.add(pole);
const board = new THREE.Mesh(
new THREE.BoxGeometry(0.95, 0.48, 0.11),
new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
flatShading: true
})
);
board.position.y = 1.47;
board.rotation.z = -0.04;
board.castShadow = true;
group.add(board);
group.position.set(x, baseY, z);
world.add(group);
}
// Winter shelter cluster.
makeGer(-28, 17.2, "#bf765b", 1.02);
makeGer(-24.6, 21.1, "#d18b69", 0.92);
makeGer(-28.4, 23.2, "#e1d5bd", 0.85);
makeFence(-20.6, 17.8, 4.6, 3.4);
makeWindbreak(-31.0, 14.9);
makeHaystack(-21.3, 21.3, 0.95);
makeHaystack(-22.0, 22.2, 0.82);
makeSign(-22.2, 14.3, "#e49a71");
// Spring camp and water infrastructure.
makeWell(2.1, 1.2);
makeTrough(-0.8, 3.7);
makeSign(-6.8, 5.2, "#65c5ba");
// Summer pasture camp.
makeGer(20.2, -19.4, "#d8bd72", 0.86);
makeHaystack(22.0, -17.0, 0.73);
makeSign(18.1, -14.5, "#f3c85e");
// Autumn staging camp.
makeGer(8.0, 17.5, "#a77eae", 0.76);
makeGer(11.0, 19.2, "#bc91c6", 0.68);
makeHaystack(13.5, 16.4, 0.82);
makeSign(7.3, 14.0, "#bd91c8");
// -------------------------------------------------------------------------
// Livestock
// -------------------------------------------------------------------------
const sheepPositions = [];
for (let i = 0; i < 25; i++) {
const angle = rand() * Math.PI * 2;
const radius = 2 + rand() * 8;
sheepPositions.push({
x: 23 + Math.cos(angle) * radius,
z: -17 + Math.sin(angle) * radius * 0.62,
rotation: rand() * Math.PI * 2,
scale: 0.72 + rand() * 0.34
});
}
for (let i = 0; i < 7; i++) {
sheepPositions.push({
x: 8 + rand() * 7,
z: 16 + rand() * 6,
rotation: rand() * Math.PI * 2,
scale: 0.74 + rand() * 0.28
});
}
const bodyCount = sheepPositions.length;
const bodyGeometry = new THREE.DodecahedronGeometry(0.49, 0);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 1,
flatShading: true
});
const bodies = new THREE.InstancedMesh(
bodyGeometry,
bodyMaterial,
bodyCount
);
bodies.castShadow = true;
bodies.receiveShadow = true;
const heads = new THREE.InstancedMesh(
new THREE.DodecahedronGeometry(0.20, 0),
new THREE.MeshStandardMaterial({
color: "#51473d",
roughness: 1,
flatShading: true
}),
bodyCount
);
heads.castShadow = true;
const legs = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.075, 0.38, 0.075),
new THREE.MeshStandardMaterial({
color: "#4a4139",
roughness: 1
}),
bodyCount * 4
);
legs.castShadow = true;
const dummy = new THREE.Object3D();
const sheepCream = new THREE.Color("#eee8d4");
const sheepBrown = new THREE.Color("#9b8064");
sheepPositions.forEach((sheep, index) => {
const y = terrainHeight(sheep.x, sheep.z);
const s = sheep.scale;
dummy.position.set(sheep.x, y + 0.57 * s, sheep.z);
dummy.rotation.set(0, sheep.rotation, 0);
dummy.scale.set(1.22 * s, 0.78 * s, 0.72 * s);
dummy.updateMatrix();
bodies.setMatrixAt(index, dummy.matrix);
bodies.setColorAt(index, rand() > 0.76 ? sheepBrown : sheepCream);
const forward = new THREE.Vector3(
Math.cos(sheep.rotation),
0,
-Math.sin(sheep.rotation)
);
const headPosition = new THREE.Vector3(sheep.x, y + 0.61 * s, sheep.z)
.addScaledVector(forward, 0.54 * s);
dummy.position.copy(headPosition);
dummy.rotation.set(0, sheep.rotation, 0);
dummy.scale.setScalar(s);
dummy.updateMatrix();
heads.setMatrixAt(index, dummy.matrix);
const side = new THREE.Vector3(
-Math.sin(sheep.rotation),
0,
-Math.cos(sheep.rotation)
);
let legIndex = index * 4;
for (const lx of [-0.28, 0.28]) {
for (const lz of [-0.18, 0.18]) {
const legPosition = new THREE.Vector3(sheep.x, y + 0.22 * s, sheep.z)
.addScaledVector(forward, lx * s)
.addScaledVector(side, lz * s);
dummy.position.copy(legPosition);
dummy.rotation.set(0, sheep.rotation, 0);
dummy.scale.set(s, s, s);
dummy.updateMatrix();
legs.setMatrixAt(legIndex++, dummy.matrix);
}
}
});
bodies.instanceMatrix.needsUpdate = true;
heads.instanceMatrix.needsUpdate = true;
legs.instanceMatrix.needsUpdate = true;
if (bodies.instanceColor) bodies.instanceColor.needsUpdate = true;
world.add(bodies, heads, legs);
// -------------------------------------------------------------------------
// Trees, rocks and grass
// -------------------------------------------------------------------------
const treeCount = 29;
const trunks = new THREE.InstancedMesh(
new THREE.CylinderGeometry(0.11, 0.17, 1.05, 5),
new THREE.MeshStandardMaterial({
color: "#6f563b",
roughness: 1,
flatShading: true
}),
treeCount
);
const crowns = new THREE.InstancedMesh(
new THREE.DodecahedronGeometry(0.72, 0),
new THREE.MeshStandardMaterial({
color: "#536c47",
roughness: 1,
flatShading: true
}),
treeCount
);
trunks.castShadow = true;
crowns.castShadow = true;
let treeIndex = 0;
while (treeIndex < treeCount) {
const x = -40 + rand() * 80;
const z = -29 + rand() * 58;
const dRiver = distanceToRiver(x, z);
const nearCamp =
Math.hypot(x + 25, z - 18) < 8 ||
Math.hypot(x - 24, z + 17) < 7 ||
Math.hypot(x - 2, z - 1) < 5;
if (dRiver < 1.7 || dRiver > 9 || nearCamp) continue;
const y = terrainHeight(x, z);
const scale = 0.68 + rand() * 0.62;
dummy.position.set(x, y + 0.48 * scale, z);
dummy.rotation.set(0, rand() * Math.PI, 0);
dummy.scale.set(scale, scale, scale);
dummy.updateMatrix();
trunks.setMatrixAt(treeIndex, dummy.matrix);
dummy.position.set(x, y + 1.35 * scale, z);
dummy.rotation.set(rand() * 0.2, rand() * Math.PI, rand() * 0.2);
dummy.scale.set(scale * 1.15, scale, scale * 1.0);
dummy.updateMatrix();
crowns.setMatrixAt(treeIndex, dummy.matrix);
treeIndex++;
}
trunks.instanceMatrix.needsUpdate = true;
crowns.instanceMatrix.needsUpdate = true;
world.add(trunks, crowns);
const rockCount = 42;
const rocks = new THREE.InstancedMesh(
new THREE.DodecahedronGeometry(0.42, 0),
new THREE.MeshStandardMaterial({
color: "#8b8a79",
roughness: 1,
flatShading: true
}),
rockCount
);
for (let i = 0; i < rockCount; i++) {
const x = -42 + rand() * 84;
const z = -31 + rand() * 62;
const scale = 0.16 + rand() * 0.46;
dummy.position.set(x, terrainHeight(x, z) + scale * 0.35, z);
dummy.rotation.set(rand() * 0.4, rand() * Math.PI, rand() * 0.4);
dummy.scale.set(scale * 1.2, scale * 0.7, scale);
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
}
rocks.instanceMatrix.needsUpdate = true;
rocks.castShadow = true;
world.add(rocks);
const grassCount = 150;
const grass = new THREE.InstancedMesh(
new THREE.ConeGeometry(0.11, 0.55, 3),
new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 1,
flatShading: true
}),
grassCount
);
const grassColors = [
new THREE.Color("#737e49"),
new THREE.Color("#90934f"),
new THREE.Color("#a79a58"),
new THREE.Color("#65754a")
];
for (let i = 0; i < grassCount; i++) {
const x = -43 + rand() * 86;
const z = -32 + rand() * 64;
const scale = 0.45 + rand() * 0.8;
dummy.position.set(x, terrainHeight(x, z) + 0.24 * scale, z);
dummy.rotation.set(0, rand() * Math.PI, (rand() - 0.5) * 0.12);
dummy.scale.set(scale, scale, scale);
dummy.updateMatrix();
grass.setMatrixAt(i, dummy.matrix);
grass.setColorAt(i, grassColors[Math.floor(rand() * grassColors.length)]);
}
grass.instanceMatrix.needsUpdate = true;
if (grass.instanceColor) grass.instanceColor.needsUpdate = true;
world.add(grass);
// -------------------------------------------------------------------------
// Seasonal marker
// -------------------------------------------------------------------------
const seasonMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.36, 12, 8),
new THREE.MeshBasicMaterial({
color: "#ffffff",
transparent: true,
opacity: 0.95
})
);
world.add(seasonMarker);
const markerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.065, 6, 28),
new THREE.MeshBasicMaterial({
color: "#ffd166",
transparent: true,
opacity: 0.8
})
);
markerRing.rotation.x = Math.PI / 2;
world.add(markerRing);
// -------------------------------------------------------------------------
// HTML map labels
// -------------------------------------------------------------------------
const labelDefinitions = [
{
id: "winter",
className: "winter",
number: "01",
title: "Winter shelter",
subtitle: "sheltered winter range",
position: new THREE.Vector3(-25, 0, 18)
},
{
id: "spring",
className: "spring",
number: "02",
title: "Spring pasture",
subtitle: "water + pasture recovery",
position: new THREE.Vector3(-3, 0, 7)
},
{
id: "summer",
className: "summer",
number: "03",
title: "Summer pasture",
subtitle: "open upland grazing",
position: new THREE.Vector3(24, 0, -17)
},
{
id: "autumn",
className: "autumn",
number: "04",
title: "Autumn pasture",
subtitle: "return toward winter ground",
position: new THREE.Vector3(10, 0, 18)
},
{
id: "water",
className: "water",
number: "H₂O",
title: "Water network",
subtitle: "river · wells · trough",
position: new THREE.Vector3(4.3, 0, 0)
},
{
id: "oneway",
className: "oneway",
number: "→",
title: "One-way migration",
subtitle: "comparison only · no return",
position: new THREE.Vector3(36.5, 0, 25.4)
}
];
const labelsRoot = document.getElementById("labels");
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = `map-label ${definition.className}`;
element.id = `label-${definition.id}`;
element.innerHTML = `
<span class="number">${definition.number}</span>
<span>
<b>${definition.title}</b>
<small>${definition.subtitle}</small>
</span>
`;
labelsRoot.appendChild(element);
definition.element = element;
definition.position.y = terrainHeight(
definition.position.x,
definition.position.z
) + (definition.id === "oneway" ? 2.2 : 3.1);
}
// -------------------------------------------------------------------------
// Camera controls — implemented directly, without Three.js addons
// -------------------------------------------------------------------------
const orbit = {
theta: 0.70,
phi: 0.88,
radius: 82,
target: new THREE.Vector3(0, 0, 0),
goalTheta: 0.70,
goalPhi: 0.88,
goalRadius: 82,
goalTarget: new THREE.Vector3(0, 0, 0)
};
let cameraTween = null;
function shortestAngle(from, to) {
let delta = (to - from) % (Math.PI * 2);
if (delta > Math.PI) delta -= Math.PI * 2;
if (delta < -Math.PI) delta += Math.PI * 2;
return delta;
}
function moveCameraTo(target, radius, theta = orbit.theta, phi = orbit.phi) {
cameraTween = {
time: 0,
duration: 0.85,
fromTarget: orbit.target.clone(),
toTarget: target.clone(),
fromRadius: orbit.radius,
toRadius: radius,
fromTheta: orbit.theta,
deltaTheta: shortestAngle(orbit.theta, theta),
fromPhi: orbit.phi,
toPhi: phi
};
}
function updateCamera(delta) {
if (cameraTween) {
cameraTween.time += delta;
const t = clamp(cameraTween.time / cameraTween.duration, 0, 1);
const eased = 1 - (1 - t) ** 3;
orbit.target.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
eased
);
orbit.radius = THREE.MathUtils.lerp(
cameraTween.fromRadius,
cameraTween.toRadius,
eased
);
orbit.theta = cameraTween.fromTheta + cameraTween.deltaTheta * eased;
orbit.phi = THREE.MathUtils.lerp(
cameraTween.fromPhi,
cameraTween.toPhi,
eased
);
if (t >= 1) cameraTween = null;
}
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
const pointers = new Map();
let dragPointer = null;
let previousPinchDistance = 0;
function pinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
canvas.setPointerCapture(event.pointerId);
cameraTween = null;
if (pointers.size === 1) {
dragPointer = event.pointerId;
} else if (pointers.size === 2) {
previousPinchDistance = pinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && dragPointer === event.pointerId) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
orbit.theta -= dx * 0.0055;
orbit.phi = clamp(orbit.phi + dy * 0.0045, 0.38, 1.28);
} else if (pointers.size === 2) {
const nextDistance = pinchDistance();
if (previousPinchDistance > 0 && nextDistance > 0) {
orbit.radius = clamp(
orbit.radius * (previousPinchDistance / nextDistance),
28,
125
);
}
previousPinchDistance = nextDistance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (dragPointer === event.pointerId) dragPointer = null;
if (pointers.size < 2) previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
orbit.radius = clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
28,
125
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
moveCameraTo(new THREE.Vector3(0, 0, 0), 82, 0.70, 0.88);
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
orbit.theta += 0.10;
cameraTween = null;
} else if (event.key === "ArrowRight") {
orbit.theta -= 0.10;
cameraTween = null;
} else if (event.key === "ArrowUp") {
orbit.phi = clamp(orbit.phi - 0.08, 0.38, 1.28);
cameraTween = null;
} else if (event.key === "ArrowDown") {
orbit.phi = clamp(orbit.phi + 0.08, 0.38, 1.28);
cameraTween = null;
} else if (event.key === "+" || event.key === "=") {
orbit.radius = clamp(orbit.radius - 5, 28, 125);
cameraTween = null;
} else if (event.key === "-" || event.key === "_") {
orbit.radius = clamp(orbit.radius + 5, 28, 125);
cameraTween = null;
} else if (event.key.toLowerCase() === "r") {
moveCameraTo(new THREE.Vector3(0, 0, 0), 82, 0.70, 0.88);
}
});
// -------------------------------------------------------------------------
// Season controls
// -------------------------------------------------------------------------
const seasonData = {
winter: {
position: new THREE.Vector3(-25, 0, 18),
radius: 50,
theta: 0.88,
color: "#e49a71",
copy:
"<strong>Winter:</strong> sheltered ground reduces exposure; smaller camps, stored fodder, and a livestock pen cluster around the basin."
},
spring: {
position: new THREE.Vector3(-3, 0, 7),
radius: 49,
theta: 0.58,
color: "#65c5ba",
copy:
"<strong>Spring:</strong> the route reaches dependable water and recovering pasture before moving toward open summer grazing."
},
summer: {
position: new THREE.Vector3(24, 0, -17),
radius: 52,
theta: 0.56,
color: "#f3c85e",
copy:
"<strong>Summer:</strong> the herd disperses across open upland pasture near a small camp and a secondary water point."
},
autumn: {
position: new THREE.Vector3(10, 0, 18),
radius: 50,
theta: 0.76,
color: "#bd91c8",
copy:
"<strong>Autumn:</strong> gold arrows show movement descending through staging pasture and water points toward the winter range."
}
};
const seasonCopy = document.getElementById("seasonCopy");
const seasonButtons = [...document.querySelectorAll(".season-button")];
function selectSeason(key) {
const data = seasonData[key];
if (!data) return;
seasonButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.season === key);
});
seasonCopy.innerHTML = data.copy;
const markerPosition = data.position;
seasonMarker.position.set(
markerPosition.x,
terrainHeight(markerPosition.x, markerPosition.z) + 1.25,
markerPosition.z
);
markerRing.position.copy(seasonMarker.position);
markerRing.material.color.set(data.color);
moveCameraTo(
new THREE.Vector3(markerPosition.x, 0, markerPosition.z),
data.radius,
data.theta,
0.93
);
}
seasonButtons.forEach((button) => {
button.addEventListener("click", () => selectSeason(button.dataset.season));
});
document.getElementById("overview").addEventListener("click", () => {
seasonButtons.forEach((button) => button.classList.remove("active"));
seasonCopy.innerHTML =
"<strong>Overview:</strong> select a season to inspect its role in the closed circuit.";
moveCameraTo(new THREE.Vector3(0, 0, 0), 82, 0.70, 0.88);
});
// -------------------------------------------------------------------------
// Label projection and animation
// -------------------------------------------------------------------------
const compassNeedle = document.getElementById("compassNeedle");
const clock = new THREE.Clock();
function updateLabels() {
for (const definition of labelDefinitions) {
const projected = definition.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
definition.element.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
}
}
compassNeedle.style.transform = `rotate(${-orbit.theta}rad)`;
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
updateLabels();
const pulse = 1 + Math.sin(elapsed * 2.4) * 0.13;
markerRing.scale.setScalar(pulse);
seasonMarker.position.y += Math.sin(elapsed * 2.4) * 0.002;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
updateCamera(0);
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```