Prompt specification
Build or customize the Three.js 3D scene "Four-field rotation planning board" 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: Four-field rotation planning board
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/four-field-rotation-planning-board-x1049
Scene Description Prompt:
A stylized four-field crop-rotation board; season cards change crops while the same four fields remain identifiable. Three.js from cdnjs, one HTML file.
Working Three.js Starter (four-field-rotation-planning-board-x1049):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#c7e0df">
<title>Four Seasons — A Crop-Rotation Board</title>
<style>
:root {
--accent: #6e9d62;
--ink: #25352d;
--paper: #f7f0df;
--glass: rgba(250, 246, 232, 0.86);
--line: rgba(42, 61, 49, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c7e0df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
outline: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 45%, rgba(35, 53, 43, 0.08) 100%),
linear-gradient(to bottom, rgba(255, 255, 255, 0.08), transparent 28%);
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.brand {
position: absolute;
top: clamp(20px, 4vw, 52px);
left: clamp(20px, 4vw, 56px);
max-width: 430px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--accent);
border-radius: 99px;
transition: background 400ms ease;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 5vw, 68px);
font-weight: 500;
line-height: 0.94;
letter-spacing: -0.045em;
}
h1 em {
display: block;
margin-top: 7px;
color: color-mix(in srgb, var(--ink) 70%, var(--paper));
font-size: 0.53em;
font-weight: 400;
letter-spacing: -0.025em;
}
.brand-copy {
display: inline-flex;
align-items: center;
gap: 10px;
margin-top: 17px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.36);
border-radius: 99px;
background: rgba(250, 247, 235, 0.35);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.brand-copy span {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
transition: background 400ms ease;
}
.field-panel {
position: absolute;
top: clamp(20px, 4vw, 46px);
right: clamp(20px, 4vw, 48px);
width: 254px;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.46);
border-radius: 18px;
background: var(--glass);
box-shadow:
0 18px 50px rgba(35, 50, 40, 0.12),
inset 0 1px 0 rgba(255, 255, 255, 0.65);
backdrop-filter: blur(18px) saturate(1.12);
}
.panel-heading {
display: flex;
justify-content: space-between;
margin-bottom: 12px;
color: rgba(37, 53, 45, 0.57);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.field-panel h2 {
margin: 0 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
font-weight: 500;
letter-spacing: -0.025em;
}
.crop-line {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
transition: background 400ms ease;
}
.field-panel p {
min-height: 32px;
margin: 10px 0 14px;
color: rgba(37, 53, 45, 0.66);
font-size: 11px;
line-height: 1.55;
}
.play-button {
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
width: 100%;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.38);
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
transition:
background 180ms ease,
transform 180ms ease;
}
.play-button:hover {
background: rgba(255, 255, 255, 0.7);
transform: translateY(-1px);
}
.play-icon {
display: inline-grid;
width: 18px;
height: 18px;
place-items: center;
border-radius: 50%;
background: var(--accent);
color: white;
font-size: 8px;
line-height: 1;
transition: background 400ms ease;
}
.season-dock {
position: absolute;
bottom: 24px;
left: 50%;
display: flex;
gap: 10px;
max-width: calc(100vw - 36px);
padding: 9px;
overflow-x: auto;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 23px;
background: rgba(247, 240, 223, 0.78);
box-shadow:
0 22px 70px rgba(31, 45, 36, 0.18),
inset 0 1px 0 rgba(255, 255, 255, 0.72);
backdrop-filter: blur(22px) saturate(1.08);
pointer-events: auto;
transform: translateX(-50%);
scrollbar-width: none;
}
.season-dock::-webkit-scrollbar {
display: none;
}
.season-card {
position: relative;
display: grid;
grid-template-columns: 42px 1fr;
align-items: center;
gap: 11px;
min-width: 190px;
min-height: 91px;
padding: 13px 15px 13px 12px;
overflow: hidden;
border: 1px solid transparent;
border-radius: 16px;
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
transform 220ms ease,
border-color 220ms ease,
background 220ms ease,
box-shadow 220ms ease;
}
.season-card::after {
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 3px;
content: "";
background: var(--card-accent);
opacity: 0;
transform: scaleX(0.4);
transition:
opacity 220ms ease,
transform 220ms ease;
}
.season-card:hover {
background: rgba(255, 255, 255, 0.45);
transform: translateY(-2px);
}
.season-card.active {
border-color: color-mix(in srgb, var(--card-accent) 35%, transparent);
background: rgba(255, 255, 255, 0.66);
box-shadow: 0 10px 26px rgba(37, 53, 45, 0.09);
transform: translateY(-5px);
}
.season-card.active::after {
opacity: 1;
transform: scaleX(1);
}
.card-number {
position: absolute;
top: 8px;
right: 10px;
color: rgba(37, 53, 45, 0.3);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
}
.card-icon {
display: grid;
width: 42px;
height: 52px;
place-items: center;
border-radius: 12px;
background:
linear-gradient(
145deg,
color-mix(in srgb, var(--card-accent) 18%, transparent),
color-mix(in srgb, var(--card-accent) 4%, transparent)
);
color: var(--card-accent);
}
.card-icon svg {
width: 27px;
height: 27px;
overflow: visible;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.6;
}
.card-copy {
display: flex;
flex-direction: column;
min-width: 0;
}
.season-name {
margin-bottom: 4px;
color: rgba(37, 53, 45, 0.55);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.card-copy strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
letter-spacing: -0.025em;
}
.card-copy small {
margin-top: 4px;
overflow: hidden;
color: rgba(37, 53, 45, 0.58);
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.controls-hint {
position: absolute;
right: clamp(20px, 4vw, 48px);
bottom: 137px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 99px;
background: rgba(248, 244, 231, 0.32);
backdrop-filter: blur(10px);
color: rgba(37, 53, 45, 0.63);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls-hint svg {
width: 14px;
height: 14px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.5;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #c7e0df;
transition:
opacity 600ms ease,
visibility 600ms ease;
}
#loading.hidden {
visibility: hidden;
opacity: 0;
}
.loader-mark {
text-align: center;
}
.loader-ring {
width: 42px;
height: 42px;
margin: 0 auto 15px;
border: 2px solid rgba(37, 53, 45, 0.13);
border-top-color: var(--ink);
border-radius: 50%;
animation: spin 850ms linear infinite;
}
.loader-mark span {
font-size: 9px;
font-weight: 850;
letter-spacing: 0.22em;
text-transform: uppercase;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 760px) {
.brand {
top: 20px;
left: 20px;
}
.brand-copy {
display: none;
}
h1 {
font-size: 38px;
}
.field-panel {
top: 18px;
right: 16px;
width: 178px;
padding: 13px;
border-radius: 14px;
}
.field-panel h2 {
font-size: 19px;
}
.field-panel p {
display: none;
}
.play-button {
margin-top: 11px;
padding: 8px;
font-size: 8px;
}
.season-dock {
bottom: 12px;
left: 12px;
right: 12px;
max-width: none;
justify-content: flex-start;
transform: none;
}
.season-card {
min-width: 166px;
min-height: 80px;
grid-template-columns: 36px 1fr;
padding: 10px;
}
.card-icon {
width: 36px;
height: 46px;
}
.card-copy strong {
font-size: 17px;
}
.controls-hint {
display: none;
}
}
@media (max-width: 480px) {
.brand .eyebrow {
margin-bottom: 8px;
font-size: 8px;
}
h1 {
font-size: 31px;
}
.field-panel {
width: 142px;
}
.panel-heading span:last-child,
.field-panel p {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="vignette"></div>
<div class="hud">
<header class="brand">
<div class="eyebrow">Field study / No. 04</div>
<h1>
Four Seasons,
<em>one living board.</em>
</h1>
<div class="brand-copy">
<span></span>
4 permanent plots · 4 seasonal crops
</div>
</header>
<aside class="field-panel">
<div class="panel-heading">
<span id="field-code">Field A</span>
<span id="field-index">01 / 04</span>
</div>
<h2 id="field-name">North Ridge</h2>
<div class="crop-line">
<span class="status-dot"></span>
<span id="field-crop">Barley</span>
</div>
<p id="field-note">Loam soil · well drained · gentle north slope</p>
<button class="play-button" id="play-button" type="button">
<span class="play-icon" id="play-icon">▶</span>
<span id="play-label">Play rotation</span>
</button>
</aside>
<nav class="season-dock" aria-label="Choose a season">
<button
class="season-card active"
type="button"
data-season="0"
style="--card-accent:#6e9d62"
aria-pressed="true"
>
<span class="card-number">01</span>
<span class="card-icon">
<svg viewBox="0 0 32 32" aria-hidden="true">
<circle cx="16" cy="16" r="5"></circle>
<path d="M16 2v4M16 26v4M2 16h4M26 16h4M6.1 6.1l2.8 2.8M23.1 23.1l2.8 2.8M25.9 6.1l-2.8 2.8M8.9 23.1l-2.8 2.8"></path>
</svg>
</span>
<span class="card-copy">
<span class="season-name">Spring</span>
<strong>Barley</strong>
<small>Cool-season grain</small>
</span>
</button>
<button
class="season-card"
type="button"
data-season="1"
style="--card-accent:#d59a2b"
aria-pressed="false"
>
<span class="card-number">02</span>
<span class="card-icon">
<svg viewBox="0 0 32 32" aria-hidden="true">
<path d="M8 27h16M11 27V15h10v12M8 15h16l-8-9-8 9Z"></path>
<path d="M16 27v-7M16 9V5M13 7l3 3 3-3"></path>
</svg>
</span>
<span class="card-copy">
<span class="season-name">Summer</span>
<strong>Maize</strong>
<small>Warm-season staple</small>
</span>
</button>
<button
class="season-card"
type="button"
data-season="2"
style="--card-accent:#d97932"
aria-pressed="false"
>
<span class="card-number">03</span>
<span class="card-icon">
<svg viewBox="0 0 32 32" aria-hidden="true">
<path d="M8 13c0-4 16-4 16 0v9c0 5-16 5-16 0v-9Z"></path>
<path d="M16 9c-3-3-6-2-7-1 1 3 3 5 7 5M16 9c3-3 6-2 7-1-1 3-3 5-7 5M16 10v16"></path>
</svg>
</span>
<span class="card-copy">
<span class="season-name">Autumn</span>
<strong>Pumpkin</strong>
<small>Deep-rooted ground crop</small>
</span>
</button>
<button
class="season-card"
type="button"
data-season="3"
style="--card-accent:#668b86"
aria-pressed="false"
>
<span class="card-number">04</span>
<span class="card-icon">
<svg viewBox="0 0 32 32" aria-hidden="true">
<path d="M16 3v26M4.7 9.5l22.6 13M27.3 9.5 4.7 22.5M12 5l4 4 4-4M12 27l4-4 4 4M5.5 16l4.5-2.5L8 9M26.5 16 22 13.5 24 9"></path>
</svg>
</span>
<span class="card-copy">
<span class="season-name">Winter</span>
<strong>Rye</strong>
<small>Protective cover crop</small>
</span>
</button>
</nav>
<div class="controls-hint">
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M10 2v16M2 10h16M6 6l4-4 4 4M6 14l4 4 4-4M4 6v8l4-2M16 14V6l-4 2"></path>
</svg>
Drag to orbit · Scroll to zoom
</div>
</div>
<div id="loading">
<div class="loader-mark">
<div class="loader-ring"></div>
<span>Preparing the field board</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const loading = document.querySelector("#loading");
const cards = [...document.querySelectorAll(".season-card")];
const playButton = document.querySelector("#play-button");
const playIcon = document.querySelector("#play-icon");
const playLabel = document.querySelector("#play-label");
const fieldCode = document.querySelector("#field-code");
const fieldIndex = document.querySelector("#field-index");
const fieldName = document.querySelector("#field-name");
const fieldCrop = document.querySelector("#field-crop");
const fieldNote = document.querySelector("#field-note");
const seasons = [
{
name: "Spring",
crop: "Barley",
sky: 0xc7e0df,
ground: 0x89aa65,
board: 0xd7c49a,
soil: 0x76523d,
accent: 0x6e9d62,
foliage: 0x5f8c51,
sunlight: 0xffefd2,
particle: 0xffe8a0,
particleMode: "pollen"
},
{
name: "Summer",
crop: "Maize",
sky: 0x9fd5e6,
ground: 0x6b9c4d,
board: 0xd7bc83,
soil: 0x6c4635,
accent: 0xd59a2b,
foliage: 0x3f713a,
sunlight: 0xfff1bd,
particle: 0xffe58d,
particleMode: "fireflies"
},
{
name: "Autumn",
crop: "Pumpkin",
sky: 0xe9c393,
ground: 0xa78a50,
board: 0xc6a574,
soil: 0x684333,
accent: 0xd97932,
foliage: 0xc27a3c,
sunlight: 0xffd29b,
particle: 0xd97834,
particleMode: "leaves"
},
{
name: "Winter",
crop: "Rye",
sky: 0xd9e5e8,
ground: 0xd2d9d2,
board: 0xcfc9b7,
soil: 0x66534a,
accent: 0x668b86,
foliage: 0x91a293,
sunlight: 0xe5efff,
particle: 0xffffff,
particleMode: "snow"
}
];
const fields = [
{
letter: "A",
name: "North Ridge",
x: -3.05,
z: -2.05,
note: "Loam soil · well drained · gentle north slope"
},
{
letter: "B",
name: "Highbank",
x: 3.05,
z: -2.05,
note: "Sandy soil · sun-facing · quick drainage"
},
{
letter: "C",
name: "Clover Bottom",
x: -3.05,
z: 2.05,
note: "Clay soil · moisture-rich · sheltered hollow"
},
{
letter: "D",
name: "South Acre",
x: 3.05,
z: 2.05,
note: "Silt soil · level terraces · long sunlight"
}
];
const scene = new THREE.Scene();
scene.background = new THREE.Color(seasons[0].sky);
scene.fog = new THREE.Fog(seasons[0].sky, 24, 48);
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe5f5ff, 0x6f7449, 1.65);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xffefd2, 2.65);
sunLight.position.set(-9, 14, 8);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -12;
sunLight.shadow.camera.right = 12;
sunLight.shadow.camera.top = 12;
sunLight.shadow.camera.bottom = -12;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 35;
sunLight.shadow.bias = -0.00035;
sunLight.shadow.normalBias = 0.025;
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0xb7d8ed, 0.45);
fillLight.position.set(8, 7, -10);
scene.add(fillLight);
const orbit = {
theta: 0.72,
phi: 0.91,
radius: 20.5,
target: new THREE.Vector3(0, 0.45, 0)
};
function updateCamera() {
const spherical = new THREE.Spherical(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.setFromSpherical(spherical).add(orbit.target);
camera.lookAt(orbit.target);
}
let firstResize = true;
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = aspect;
camera.fov = aspect < 0.75 ? 52 : 36;
if (firstResize) {
orbit.radius = aspect < 0.75 ? 31 : aspect < 1 ? 25 : 20.5;
firstResize = false;
}
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const groundMaterial = new THREE.MeshStandardMaterial({
color: seasons[0].ground,
roughness: 1
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.42;
ground.receiveShadow = true;
scene.add(ground);
const boardMaterial = new THREE.MeshStandardMaterial({
color: seasons[0].board,
roughness: 0.92
});
const boardEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x71614b,
roughness: 1
});
const pathMaterial = new THREE.MeshStandardMaterial({
color: 0xd9c99e,
roughness: 1
});
const borderMaterial = new THREE.MeshStandardMaterial({
color: 0x574737,
roughness: 1
});
const soilMaterial = new THREE.MeshStandardMaterial({
color: seasons[0].soil,
roughness: 1
});
const furrowMaterial = new THREE.MeshStandardMaterial({
color: 0x493329,
roughness: 1
});
const foliageMaterial = new THREE.MeshStandardMaterial({
color: seasons[0].foliage,
roughness: 0.92,
flatShading: true
});
function roundedRectShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function roundedSlab(width, height, depth, radius, material) {
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, height, radius),
{
depth,
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: 0.055,
bevelThickness: 0.045,
curveSegments: 8
}
);
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
const boardEdge = roundedSlab(
15.8,
11.6,
0.22,
0.72,
boardEdgeMaterial
);
boardEdge.position.y = -0.32;
scene.add(boardEdge);
const board = roundedSlab(
15.4,
11.2,
0.34,
0.65,
boardMaterial
);
board.position.y = -0.18;
scene.add(board);
const verticalPath = new THREE.Mesh(
new THREE.BoxGeometry(1.05, 0.055, 10.45),
pathMaterial
);
verticalPath.position.y = 0.17;
verticalPath.receiveShadow = true;
scene.add(verticalPath);
const horizontalPath = new THREE.Mesh(
new THREE.BoxGeometry(14.45, 0.058, 1.05),
pathMaterial
);
horizontalPath.position.y = 0.175;
horizontalPath.receiveShadow = true;
scene.add(horizontalPath);
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0xb6a68a,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 10; i += 1) {
const stone = new THREE.Mesh(
new THREE.CylinderGeometry(0.1 + (i % 3) * 0.025, 0.12, 0.045, 7),
stoneMaterial
);
stone.position.set(
(i % 2 ? -1 : 1) * 0.16,
0.22,
-4.6 + i * 1.02
);
stone.rotation.y = i * 0.63;
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
}
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 160;
function roundedCanvasRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeFieldLabel(field) {
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 160);
ctx.shadowColor = "rgba(20, 30, 23, 0.22)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 8;
roundedCanvasRect(ctx, 12, 12, 488, 126, 30);
ctx.fillStyle = "#f6eedc";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.strokeStyle = "#425246";
ctx.lineWidth = 5;
ctx.stroke();
ctx.beginPath();
ctx.arc(78, 75, 43, 0, Math.PI * 2);
ctx.fillStyle = "#425246";
ctx.fill();
ctx.fillStyle = "#fff8e8";
ctx.font = "700 48px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(field.letter, 78, 78);
ctx.fillStyle = "#2e4034";
ctx.font = "700 25px Arial";
ctx.textAlign = "left";
ctx.fillText("FIELD " + field.letter, 140, 58);
ctx.fillStyle = "rgba(46, 64, 52, 0.65)";
ctx.font = "500 23px Arial";
ctx.fillText(field.name.toUpperCase(), 140, 96);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(2.05, 0.64, 1);
return sprite;
}
const fieldMeshes = [];
const fieldGroups = [];
for (let index = 0; index < fields.length; index += 1) {
const field = fields[index];
const group = new THREE.Group();
group.position.set(field.x, 0, field.z);
scene.add(group);
const border = roundedSlab(
5.18,
3.62,
0.12,
0.32,
borderMaterial
);
border.position.y = 0.17;
group.add(border);
const soil = roundedSlab(
4.94,
3.38,
0.11,
0.25,
soilMaterial
);
soil.position.y = 0.27;
soil.userData.fieldIndex = index;
group.add(soil);
fieldMeshes.push(soil);
const furrowGeometry = new THREE.BoxGeometry(0.045, 0.024, 3.03);
for (let row = 0; row < 9; row += 1) {
const furrow = new THREE.Mesh(furrowGeometry, furrowMaterial);
furrow.position.set(-1.9 + row * 0.475, 0.385, 0);
furrow.receiveShadow = true;
group.add(furrow);
}
const signPost = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, 0.86, 6),
borderMaterial
);
signPost.position.set(-2.12, 0.72, 1.28);
signPost.castShadow = true;
group.add(signPost);
const label = makeFieldLabel(field);
label.position.set(-2.12, 1.27, 1.28);
group.add(label);
field.crop = null;
fieldGroups.push(group);
}
const selectionPoints = [
new THREE.Vector3(-2.65, 0.45, -1.87),
new THREE.Vector3(2.65, 0.45, -1.87),
new THREE.Vector3(2.65, 0.45, 1.87),
new THREE.Vector3(-2.65, 0.45, 1.87)
];
const selectionMaterial = new THREE.LineBasicMaterial({
color: seasons[0].accent,
transparent: true,
opacity: 0.95
});
const selectionFrame = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(selectionPoints),
selectionMaterial
);
scene.add(selectionFrame);
let selectedField = 0;
function updateSelection(index) {
selectedField = index;
const field = fields[index];
selectionFrame.position.set(field.x, 0, field.z);
fieldCode.textContent = `Field ${field.letter}`;
fieldIndex.textContent = `${String(index + 1).padStart(2, "0")} / 04`;
fieldName.textContent = field.name;
fieldNote.textContent = field.note;
}
updateSelection(0);
const barnMaterial = new THREE.MeshStandardMaterial({
color: 0xa94f3e,
roughness: 0.9
});
const barnTrimMaterial = new THREE.MeshStandardMaterial({
color: 0xf0dfc4,
roughness: 0.9
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x4d5149,
roughness: 0.95,
side: THREE.DoubleSide
});
function makeBarn() {
const group = new THREE.Group();
group.position.set(8.8, -0.4, -2.7);
group.rotation.y = -0.18;
const body = new THREE.Mesh(
new THREE.BoxGeometry(1.65, 1.35, 1.4),
barnMaterial
);
body.position.y = 0.675;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const roofGeometry = new THREE.BufferGeometry();
roofGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-0.93, 0, -0.78,
0.93, 0, -0.78,
0, 0.72, -0.78,
-0.93, 0, 0.78,
0.93, 0, 0.78,
0, 0.72, 0.78
], 3)
);
roofGeometry.setIndex([
0, 1, 2,
3, 5, 4,
0, 3, 4,
0, 4, 1,
1, 4, 5,
1, 5, 2,
2, 5, 3,
2, 3, 0
]);
roofGeometry.computeVertexNormals();
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.position.y = 1.35;
roof.castShadow = true;
group.add(roof);
const door = new THREE.Mesh(
new THREE.BoxGeometry(0.63, 0.83, 0.035),
barnTrimMaterial
);
door.position.set(0, 0.415, 0.716);
group.add(door);
const doorCrossA = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.84, 0.045),
barnTrimMaterial
);
doorCrossA.position.set(0, 0.415, 0.742);
group.add(doorCrossA);
const doorCrossB = new THREE.Mesh(
new THREE.BoxGeometry(0.64, 0.035, 0.045),
barnTrimMaterial
);
doorCrossB.position.set(0, 0.415, 0.742);
group.add(doorCrossB);
return group;
}
scene.add(makeBarn());
const siloMaterial = new THREE.MeshStandardMaterial({
color: 0xc9c5b5,
roughness: 0.7,
metalness: 0.15
});
const silo = new THREE.Group();
silo.position.set(8.25, -0.4, -4.15);
const siloBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.45, 0.5, 1.8, 16),
siloMaterial
);
siloBody.position.y = 0.9;
siloBody.castShadow = true;
silo.add(siloBody);
const siloTop = new THREE.Mesh(
new THREE.ConeGeometry(0.49, 0.48, 16),
roofMaterial
);
siloTop.position.y = 2.03;
siloTop.castShadow = true;
silo.add(siloTop);
scene.add(silo);
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x76533a,
roughness: 1
});
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.4, z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.15, 1.25, 7),
trunkMaterial
);
trunk.position.y = 0.625;
trunk.castShadow = true;
group.add(trunk);
const crownA = new THREE.Mesh(
new THREE.ConeGeometry(0.62, 1.25, 8),
foliageMaterial
);
crownA.position.y = 1.35;
crownA.castShadow = true;
group.add(crownA);
const crownB = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.05, 8),
foliageMaterial
);
crownB.position.y = 1.95;
crownB.castShadow = true;
group.add(crownB);
scene.add(group);
}
makeTree(-8.45, 3.8, 1.1);
makeTree(-8.7, -3.6, 0.9);
makeTree(8.6, 3.8, 1.05);
const fenceMaterial = new THREE.MeshStandardMaterial({
color: 0xd9c59b,
roughness: 1
});
function addFencePost(x, z) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.92, 0.11),
fenceMaterial
);
post.position.set(x, 0.03, z);
post.castShadow = true;
scene.add(post);
}
for (let x = -7.4; x <= 7.5; x += 1.48) {
addFencePost(x, -5.48);
addFencePost(x, 5.48);
}
for (let z = -4.05; z <= 4.1; z += 1.48) {
addFencePost(-7.55, z);
addFencePost(7.55, z);
}
const railLongGeometry = new THREE.BoxGeometry(15.1, 0.09, 0.07);
const railShortGeometry = new THREE.BoxGeometry(0.07, 0.09, 11.0);
for (const z of [-5.48, 5.48]) {
const rail = new THREE.Mesh(railLongGeometry, fenceMaterial);
rail.position.set(0, 0.22, z);
rail.castShadow = true;
scene.add(rail);
}
for (const x of [-7.55, 7.55]) {
const rail = new THREE.Mesh(railShortGeometry, fenceMaterial);
rail.position.set(x, 0.22, 0);
rail.castShadow = true;
scene.add(rail);
}
const hayMaterial = new THREE.MeshStandardMaterial({
color: 0xd9b963,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 3; i += 1) {
const bale = new THREE.Mesh(
new THREE.CylinderGeometry(0.32, 0.32, 0.52, 12),
hayMaterial
);
bale.rotation.z = Math.PI / 2;
bale.position.set(-6.45 + i * 0.62, 0.09, -4.45);
bale.castShadow = true;
bale.receiveShadow = true;
scene.add(bale);
}
function createLeafGeometry() {
const shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.bezierCurveTo(0.22, 0.18, 0.2, 0.52, 0, 0.72);
shape.bezierCurveTo(-0.2, 0.52, -0.22, 0.18, 0, 0);
return new THREE.ShapeGeometry(shape, 7);
}
const cropGeometry = {
stem: new THREE.CylinderGeometry(0.022, 0.032, 1, 5),
grain: new THREE.SphereGeometry(0.075, 6, 4),
leaf: createLeafGeometry(),
cob: new THREE.CylinderGeometry(0.09, 0.13, 0.5, 8),
tassel: new THREE.ConeGeometry(0.09, 0.28, 5),
pumpkin: new THREE.SphereGeometry(0.27, 12, 8),
vine: new THREE.CylinderGeometry(0.018, 0.024, 1, 5),
blade: new THREE.CylinderGeometry(0.008, 0.017, 1, 4)
};
cropGeometry.flatLeaf = createLeafGeometry();
cropGeometry.flatLeaf.rotateX(-Math.PI / 2);
const cropAssets = {
barley: {
stem: new THREE.MeshStandardMaterial({
color: 0x608d42,
roughness: 0.95,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x78a34f,
roughness: 0.95,
side: THREE.DoubleSide,
flatShading: true
}),
grain: new THREE.MeshStandardMaterial({
color: 0xd8b95b,
roughness: 0.9,
flatShading: true
})
},
maize: {
stem: new THREE.MeshStandardMaterial({
color: 0x3e7937,
roughness: 0.95,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x4f963f,
roughness: 0.95,
side: THREE.DoubleSide,
flatShading: true
}),
cob: new THREE.MeshStandardMaterial({
color: 0xf0b92f,
roughness: 0.85,
flatShading: true
}),
tassel: new THREE.MeshStandardMaterial({
color: 0xb18d3f,
roughness: 1,
flatShading: true
})
},
pumpkin: {
vine: new THREE.MeshStandardMaterial({
color: 0x4b7336,
roughness: 1,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x628a3c,
roughness: 1,
side: THREE.DoubleSide,
flatShading: true
}),
pumpkin: new THREE.MeshStandardMaterial({
color: 0xe47827,
roughness: 0.82,
flatShading: true
}),
stem: new THREE.MeshStandardMaterial({
color: 0x6e7732,
roughness: 1
})
},
rye: {
stem: new THREE.MeshStandardMaterial({
color: 0x57765c,
roughness: 1,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x6f8c70,
roughness: 1,
side: THREE.DoubleSide,
flatShading: true
}),
grain: new THREE.MeshStandardMaterial({
color: 0x899a7d,
roughness: 1,
flatShading: true
})
}
};
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
function makePlants(columns, rows, seed, jitter = 0.08) {
const random = seededRandom(seed);
const plants = [];
for (let row = 0; row < rows; row += 1) {
for (let column = 0; column < columns; column += 1) {
const x =
columns === 1
? 0
: -1.82 + (column / (columns - 1)) * 3.64;
const z =
rows === 1
? 0
: -1.08 + (row / (rows - 1)) * 2.16;
plants.push({
x: x + (random() - 0.5) * jitter,
z: z + (random() - 0.5) * jitter,
rotation: random() * Math.PI * 2,
scale: 0.82 + random() * 0.35
});
}
}
return plants;
}
function resetTransform(object) {
object.position.set(0, 0, 0);
object.rotation.set(0, 0, 0);
object.quaternion.identity();
object.scale.set(1, 1, 1);
}
function addInstances(group, geometry, material, count, fill) {
const mesh = new THREE.InstancedMesh(geometry, material, count);
const dummy = new THREE.Object3D();
for (let index = 0; index < count; index += 1) {
resetTransform(dummy);
fill(index, dummy);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function buildBarley(fieldIndex) {
const group = new THREE.Group();
const plants = makePlants(7, 5, 1100 + fieldIndex * 93);
const assets = cropAssets.barley;
addInstances(
group,
cropGeometry.stem,
assets.stem,
plants.length,
(index, object) => {
const plant = plants[index];
const height = (0.58 + (index % 4) * 0.055) * plant.scale;
object.position.set(plant.x, height / 2, plant.z);
object.scale.set(1, height, 1);
}
);
addInstances(
group,
cropGeometry.leaf,
assets.leaf,
plants.length * 2,
(index, object) => {
const plant = plants[index % plants.length];
const side = index < plants.length ? -1 : 1;
object.position.set(plant.x, 0.18 * plant.scale, plant.z);
object.rotation.set(
0,
plant.rotation + side * 0.8,
side * 0.62
);
object.scale.set(0.75, 0.72 * plant.scale, 0.75);
}
);
addInstances(
group,
cropGeometry.grain,
assets.grain,
plants.length * 3,
(index, object) => {
const plant = plants[Math.floor(index / 3)];
const row = index % 3;
const height = (0.62 + (index % 4) * 0.045) * plant.scale;
object.position.set(
plant.x + (row - 1) * 0.018,
height + row * 0.045,
plant.z
);
object.scale.set(0.72, 1.65, 0.72);
}
);
return group;
}
function buildMaize(fieldIndex) {
const group = new THREE.Group();
const plants = makePlants(7, 4, 2200 + fieldIndex * 73);
const assets = cropAssets.maize;
addInstances(
group,
cropGeometry.stem,
assets.stem,
plants.length,
(index, object) => {
const plant = plants[index];
const height = (1.04 + (index % 3) * 0.12) * plant.scale;
object.position.set(plant.x, height / 2, plant.z);
object.scale.set(1, height, 1);
}
);
addInstances(
group,
cropGeometry.leaf,
assets.leaf,
plants.length * 4,
(index, object) => {
const plant = plants[Math.floor(index / 4)];
const level = index % 4;
const side = level % 2 ? -1 : 1;
object.position.set(
plant.x + side * 0.025,
(0.18 + level * 0.19) * plant.scale,
plant.z
);
object.rotation.set(
0,
plant.rotation + level * 1.75,
side * 0.52
);
object.scale.set(1, 0.95 + (level % 2) * 0.15, 1);
}
);
addInstances(
group,
cropGeometry.cob,
assets.cob,
plants.length,
(index, object) => {
const plant = plants[index];
object.position.set(
plant.x + Math.cos(plant.rotation) * 0.11,
0.57 * plant.scale,
plant.z + Math.sin(plant.rotation) * 0.11
);
object.rotation.set(0.12, plant.rotation, 0.22);
}
);
addInstances(
group,
cropGeometry.tassel,
assets.tassel,
plants.length,
(index, object) => {
const plant = plants[index];
const height = (1.04 + (index % 3) * 0.12) * plant.scale;
object.position.set(plant.x, height + 0.12, plant.z);
object.rotation.z = Math.sin(plant.rotation) * 0.12;
}
);
return group;
}
function buildPumpkin(fieldIndex) {
const group = new THREE.Group();
const plants = makePlants(6, 4, 3300 + fieldIndex * 57);
const assets = cropAssets.pumpkin;
const yAxis = new THREE.Vector3(0, 1, 0);
addInstances(
group,
cropGeometry.pumpkin,
assets.pumpkin,
plants.length,
(index, object) => {
const plant = plants[index];
const size = 0.88 + (index % 3) * 0.08;
object.position.set(plant.x, 0.2 * size, plant.z);
object.scale.set(size, 0.73 * size, size);
object.rotation.y = plant.rotation;
}
);
addInstances(
group,
cropGeometry.vine,
assets.vine,
plants.length * 2,
(index, object) => {
const plant = plants[Math.floor(index / 2)];
const direction = new THREE.Vector3(
-plant.x,
0,
-plant.z
);
const length = Math.max(0.001, direction.length());
direction.normalize();
object.position.set(plant.x * 0.5, 0.055, plant.z * 0.5);
object.quaternion.setFromUnitVectors(yAxis, direction);
object.scale.set(1, length, 1);
}
);
addInstances(
group,
cropGeometry.flatLeaf,
assets.leaf,
plants.length * 2,
(index, object) => {
const plant = plants[Math.floor(index / 2)];
const side = index % 2 ? -1 : 1;
object.position.set(
plant.x + side * 0.15,
0.045,
plant.z + side * 0.08
);
object.rotation.set(0, plant.rotation + side * 0.7, 0);
object.scale.set(0.78, 0.78, 0.78);
}
);
addInstances(
group,
cropGeometry.vine,
assets.stem,
plants.length,
(index, object) => {
const plant = plants[index];
const direction = new THREE.Vector3(0.04, 0.12, 0.02);
const length = direction.length();
direction.normalize();
object.position.set(plant.x, 0.34, plant.z);
object.quaternion.setFromUnitVectors(yAxis, direction);
object.scale.set(1.2, length, 1.2);
}
);
return group;
}
function buildRye(fieldIndex) {
const group = new THREE.Group();
const plants = makePlants(8, 5, 4400 + fieldIndex * 41, 0.13);
const assets = cropAssets.rye;
addInstances(
group,
cropGeometry.blade,
assets.stem,
plants.length * 3,
(index, object) => {
const plant = plants[Math.floor(index / 3)];
const blade = index % 3;
const height =
(0.35 + blade * 0.075 + (index % 4) * 0.025) * plant.scale;
object.position.set(
plant.x + (blade - 1) * 0.055,
height / 2,
plant.z + (blade % 2) * 0.025
);
object.rotation.z = (blade - 1) * 0.19;
object.scale.set(1, height, 1);
}
);
addInstances(
group,
cropGeometry.leaf,
assets.leaf,
plants.length,
(index, object) => {
const plant = plants[index];
const height = 0.34 * plant.scale;
object.position.set(plant.x, height * 0.45, plant.z);
object.rotation.set(0, plant.rotation, 0.48);
object.scale.set(0.38, 0.48, 0.38);
}
);
addInstances(
group,
cropGeometry.grain,
assets.grain,
plants.length,
(index, object) => {
const plant = plants[index];
const height = (0.48 + (index % 3) * 0.035) * plant.scale;
object.position.set(plant.x, height, plant.z);
object.scale.set(0.48, 1.55, 0.48);
}
);
return group;
}
function buildCrop(seasonIndex, fieldIndex) {
if (seasonIndex === 0) return buildBarley(fieldIndex);
if (seasonIndex === 1) return buildMaize(fieldIndex);
if (seasonIndex === 2) return buildPumpkin(fieldIndex);
return buildRye(fieldIndex);
}
const transitionList = [];
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function removeCropGroup(group) {
if (!group) return;
group.removeFromParent();
group.traverse((object) => {
if (object.isInstancedMesh && object.dispose) object.dispose();
});
}
function applySeason(seasonIndex, animate = true) {
const season = seasons[seasonIndex];
cards.forEach((card, index) => {
const active = index === seasonIndex;
card.classList.toggle("active", active);
card.setAttribute("aria-pressed", String(active));
});
document.documentElement.style.setProperty(
"--accent",
`#${season.accent.toString(16).padStart(6, "0")}`
);
fields.forEach((field, fieldIndex) => {
const previous = field.crop;
if (previous && animate) {
transitionList.push({
group: previous,
outgoing: true,
time: 0,
duration: reduceMotion ? 0.01 : 0.32,
startScale: previous.scale.y
});
} else if (previous) {
removeCropGroup(previous);
}
const next = buildCrop(seasonIndex, fieldIndex);
next.position.y = 0.39;
fieldGroups[fieldIndex].add(next);
field.crop = next;
if (animate) {
next.scale.set(0.98, 0.015, 0.98);
transitionList.push({
group: next,
outgoing: false,
time: 0,
duration: reduceMotion ? 0.01 : 0.68
});
}
});
fieldCrop.textContent = season.crop;
}
let currentSeason = 0;
function setSeason(index, animate = true) {
currentSeason = (index + seasons.length) % seasons.length;
applySeason(currentSeason, animate);
}
const environmentCurrent = {
sky: new THREE.Color(seasons[0].sky),
ground: new THREE.Color(seasons[0].ground),
board: new THREE.Color(seasons[0].board),
soil: new THREE.Color(seasons[0].soil),
accent: new THREE.Color(seasons[0].accent),
foliage: new THREE.Color(seasons[0].foliage),
sunlight: new THREE.Color(seasons[0].sunlight)
};
const environmentTarget = {
sky: new THREE.Color(),
ground: new THREE.Color(),
board: new THREE.Color(),
soil: new THREE.Color(),
accent: new THREE.Color(),
foliage: new THREE.Color(),
sunlight: new THREE.Color()
};
function setEnvironmentTarget(index) {
const season = seasons[index];
for (const key of Object.keys(environmentTarget)) {
environmentTarget[key].setHex(season[key]);
}
}
setEnvironmentTarget(0);
applySeason(0, false);
const particleCount = 170;
const particlePositions = new Float32Array(particleCount * 3);
const particleSpeeds = new Float32Array(particleCount);
const particleRandom = seededRandom(9912);
for (let index = 0; index < particleCount; index += 1) {
particlePositions[index * 3] = (particleRandom() - 0.5) * 22;
particlePositions[index * 3 + 1] = 0.5 + particleRandom() * 8;
particlePositions[index * 3 + 2] = (particleRandom() - 0.5) * 17;
particleSpeeds[index] = 0.45 + particleRandom() * 0.8;
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particleMaterial = new THREE.PointsMaterial({
color: seasons[0].particle,
size: 0.09,
transparent: true,
opacity: 0.68,
depthWrite: false,
sizeAttenuation: true
});
const particles = new THREE.Points(particleGeometry, particleMaterial);
scene.add(particles);
let autoRotate = false;
let rotationTimer = null;
function stopAutoRotate() {
autoRotate = false;
if (rotationTimer) {
clearInterval(rotationTimer);
rotationTimer = null;
}
playIcon.textContent = "▶";
playLabel.textContent = "Play rotation";
}
function startAutoRotate() {
autoRotate = true;
playIcon.textContent = "Ⅱ";
playLabel.textContent = "Pause rotation";
rotationTimer = setInterval(() => {
setSeason(currentSeason + 1);
}, 3600);
}
playButton.addEventListener("click", () => {
if (autoRotate) {
stopAutoRotate();
} else {
startAutoRotate();
}
});
cards.forEach((card, index) => {
card.addEventListener("click", () => {
stopAutoRotate();
setSeason(index);
});
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowRight") {
stopAutoRotate();
setSeason(currentSeason + 1);
} else if (event.key === "ArrowLeft") {
stopAutoRotate();
setSeason(currentSeason - 1);
} else if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
if (autoRotate) stopAutoRotate();
else startAutoRotate();
}
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const activePointers = new Map();
let activePointerId = null;
let dragDistance = 0;
let pinchDistance = 0;
function getPinchDistance() {
const points = [...activePointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
function selectFieldAt(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 intersections = raycaster.intersectObjects(fieldMeshes, false);
if (intersections.length) {
updateSelection(intersections[0].object.userData.fieldIndex);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
activePointerId = event.pointerId;
dragDistance = 0;
} else if (activePointers.size === 2) {
pinchDistance = getPinchDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = activePointers.get(event.pointerId);
if (!previous) return;
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (activePointers.size === 1 && event.pointerId === activePointerId) {
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.42,
1.34
);
dragDistance += Math.abs(deltaX) + Math.abs(deltaY);
updateCamera();
} else if (activePointers.size === 2) {
const nextPinchDistance = getPinchDistance();
if (pinchDistance > 0 && nextPinchDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (pinchDistance / nextPinchDistance),
12,
36
);
updateCamera();
}
pinchDistance = nextPinchDistance;
}
});
function endPointer(event) {
const wasClick =
activePointers.size === 1 &&
event.pointerId === activePointerId &&
dragDistance < 7;
activePointers.delete(event.pointerId);
if (wasClick) {
selectFieldAt(event.clientX, event.clientY);
}
if (activePointers.size === 1) {
activePointerId = [...activePointers.keys()][0];
} else if (activePointers.size === 0) {
activePointerId = null;
dragDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
12,
36
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.theta = 0.72;
orbit.phi = 0.91;
orbit.radius = window.innerWidth / window.innerHeight < 0.75
? 31
: 20.5;
updateCamera();
});
function updateEnvironment(delta) {
const amount = 1 - Math.exp(-delta * 2.6);
for (const key of Object.keys(environmentCurrent)) {
environmentCurrent[key].lerp(
environmentTarget[key],
amount
);
}
scene.background.copy(environmentCurrent.sky);
scene.fog.color.copy(environmentCurrent.sky);
groundMaterial.color.copy(environmentCurrent.ground);
boardMaterial.color.copy(environmentCurrent.board);
soilMaterial.color.copy(environmentCurrent.soil);
foliageMaterial.color.copy(environmentCurrent.foliage);
sunLight.color.copy(environmentCurrent.sunlight);
selectionMaterial.color.copy(environmentCurrent.accent);
}
function updateParticles(delta, elapsed) {
const mode = seasons[currentSeason].particleMode;
const positions = particleGeometry.attributes.position.array;
for (let index = 0; index < particleCount; index += 1) {
const offset = index * 3;
const speed = particleSpeeds[index];
if (mode === "pollen") {
positions[offset + 1] += delta * 0.22 * speed;
positions[offset] +=
Math.sin(elapsed * 0.7 + index) * delta * 0.055;
if (positions[offset + 1] > 8.5) {
positions[offset + 1] = 0.45;
}
} else if (mode === "fireflies") {
positions[offset] +=
Math.sin(elapsed * 0.65 + index * 2.1) * delta * 0.11;
positions[offset + 2] +=
Math.cos(elapsed * 0.52 + index * 1.7) * delta * 0.08;
positions[offset + 1] +=
Math.sin(elapsed * 1.1 + index) * delta * 0.025;
if (positions[offset + 1] < 0.4) positions[offset + 1] = 2.7;
if (positions[offset + 1] > 2.9) positions[offset + 1] = 0.4;
} else if (mode === "leaves") {
positions[offset + 1] -= delta * 0.48 * speed;
positions[offset] += delta * 0.17 * speed;
positions[offset + 2] +=
Math.sin(elapsed + index) * delta * 0.045;
if (positions[offset + 1] < 0.25) {
positions[offset + 1] = 8.5;
positions[offset] = (particleRandom() - 0.5) * 22;
positions[offset + 2] = (particleRandom() - 0.5) * 17;
}
} else {
positions[offset + 1] -= delta * 0.58 * speed;
positions[offset] += delta * 0.16 * speed;
positions[offset + 2] +=
Math.sin(elapsed * 0.8 + index) * delta * 0.025;
if (positions[offset + 1] < 0.15) {
positions[offset + 1] = 8.8;
positions[offset] = (particleRandom() - 0.5) * 22;
positions[offset + 2] = (particleRandom() - 0.5) * 17;
}
}
}
particleGeometry.attributes.position.needsUpdate = true;
particleMaterial.color.setHex(seasons[currentSeason].particle);
particleMaterial.size =
mode === "snow" ? 0.11 : mode === "fireflies" ? 0.075 : 0.085;
particleMaterial.opacity =
mode === "fireflies" ? 0.48 : mode === "snow" ? 0.82 : 0.62;
}
function updateTransitions(delta) {
for (let index = transitionList.length - 1; index >= 0; index -= 1) {
const transition = transitionList[index];
transition.time += delta;
const progress = Math.min(
1,
transition.time / transition.duration
);
if (transition.outgoing) {
const eased = 1 - Math.pow(1 - progress, 2);
transition.group.scale.y = Math.max(
0.01,
transition.startScale * (1 - eased)
);
transition.group.position.y = 0.39 + eased * 0.1;
} else {
const eased = 1 - Math.pow(1 - progress, 3);
transition.group.scale.y = 0.015 + eased * 0.985;
transition.group.scale.x = 0.98 + eased * 0.02;
transition.group.scale.z = 0.98 + eased * 0.02;
transition.group.position.y = 0.39 + (1 - eased) * 0.12;
}
if (progress >= 1) {
if (transition.outgoing) {
removeCropGroup(transition.group);
}
transitionList.splice(index, 1);
}
}
}
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
updateEnvironment(delta);
updateParticles(delta, elapsed);
updateTransitions(delta);
selectionMaterial.opacity = 0.78 + Math.sin(elapsed * 2.2) * 0.15;
selectionFrame.position.y =
Math.sin(elapsed * 1.8) * 0.012;
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
});
</script>
</body>
</html>
```