Prompt specification
Build or customize the Three.js 3D scene "Courtyard edible pergola" 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: Courtyard edible pergola
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-edible-pergola-x1115
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: courtyard edible pergola. Compose a small pergola with climbing plants, raised bed, bench, and path; leaves provide patterned shade while training ties remain visible at selected support contacts.
Working Three.js Starter (courtyard-edible-pergola-x1115):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Courtyard Edible Pergola</title>
<style>
:root {
--ink: #263c32;
--muted: #617269;
--cream: #f5f0e5;
--glass: rgba(248, 245, 235, 0.86);
--accent: #df704b;
--leaf: #54745c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce6dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(241, 238, 224, 0.22), transparent 28%),
radial-gradient(circle at 52% 45%, transparent 52%, rgba(33, 54, 43, 0.12) 120%);
}
.masthead {
position: fixed;
top: clamp(20px, 4vw, 48px);
left: clamp(20px, 4vw, 58px);
width: min(390px, calc(100vw - 40px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 14px;
color: #50685a;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5vw, 68px);
font-weight: 400;
line-height: 0.94;
letter-spacing: -0.055em;
text-wrap: balance;
}
h1 em {
color: #52705c;
font-weight: 400;
}
.subtitle {
max-width: 335px;
margin: 18px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.actions {
position: fixed;
top: clamp(20px, 4vw, 42px);
right: clamp(18px, 3vw, 42px);
display: flex;
gap: 8px;
}
.action {
min-height: 38px;
padding: 0 15px;
border: 1px solid rgba(46, 67, 55, 0.18);
border-radius: 999px;
background: var(--glass);
color: var(--ink);
box-shadow: 0 8px 30px rgba(39, 58, 47, 0.08);
backdrop-filter: blur(12px);
cursor: pointer;
transition:
transform 160ms ease,
background 160ms ease;
}
.action:hover {
transform: translateY(-2px);
background: rgba(255, 253, 245, 0.96);
}
.action[aria-pressed="true"] {
border-color: rgba(223, 112, 75, 0.45);
background: #f7dfd1;
}
.legend {
position: fixed;
bottom: clamp(20px, 4vw, 44px);
left: clamp(20px, 4vw, 58px);
display: flex;
flex-wrap: wrap;
gap: 18px;
max-width: calc(100vw - 40px);
padding: 12px 16px;
border: 1px solid rgba(48, 70, 57, 0.12);
border-radius: 13px;
background: rgba(248, 245, 235, 0.76);
box-shadow: 0 12px 40px rgba(40, 58, 48, 0.08);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #52665a;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--leaf);
}
.swatch.tie {
background: var(--accent);
box-shadow: 0 0 0 3px rgba(223, 112, 75, 0.14);
}
.swatch.bed {
background: #aa7751;
}
.hint {
position: fixed;
right: clamp(18px, 3vw, 42px);
bottom: clamp(22px, 4vw, 47px);
color: rgba(39, 61, 49, 0.72);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
.zoom-controls {
position: fixed;
right: clamp(18px, 3vw, 42px);
bottom: 76px;
display: flex;
gap: 6px;
}
.zoom {
width: 38px;
height: 38px;
border: 1px solid rgba(46, 67, 55, 0.17);
border-radius: 50%;
background: var(--glass);
color: var(--ink);
font-size: 20px;
cursor: pointer;
backdrop-filter: blur(10px);
}
.marker {
position: fixed;
z-index: 5;
display: flex;
align-items: center;
gap: 8px;
transform: translate(-9px, -9px);
pointer-events: none;
}
.marker i {
position: relative;
display: block;
width: 18px;
height: 18px;
border: 3px solid rgba(255, 249, 235, 0.94);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 3px 14px rgba(120, 54, 34, 0.3);
}
.marker i::after {
position: absolute;
inset: -7px;
border: 1px solid rgba(223, 112, 75, 0.4);
border-radius: 50%;
content: "";
animation: ping 2.8s ease-out infinite;
}
.marker span {
padding: 5px 8px;
border-radius: 5px;
background: rgba(249, 242, 228, 0.88);
color: #82503d;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
opacity: 0;
text-transform: uppercase;
transform: translateX(-4px);
transition: 180ms ease;
white-space: nowrap;
}
.marker:hover span {
opacity: 1;
transform: translateX(0);
}
@keyframes ping {
0% {
opacity: 0;
transform: scale(0.75);
}
30% {
opacity: 1;
}
100% {
opacity: 0;
transform: scale(1.4);
}
}
@media (max-width: 720px) {
.masthead {
top: 20px;
left: 20px;
}
h1 {
font-size: 42px;
}
.subtitle {
display: none;
}
.actions {
top: auto;
right: 16px;
bottom: 78px;
}
.action {
min-height: 34px;
padding: 0 12px;
font-size: 11px;
}
.legend {
right: 16px;
bottom: 16px;
left: 16px;
gap: 11px;
}
.legend-item {
font-size: 8px;
}
.hint {
display: none;
}
.zoom-controls {
right: 16px;
bottom: 128px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive three-dimensional courtyard edible pergola"></main>
<div class="vignette"></div>
<header class="masthead">
<div class="eyebrow">Courtyard study · No. 04</div>
<h1>The edible<br /><em>arbour</em></h1>
<p class="subtitle">
A sunlit timber structure trained with tomatoes, beans, salad greens,
and the visible rhythm of garden ties.
</p>
</header>
<div class="actions">
<button class="action" id="autoOrbit" aria-pressed="false">Auto orbit</button>
<button class="action" id="resetView">Reset view</button>
</div>
<div class="legend" aria-hidden="true">
<div class="legend-item"><i class="swatch"></i>Dappled leaf shade</div>
<div class="legend-item"><i class="swatch bed"></i>Raised edible bed</div>
<div class="legend-item"><i class="swatch tie"></i>Training ties</div>
</div>
<div class="zoom-controls">
<button class="zoom" id="zoomOut" aria-label="Zoom out">−</button>
<button class="zoom" id="zoomIn" aria-label="Zoom in">+</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Arrow keys to look</div>
<div class="marker" id="marker0"><i></i><span>Training tie</span></div>
<div class="marker" id="marker1"><i></i><span>Support contact</span></div>
<div class="marker" id="marker2"><i></i><span>Visible tie</span></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and camera
// ------------------------------------------------------------
const mount = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.08;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdde7de);
scene.fog = new THREE.Fog(0xdde7de, 18, 35);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
// Direct camera controls; no OrbitControls or addons are used.
const initialView = {
theta: 0.72,
phi: 1.12,
radius: 15.4
};
const controls = {
target: { ...initialView },
current: { ...initialView },
focus: new THREE.Vector3(-1.0, 1.55, -0.8),
dragging: false,
pointerId: null,
lastX: 0,
lastY: 0,
autoOrbit: false
};
function updateCamera(dt = 1) {
const smoothing = 1 - Math.exp(-dt * 8);
controls.current.theta +=
(controls.target.theta - controls.current.theta) * smoothing;
controls.current.phi +=
(controls.target.phi - controls.current.phi) * smoothing;
controls.current.radius +=
(controls.target.radius - controls.current.radius) * smoothing;
const { theta, phi, radius } = controls.current;
camera.position.set(
controls.focus.x + radius * Math.sin(phi) * Math.sin(theta),
controls.focus.y + radius * Math.cos(phi),
controls.focus.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(controls.focus);
}
updateCamera();
// ------------------------------------------------------------
// Deterministic random helpers and geometry utilities
// ------------------------------------------------------------
let seed = 42073;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
...options
});
}
function addMesh(
geometry,
material,
x = 0,
y = 0,
z = 0,
parent = scene,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, material, x, y, z, parent = scene) {
return addMesh(
new THREE.BoxGeometry(w, h, d),
material,
x,
y,
z,
parent
);
}
function addTube(points, radius, material, parent = scene, segments = 32) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) =>
point.isVector3 ? point : new THREE.Vector3(...point)
)
);
const mesh = addMesh(
new THREE.TubeGeometry(curve, segments, radius, 6, false),
material,
0,
0,
0,
parent
);
return { mesh, curve };
}
function makeCanvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
draw(canvas.getContext("2d"), width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
// ------------------------------------------------------------
// Materials and procedural textures
// ------------------------------------------------------------
const woodTexture = makeCanvasTexture(256, 256, (ctx, w, h) => {
ctx.fillStyle = "#a57850";
ctx.fillRect(0, 0, w, h);
for (let i = 0; i < 80; i++) {
const x = range(0, w);
ctx.strokeStyle = `rgba(66, 40, 22, ${range(0.025, 0.11)})`;
ctx.lineWidth = range(0.5, 2.2);
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.bezierCurveTo(
x + range(-8, 8),
h * 0.3,
x + range(-8, 8),
h * 0.65,
x + range(-5, 5),
h
);
ctx.stroke();
}
for (let i = 0; i < 12; i++) {
ctx.fillStyle = "rgba(58, 35, 20, 0.06)";
ctx.beginPath();
ctx.ellipse(
range(0, w),
range(0, h),
range(2, 7),
range(8, 28),
0,
0,
Math.PI * 2
);
ctx.fill();
}
});
woodTexture.wrapS = woodTexture.wrapT = THREE.RepeatWrapping;
woodTexture.repeat.set(2, 2);
const pavingTexture = makeCanvasTexture(1024, 1024, (ctx, w, h) => {
ctx.fillStyle = "#ded4c0";
ctx.fillRect(0, 0, w, h);
const tile = 128;
for (let y = 0; y < h; y += tile) {
for (let x = 0; x < w; x += tile) {
const shade = Math.floor(range(-5, 6));
ctx.fillStyle = `rgb(${222 + shade}, ${211 + shade}, ${190 + shade})`;
ctx.fillRect(x + 2, y + 2, tile - 4, tile - 4);
ctx.strokeStyle = "rgba(117, 109, 92, 0.16)";
ctx.lineWidth = 2;
ctx.strokeRect(x + 2, y + 2, tile - 4, tile - 4);
}
}
for (let i = 0; i < 2400; i++) {
ctx.fillStyle = `rgba(89, 78, 58, ${range(0.015, 0.055)})`;
ctx.fillRect(range(0, w), range(0, h), 1, 1);
}
});
pavingTexture.wrapS = pavingTexture.wrapT = THREE.RepeatWrapping;
pavingTexture.repeat.set(7, 7);
const signTexture = makeCanvasTexture(512, 160, (ctx, w, h) => {
ctx.fillStyle = "#eee5cc";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#526a58";
ctx.lineWidth = 7;
ctx.strokeRect(14, 14, w - 28, h - 28);
ctx.fillStyle = "#415947";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "italic 49px Georgia";
ctx.fillText("Edible Arbour", w / 2, h / 2 + 2);
});
const wood = standardMaterial(0xc09a72, { map: woodTexture });
const woodDark = standardMaterial(0x8f6a48, { map: woodTexture });
const woodLight = standardMaterial(0xd2ad83, { map: woodTexture });
const metal = standardMaterial(0x344d40, {
roughness: 0.56,
metalness: 0.22
});
const wallMaterial = standardMaterial(0xe8dfcd, { roughness: 0.98 });
const stone = standardMaterial(0xc4b9a4, { roughness: 0.95 });
const soil = standardMaterial(0x584637, { roughness: 1 });
const vineMaterial = standardMaterial(0x62734a, { roughness: 0.92 });
const vineWood = standardMaterial(0x6d583b, { roughness: 0.94 });
const stemMaterial = standardMaterial(0x587248, { roughness: 0.93 });
const terracotta = standardMaterial(0xb96f4e, { roughness: 0.88 });
const tomatoRed = standardMaterial(0xd9573e, { roughness: 0.48 });
const tomatoOrange = standardMaterial(0xe69b43, { roughness: 0.52 });
const carrotMaterial = standardMaterial(0xd9823c, { roughness: 0.76 });
const tieMaterial = standardMaterial(0xe1714a, { roughness: 0.66 });
// ------------------------------------------------------------
// Courtyard ground and walls
// ------------------------------------------------------------
const ground = addMesh(
new THREE.PlaneGeometry(28, 28),
standardMaterial(0xffffff, { map: pavingTexture }),
0,
0,
0,
scene,
false,
true
);
ground.rotation.x = -Math.PI / 2;
addBox(19.2, 4.7, 0.3, wallMaterial, -0.6, 2.35, -7.2);
addBox(0.3, 4.7, 10.9, wallMaterial, -9.6, 2.35, -1.7);
addBox(19.35, 0.13, 0.42, stone, -0.6, 4.73, -7.2);
addBox(0.42, 0.13, 11, stone, -9.6, 4.73, -1.7);
// A painted courtyard door and simple frame.
const doorMaterial = standardMaterial(0x688b83, { roughness: 0.78 });
addBox(2.15, 3.15, 0.1, doorMaterial, 4.7, 1.58, -7.01);
addBox(2.4, 0.13, 0.14, woodLight, 4.7, 3.22, -6.94);
addBox(0.13, 3.25, 0.14, woodLight, 3.57, 1.62, -6.94);
addBox(0.13, 3.25, 0.14, woodLight, 5.83, 1.62, -6.94);
addBox(1.48, 1.25, 0.04, standardMaterial(0x759891), 4.7, 2.15, -6.94);
addBox(1.48, 1.25, 0.04, standardMaterial(0x759891), 4.7, 0.9, -6.94);
addMesh(
new THREE.SphereGeometry(0.075, 14, 10),
metal,
5.48,
1.46,
-6.86
);
// ------------------------------------------------------------
// Pergola structure
// ------------------------------------------------------------
const pergola = new THREE.Group();
scene.add(pergola);
const leftX = -5.1;
const rightX = 1.6;
const backZ = -3.4;
const frontZ = 0.7;
const postTop = 3.32;
for (const x of [leftX, rightX]) {
for (const z of [backZ, frontZ]) {
addBox(0.26, postTop, 0.26, wood, x, postTop / 2, z, pergola);
addBox(0.49, 0.28, 0.49, stone, x, 0.14, z, pergola);
addBox(0.34, 0.08, 0.34, woodDark, x, 0.29, z, pergola);
}
}
// Main perimeter beams.
addBox(7.05, 0.28, 0.25, woodDark, -1.75, 3.36, backZ, pergola);
addBox(7.05, 0.28, 0.25, woodDark, -1.75, 3.36, frontZ, pergola);
addBox(0.25, 0.28, 4.55, woodDark, leftX, 3.36, -1.35, pergola);
addBox(0.25, 0.28, 4.55, woodDark, rightX, 3.36, -1.35, pergola);
// Rafters and finer cross slats.
for (let x = leftX + 0.22; x <= rightX - 0.12; x += 0.53) {
addBox(0.12, 0.19, 4.75, wood, x, 3.57, -1.35, pergola);
}
for (let z = backZ + 0.22; z <= frontZ - 0.12; z += 0.51) {
addBox(6.86, 0.095, 0.105, woodLight, -1.75, 3.78, z, pergola);
}
// Corner braces.
const brace = addBox(
0.9,
0.13,
0.13,
wood,
rightX - 0.34,
3.02,
frontZ,
pergola
);
brace.rotation.z = Math.PI / 4;
const leftBrace = addBox(
0.9,
0.13,
0.13,
wood,
leftX + 0.34,
3.02,
backZ,
pergola
);
leftBrace.rotation.z = -Math.PI / 4;
const sign = addMesh(
new THREE.PlaneGeometry(1.18, 0.37),
standardMaterial(0xffffff, {
map: signTexture,
roughness: 0.9,
side: THREE.DoubleSide
}),
0.3,
3.29,
0.835,
pergola
);
// ------------------------------------------------------------
// Raised bed
// ------------------------------------------------------------
const bedX = -1.7;
const bedZ = -1.35;
const bedW = 4.65;
const bedD = 2.15;
for (let i = 0; i < 3; i++) {
const y = 0.18 + i * 0.17;
addBox(bedW, 0.145, 0.13, wood, bedX, y, bedZ - bedD / 2, pergola);
addBox(bedW, 0.145, 0.13, wood, bedX, y, bedZ + bedD / 2, pergola);
addBox(0.13, 0.145, bedD, wood, bedX - bedW / 2, y, bedZ, pergola);
addBox(0.13, 0.145, bedD, wood, bedX + bedW / 2, y, bedZ, pergola);
}
for (const x of [bedX - bedW / 2, bedX + bedW / 2]) {
for (const z of [bedZ - bedD / 2, bedZ + bedD / 2]) {
addBox(0.19, 0.75, 0.19, woodDark, x, 0.375, z, pergola);
}
}
addBox(
bedW - 0.2,
0.16,
bedD - 0.2,
soil,
bedX,
0.55,
bedZ,
pergola
);
// ------------------------------------------------------------
// Custom leaf geometry and instanced foliage
// ------------------------------------------------------------
function createLeafGeometry() {
const longitudinal = 9;
const transverse = 4;
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= longitudinal; i++) {
const t = i / longitudinal;
const halfWidth =
0.29 * Math.pow(Math.sin(Math.PI * t), 0.72) * (1 - 0.13 * t);
for (let j = 0; j <= transverse; j++) {
const s = (j / transverse) * 2 - 1;
const x = s * halfWidth;
const y = t;
const z =
0.085 * (1 - s * s) * Math.sin(Math.PI * t) +
0.025 * Math.sin(t * Math.PI * 2);
positions.push(x, y, z);
uvs.push((s + 1) / 2, t);
}
}
for (let i = 0; i < longitudinal; i++) {
for (let j = 0; j < transverse; j++) {
const a = i * (transverse + 1) + j;
const b = a + transverse + 1;
const c = b + 1;
const d = a + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const leafGeometry = createLeafGeometry();
const leafMaterial = standardMaterial(0xffffff, {
side: THREE.DoubleSide,
roughness: 0.87
});
const leafData = [];
const up = new THREE.Vector3(0, 1, 0);
function leafColor(minLight = 0.24, maxLight = 0.47) {
return new THREE.Color().setHSL(
range(0.245, 0.33),
range(0.34, 0.58),
range(minLight, maxLight)
);
}
function addLeafData(
position,
direction,
scale,
color = leafColor(),
horizontal = false
) {
const quaternion = new THREE.Quaternion();
if (horizontal) {
quaternion.setFromEuler(
new THREE.Euler(
-Math.PI / 2 + range(-0.3, 0.3),
range(-Math.PI, Math.PI),
range(-0.5, 0.5),
"XYZ"
)
);
} else {
quaternion.setFromUnitVectors(up, direction.clone().normalize());
quaternion.multiply(
new THREE.Quaternion().setFromAxisAngle(up, range(-0.9, 0.9))
);
}
leafData.push({
position: position.clone(),
quaternion,
scale: new THREE.Vector3(scale * range(0.84, 1.06), scale, scale),
color
});
}
// Canopy leaves are grouped to preserve patterned gaps in the shade.
const canopyClusters = [
[-4.55, -2.85],
[-2.45, -3.0],
[0.35, -2.65],
[-4.5, -0.85],
[-2.2, -1.25],
[0.55, -1.05],
[-3.25, 0.25],
[-0.6, -0.15]
];
for (let i = 0; i < 162; i++) {
const cluster = canopyClusters[i % canopyClusters.length];
const x = cluster[0] + range(-1.15, 1.15);
const z = cluster[1] + range(-0.78, 0.78);
const y = range(3.72, 3.92);
addLeafData(
new THREE.Vector3(x, y, z),
new THREE.Vector3(range(-1, 1), range(-0.2, 0.2), range(-1, 1)),
range(0.4, 0.7),
leafColor(0.22, 0.46),
true
);
}
// Small woody branches visible between the leaf clusters.
for (const cluster of canopyClusters) {
const x = cluster[0];
const z = cluster[1];
addTube(
[
[x - 0.8, 3.73, z - 0.25],
[x, 3.79, z],
[x + 0.85, 3.74, z + 0.2]
],
0.019,
vineWood,
pergola,
18
);
}
// ------------------------------------------------------------
// Climbing tomato vines
// ------------------------------------------------------------
const vineDefinitions = [
[
[0.35, 0.65, -0.8],
[1.43, 0.62, 0.68],
[1.51, 1.35, 0.72],
[1.46, 2.28, 0.68],
[1.54, 3.25, 0.71],
[0.75, 3.63, 0.4],
[-0.45, 3.74, 0.1],
[-1.75, 3.73, -0.35],
[-3.4, 3.69, -0.85],
[-4.85, 3.58, -1.4]
],
[
[0.35, 0.65, -1.85],
[1.43, 0.6, -3.27],
[1.49, 1.5, -3.32],
[1.48, 2.55, -3.26],
[1.53, 3.3, -3.31],
[0.45, 3.68, -3.46],
[-0.9, 3.74, -3.5]
],
[
[-3.2, 0.65, -1.85],
[-4.9, 0.66, -3.28],
[-5.02, 1.4, -3.32],
[-4.98, 2.35, -3.24],
[-5.01, 3.23, -3.31],
[-4.2, 3.64, -3.42],
[-3.1, 3.75, -3.3]
],
[
[-3.4, 0.65, -0.75],
[-4.91, 0.64, 0.68],
[-5.02, 1.5, 0.72],
[-4.96, 2.55, 0.67],
[-5.01, 3.25, 0.7],
[-4.15, 3.65, 0.3],
[-3.0, 3.76, 0.05]
]
];
for (const definition of vineDefinitions) {
const { curve } = addTube(
definition,
0.042,
vineMaterial,
pergola,
70
);
for (let i = 0; i < 58; i++) {
const t = range(0.03, 0.98);
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
const angle = range(0, Math.PI * 2);
const radial = new THREE.Vector3(
Math.cos(angle),
0,
Math.sin(angle)
);
const position = point
.clone()
.addScaledVector(radial, range(0.025, 0.14));
const direction = radial
.clone()
.multiplyScalar(0.85)
.addScaledVector(tangent, range(0.05, 0.42));
if (t > 0.64) direction.y -= range(0.18, 0.58);
addLeafData(
position,
direction,
range(0.25, 0.47),
leafColor(0.23, 0.43)
);
}
}
// ------------------------------------------------------------
// Edible plants in the raised bed
// ------------------------------------------------------------
function addFruitCluster(x, y, z, count = 5, scale = 1) {
const fruitMaterial = random() > 0.45 ? tomatoRed : tomatoOrange;
addTube(
[
[x, y + 0.22, z],
[x + 0.05, y + 0.08, z],
[x + 0.02, y - 0.12, z + 0.02]
],
0.012 * scale,
stemMaterial,
pergola,
12
);
for (let i = 0; i < count; i++) {
const angle = range(0, Math.PI * 2);
const radius = range(0.05, 0.18) * scale;
const fruit = addMesh(
new THREE.SphereGeometry(range(0.085, 0.12) * scale, 16, 12),
fruitMaterial,
x + Math.cos(angle) * radius,
y - range(0.08, 0.28) * scale,
z + Math.sin(angle) * radius,
pergola
);
fruit.scale.y = range(0.9, 1.08);
}
}
function makeTomatoPlant(x, z, height = 1) {
addTube(
[
[x, 0.62, z],
[x - 0.04, 0.95 * height, z + 0.02],
[x + 0.05, 1.36 * height, z - 0.03],
[x, 1.68 * height, z]
],
0.026,
stemMaterial,
pergola,
24
);
for (let i = 0; i < 13; i++) {
const y = range(0.76, 1.55) * height;
const angle = range(0, Math.PI * 2);
const direction = new THREE.Vector3(
Math.cos(angle),
range(-0.05, 0.45),
Math.sin(angle)
);
addLeafData(
new THREE.Vector3(x, y, z),
direction,
range(0.25, 0.39),
leafColor(0.23, 0.4)
);
}
addFruitCluster(x + 0.12, 1.02 * height, z + 0.04, 4, 0.7);
}
function makeLettuce(x, z, size = 1) {
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2 + range(-0.15, 0.15);
const direction = new THREE.Vector3(
Math.cos(angle),
range(0.35, 0.85),
Math.sin(angle)
);
addLeafData(
new THREE.Vector3(x, 0.65, z),
direction,
range(0.26, 0.38) * size,
leafColor(0.3, 0.49)
);
}
addMesh(
new THREE.SphereGeometry(0.1 * size, 14, 10),
leafColor(0.35, 0.46),
x,
0.68,
z,
pergola
);
}
function makeCarrot(x, z) {
const carrot = addMesh(
new THREE.ConeGeometry(0.085, 0.28, 10),
carrotMaterial,
x,
0.67,
z,
pergola
);
carrot.rotation.z = Math.PI;
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
addLeafData(
new THREE.Vector3(x, 0.79, z),
new THREE.Vector3(
Math.cos(angle) * 0.55,
1,
Math.sin(angle) * 0.55
),
range(0.22, 0.3),
leafColor(0.27, 0.45)
);
}
}
makeTomatoPlant(-3.35, -1.75, 0.94);
makeTomatoPlant(-2.5, -1.1, 0.82);
makeTomatoPlant(-3.2, -0.75, 0.75);
makeLettuce(-0.65, -1.95, 1.0);
makeLettuce(-0.55, -1.05, 0.85);
makeLettuce(-1.35, -0.63, 0.76);
makeCarrot(-1.65, -2.0);
makeCarrot(-1.95, -1.48);
makeCarrot(-1.35, -1.95);
// Hanging fruit from the trained overhead vines.
addFruitCluster(-0.45, 3.12, 0.1, 6, 1.0);
addFruitCluster(-2.65, 3.04, -0.62, 5, 0.92);
addFruitCluster(1.0, 2.86, -1.2, 4, 0.82);
addFruitCluster(-3.8, 3.08, -1.45, 4, 0.78);
// ------------------------------------------------------------
// Stepping-stone path
// ------------------------------------------------------------
const pathStones = [
[-1.15, 7.1, 0.64],
[-1.55, 6.0, 0.61],
[-1.18, 4.95, 0.65],
[-1.72, 3.88, 0.62],
[-1.37, 2.83, 0.64],
[-1.7, 1.79, 0.68]
];
for (let i = 0; i < pathStones.length; i++) {
const [x, z, radius] = pathStones[i];
const stoneMesh = addMesh(
new THREE.CylinderGeometry(radius, radius * 0.94, 0.13, 7),
standardMaterial(i % 2 ? 0xc7bca7 : 0xd0c5b1),
x,
0.075,
z,
scene
);
stoneMesh.rotation.y = range(0, Math.PI);
stoneMesh.scale.z = range(0.78, 1.04);
}
// A short side path toward the bench.
for (let i = 0; i < 3; i++) {
const stoneMesh = addMesh(
new THREE.CylinderGeometry(0.52, 0.5, 0.11, 7),
stone,
2.25 + i * 0.77,
0.065,
3.2 - i * 0.48,
scene
);
stoneMesh.rotation.y = range(0, Math.PI);
}
// ------------------------------------------------------------
// Bench
// ------------------------------------------------------------
const bench = new THREE.Group();
bench.position.set(3.55, 0, -0.25);
bench.rotation.y = Math.PI / 2;
scene.add(bench);
for (let i = 0; i < 4; i++) {
addBox(
2.75,
0.12,
0.16,
woodLight,
0,
0.72,
-0.25 + i * 0.17,
bench
);
}
for (const x of [-1.12, 1.12]) {
addBox(0.12, 0.78, 0.12, metal, x, 0.38, 0.2, bench);
addBox(0.12, 0.78, 0.12, metal, x, 0.38, -0.25, bench);
addBox(0.12, 1.13, 0.12, metal, x, 0.56, -0.36, bench);
addBox(0.14, 0.12, 0.82, metal, x, 1.08, -0.02, bench);
addBox(0.1, 0.1, 0.78, metal, x, 0.35, 0, bench);
}
for (let i = 0; i < 3; i++) {
addBox(
2.65,
0.16,
0.12,
wood,
0,
1.02 + i * 0.22,
-0.37,
bench
);
}
// ------------------------------------------------------------
// Pots and small courtyard planting
// ------------------------------------------------------------
function makePot(x, z, scale = 1, tree = false) {
const potGroup = new THREE.Group();
potGroup.position.set(x, 0, z);
potGroup.scale.setScalar(scale);
scene.add(potGroup);
addMesh(
new THREE.CylinderGeometry(0.34, 0.26, 0.58, 18),
terracotta,
0,
0.29,
0,
potGroup
);
const rim = addMesh(
new THREE.TorusGeometry(0.32, 0.045, 8, 24),
terracotta,
0,
0.57,
0,
potGroup
);
rim.rotation.x = Math.PI / 2;
addMesh(
new THREE.CylinderGeometry(0.285, 0.285, 0.035, 18),
soil,
0,
0.575,
0,
potGroup,
false,
true
);
if (tree) {
addTube(
[
[0, 0.58, 0],
[0.03, 1.2, 0],
[-0.04, 1.85, 0.02]
],
0.055,
woodDark,
potGroup,
24
);
for (let i = 0; i < 26; i++) {
const angle = range(0, Math.PI * 2);
const y = range(1.05, 2.05);
const radius = range(0.12, 0.48);
addLeafData(
new THREE.Vector3(x, y, z),
new THREE.Vector3(
Math.cos(angle),
range(-0.15, 0.55),
Math.sin(angle)
),
range(0.28, 0.45),
leafColor(0.25, 0.44)
);
}
} else {
for (let i = 0; i < 13; i++) {
const angle = range(0, Math.PI * 2);
addLeafData(
new THREE.Vector3(x, 0.59, z),
new THREE.Vector3(
Math.cos(angle),
range(0.55, 1),
Math.sin(angle)
),
range(0.25, 0.4),
leafColor(0.27, 0.47)
);
}
}
}
makePot(5.05, 2.15, 1.15);
makePot(6.08, 1.08, 0.82);
makePot(6.45, -5.75, 1.35, true);
// ------------------------------------------------------------
// Visible training ties at selected support contacts
// ------------------------------------------------------------
const markerPoints = [];
function makePostTie(x, z, y) {
const ring = addMesh(
new THREE.TorusGeometry(0.18, 0.024, 8, 28),
tieMaterial,
x,
y,
z
);
ring.rotation.x = Math.PI / 2;
const knotPosition = new THREE.Vector3(x + 0.15, y, z + 0.13);
addMesh(
new THREE.SphereGeometry(0.052, 12, 9),
tieMaterial,
knotPosition.x,
knotPosition.y,
knotPosition.z
);
addTube(
[
knotPosition,
knotPosition.clone().add(new THREE.Vector3(0.025, -0.1, 0.02)),
knotPosition.clone().add(new THREE.Vector3(0.08, -0.29, 0.045))
],
0.017,
tieMaterial,
scene,
12
);
return knotPosition;
}
function makeRoofTie(x, z, alongX = true) {
const ring = addMesh(
new THREE.TorusGeometry(0.18, 0.024, 8, 28),
tieMaterial,
x,
3.37,
z
);
if (alongX) {
ring.rotation.y = Math.PI / 2;
}
const knotPosition = alongX
? new THREE.Vector3(x + 0.02, 3.37, z + 0.16)
: new THREE.Vector3(x + 0.16, 3.37, z + 0.02);
addMesh(
new THREE.SphereGeometry(0.052, 12, 9),
tieMaterial,
knotPosition.x,
knotPosition.y,
knotPosition.z
);
addTube(
[
knotPosition,
knotPosition.clone().add(new THREE.Vector3(0.015, -0.1, 0.015)),
knotPosition.clone().add(new THREE.Vector3(0.06, -0.28, 0.035))
],
0.017,
tieMaterial,
scene,
12
);
return knotPosition;
}
markerPoints.push(makePostTie(rightX, frontZ, 1.28));
markerPoints.push(makePostTie(rightX, frontZ, 2.48));
markerPoints.push(makeRoofTie(-0.45, frontZ, true));
markerPoints.push(makeRoofTie(leftX, -0.8, false));
// ------------------------------------------------------------
// Commit all leaf instances
// ------------------------------------------------------------
const leafMesh = new THREE.InstancedMesh(
leafGeometry,
leafMaterial,
leafData.length
);
leafMesh.castShadow = true;
leafMesh.receiveShadow = true;
leafMesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
const dummy = new THREE.Object3D();
leafData.forEach((leaf, index) => {
dummy.position.copy(leaf.position);
dummy.quaternion.copy(leaf.quaternion);
dummy.scale.copy(leaf.scale);
dummy.updateMatrix();
leafMesh.setMatrixAt(index, dummy.matrix);
leafMesh.setColorAt(index, leaf.color);
});
leafMesh.instanceMatrix.needsUpdate = true;
leafMesh.instanceColor.needsUpdate = true;
scene.add(leafMesh);
// ------------------------------------------------------------
// Lighting and atmospheric pollen
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf1f6eb, 0x9b8060, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6b9, 3.15);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 36;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.018;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xd5e6e0, 0.72);
fill.position.set(9, 6, -3);
scene.add(fill);
const pollenCount = 90;
const pollenPositions = new Float32Array(pollenCount * 3);
for (let i = 0; i < pollenCount; i++) {
pollenPositions[i * 3] = range(-8, 7);
pollenPositions[i * 3 + 1] = range(0.5, 6.2);
pollenPositions[i * 3 + 2] = range(-6, 7);
}
const pollenGeometry = new THREE.BufferGeometry();
pollenGeometry.setAttribute(
"position",
new THREE.BufferAttribute(pollenPositions, 3)
);
const pollen = new THREE.Points(
pollenGeometry,
new THREE.PointsMaterial({
color: 0xfff2c8,
size: 0.045,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
scene.add(pollen);
// ------------------------------------------------------------
// Pointer, wheel, touch, keyboard, and UI controls
// ------------------------------------------------------------
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
if (!event.isPrimary) return;
controls.dragging = true;
controls.pointerId = event.pointerId;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging || event.pointerId !== controls.pointerId) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.target.theta -= dx * 0.006;
controls.target.phi = THREE.MathUtils.clamp(
controls.target.phi - dy * 0.005,
0.58,
1.4
);
});
function endDrag(event) {
if (event.pointerId !== controls.pointerId) return;
controls.dragging = false;
controls.pointerId = null;
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();
controls.target.radius = THREE.MathUtils.clamp(
controls.target.radius + event.deltaY * 0.012,
9,
22
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
window.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") controls.target.theta += step;
if (event.key === "ArrowRight") controls.target.theta -= step;
if (event.key === "ArrowUp") {
controls.target.phi = Math.max(0.58, controls.target.phi - step);
}
if (event.key === "ArrowDown") {
controls.target.phi = Math.min(1.4, controls.target.phi + step);
}
if (event.key === "+" || event.key === "=") {
controls.target.radius = Math.max(9, controls.target.radius - 1);
}
if (event.key === "-" || event.key === "_") {
controls.target.radius = Math.min(22, controls.target.radius + 1);
}
});
const autoOrbitButton = document.querySelector("#autoOrbit");
autoOrbitButton.addEventListener("click", () => {
controls.autoOrbit = !controls.autoOrbit;
autoOrbitButton.setAttribute("aria-pressed", String(controls.autoOrbit));
autoOrbitButton.textContent = controls.autoOrbit ? "Pause orbit" : "Auto orbit";
});
document.querySelector("#resetView").addEventListener("click", () => {
controls.target = { ...initialView };
controls.autoOrbit = false;
autoOrbitButton.setAttribute("aria-pressed", "false");
autoOrbitButton.textContent = "Auto orbit";
});
document.querySelector("#zoomIn").addEventListener("click", () => {
controls.target.radius = Math.max(9, controls.target.radius - 1.3);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
controls.target.radius = Math.min(22, controls.target.radius + 1.3);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------
// DOM markers follow their tie positions in screen space
// ------------------------------------------------------------
const markerElements = [
document.querySelector("#marker0"),
document.querySelector("#marker1"),
document.querySelector("#marker2")
];
const projected = new THREE.Vector3();
function updateMarkers() {
markerElements.forEach((element, index) => {
projected.copy(markerPoints[index]).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
});
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
if (controls.autoOrbit) {
controls.target.theta += dt * 0.16;
}
updateCamera(dt);
const pollenAttribute = pollenGeometry.getAttribute("position");
for (let i = 0; i < pollenCount; i++) {
const yIndex = i * 3 + 1;
pollenAttribute.array[yIndex] += dt * 0.035;
if (pollenAttribute.array[yIndex] > 6.4) {
pollenAttribute.array[yIndex] = 0.45;
}
}
pollenAttribute.needsUpdate = true;
updateMarkers();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```