Prompt specification
Build or customize the Three.js 3D scene "Orchard floor management mosaic" 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: Orchard floor management mosaic
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/orchard-floor-management-mosaic-x1087
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing mulch cover. Build a small orchard patch with mulched tree circles, grass paths, and bare demonstration soil; a weather control reveals distinct surface exposure without claiming exact moisture savings. Voxel style.
Working Three.js Starter (orchard-floor-management-mosaic-x1087):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="An interactive voxel orchard demonstrating how mulch, grass paths, and bare soil differ in surface exposure during dry and rainy weather."
/>
<title>Mulch Field Study — Voxel Orchard</title>
<style>
:root {
--ink: #17352b;
--muted: #62756c;
--panel: rgba(250, 248, 238, 0.93);
--line: rgba(35, 67, 53, 0.16);
--green: #2f684b;
--mulch: #a66b38;
--soil: #74503d;
--blue: #4e7892;
--shadow: 0 18px 50px rgba(39, 64, 48, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9dd;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene.dragging {
cursor: grabbing;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
z-index: 4;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: #426655;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
content: "";
background: var(--mulch);
box-shadow:
13px 0 0 #6e9561,
26px 0 0 #466e4d;
margin-right: 26px;
}
h1 {
margin: 0;
max-width: 440px;
font-size: clamp(27px, 3vw, 44px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 850;
}
.brand p {
max-width: 390px;
margin: 11px 0 0;
color: #4f6c5e;
font-size: 13px;
line-height: 1.5;
}
.panel {
position: absolute;
top: 24px;
right: 24px;
z-index: 5;
width: min(346px, calc(100vw - 48px));
padding: 19px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 19px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(15px) saturate(1.1);
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
margin-bottom: 17px;
}
.panel h2 {
margin: 0 0 3px;
font-size: 16px;
line-height: 1.2;
letter-spacing: -0.02em;
}
.panel-kicker {
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.weather-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(44, 80, 61, 0.055);
}
.weather-button {
min-height: 42px;
padding: 9px 11px;
border: 0;
border-radius: 9px;
color: #587064;
background: transparent;
cursor: pointer;
font-size: 12px;
font-weight: 800;
transition:
color 160ms ease,
background 160ms ease,
box-shadow 160ms ease,
transform 160ms ease;
}
.weather-button:hover {
color: var(--ink);
}
.weather-button:active {
transform: translateY(1px);
}
.weather-button[aria-pressed="true"] {
color: #fffdf5;
background: var(--green);
box-shadow: 0 5px 13px rgba(47, 104, 75, 0.22);
}
.weather-icon {
display: inline-block;
margin-right: 6px;
font-size: 14px;
vertical-align: -1px;
}
.weather-status {
display: flex;
align-items: center;
gap: 8px;
min-height: 35px;
padding: 10px 1px 7px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.status-dot {
flex: 0 0 auto;
width: 8px;
height: 8px;
border-radius: 50%;
background: #d5a84c;
box-shadow: 0 0 0 4px rgba(213, 168, 76, 0.14);
transition: background 200ms ease, box-shadow 200ms ease;
}
body[data-weather="rain"] .status-dot {
background: #5d8ba7;
box-shadow: 0 0 0 4px rgba(93, 139, 167, 0.15);
}
.exposure {
margin-top: 8px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.section-label {
margin-bottom: 10px;
color: #7b8c83;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.exposure-row {
display: grid;
grid-template-columns: 29px 1fr auto;
align-items: center;
gap: 10px;
min-height: 45px;
padding: 6px 0;
}
.swatch {
position: relative;
width: 29px;
height: 29px;
border: 1px solid rgba(45, 64, 51, 0.12);
border-radius: 8px;
overflow: hidden;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}
.swatch.mulch {
background:
linear-gradient(27deg, transparent 40%, #6f4128 42% 55%, transparent 57%),
linear-gradient(145deg, #c58b52, #9b6035);
}
.swatch.grass {
background:
repeating-linear-gradient(
80deg,
#71955e 0 4px,
#567d4e 4px 8px
);
}
.swatch.soil {
background:
linear-gradient(15deg, transparent 46%, #4c3329 48% 58%, transparent 60%),
#79523b;
}
.exposure-name {
color: #334d40;
font-size: 12px;
font-weight: 760;
}
.exposure-detail {
margin-top: 2px;
color: #788980;
font-size: 10px;
}
.exposure-state {
padding: 5px 7px;
border-radius: 999px;
color: #425c4d;
background: rgba(47, 104, 75, 0.08);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.025em;
white-space: nowrap;
transition:
color 220ms ease,
background 220ms ease;
}
.exposure-row.partial .exposure-state {
color: #7a6331;
background: rgba(159, 122, 46, 0.11);
}
.exposure-row.open .exposure-state {
color: #79523c;
background: rgba(121, 82, 59, 0.12);
}
.note {
margin: 12px 0 0;
padding: 10px 11px;
border: 1px solid rgba(60, 92, 74, 0.1);
border-radius: 10px;
color: #6d7e75;
background: rgba(55, 87, 69, 0.045);
font-size: 10px;
line-height: 1.45;
}
.note strong {
color: #4f685b;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
z-index: 3;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 999px;
color: #26463a;
background: rgba(251, 249, 240, 0.94);
box-shadow: 0 8px 22px rgba(36, 65, 49, 0.15);
font-size: 10px;
font-weight: 850;
white-space: nowrap;
pointer-events: none;
opacity: 0;
transform: translate(-50%, -50%);
transition: opacity 120ms linear;
}
.scene-label::before {
width: 8px;
height: 8px;
content: "";
border-radius: 50%;
background: var(--mulch);
}
.scene-label.grass::before {
background: #638e56;
}
.scene-label.soil::before {
background: #76503c;
}
.scene-label small {
color: #74847b;
font-size: 9px;
font-weight: 650;
}
.tooltip {
position: absolute;
z-index: 8;
max-width: 220px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 9px;
color: #f8f5e9;
background: rgba(25, 51, 40, 0.92);
box-shadow: 0 9px 25px rgba(25, 51, 40, 0.2);
font-size: 11px;
line-height: 1.45;
pointer-events: none;
opacity: 0;
transform: translateY(4px);
transition:
opacity 100ms ease,
transform 100ms ease;
}
.tooltip.visible {
opacity: 1;
transform: translateY(0);
}
.tooltip strong {
display: block;
margin-bottom: 2px;
color: #ffffff;
font-size: 11px;
}
.controls-help {
position: absolute;
bottom: 22px;
left: 25px;
z-index: 4;
display: flex;
align-items: center;
gap: 9px;
color: #496658;
font-size: 10px;
font-weight: 720;
letter-spacing: 0.01em;
pointer-events: none;
}
.controls-help .mouse {
position: relative;
width: 16px;
height: 23px;
border: 2px solid #567765;
border-radius: 8px;
}
.controls-help .mouse::after {
position: absolute;
top: 4px;
left: 5px;
width: 2px;
height: 5px;
content: "";
border-radius: 2px;
background: #567765;
}
.reset-button {
position: absolute;
right: 24px;
bottom: 22px;
z-index: 5;
min-height: 36px;
padding: 8px 12px;
border: 1px solid rgba(43, 79, 60, 0.14);
border-radius: 10px;
color: #315844;
background: rgba(250, 248, 238, 0.82);
box-shadow: 0 8px 25px rgba(39, 64, 48, 0.1);
cursor: pointer;
font-size: 10px;
font-weight: 800;
backdrop-filter: blur(10px);
}
.reset-button:hover {
background: rgba(255, 254, 248, 0.96);
}
.loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #496658;
background: #dce9dd;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 17px;
}
.brand p {
display: none;
}
h1 {
max-width: 260px;
font-size: 28px;
}
.panel {
top: auto;
right: 12px;
bottom: 57px;
left: 12px;
width: auto;
padding: 14px;
border-radius: 16px;
}
.panel-head {
margin-bottom: 10px;
}
.weather-status {
min-height: 28px;
padding: 7px 1px 4px;
}
.exposure {
margin-top: 3px;
padding-top: 8px;
}
.exposure-row {
min-height: 39px;
padding: 3px 0;
}
.swatch {
width: 25px;
height: 25px;
}
.exposure-detail,
.note {
display: none;
}
.controls-help {
bottom: 18px;
left: 16px;
}
.reset-button {
right: 12px;
bottom: 14px;
}
.scene-label {
padding: 5px 7px;
font-size: 9px;
}
.scene-label small {
display: none;
}
}
</style>
</head>
<body data-weather="sunny">
<main id="app">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel orchard with mulched tree circles, grass paths, and a bare soil demonstration bed"
></canvas>
<header class="brand">
<div class="eyebrow">Mulch field study</div>
<h1>See what the surface covers.</h1>
<p>
A small voxel orchard comparing mulch, grass paths, and open soil in
different weather.
</p>
</header>
<aside class="panel" aria-label="Weather and surface exposure controls">
<div class="panel-head">
<div>
<h2>Weather lens</h2>
<div class="panel-kicker">Switch conditions to compare visible surface coverage.</div>
</div>
</div>
<div class="weather-switch" role="group" aria-label="Weather condition">
<button
class="weather-button"
type="button"
data-weather="sunny"
aria-pressed="true"
>
<span class="weather-icon" aria-hidden="true">☀</span>Sunny
</button>
<button
class="weather-button"
type="button"
data-weather="rain"
aria-pressed="false"
>
<span class="weather-icon" aria-hidden="true">☂</span>Rain
</button>
</div>
<div class="weather-status" aria-live="polite">
<span class="status-dot"></span>
<span id="weather-status-text">Dry-surface view</span>
</div>
<section class="exposure" aria-label="Qualitative surface exposure comparison">
<div class="section-label">Relative surface exposure</div>
<div class="exposure-row">
<span class="swatch mulch" aria-hidden="true"></span>
<div>
<div class="exposure-name">Mulch circle</div>
<div class="exposure-detail">Loose cover over tree soil</div>
</div>
<span class="exposure-state">Covered</span>
</div>
<div class="exposure-row partial">
<span class="swatch grass" aria-hidden="true"></span>
<div>
<div class="exposure-name">Grass path</div>
<div class="exposure-detail">Vegetation with partial soil contact</div>
</div>
<span class="exposure-state">Partly covered</span>
</div>
<div class="exposure-row open">
<span class="swatch soil" aria-hidden="true"></span>
<div>
<div class="exposure-name">Bare demonstration soil</div>
<div class="exposure-detail">Open surface without cover</div>
</div>
<span class="exposure-state">Exposed</span>
</div>
</section>
<p class="note">
<strong>Qualitative illustration only.</strong>
Rain darkens open soil more strongly to make relative surface exposure
easier to see. This is not a moisture measurement or savings estimate.
</p>
</aside>
<div class="scene-label mulch" id="label-mulch">
Mulch <small>covered</small>
</div>
<div class="scene-label grass" id="label-grass">
Grass path <small>partly covered</small>
</div>
<div class="scene-label soil" id="label-soil">
Bare soil <small>exposed</small>
</div>
<div class="tooltip" id="tooltip" role="status"></div>
<div class="controls-help" aria-hidden="true">
<span class="mouse"></span>
Drag to orbit · Scroll to zoom · Hover a surface
</div>
<button class="reset-button" id="reset-view" type="button">
Reset view
</button>
<div class="loading" id="loading">Building orchard…</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Setup
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const tooltip = document.querySelector("#tooltip");
const weatherStatus = document.querySelector("#weather-status-text");
const weatherButtons = [...document.querySelectorAll(".weather-button")];
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
const sunnySky = new THREE.Color("#dce9dd");
const rainySky = new THREE.Color("#aebfca");
scene.background = sunnySky.clone();
scene.fog = new THREE.Fog(sunnySky.clone(), 30, 56);
const camera = new THREE.OrthographicCamera(-12, 12, 8, -8, 0.1, 100);
const target = new THREE.Vector3(0, 1.25, 0);
const spherical = new THREE.Spherical(25, 0.88, 0.72);
let cameraZoom = 1;
const hemisphere = new THREE.HemisphereLight("#eff8e9", "#6d5138", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cd", 3.15);
sun.position.set(-8, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9d8e5", 0.65);
fill.position.set(10, 7, -8);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, roughness = 0.94) {
const key = `${color}-${roughness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(unitBox, material(color, options.roughness ?? 0.94));
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(size[0], size[1], size[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
// Deterministic pseudo-randomness keeps the orchard stable between reloads.
function mulberry32(seed) {
return function random() {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(48291);
function randomBetween(min, max) {
return min + (max - min) * random();
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
// ---------------------------------------------------------------------
// Orchard terrain
// ---------------------------------------------------------------------
const orchard = new THREE.Group();
scene.add(orchard);
// Raised soil slab under the individual voxel tiles.
addBox(
orchard,
[16.85, 0.72, 12.85],
[0, -0.43, 0],
"#634332"
);
addBox(
orchard,
[16.35, 0.13, 12.35],
[0, -0.02, 0],
"#6f5037"
);
const treePositions = [
[-5, -3],
[-1, -3],
[3, -3],
[-5, 2],
[-1, 2],
[3, 2]
];
const tiles = [];
const tileGeometry = new THREE.BoxGeometry(0.97, 0.18, 0.97);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const terrain = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
16 * 12
);
terrain.receiveShadow = true;
terrain.castShadow = false;
orchard.add(terrain);
const dummy = new THREE.Object3D();
const baseColors = {
grass: ["#668451", "#6c8d55", "#5f7e4c", "#75935a"],
path: ["#8aa66a", "#93ad73", "#82a066", "#9ab278"],
mulch: ["#9b6339", "#a96e3d", "#8e5734", "#b07843"],
soil: ["#76503b", "#805842", "#6d4937", "#875c42"]
};
let tileIndex = 0;
for (let z = -6; z <= 5; z++) {
for (let x = -8; x <= 7; x++) {
let category = "grass";
const nearTree = treePositions.some(([tx, tz]) => {
const dx = x - tx;
const dz = z - tz;
return Math.sqrt(dx * dx + dz * dz) <= 1.48;
});
const isPath = z === 0 || x === 1 || x === 7;
const isBareBed = x >= 5 && z >= 1 && z <= 5;
if (nearTree) category = "mulch";
else if (isPath) category = "path";
else if (isBareBed) category = "soil";
const color = new THREE.Color(
choose(baseColors[category])
);
// Slight per-tile shade variation reinforces the voxel/grid style.
color.offsetHSL(
randomBetween(-0.012, 0.012),
randomBetween(-0.025, 0.025),
randomBetween(-0.025, 0.025)
);
const height = category === "soil" ? 0.14 : 0.18;
dummy.position.set(x, height * 0.5 - 0.02, z);
dummy.scale.set(1, height / 0.18, 1);
dummy.updateMatrix();
terrain.setMatrixAt(tileIndex, dummy.matrix);
terrain.setColorAt(tileIndex, color);
tiles.push({
index: tileIndex,
x,
z,
category,
baseColor: color
});
tileIndex++;
}
}
terrain.instanceMatrix.needsUpdate = true;
terrain.instanceColor.needsUpdate = true;
// ---------------------------------------------------------------------
// Mulch chips, grass tufts, and bare-soil detail
// ---------------------------------------------------------------------
const detail = new THREE.Group();
orchard.add(detail);
const mulchChipColors = ["#bd7c43", "#95572f", "#c58b50", "#a76838"];
const grassColors = ["#88a66a", "#6f9258", "#9bb579"];
const soilColors = ["#5f4132", "#8a6044", "#6b4836"];
for (const tile of tiles) {
if (tile.category === "mulch") {
const centerIsTrunk = treePositions.some(
([tx, tz]) =>
Math.abs(tile.x - tx) < 0.35 &&
Math.abs(tile.z - tz) < 0.35
);
if (!centerIsTrunk) {
const count = 3 + Math.floor(random() * 3);
for (let i = 0; i < count; i++) {
const chip = addBox(
detail,
[
randomBetween(0.17, 0.38),
randomBetween(0.055, 0.105),
randomBetween(0.12, 0.3)
],
[
tile.x + randomBetween(-0.42, 0.42),
0.115 + randomBetween(0, 0.035),
tile.z + randomBetween(-0.42, 0.42)
],
choose(mulchChipColors),
{ roughness: 1 }
);
chip.rotation.y = randomBetween(-0.55, 0.55);
}
}
}
if (tile.category === "path") {
const count = 2 + Math.floor(random() * 3);
for (let i = 0; i < count; i++) {
const blade = addBox(
detail,
[
randomBetween(0.045, 0.075),
randomBetween(0.13, 0.25),
randomBetween(0.045, 0.075)
],
[
tile.x + randomBetween(-0.38, 0.38),
0.19,
tile.z + randomBetween(-0.38, 0.38)
],
choose(grassColors),
{ castShadow: false }
);
blade.rotation.y = randomBetween(-0.35, 0.35);
}
}
if (tile.category === "soil") {
if (random() > 0.3) {
const clod = addBox(
detail,
[
randomBetween(0.08, 0.19),
randomBetween(0.05, 0.09),
randomBetween(0.08, 0.17)
],
[
tile.x + randomBetween(-0.34, 0.34),
0.125,
tile.z + randomBetween(-0.34, 0.34)
],
choose(soilColors),
{ castShadow: false }
);
clod.rotation.y = randomBetween(0, Math.PI);
}
}
if (tile.category === "grass" && random() > 0.68) {
const tuft = addBox(
detail,
[0.055, randomBetween(0.11, 0.2), 0.055],
[
tile.x + randomBetween(-0.35, 0.35),
0.16,
tile.z + randomBetween(-0.35, 0.35)
],
choose(grassColors),
{ castShadow: false }
);
tuft.rotation.y = randomBetween(-0.4, 0.4);
}
}
// Raised furrows make the demonstration bed read as intentionally bare.
for (const x of [5.28, 6.28, 7.28]) {
addBox(
detail,
[0.09, 0.055, 4.65],
[x, 0.125, 3],
"#5c3f31",
{ castShadow: false }
);
addBox(
detail,
[0.065, 0.025, 4.55],
[x - 0.07, 0.155, 3],
"#8b6044",
{ castShadow: false }
);
}
// Small voxel edging around the bare demonstration plot.
for (let z = 1; z <= 5; z++) {
addBox(
detail,
[0.13, 0.18, 0.13],
[4.83, 0.14, z],
"#8b6847"
);
}
for (let x = 5; x <= 7; x++) {
addBox(
detail,
[0.13, 0.18, 0.13],
[x, 0.14, 0.83],
"#8b6847"
);
}
// ---------------------------------------------------------------------
// Voxel trees
// ---------------------------------------------------------------------
const trunkColors = ["#68402d", "#744831", "#5f3928"];
const leafColors = [
"#315f3e",
"#3c7046",
"#477b4d",
"#2f5938",
"#527f50",
"#638b55"
];
const fruitColors = ["#d9782e", "#e48b35", "#c96729"];
function createTree(x, z, index) {
const tree = new THREE.Group();
tree.position.set(x, 0.08, z);
orchard.add(tree);
const trunkColor = trunkColors[index % trunkColors.length];
const height = 2.38 + (index % 3) * 0.08;
// Stacked trunk blocks.
for (let i = 0; i < 6; i++) {
const width = i < 2 ? 0.44 : 0.38;
addBox(
tree,
[width, 0.42, width],
[0, 0.2 + i * 0.4, 0],
i % 2 ? trunkColor : trunkColors[(index + 1) % trunkColors.length]
);
}
// Blocky branches.
addBox(tree, [0.95, 0.27, 0.29], [0.37, height, 0.02], trunkColor);
addBox(tree, [0.28, 0.27, 0.86], [-0.08, height - 0.13, 0.34], trunkColor);
addBox(tree, [0.7, 0.24, 0.25], [-0.36, height - 0.37, -0.18], trunkColor);
const offsets = [
[-0.78, 0.03, -0.48],
[-0.38, 0.05, -0.68],
[0.08, 0.02, -0.72],
[0.55, 0.04, -0.47],
[0.82, 0.02, 0.03],
[0.58, 0.08, 0.48],
[0.15, 0.02, 0.65],
[-0.38, 0.06, 0.55],
[-0.78, 0.07, 0.18],
[-0.55, 0.54, -0.35],
[-0.12, 0.58, -0.5],
[0.36, 0.55, -0.37],
[0.61, 0.53, 0.02],
[0.33, 0.58, 0.4],
[-0.15, 0.6, 0.48],
[-0.55, 0.52, 0.29],
[-0.25, 1.02, -0.1],
[0.25, 1.03, -0.12],
[0, 1.1, 0.26],
[-0.38, 1.0, 0.18],
[0.43, 0.98, 0.18]
];
offsets.forEach(([ox, oy, oz], i) => {
const size = randomBetween(0.65, 0.92);
addBox(
tree,
[size, size * randomBetween(0.78, 1.02), size],
[ox, height + 0.52 + oy, oz],
choose(leafColors)
);
// Sparse voxel fruit.
if (i % 7 === 2 || (index % 2 === 0 && i === 14)) {
addBox(
tree,
[0.13, 0.13, 0.13],
[ox + 0.3, height + 0.42 + oy, oz + 0.3],
choose(fruitColors),
{ roughness: 0.7 }
);
}
});
return tree;
}
treePositions.forEach(([x, z], index) => createTree(x, z, index));
// ---------------------------------------------------------------------
// Rear voxel fence
// ---------------------------------------------------------------------
const fence = new THREE.Group();
orchard.add(fence);
for (let x = -8; x <= 8; x += 2) {
addBox(fence, [0.18, 1.25, 0.18], [x, 0.63, -6.18], "#79523a");
addBox(fence, [0.23, 0.13, 0.23], [x, 1.22, -6.18], "#916848");
}
addBox(fence, [16.4, 0.14, 0.14], [0, 0.92, -6.18], "#81593e");
addBox(fence, [16.4, 0.14, 0.14], [0, 0.46, -6.18], "#81593e");
// ---------------------------------------------------------------------
// Rain particles
// ---------------------------------------------------------------------
const dropCount = 520;
const rainPositions = new Float32Array(dropCount * 6);
const rainData = [];
for (let i = 0; i < dropCount; i++) {
rainData.push({
x: randomBetween(-11, 11),
y: randomBetween(0, 14),
z: randomBetween(-8, 8),
speed: randomBetween(7, 11)
});
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
const rainMaterial = new THREE.LineBasicMaterial({
color: "#d4ebf5",
transparent: true,
opacity: 0,
depthWrite: false
});
const rainLines = new THREE.LineSegments(rainGeometry, rainMaterial);
rainLines.frustumCulled = false;
rainLines.visible = false;
scene.add(rainLines);
function updateRain(dt) {
if (rainAmount <= 0.001) {
rainLines.visible = false;
return;
}
rainLines.visible = true;
rainMaterial.opacity = 0.48 * rainAmount;
for (let i = 0; i < dropCount; i++) {
const drop = rainData[i];
drop.y -= drop.speed * dt;
if (drop.y < -0.2) {
drop.y = randomBetween(10, 15);
drop.x = randomBetween(-11, 11);
drop.z = randomBetween(-8, 8);
}
const p = i * 6;
rainPositions[p] = drop.x;
rainPositions[p + 1] = drop.y;
rainPositions[p + 2] = drop.z;
rainPositions[p + 3] = drop.x + 0.07;
rainPositions[p + 4] = drop.y + 0.42;
rainPositions[p + 5] = drop.z;
}
rainGeometry.attributes.position.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Weather control and surface exposure coloring
// ---------------------------------------------------------------------
let targetRain = 0;
let rainAmount = 0;
const wetTint = new THREE.Color("#244c61");
const tempColor = new THREE.Color();
function setWeather(weather) {
targetRain = weather === "rain" ? 1 : 0;
document.body.dataset.weather = weather;
weatherButtons.forEach((button) => {
const active = button.dataset.weather === weather;
button.setAttribute("aria-pressed", String(active));
});
weatherStatus.textContent =
weather === "rain"
? "Rain-surface view"
: "Dry-surface view";
}
weatherButtons.forEach((button) => {
button.addEventListener("click", () => {
setWeather(button.dataset.weather);
});
});
function updateWeather(dt) {
const smoothing = 1 - Math.exp(-dt * 3.4);
rainAmount += (targetRain - rainAmount) * smoothing;
scene.background.lerpColors(sunnySky, rainySky, rainAmount);
scene.fog.color.copy(scene.background);
hemisphere.intensity = THREE.MathUtils.lerp(
2.15,
1.32,
rainAmount
);
sun.intensity = THREE.MathUtils.lerp(3.15, 1.22, rainAmount);
fill.intensity = THREE.MathUtils.lerp(0.65, 1.0, rainAmount);
renderer.toneMappingExposure = THREE.MathUtils.lerp(
1.08,
0.88,
rainAmount
);
// Open soil darkens more than mulch or vegetation-covered surfaces.
for (const tile of tiles) {
const wetFactor =
tile.category === "soil"
? 0.34
: tile.category === "path"
? 0.18
: tile.category === "mulch"
? 0.12
: 0.13;
tempColor
.copy(tile.baseColor)
.lerp(wetTint, rainAmount * wetFactor);
terrain.setColorAt(tile.index, tempColor);
}
terrain.instanceColor.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Camera controls implemented directly with pointer events
// ---------------------------------------------------------------------
let dragging = false;
let dragMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
camera.updateProjectionMatrix();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
tooltip.classList.remove("visible");
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 1) dragMoved = true;
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi + dy * 0.0045,
0.48,
1.2
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
return;
}
updateHover(event);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.75
);
resize();
},
{ passive: false }
);
document.querySelector("#reset-view").addEventListener("click", () => {
spherical.set(25, 0.88, 0.72);
cameraZoom = 1;
target.set(0, 1.25, 0);
updateCamera();
resize();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
const viewHeight = aspect < 0.9 ? 18 / aspect : 15;
const viewWidth = viewHeight * aspect;
camera.left = -viewWidth / 2;
camera.right = viewWidth / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = cameraZoom;
updateCamera();
}
window.addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Hover inspection
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const hoverCopy = {
mulch: {
title: "Mulch-covered circle",
body: "A loose layer covers most of the soil around this tree."
},
path: {
title: "Grass path",
body: "Low vegetation covers parts of the path while some soil remains visible."
},
soil: {
title: "Bare demonstration soil",
body: "This plot is intentionally left uncovered for comparison."
},
grass: {
title: "Orchard floor",
body: "Low ground cover surrounds the planted rows."
}
};
function updateHover(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObject(terrain, false)[0];
if (!hit || hit.instanceId === undefined) {
tooltip.classList.remove("visible");
canvas.style.cursor = "grab";
return;
}
const tile = tiles[hit.instanceId];
const copy = hoverCopy[tile.category];
tooltip.innerHTML = `
<strong>${copy.title}</strong>
${copy.body}
`;
const panelWidth = window.innerWidth > 760 ? 370 : window.innerWidth;
let x = event.clientX + 15;
let y = event.clientY + 15;
if (x + 230 > window.innerWidth) x = event.clientX - 235;
if (y + 90 > window.innerHeight) y = event.clientY - 90;
tooltip.style.left = `${Math.max(8, x)}px`;
tooltip.style.top = `${Math.max(8, y)}px`;
tooltip.classList.add("visible");
canvas.style.cursor = "pointer";
}
canvas.addEventListener("pointerleave", () => {
tooltip.classList.remove("visible");
});
// ---------------------------------------------------------------------
// Rain-view labels projected into the scene
// ---------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#label-mulch"),
point: new THREE.Vector3(-5, 0.45, -1.35)
},
{
element: document.querySelector("#label-grass"),
point: new THREE.Vector3(1, 0.42, 0)
},
{
element: document.querySelector("#label-soil"),
point: new THREE.Vector3(6.15, 0.42, 3.45)
}
];
const projected = new THREE.Vector3();
function positionLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.point).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity =
projected.z > -1 && projected.z < 1
? String(Math.min(1, rainAmount * 1.5))
: "0";
}
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
updateWeather(dt);
updateRain(dt);
positionLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
updateCamera();
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```