Prompt specification
Build or customize the Three.js 3D scene "Community rooftop growing space" 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: Community rooftop growing space
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/community-rooftop-growing-space-x1119
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing urban rooftop farming. Compose raised beds, tool storage, shaded seating, and broad paths on a bounded roof garden; volunteers share harvesting and maintenance without obscuring access routes. Stylized solid forms.
Working Three.js Starter (community-rooftop-growing-space-x1119):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rooftop Commons — Urban Rooftop Farming</title>
<style>
:root {
--ink: #173a35;
--muted: #55706a;
--glass: rgba(250, 253, 247, 0.9);
--line: rgba(23, 58, 53, 0.14);
--accent: #e2784f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e7;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.intro {
position: fixed;
top: 24px;
left: 24px;
z-index: 2;
width: min(360px, calc(100vw - 48px));
padding: 18px 20px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--glass);
box-shadow: 0 14px 38px rgba(32, 66, 61, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(226, 120, 79, 0.14);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
line-height: 1;
letter-spacing: -0.04em;
}
.intro p {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.route {
display: flex;
align-items: center;
gap: 9px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #34645a;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.route svg {
flex: 0 0 auto;
width: 18px;
height: 18px;
}
.controls {
position: fixed;
top: 24px;
right: 24px;
z-index: 3;
display: flex;
gap: 8px;
}
button {
min-height: 42px;
padding: 0 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--glass);
color: var(--ink);
box-shadow: 0 8px 24px rgba(32, 66, 61, 0.1);
backdrop-filter: blur(12px);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 750;
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fffef8;
}
button:focus-visible {
outline: 3px solid rgba(226, 120, 79, 0.35);
outline-offset: 2px;
}
.legend {
position: fixed;
bottom: 24px;
left: 24px;
z-index: 2;
display: flex;
flex-wrap: wrap;
gap: 9px 17px;
max-width: calc(100vw - 48px);
padding: 12px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--glass);
box-shadow: 0 10px 28px rgba(32, 66, 61, 0.1);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
.hint {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 2;
padding: 10px 13px;
border-radius: 12px;
background: rgba(23, 58, 53, 0.78);
color: #f4f8ef;
font-size: 11px;
font-weight: 650;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 680px) {
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 16px;
}
.intro p {
display: none;
}
.route {
margin-top: 10px;
padding-top: 10px;
}
.controls {
top: auto;
right: 14px;
bottom: 62px;
}
.legend {
right: 14px;
bottom: 14px;
left: 14px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive 3D rooftop community garden"></main>
<section class="intro">
<div class="eyebrow">Shared urban harvest</div>
<h1>Rooftop Commons</h1>
<p>
Raised beds, shared tools, shaded seating, and an open circulation spine
for a productive neighborhood garden.
</p>
<div class="route">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path
d="M4 4v16h16M4 12h10m0-4h6m-6 8h6"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
Wide access routes remain unobstructed
</div>
</section>
<nav class="controls" aria-label="Camera controls">
<button id="reset-view" type="button">Reset view</button>
<button id="plan-view" type="button">Plan view</button>
</nav>
<div class="legend" aria-label="Scene legend">
<span><i class="swatch" style="background:#4f9255"></i>Crop beds</span>
<span><i class="swatch" style="background:#d8c39a"></i>Wide paths</span>
<span><i class="swatch" style="background:#377b77"></i>Tool storage</span>
<span><i class="swatch" style="background:#df9e54"></i>Shaded seating</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click 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 and scene
// ------------------------------------------------------------
const host = 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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional rooftop farm with raised beds, volunteers, tools, paths, and seating"
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e7);
scene.fog = new THREE.Fog(0xdce9e7, 58, 105);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const clock = new THREE.Clock();
const GROUND = 0.22;
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xeaf7f1, 0x6a746e, 1.8);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d4, 2.8);
sun.position.set(-19, 31, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -27;
sun.shadow.camera.right = 27;
sun.shadow.camera.top = 27;
sun.shadow.camera.bottom = -27;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfdde2, 0.65);
fill.position.set(22, 13, -18);
scene.add(fill);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
roof: material(0x839c95),
building: material(0xc2c7bf),
facade: material(0xaeb9b3),
window: material(0x46635f, { roughness: 0.45 }),
parapet: material(0xd6ddd1),
parapetCap: material(0x4f7771),
path: material(0xd9c59d),
pathEdge: material(0xbca77d),
soil: material(0x60483b),
wood: material(0x9b6744),
woodLight: material(0xb77e50),
woodDark: material(0x684633),
leafDark: material(0x2d7145),
leaf: material(0x4e9854),
leafLight: material(0x8ec56a),
cabbage: material(0x78b968),
tomato: material(0xe45f48),
carrot: material(0xeb9844),
purple: material(0x76638e),
teal: material(0x377b77),
tealLight: material(0x70aaa1),
shedRoof: material(0x294f4c),
terracotta: material(0xc97755),
cream: material(0xf1e4bf),
charcoal: material(0x314744),
skin: material(0xc98c67),
skinLight: material(0xe1ad83),
skinDark: material(0x996249),
denim: material(0x345f70),
orange: material(0xe2784f),
yellow: material(0xe4b84f),
city: material(0xa7b5b0),
cityDark: material(0x8e9d99),
ground: material(0x8fa39a)
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function addBox(parent, size, position, mat) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
mat,
segments = 12
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(
parent,
radius,
position,
mat,
scale = [1, 1, 1],
lowPoly = false
) {
const geometry = lowPoly
? new THREE.IcosahedronGeometry(radius, 1)
: new THREE.SphereGeometry(radius, 12, 8);
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(scale[0], scale[1], scale[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addRod(parent, pointA, pointB, radius, mat) {
const a = new THREE.Vector3(...pointA);
const b = new THREE.Vector3(...pointB);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Roof, building, parapet, and surrounding city
// ------------------------------------------------------------
addBox(scene, [32, 13, 24], [0, -6.5, 0], M.building);
addBox(scene, [32.25, 0.2, 24.25], [0, 0.1, 0], M.roof);
addBox(scene, [32, 0.12, 24], [0, -0.02, 0], M.facade);
// Facade windows.
for (const x of [-14, -10, -6, -2, 2, 6, 10, 14]) {
for (const y of [-2.2, -5.1, -8, -10.9]) {
addBox(
scene,
[1.25, 0.9, 0.06],
[x, y, 12.035],
M.window
);
}
}
for (const z of [-9, -5, -1, 3, 7, 11]) {
for (const y of [-2.2, -5.1, -8, -10.9]) {
addBox(
scene,
[0.06, 0.9, 1.25],
[16.035, y, z],
M.window
);
}
}
// Parapets, with a central entrance gap.
addBox(scene, [32, 1.1, 0.38], [0, GROUND + 0.55, -12], M.parapet);
addBox(scene, [0.38, 1.1, 24], [-16, GROUND + 0.55, 0], M.parapet);
addBox(scene, [0.38, 1.1, 24], [16, GROUND + 0.55, 0], M.parapet);
addBox(
scene,
[13.75, 0.62, 0.38],
[-9.125, GROUND + 0.31, 12],
M.parapet
);
addBox(
scene,
[13.75, 0.62, 0.38],
[9.125, GROUND + 0.31, 12],
M.parapet
);
// Dark caps emphasize the roof boundary.
addBox(scene, [32.2, 0.1, 0.48], [0, GROUND + 1.12, -12], M.parapetCap);
addBox(scene, [0.48, 0.1, 24], [-16, GROUND + 1.12, 0], M.parapetCap);
addBox(scene, [0.48, 0.1, 24], [16, GROUND + 1.12, 0], M.parapetCap);
addBox(
scene,
[13.85, 0.09, 0.48],
[-9.125, GROUND + 0.64, 12],
M.parapetCap
);
addBox(
scene,
[13.85, 0.09, 0.48],
[9.125, GROUND + 0.64, 12],
M.parapetCap
);
// Entrance markers.
for (const x of [-2.3, 2.3]) {
addCylinder(
scene,
0.13,
0.16,
1.2,
[x, GROUND + 0.6, 11.65],
M.teal
);
addSphere(
scene,
0.17,
[x, GROUND + 1.25, 11.65],
M.cream
);
}
// City context below the roof.
addBox(
scene,
[140, 0.35, 140],
[0, -13.4, 0],
M.ground
);
const cityBlocks = [
[-29, -12, 7, 10, 8, M.city],
[-27, 12, 6, 8, 9, M.cityDark],
[-19, 25, 8, 7, 7, M.city],
[27, -13, 8, 11, 7, M.cityDark],
[29, 11, 7, 8, 8, M.city],
[19, 25, 8, 6, 8, M.cityDark],
[-7, -26, 9, 7, 8, M.city],
[5, -27, 7, 9, 7, M.cityDark],
[-38, -4, 9, 7, 10, M.cityDark],
[39, -2, 8, 8, 9, M.city]
];
for (const [x, z, w, h, d, mat] of cityBlocks) {
addBox(
scene,
[w, h, d],
[x, -13.2 + h / 2, z],
mat
);
addBox(
scene,
[w + 0.3, 0.18, d + 0.3],
[x, -13.2 + h, z],
M.cityDark
);
}
// ------------------------------------------------------------
// Broad circulation network
// ------------------------------------------------------------
const paths = new THREE.Group();
scene.add(paths);
// Slightly different heights prevent coplanar intersection flicker.
addBox(paths, [4, 0.08, 24], [0, GROUND + 0.04, 0], M.path);
addBox(paths, [32, 0.085, 3.4], [0, GROUND + 0.045, 1.5], M.path);
addBox(paths, [3.2, 0.09, 24], [8.3, GROUND + 0.05, 0], M.path);
addBox(paths, [32, 0.09, 2.4], [0, GROUND + 0.055, 9.5], M.path);
// Subtle route edging on the main central spine.
addBox(
paths,
[0.09, 0.022, 23.8],
[-1.96, GROUND + 0.09, 0],
M.pathEdge
);
addBox(
paths,
[0.09, 0.022, 23.8],
[1.96, GROUND + 0.09, 0],
M.pathEdge
);
// ------------------------------------------------------------
// Raised beds and stylized crops
// ------------------------------------------------------------
const plantGroups = [];
function addCrop(parent, x, z, type, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
parent.add(group);
const stemHeight = type === 3 ? 0.82 : 0.5;
addCylinder(
group,
0.035,
0.045,
stemHeight,
[0, stemHeight / 2, 0],
M.leafDark,
7
);
if (type === 0) {
// Low cabbage.
addSphere(
group,
0.3,
[0, 0.27, 0],
M.cabbage,
[1, 0.8, 1],
true
);
addSphere(
group,
0.22,
[-0.22, 0.24, 0.04],
M.leaf,
[1, 0.6, 1],
true
);
addSphere(
group,
0.22,
[0.22, 0.24, 0.04],
M.leaf,
[1, 0.6, 1],
true
);
addSphere(
group,
0.21,
[0, 0.24, -0.23],
M.leafLight,
[1, 0.6, 1],
true
);
} else if (type === 1) {
// Herb-like foliage.
for (let i = 0; i < 4; i++) {
const angle = (i / 4) * Math.PI * 2;
addSphere(
group,
0.19,
[
Math.cos(angle) * 0.16,
0.25 + i * 0.035,
Math.sin(angle) * 0.16
],
i % 2 ? M.leafLight : M.leaf,
[1.1, 0.55, 0.75],
true
);
}
} else if (type === 2) {
// Tomato vine.
addRod(
group,
[0, 0.05, 0],
[0.08, 0.72, 0.02],
0.04,
M.leafDark
);
addSphere(
group,
0.18,
[-0.18, 0.38, 0.03],
M.leaf,
[1.3, 0.5, 0.8],
true
);
addSphere(
group,
0.18,
[0.2, 0.58, 0],
M.leafLight,
[1.3, 0.5, 0.8],
true
);
addSphere(group, 0.105, [-0.1, 0.4, 0.16], M.tomato);
addSphere(group, 0.1, [0.18, 0.61, 0.13], M.tomato);
} else {
// Tall chard or kale.
addSphere(
group,
0.21,
[-0.17, 0.4, 0],
M.leafDark,
[0.55, 1.5, 0.8],
true
);
addSphere(
group,
0.2,
[0.17, 0.47, 0.03],
M.leaf,
[0.55, 1.55, 0.8],
true
);
addSphere(
group,
0.18,
[0, 0.55, -0.14],
M.leafLight,
[0.55, 1.45, 0.8],
true
);
}
plantGroups.push({
group,
phase: (x * 2.7 + z * 1.9) % (Math.PI * 2)
});
}
function addRaisedBed(x, z, bedIndex, sx = 3.2, sz = 2.3) {
const bed = new THREE.Group();
bed.position.set(x, GROUND, z);
scene.add(bed);
const wood = bedIndex % 2 ? M.woodLight : M.wood;
addBox(bed, [sx, 0.5, 0.16], [0, 0.35, sz / 2 - 0.08], wood);
addBox(bed, [sx, 0.5, 0.16], [0, 0.35, -sz / 2 + 0.08], wood);
addBox(bed, [0.16, 0.5, sz], [-sx / 2 + 0.08, 0.35, 0], wood);
addBox(bed, [0.16, 0.5, sz], [sx / 2 - 0.08, 0.35, 0], wood);
// Corner braces.
for (const cornerX of [-sx / 2 + 0.11, sx / 2 - 0.11]) {
for (const cornerZ of [-sz / 2 + 0.11, sz / 2 - 0.11]) {
addBox(
bed,
[0.2, 0.64, 0.2],
[cornerX, 0.36, cornerZ],
M.woodDark
);
}
}
addBox(
bed,
[sx - 0.18, 0.12, sz - 0.18],
[0, 0.53, 0],
M.soil
);
const nx = Math.max(3, Math.floor(sx / 0.72));
const nz = 2;
const cropType = bedIndex % 4;
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
const px =
-sx / 2 +
((ix + 1) * sx) / (nx + 1) +
(iz % 2 ? 0.1 : -0.1);
const pz =
-sz / 2 +
((iz + 1) * sz) / (nz + 1) +
(ix % 2 ? 0.08 : -0.08);
const scale = 0.88 + ((ix + iz + bedIndex) % 3) * 0.09;
addCrop(bed, px, pz, cropType, scale);
}
}
return bed;
}
const beds = [
[-11.4, -8.0],
[-7.4, -8.0],
[-3.8, -8.0],
[-11.4, -4.2],
[-7.4, -4.2],
[4.2, -8.0],
[4.2, -4.2]
];
beds.forEach(([x, z], index) => addRaisedBed(x, z, index));
// ------------------------------------------------------------
// Open-front tool storage
// ------------------------------------------------------------
const shed = new THREE.Group();
shed.position.set(12.5, GROUND, -7.2);
scene.add(shed);
addBox(shed, [5.2, 0.15, 4], [0, 0.08, 0], M.woodDark);
addBox(shed, [5, 3, 0.2], [0, 1.55, -1.9], M.teal);
addBox(shed, [0.2, 3, 4], [-2.4, 1.55, 0], M.teal);
addBox(shed, [5.7, 0.24, 4.5], [0, 3.18, 0], M.shedRoof);
addBox(shed, [5.35, 0.12, 4.1], [0, 3.03, 0], M.tealLight);
// Shelves and storage bins.
addBox(shed, [4.45, 0.13, 0.52], [0, 1.0, -1.62], M.woodLight);
addBox(shed, [4.45, 0.13, 0.52], [0, 2.08, -1.62], M.woodLight);
addBox(shed, [1.05, 0.55, 0.5], [-1.45, 1.34, -1.56], M.cream);
addBox(shed, [1.25, 0.55, 0.5], [0.05, 1.34, -1.56], M.orange);
addBox(shed, [0.85, 0.48, 0.5], [1.35, 1.31, -1.56], M.tealLight);
for (let i = 0; i < 3; i++) {
addBox(
shed,
[0.9, 0.45, 0.48],
[-1.35 + i * 1.35, 2.38, -1.58],
i % 2 ? M.terracotta : M.cream
);
}
// Hanging rake.
addRod(
shed,
[-1.45, 0.55, -1.69],
[-1.45, 2.65, -1.69],
0.045,
M.woodLight
);
addBox(shed, [0.8, 0.12, 0.14], [-1.45, 0.54, -1.69], M.charcoal);
for (let i = 0; i < 5; i++) {
addBox(
shed,
[0.055, 0.28, 0.09],
[-1.76 + i * 0.155, 0.38, -1.69],
M.charcoal
);
}
// Hanging shovel.
addRod(
shed,
[-0.45, 0.7, -1.69],
[-0.45, 2.65, -1.69],
0.045,
M.woodLight
);
addSphere(
shed,
0.24,
[-0.45, 0.6, -1.68],
M.charcoal,
[0.8, 1.15, 0.22],
true
);
// Broom and hand fork.
addRod(
shed,
[0.5, 0.35, -1.69],
[0.5, 2.65, -1.69],
0.04,
M.woodLight
);
addBox(shed, [0.48, 0.42, 0.16], [0.5, 0.33, -1.69], M.terracotta);
addRod(
shed,
[1.32, 0.65, -1.69],
[1.32, 2.45, -1.69],
0.04,
M.woodLight
);
addBox(shed, [0.32, 0.12, 0.1], [1.32, 0.65, -1.69], M.charcoal);
for (let i = 0; i < 3; i++) {
addBox(
shed,
[0.045, 0.35, 0.08],
[1.21 + i * 0.11, 0.48, -1.69],
M.charcoal
);
}
// ------------------------------------------------------------
// Shaded seating area
// ------------------------------------------------------------
const pergola = new THREE.Group();
pergola.position.set(12, GROUND, 5.65);
scene.add(pergola);
const postXs = [-2.7, 2.7];
const postZs = [-2.1, 2.1];
for (const px of postXs) {
for (const pz of postZs) {
addBox(pergola, [0.25, 3.25, 0.25], [px, 1.62, pz], M.woodDark);
addBox(pergola, [0.36, 0.25, 0.36], [px, 0.13, pz], M.wood);
}
}
addBox(pergola, [6, 0.24, 0.25], [0, 3.15, -2.1], M.wood);
addBox(pergola, [6, 0.24, 0.25], [0, 3.15, 2.1], M.wood);
for (let i = 0; i < 8; i++) {
const x = -2.7 + (i * 5.4) / 7;
addBox(pergola, [0.18, 0.17, 4.6], [x, 3.35, 0], M.woodLight);
if (i % 2 === 0) {
addBox(
pergola,
[0.42, 0.055, 4.45],
[x + 0.12, 3.47, 0],
i % 4 === 0 ? M.cream : M.tealLight
);
}
}
// Round communal table.
addCylinder(pergola, 1.2, 1.2, 0.16, [0, 1.04, 0], M.woodLight, 20);
addCylinder(pergola, 0.15, 0.19, 0.85, [0, 0.56, 0], M.woodDark, 10);
addCylinder(pergola, 0.55, 0.55, 0.08, [0, 0.16, 0], M.woodDark, 16);
// Benches.
for (const z of [-1.45, 1.45]) {
addBox(pergola, [4.1, 0.18, 0.62], [0, 0.62, z], M.woodLight);
addBox(pergola, [0.22, 0.58, 0.5], [-1.45, 0.31, z], M.woodDark);
addBox(pergola, [0.22, 0.58, 0.5], [1.45, 0.31, z], M.woodDark);
}
// Small table objects.
addCylinder(pergola, 0.14, 0.18, 0.3, [-0.45, 1.27, 0.12], M.terracotta, 10);
addSphere(pergola, 0.22, [-0.45, 1.55, 0.12], M.leaf, [1, 0.7, 1], true);
addBox(pergola, [0.55, 0.1, 0.42], [0.45, 1.17, -0.1], M.cream);
// Terracotta planters tucked inside the pergola, clear of the path.
for (const p of [
[2.35, -1.62],
[-2.3, 1.65]
]) {
addCylinder(pergola, 0.32, 0.23, 0.55, [p[0], 0.28, p[1]], M.terracotta, 10);
addSphere(pergola, 0.35, [p[0], 0.7, p[1]], M.leaf, [1, 0.8, 1], true);
}
// ------------------------------------------------------------
// Potting station and harvest crates
// ------------------------------------------------------------
const potting = new THREE.Group();
potting.position.set(-10.7, GROUND, 5.1);
scene.add(potting);
addBox(potting, [3.8, 0.18, 1.45], [0, 1.05, 0], M.woodLight);
for (const x of [-1.55, 1.55]) {
for (const z of [-0.5, 0.5]) {
addBox(potting, [0.18, 1.0, 0.18], [x, 0.52, z], M.woodDark);
}
}
addBox(potting, [1.15, 0.12, 0.78], [-0.7, 1.2, 0], M.teal);
addBox(potting, [0.9, 0.12, 0.7], [0.65, 1.2, 0.02], M.terracotta);
for (let i = 0; i < 3; i++) {
addCylinder(
potting,
0.16,
0.12,
0.28,
[-1.25 + i * 0.42, 1.34, 0.24],
M.terracotta,
10
);
}
function addCrate(parent, x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
addBox(group, [1.2, 0.12, 0.85], [0, 0.08, 0], M.woodLight);
addBox(group, [1.2, 0.5, 0.12], [0, 0.32, 0.38], M.wood);
addBox(group, [1.2, 0.5, 0.12], [0, 0.32, -0.38], M.wood);
addBox(group, [0.12, 0.5, 0.72], [-0.54, 0.32, 0], M.wood);
addBox(group, [0.12, 0.5, 0.72], [0.54, 0.32, 0], M.wood);
return group;
}
addCrate(scene, -13.2, GROUND, 6.6, 1);
addCrate(scene, -13.2, GROUND + 0.55, 6.6, 0.9);
addCrate(scene, -11.6, GROUND, 6.7, 0.9);
// ------------------------------------------------------------
// Volunteers
// ------------------------------------------------------------
const people = [];
function addVolunteer({
x,
z,
rotation = 0,
shirt = M.orange,
pose = "harvest",
skin = M.skin,
phase = 0
}) {
const person = new THREE.Group();
person.position.set(x, GROUND, z);
person.rotation.y = rotation;
scene.add(person);
// Legs and shoes.
addRod(person, [-0.2, 0.18, 0], [-0.18, 1.0, 0], 0.13, M.denim);
addRod(person, [0.2, 0.18, 0], [0.18, 1.0, 0], 0.13, M.denim);
addBox(person, [0.38, 0.22, 0.58], [-0.2, 0.12, 0.13], M.charcoal);
addBox(person, [0.38, 0.22, 0.58], [0.2, 0.12, 0.13], M.charcoal);
// Torso and apron.
addCylinder(person, 0.43, 0.52, 1.02, [0, 1.48, 0], shirt, 10);
addBox(person, [0.65, 0.72, 0.09], [0, 1.32, 0.4], M.cream);
addBox(person, [0.7, 0.1, 0.1], [0, 1.62, 0.42], shirt);
// Neck, head, and facial details.
addCylinder(person, 0.12, 0.13, 0.18, [0, 2.08, 0], skin, 8);
addSphere(person, 0.32, [0, 2.31, 0], skin, [1, 1.08, 0.96]);
addSphere(person, 0.048, [-0.11, 2.35, 0.285], M.charcoal);
addSphere(person, 0.048, [0.11, 2.35, 0.285], M.charcoal);
// Broad-brimmed sun hat.
addCylinder(person, 0.47, 0.47, 0.07, [0, 2.55, 0], M.cream, 16);
addCylinder(person, 0.28, 0.32, 0.22, [0, 2.66, 0], M.cream, 12);
if (pose === "harvest") {
// Reaching into the crop bed.
addRod(
person,
[-0.43, 1.83, 0],
[-0.47, 1.55, 0.48],
0.11,
shirt
);
addRod(
person,
[-0.47, 1.55, 0.48],
[-0.3, 1.72, 0.88],
0.1,
skin
);
addRod(
person,
[0.43, 1.83, 0],
[0.47, 1.55, 0.48],
0.11,
shirt
);
addRod(
person,
[0.47, 1.55, 0.48],
[0.3, 1.72, 0.88],
0.1,
skin
);
addBox(person, [0.76, 0.4, 0.54], [0, 1.3, 1.02], M.woodLight);
addBox(person, [0.61, 0.08, 0.4], [0, 1.52, 1.02], M.soil);
} else if (pose === "maintenance") {
// Holding a rake.
addRod(
person,
[-0.43, 1.82, 0],
[-0.55, 1.28, 0.15],
0.11,
shirt
);
addRod(
person,
[-0.55, 1.28, 0.15],
[-0.52, 0.93, 0.38],
0.1,
skin
);
addRod(
person,
[0.43, 1.82, 0],
[0.58, 1.48, 0.32],
0.11,
shirt
);
addRod(
person,
[0.58, 1.48, 0.32],
[0.57, 1.08, 0.5],
0.1,
skin
);
addRod(
person,
[0.57, 0.2, 0.57],
[0.57, 1.4, 0.45],
0.04,
M.woodLight
);
addBox(person, [0.75, 0.1, 0.13], [0.57, 0.2, 0.57], M.charcoal);
for (let i = 0; i < 4; i++) {
addBox(
person,
[0.05, 0.25, 0.08],
[0.34 + i * 0.15, 0.08, 0.57],
M.charcoal
);
}
} else {
// Watering a bed.
addRod(
person,
[-0.43, 1.82, 0],
[-0.56, 1.36, 0.23],
0.11,
shirt
);
addRod(
person,
[-0.56, 1.36, 0.23],
[-0.52, 1.08, 0.5],
0.1,
skin
);
addRod(
person,
[0.43, 1.82, 0],
[0.58, 1.45, 0.33],
0.11,
shirt
);
addRod(
person,
[0.58, 1.45, 0.33],
[0.62, 1.02, 0.52],
0.1,
skin
);
addCylinder(person, 0.24, 0.27, 0.38, [0.63, 0.92, 0.55], M.tealLight, 12);
addRod(
person,
[0.72, 1.02, 0.55],
[1.04, 1.15, 0.75],
0.07,
M.tealLight
);
addSphere(person, 0.09, [1.05, 1.15, 0.76], M.charcoal);
}
person.userData.phase = phase;
person.userData.baseY = GROUND;
people.push(person);
return person;
}
// Volunteers remain beside beds or tools, never in the main paths.
addVolunteer({
x: -7.4,
z: -2.3,
rotation: Math.PI,
shirt: M.orange,
pose: "harvest",
skin: M.skinLight,
phase: 0.3
});
addVolunteer({
x: 4.2,
z: -5.9,
rotation: Math.PI,
shirt: M.teal,
pose: "water",
skin: M.skinDark,
phase: 1.8
});
addVolunteer({
x: 10.75,
z: -4.55,
rotation: Math.PI,
shirt: M.yellow,
pose: "maintenance",
skin: M.skin,
phase: 3.1
});
// ------------------------------------------------------------
// Custom camera controls
// ------------------------------------------------------------
const desiredView = {
radius: 48,
theta: 0.72,
phi: 0.86
};
const currentView = {
radius: 48,
theta: 0.72,
phi: 0.86
};
const cameraTarget = new THREE.Vector3(0, 0.45, -0.5);
const spherical = new THREE.Spherical();
function applyCamera() {
spherical.set(
currentView.radius,
currentView.phi,
currentView.theta
);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
function resetView() {
desiredView.radius = 48;
desiredView.theta = 0.72;
desiredView.phi = 0.86;
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredView.theta -= dx * 0.006;
desiredView.phi = THREE.MathUtils.clamp(
desiredView.phi - dy * 0.005,
0.18,
1.32
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius + event.deltaY * 0.03,
27,
72
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.querySelector("#reset-view").addEventListener("click", resetView);
document.querySelector("#plan-view").addEventListener("click", () => {
desiredView.phi = 0.18;
desiredView.theta = 0;
desiredView.radius = 45;
});
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") desiredView.theta += step;
if (event.key === "ArrowRight") desiredView.theta -= step;
if (event.key === "ArrowUp") {
desiredView.phi = Math.max(0.18, desiredView.phi - step);
}
if (event.key === "ArrowDown") {
desiredView.phi = Math.min(1.32, desiredView.phi + step);
}
if (event.key === "+" || event.key === "=") {
desiredView.radius = Math.max(27, desiredView.radius - 2);
}
if (event.key === "-") {
desiredView.radius = Math.min(72, desiredView.radius + 2);
}
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
// Gentle camera easing.
currentView.radius = THREE.MathUtils.lerp(
currentView.radius,
desiredView.radius,
0.08
);
currentView.theta = THREE.MathUtils.lerp(
currentView.theta,
desiredView.theta,
0.1
);
currentView.phi = THREE.MathUtils.lerp(
currentView.phi,
desiredView.phi,
0.1
);
applyCamera();
// Crop movement.
for (const plant of plantGroups) {
plant.group.rotation.z =
Math.sin(time * 1.25 + plant.phase) * 0.025;
plant.group.rotation.x =
Math.cos(time * 0.9 + plant.phase) * 0.012;
}
// Small volunteer idle movement.
for (const person of people) {
person.position.y =
person.userData.baseY +
Math.sin(time * 1.45 + person.userData.phase) * 0.012;
}
renderer.render(scene, camera);
}
applyCamera();
animate();
</script>
</body>
</html>
```