Prompt specification
Build or customize the Three.js 3D scene "Small diversified farm plot" 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: Small diversified farm plot
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-diversified-farm-plot-x1079
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts intercropping. Build a bounded garden with several crop forms, support poles, paths, and labels; highlight structural differences in height and ground coverage within the same plot. Stylized solid forms.
Working Three.js Starter (small-diversified-farm-plot-x1079):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Intercropping — One Plot, Five Structures</title>
<style>
:root {
--ink: #263a2f;
--muted: #617267;
--paper: rgba(250, 248, 237, 0.9);
--line: rgba(48, 72, 57, 0.14);
--corn: #d8a93f;
--beans: #4f9451;
--tomato: #d65c45;
--carrot: #ec7c2f;
--squash: #829c43;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe7d3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#stage canvas {
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.title-block {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
width: min(380px, calc(100vw - 56px));
pointer-events: none;
text-shadow: 0 1px 10px rgba(247, 247, 232, 0.7);
}
.eyebrow {
margin-bottom: 7px;
color: #52695a;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(29px, 3.1vw, 48px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
margin: 10px 0 0;
max-width: 330px;
color: #50675a;
font-size: 13px;
line-height: 1.45;
}
.toolbar {
position: fixed;
top: 136px;
left: 28px;
z-index: 8;
display: flex;
gap: 8px;
}
button {
border: 1px solid rgba(42, 67, 52, 0.18);
border-radius: 999px;
padding: 8px 13px;
background: rgba(250, 248, 237, 0.84);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.035em;
cursor: pointer;
box-shadow: 0 5px 20px rgba(40, 62, 48, 0.08);
backdrop-filter: blur(9px);
transition:
transform 160ms ease,
background 160ms ease;
}
button:hover {
transform: translateY(-1px);
background: rgba(255, 253, 244, 0.97);
}
button:focus-visible {
outline: 2px solid #6a916e;
outline-offset: 2px;
}
.study-card {
position: fixed;
top: 24px;
right: 24px;
z-index: 6;
width: 326px;
padding: 18px 18px 16px;
border: 1px solid rgba(50, 76, 59, 0.14);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 18px 55px rgba(49, 72, 55, 0.13);
backdrop-filter: blur(14px);
}
.card-heading {
display: flex;
align-items: start;
justify-content: space-between;
gap: 12px;
padding-bottom: 13px;
border-bottom: 1px solid var(--line);
}
.card-heading h2 {
margin: 0 0 4px;
font-size: 14px;
letter-spacing: -0.02em;
}
.card-heading p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.badge {
flex: 0 0 auto;
padding: 5px 8px;
border-radius: 999px;
background: #e5ebd9;
color: #45624d;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-header,
.metric-row {
display: grid;
grid-template-columns: 72px 1fr 1fr;
gap: 10px;
align-items: center;
}
.metric-header {
margin: 14px 0 6px;
color: #78867d;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-header span:not(:first-child) {
text-align: center;
}
.metric-row {
min-height: 37px;
border-top: 1px solid rgba(48, 72, 57, 0.08);
}
.crop-name {
display: flex;
align-items: center;
gap: 7px;
font-size: 11px;
font-weight: 750;
}
.swatch {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--crop);
}
.bar {
position: relative;
height: 6px;
overflow: visible;
border-radius: 999px;
background: rgba(65, 87, 70, 0.1);
}
.bar > span {
position: absolute;
inset: 0 auto 0 0;
width: var(--w);
min-width: 4px;
border-radius: inherit;
background: var(--crop);
opacity: 0.88;
}
.bar > b {
position: absolute;
top: 9px;
left: 50%;
color: #52675a;
font-size: 8px;
font-weight: 750;
transform: translateX(-50%);
white-space: nowrap;
}
.card-note {
margin: 18px 0 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #627368;
font-size: 10px;
line-height: 1.5;
}
.card-note strong {
color: #3f5948;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.plot-label {
position: absolute;
top: 0;
left: 0;
min-width: 112px;
padding: 8px 10px 7px;
border: 1px solid rgba(38, 58, 47, 0.16);
border-radius: 10px;
background: rgba(255, 253, 243, 0.9);
box-shadow: 0 8px 24px rgba(43, 65, 51, 0.14);
backdrop-filter: blur(8px);
transform: translate(-50%, -100%);
will-change: transform;
}
.plot-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 14px;
background: rgba(38, 58, 47, 0.42);
content: "";
}
.plot-label .name {
display: flex;
align-items: center;
gap: 6px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.plot-label .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--crop);
}
.plot-label small {
display: block;
margin-top: 3px;
color: #65756a;
font-size: 9px;
white-space: nowrap;
}
.scale-label {
position: absolute;
padding: 2px 5px;
border-radius: 4px;
background: rgba(255, 253, 243, 0.85);
color: #5d6f63;
font-size: 9px;
font-weight: 800;
transform: translate(-50%, -50%);
}
.hint {
position: fixed;
bottom: 20px;
left: 50%;
z-index: 7;
padding: 8px 13px;
border: 1px solid rgba(49, 72, 56, 0.12);
border-radius: 999px;
background: rgba(248, 247, 233, 0.76);
color: #566b5d;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(8px);
}
@media (max-width: 900px) {
.study-card {
display: none;
}
.title-block {
top: 20px;
left: 20px;
}
.toolbar {
top: auto;
bottom: 20px;
left: 20px;
}
.hint {
right: 16px;
bottom: 25px;
left: auto;
transform: none;
}
}
@media (max-width: 560px) {
.subtitle {
display: none;
}
.toolbar {
bottom: 18px;
}
.hint {
display: none;
}
.plot-label {
min-width: 92px;
padding: 6px 8px;
}
.plot-label small {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels" aria-hidden="true"></div>
<header class="title-block">
<div class="eyebrow">Shared-bed study / plot 01</div>
<h1>Intercropping</h1>
<p class="subtitle">
One garden, five crop structures—contrasting vertical reach and
horizontal ground coverage.
</p>
</header>
<nav class="toolbar" aria-label="Scene controls">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-labels" type="button">Hide labels</button>
</nav>
<aside class="study-card" aria-label="Crop structure comparison">
<div class="card-heading">
<div>
<h2>Structure key</h2>
<p>Height and soil coverage compared within one plot.</p>
</div>
<div class="badge">5 forms</div>
</div>
<div class="metric-header">
<span>Crop</span>
<span>Height</span>
<span>Cover</span>
</div>
<div class="metric-row" style="--crop: var(--corn)">
<div class="crop-name"><i class="swatch"></i>Corn</div>
<div class="bar" style="--w: 100%"><span></span><b>2.4 m</b></div>
<div class="bar" style="--w: 30%"><span></span><b>30%</b></div>
</div>
<div class="metric-row" style="--crop: var(--beans)">
<div class="crop-name"><i class="swatch"></i>Beans</div>
<div class="bar" style="--w: 88%"><span></span><b>2.1 m</b></div>
<div class="bar" style="--w: 42%"><span></span><b>42%</b></div>
</div>
<div class="metric-row" style="--crop: var(--tomato)">
<div class="crop-name"><i class="swatch"></i>Tomato</div>
<div class="bar" style="--w: 46%"><span></span><b>1.1 m</b></div>
<div class="bar" style="--w: 64%"><span></span><b>64%</b></div>
</div>
<div class="metric-row" style="--crop: var(--carrot)">
<div class="crop-name"><i class="swatch"></i>Carrot</div>
<div class="bar" style="--w: 13%"><span></span><b>0.3 m</b></div>
<div class="bar" style="--w: 52%"><span></span><b>52%</b></div>
</div>
<div class="metric-row" style="--crop: var(--squash)">
<div class="crop-name"><i class="swatch"></i>Squash</div>
<div class="bar" style="--w: 21%"><span></span><b>0.5 m</b></div>
<div class="bar" style="--w: 86%"><span></span><b>86%</b></div>
</div>
<p class="card-note">
<strong>Open soil between stems</strong> leaves room for low crops;
climbing structures use the unused vertical space.
</p>
</aside>
<div class="hint">Drag to orbit · Scroll or pinch to zoom · R to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const stage = document.querySelector("#stage");
const labelLayer = document.querySelector("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dfe7d3");
scene.fog = new THREE.Fog("#dfe7d3", 31, 58);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#fff8df", "#718267", 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff2cf", 3.1);
sun.position.set(-8, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0007;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9d5df", 0.75);
fill.position.set(9, 7, -10);
scene.add(fill);
// ------------------------------------------------------------
// Reusable geometry and materials
// ------------------------------------------------------------
const geo = {
box: new THREE.BoxGeometry(1, 1, 1),
cylinder: new THREE.CylinderGeometry(1, 1, 1, 10),
sphere: new THREE.SphereGeometry(1, 12, 8),
cone: new THREE.ConeGeometry(1, 1, 9),
torus: new THREE.TorusGeometry(0.35, 0.016, 5, 18)
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.94,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
soil: material("#6d4c38"),
soilDark: material("#5a3d2e"),
soilLight: material("#79543d"),
path: material("#cbb78d"),
pathEdge: material("#ad956c"),
wood: material("#8f6543"),
woodLight: material("#b38858"),
woodDark: material("#644733"),
ground: material("#d7dfc7"),
cornStem: material("#4f8743"),
cornLeaf: material("#5f9b43"),
cornLeafLight: material("#76aa4c"),
corn: material("#e6b849"),
beanStem: material("#477e43"),
beanLeaf: material("#4d934c"),
beanLeafLight: material("#65a45a"),
beanPod: material("#82a94c"),
tomatoStem: material("#3f713d"),
tomatoLeaf: material("#4f8847"),
tomato: material("#d9573f"),
carrot: material("#e9782d"),
carrotLeaf: material("#4d8a4a"),
squashLeaf: material("#547c3f"),
squashLeafLight: material("#6f9145"),
squash: material("#d78b35"),
string: material("#d8c89b"),
stone: material("#b8b5a2")
};
function addMesh(parent, geometry, mat, position, scale, rotation) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(...position);
mesh.scale.set(...scale);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(parent, mat, position, scale, rotation) {
return addMesh(parent, geo.box, mat, position, scale, rotation);
}
function cylinder(parent, mat, position, radius, height, rotation) {
return addMesh(
parent,
geo.cylinder,
mat,
position,
[radius, height, radius],
rotation
);
}
function cone(parent, mat, position, radius, height, rotation) {
return addMesh(
parent,
geo.cone,
mat,
position,
[radius, height, radius],
rotation
);
}
function ellipsoid(
parent,
mat,
position,
scale,
rotation = [0, 0, 0]
) {
return addMesh(parent, geo.sphere, mat, position, scale, rotation);
}
function beam(parent, mat, a, b, radius = 0.035) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(geo.cylinder, mat);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.scale.set(radius, length, radius);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let seed = 4217;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const windPlants = [];
// ------------------------------------------------------------
// Ground, bounded plot, paths, and timber border
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
M.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.18;
ground.receiveShadow = true;
scene.add(ground);
box(scene, M.soil, [0, 0.06, 0], [16, 0.48, 11]);
// A warmer top layer makes the plot read clearly from above.
box(scene, M.soilLight, [0, 0.305, 0], [15.9, 0.035, 10.9]);
// Main cross paths.
box(scene, M.path, [0, 0.34, 0], [1.22, 0.07, 11]);
box(scene, M.path, [0, 0.345, 0], [16, 0.075, 1.22]);
// Path edging.
box(scene, M.pathEdge, [-0.66, 0.37, 0], [0.08, 0.12, 10.9]);
box(scene, M.pathEdge, [0.66, 0.37, 0], [0.08, 0.12, 10.9]);
box(scene, M.pathEdge, [0, 0.37, -0.66], [15.9, 0.12, 0.08]);
box(scene, M.pathEdge, [0, 0.37, 0.66], [15.9, 0.12, 0.08]);
// Entrance apron.
box(scene, M.path, [0, -0.04, 7.0], [1.22, 0.12, 2.7]);
box(scene, M.pathEdge, [0, 0.01, 8.35], [1.35, 0.13, 0.12]);
// Timber perimeter.
box(scene, M.wood, [0, 0.47, -5.62], [16.65, 0.48, 0.3]);
box(scene, M.wood, [0, 0.47, 5.62], [16.65, 0.48, 0.3]);
box(scene, M.wood, [-8.18, 0.47, 0], [0.3, 0.48, 11.55]);
box(scene, M.wood, [8.18, 0.47, 0], [0.3, 0.48, 11.55]);
// Corner posts.
for (const x of [-8.18, 8.18]) {
for (const z of [-5.62, 5.62]) {
box(scene, M.woodDark, [x, 0.69, z], [0.42, 1.0, 0.42]);
box(scene, M.woodLight, [x, 1.21, z], [0.46, 0.12, 0.46]);
}
}
// Small decorative stones outside the plot.
[
[-9.3, -0.03, 3.2, 0.34],
[-9.7, -0.02, 2.7, 0.22],
[9.4, -0.02, -3.8, 0.31],
[9.0, -0.02, -4.3, 0.19],
[7.5, -0.02, 7.1, 0.25]
].forEach(([x, y, z, s]) => {
ellipsoid(
scene,
M.stone,
[x, y, z],
[s, s * 0.58, s * 0.8],
[0.1, random(), 0.08]
);
});
// ------------------------------------------------------------
// Tall corn: narrow cover, high vertical structure
// ------------------------------------------------------------
function createCorn(x, z, height) {
const g = new THREE.Group();
g.position.set(x, 0.37, z);
g.rotation.y = random() * Math.PI;
scene.add(g);
cylinder(g, M.cornStem, [0, height / 2, 0], 0.045, height);
const leafLevels = [0.33, 0.52, 0.69, 0.83];
leafLevels.forEach((level, index) => {
const side = index % 2 === 0 ? -1 : 1;
const leaf = ellipsoid(
g,
index % 2 ? M.cornLeaf : M.cornLeafLight,
[side * 0.21, height * level, 0],
[0.13, 0.43, 0.055],
[0.16, 0, side * 1.05]
);
leaf.rotation.x += (random() - 0.5) * 0.35;
});
// Ear and husk.
ellipsoid(
g,
M.corn,
[0.12, height * 0.51, 0.02],
[0.1, 0.25, 0.11],
[0.05, 0, -0.15]
);
ellipsoid(
g,
M.cornLeaf,
[0.12, height * 0.46, 0.02],
[0.07, 0.2, 0.075],
[0, 0, -0.12]
);
// Tassel.
cone(
g,
M.corn,
[0, height + 0.14, 0],
0.045,
0.27
);
beam(
g,
M.corn,
[-0.06, height + 0.04, 0],
[-0.16, height + 0.29, 0.02],
0.012
);
beam(
g,
M.corn,
[0.06, height + 0.04, 0],
[0.15, height + 0.27, -0.02],
0.012
);
windPlants.push({ g, phase: random() * 7, amount: 0.012 });
}
const cornXs = [-6.55, -5.2, -3.85, -2.5];
const cornZs = [-4.35, -2.25];
for (const z of cornZs) {
box(scene, M.soilDark, [-4.52, 0.34, z], [5.55, 0.025, 0.18]);
for (const x of cornXs) {
createCorn(x, z, 1.82 + random() * 0.3);
}
}
// ------------------------------------------------------------
// Pole bean trellis: vertical support in the northeast bed
// ------------------------------------------------------------
const trellis = new THREE.Group();
scene.add(trellis);
const postXs = [1.35, 4.0, 6.65];
const postZs = [-4.75, -1.85];
postXs.forEach((x) => {
postZs.forEach((z) => {
cylinder(trellis, M.woodLight, [x, 1.43, z], 0.075, 2.15);
cylinder(trellis, M.woodDark, [x, 0.48, z], 0.085, 0.32);
});
});
postZs.forEach((z) => {
beam(
trellis,
M.woodLight,
[1.35, 2.39, z],
[6.65, 2.39, z],
0.075
);
beam(
trellis,
M.woodLight,
[1.35, 1.0, z],
[6.65, 1.0, z],
0.045
);
});
beam(
trellis,
M.woodLight,
[1.35, 2.39, -4.75],
[1.35, 2.39, -1.85],
0.065
);
beam(
trellis,
M.woodLight,
[6.65, 2.39, -4.75],
[6.65, 2.39, -1.85],
0.065
);
// Diagonal braces.
beam(
trellis,
M.woodDark,
[1.35, 0.55, -4.75],
[2.55, 2.35, -4.75],
0.038
);
beam(
trellis,
M.woodDark,
[6.65, 0.55, -1.85],
[5.45, 2.35, -1.85],
0.038
);
// Vertical strings.
[1.8, 2.65, 3.5, 4.8, 5.55, 6.15].forEach((x) => {
beam(
trellis,
M.string,
[x, 0.4, -3.3],
[x, 2.34, -3.3],
0.012
);
});
function createBeanPlant(x, z, height) {
const g = new THREE.Group();
g.position.set(x, 0.37, z);
scene.add(g);
const points = [
[0, 0, 0],
[-0.08, height * 0.35, 0.03],
[0.07, height * 0.68, -0.03],
[0, height, 0]
];
for (let i = 0; i < points.length - 1; i++) {
beam(g, M.beanStem, points[i], points[i + 1], 0.027);
}
for (let i = 0; i < 9; i++) {
const level = 0.18 + i * 0.085;
const side = i % 2 ? 1 : -1;
ellipsoid(
g,
i % 3 ? M.beanLeaf : M.beanLeafLight,
[side * (0.15 + random() * 0.07), level * height, 0],
[0.17, 0.3, 0.055],
[0.08, 0, side * 0.95]
);
}
// Hanging pods.
for (let i = 0; i < 4; i++) {
ellipsoid(
g,
M.beanPod,
[0.11 + (i % 2) * 0.08, height * (0.38 + i * 0.13), 0.07],
[0.055, 0.23, 0.055],
[0, 0, -0.16 + i * 0.05]
);
}
windPlants.push({ g, phase: random() * 7, amount: 0.016 });
}
[1.8, 2.8, 3.9, 5.0, 6.15].forEach((x) => {
createBeanPlant(x, -3.3, 1.72 + random() * 0.18);
});
// ------------------------------------------------------------
// Medium-height tomatoes with individual support cages
// ------------------------------------------------------------
function createTomato(x, z) {
const g = new THREE.Group();
g.position.set(x, 0.37, z);
scene.add(g);
// Cage stakes.
for (let i = 0; i < 3; i++) {
const angle = (i / 3) * Math.PI * 2 + 0.2;
const px = Math.cos(angle) * 0.35;
const pz = Math.sin(angle) * 0.35;
beam(g, M.woodLight, [px, 0, pz], [px, 0.95, pz], 0.022);
}
[0.43, 0.83].forEach((y) => {
const ring = new THREE.Mesh(geo.torus, M.woodLight);
ring.position.y = y;
ring.rotation.x = Math.PI / 2;
ring.castShadow = true;
g.add(ring);
});
// Bush.
cylinder(g, M.tomatoStem, [0, 0.45, 0], 0.035, 0.9);
beam(
g,
M.tomatoStem,
[0, 0.42, 0],
[-0.25, 0.75, 0.06],
0.026
);
beam(
g,
M.tomatoStem,
[0, 0.55, 0],
[0.28, 0.83, -0.03],
0.026
);
beam(
g,
M.tomatoStem,
[0, 0.72, 0],
[-0.05, 0.98, -0.22],
0.022
);
const leafData = [
[-0.24, 0.58, 0.03, 0.12],
[0.24, 0.7, -0.02, -0.15],
[-0.1, 0.86, -0.14, 0.1],
[0.1, 0.94, 0.12, -0.2]
];
leafData.forEach(([px, py, pz, rz]) => {
ellipsoid(
g,
M.tomatoLeaf,
[px, py, pz],
[0.29, 0.065, 0.17],
[0, rz * 0.6, rz]
);
});
[
[-0.19, 0.55, 0.11],
[0.2, 0.72, 0.1],
[-0.07, 0.82, -0.15],
[0.13, 0.4, -0.12]
].forEach(([px, py, pz]) => {
ellipsoid(
g,
M.tomato,
[px, py, pz],
[0.11, 0.11, 0.11]
);
});
windPlants.push({ g, phase: random() * 7, amount: 0.018 });
}
[2.2, 4.1, 6.0].forEach((x) => createTomato(x, -1.18));
// ------------------------------------------------------------
// Low carrots: compact height, moderate ground coverage
// ------------------------------------------------------------
function createCarrot(x, z) {
const g = new THREE.Group();
g.position.set(x, 0.37, z);
g.rotation.y = random() * Math.PI;
scene.add(g);
// Point the cone downward.
cone(g, M.carrot, [0, 0.08, 0], 0.115, 0.4, [0, 0, Math.PI]);
ellipsoid(g, M.carrot, [0, 0.25, 0], [0.12, 0.08, 0.12]);
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const leaf = ellipsoid(
g,
M.carrotLeaf,
[Math.cos(angle) * 0.08, 0.34, Math.sin(angle) * 0.08],
[0.055, 0.27, 0.045],
[Math.sin(angle) * 0.55, 0, -Math.cos(angle) * 0.55]
);
leaf.rotation.y = angle;
}
windPlants.push({ g, phase: random() * 7, amount: 0.012 });
}
const carrotXs = [-6.65, -5.3, -3.95, -2.6, -1.25];
const carrotZs = [1.15, 2.25, 3.35, 4.45];
for (const z of carrotZs) {
box(scene, M.soilDark, [-3.95, 0.34, z], [6.15, 0.025, 0.16]);
for (const x of carrotXs) {
if (random() > 0.08) createCarrot(x, z + (random() - 0.5) * 0.15);
}
}
// ------------------------------------------------------------
// Spreading squash: low height, high ground coverage
// ------------------------------------------------------------
function createSquash(x, z, size = 1) {
const g = new THREE.Group();
g.position.set(x, 0.37, z);
g.rotation.y = random() * Math.PI;
scene.add(g);
const vineEnds = [
[0.75 * size, 0.05, 0.1],
[-0.72 * size, 0.05, 0.2],
[0.2 * size, 0.05, 0.72 * size],
[-0.22 * size, 0.05, -0.7 * size]
];
vineEnds.forEach((end, index) => {
beam(g, M.squashLeaf, [0, 0.05, 0], end, 0.025 * size);
const leaf = ellipsoid(
g,
index % 2 ? M.squashLeaf : M.squashLeafLight,
[end[0] * 0.82, 0.16 * size, end[2] * 0.82],
[0.46 * size, 0.075 * size, 0.35 * size],
[0.05, index * 0.72, index % 2 ? 0.14 : -0.14]
);
leaf.rotation.y += index * 0.63;
});
// Two low leaves near the center.
ellipsoid(
g,
M.squashLeafLight,
[-0.22 * size, 0.18, -0.12],
[0.44 * size, 0.07, 0.31 * size],
[0, 0.4, 0.08]
);
ellipsoid(
g,
M.squashLeaf,
[0.25 * size, 0.16, 0.18],
[0.4 * size, 0.065, 0.3 * size],
[0, -0.35, -0.08]
);
// Squash fruit.
ellipsoid(
g,
M.squash,
[0.05, 0.16 * size, -0.03],
[0.27 * size, 0.23 * size, 0.27 * size],
[0, random(), 0]
);
cylinder(
g,
M.squashLeaf,
[0.05, 0.36 * size, -0.03],
0.035,
0.1
);
windPlants.push({ g, phase: random() * 7, amount: 0.006 });
}
createSquash(2.05, 2.05, 1.03);
createSquash(4.0, 2.4, 1.12);
createSquash(5.95, 3.1, 0.95);
createSquash(3.25, 4.25, 1.08);
// ------------------------------------------------------------
// Height reference stake
// ------------------------------------------------------------
const scaleGroup = new THREE.Group();
scaleGroup.position.set(-7.48, 0.37, 0.85);
scene.add(scaleGroup);
box(scaleGroup, M.woodLight, [0, 1.1, 0], [0.12, 2.2, 0.12]);
box(scaleGroup, M.woodDark, [0.16, 0.98, 0], [0.42, 0.045, 0.07]);
box(scaleGroup, M.woodDark, [0.2, 1.98, 0], [0.48, 0.045, 0.07]);
box(scaleGroup, M.woodDark, [0.12, 0.48, 0], [0.34, 0.04, 0.065]);
// ------------------------------------------------------------
// Small physical plot sign
// ------------------------------------------------------------
const sign = new THREE.Group();
sign.position.set(-1.65, 0, 5.98);
scene.add(sign);
box(sign, M.woodDark, [-0.78, 0.63, 0], [0.12, 1.15, 0.12]);
box(sign, M.woodDark, [0.78, 0.63, 0], [0.12, 1.15, 0.12]);
box(sign, M.wood, [0, 1.1, 0], [2.35, 0.86, 0.15]);
const signCanvas = document.createElement("canvas");
signCanvas.width = 768;
signCanvas.height = 280;
const ctx = signCanvas.getContext("2d");
ctx.fillStyle = "#f3e8c9";
ctx.fillRect(0, 0, 768, 280);
ctx.fillStyle = "#3f5948";
ctx.font = "800 66px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText("INTERCROPPING", 384, 105);
ctx.fillStyle = "#7a6448";
ctx.font = "700 31px system-ui, sans-serif";
ctx.fillText("PLOT 01 · FIVE STRUCTURES", 384, 166);
ctx.fillStyle = "#b68a54";
ctx.fillRect(130, 205, 508, 9);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
signTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const signFace = new THREE.Mesh(
new THREE.PlaneGeometry(2.18, 0.72),
new THREE.MeshBasicMaterial({ map: signTexture })
);
signFace.position.set(0, 1.1, 0.077);
sign.add(signFace);
// ------------------------------------------------------------
// Screen-space labels projected from world-space anchors
// ------------------------------------------------------------
const labels = [];
function addPlotLabel(name, metric, color, anchor, offsetY = 0) {
const element = document.createElement("div");
element.className = "plot-label";
element.style.setProperty("--crop", color);
element.innerHTML = `
<div class="name"><i class="dot"></i>${name}</div>
<small>${metric}</small>
`;
labelLayer.appendChild(element);
labels.push({
element,
anchor: new THREE.Vector3(...anchor),
offsetY
});
}
function addScaleLabel(text, anchor) {
const element = document.createElement("div");
element.className = "scale-label";
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
element,
anchor: new THREE.Vector3(...anchor),
offsetY: 0
});
}
addPlotLabel(
"Tall corn",
"2.4 m · 30% cover",
"#d8a93f",
[-4.4, 2.95, -2.25]
);
addPlotLabel(
"Pole beans",
"2.1 m · 42% cover",
"#4f9451",
[4.0, 2.78, -3.3]
);
addPlotLabel(
"Tomato",
"1.1 m · 64% cover",
"#d65c45",
[4.1, 1.72, -1.18]
);
addPlotLabel(
"Carrot",
"0.3 m · 52% cover",
"#ec7c2f",
[-4.0, 0.95, 2.25]
);
addPlotLabel(
"Spreading squash",
"0.5 m · 86% cover",
"#829c43",
[4.0, 1.08, 2.4]
);
addScaleLabel("1 m", [-7.3, 1.35, 0.85]);
addScaleLabel("2 m", [-7.25, 2.35, 0.85]);
const projected = new THREE.Vector3();
function updateLabels() {
for (const item of labels) {
projected.copy(item.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.35 &&
Math.abs(projected.y) < 1.35;
item.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
item.element.style.transform =
`translate(-50%, -100%) translate(${x}px, ${y + item.offsetY}px)`;
}
}
// ------------------------------------------------------------
// Custom camera controls — no external controls module
// ------------------------------------------------------------
const target = new THREE.Vector3(
innerWidth > 900 ? 0.65 : 0,
0.52,
0
);
const desired = {
theta: 0.73,
phi: 1.03,
radius: 24.5
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius
};
let dragging = false;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.48,
1.38
);
previousX = event.clientX;
previousY = event.clientY;
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.012,
16,
34
);
},
{ passive: false }
);
function resetView() {
desired.theta = 0.73;
desired.phi = 1.03;
desired.radius = 24.5;
}
document.querySelector("#reset-view").addEventListener("click", resetView);
let labelsVisible = true;
const labelButton = document.querySelector("#toggle-labels");
labelButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelButton.textContent = labelsVisible ? "Hide labels" : "Show labels";
labelLayer.style.display = labelsVisible ? "block" : "none";
});
addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "l") labelButton.click();
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
target.x = innerWidth > 900 ? 0.65 : 0;
});
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
const reduceMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
current.theta = THREE.MathUtils.lerp(
current.theta,
desired.theta,
0.075
);
current.phi = THREE.MathUtils.lerp(
current.phi,
desired.phi,
0.075
);
current.radius = THREE.MathUtils.lerp(
current.radius,
desired.radius,
0.075
);
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x + current.radius * sinPhi * Math.sin(current.theta),
target.y + current.radius * Math.cos(current.phi),
target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
if (!reduceMotion) {
for (const plant of windPlants) {
plant.g.rotation.z =
Math.sin(elapsed * 0.72 + plant.phase) * plant.amount;
plant.g.rotation.x =
Math.cos(elapsed * 0.58 + plant.phase) * plant.amount * 0.45;
}
}
renderer.render(scene, camera);
camera.updateMatrixWorld();
updateLabels();
}
animate();
</script>
</body>
</html>
```