Prompt specification
Build or customize the Three.js 3D scene "Seasonal resource planning diorama" 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 resource planning diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/seasonal-resource-planning-diorama-x1248
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: seasonal resource planning diorama. Provide selectable seasonal states for a small farm and nearby wetland; highlight changed shade, vegetation, and water storage qualitatively without prescribing agriculture or forecasting weather. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (seasonal-resource-planning-diorama-x1248):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Seasonal Resource Planning Diorama</title>
<style>
:root {
--ink: #24342f;
--muted: #63736d;
--panel: rgba(250, 252, 248, 0.93);
--line: rgba(42, 65, 56, 0.14);
--accent: #315f50;
--accent-soft: #dce9df;
--shadow: 0 16px 42px rgba(39, 62, 53, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe9e3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, select { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.masthead {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
width: min(390px, calc(100vw - 48px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 7px;
color: #46665a;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 2px;
background: #4d7967;
box-shadow: 4px 4px 0 #b4cbb9;
}
h1 {
max-width: 370px;
margin: 0;
font-size: clamp(1.55rem, 2.7vw, 2.45rem);
line-height: 1.04;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 360px;
margin: 9px 0 0;
color: var(--muted);
font-size: 0.86rem;
line-height: 1.45;
}
.panel {
position: fixed;
z-index: 6;
top: 152px;
left: 24px;
width: 326px;
max-height: calc(100vh - 176px);
overflow: auto;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
scrollbar-width: thin;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 11px;
}
.section-heading h2,
.section-heading h3 {
margin: 0;
font-size: 0.74rem;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.section-heading h3 { color: #4e625a; }
.small-badge {
padding: 4px 7px;
border-radius: 999px;
background: var(--accent-soft);
color: #416353;
font-size: 0.62rem;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.state-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
}
.state-button {
min-width: 0;
padding: 10px 4px 9px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.65);
color: #586a63;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
color 160ms ease;
}
.state-button:hover {
transform: translateY(-1px);
border-color: rgba(49, 95, 80, 0.34);
}
.state-button[aria-pressed="true"] {
border-color: var(--accent);
background: var(--accent);
color: white;
box-shadow: 0 6px 16px rgba(49, 95, 80, 0.2);
}
.state-dot {
display: block;
width: 13px;
height: 13px;
margin: 0 auto 7px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.state-button span:last-child {
font-size: 0.72rem;
font-weight: 750;
}
.season-caption {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin: 16px 0 12px;
padding-bottom: 12px;
border-bottom: 1px solid var(--line);
}
.season-caption strong {
display: block;
margin-bottom: 2px;
font-size: 1.12rem;
letter-spacing: -0.025em;
}
.season-caption small {
color: var(--muted);
font-size: 0.72rem;
}
.season-glyph {
flex: 0 0 auto;
width: 38px;
height: 38px;
border: 1px solid var(--line);
border-radius: 12px;
background:
linear-gradient(135deg, transparent 48%, rgba(255,255,255,.65) 49% 53%, transparent 54%),
var(--glyph-color, #88a96d);
box-shadow: inset 0 0 0 5px rgba(255,255,255,.2);
}
.measure-list {
display: grid;
gap: 8px;
}
.measure {
display: grid;
grid-template-columns: 34px 1fr;
align-items: center;
gap: 10px;
padding: 9px;
border: 1px solid rgba(49, 75, 65, 0.08);
border-radius: 12px;
background: rgba(255, 255, 255, 0.48);
}
.measure-swatch {
width: 34px;
height: 34px;
border-radius: 9px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.measure small {
display: block;
margin-bottom: 2px;
color: var(--muted);
font-size: 0.64rem;
font-weight: 750;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.measure strong {
font-size: 0.79rem;
font-weight: 750;
}
.comparison {
margin-top: 17px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.compare-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
select {
max-width: 138px;
padding: 6px 27px 6px 9px;
border: 1px solid var(--line);
border-radius: 8px;
background: white;
color: var(--ink);
font-size: 0.72rem;
font-weight: 700;
cursor: pointer;
}
.delta-list { display: grid; gap: 7px; }
.delta-item {
display: grid;
grid-template-columns: 42px 1fr;
align-items: center;
gap: 9px;
padding: 8px 9px;
border-radius: 10px;
background: rgba(222, 235, 226, 0.7);
}
.delta-item.same {
background: rgba(235, 238, 233, 0.62);
}
.delta-swatches {
display: flex;
align-items: center;
}
.delta-swatches i {
display: block;
width: 22px;
height: 22px;
border: 2px solid rgba(255,255,255,.9);
border-radius: 7px;
box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.delta-swatches i + i { margin-left: -7px; }
.delta-item small {
display: block;
color: var(--muted);
font-size: 0.61rem;
font-weight: 750;
letter-spacing: .06em;
text-transform: uppercase;
}
.delta-item strong {
display: block;
margin-top: 2px;
font-size: 0.73rem;
}
.disclaimer {
margin: 14px 0 0;
color: #687871;
font-size: 0.66rem;
line-height: 1.45;
}
.toolbar {
position: fixed;
z-index: 7;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
}
.tool-button {
display: grid;
place-items: center;
width: 42px;
height: 42px;
padding: 0;
border: 1px solid rgba(255,255,255,.75);
border-radius: 12px;
background: rgba(250,252,248,.9);
color: #3e5c50;
box-shadow: 0 8px 20px rgba(42,65,56,.12);
cursor: pointer;
backdrop-filter: blur(10px);
}
.tool-button:hover { background: white; }
.tool-button svg {
width: 19px;
height: 19px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.8;
}
.legend {
position: fixed;
z-index: 5;
right: 24px;
bottom: 24px;
width: 224px;
padding: 13px 14px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 14px;
background: rgba(250,252,248,.88);
box-shadow: 0 12px 30px rgba(42,65,56,.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 9px;
font-size: 0.66rem;
font-weight: 850;
letter-spacing: .1em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 6px;
color: #52665e;
font-size: 0.68rem;
}
.legend-row i {
width: 14px;
height: 14px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.legend-note {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: #728078;
font-size: 0.62rem;
line-height: 1.4;
}
.hint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 999px;
background: rgba(41, 64, 55, 0.74);
color: rgba(255,255,255,.9);
font-size: 0.65rem;
pointer-events: none;
backdrop-filter: blur(8px);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.masthead {
top: 14px;
left: 14px;
width: calc(100vw - 76px);
}
h1 { font-size: 1.42rem; }
.subtitle { display: none; }
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 13px;
border-radius: 16px;
}
.state-grid { gap: 5px; }
.state-button { padding: 8px 2px; }
.season-caption { margin: 11px 0 9px; padding-bottom: 9px; }
.measure-list { grid-template-columns: repeat(3, 1fr); }
.measure {
grid-template-columns: 1fr;
gap: 6px;
align-items: start;
}
.measure-swatch { width: 100%; height: 23px; }
.comparison { margin-top: 11px; padding-top: 10px; }
.delta-list { grid-template-columns: repeat(3, 1fr); }
.delta-item {
grid-template-columns: 1fr;
align-items: start;
}
.disclaimer { display: none; }
.toolbar { top: 14px; right: 14px; }
.legend, .hint { display: none; }
}
@media (max-width: 430px) {
.measure strong { font-size: .69rem; }
.measure small { font-size: .55rem; }
.delta-item strong { font-size: .65rem; }
.compare-row { align-items: flex-start; flex-direction: column; }
select { max-width: 100%; width: 100%; }
}
</style>
</head>
<body>
<div id="scene" role="img" aria-label="Interactive voxel diorama of a small farm beside a wetland"></div>
<header class="masthead">
<p class="eyebrow">Seasonal states</p>
<h1>Farm & wetland diorama</h1>
<p class="subtitle">
Compare qualitative seasonal shifts in shade, vegetation, and visible water storage.
</p>
</header>
<aside class="panel" aria-label="Seasonal comparison controls">
<div class="section-heading">
<h2>Selected state</h2>
<span class="small-badge">Illustrative</span>
</div>
<div class="state-grid" role="group" aria-label="Choose a seasonal state">
<button class="state-button" data-season="spring" aria-pressed="true">
<i class="state-dot" style="background:#91ad77"></i>
<span>Spring</span>
</button>
<button class="state-button" data-season="summer" aria-pressed="false">
<i class="state-dot" style="background:#5f8f5c"></i>
<span>Summer</span>
</button>
<button class="state-button" data-season="autumn" aria-pressed="false">
<i class="state-dot" style="background:#c18a49"></i>
<span>Autumn</span>
</button>
<button class="state-button" data-season="winter" aria-pressed="false">
<i class="state-dot" style="background:#dce8e4"></i>
<span>Winter</span>
</button>
</div>
<div class="season-caption">
<div>
<strong id="seasonTitle">Spring</strong>
<small id="seasonTag">Fresh emergence and moderate visible water</small>
</div>
<div id="seasonGlyph" class="season-glyph" aria-hidden="true"></div>
</div>
<div class="measure-list">
<div class="measure">
<div id="shadeSwatch" class="measure-swatch" aria-hidden="true"></div>
<div>
<small>Shade & light</small>
<strong id="shadeValue">Fresh, light</strong>
</div>
</div>
<div class="measure">
<div id="vegetationSwatch" class="measure-swatch" aria-hidden="true"></div>
<div>
<small>Vegetation</small>
<strong id="vegetationValue">Emerging</strong>
</div>
</div>
<div class="measure">
<div id="waterSwatch" class="measure-swatch" aria-hidden="true"></div>
<div>
<small>Water storage · visual</small>
<strong id="waterValue">Moderate</strong>
</div>
</div>
</div>
<section class="comparison" aria-labelledby="comparisonTitle">
<div class="section-heading">
<h3 id="comparisonTitle">Changed from</h3>
</div>
<div class="compare-row">
<label for="compareSelect" class="sr-only">Comparison season</label>
<select id="compareSelect">
<option value="spring">Spring</option>
<option value="summer" selected>Summer</option>
<option value="autumn">Autumn</option>
<option value="winter">Winter</option>
</select>
<span class="small-badge">Visual delta</span>
</div>
<div id="deltaList" class="delta-list"></div>
</section>
<p class="disclaimer">
These are qualitative visual states only. They are not calibrated measurements,
agricultural recommendations, or weather forecasts.
</p>
</aside>
<div class="toolbar">
<button id="resetView" class="tool-button" type="button" aria-label="Reset camera view" title="Reset camera view">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 4v6h6"></path>
<path d="M5.6 15.2A7 7 0 1 0 6 8.5L4 10"></path>
</svg>
</button>
</div>
<div class="legend" aria-hidden="true">
<div class="legend-title">Visual cues</div>
<div class="legend-row"><i style="background:#648d61"></i>Canopy shade</div>
<div class="legend-row"><i style="background:#91aa69"></i>Vegetation</div>
<div class="legend-row"><i style="background:#4f95a0"></i>Visible water</div>
<div class="legend-note">Swatches indicate relative visual character, not measured quantities.</div>
</div>
<div class="hint" aria-hidden="true">Drag to orbit · Shift-drag to pan · Scroll or pinch to zoom</div>
<div id="sceneStatus" class="sr-only" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const seasons = {
spring: {
name: "Spring",
tag: "Fresh emergence and moderate visible water",
ground: "#91ad77",
farm: "#7d9d66",
wetGround: "#738d68",
canopyA: "#78a968",
canopyB: "#a0c67a",
crop: "#72a653",
cropLight: "#a1c56d",
grass: "#7ca15f",
reeds: "#819c59",
water: "#5799a3",
waterDeep: "#3f7f8b",
shadeText: "Fresh, light",
vegetationText: "Emerging",
waterText: "Moderate",
cover: 0.58,
plantScale: 0.62,
waterLevel: 0.74,
sun: "#fff0c9",
sunIntensity: 2.15,
sky: "#d9edf0",
groundLight: "#7b715e",
snow: false
},
summer: {
name: "Summer",
tag: "Deeper canopy color and fuller vegetation",
ground: "#719963",
farm: "#6f9159",
wetGround: "#617f5c",
canopyA: "#477653",
canopyB: "#63905c",
crop: "#6f984d",
cropLight: "#8bad55",
grass: "#638c50",
reeds: "#688b4d",
water: "#4b929c",
waterDeep: "#347582",
shadeText: "Deeper, saturated",
vegetationText: "Dense",
waterText: "Moderate-low",
cover: 1.0,
plantScale: 1.0,
waterLevel: 0.62,
sun: "#fff5d6",
sunIntensity: 2.4,
sky: "#d5edf3",
groundLight: "#756a51",
snow: false
},
autumn: {
name: "Autumn",
tag: "Warm canopy tones and mixed vegetation",
ground: "#9b9565",
farm: "#8f835a",
wetGround: "#827b5d",
canopyA: "#b96f3f",
canopyB: "#d09a4c",
crop: "#997344",
cropLight: "#c3984e",
grass: "#9b8651",
reeds: "#aa8a4b",
water: "#5b8990",
waterDeep: "#46747b",
shadeText: "Warm, amber",
vegetationText: "Mixed color",
waterText: "Low",
cover: 0.92,
plantScale: 0.72,
waterLevel: 0.49,
sun: "#f7d7a3",
sunIntensity: 1.95,
sky: "#e9dfcf",
groundLight: "#796a52",
snow: false
},
winter: {
name: "Winter",
tag: "Pale shade, sparse vegetation, and limited visible water",
ground: "#dce8e4",
farm: "#b9b8aa",
wetGround: "#aabbb5",
canopyA: "#8fa4a4",
canopyB: "#b6c8c8",
crop: "#9d9e91",
cropLight: "#c0c2b8",
grass: "#a6b3a7",
reeds: "#999987",
water: "#9fbec0",
waterDeep: "#82a7ab",
shadeText: "Pale, cool",
vegetationText: "Sparse",
waterText: "Very low",
cover: 0.0,
plantScale: 0.16,
waterLevel: 0.34,
sun: "#dce9f2",
sunIntensity: 1.45,
sky: "#dce9ef",
groundLight: "#9aa5a0",
snow: true
}
};
const sceneHost = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel farm and wetland. Drag to orbit, shift-drag to pan, scroll or pinch to zoom, or use arrow keys."
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dbe9e3");
scene.fog = new THREE.Fog("#dbe9e3", 31, 65);
const camera = new THREE.OrthographicCamera(-12, 12, 8, -8, 0.1, 100);
const target = new THREE.Vector3(0.3, 0.25, 0);
let yaw = 0.72;
let pitch = 0.72;
let zoom = 1;
const hemi = new THREE.HemisphereLight("#d9edf0", "#7b715e", 1.65);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0c9", 2.15);
sun.position.set(-9, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0007;
sun.shadow.normalBias = 0.025;
scene.add(sun);
scene.add(sun.target);
const materials = {
soil: new THREE.MeshLambertMaterial({ color: "#77614c" }),
soilEdge: new THREE.MeshLambertMaterial({ color: "#624f3e" }),
ground: new THREE.MeshLambertMaterial({ color: "#91ad77" }),
farm: new THREE.MeshLambertMaterial({ color: "#7d9d66" }),
wetGround: new THREE.MeshLambertMaterial({ color: "#738d68" }),
path: new THREE.MeshLambertMaterial({ color: "#c4b695" }),
trunk: new THREE.MeshLambertMaterial({ color: "#75543a" }),
branch: new THREE.MeshLambertMaterial({ color: "#6e533d" }),
canopyA: new THREE.MeshLambertMaterial({ color: "#78a968" }),
canopyB: new THREE.MeshLambertMaterial({ color: "#a0c67a" }),
cropStem: new THREE.MeshLambertMaterial({ color: "#6f984d" }),
cropLeaf: new THREE.MeshLambertMaterial({ color: "#72a653" }),
cropLight: new THREE.MeshLambertMaterial({ color: "#a1c56d" }),
cropHead: new THREE.MeshLambertMaterial({ color: "#c6ad58" }),
grass: new THREE.MeshLambertMaterial({ color: "#7ca15f" }),
reeds: new THREE.MeshLambertMaterial({ color: "#819c59" }),
reedHead: new THREE.MeshLambertMaterial({ color: "#806846" }),
water: new THREE.MeshLambertMaterial({
color: "#5799a3",
transparent: true,
opacity: 0.82,
depthWrite: false
}),
snow: new THREE.MeshLambertMaterial({ color: "#edf4f1" }),
wall: new THREE.MeshLambertMaterial({ color: "#e0d0ae" }),
barn: new THREE.MeshLambertMaterial({ color: "#9b5744" }),
roof: new THREE.MeshLambertMaterial({ color: "#4d5b58" }),
barnRoof: new THREE.MeshLambertMaterial({ color: "#59625e" }),
door: new THREE.MeshLambertMaterial({ color: "#675441" }),
window: new THREE.MeshBasicMaterial({ color: "#f4d782" }),
fence: new THREE.MeshLambertMaterial({ color: "#d3c5a2" }),
stone: new THREE.MeshLambertMaterial({ color: "#8c9187" }),
litter: new THREE.MeshLambertMaterial({ color: "#bb713e" })
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(parent, size, position, material, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(...size);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// Ground plane and the raised voxel terrain slab.
const groundPlane = new THREE.Mesh(
new THREE.PlaneGeometry(160, 160),
new THREE.MeshLambertMaterial({ color: "#cbdcd3" })
);
groundPlane.rotation.x = -Math.PI / 2;
groundPlane.position.y = -1.18;
groundPlane.receiveShadow = true;
scene.add(groundPlane);
const board = new THREE.Group();
scene.add(board);
box(board, [16.25, 0.9, 12.25], [0, -0.75, 0], materials.soilEdge);
box(board, [16, 0.72, 12], [0, -0.71, 0], materials.soil);
const tileGeometry = new THREE.BoxGeometry(0.98, 0.34, 0.98);
const wetTileGeometry = new THREE.BoxGeometry(0.98, 0.24, 0.98);
for (let ix = 0; ix < 16; ix++) {
for (let iz = 0; iz < 12; iz++) {
const x = -7.5 + ix;
const z = -5.5 + iz;
const wetland = ix <= 5 && iz >= 6;
const farm = ix >= 9 && ix <= 13 && iz >= 2 && iz <= 8;
const path = ix === 7 || (iz === 5 && ix >= 6);
const material = path
? materials.path
: wetland
? materials.wetGround
: farm
? materials.farm
: materials.ground;
const geometry = wetland ? wetTileGeometry : tileGeometry;
const tile = new THREE.Mesh(geometry, material);
tile.position.set(x, wetland ? -0.19 : -0.12, z);
tile.receiveShadow = true;
board.add(tile);
}
}
// Board edge blocks emphasize the diorama construction.
box(board, [16.3, 0.24, 0.24], [0, -0.32, -6.03], materials.soilEdge);
box(board, [16.3, 0.24, 0.24], [0, -0.32, 6.03], materials.soilEdge);
box(board, [0.24, 0.24, 12.3], [-8.03, -0.32, 0], materials.soilEdge);
box(board, [0.24, 0.24, 12.3], [8.03, -0.32, 0], materials.soilEdge);
// Irregular wetland water is made from individual voxel cells.
const waterCells = [];
const pondLayout = [
[-6.5, 1.5, 0.78], [-5.5, 1.5, 0.72], [-4.5, 1.5, 0.65],
[-3.5, 1.5, 0.76],
[-6.5, 2.5, 0.66], [-5.5, 2.5, 0.42], [-4.5, 2.5, 0.25],
[-3.5, 2.5, 0.46], [-2.5, 2.5, 0.82],
[-6.5, 3.5, 0.74], [-5.5, 3.5, 0.48], [-4.5, 3.5, 0.28],
[-3.5, 3.5, 0.55],
[-5.5, 4.5, 0.82], [-4.5, 4.5, 0.69],
[-1.5, 4.5, 0.84], [-1.5, 3.5, 0.87]
];
for (const [x, z, threshold] of pondLayout) {
const cell = box(
board,
[0.94, 0.1, 0.94],
[x, -0.035, z],
materials.water,
false,
true
);
cell.userData.threshold = threshold;
waterCells.push(cell);
}
// Reed clusters around the wetland margin.
const reedPositions = [
[-7, 1.1], [-7, 2.2], [-6.7, 4.3], [-5.8, 5.0],
[-4.8, 5.1], [-3.6, 5.0], [-2.6, 4.7], [-1.7, 5.1],
[-1.1, 4.2], [-2.1, 2.7], [-3.0, 1.1], [-4.0, 0.8],
[-5.2, 0.7], [-6.2, 0.8], [-7.1, 3.6], [-0.8, 2.9]
];
const reedGroups = [];
reedPositions.forEach(([x, z], index) => {
const group = new THREE.Group();
group.position.set(x, 0, z);
const height = 0.55 + (index % 3) * 0.12;
box(group, [0.07, height, 0.07], [0, height / 2, 0], materials.reeds);
box(group, [0.12, 0.22, 0.1], [0, height + 0.05, 0], materials.reedHead);
board.add(group);
reedGroups.push(group);
});
// Crop-like vegetation rows, presented only as changing voxel vegetation.
const plantGroups = [];
const cropLeaves = [];
const cropHeads = [];
for (let x = 2.5; x <= 5.5; x += 1) {
for (let z = -3.5; z <= -0.5; z += 1) {
const group = new THREE.Group();
group.position.set(x, 0.07, z);
for (let n = 0; n < 3; n++) {
const offset = (n - 1) * 0.23;
box(group, [0.07, 0.62, 0.07], [offset, 0.31, 0], materials.cropStem);
const leafA = box(
group,
[0.25, 0.18, 0.25],
[offset - 0.08, 0.36, 0],
materials.cropLeaf
);
const leafB = box(
group,
[0.25, 0.18, 0.25],
[offset + 0.08, 0.52, 0],
materials.cropLight
);
cropLeaves.push(leafA, leafB);
if (x < 5) {
const head = box(
group,
[0.13, 0.22, 0.13],
[offset, 0.71, 0],
materials.cropHead
);
cropHeads.push(head);
}
}
board.add(group);
plantGroups.push(group);
}
}
// Voxel trees with seasonal canopy clusters and permanent branches.
const treePositions = [
[-6.8, -4.4, 1.05], [-5.7, -4.8, 0.85], [-1.0, -4.7, 1.0],
[0.7, -4.7, 0.82], [6.8, -4.7, 1.02], [7.0, -1.3, 0.86],
[7.0, 2.0, 0.9], [0.8, 4.8, 0.94], [-0.7, 4.8, 0.78],
[-7.1, 5.0, 0.72]
];
const leafMeshes = [];
const leafThresholds = [];
const treeGroups = [];
treePositions.forEach(([x, z, scale], treeIndex) => {
const group = new THREE.Group();
group.position.set(x, 0.03, z);
group.scale.setScalar(scale);
box(group, [0.28, 1.45, 0.28], [0, 0.72, 0], materials.trunk);
box(group, [0.72, 0.16, 0.17], [0.21, 1.18, 0], materials.branch);
box(group, [0.16, 0.17, 0.66], [0, 1.35, 0.13], materials.branch);
const clusters = [
[-0.38, 1.55, -0.15, 0.72],
[0.34, 1.62, -0.08, 0.78],
[0.02, 1.88, 0.02, 0.82],
[-0.15, 1.65, 0.36, 0.7],
[0.42, 1.48, 0.32, 0.62]
];
clusters.forEach((cluster, index) => {
const [cx, cy, cz, size] = cluster;
const leaf = box(
group,
[size, size * 0.82, size],
[cx, cy, cz],
index % 2 ? materials.canopyB : materials.canopyA
);
const threshold = 0.2 + ((treeIndex * 3 + index * 5) % 7) * 0.105;
leafMeshes.push(leaf);
leafThresholds.push(threshold);
});
board.add(group);
treeGroups.push(group);
});
// Small scattered grass voxels.
let seed = 78123;
const random = () => {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
};
const grassTufts = [];
for (let i = 0; i < 70; i++) {
const x = -7.4 + random() * 14.8;
const z = -5.4 + random() * 10.8;
const inFarm = x > 1.2 && x < 6.7 && z > -4.8 && z < 2.1;
const inWetland = x < -1.6 && z > 0.1;
const onPath = Math.abs(x - 0.5) < 0.8 || (Math.abs(z - 0.5) < 0.65 && x > 0);
if (inFarm || inWetland || onPath) continue;
const tuft = new THREE.Group();
tuft.position.set(x, 0.05, z);
const h = 0.12 + random() * 0.16;
box(tuft, [0.07, h, 0.07], [-0.08, h / 2, 0], materials.grass);
box(tuft, [0.07, h * 0.8, 0.07], [0.06, h * 0.4, 0.03], materials.grass);
board.add(tuft);
grassTufts.push(tuft);
}
// Small farmhouse.
const house = new THREE.Group();
house.position.set(2.7, 0.05, 3.65);
box(house, [2.05, 1.35, 1.75], [0, 0.68, 0], materials.wall);
box(house, [2.42, 0.3, 2.05], [0, 1.5, 0], materials.roof);
box(house, [1.68, 0.3, 2.05], [0, 1.78, 0], materials.roof);
box(house, [0.48, 0.9, 0.08], [0, 0.47, 0.9], materials.door);
box(house, [0.38, 0.38, 0.08], [-0.67, 0.83, 0.91], materials.window);
box(house, [0.38, 0.38, 0.08], [0.67, 0.83, 0.91], materials.window);
box(house, [0.28, 0.68, 0.28], [-0.55, 1.94, -0.34], materials.barn);
board.add(house);
// Barn.
const barn = new THREE.Group();
barn.position.set(5.05, 0.05, -4.05);
box(barn, [2.15, 1.55, 2.05], [0, 0.78, 0], materials.barn);
box(barn, [2.5, 0.3, 2.35], [0, 1.7, 0], materials.barnRoof);
box(barn, [1.68, 0.3, 2.35], [0, 1.98, 0], materials.barnRoof);
box(barn, [1.18, 1.24, 0.08], [0, 0.64, 1.07], materials.door);
box(barn, [0.08, 1.24, 0.1], [0, 0.64, 1.13], materials.fence);
board.add(barn);
// Square silo.
const silo = new THREE.Group();
silo.position.set(6.75, 0.05, -4.65);
box(silo, [1.05, 2.35, 1.05], [0, 1.17, 0], materials.wall);
box(silo, [1.28, 0.22, 1.28], [0, 2.42, 0], materials.barnRoof);
box(silo, [0.9, 0.2, 0.9], [0, 2.61, 0], materials.barnRoof);
board.add(silo);
// Fence posts and rails around the planted area.
const fenceMaterial = materials.fence;
for (let z = -4.5; z <= 1; z += 1) {
box(board, [0.13, 0.72, 0.13], [1.45, 0.36, z], fenceMaterial);
box(board, [0.13, 0.72, 0.13], [6.45, 0.36, z], fenceMaterial);
}
box(board, [0.1, 0.1, 5.7], [1.45, 0.48, -1.75], fenceMaterial);
box(board, [0.1, 0.1, 5.7], [1.45, 0.22, -1.75], fenceMaterial);
box(board, [0.1, 0.1, 5.7], [6.45, 0.48, -1.75], fenceMaterial);
box(board, [0.1, 0.1, 5.7], [6.45, 0.22, -1.75], fenceMaterial);
for (let x = 1.5; x <= 6.5; x += 1) {
box(board, [0.13, 0.72, 0.13], [x, 0.36, 1.05], fenceMaterial);
}
box(board, [5.2, 0.1, 0.1], [4, 0.48, 1.05], fenceMaterial);
box(board, [5.2, 0.1, 0.1], [4, 0.22, 1.05], fenceMaterial);
// A few voxel stones beside the path.
const stonePositions = [
[0.2, 2.2, .35], [0.45, 2.75, .25], [-0.1, 3.25, .3],
[6.9, -2.8, .28], [6.65, -2.3, .22]
];
stonePositions.forEach(([x, z, s]) => {
box(board, [s, s * .7, s], [x, s * .35, z], materials.stone);
});
// Snow caps are a separate winter-only layer.
const snowGroup = new THREE.Group();
box(snowGroup, [2.46, 0.08, 2.09], [0, 1.69, 0], materials.snow);
box(snowGroup, [1.72, 0.08, 2.09], [0, 1.97, 0], materials.snow);
house.add(snowGroup);
const barnSnow = new THREE.Group();
box(barnSnow, [2.54, 0.08, 2.39], [0, 1.89, 0], materials.snow);
box(barnSnow, [1.72, 0.08, 2.39], [0, 2.17, 0], materials.snow);
barn.add(barnSnow);
const siloSnow = new THREE.Group();
box(siloSnow, [1.32, 0.08, 1.32], [0, 2.56, 0], materials.snow);
silo.add(siloSnow);
snowGroup.visible = false;
barnSnow.visible = false;
siloSnow.visible = false;
// Autumn leaf litter, distributed as small voxel accents.
const autumnLitter = new THREE.Group();
treePositions.forEach(([x, z]) => {
for (let i = 0; i < 9; i++) {
const angle = random() * Math.PI * 2;
const radius = .45 + random() * .9;
box(
autumnLitter,
[.14, .055, .18],
[x + Math.cos(angle) * radius, .09, z + Math.sin(angle) * radius],
materials.litter,
false,
true
);
}
});
board.add(autumnLitter);
autumnLitter.visible = false;
// Canvas-based labels are implemented locally with core Three.js sprites.
function makeLabel(text, accent) {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 80;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(248,251,247,.92)";
context.beginPath();
context.roundRect(3, 3, 314, 74, 18);
context.fill();
context.strokeStyle = accent;
context.lineWidth = 5;
context.stroke();
context.fillStyle = "#344a41";
context.font = "700 30px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 160, 41);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(2.7, 0.675, 1);
sprite.renderOrder = 10;
return sprite;
}
const farmLabel = makeLabel("FARM", "#9b8063");
farmLabel.position.set(4.4, 2.95, 3.4);
scene.add(farmLabel);
const wetlandLabel = makeLabel("WETLAND", "#538b91");
wetlandLabel.position.set(-4.4, 2.25, 2.2);
scene.add(wetlandLabel);
let currentSeason = "spring";
function updateScene(seasonId) {
currentSeason = seasonId;
const season = seasons[seasonId];
materials.ground.color.set(season.ground);
materials.farm.color.set(season.farm);
materials.wetGround.color.set(season.wetGround);
materials.canopyA.color.set(season.canopyA);
materials.canopyB.color.set(season.canopyB);
materials.cropStem.color.set(season.crop);
materials.cropLeaf.color.set(season.crop);
materials.cropLight.color.set(season.cropLight);
materials.grass.color.set(season.grass);
materials.reeds.color.set(season.reeds);
materials.reedHead.color.set(seasonId === "autumn" ? "#80633d" : "#81704d");
materials.water.color.set(season.water);
leafMeshes.forEach((leaf, index) => {
leaf.visible = season.cover > 0 && season.cover >= leafThresholds[index];
});
cropLeaves.forEach(leaf => {
leaf.visible = seasonId !== "winter";
});
cropHeads.forEach(head => {
head.visible = seasonId === "summer" || seasonId === "autumn";
});
plantGroups.forEach(group => {
group.scale.y = season.plantScale;
});
grassTufts.forEach(tuft => {
tuft.scale.y = seasonId === "winter" ? 0.35 : seasonId === "autumn" ? 0.75 : 1;
});
reedGroups.forEach(group => {
group.scale.y = seasonId === "winter" ? 0.62 : seasonId === "autumn" ? 0.82 : 1;
});
waterCells.forEach(cell => {
cell.visible = season.waterLevel >= cell.userData.threshold;
cell.position.y = -0.045 + season.waterLevel * 0.075;
});
materials.water.opacity = seasonId === "winter" ? 0.9 : 0.82;
sun.color.set(season.sun);
sun.intensity = season.sunIntensity;
hemi.color.set(season.sky);
hemi.groundColor.set(season.groundLight);
snowGroup.visible = season.snow;
barnSnow.visible = season.snow;
siloSnow.visible = season.snow;
autumnLitter.visible = seasonId === "autumn";
updateInterface();
}
function luminance(hex) {
const value = parseInt(hex.slice(1), 16);
const r = ((value >> 16) & 255) / 255;
const g = ((value >> 8) & 255) / 255;
const b = (value & 255) / 255;
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
function deltaItem(label, currentColor, compareColor, text, same = false) {
return `
<div class="delta-item ${same ? "same" : ""}">
<div class="delta-swatches" aria-hidden="true">
<i style="background:${currentColor}"></i>
<i style="background:${compareColor}"></i>
</div>
<div>
<small>${label}</small>
<strong>${text}</strong>
</div>
</div>
`;
}
function updateInterface() {
const season = seasons[currentSeason];
const compareId = document.querySelector("#compareSelect").value;
const compare = seasons[compareId];
document.querySelector("#seasonTitle").textContent = season.name;
document.querySelector("#seasonTag").textContent = season.tag;
document.querySelector("#shadeValue").textContent = season.shadeText;
document.querySelector("#vegetationValue").textContent = season.vegetationText;
document.querySelector("#waterValue").textContent = season.waterText;
document.querySelector("#shadeSwatch").style.background =
`linear-gradient(135deg, ${season.canopyA}, ${season.canopyB})`;
document.querySelector("#vegetationSwatch").style.background = season.cropLight;
document.querySelector("#waterSwatch").style.background = season.water;
document.querySelector("#seasonGlyph").style.setProperty("--glyph-color", season.canopyA);
document.querySelectorAll("[data-season]").forEach(button => {
button.setAttribute("aria-pressed", String(button.dataset.season === currentSeason));
});
const shadeDifference = luminance(season.canopyA) - luminance(compare.canopyA);
let shadeText = "Different shade palette";
if (currentSeason === compareId) shadeText = "Same shade palette";
else if (shadeDifference > 0.08) shadeText = "Lighter shade palette";
else if (shadeDifference < -0.08) shadeText = "Darker shade palette";
const coverDifference = season.cover - compare.cover;
let vegetationText = "Similar visible vegetation";
if (currentSeason === compareId) vegetationText = "Same vegetation state";
else if (coverDifference > 0.15) vegetationText = "More visible vegetation";
else if (coverDifference < -0.15) vegetationText = "Less visible vegetation";
const waterDifference = season.waterLevel - compare.waterLevel;
let waterText = "Similar visible storage";
if (currentSeason === compareId) waterText = "Same visible storage";
else if (waterDifference > 0.08) waterText = "More visible storage";
else if (waterDifference < -0.08) waterText = "Less visible storage";
document.querySelector("#deltaList").innerHTML =
deltaItem(
"Shade",
season.canopyA,
compare.canopyA,
shadeText,
currentSeason === compareId
) +
deltaItem(
"Vegetation",
season.cropLight,
compare.cropLight,
vegetationText,
currentSeason === compareId
) +
deltaItem(
"Water",
season.water,
compare.water,
waterText,
currentSeason === compareId
);
document.querySelector("#sceneStatus").textContent =
`${season.name} state displayed. ${season.shadeText} shade, ${season.vegetationText.toLowerCase()} vegetation, and ${season.waterText.toLowerCase()} visible water storage.`;
}
document.querySelectorAll("[data-season]").forEach(button => {
button.addEventListener("click", () => {
updateScene(button.dataset.season);
});
});
document.querySelector("#compareSelect").addEventListener("change", updateInterface);
function updateCamera() {
const radius = 23;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
yaw = 0.72;
pitch = 0.72;
zoom = 1;
target.set(0.3, 0.25, 0);
updateCamera();
}
document.querySelector("#resetView").addEventListener("click", resetCamera);
const pointers = new Map();
let lastPinchDistance = 0;
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) lastPinchDistance = pointerDistance();
});
renderer.domElement.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
if (event.shiftKey) {
const right = new THREE.Vector3(Math.cos(yaw), 0, -Math.sin(yaw));
const forward = new THREE.Vector3(-Math.sin(yaw), 0, -Math.cos(yaw));
target.addScaledVector(right, -dx * 0.012);
target.addScaledVector(forward, -dy * 0.012);
} else {
yaw -= dx * 0.007;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, 0.3, 1.3);
}
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
zoom = THREE.MathUtils.clamp(zoom * (distance / lastPinchDistance), 0.7, 2.1);
}
lastPinchDistance = distance;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(zoom * Math.exp(-event.deltaY * 0.001), 0.7, 2.1);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
yaw += 0.1;
break;
case "ArrowRight":
yaw -= 0.1;
break;
case "ArrowUp":
pitch = THREE.MathUtils.clamp(pitch + 0.08, 0.3, 1.3);
break;
case "ArrowDown":
pitch = THREE.MathUtils.clamp(pitch - 0.08, 0.3, 1.3);
break;
case "+":
case "=":
zoom = THREE.MathUtils.clamp(zoom + 0.1, 0.7, 2.1);
break;
case "-":
case "_":
zoom = THREE.MathUtils.clamp(zoom - 0.1, 0.7, 2.1);
break;
case "0":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(14.5, 20 / aspect);
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
resetCamera();
updateScene("spring");
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```