Prompt specification
Build or customize the Three.js 3D scene "Crop assignments move through seasons" 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: Crop assignments move through seasons
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/crop-assignments-move-through-seasons-x1050
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring crop rotation. Animate crop symbols rotating among fixed plots over four labeled periods; retain an explicit schedule so viewers can trace each plot's full sequence. Low-poly.
Working Three.js Starter (crop-assignments-move-through-seasons-x1050):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Four-Period Crop Rotation</title>
<style>
:root {
color-scheme: dark;
--ink: #f5f2e7;
--muted: #b8c7b6;
--panel: rgba(16, 38, 31, 0.86);
--panel-border: rgba(225, 238, 211, 0.17);
--accent: #d9ee87;
--shadow: 0 18px 50px rgba(7, 18, 13, 0.28);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d5cf;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.glass {
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.15);
-webkit-backdrop-filter: blur(16px) saturate(1.15);
}
.topbar {
position: fixed;
z-index: 5;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.brand {
max-width: 420px;
padding: 15px 17px 14px;
border-radius: 18px;
pointer-events: auto;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.1vw, 31px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.period-panel {
padding: 9px;
border-radius: 18px;
pointer-events: auto;
}
.period-row {
display: flex;
align-items: stretch;
gap: 6px;
}
.period-button {
min-width: 78px;
padding: 10px 12px;
border: 1px solid transparent;
border-radius: 12px;
color: #dce7da;
background: rgba(255, 255, 255, 0.045);
cursor: pointer;
text-align: left;
transition: 160ms ease;
}
.period-button:hover {
background: rgba(255, 255, 255, 0.1);
transform: translateY(-1px);
}
.period-button.active {
color: #16251c;
background: var(--accent);
border-color: rgba(255, 255, 255, 0.25);
box-shadow: 0 5px 16px rgba(188, 218, 102, 0.18);
}
.period-button strong {
display: block;
font-size: 12px;
}
.period-button span {
display: block;
margin-top: 2px;
font-size: 10px;
opacity: 0.72;
}
.transport {
display: flex;
gap: 6px;
margin-top: 7px;
}
.transport button {
flex: 1;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
background: rgba(0, 0, 0, 0.13);
color: var(--ink);
font: inherit;
font-size: 11px;
cursor: pointer;
}
.transport button:hover {
background: rgba(255, 255, 255, 0.09);
}
.progress-track {
height: 3px;
margin-top: 8px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.09);
}
#cycleProgress {
width: 0;
height: 100%;
background: var(--accent);
transform-origin: left center;
}
.schedule-panel {
position: fixed;
z-index: 5;
top: 104px;
right: 18px;
width: min(510px, calc(100vw - 36px));
max-height: calc(100vh - 126px);
padding: 15px;
border-radius: 20px;
display: flex;
flex-direction: column;
pointer-events: auto;
}
.schedule-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.schedule-heading h2 {
margin: 0;
font-size: 16px;
letter-spacing: -0.02em;
}
.schedule-heading p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.status-pill {
flex: none;
padding: 7px 9px;
border-radius: 999px;
color: #17251b;
background: var(--accent);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.schedule-scroll {
min-height: 0;
overflow: auto;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
scrollbar-width: thin;
scrollbar-color: rgba(217, 238, 135, 0.35) transparent;
}
table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
font-size: 11px;
}
th, td {
padding: 7px 6px;
border-bottom: 1px solid rgba(255, 255, 255, 0.065);
text-align: left;
white-space: nowrap;
}
thead th {
position: sticky;
z-index: 2;
top: 0;
color: #dce8d9;
background: #19382d;
font-size: 10px;
cursor: pointer;
}
thead th span {
display: block;
margin-top: 2px;
color: #9fb1a0;
font-size: 9px;
font-weight: 500;
}
tbody tr {
cursor: pointer;
transition: background 120ms ease;
}
tbody tr:hover,
tbody tr.selected {
background: rgba(217, 238, 135, 0.1);
}
tbody tr.selected td:first-child {
color: var(--accent);
font-weight: 900;
}
td:first-child {
position: sticky;
z-index: 1;
left: 0;
color: #aebda9;
background: #19382d;
font-weight: 700;
}
tbody tr.selected td:first-child {
background: #254537;
}
.crop-cell {
width: 100%;
padding: 5px 6px;
border: 1px solid transparent;
border-radius: 7px;
display: flex;
align-items: center;
gap: 5px;
color: #dfe9da;
background: transparent;
font: inherit;
font-size: 10px;
cursor: pointer;
}
.crop-cell:hover,
.crop-cell.active {
border-color: rgba(255, 255, 255, 0.13);
background: rgba(255, 255, 255, 0.065);
}
.crop-dot {
width: 8px;
height: 8px;
flex: none;
border-radius: 2px;
transform: rotate(45deg);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.wheat { --crop: #e6b84a; }
.tomato { --crop: #ef6758; }
.bean { --crop: #65ad68; }
.clover { --crop: #b58bd7; }
.crop-dot { background: var(--crop); }
.left-stack {
position: fixed;
z-index: 5;
left: 18px;
bottom: 18px;
width: min(380px, calc(100vw - 36px));
display: grid;
gap: 9px;
pointer-events: none;
}
.legend, .trace {
padding: 13px 14px;
border-radius: 16px;
pointer-events: auto;
}
.legend-title {
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-items {
display: flex;
flex-wrap: wrap;
gap: 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #e6eee0;
font-size: 11px;
}
.legend-symbol {
width: 13px;
height: 13px;
display: grid;
place-items: center;
border-radius: 4px;
color: #17251c;
background: var(--crop);
font-size: 8px;
font-weight: 900;
transform: rotate(45deg);
}
.legend-symbol span { transform: rotate(-45deg); }
.trace-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
#traceTitle {
font-size: 13px;
font-weight: 800;
}
#traceHint {
color: var(--muted);
font-size: 9px;
}
#traceSequence {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 6px;
}
.trace-step {
min-width: 0;
padding: 7px 4px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 9px;
color: #dfe9da;
background: rgba(255, 255, 255, 0.035);
font: inherit;
font-size: 9px;
cursor: pointer;
}
.trace-step strong {
display: block;
overflow: hidden;
margin-top: 3px;
font-size: 10px;
text-overflow: ellipsis;
}
.trace-step.active {
color: #17251c;
border-color: transparent;
background: var(--accent);
}
.hint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 18px;
padding: 8px 12px;
border-radius: 999px;
color: rgba(246, 249, 239, 0.86);
background: rgba(20, 42, 34, 0.62);
border: 1px solid rgba(255, 255, 255, 0.11);
font-size: 10px;
pointer-events: none;
transform: translateX(-50%);
white-space: nowrap;
}
@media (max-width: 980px) {
.schedule-panel {
top: auto;
bottom: 18px;
max-height: 43vh;
}
.left-stack {
bottom: calc(43vh + 28px);
width: min(360px, calc(100vw - 36px));
}
.hint { display: none; }
}
@media (max-width: 700px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
flex-direction: column;
}
.brand {
width: 100%;
max-width: none;
padding: 11px 13px;
}
.brand p { display: none; }
.period-panel {
width: 100%;
overflow-x: auto;
}
.period-row { min-width: 430px; }
.schedule-panel {
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 42vh;
padding: 11px;
}
.left-stack {
left: 10px;
bottom: calc(42vh + 20px);
width: calc(100vw - 20px);
}
.legend { display: none; }
.trace { padding: 10px; }
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive low-poly crop rotation scene"></main>
<header class="topbar">
<section class="brand glass">
<div class="eyebrow">Field plan / four-period cycle</div>
<h1>Crop Rotation</h1>
<p>Fixed beds, changing crop symbols. Select a plot to trace its complete four-period sequence.</p>
</section>
<nav class="period-panel glass" aria-label="Crop rotation periods">
<div class="period-row" id="periodButtons">
<button class="period-button active" data-period="0">
<strong>P1 · Spring</strong><span>Opening cycle</span>
</button>
<button class="period-button" data-period="1">
<strong>P2 · Summer</strong><span>Second cycle</span>
</button>
<button class="period-button" data-period="2">
<strong>P3 · Autumn</strong><span>Third cycle</span>
</button>
<button class="period-button" data-period="3">
<strong>P4 · Winter</strong><span>Closing cycle</span>
</button>
</div>
<div class="transport">
<button id="autoButton" type="button">Pause cycle</button>
<button id="resetView" type="button">Reset view</button>
</div>
<div class="progress-track"><div id="cycleProgress"></div></div>
</nav>
</header>
<aside class="schedule-panel glass">
<div class="schedule-heading">
<div>
<h2>Explicit rotation schedule</h2>
<p>Every row is one fixed plot. Click a period heading or crop cell to inspect it.</p>
</div>
<div class="status-pill" id="statusPill">P1 · Spring</div>
</div>
<div class="schedule-scroll" id="scheduleScroll">
<table>
<thead>
<tr>
<th>Plot</th>
<th data-period="0">P1<span>Spring</span></th>
<th data-period="1">P2<span>Summer</span></th>
<th data-period="2">P3<span>Autumn</span></th>
<th data-period="3">P4<span>Winter</span></th>
</tr>
</thead>
<tbody id="scheduleBody"></tbody>
</table>
</div>
</aside>
<section class="left-stack">
<div class="legend glass">
<div class="legend-title">Crop symbols</div>
<div class="legend-items">
<div class="legend-item wheat">
<span class="legend-symbol"><span>WH</span></span>Wheat
</div>
<div class="legend-item tomato">
<span class="legend-symbol"><span>TO</span></span>Tomato
</div>
<div class="legend-item bean">
<span class="legend-symbol"><span>BE</span></span>Bean
</div>
<div class="legend-item clover">
<span class="legend-symbol"><span>CL</span></span>Clover
</div>
</div>
</div>
<div class="trace glass">
<div class="trace-title">
<span id="traceTitle">Plot 01 · full sequence</span>
<span id="traceHint">Click to inspect</span>
</div>
<div id="traceSequence"></div>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Click a plot</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Explicit schedule: one row per fixed plot, four periods wide.
// ------------------------------------------------------------
const schedule = [
["wheat", "tomato", "bean", "clover"],
["tomato", "bean", "clover", "wheat"],
["bean", "clover", "wheat", "tomato"],
["clover", "wheat", "tomato", "bean"],
["wheat", "clover", "tomato", "bean"],
["clover", "bean", "wheat", "tomato"],
["tomato", "wheat", "bean", "clover"],
["bean", "tomato", "clover", "wheat"],
["wheat", "bean", "clover", "tomato"],
["bean", "wheat", "tomato", "clover"],
["clover", "tomato", "wheat", "bean"],
["tomato", "clover", "bean", "wheat"],
["wheat", "tomato", "clover", "bean"],
["tomato", "wheat", "clover", "bean"],
["clover", "bean", "tomato", "wheat"],
["bean", "clover", "wheat", "tomato"]
];
const cropMeta = {
wheat: { label: "Wheat", short: "WH" },
tomato: { label: "Tomato", short: "TO" },
bean: { label: "Bean", short: "BE" },
clover: { label: "Clover", short: "CL" }
};
const periodNames = ["Spring", "Summer", "Autumn", "Winter"];
const periodLabels = ["P1 · Spring", "P2 · Summer", "P3 · Autumn", "P4 · Winter"];
const sceneHost = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Three-dimensional crop rotation field");
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d5cf);
scene.fog = new THREE.Fog(0xb9d5cf, 30, 62);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Direct camera controls, implemented without addons.
const orbit = {
yaw: 0.72,
pitch: 0.76,
radius: 24,
target: new THREE.Vector3(0, 0.3, 0)
};
function updateCamera() {
const horizontal = orbit.radius * Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.yaw),
orbit.target.y + orbit.radius * Math.sin(orbit.pitch),
orbit.target.z + horizontal * Math.cos(orbit.yaw)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.yaw = 0.72;
orbit.pitch = 0.76;
orbit.radius = window.innerWidth < 700 ? 28 : 24;
updateCamera();
}
resetCamera();
const hemi = new THREE.HemisphereLight(0xe8f4df, 0x587246, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1c9, 3.0);
sun.position.set(-9, 18, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xbad9ff, 0.7);
rim.position.set(12, 8, -14);
scene.add(rim);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const materials = {
ground: material(0x83a968),
base: material(0xb89a68),
soil: material(0x714332),
furrow: material(0x4d3027),
border: material(0xc6a36c),
fence: material(0xe5d4a9),
stem: material(0x466e3d),
leaf: material(0x5a934c),
darkLeaf: material(0x315f38),
wheat: material(0xe2b23f),
wheatLight: material(0xf1cf69),
tomato: material(0xe55243),
bean: material(0x79aa4d),
beanPod: material(0x9ebd5a),
clover: material(0xa77ac9),
cloverLeaf: material(0x4c8c52),
barn: material(0xa94839),
barnRoof: material(0x5d4038),
silo: material(0xd5d6c6),
siloRoof: material(0x66746d),
window: material(0xf0d78d, { emissive: 0x5a3c0d, emissiveIntensity: 0.35 })
};
function addMesh(parent, geometry, mat, position = [0, 0, 0], scale = [1, 1, 1], rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Low-poly terrain and farm platform
// ------------------------------------------------------------
const terrainGeometry = new THREE.PlaneGeometry(62, 62, 18, 18);
const terrainPositions = terrainGeometry.attributes.position;
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const y = terrainPositions.getY(i);
const edge = Math.max(Math.abs(x), Math.abs(y));
const flatten = THREE.MathUtils.smoothstep(edge, 8, 17);
const height =
(Math.sin(x * 0.18) * 0.22 + Math.cos(y * 0.15) * 0.18) * flatten;
terrainPositions.setZ(i, height - 0.08);
}
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(terrainGeometry, materials.ground);
terrain.rotation.x = -Math.PI / 2;
terrain.receiveShadow = true;
scene.add(terrain);
const base = addMesh(
scene,
new THREE.BoxGeometry(14.7, 0.42, 14.7),
materials.base,
[0, 0.19, 0]
);
base.receiveShadow = true;
// A subtle raised rim around the field.
addMesh(scene, new THREE.BoxGeometry(15.0, 0.18, 0.22), materials.border, [0, 0.48, -7.36]);
addMesh(scene, new THREE.BoxGeometry(15.0, 0.18, 0.22), materials.border, [0, 0.48, 7.36]);
addMesh(scene, new THREE.BoxGeometry(0.22, 0.18, 14.5), materials.border, [-7.36, 0.48, 0]);
addMesh(scene, new THREE.BoxGeometry(0.22, 0.18, 14.5), materials.border, [7.36, 0.48, 0]);
// ------------------------------------------------------------
// Fixed plots
// ------------------------------------------------------------
const plotEntries = [];
const soilMeshes = [];
const spacing = 3.25;
const bedSize = 2.72;
function makePlotLabel(text) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(25, 51, 40, 0.91)";
context.beginPath();
context.roundRect(4, 4, 248, 88, 22);
context.fill();
context.strokeStyle = "rgba(224, 241, 198, 0.32)";
context.lineWidth = 4;
context.stroke();
context.fillStyle = "#eff6df";
context.font = "800 43px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 50);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(1.12, 0.42, 1);
return sprite;
}
for (let row = 0; row < 4; row++) {
for (let column = 0; column < 4; column++) {
const index = row * 4 + column;
const x = (column - 1.5) * spacing;
const z = (row - 1.5) * spacing;
const soilMaterial = materials.soil.clone();
const bed = addMesh(
scene,
new THREE.BoxGeometry(bedSize, 0.28, bedSize),
soilMaterial,
[x, 0.58, z]
);
soilMeshes.push(bed);
// Fixed wooden bed edges.
addMesh(scene, new THREE.BoxGeometry(bedSize + 0.18, 0.18, 0.11), materials.border, [x, 0.65, z - bedSize / 2 - 0.02]);
addMesh(scene, new THREE.BoxGeometry(bedSize + 0.18, 0.18, 0.11), materials.border, [x, 0.65, z + bedSize / 2 + 0.02]);
addMesh(scene, new THREE.BoxGeometry(0.11, 0.18, bedSize + 0.18), materials.border, [x - bedSize / 2 - 0.02, 0.65, z]);
addMesh(scene, new THREE.BoxGeometry(0.11, 0.18, bedSize + 0.18), materials.border, [x + bedSize / 2 + 0.02, 0.65, z]);
// Low-poly furrows make each plot readable from above.
for (let furrow = -2; furrow <= 2; furrow++) {
addMesh(
scene,
new THREE.BoxGeometry(bedSize - 0.35, 0.025, 0.08),
materials.furrow,
[x, 0.735, z + furrow * 0.48]
);
}
const label = makePlotLabel(`P${String(index + 1).padStart(2, "0")}`);
label.position.set(x, 0.97, z + 1.61);
scene.add(label);
plotEntries.push({
index,
x,
z,
bed,
group: null,
transition: null,
phase: index * 0.63
});
}
}
// Selection outline.
const half = bedSize / 2 + 0.13;
const selectionPoints = [
new THREE.Vector3(-half, 0, -half),
new THREE.Vector3(half, 0, -half),
new THREE.Vector3(half, 0, half),
new THREE.Vector3(-half, 0, half)
];
const selectionRing = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(selectionPoints),
new THREE.LineBasicMaterial({ color: 0xd9ee87 })
);
selectionRing.position.y = 0.79;
scene.add(selectionRing);
// ------------------------------------------------------------
// Fence
// ------------------------------------------------------------
const fenceGroup = new THREE.Group();
scene.add(fenceGroup);
function fenceSide(from, to, count) {
for (let i = 0; i < count; i++) {
const t = i / (count - 1);
const x = THREE.MathUtils.lerp(from[0], to[0], t);
const z = THREE.MathUtils.lerp(from[1], to[1], t);
addMesh(fenceGroup, new THREE.BoxGeometry(0.15, 1.25, 0.15), materials.fence, [x, 0.92, z]);
}
const midpoint = [
(from[0] + to[0]) / 2,
(from[1] + to[1]) / 2
];
const horizontal = from[1] === to[1];
const length = Math.hypot(to[0] - from[0], to[1] - from[1]);
for (const height of [0.65, 1.08]) {
addMesh(
fenceGroup,
horizontal
? new THREE.BoxGeometry(length, 0.10, 0.10)
: new THREE.BoxGeometry(0.10, 0.10, length),
materials.fence,
[midpoint[0], height, midpoint[1]]
);
}
}
fenceSide([-7.65, -7.65], [7.65, -7.65], 9);
fenceSide([-7.65, 7.65], [7.65, 7.65], 9);
fenceSide([-7.65, -7.65], [-7.65, 7.65], 9);
fenceSide([7.65, -7.65], [7.65, 7.65], 9);
// ------------------------------------------------------------
// Barn and silo
// ------------------------------------------------------------
const barn = new THREE.Group();
barn.position.set(-9.7, 0, -7.5);
barn.rotation.y = 0.12;
scene.add(barn);
addMesh(barn, new THREE.BoxGeometry(3.8, 2.4, 3.1), materials.barn, [0, 1.2, 0]);
addMesh(
barn,
new THREE.ConeGeometry(2.85, 1.55, 4),
materials.barnRoof,
[0, 3.05, 0],
[1, 1, 0.92],
[0, Math.PI / 4, 0]
);
addMesh(barn, new THREE.BoxGeometry(1.2, 1.8, 0.08), materials.barnRoof, [0, 0.9, 1.59]);
addMesh(barn, new THREE.BoxGeometry(0.7, 0.55, 0.07), materials.window, [-1.1, 1.4, 1.59]);
addMesh(barn, new THREE.BoxGeometry(0.7, 0.55, 0.07), materials.window, [1.1, 1.4, 1.59]);
const silo = new THREE.Group();
silo.position.set(9.2, 0, -8.2);
scene.add(silo);
addMesh(silo, new THREE.CylinderGeometry(1.05, 1.1, 3.5, 8), materials.silo, [0, 1.75, 0]);
addMesh(silo, new THREE.ConeGeometry(1.13, 0.9, 8), materials.siloRoof, [0, 3.95, 0]);
addMesh(silo, new THREE.TorusGeometry(1.07, 0.055, 4, 8), materials.siloRoof, [0, 1.75, 0], [1, 1, 1], [Math.PI / 2, 0, 0]);
// A few geometric trees around the perimeter.
const treeTrunk = material(0x79523a);
const treeLeaf = material(0x4f7d4a);
const treePositions = [
[-12, -2], [-11.5, 5.5], [11.8, 3.8], [12.2, -3.8], [3.5, -12]
];
for (const [x, z] of treePositions) {
addMesh(scene, new THREE.CylinderGeometry(0.15, 0.22, 1.6, 6), treeTrunk, [x, 0.72, z]);
addMesh(scene, new THREE.ConeGeometry(1.05, 2.6, 7), treeLeaf, [x, 2.4, z]);
addMesh(scene, new THREE.ConeGeometry(0.78, 1.8, 7), treeLeaf, [x, 3.25, z], [1, 1, 1], [0, 0.5, 0]);
}
// ------------------------------------------------------------
// Low-poly crop symbols
// ------------------------------------------------------------
function createWheat() {
const root = new THREE.Group();
const inner = new THREE.Group();
root.add(inner);
const positions = [
[-0.65, -0.25], [-0.18, 0.25], [0.28, -0.2],
[0.67, 0.24], [0.02, -0.52]
];
positions.forEach(([x, z], i) => {
const height = 0.88 + (i % 3) * 0.12;
addMesh(inner, new THREE.CylinderGeometry(0.035, 0.045, height, 5), materials.stem, [x, height / 2, z]);
for (let grain = 0; grain < 3; grain++) {
addMesh(
inner,
new THREE.OctahedronGeometry(0.13, 0),
grain % 2 ? materials.wheatLight : materials.wheat,
[x + (grain - 1) * 0.045, height + grain * 0.11, z],
[0.72, 1.25, 0.72],
[0, grain * 0.7, (grain - 1) * 0.25]
);
}
addMesh(
inner,
new THREE.ConeGeometry(0.12, 0.38, 4),
materials.leaf,
[x + 0.1, height * 0.45, z],
[1, 1, 0.45],
[0, 0, -0.85]
);
});
return { root, inner };
}
function createTomato() {
const root = new THREE.Group();
const inner = new THREE.Group();
root.add(inner);
addMesh(inner, new THREE.CylinderGeometry(0.045, 0.06, 1.15, 6), materials.stem, [0, 0.57, 0]);
const branches = [
[-0.38, 0.62, 0.22, 0.9],
[0.38, 0.75, -0.18, -0.85],
[0.15, 0.43, 0.4, 0.25]
];
for (const [x, y, z, angle] of branches) {
addMesh(
inner,
new THREE.CylinderGeometry(0.025, 0.035, 0.58, 5),
materials.stem,
[x / 2, y, z / 2],
[1, 1, 1],
[Math.PI / 2, 0, angle]
);
addMesh(
inner,
new THREE.ConeGeometry(0.16, 0.4, 4),
materials.leaf,
[x, y + 0.03, z],
[1, 1, 0.45],
[0, 0, angle]
);
}
const fruits = [
[-0.38, 0.48, 0.22],
[0.39, 0.63, -0.18],
[0.14, 0.31, 0.4]
];
fruits.forEach(([x, y, z]) => {
addMesh(inner, new THREE.IcosahedronGeometry(0.25, 0), materials.tomato, [x, y, z], [1, 0.9, 1]);
addMesh(inner, new THREE.ConeGeometry(0.15, 0.12, 5), materials.darkLeaf, [x, y + 0.23, z]);
});
return { root, inner };
}
function createBean() {
const root = new THREE.Group();
const inner = new THREE.Group();
root.add(inner);
const positions = [
[-0.62, -0.22], [-0.2, 0.28], [0.25, -0.3], [0.63, 0.23]
];
positions.forEach(([x, z], i) => {
const height = 0.95 + (i % 2) * 0.18;
addMesh(inner, new THREE.CylinderGeometry(0.03, 0.04, height, 5), materials.stem, [x, height / 2, z]);
for (let leaf = 0; leaf < 3; leaf++) {
addMesh(
inner,
new THREE.IcosahedronGeometry(0.26, 0),
leaf % 2 ? materials.leaf : materials.darkLeaf,
[x + (leaf - 1) * 0.14, 0.38 + leaf * 0.18, z],
[1.35, 0.3, 0.7],
[0, leaf * 0.8, (leaf - 1) * 0.28]
);
}
addMesh(
inner,
new THREE.CapsuleGeometry(0.065, 0.42, 2, 5),
materials.beanPod,
[x + 0.08, 0.62, z + 0.03],
[1, 1, 1],
[0.15, 0, i % 2 ? -0.45 : 0.45]
);
});
return { root, inner };
}
function createClover() {
const root = new THREE.Group();
const inner = new THREE.Group();
root.add(inner);
const positions = [
[-0.58, -0.3], [-0.12, 0.25], [0.36, -0.26], [0.68, 0.28]
];
positions.forEach(([x, z], i) => {
addMesh(
inner,
new THREE.IcosahedronGeometry(0.38, 0),
materials.cloverLeaf,
[x, 0.18, z],
[1.15, 0.48, 1.05]
);
const stemHeight = 0.58 + (i % 2) * 0.16;
addMesh(inner, new THREE.CylinderGeometry(0.025, 0.035, stemHeight, 5), materials.stem, [x, stemHeight / 2, z]);
addMesh(
inner,
new THREE.OctahedronGeometry(0.14, 0),
materials.clover,
[x, stemHeight + 0.08, z],
[0.9, 1.25, 0.9]
);
for (let leaf = 0; leaf < 3; leaf++) {
const angle = leaf * Math.PI * 2 / 3;
addMesh(
inner,
new THREE.OctahedronGeometry(0.18, 0),
materials.cloverLeaf,
[x + Math.cos(angle) * 0.14, 0.08, z + Math.sin(angle) * 0.14],
[1.1, 0.22, 0.65],
[0, angle, 0]
);
}
});
return { root, inner };
}
const cropFactories = {
wheat: createWheat,
tomato: createTomato,
bean: createBean,
clover: createClover
};
function createCrop(cropName) {
const crop = cropFactories[cropName]();
crop.root.userData.inner = crop.inner;
crop.root.userData.crop = cropName;
return crop.root;
}
// ------------------------------------------------------------
// Schedule table and trace UI
// ------------------------------------------------------------
const scheduleBody = document.querySelector("#scheduleBody");
const traceSequence = document.querySelector("#traceSequence");
const traceTitle = document.querySelector("#traceTitle");
const statusPill = document.querySelector("#statusPill");
const autoButton = document.querySelector("#autoButton");
const cycleProgress = document.querySelector("#cycleProgress");
const periodButtons = [...document.querySelectorAll(".period-button")];
let selectedPlot = 0;
let currentPeriod = 0;
let autoplay = true;
let lastPeriodChange = performance.now();
const cycleDuration = 7000;
schedule.forEach((row, rowIndex) => {
const tr = document.createElement("tr");
tr.dataset.row = rowIndex;
tr.innerHTML = `
<td>P${String(rowIndex + 1).padStart(2, "0")}</td>
${row.map((crop, periodIndex) => `
<td>
<button class="crop-cell ${crop}" data-row="${rowIndex}" data-period="${periodIndex}">
<span class="crop-dot"></span>
<span>${cropMeta[crop].label}</span>
</button>
</td>
`).join("")}
`;
scheduleBody.appendChild(tr);
});
function renderTrace() {
const row = schedule[selectedPlot];
traceTitle.textContent = `Plot ${String(selectedPlot + 1).padStart(2, "0")} · full sequence`;
traceSequence.innerHTML = row.map((crop, periodIndex) => `
<button
class="trace-step ${crop} ${periodIndex === currentPeriod ? "active" : ""}"
data-period="${periodIndex}"
title="Show ${periodLabels[periodIndex]} for plot ${selectedPlot + 1}"
>
P${periodIndex + 1}
<strong>${cropMeta[crop].label}</strong>
</button>
`).join("");
}
function setSelectedPlot(index) {
selectedPlot = index;
selectionRing.position.x = plotEntries[index].x;
selectionRing.position.z = plotEntries[index].z;
[...scheduleBody.children].forEach((row, i) => {
row.classList.toggle("selected", i === selectedPlot);
});
renderTrace();
const selectedRow = scheduleBody.children[selectedPlot];
selectedRow?.scrollIntoView({ block: "nearest" });
}
scheduleBody.addEventListener("click", event => {
const cell = event.target.closest(".crop-cell");
if (cell) {
setSelectedPlot(Number(cell.dataset.row));
setPeriod(Number(cell.dataset.period));
return;
}
const row = event.target.closest("tr");
if (row) setSelectedPlot(Number(row.dataset.row));
});
traceSequence.addEventListener("click", event => {
const step = event.target.closest(".trace-step");
if (step) setPeriod(Number(step.dataset.period));
});
document.querySelectorAll("thead th[data-period]").forEach(header => {
header.addEventListener("click", () => setPeriod(Number(header.dataset.period)));
});
// ------------------------------------------------------------
// Period transitions: crops spin away while the next symbol
// grows and rotates into the same fixed plot.
// ------------------------------------------------------------
function completeTransition(entry) {
if (!entry.transition) return;
const { oldGroup, nextGroup } = entry.transition;
if (oldGroup && oldGroup !== nextGroup) scene.remove(oldGroup);
nextGroup.scale.setScalar(1);
nextGroup.rotation.y = 0;
nextGroup.position.y = 0.75;
entry.group = nextGroup;
entry.transition = null;
}
function setPeriod(nextPeriod, animate = true) {
nextPeriod = (nextPeriod + 4) % 4;
if (animate && nextPeriod === currentPeriod) return;
currentPeriod = nextPeriod;
lastPeriodChange = performance.now();
plotEntries.forEach((entry, index) => {
completeTransition(entry);
const nextGroup = createCrop(schedule[index][currentPeriod]);
nextGroup.position.set(entry.x, 0.75, entry.z);
scene.add(nextGroup);
if (animate && entry.group) {
nextGroup.scale.setScalar(0.001);
nextGroup.rotation.y = -Math.PI * 1.35;
entry.transition = {
oldGroup: entry.group,
nextGroup,
start: performance.now(),
delay: index * 0.024,
duration: 1050,
oldScale: entry.group.scale.x,
oldRotation: entry.group.rotation.y
};
} else {
if (entry.group) scene.remove(entry.group);
entry.group = nextGroup;
}
});
periodButtons.forEach((button, index) => {
button.classList.toggle("active", index === currentPeriod);
button.setAttribute("aria-current", index === currentPeriod ? "step" : "false");
});
statusPill.textContent = periodLabels[currentPeriod];
renderTrace();
[...scheduleBody.querySelectorAll(".crop-cell")].forEach(cell => {
cell.classList.toggle("active", Number(cell.dataset.period) === currentPeriod);
});
}
periodButtons.forEach(button => {
button.addEventListener("click", () => setPeriod(Number(button.dataset.period)));
});
autoButton.addEventListener("click", () => {
autoplay = !autoplay;
lastPeriodChange = performance.now();
autoButton.textContent = autoplay ? "Pause cycle" : "Play cycle";
});
document.querySelector("#resetView").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Plot picking
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let dragged = false;
let downX = 0;
let downY = 0;
let hoverPlot = -1;
function raycastPlot(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(soilMeshes, false)[0];
return hit ? soilMeshes.indexOf(hit.object) : -1;
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
dragged = false;
downX = event.clientX;
downY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - downX;
const dy = event.clientY - downY;
if (Math.hypot(dx, dy) > 5) dragged = true;
if (dragged) {
orbit.yaw -= dx * 0.005;
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch + dy * 0.004, 0.34, 1.28);
updateCamera();
}
} else {
hoverPlot = raycastPlot(event.clientX, event.clientY);
renderer.domElement.style.cursor = hoverPlot >= 0 ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (!dragged) {
const plot = raycastPlot(event.clientX, event.clientY);
if (plot >= 0) setSelectedPlot(plot);
}
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
dragged = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(orbit.radius + event.deltaY * 0.012, 14, 36);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
function easeOutCubic(t) {
return 1 - Math.pow(1 - t, 3);
}
function easeOutBack(t) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
}
function animate(now) {
if (autoplay && now - lastPeriodChange >= cycleDuration) {
setPeriod(currentPeriod + 1);
}
plotEntries.forEach(entry => {
if (entry.transition) {
const tr = entry.transition;
const raw = THREE.MathUtils.clamp((now - tr.start - tr.delay) / tr.duration, 0, 1);
const eased = easeOutCubic(raw);
tr.oldGroup.scale.setScalar(tr.oldScale * (1 - eased));
tr.oldGroup.rotation.y = tr.oldRotation + eased * Math.PI * 1.45;
tr.oldGroup.position.y = 0.75 + eased * 0.38;
tr.nextGroup.scale.setScalar(Math.max(0.001, easeOutBack(raw)));
tr.nextGroup.rotation.y = -Math.PI * 1.35 * (1 - eased);
tr.nextGroup.position.y = 0.75 + (1 - eased) * 0.48;
if (raw >= 1) completeTransition(entry);
}
if (entry.group) {
const inner = entry.group.userData.inner;
inner.rotation.z = Math.sin(now * 0.00125 + entry.phase) * 0.026;
inner.rotation.x = Math.cos(now * 0.00105 + entry.phase) * 0.012;
inner.position.y = Math.sin(now * 0.0017 + entry.phase) * 0.018;
}
});
soilMeshes.forEach((soil, index) => {
const isHovered = index === hoverPlot;
const isSelected = index === selectedPlot;
soil.material.emissive.setHex(isHovered ? 0x173d27 : isSelected ? 0x12362d : 0x000000);
soil.material.emissiveIntensity = isHovered ? 0.5 : isSelected ? 0.22 : 0;
});
const progress = autoplay
? THREE.MathUtils.clamp((now - lastPeriodChange) / cycleDuration, 0, 1)
: 0;
cycleProgress.style.width = `${progress * 100}%`;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Initialize the first period without transition.
setPeriod(0, false);
setSelectedPlot(0);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```