Prompt specification
Build or customize the Three.js 3D scene "Road access beside farmland parcels" 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: Road access beside farmland parcels
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/road-access-beside-farmland-parcels-x1310
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows land-use mosaics. Arrange fields around a road and loading point. Show harvest carts using entrances and paths while keeping cultivated strips clear of vehicle shortcuts through crops. A 3D cutaway view.
Working Three.js Starter (road-access-beside-farmland-parcels-x1310):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Land-Use Mosaic — 3D Agricultural Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #101820;
--panel: rgba(15, 24, 31, 0.88);
--line: rgba(184, 217, 220, 0.16);
--text: #edf5f2;
--muted: #9eb0b2;
--cyan: #5ce4cf;
--gold: #e4bc64;
--orange: #f18b49;
--green: #8fc58f;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 64% 24%, #243743 0%, transparent 42%),
linear-gradient(145deg, #111a21, #080e13 78%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
button {
font: inherit;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
pointer-events: auto;
position: absolute;
top: 20px;
left: 20px;
width: 322px;
padding: 18px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
}
.eyebrow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: #b7d9c7;
letter-spacing: 0.08em;
}
.live::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
content: "";
}
h1 {
margin: 0;
font-size: 25px;
font-weight: 650;
line-height: 1.06;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 11px;
border: 1px solid rgba(92, 228, 207, 0.22);
border-radius: 10px;
background: rgba(92, 228, 207, 0.07);
color: #d7f5ee;
font-size: 11px;
}
.status strong {
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.09em;
}
.section-title {
margin: 16px 0 8px;
color: #7f9698;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.toggle-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.toggle,
.view-button {
min-height: 34px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: #aab9ba;
cursor: pointer;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.055em;
transition: 160ms ease;
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
padding: 0 9px;
text-align: left;
}
.toggle::before {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: #546163;
content: "";
}
.toggle.active {
border-color: rgba(92, 228, 207, 0.34);
background: rgba(92, 228, 207, 0.08);
color: #d7f2ed;
}
.toggle.active::before {
background: var(--cyan);
box-shadow: 0 0 9px rgba(92, 228, 207, 0.65);
}
.toggle:hover,
.view-button:hover {
border-color: rgba(92, 228, 207, 0.4);
color: white;
}
.inspector {
margin-top: 14px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.inspector-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.inspector-head strong {
font-size: 12px;
letter-spacing: 0.03em;
}
.chip {
padding: 4px 6px;
border-radius: 5px;
background: rgba(228, 188, 100, 0.12);
color: var(--gold);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
}
.inspector p {
margin: 7px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.viewbar {
pointer-events: auto;
position: absolute;
top: 20px;
right: 20px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
backdrop-filter: blur(16px);
}
.view-button {
min-height: 32px;
padding: 0 11px;
}
.view-button.active {
border-color: rgba(92, 228, 207, 0.34);
background: rgba(92, 228, 207, 0.08);
color: var(--cyan);
}
.legend {
pointer-events: auto;
position: absolute;
bottom: 20px;
left: 20px;
width: 235px;
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(16px);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0;
color: #b5c2c2;
font-size: 10px;
}
.swatch {
width: 16px;
height: 8px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--swatch);
}
.route-swatch {
width: 19px;
height: 0;
border-top: 3px dashed var(--cyan);
}
.hint {
position: absolute;
bottom: 21px;
left: 50%;
transform: translateX(-50%);
color: rgba(207, 222, 220, 0.58);
font-size: 10px;
letter-spacing: 0.035em;
white-space: nowrap;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
top: 0;
left: 0;
padding: 5px 7px;
border: 1px solid rgba(226, 239, 235, 0.15);
border-left: 3px solid var(--label-color, #d8bc6a);
border-radius: 5px;
background: rgba(14, 23, 29, 0.78);
box-shadow: 0 5px 16px rgba(0, 0, 0, 0.2);
color: #e9f1ef;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
white-space: nowrap;
will-change: transform;
}
.world-label small {
display: block;
margin-top: 2px;
color: #9aadae;
font-size: 7px;
font-weight: 600;
letter-spacing: 0.055em;
}
.world-label.loading {
border-color: rgba(92, 228, 207, 0.32);
background: rgba(16, 45, 43, 0.84);
}
.world-label.section {
border-color: rgba(228, 188, 100, 0.35);
color: #f1d89c;
}
@media (max-width: 760px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
max-width: 310px;
padding: 13px;
}
h1 { font-size: 20px; }
.subtitle { margin-bottom: 10px; }
.legend, .hint { display: none; }
.viewbar {
top: auto;
right: 10px;
bottom: 10px;
}
.toggle-grid { grid-template-columns: repeat(4, 1fr); }
.toggle { justify-content: center; padding: 0 5px; font-size: 8px; }
.toggle::before { display: none; }
}
</style>
</head>
<body>
<div id="labels"></div>
<div id="ui">
<section class="panel">
<div class="eyebrow">
<span>Terrain / 07</span>
<span class="live">Operational model</span>
</div>
<h1>Land-use mosaic</h1>
<p class="subtitle">
Harvest circulation through entrances, protected crop lanes and the central haul road.
</p>
<div class="status">
<span>Traffic conflict</span>
<strong>NONE DETECTED</strong>
</div>
<div class="section-title">Display layers</div>
<div class="toggle-grid">
<button class="toggle active" data-toggle="fields" aria-pressed="true">Mosaic</button>
<button class="toggle active" data-toggle="routes" aria-pressed="true">Routes</button>
<button class="toggle active" data-toggle="carts" aria-pressed="true">Carts</button>
<button class="toggle active" data-toggle="section" aria-pressed="true">Section</button>
</div>
<div class="inspector">
<div class="inspector-head">
<strong id="inspector-title">N2 · WHEAT</strong>
<span class="chip" id="inspector-chip">ACTIVE</span>
</div>
<p id="inspector-text"></p>
</div>
</section>
<nav class="viewbar" aria-label="Camera views">
<button class="view-button active" data-view="iso">ISOMETRIC</button>
<button class="view-button" data-view="top">PLAN</button>
<button class="view-button" data-view="section">SECTION</button>
<button class="view-button" id="pause">PAUSE</button>
</nav>
<aside class="legend">
<div class="section-title" style="margin-top:0">Map key</div>
<div class="legend-row"><span class="swatch" style="--swatch:#d8bc6a"></span>Cultivated strips</div>
<div class="legend-row"><span class="swatch" style="--swatch:#637e59"></span>Pasture / orchard</div>
<div class="legend-row"><span class="route-swatch"></span>Designated cart route</div>
<div class="legend-row"><span class="swatch" style="--swatch:#4d5559"></span>Haul road / entrances</div>
<div class="legend-row"><span class="swatch" style="--swatch:#9b6f4d"></span>Exposed soil profile</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Select a parcel for access details</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera and custom orbit controls
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101820);
scene.fog = new THREE.Fog(0x101820, 128, 220);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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.13;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-50, 50, 32, -32, 0.1, 350);
const orbit = {
target: new THREE.Vector3(0, -1, 0),
radius: 108,
theta: 0.72,
phi: 0.92,
zoom: 1
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const w = window.innerWidth;
const h = window.innerHeight;
const aspect = w / h;
const viewHeight = Math.max(64, 88 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(w, h);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemi = new THREE.HemisphereLight(0xcbe9ff, 0x33402f, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe6bd, 3.0);
sun.position.set(-35, 65, 45);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -75;
sun.shadow.camera.right = 75;
sun.shadow.camera.top = 75;
sun.shadow.camera.bottom = -75;
sun.shadow.camera.near = 5;
sun.shadow.camera.far = 160;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x86bfd2, 0.9);
fill.position.set(50, 25, -45);
scene.add(fill);
// -------------------------------------------------------------------------
// Scene groups
// -------------------------------------------------------------------------
const world = new THREE.Group();
const fieldsGroup = new THREE.Group();
const routeGroup = new THREE.Group();
const cartGroup = new THREE.Group();
const sectionOverlay = new THREE.Group();
world.add(fieldsGroup, routeGroup, cartGroup, sectionOverlay);
scene.add(world);
const shadowGround = new THREE.Mesh(
new THREE.PlaneGeometry(260, 260),
new THREE.MeshStandardMaterial({ color: 0x0d151b, roughness: 1 })
);
shadowGround.rotation.x = -Math.PI / 2;
shadowGround.position.y = -5.28;
shadowGround.receiveShadow = true;
scene.add(shadowGround);
function standard(color, roughness = 0.92, metalness = 0) {
return new THREE.MeshStandardMaterial({ color, roughness, metalness });
}
function addBox(parent, w, h, d, material, x, y, z, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Geological cutaway: stacked polygon prisms with a clipped near corner
// -------------------------------------------------------------------------
const footprint = [
[-37, -27],
[37, -27],
[37, 17],
[28, 27],
[-37, 27]
];
const footprintShape = new THREE.Shape();
footprintShape.moveTo(footprint[0][0], footprint[0][1]);
for (let i = 1; i < footprint.length; i++) {
footprintShape.lineTo(footprint[i][0], footprint[i][1]);
}
footprintShape.closePath();
function addStratum(top, depth, sideColor, capColor = sideColor) {
const geometry = new THREE.ExtrudeGeometry(footprintShape, {
depth,
bevelEnabled: false,
steps: 1
});
geometry.rotateX(Math.PI / 2);
geometry.translate(0, top, 0);
const mesh = new THREE.Mesh(geometry, [
standard(capColor, 1),
standard(sideColor, 1)
]);
mesh.castShadow = true;
mesh.receiveShadow = true;
world.add(mesh);
}
addStratum(0.0, 0.70, 0x53694d, 0x6e865d);
addStratum(-0.70, 0.90, 0x49362a);
addStratum(-1.60, 1.00, 0x80583d);
addStratum(-2.60, 1.20, 0xac7950);
addStratum(-3.80, 1.40, 0x4c555b);
const strataLevels = [0, -0.7, -1.6, -2.6, -3.8];
const sectionLineMaterial = new THREE.LineBasicMaterial({
color: 0xf3d58c,
transparent: true,
opacity: 0.44
});
function addSectionLine(points) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map(p => new THREE.Vector3(p[0], p[1], p[2]))
);
sectionOverlay.add(new THREE.Line(geometry, sectionLineMaterial));
}
for (const y of strataLevels) {
addSectionLine([[-36.9, y + 0.015, -26.96], [36.9, y + 0.015, -26.96]]);
addSectionLine([[36.96, y + 0.015, -26.9], [36.96, y + 0.015, 17]]);
addSectionLine([[36.96, y + 0.015, 17], [28, y + 0.015, 26.96]]);
}
// -------------------------------------------------------------------------
// Roads and entrances
// -------------------------------------------------------------------------
const roadMaterial = standard(0x4c5559, 0.96);
const shoulderMaterial = standard(0x776b55, 1);
const roadMarkMaterial = new THREE.MeshBasicMaterial({ color: 0xc4c4ad });
addBox(world, 71.5, 0.08, 5.3, shoulderMaterial, 0, 0.035, 0, false);
addBox(world, 70.5, 0.11, 4.25, roadMaterial, 0, 0.075, 0, false);
for (const x of [-17.5, 0, 17.5]) {
addBox(world, 2.6, 0.065, 50.2, shoulderMaterial, x, 0.028, 0, false);
addBox(world, 1.85, 0.095, 50, roadMaterial, x, 0.066, 0, false);
}
for (let x = -33; x <= 33; x += 2.8) {
addBox(world, 1.15, 0.018, 0.075, roadMarkMaterial, x, 0.145, -1.86, false);
addBox(world, 1.15, 0.018, 0.075, roadMarkMaterial, x, 0.145, 1.86, false);
}
// -------------------------------------------------------------------------
// Parcel definitions
// -------------------------------------------------------------------------
const parcels = [
{
code: "N1", name: "PASTURE", type: "pasture",
x0: -34, x1: -19, z0: 6.5, z1: 24.5, color: 0x789566
},
{
code: "N2", name: "WHEAT", type: "crop",
x0: -16, x1: -1.5, z0: 8, z1: 24, color: 0xd8bc6a,
corridor: 0, active: true, cartColor: 0xf28b45
},
{
code: "N3", name: "MAIZE", type: "crop",
x0: 1.5, x1: 16, z0: 6.5, z1: 24.5, color: 0x8eaa59,
corridor: 17.5, active: true, cartColor: 0xf1c84c
},
{
code: "N4", name: "ORCHARD", type: "orchard",
x0: 18.5, x1: 27, z0: 10, z1: 24, color: 0x677f4d
},
{
code: "S1", name: "BARLEY", type: "crop",
x0: -34, x1: -19, z0: -24, z1: -6.5, color: 0xbda96d
},
{
code: "S2", name: "CLOVER", type: "crop",
x0: -16, x1: -1.5, z0: -23, z1: -8, color: 0x62a18a,
corridor: 0, active: true, cartColor: 0x4f9edc
},
{
code: "S3", name: "RAPESEED", type: "crop",
x0: 1.5, x1: 16, z0: -24, z1: -6.5, color: 0xa8b85a
},
{
code: "S4", name: "STUBBLE", type: "crop",
x0: 18.5, x1: 34, z0: -22, z1: -8, color: 0xb5a782
}
];
const parcelByCode = new Map(parcels.map(p => [p.code, p]));
const pickables = [];
function cropLayout(p) {
const north = p.z0 < 0;
const nearZ = north ? p.z0 : p.z1;
const farZ = north ? p.z1 : p.z0;
const direction = north ? 1 : -1;
const gap = 1.30;
const innerNear = nearZ + direction * 1.4;
const innerFar = farZ - direction * 1.4;
const innerDepth = Math.abs(innerFar - innerNear);
const bandDepth = (innerDepth - gap * 3) / 4;
return {
north,
nearZ,
farZ,
direction,
gap,
innerNear,
innerFar,
innerDepth,
bandDepth,
innerX0: p.x0 + 1.4,
innerX1: p.x1 - 1.4,
laneZ: innerNear + direction * (bandDepth + gap / 2)
};
}
function addTree(parent, x, z, scale = 1) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.18, 1.25, 7),
standard(0x69513a)
);
trunk.position.set(x, 0.7, z);
trunk.castShadow = true;
parent.add(trunk);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.95 * scale, 0),
standard(0x557a46)
);
crown.position.set(x, 1.65 * scale, z);
crown.scale.y = 1.05;
crown.castShadow = true;
parent.add(crown);
}
function addHayBale(parent, x, z, rotation = 0) {
const bale = new THREE.Mesh(
new THREE.CylinderGeometry(0.52, 0.52, 0.9, 14),
standard(0xd2b96d)
);
bale.rotation.x = Math.PI / 2;
bale.rotation.z = rotation;
bale.position.set(x, 0.57, z);
bale.castShadow = true;
bale.receiveShadow = true;
parent.add(bale);
}
function addFence(parent, x1, z1, x2, z2) {
const length = Math.hypot(x2 - x1, z2 - z1);
const count = Math.max(2, Math.ceil(length / 2.7));
const postMat = standard(0x6d5941);
for (let i = 0; i <= count; i++) {
const t = i / count;
addBox(
parent, 0.12, 0.75, 0.12, postMat,
THREE.MathUtils.lerp(x1, x2, t), 0.43,
THREE.MathUtils.lerp(z1, z2, t)
);
}
const rail = addBox(
parent, length, 0.08, 0.08, postMat,
(x1 + x2) / 2, 0.55, (z1 + z2) / 2
);
rail.rotation.y = -Math.atan2(z2 - z1, x2 - x1);
}
function createParcel(p) {
const width = p.x1 - p.x0;
const depth = p.z1 - p.z0;
const cx = (p.x0 + p.x1) / 2;
const cz = (p.z0 + p.z1) / 2;
const baseColor = new THREE.Color(p.color);
const baseMaterial = standard(
baseColor.clone().multiplyScalar(p.type === "crop" ? 0.62 : 0.78)
);
const base = addBox(
fieldsGroup, width, 0.12, depth, baseMaterial,
cx, 0.085, cz, false
);
base.userData.parcel = p;
pickables.push(base);
p.baseMesh = base;
if (p.type === "crop") {
const c = cropLayout(p);
p.layout = c;
// Clear, protected inter-row lanes remain unplanted.
for (let bandIndex = 0; bandIndex < 4; bandIndex++) {
const start = c.innerNear +
c.direction * (bandIndex * (c.bandDepth + c.gap));
const center = start + c.direction * c.bandDepth / 2;
const bandColor = baseColor.clone().multiplyScalar(
bandIndex % 2 === 0 ? 0.98 : 0.9
);
addBox(
fieldsGroup,
c.innerX1 - c.innerX0,
0.12,
c.bandDepth,
standard(bandColor),
(c.innerX0 + c.innerX1) / 2,
0.18,
center,
false
);
const furrowMaterial = standard(
baseColor.clone().multiplyScalar(0.72),
1
);
const furrowCount = Math.max(3, Math.floor(c.bandDepth / 0.45));
for (let f = 0; f < furrowCount; f++) {
const t = (f + 0.5) / furrowCount;
const fz = start + c.direction * t * c.bandDepth;
addBox(
fieldsGroup,
c.innerX1 - c.innerX0,
0.025,
0.065,
furrowMaterial,
(c.innerX0 + c.innerX1) / 2,
0.25,
fz,
false
);
}
}
// Visible bare soil in each protected lane.
for (let laneIndex = 0; laneIndex < 3; laneIndex++) {
const laneCenter = c.innerNear +
c.direction * (c.bandDepth + c.gap / 2 + laneIndex * (c.bandDepth + c.gap));
addBox(
fieldsGroup,
c.innerX1 - c.innerX0,
0.035,
c.gap * 0.92,
standard(0x73664e),
(c.innerX0 + c.innerX1) / 2,
0.155,
laneCenter,
false
);
}
// Hedges stay away from the selected entrance.
const hedgeMat = standard(0x3f6241);
addBox(fieldsGroup, width - 0.5, 0.38, 0.34, hedgeMat, cx, 0.28, p.z1 - 0.2);
addBox(fieldsGroup, 0.34, 0.38, depth - 0.5, hedgeMat, p.x0 + 0.2, 0.28, cz);
} else if (p.type === "pasture") {
for (let z = p.z0 + 1.5; z < p.z1; z += 2.0) {
addBox(
fieldsGroup, width - 0.7, 0.025, 0.46,
standard(0x90a875), cx, 0.16, z, false
);
}
addHayBale(fieldsGroup, p.x0 + 3.2, p.z0 + 3.1, 0.1);
addHayBale(fieldsGroup, p.x0 + 4.6, p.z0 + 4.2, -0.15);
addHayBale(fieldsGroup, p.x1 - 3.1, p.z1 - 3.0, 0.2);
addFence(fieldsGroup, p.x0 + 0.5, p.z1 - 0.5, p.x1 - 0.5, p.z1 - 0.5);
} else if (p.type === "orchard") {
for (let x = p.x0 + 1.5; x < p.x1 - 0.5; x += 2.1) {
for (let z = p.z0 + 1.6; z < p.z1 - 0.5; z += 2.8) {
addTree(fieldsGroup, x, z, 0.85 + ((x + z) % 0.2));
}
}
addFence(fieldsGroup, p.x0 + 0.5, p.z1 - 0.5, p.x1 - 0.5, p.z1 - 0.5);
}
}
parcels.forEach(createParcel);
// -------------------------------------------------------------------------
// Loading point
// -------------------------------------------------------------------------
const loading = new THREE.Group();
world.add(loading);
addBox(loading, 9.2, 0.12, 7.3, standard(0x6c6d61), 29.8, 0.08, 2.8, false);
addBox(loading, 7.8, 0.25, 4.4, standard(0x51595a), 30.4, 0.23, 5.7);
const postMat = standard(0x37474a, 0.72, 0.18);
const roofMat = standard(0x2f5558, 0.65, 0.15);
for (const x of [27.1, 30.4, 33.7]) {
for (const z of [4.0, 7.3]) {
addBox(loading, 0.24, 3.35, 0.24, postMat, x, 1.95, z);
}
}
const roof = addBox(loading, 8.2, 0.34, 4.8, roofMat, 30.4, 3.65, 5.65);
roof.rotation.z = -0.035;
const crateMat = standard(0xb9874d);
for (let i = 0; i < 6; i++) {
const crate = addBox(
loading, 0.9, 0.65, 0.9, crateMat,
25.8 + (i % 3) * 1.05,
0.42 + Math.floor(i / 3) * 0.67,
5.0
);
crate.rotation.y = (i % 2) * 0.05;
}
const siloMaterial = standard(0xa9aaa0, 0.72, 0.2);
const silo = new THREE.Mesh(
new THREE.CylinderGeometry(1.18, 1.18, 4.2, 24),
siloMaterial
);
silo.position.set(35.0, 2.2, 6.1);
silo.castShadow = true;
loading.add(silo);
const siloCap = new THREE.Mesh(
new THREE.ConeGeometry(1.25, 0.8, 24),
roofMat
);
siloCap.position.set(35.0, 4.65, 6.1);
siloCap.castShadow = true;
loading.add(siloCap);
function makeSignTexture(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#20383a";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "#5ce4cf";
ctx.lineWidth = 7;
ctx.strokeRect(8, 8, 496, 112);
ctx.fillStyle = "#eef9f5";
ctx.font = "700 48px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(4.7, 1.18),
new THREE.MeshBasicMaterial({ map: makeSignTexture("LOAD 04") })
);
sign.position.set(30.4, 2.95, 3.43);
loading.add(sign);
// -------------------------------------------------------------------------
// Route geometry and protected lane calculation
// -------------------------------------------------------------------------
class FarmRoute {
constructor(points, speed = 3.8) {
this.points = points;
this.speed = speed;
this.segments = [];
this.total = 0;
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const length = Math.hypot(b.x - a.x, b.z - a.z);
this.segments.push({ a, b, length, start: this.total });
this.total += length;
}
}
sample(distance, outPosition, outDirection) {
const d = THREE.MathUtils.clamp(distance, 0, this.total);
let segment = this.segments[this.segments.length - 1];
for (const candidate of this.segments) {
if (d <= candidate.start + candidate.length) {
segment = candidate;
break;
}
}
const t = segment.length === 0
? 0
: (d - segment.start) / segment.length;
outPosition.lerpVectors(segment.a, segment.b, t);
outDirection.subVectors(segment.b, segment.a).normalize();
return segment;
}
}
const routeUnderlayMaterial = new THREE.MeshBasicMaterial({
color: 0x5ce4cf,
transparent: true,
opacity: 0.22,
depthWrite: false
});
const routeDashMaterial = new THREE.MeshBasicMaterial({
color: 0x68f0dc,
transparent: true,
opacity: 0.95,
depthWrite: false
});
function createRouteVisual(route) {
for (const segment of route.segments) {
const mid = segment.a.clone().add(segment.b).multiplyScalar(0.5);
const angle = -Math.atan2(
segment.b.z - segment.a.z,
segment.b.x - segment.a.x
);
const underlay = addBox(
routeGroup,
segment.length,
0.025,
0.42,
routeUnderlayMaterial,
mid.x,
0.315,
mid.z,
false
);
underlay.rotation.y = angle;
const dashSpacing = 1.18;
const dashLength = 0.56;
for (let d = 0; d < segment.length; d += dashSpacing) {
const length = Math.min(dashLength, segment.length - d);
const t = (d + length / 2) / segment.length;
const dash = addBox(
routeGroup,
length,
0.035,
0.24,
routeDashMaterial,
THREE.MathUtils.lerp(segment.a.x, segment.b.x, t),
0.34,
THREE.MathUtils.lerp(segment.a.z, segment.b.z, t),
false
);
dash.rotation.y = angle;
}
}
}
const routeRecords = [];
function makeCartModel(parcel) {
const group = new THREE.Group();
const bodyMat = standard(parcel.cartColor, 0.56, 0.12);
const darkMat = standard(0x263237, 0.76, 0.2);
const glassMat = standard(0x8cc9d7, 0.3, 0.25);
const wheelMat = standard(0x171b1d, 0.95);
addBox(group, 2.35, 0.38, 1.35, darkMat, 0, 0.55, 0);
addBox(group, 1.15, 0.72, 1.2, bodyMat, -0.48, 1.05, 0);
addBox(group, 0.62, 0.92, 1.12, bodyMat, 0.78, 1.05, 0);
addBox(group, 0.42, 0.42, 0.95, glassMat, 1.02, 1.38, 0);
const cropMaterial = standard(parcel.color, 1);
for (let i = 0; i < 7; i++) {
const cargo = addBox(
group,
0.28,
0.22,
0.36,
cropMaterial,
-0.83 + (i % 4) * 0.23,
1.52 + Math.floor(i / 4) * 0.2,
-0.28 + Math.floor(i / 4) * 0.48
);
cargo.rotation.y = i * 0.17;
}
for (const x of [-0.72, 0.72]) {
for (const z of [-0.72, 0.72]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.32, 0.32, 0.22, 14),
wheelMat
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(x, 0.34, z);
wheel.castShadow = true;
group.add(wheel);
}
}
const beaconMaterial = new THREE.MeshBasicMaterial({ color: 0xffc54f });
const beacon = new THREE.Mesh(
new THREE.CylinderGeometry(0.10, 0.10, 0.18, 10),
beaconMaterial
);
beacon.position.set(0.78, 1.65, 0);
group.add(beacon);
cartGroup.add(group);
return group;
}
function createParcelRoute(p, index) {
const c = p.layout;
const points = [
new THREE.Vector3(p.x0 + 4.2, 0, c.laneZ),
new THREE.Vector3(p.x1 - 0.7, 0, c.laneZ),
new THREE.Vector3(p.x1 - 0.7, 0, c.nearZ),
new THREE.Vector3(p.corridor, 0, c.nearZ),
new THREE.Vector3(p.corridor, 0, 0),
new THREE.Vector3(28.6, 0, 0),
new THREE.Vector3(29.1, 0, 1.35)
];
const route = new FarmRoute(points, 3.55 + index * 0.22);
createRouteVisual(route);
const entrance = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.075, 7, 24),
new THREE.MeshBasicMaterial({ color: 0xffb35c })
);
entrance.rotation.x = Math.PI / 2;
entrance.position.set(p.corridor, 0.38, c.nearZ);
routeGroup.add(entrance);
for (const zOffset of [-0.82, 0.82]) {
addBox(
routeGroup, 0.16, 0.9, 0.16,
standard(0xf2a64c),
p.corridor, 0.48, c.nearZ + zOffset
);
}
const flowMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 10, 10),
new THREE.MeshBasicMaterial({ color: 0xa7fff0 })
);
routeGroup.add(flowMarker);
const cart = makeCartModel(p);
const record = {
parcel: p,
route,
cart,
flowMarker,
phase: index * route.total * 0.31,
index
};
routeRecords.push(record);
return record;
}
parcels.filter(p => p.active).forEach(createParcelRoute);
// -------------------------------------------------------------------------
// Projected labels
// -------------------------------------------------------------------------
const labelItems = [];
function addWorldLabel(html, position, className = "", color = "#d8bc6a", key = "static") {
const el = document.createElement("div");
el.className = `world-label ${className}`;
el.style.setProperty("--label-color", color);
el.innerHTML = html;
document.getElementById("labels").appendChild(el);
labelItems.push({ el, position, key });
return el;
}
for (const p of parcels) {
const labelColor = `#${new THREE.Color(p.color).getHexString()}`;
addWorldLabel(
`${p.code} · ${p.name}<small>${p.type.toUpperCase()}</small>`,
new THREE.Vector3((p.x0 + p.x1) / 2, 0.75, (p.z0 + p.z1) / 2),
"",
labelColor,
"fields"
);
}
addWorldLabel(
"LOADING POINT 04<small>HARVEST INTAKE</small>",
new THREE.Vector3(30.4, 4.9, 5.6),
"loading",
"#5ce4cf",
"static"
);
addWorldLabel(
"A—A / SOIL SECTION<small>TOPSOIL · SILT · CLAY</small>",
new THREE.Vector3(32.5, -1.65, 22),
"section",
"#e4bc64",
"section"
);
addWorldLabel(
"MAIN HAUL ROAD<small>C-00</small>",
new THREE.Vector3(-7, 0.5, 0),
"",
"#91a2a4",
"static"
);
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of labelItems) {
const groupVisible =
item.key !== "fields" ||
fieldsGroup.visible;
const sectionVisible =
item.key !== "section" ||
sectionOverlay.visible;
if (!groupVisible || !sectionVisible) {
item.el.style.display = "none";
continue;
}
const p = item.position.clone().project(camera);
if (p.z < -1 || p.z > 1) {
item.el.style.display = "none";
continue;
}
const x = (p.x * 0.5 + 0.5) * width;
const y = (-p.y * 0.5 + 0.5) * height;
item.el.style.display = "block";
item.el.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
}
// -------------------------------------------------------------------------
// Selection and UI
// -------------------------------------------------------------------------
const inspectorTitle = document.getElementById("inspector-title");
const inspectorText = document.getElementById("inspector-text");
const inspectorChip = document.getElementById("inspector-chip");
let selectedParcel = parcelByCode.get("N2");
function selectParcel(p) {
if (!p) return;
if (selectedParcel?.baseMesh) {
selectedParcel.baseMesh.material.emissive.setHex(0x000000);
selectedParcel.baseMesh.material.emissiveIntensity = 0;
}
selectedParcel = p;
p.baseMesh.material.emissive.setHex(0x1c5148);
p.baseMesh.material.emissiveIntensity = 0.52;
inspectorTitle.textContent = `${p.code} · ${p.name}`;
inspectorChip.textContent = p.active ? "ACTIVE" : "Mosaic";
const area = Math.round((p.x1 - p.x0) * (p.z1 - p.z0));
if (p.active) {
inspectorText.textContent =
`${area} plot units. Harvest carts use entrance C-${String(p.corridor).replace(".", "0")}, ` +
`a protected inter-row lane and the perimeter headland. No route crosses a cultivated strip.`;
} else if (p.type === "crop") {
inspectorText.textContent =
`${area} plot units. Cultivated strips are separated by clear agricultural lanes. ` +
`The parcel is connected to the nearest perimeter path without a vehicle shortcut through crops.`;
} else {
inspectorText.textContent =
`${area} plot units. This land-use block is served from the perimeter network; ` +
`no harvest vehicle circulation is permitted through the parcel.`;
}
}
selectParcel(selectedParcel);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: false,
x: 0,
y: 0
};
function raycastParcel(event) {
const rect = renderer.domElement.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 hits = raycaster.intersectObjects(pickables, false);
return hits.length ? hits[0].object.userData.parcel : null;
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerState.down = true;
pointerState.moved = false;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerState.down) {
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
if (Math.abs(dx) + Math.abs(dy) > 4) pointerState.moved = true;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.10,
1.28
);
pointerState.x = event.clientX;
pointerState.y = event.clientY;
updateCamera();
renderer.domElement.style.cursor = "grabbing";
} else {
renderer.domElement.style.cursor =
raycastParcel(event) ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (!pointerState.moved) {
const parcel = raycastParcel(event);
if (parcel) selectParcel(parcel);
}
pointerState.down = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.down = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.8
);
updateCamera();
}, { passive: false });
const toggleState = {
fields: true,
routes: true,
carts: true,
section: true
};
document.querySelectorAll("[data-toggle]").forEach(button => {
button.addEventListener("click", () => {
const key = button.dataset.toggle;
toggleState[key] = !toggleState[key];
if (key === "fields") fieldsGroup.visible = toggleState.fields;
if (key === "routes") routeGroup.visible = toggleState.routes;
if (key === "carts") cartGroup.visible = toggleState.carts;
if (key === "section") sectionOverlay.visible = toggleState.section;
button.classList.toggle("active", toggleState[key]);
button.setAttribute("aria-pressed", String(toggleState[key]));
});
});
const viewPresets = {
iso: { theta: 0.72, phi: 0.92, zoom: 1 },
top: { theta: 0.02, phi: 0.10, zoom: 0.92 },
section: { theta: 1.04, phi: 1.19, zoom: 1.13 }
};
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => {
const preset = viewPresets[button.dataset.view];
orbit.theta = preset.theta;
orbit.phi = preset.phi;
orbit.zoom = preset.zoom;
updateCamera();
document.querySelectorAll("[data-view]").forEach(other => {
other.classList.toggle("active", other === button);
});
});
});
let paused = false;
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "RESUME" : "PAUSE";
pauseButton.classList.toggle("active", paused);
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const tempPosition = new THREE.Vector3();
const tempDirection = new THREE.Vector3();
function animate() {
const elapsed = clock.getElapsedTime();
const simTime = paused ? clock.getElapsedTime() - 0 : elapsed;
let simulationTime = elapsed;
// Pausing freezes cart motion without stopping rendering or camera controls.
if (paused) {
if (!animate.previousTime) animate.previousTime = elapsed;
simulationTime = animate.previousTime;
} else {
animate.previousTime = elapsed;
}
for (const record of routeRecords) {
const route = record.route;
const travel = (simulationTime * route.speed + record.phase) % (route.total * 2);
const distance = travel <= route.total ? travel : route.total * 2 - travel;
const reverse = travel > route.total;
route.sample(distance, tempPosition, tempDirection);
record.cart.position.set(tempPosition.x, 0.12, tempPosition.z);
if (reverse) tempDirection.multiplyScalar(-1);
record.cart.rotation.y = -Math.atan2(tempDirection.z, tempDirection.x);
const markerDistance = (simulationTime * route.speed + route.total * 0.18) % route.total;
route.sample(markerDistance, tempPosition, tempDirection);
record.flowMarker.position.set(tempPosition.x, 0.56, tempPosition.z);
}
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```