Prompt specification
Build or customize the Three.js 3D scene "Rural School Access Network" 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: Rural School Access Network
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/rural-school-access-network-x2139
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Build an original rural landscape with homes, school, bridge, and seasonal path. Show alternative routes and explicit travel assumptions without claiming a real community map.
Working Three.js Starter (rural-school-access-network-x2139):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Brackenfold — Fictional Voxel Travel Study</title>
<style>
:root {
--ink: #24312d;
--muted: #65716b;
--paper: rgba(250, 248, 238, 0.92);
--paper-solid: #faf8ee;
--line: rgba(36, 49, 45, 0.14);
--route-a: #078f86;
--route-b: #e88b28;
--route-c: #c94e78;
--shadow: 0 16px 45px rgba(39, 49, 42, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e5d2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.68);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.1);
-webkit-backdrop-filter: blur(16px) saturate(1.1);
}
header {
position: fixed;
z-index: 20;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.title-block {
max-width: 520px;
padding: 16px 18px 15px;
border-radius: 18px;
background: rgba(250, 248, 238, 0.9);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.eyebrow {
display: block;
margin-bottom: 5px;
color: #4e7467;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 42px);
line-height: 0.96;
letter-spacing: -0.045em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.badge {
display: inline-flex;
align-items: center;
min-height: 34px;
padding: 8px 11px;
border-radius: 999px;
background: #263b35;
color: #f8f4df;
box-shadow: 0 8px 24px rgba(29, 45, 39, 0.2);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
white-space: nowrap;
}
.badge::before {
content: "";
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: #f0b852;
}
.icon-button {
min-height: 34px;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 999px;
background: rgba(250, 248, 238, 0.92);
color: var(--ink);
box-shadow: 0 8px 24px rgba(29, 45, 39, 0.16);
cursor: pointer;
font-size: 11px;
font-weight: 750;
}
.icon-button:hover {
background: #fffdf4;
}
#routes-panel {
top: 124px;
left: 20px;
width: 310px;
max-height: calc(100vh - 145px);
padding: 15px;
border-radius: 18px;
overflow: auto;
scrollbar-width: thin;
}
.panel-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin: 0 1px 10px;
}
.panel-heading h2,
.panel-heading h3 {
margin: 0;
font-size: 14px;
letter-spacing: -0.01em;
}
.panel-heading span {
color: var(--muted);
font-size: 10px;
}
.route-card {
position: relative;
display: block;
width: 100%;
margin: 0 0 8px;
padding: 11px 11px 10px 13px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.44);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
.route-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--route-color);
opacity: 0.72;
}
.route-card:hover {
transform: translateX(2px);
border-color: rgba(36, 49, 45, 0.28);
background: rgba(255, 255, 255, 0.66);
}
.route-card.active {
border-color: var(--route-color);
background: rgba(255, 255, 255, 0.86);
box-shadow: 0 7px 18px rgba(36, 49, 45, 0.08);
}
.route-card.closed {
opacity: 0.68;
}
.route-top {
display: grid;
grid-template-columns: 24px 1fr auto;
align-items: center;
gap: 7px;
}
.route-letter {
display: grid;
place-items: center;
width: 23px;
height: 23px;
border-radius: 7px;
background: var(--route-color);
color: white;
font-size: 11px;
font-weight: 850;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.route-top strong {
font-size: 12px;
}
.route-state {
color: var(--muted);
font-size: 9px;
font-weight: 750;
white-space: nowrap;
}
.route-meta {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0 0 31px;
color: var(--muted);
font-size: 10px;
}
.route-meta b {
color: var(--ink);
font-size: 11px;
}
.route-detail {
margin-top: 10px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.48);
}
.route-detail h3 {
margin: 0 0 5px;
font-size: 13px;
}
.route-detail p {
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.55;
}
.route-detail .condition {
display: inline-block;
margin-top: 9px;
padding: 5px 7px;
border-radius: 7px;
background: #e8efe8;
color: #36594b;
font-size: 9px;
font-weight: 750;
}
.route-detail .condition.warning {
background: #f5e1d8;
color: #8b4c35;
}
#controls-panel {
top: 124px;
right: 20px;
width: 288px;
max-height: calc(100vh - 145px);
padding: 15px;
border-radius: 18px;
overflow: auto;
scrollbar-width: thin;
}
.season-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
margin-bottom: 15px;
}
.season-button {
padding: 8px 4px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.42);
color: var(--muted);
cursor: pointer;
font-size: 9px;
font-weight: 750;
}
.season-button:hover {
background: rgba(255, 255, 255, 0.78);
}
.season-button.active {
border-color: #496e61;
background: #496e61;
color: #fffdf3;
}
.assumptions {
padding-top: 13px;
border-top: 1px solid var(--line);
}
.assumptions h3 {
margin: 0 0 8px;
font-size: 12px;
}
.assumptions ul {
margin: 0;
padding: 0;
list-style: none;
}
.assumptions li {
position: relative;
margin: 0 0 8px;
padding-left: 13px;
color: var(--muted);
font-size: 9.5px;
line-height: 1.48;
}
.assumptions li::before {
content: "";
position: absolute;
top: 5px;
left: 0;
width: 4px;
height: 4px;
border-radius: 50%;
background: #6b8e80;
}
.disclaimer {
margin-top: 10px;
padding: 9px;
border-radius: 9px;
background: #efe7d3;
color: #6d5730;
font-size: 9.5px;
font-weight: 700;
line-height: 1.45;
}
.legend {
display: grid;
gap: 6px;
margin-top: 12px;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 9.5px;
}
.legend-swatch {
width: 21px;
height: 4px;
border-radius: 4px;
background: var(--swatch);
}
.legend-square {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--swatch);
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.map-label {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 999px;
background: rgba(250, 248, 238, 0.88);
box-shadow: 0 6px 18px rgba(34, 46, 40, 0.16);
color: var(--ink);
font-size: 9px;
font-weight: 800;
white-space: nowrap;
transform: translate(-50%, -100%);
will-change: left, top;
}
.map-label::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--dot, #6a8579);
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.58);
}
.map-label.minor {
padding: 4px 7px;
font-size: 8px;
opacity: 0.9;
}
#bottom-strip {
position: fixed;
z-index: 9;
left: 50%;
bottom: 17px;
display: flex;
align-items: center;
gap: 12px;
padding: 9px 13px;
border-radius: 999px;
background: rgba(250, 248, 238, 0.88);
box-shadow: 0 10px 30px rgba(34, 46, 40, 0.15);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 9.5px;
transform: translateX(-50%);
white-space: nowrap;
}
#bottom-strip strong {
color: var(--ink);
}
.separator {
width: 1px;
height: 14px;
background: var(--line);
}
#compass {
position: fixed;
z-index: 9;
right: 28px;
bottom: 25px;
display: grid;
place-items: center;
width: 46px;
height: 46px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 50%;
background: rgba(250, 248, 238, 0.82);
box-shadow: 0 8px 22px rgba(34, 46, 40, 0.14);
color: var(--ink);
font-size: 9px;
font-weight: 850;
}
#compass span {
position: absolute;
top: 4px;
color: #a05c3f;
font-size: 8px;
}
#compass::after {
content: "";
width: 0;
height: 0;
margin-top: 6px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 17px solid #344d44;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #dce7d7;
color: #38564b;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
header {
top: 10px;
left: 10px;
right: 10px;
}
.title-block {
padding: 12px 14px;
}
.subtitle {
display: none;
}
.badge {
position: absolute;
top: 85px;
right: 0;
}
#routes-panel {
top: auto;
bottom: 12px;
left: 10px;
width: min(300px, calc(100vw - 20px));
max-height: 43vh;
}
#controls-panel {
top: 94px;
right: 10px;
width: 225px;
max-height: 45vh;
}
#bottom-strip {
display: none;
}
#compass {
right: 17px;
bottom: 18px;
}
.minor-marker {
display: none !important;
}
}
@media (max-width: 540px) {
.header-actions .badge {
display: none;
}
#controls-panel {
width: 196px;
padding: 11px;
}
#routes-panel {
width: calc(100vw - 20px);
}
.map-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels" aria-hidden="true"></div>
<header>
<div class="title-block">
<span class="eyebrow">Original voxel travel concept</span>
<h1>Brackenfold</h1>
<p class="subtitle">
A fictional rural settlement, seasonal paths, and three modeled walking routes.
</p>
</div>
<div class="header-actions">
<span class="badge">NOT A REAL COMMUNITY MAP</span>
<button id="reset-view" class="icon-button" type="button">Reset view</button>
</div>
</header>
<aside id="routes-panel" class="panel" aria-label="Alternative routes">
<div class="panel-heading">
<h2>Alternative routes</h2>
<span>Lane End → School</span>
</div>
<button class="route-card active" type="button" data-route="A"
style="--route-color: var(--route-a)">
<div class="route-top">
<span class="route-letter">A</span>
<strong>Creek Bridge</strong>
<span class="route-state">All season</span>
</div>
<div class="route-meta">
<span><b data-distance="A">—</b> km</span>
<span>·</span>
<span><b data-time="A">—</b> min</span>
<span>·</span>
<span>Shortest modeled link</span>
</div>
</button>
<button class="route-card" type="button" data-route="B"
style="--route-color: var(--route-b)">
<div class="route-top">
<span class="route-letter">B</span>
<strong>Orchard & North Footbridge</strong>
<span class="route-state">All season</span>
</div>
<div class="route-meta">
<span><b data-distance="B">—</b> km</span>
<span>·</span>
<span><b data-time="B">—</b> min</span>
<span>·</span>
<span>Longer, higher ground</span>
</div>
</button>
<button class="route-card" type="button" data-route="C"
style="--route-color: var(--route-c)">
<div class="route-top">
<span class="route-letter">C</span>
<strong>Meadow Steps</strong>
<span class="route-state" data-state="C">May–Sep</span>
</div>
<div class="route-meta">
<span><b data-distance="C">—</b> km</span>
<span>·</span>
<span><b data-time="C">—</b> min</span>
<span>·</span>
<span>Seasonal crossing</span>
</div>
</button>
<section id="route-detail" class="route-detail" aria-live="polite"></section>
</aside>
<aside id="controls-panel" class="panel" aria-label="Season and travel assumptions">
<div class="panel-heading">
<h2>Seasonal view</h2>
<span id="season-status">Spring</span>
</div>
<div class="season-grid" role="group" aria-label="Choose season">
<button class="season-button active" type="button" data-season="spring">Spring</button>
<button class="season-button" type="button" data-season="summer">Summer</button>
<button class="season-button" type="button" data-season="autumn">Autumn</button>
<button class="season-button" type="button" data-season="winter">Winter</button>
</div>
<div class="panel-heading">
<h3>Travel assumptions</h3>
<span>Model only</span>
</div>
<div class="assumptions">
<ul>
<li>
Brackenfold is fictional. The landscape combines invented places and does not
describe any surveyed or real community geography.
</li>
<li>
Distances use a simple illustrative scale of 50 metres per scene unit,
summed from straight path segments.
</li>
<li>
Walking time assumes 4.5 km/h with no stops. Estimates are rounded to
the nearest minute.
</li>
<li>
Winter walking time on Routes A and B includes a 20% adverse-condition
allowance. Route C is modeled as closed outside May–September.
</li>
<li>
Bus services, traffic, gradients, accessibility, personal mobility,
flood risk, and current construction are not assessed.
</li>
</ul>
<div class="disclaimer">
This is an illustrative design and route-comparison scene, not navigation,
safety advice, or a substitute for current local information.
</div>
</div>
<div class="panel-heading" style="margin-top:14px">
<h3>Map key</h3>
<span>Illustrative</span>
</div>
<div class="legend">
<div class="legend-row">
<span class="legend-swatch" style="--swatch: var(--route-a)"></span>
Route A · Creek Bridge
</div>
<div class="legend-row">
<span class="legend-swatch" style="--swatch: var(--route-b)"></span>
Route B · Orchard Loop
</div>
<div class="legend-row">
<span class="legend-swatch" style="--swatch: var(--route-c)"></span>
Route C · Meadow Steps
</div>
<div class="legend-row">
<span class="legend-square" style="--swatch: #68a9c1"></span>
Stream
</div>
<div class="legend-row">
<span class="legend-square" style="--swatch: #ede6d3"></span>
School building
</div>
</div>
</aside>
<div id="bottom-strip">
<strong id="selected-status">Route A selected</strong>
<span class="separator"></span>
<span>Drag to orbit · Wheel to zoom · Right-drag to pan</span>
<span class="separator"></span>
<span>50 m / scene unit</span>
</div>
<div id="compass"><span>N</span></div>
<div id="loading">BUILDING BRACKENFOLD…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const loading = document.querySelector("#loading");
const labelsLayer = document.querySelector("#labels");
const routeDetail = document.querySelector("#route-detail");
const seasonStatus = document.querySelector("#season-status");
const selectedStatus = document.querySelector("#selected-status");
// ------------------------------------------------------------
// Renderer, scene, camera, and direct camera controls
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8d8);
scene.fog = new THREE.Fog(0xdce8d8, 48, 88);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel landscape. Drag to orbit, scroll to zoom, and use arrow keys to rotate."
);
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe8f5ff, 0x69734d, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.2);
sun.position.set(-18, 30, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 31;
sun.shadow.camera.bottom = -31;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7e2ff, 0.65);
fill.position.set(24, 15, -20);
scene.add(fill);
const orbit = {
radius: 45,
theta: 0.72,
phi: 0.82,
target: new THREE.Vector3(0, 0.7, 0)
};
function updateCamera() {
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.28, 1.22);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 17, 72);
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);
}
function resetCamera() {
orbit.radius = 45;
orbit.theta = 0.72;
orbit.phi = 0.82;
orbit.target.set(0, 0.7, 0);
updateCamera();
}
updateCamera();
let pointerState = null;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerState = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState || pointerState.id !== event.pointerId) return;
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
if (pointerState.pan) {
const right = new THREE.Vector3();
camera.getWorldDirection(right);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(-right.z, 0, right.x);
const scale = orbit.radius * 0.0017;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(forward, dy * scale);
} else {
orbit.theta -= dx * 0.006;
orbit.phi -= dy * 0.005;
}
updateCamera();
});
function endPointer(event) {
if (pointerState?.id === event.pointerId) pointerState = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") orbit.theta += 0.09;
else if (key === "arrowright") orbit.theta -= 0.09;
else if (key === "arrowup") orbit.phi -= 0.07;
else if (key === "arrowdown") orbit.phi += 0.07;
else if (key === "+" || key === "=") orbit.radius -= 2;
else if (key === "-") orbit.radius += 2;
else if (key === "0") resetCamera();
else return;
event.preventDefault();
updateCamera();
});
document.querySelector("#reset-view").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Fictional terrain and route definitions
// ------------------------------------------------------------
const SCENE_METRES_PER_UNIT = 50;
const WALK_SPEED_KMH = 4.5;
function creekX(z) {
return (
6 +
1.2 * Math.sin((z + 3) * 0.18) +
0.3 * Math.sin(z * 0.47)
);
}
function groundTop(x, z) {
const streamDistance = Math.abs(x - creekX(z));
let h =
1.22 +
0.35 * Math.sin(x * 0.32) +
0.3 * Math.cos(z * 0.29) +
0.18 * Math.sin((x + z) * 0.5);
// A broad rise toward the northwestern orchard.
h +=
Math.max(0, (-z - 4) / 14) *
1.35 *
Math.max(0, (-x - 2) / 18);
// A low southern meadow shelf.
h += Math.max(0, (z - 11) / 7) * 0.38;
// Stream incision.
if (streamDistance < 2.7) {
h -= (1 - streamDistance / 2.7) * 1.85;
}
if (streamDistance < 1.45) {
h = Math.min(h, -0.34 + 0.04 * Math.sin(z));
}
return Math.round(h * 4) / 4;
}
const bridgeZ = 0;
const northBridgeZ = -12;
const meadowStepsZ = 13;
const mainBridgeX = creekX(bridgeZ);
const northBridgeX = creekX(northBridgeZ);
const meadowStepsX = creekX(meadowStepsZ);
const routes = [
{
id: "A",
name: "Creek Bridge",
color: 0x078f86,
css: "#078f86",
points: [
[-13, 10],
[-11, 8],
[-7, 6],
[-1, 5],
[2.4, 3.5],
[mainBridgeX - 2.6, bridgeZ],
[mainBridgeX + 2.6, bridgeZ],
[10.2, -0.8],
[14, -3.2],
[12, -6.55]
],
surface: "Packed lane and timber bridge",
description:
"The most direct modeled connection. It uses the broad main bridge, but the approach remains an unpaved rural lane.",
availability: "Modeled as available in all four seasons."
},
{
id: "B",
name: "Orchard & North Footbridge",
color: 0xe88b28,
css: "#e88b28",
points: [
[-13, 10],
[-16, 7],
[-17, 2],
[-16, -4],
[-12, -9],
[-7, -12],
[-1, -13],
[3, -13],
[northBridgeX - 1.8, northBridgeZ],
[northBridgeX + 1.8, northBridgeZ],
[11, -12],
[16, -10],
[17, -6],
[15, -3.8],
[12, -6.55]
],
surface: "Earth track, orchard trail, north footbridge",
description:
"A longer loop around the orchard and over higher northwestern ground before reaching the school from the north.",
availability: "Modeled as available in all four seasons."
},
{
id: "C",
name: "Meadow Steps",
color: 0xc94e78,
css: "#c94e78",
points: [
[-13, 10],
[-10, 13],
[-4, 14],
[2, 14],
[meadowStepsX - 1.65, meadowStepsZ],
[meadowStepsX + 1.65, meadowStepsZ],
[9.5, 12],
[11.5, 9],
[14.5, 5],
[14, 0],
[12, -6.55]
],
surface: "Mown meadow and stepping stones",
description:
"A southern alternative with a seasonal stream crossing. The model treats the stones as usable only during the May–September dry-season window.",
availability: "Modeled as open May–September and closed October–April."
}
];
function segmentDistance(px, pz, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const denominator = dx * dx + dz * dz;
if (denominator === 0) {
return Math.hypot(px - ax, pz - az);
}
const t = THREE.MathUtils.clamp(
((px - ax) * dx + (pz - az) * dz) / denominator,
0,
1
);
return Math.hypot(px - (ax + t * dx), pz - (az + t * dz));
}
function distanceToPolyline(x, z, points) {
let nearest = Infinity;
for (let i = 0; i < points.length - 1; i++) {
nearest = Math.min(
nearest,
segmentDistance(
x,
z,
points[i][0],
points[i][1],
points[i + 1][0],
points[i + 1][1]
)
);
}
return nearest;
}
function routeDistanceKm(route) {
let units = 0;
for (let i = 0; i < route.points.length - 1; i++) {
units += Math.hypot(
route.points[i + 1][0] - route.points[i][0],
route.points[i + 1][1] - route.points[i][1]
);
}
return (units * SCENE_METRES_PER_UNIT) / 1000;
}
function routeTimeMinutes(route, season) {
const base = (routeDistanceKm(route) / WALK_SPEED_KMH) * 60;
const winterAllowance = season === "winter" && route.id !== "C" ? 1.2 : 1;
return Math.max(1, Math.round(base * winterAllowance));
}
// ------------------------------------------------------------
// Voxel terrain
// ------------------------------------------------------------
const terrainBottom = -1.35;
const terrainCells = [];
const terrainGeometry = new THREE.BoxGeometry(0.985, 1, 0.985);
const terrainMaterial = new THREE.MeshStandardMaterial({
roughness: 0.97,
metalness: 0,
vertexColors: false
});
for (let z = -18; z <= 18; z++) {
for (let x = -22; x <= 22; x++) {
terrainCells.push({
x,
z,
top: groundTop(x, z),
streamDistance: Math.abs(x - creekX(z))
});
}
}
const terrainMesh = new THREE.InstancedMesh(
terrainGeometry,
terrainMaterial,
terrainCells.length
);
terrainMesh.receiveShadow = true;
terrainMesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
scene.add(terrainMesh);
const terrainMatrix = new THREE.Matrix4();
const terrainQuaternion = new THREE.Quaternion();
terrainCells.forEach((cell, index) => {
const height = cell.top - terrainBottom;
terrainMatrix.compose(
new THREE.Vector3(cell.x, terrainBottom + height / 2, cell.z),
terrainQuaternion,
new THREE.Vector3(1, height, 1)
);
terrainMesh.setMatrixAt(index, terrainMatrix);
});
terrainMesh.instanceMatrix.needsUpdate = true;
function seededNoise(x, z) {
const value = Math.sin(x * 12.9898 + z * 78.233) * 43758.5453;
return value - Math.floor(value);
}
function inRect(x, z, x0, x1, z0, z1) {
return x >= x0 && x <= x1 && z >= z0 && z <= z1;
}
const seasonPalettes = {
spring: {
ground: [0x79a95c, 0x87b563, 0x6e9f55, 0x91ba66],
path: 0xc6ad78,
field: 0x94aa55,
crop: 0x557f43,
water: 0x67a8bd,
foliage: [0x4e884e, 0x5f9853, 0x477c49, 0x78a95a],
sky: 0xdce8d8,
sun: 0xfff0cf,
intensity: 3.2
},
summer: {
ground: [0x9eae59, 0xa8b65f, 0x91a653, 0xb1b967],
path: 0xc9b477,
field: 0xb0a657,
crop: 0x6f873e,
water: 0x5599aa,
foliage: [0x386d43, 0x477b45, 0x315f3d, 0x648749],
sky: 0xe3ead2,
sun: 0xfff1c2,
intensity: 3.4
},
autumn: {
ground: [0xaa9a54, 0xb49d57, 0x9b8749, 0xbda35c],
path: 0xc1a66f,
field: 0xb78b45,
crop: 0x8d6935,
water: 0x6e969c,
foliage: [0xb96635, 0xce8038, 0x9f4e2e, 0xd59b42],
sky: 0xe8dfc9,
sun: 0xffdda4,
intensity: 2.85
},
winter: {
ground: [0xdce7e5, 0xe8eeeb, 0xcfdddc, 0xf0f2ed],
path: 0xdce3df,
field: 0xcbd8d6,
crop: 0x9caea7,
water: 0x9dbbc2,
foliage: [0x857662, 0x9a8870, 0x75685e, 0xa69783],
sky: 0xdbe5e8,
sun: 0xe6f0ff,
intensity: 2.25
}
};
let currentSeason = "spring";
let selectedRoute = "A";
function updateTerrainColors() {
const palette = seasonPalettes[currentSeason];
terrainCells.forEach((cell, index) => {
const color = new THREE.Color();
const noise = seededNoise(cell.x, cell.z);
const paletteIndex = Math.floor(noise * palette.ground.length);
color.setHex(palette.ground[paletteIndex]);
color.offsetHSL(0, 0, (noise - 0.5) * 0.045);
let routeDistance = Infinity;
for (const route of routes) {
routeDistance = Math.min(
routeDistance,
distanceToPolyline(cell.x, cell.z, route.points)
);
}
if (
inRect(cell.x, cell.z, -12, -4, -9, -5) ||
inRect(cell.x, cell.z, 1, 5, -7, 0) ||
inRect(cell.x, cell.z, -8, -1, 7, 12)
) {
color.setHex(palette.field);
color.offsetHSL(0, 0, (noise - 0.5) * 0.04);
}
if (routeDistance < 0.72) {
color.setHex(palette.path);
color.offsetHSL(0, 0, (noise - 0.5) * 0.035);
}
if (cell.streamDistance < 1.55) {
color.setHex(currentSeason === "winter" ? 0xbac9c8 : 0x8e9980);
color.offsetHSL(0, 0, (noise - 0.5) * 0.05);
}
terrainMesh.setColorAt(index, color);
});
terrainMesh.instanceColor.needsUpdate = true;
}
updateTerrainColors();
// ------------------------------------------------------------
// Stream, banks, and bridges
// ------------------------------------------------------------
const waterCells = terrainCells.filter(
(cell) => cell.streamDistance < 1.48
);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x67a8bd,
roughness: 0.3,
metalness: 0.05,
transparent: true,
opacity: 0.93
});
const waterMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.985, 0.18, 0.985),
waterMaterial,
waterCells.length
);
waterMesh.receiveShadow = true;
waterCells.forEach((cell, index) => {
terrainMatrix.compose(
new THREE.Vector3(cell.x, 0.05, cell.z),
terrainQuaternion,
new THREE.Vector3(1, 1, 1)
);
waterMesh.setMatrixAt(index, terrainMatrix);
});
waterMesh.instanceMatrix.needsUpdate = true;
scene.add(waterMesh);
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x79513a,
roughness: 0.9
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
color: 0x4d372b,
roughness: 0.95
});
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x777d72,
roughness: 1
});
function makeBox(
width,
height,
depth,
material,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeBridge(centerX, z, span, deckY, width, labelColor) {
const group = new THREE.Group();
scene.add(group);
const plankCount = Math.ceil(span / 0.42);
const plankWidth = span / plankCount;
for (let i = 0; i < plankCount; i++) {
const x = centerX - span / 2 + plankWidth * (i + 0.5);
const plank = makeBox(
plankWidth - 0.025,
0.18,
width,
woodMaterial,
x,
deckY,
z,
group
);
plank.rotation.y = ((i % 3) - 1) * 0.006;
}
const pierCount = z === bridgeZ ? 3 : 2;
for (let i = 0; i < pierCount; i++) {
const x =
centerX -
span / 2 +
(span * (i + 0.5)) / pierCount;
makeBox(
0.32,
deckY + 1.0,
width * 0.65,
stoneMaterial,
x,
(deckY - 1.0) / 2,
z,
group
);
}
for (const side of [-1, 1]) {
const railZ = z + side * (width / 2 + 0.04);
makeBox(
span + 0.3,
0.13,
0.13,
darkWoodMaterial,
centerX,
deckY + 0.92,
railZ,
group
);
const postCount = Math.ceil(span / 0.8);
for (let i = 0; i <= postCount; i++) {
const x = centerX - span / 2 + (span * i) / postCount;
makeBox(
0.13,
1.05,
0.13,
darkWoodMaterial,
x,
deckY + 0.5,
railZ,
group
);
}
}
group.userData.deckMaterial = woodMaterial;
return group;
}
const mainBridge = makeBridge(
mainBridgeX,
bridgeZ,
5.5,
1.52,
1.45,
0x078f86
);
const northBridge = makeBridge(
northBridgeX,
northBridgeZ,
3.8,
1.42,
1.08,
0xe88b28
);
// Stepping stones across the southern stream.
for (let i = 0; i < 7; i++) {
const x = meadowStepsX - 1.5 + i * 0.5;
const stone = makeBox(
0.38,
0.35 + (i % 2) * 0.06,
0.62,
stoneMaterial,
x,
0.17,
meadowStepsZ
);
stone.rotation.y = (i % 2 ? 1 : -1) * 0.08;
}
// ------------------------------------------------------------
// Route ribbons
// ------------------------------------------------------------
function routeHeight(x, z) {
let height = groundTop(x, z) + 0.14;
if (
Math.abs(z - bridgeZ) < 0.75 &&
Math.abs(x - mainBridgeX) < 3.15
) {
height = Math.max(height, 1.66);
}
if (
Math.abs(z - northBridgeZ) < 0.7 &&
Math.abs(x - northBridgeX) < 2.2
) {
height = Math.max(height, 1.56);
}
if (
Math.abs(z - meadowStepsZ) < 0.65 &&
Math.abs(x - meadowStepsX) < 1.9
) {
height = Math.max(height, 0.54);
}
return height;
}
const routeMeshes = new Map();
function createRouteRibbon(route) {
const matrices = [];
const matrix = new THREE.Matrix4();
const position = new THREE.Vector3();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
const direction = new THREE.Vector3();
const xAxis = new THREE.Vector3(1, 0, 0);
for (let i = 0; i < route.points.length - 1; i++) {
const a = route.points[i];
const b = route.points[i + 1];
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
const count = Math.max(1, Math.ceil(length / 0.34));
for (let j = 0; j < count; j++) {
const t0 = j / count;
const t1 = (j + 1) / count;
const t = (t0 + t1) / 2;
const x = THREE.MathUtils.lerp(a[0], b[0], t);
const z = THREE.MathUtils.lerp(a[1], b[1], t);
const x2 = THREE.MathUtils.lerp(a[0], b[0], t1);
const z2 = THREE.MathUtils.lerp(a[1], b[1], t1);
const y = routeHeight(x, z);
const y2 = routeHeight(x2, z2);
direction.set(x2 - x, y2 - y, z2 - z);
const segmentLength = direction.length();
direction.normalize();
quaternion.setFromUnitVectors(xAxis, direction);
position.set((x + x2) / 2, (y + y2) / 2, (z + z2) / 2);
scale.set(segmentLength + 0.035, 0.13, 0.19);
matrix.compose(position, quaternion, scale);
matrices.push(matrix.clone());
}
}
const material = new THREE.MeshStandardMaterial({
color: route.color,
emissive: route.color,
emissiveIntensity: 0.18,
roughness: 0.65,
transparent: true,
opacity: 0.95
});
const mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
material,
matrices.length
);
matrices.forEach((item, index) => mesh.setMatrixAt(index, item));
mesh.instanceMatrix.needsUpdate = true;
mesh.renderOrder = 2;
scene.add(mesh);
routeMeshes.set(route.id, mesh);
// Small pale studs make the line read as a marked route.
const studMaterial = new THREE.MeshBasicMaterial({
color: 0xfff5d8,
transparent: true,
opacity: 0.88
});
const studs = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.11, 0.12, 0.11),
studMaterial,
Math.max(2, Math.floor(matrices.length / 6))
);
let studIndex = 0;
for (let i = 0; i < matrices.length; i += 6) {
const item = matrices[i];
const p = new THREE.Vector3();
const q = new THREE.Quaternion();
const s = new THREE.Vector3();
item.decompose(p, q, s);
p.y += 0.11;
const studMatrix = new THREE.Matrix4().compose(
p,
q,
new THREE.Vector3(1, 1, 1)
);
studs.setMatrixAt(studIndex++, studMatrix);
}
studs.count = studIndex;
studs.instanceMatrix.needsUpdate = true;
scene.add(studs);
}
routes.forEach(createRouteRibbon);
// ------------------------------------------------------------
// Buildings
// ------------------------------------------------------------
const roofMaterials = [];
const wallMaterials = [];
function makeBuilding({
x,
z,
width,
depth,
height,
wallColor,
roofColor,
windows = 2,
doorColor = 0x4a5c50,
school = false,
barn = false
}) {
const group = new THREE.Group();
const base = groundTop(x, z);
group.position.set(x, base, z);
scene.add(group);
const wallMaterial = new THREE.MeshStandardMaterial({
color: wallColor,
roughness: 0.88
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: roofColor,
roughness: 0.9
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0xf4eddb,
roughness: 0.85
});
const windowMaterial = new THREE.MeshStandardMaterial({
color: school ? 0x89b7c6 : 0xf2c76f,
emissive: school ? 0x193b46 : 0x6d491c,
emissiveIntensity: 0.18,
roughness: 0.35
});
const doorMaterial = new THREE.MeshStandardMaterial({
color: doorColor,
roughness: 0.9
});
wallMaterials.push(wallMaterial);
roofMaterials.push({ material: roofMaterial, original: roofColor });
makeBox(
width + 0.28,
0.28,
depth + 0.28,
stoneMaterial,
0,
0.02,
0,
group
);
makeBox(width, height, depth, wallMaterial, 0, height / 2, 0, group);
// Stepped voxel gable roof.
const strips = 3;
const stripWidth = width / (strips * 2);
const roofDepth = depth + 0.65;
for (const side of [-1, 1]) {
for (let i = 0; i < strips; i++) {
const roofX =
side * (width / 2 - (i + 0.5) * stripWidth);
const roofY = height + 0.15 + i * 0.22;
makeBox(
stripWidth + 0.025,
0.28,
roofDepth,
roofMaterial,
roofX,
roofY,
0,
group
);
}
}
makeBox(
0.3,
0.28,
roofDepth,
roofMaterial,
0,
height + 0.81,
0,
group
);
// Front door and windows.
makeBox(
school ? 1.0 : 0.72,
school ? 1.65 : 1.35,
0.12,
doorMaterial,
0,
(school ? 1.65 : 1.35) / 2,
depth / 2 + 0.075,
group
);
const windowPositions = [];
if (windows <= 2) {
windowPositions.push(-width * 0.29, width * 0.29);
} else {
windowPositions.push(-width * 0.34, 0, width * 0.34);
}
for (const windowX of windowPositions) {
makeBox(
school ? 0.9 : 0.66,
school ? 0.85 : 0.7,
0.12,
trimMaterial,
windowX,
height * 0.6,
depth / 2 + 0.075,
group
);
makeBox(
school ? 0.68 : 0.48,
school ? 0.63 : 0.5,
0.13,
windowMaterial,
windowX,
height * 0.6,
depth / 2 + 0.095,
group
);
}
if (school) {
// Bell tower and clock face.
makeBox(
1.15,
1.9,
1.15,
wallMaterial,
-width * 0.31,
height + 0.75,
-0.1,
group
);
makeBox(
1.42,
0.22,
1.42,
roofMaterial,
-width * 0.31,
height + 1.82,
-0.1,
group
);
const clockMaterial = new THREE.MeshStandardMaterial({
color: 0xfff5d7,
emissive: 0x8b7446,
emissiveIntensity: 0.12
});
makeBox(
0.52,
0.52,
0.08,
clockMaterial,
-width * 0.31,
height + 0.87,
0.53,
group
);
// Flagpole.
makeBox(
0.08,
2.7,
0.08,
darkWoodMaterial,
width * 0.28,
height + 1.35,
0,
group
);
const flagMaterial = new THREE.MeshStandardMaterial({
color: 0xd56b45,
roughness: 0.8
});
makeBox(
0.82,
0.48,
0.06,
flagMaterial,
width * 0.28 + 0.41,
height + 2.35,
0,
group
);
}
if (barn) {
makeBox(
1.0,
1.65,
0.13,
trimMaterial,
0,
0.83,
depth / 2 + 0.085,
group
);
makeBox(
0.12,
1.55,
0.15,
darkWoodMaterial,
0,
0.78,
depth / 2 + 0.12,
group
);
}
// Small chimney.
if (!school) {
makeBox(
0.42,
1.1,
0.42,
stoneMaterial,
width * 0.25,
height + 0.55,
-depth * 0.18,
group
);
}
return group;
}
const schoolGroup = makeBuilding({
x: 12,
z: -9,
width: 6,
depth: 4,
height: 3.1,
wallColor: 0xede4cf,
roofColor: 0x8c4443,
windows: 3,
school: true
});
makeBuilding({
x: -16,
z: 6.5,
width: 3.5,
depth: 3,
height: 2.4,
wallColor: 0xe2c69a,
roofColor: 0x596d5b
});
makeBuilding({
x: -16,
z: 11.6,
width: 3.8,
depth: 3.1,
height: 2.55,
wallColor: 0xd8d5bd,
roofColor: 0x6a4c46
});
makeBuilding({
x: -8.3,
z: 11.4,
width: 3.3,
depth: 2.8,
height: 2.35,
wallColor: 0xe6bd88,
roofColor: 0x4f6658
});
makeBuilding({
x: -15,
z: -1.5,
width: 5,
depth: 4,
height: 3.15,
wallColor: 0x9e4e3d,
roofColor: 0x473c38,
windows: 2,
barn: true
});
makeBuilding({
x: 15.2,
z: 1.5,
width: 3.8,
depth: 3.2,
height: 2.6,
wallColor: 0xc6c7a7,
roofColor: 0x4f5f63
});
// School playground.
const playground = new THREE.Group();
playground.position.set(16.2, groundTop(16.2, -6.5), -6.5);
scene.add(playground);
const slideMaterial = new THREE.MeshStandardMaterial({
color: 0xe0a43b,
roughness: 0.65
});
const swingMaterial = new THREE.MeshStandardMaterial({
color: 0x3d7180,
roughness: 0.8
});
makeBox(0.18, 1.8, 0.18, swingMaterial, -0.9, 0.9, 0, playground);
makeBox(0.18, 1.8, 0.18, swingMaterial, 0.9, 0.9, 0, playground);
makeBox(2.0, 0.16, 0.16, swingMaterial, 0, 1.72, 0, playground);
makeBox(0.08, 0.95, 0.08, darkWoodMaterial, -0.35, 1.22, 0, playground);
makeBox(0.08, 0.95, 0.08, darkWoodMaterial, 0.35, 1.22, 0, playground);
makeBox(0.9, 0.1, 0.35, swingMaterial, 0, 0.72, 0, playground);
makeBox(0.18, 1.45, 0.18, slideMaterial, -1.6, 0.72, 0.9, playground);
makeBox(0.18, 1.45, 0.18, slideMaterial, -0.8, 0.72, 0.9, playground);
makeBox(1.05, 0.16, 1.45, slideMaterial, -1.2, 1.4, 0.35, playground);
makeBox(0.9, 0.15, 1.6, slideMaterial, -1.2, 0.35, 1.2, playground);
// ------------------------------------------------------------
// Trees, orchard, crops, and fences
// ------------------------------------------------------------
const buildingBounds = [
{ x: 12, z: -9, w: 7, d: 5 },
{ x: -16, z: 6.5, w: 4.5, d: 4 },
{ x: -16, z: 11.6, w: 4.8, d: 4 },
{ x: -8.3, z: 11.4, w: 4.3, d: 3.8 },
{ x: -15, z: -1.5, w: 6, d: 5 },
{ x: 15.2, z: 1.5, w: 4.8, d: 4.2 },
{ x: 16.2, z: -6.5, w: 4, d: 4 }
];
function blockedByBuilding(x, z, margin = 0.8) {
return buildingBounds.some(
(building) =>
Math.abs(x - building.x) < building.w / 2 + margin &&
Math.abs(z - building.z) < building.d / 2 + margin
);
}
const treePositions = [];
// Deliberately arranged orchard rows.
for (const x of [-10.5, -7.6, -4.7]) {
for (const z of [-8.8, -6.3]) {
treePositions.push({
x: x + (seededNoise(x, z) - 0.5) * 0.25,
z: z + (seededNoise(z, x) - 0.5) * 0.25,
scale: 0.78 + seededNoise(x * 2, z) * 0.16,
orchard: true
});
}
}
// Randomized trees elsewhere, kept clear of paths and structures.
let attempts = 0;
while (treePositions.length < 92 && attempts < 1600) {
attempts++;
const x = -21.2 + seededNoise(attempts * 1.7, 8.3) * 42.4;
const z = -17.1 + seededNoise(4.1, attempts * 2.1) * 34.2;
const streamDistance = Math.abs(x - creekX(z));
const routeDistance = Math.min(
...routes.map((route) => distanceToPolyline(x, z, route.points))
);
const inOrchard = inRect(x, z, -13, -3, -11, -4);
const inField =
inRect(x, z, -12, -4, -9, -5) ||
inRect(x, z, 1, 5, -7, 0) ||
inRect(x, z, -8, -1, 7, 12);
if (
streamDistance < 2.15 ||
routeDistance < 1.35 ||
blockedByBuilding(x, z) ||
inOrchard ||
inField
) {
continue;
}
treePositions.push({
x,
z,
scale: 0.78 + seededNoise(x * 3, z * 4) * 0.5,
orchard: false
});
}
const trunkMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.34, 1, 0.34),
new THREE.MeshStandardMaterial({ color: 0x73503b, roughness: 1 }),
treePositions.length
);
const foliageMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
vertexColors: false
}),
treePositions.length * 3
);
trunkMesh.castShadow = true;
foliageMesh.castShadow = true;
foliageMesh.receiveShadow = true;
scene.add(trunkMesh, foliageMesh);
const treeMatrix = new THREE.Matrix4();
const treePosition = new THREE.Vector3();
const treeScale = new THREE.Vector3();
const identityQuaternion = new THREE.Quaternion();
treePositions.forEach((tree, index) => {
const base = groundTop(tree.x, tree.z);
const trunkHeight = 1.45 * tree.scale;
treePosition.set(tree.x, base + trunkHeight / 2, tree.z);
treeScale.set(tree.scale, trunkHeight, tree.scale);
treeMatrix.compose(treePosition, identityQuaternion, treeScale);
trunkMesh.setMatrixAt(index, treeMatrix);
const crownBase = base + trunkHeight;
const crownSizes = [
[1.55, 1.25, 1.55, 0],
[1.22, 1.08, 1.22, 0.76],
[0.82, 0.78, 0.82, 1.4]
];
crownSizes.forEach((crown, crownIndex) => {
treePosition.set(
tree.x + (crownIndex === 1 ? 0.08 : 0),
crownBase + crown[3] * tree.scale,
tree.z + (crownIndex === 2 ? 0.06 : 0)
);
treeScale.set(
crown[0] * tree.scale,
crown[1] * tree.scale,
crown[2] * tree.scale
);
treeMatrix.compose(treePosition, identityQuaternion, treeScale);
foliageMesh.setMatrixAt(index * 3 + crownIndex, treeMatrix);
});
});
trunkMesh.instanceMatrix.needsUpdate = true;
foliageMesh.instanceMatrix.needsUpdate = true;
scene.add(foliageMesh);
function updateFoliageColors() {
const palette = seasonPalettes[currentSeason];
treePositions.forEach((tree, index) => {
for (let crownIndex = 0; crownIndex < 3; crownIndex++) {
const colorIndex =
(index + crownIndex) % palette.foliage.length;
const color = new THREE.Color(palette.foliage[colorIndex]);
color.offsetHSL(0, 0, (seededNoise(index, crownIndex) - 0.5) * 0.055);
foliageMesh.setColorAt(index * 3 + crownIndex, color);
}
});
foliageMesh.instanceColor.needsUpdate = true;
}
updateFoliageColors();
// Crop rows in the eastern field.
const cropMaterial = new THREE.MeshStandardMaterial({
color: 0x557f43,
roughness: 1
});
const cropGeometry = new THREE.BoxGeometry(0.13, 0.42, 0.75);
const cropPositions = [];
for (let x = 1.2; x <= 4.6; x += 0.6) {
for (let z = -6.5; z <= -0.5; z += 0.9) {
if (Math.abs(x - creekX(z)) > 1.5) {
cropPositions.push([x, z]);
}
}
}
const cropMesh = new THREE.InstancedMesh(
cropGeometry,
cropMaterial,
cropPositions.length
);
cropPositions.forEach((position, index) => {
treePosition.set(
position[0],
groundTop(position[0], position[1]) + 0.19,
position[1]
);
treeScale.set(1, 1, 1);
treeMatrix.compose(treePosition, identityQuaternion, treeScale);
cropMesh.setMatrixAt(index, treeMatrix);
});
cropMesh.instanceMatrix.needsUpdate = true;
cropMesh.castShadow = true;
scene.add(cropMesh);
// Simple post-and-rail fences around the farm yard.
function addFence(x0, x1, z0, z1) {
const postMaterial = woodMaterial;
function railBetween(ax, az, bx, bz) {
const length = Math.hypot(bx - ax, bz - az);
const rail = makeBox(
length,
0.09,
0.09,
postMaterial,
(ax + bx) / 2,
groundTop((ax + bx) / 2, (az + bz) / 2) + 0.55,
(az + bz) / 2
);
rail.rotation.y = -Math.atan2(bz - az, bx - ax);
}
const count = Math.ceil(Math.max(x1 - x0, z1 - z0) / 1.4);
for (let i = 0; i <= count; i++) {
const t = i / count;
const x = THREE.MathUtils.lerp(x0, x1, t);
const z = THREE.MathUtils.lerp(z0, z1, t);
makeBox(
0.12,
0.95,
0.12,
postMaterial,
x,
groundTop(x, z) + 0.42,
z
);
}
railBetween(x0, z0, x1, z0);
railBetween(x1, z0, x1, z1);
}
addFence(-19.2, -11.2, 3.6, 3.6);
addFence(-19.2, -19.2, 3.6, -4.4);
addFence(-11.2, -11.2, -4.4, 3.6);
// ------------------------------------------------------------
// Seasonal details and clouds
// ------------------------------------------------------------
const flowerGroup = new THREE.Group();
const flowerGeometry = new THREE.BoxGeometry(0.1, 0.16, 0.1);
const flowerMaterial = new THREE.MeshStandardMaterial({
color: 0xf0c557,
roughness: 0.75
});
const flowerMesh = new THREE.InstancedMesh(
flowerGeometry,
flowerMaterial,
65
);
let flowerIndex = 0;
for (let i = 0; i < 400 && flowerIndex < 65; i++) {
const x = -8 + seededNoise(i * 2.3, 4.7) * 10;
const z = 9 + seededNoise(8.9, i * 1.6) * 5.5;
const routeDistance = Math.min(
...routes.map((route) => distanceToPolyline(x, z, route.points))
);
if (routeDistance < 0.6) continue;
treePosition.set(x, groundTop(x, z) + 0.12, z);
treeScale.set(1, 1, 1);
treeMatrix.compose(treePosition, identityQuaternion, treeScale);
flowerMesh.setMatrixAt(flowerIndex++, treeMatrix);
}
flowerMesh.count = flowerIndex;
flowerMesh.instanceMatrix.needsUpdate = true;
flowerGroup.add(flowerMesh);
scene.add(flowerGroup);
const leafGroup = new THREE.Group();
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0xc97638,
roughness: 0.95
});
const leafMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.13, 0.04, 0.18),
leafMaterial,
55
);
let leafIndex = 0;
for (let i = 0; i < 300 && leafIndex < 55; i++) {
const x = -21 + seededNoise(i * 3.1, 2.6) * 42;
const z = -17 + seededNoise(7.2, i * 2.4) * 34;
treePosition.set(x, groundTop(x, z) + 0.12, z);
treeScale.set(1, 1, 1);
treeMatrix.compose(treePosition, identityQuaternion, treeScale);
leafMesh.setMatrixAt(leafIndex++, treeMatrix);
}
leafMesh.count = leafIndex;
leafMesh.instanceMatrix.needsUpdate = true;
leafGroup.add(leafMesh);
scene.add(leafGroup);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xf5f4e9,
roughness: 1,
transparent: true,
opacity: 0.84
});
const clouds = [];
for (let i = 0; i < 6; i++) {
const cloud = new THREE.Group();
const baseX = -27 + i * 10;
const baseZ = -12 + seededNoise(i, 9) * 25;
makeBox(2.8, 0.65, 1.25, cloudMaterial, 0, 0, 0, cloud);
makeBox(1.5, 0.8, 1.1, cloudMaterial, -1.35, 0.12, 0, cloud);
makeBox(1.45, 0.7, 1.05, cloudMaterial, 1.45, 0.08, 0.05, cloud);
cloud.position.set(baseX, 15 + seededNoise(i, 4) * 4, baseZ);
cloud.userData.baseX = baseX;
clouds.push(cloud);
scene.add(cloud);
}
// ------------------------------------------------------------
// HTML map labels projected from 3D positions
// ------------------------------------------------------------
const mapLabels = [];
function addLabel(text, x, y, z, options = {}) {
const element = document.createElement("div");
element.className = `map-label${options.minor ? " minor minor-marker" : ""}`;
if (options.color) element.style.setProperty("--dot", options.color);
element.textContent = text;
labelsLayer.appendChild(element);
mapLabels.push({
element,
position: new THREE.Vector3(x, y, z)
});
}
addLabel("Brackenfold School", 12, groundTop(12, -9) + 5.8, -9, {
color: "#c8543f"
});
addLabel("Lane End Gate", -13, groundTop(-13, 10) + 1.6, 10, {
color: "#4e7467"
});
addLabel("Creek Bridge", mainBridgeX, 3.0, bridgeZ, {
color: "#078f86"
});
addLabel("North Footbridge", northBridgeX, 2.8, northBridgeZ, {
color: "#e88b28",
minor: true
});
addLabel("Meadow Steps", meadowStepsX, 1.2, meadowStepsZ, {
color: "#c94e78",
minor: true
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
mapLabels.forEach((label) => {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
label.element.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
});
}
// ------------------------------------------------------------
// Route and season interface
// ------------------------------------------------------------
function updateRouteInterface() {
routes.forEach((route) => {
document.querySelector(`[data-distance="${route.id}"]`).textContent =
routeDistanceKm(route).toFixed(1);
document.querySelector(`[data-time="${route.id}"]`).textContent =
routeTimeMinutes(route, currentSeason);
});
const route = routes.find((item) => item.id === selectedRoute);
const isClosed = route.id === "C" && !["spring", "summer"].includes(currentSeason);
const warning = route.id !== "C" && currentSeason === "winter";
routeDetail.innerHTML = `
<h3>${route.name}</h3>
<p><strong>Surface:</strong> ${route.surface}<br>${route.description}</p>
<span class="condition${isClosed || warning ? " warning" : ""}">
${
isClosed
? "Closed in this model for the selected season"
: warning
? "Winter estimate includes a 20% adverse-condition allowance"
: route.availability
}
</span>
`;
document.querySelectorAll(".route-card").forEach((card) => {
card.classList.toggle("active", card.dataset.route === selectedRoute);
});
routeMeshes.forEach((mesh, id) => {
const active = id === selectedRoute;
const closed = id === "C" && !["spring", "summer"].includes(currentSeason);
mesh.material.opacity = active ? (closed ? 0.42 : 0.98) : 0.27;
mesh.material.emissiveIntensity = active ? 0.26 : 0.06;
mesh.scale.setScalar(active ? 1.08 : 1);
});
document.querySelector(`[data-state="C"]`).textContent =
["spring", "summer"].includes(currentSeason) ? "May–Sep" : "Closed";
document
.querySelector(`[data-route="C"]`)
.classList.toggle(
"closed",
!["spring", "summer"].includes(currentSeason)
);
selectedStatus.textContent = `Route ${route.id} selected · ${
isClosed ? "closed in model" : `${routeTimeMinutes(route, currentSeason)} min modeled walk`
}`;
}
function updateSeason(season) {
currentSeason = season;
const palette = seasonPalettes[season];
document.querySelectorAll(".season-button").forEach((button) => {
button.classList.toggle("active", button.dataset.season === season);
});
seasonStatus.textContent =
season.charAt(0).toUpperCase() + season.slice(1);
scene.background.setHex(palette.sky);
scene.fog.color.setHex(palette.sky);
sun.color.setHex(palette.sun);
sun.intensity = palette.intensity;
hemisphere.intensity = season === "winter" ? 1.65 : 2.0;
waterMaterial.color.setHex(palette.water);
cropMaterial.color.setHex(palette.crop);
roofMaterials.forEach(({ material, original }) => {
material.color.setHex(season === "winter" ? 0xe8edeb : original);
});
flowerGroup.visible = season === "spring" || season === "summer";
leafGroup.visible = season === "autumn";
updateTerrainColors();
updateFoliageColors();
updateRouteInterface();
}
document.querySelectorAll(".route-card").forEach((card) => {
card.addEventListener("click", () => {
selectedRoute = card.dataset.route;
updateRouteInterface();
});
});
document.querySelectorAll(".season-button").forEach((button) => {
button.addEventListener("click", () => {
updateSeason(button.dataset.season);
});
});
// ------------------------------------------------------------
// Animation and resize
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
clouds.forEach((cloud, index) => {
cloud.position.x =
cloud.userData.baseX + Math.sin(elapsed * 0.035 + index) * 2.2;
});
waterMaterial.opacity =
currentSeason === "winter" ? 0.88 : 0.9 + Math.sin(elapsed * 1.2) * 0.025;
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateSeason("spring");
updateRouteInterface();
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
});
</script>
</body>
</html>
```