Prompt specification
Build or customize the Three.js 3D scene "Food waste and planting classroom" 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: Food waste and planting classroom
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/food-waste-and-planting-classroom-x0084
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring avocado seed and flesh. Create a workshop where fruit parts go to serving, compost, or observation stations; follow one selected seed through a simplified growth timeline with required conditions shown separately. Low-poly.
Working Three.js Starter (food-waste-and-planting-classroom-x0084):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Avocado Parts Workshop</title>
<style>
:root {
--ink: #19332b;
--muted: #6f7f75;
--paper: #f8f6ea;
--green: #2f6b4f;
--lime: #a8c957;
--gold: #e4b85c;
--line: rgba(25, 51, 43, 0.13);
--shadow: 0 18px 50px rgba(31, 48, 39, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe8dc;
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;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 48% 43%, transparent 40%, rgba(37, 55, 44, 0.08)),
linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 25%);
z-index: 1;
}
header {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 44px;
height: 44px;
display: grid;
place-items: center;
border-radius: 14px;
color: #f9f6e9;
background: var(--ink);
box-shadow: var(--shadow);
font-size: 23px;
transform: rotate(-4deg);
}
.eyebrow {
margin: 0 0 3px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.4vw, 31px);
line-height: 1;
letter-spacing: -0.045em;
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.status-pill,
.reset-button {
border: 1px solid rgba(25, 51, 43, 0.12);
background: rgba(248, 246, 234, 0.82);
backdrop-filter: blur(12px);
box-shadow: 0 8px 26px rgba(31, 48, 39, 0.1);
}
.status-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 13px;
border-radius: 999px;
color: var(--ink);
font-size: 11px;
font-weight: 750;
}
.status-pill::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #6ea94c;
box-shadow: 0 0 0 4px rgba(110, 169, 76, 0.14);
}
.reset-button {
padding: 10px 13px;
border-radius: 12px;
color: var(--ink);
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
.reset-button:hover {
background: var(--paper);
}
#panel {
position: fixed;
z-index: 6;
top: 88px;
right: 24px;
bottom: 24px;
width: 366px;
overflow: auto;
padding: 19px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 24px;
background: rgba(248, 246, 234, 0.93);
backdrop-filter: blur(18px);
box-shadow: var(--shadow);
scrollbar-width: thin;
scrollbar-color: rgba(47, 107, 79, 0.25) transparent;
}
.specimen {
display: grid;
grid-template-columns: 47px 1fr auto;
align-items: center;
gap: 11px;
padding-bottom: 17px;
border-bottom: 1px solid var(--line);
}
.seed-icon {
width: 47px;
height: 47px;
display: grid;
place-items: center;
border-radius: 50%;
color: #f8ead0;
background: #76513b;
box-shadow:
inset -7px -6px 0 rgba(56, 31, 20, 0.16),
0 7px 15px rgba(72, 47, 32, 0.18);
font-size: 20px;
}
.specimen-title {
font-size: 14px;
font-weight: 850;
letter-spacing: -0.02em;
}
.specimen-sub {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.focus-button {
width: 32px;
height: 32px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.55);
color: var(--green);
cursor: pointer;
}
.focus-button:hover {
background: white;
}
.section {
padding: 17px 0;
border-bottom: 1px solid var(--line);
}
.section:last-child {
padding-bottom: 0;
border-bottom: 0;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
}
.section-heading h2 {
margin: 0;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.small-label {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline {
position: relative;
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 5px;
margin-top: 13px;
}
.timeline::before {
content: "";
position: absolute;
top: 16px;
left: 9%;
right: 9%;
height: 2px;
background: rgba(47, 107, 79, 0.13);
}
.time-step {
position: relative;
z-index: 1;
min-width: 0;
padding: 0 2px 8px;
border: 0;
background: transparent;
color: var(--muted);
cursor: pointer;
text-align: center;
}
.time-step .dot {
width: 34px;
height: 34px;
display: grid;
place-items: center;
margin: 0 auto 7px;
border: 4px solid var(--paper);
border-radius: 50%;
background: #d8ddd4;
color: var(--ink);
font-size: 9px;
font-weight: 850;
transition: 180ms ease;
}
.time-step .name {
display: block;
overflow: hidden;
font-size: 9px;
font-weight: 750;
text-overflow: ellipsis;
}
.time-step:hover .dot {
background: #b8d19e;
transform: translateY(-2px);
}
.time-step.active .dot {
background: var(--green);
color: white;
box-shadow: 0 5px 13px rgba(47, 107, 79, 0.25);
}
.time-step.active .name {
color: var(--green);
}
.stage-card {
margin-top: 13px;
padding: 13px;
border: 1px solid rgba(47, 107, 79, 0.12);
border-radius: 15px;
background: rgba(224, 235, 213, 0.48);
}
.stage-top {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
}
.stage-name {
font-size: 13px;
font-weight: 850;
}
.stage-day {
color: var(--green);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.stage-copy {
margin: 6px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.independent-note {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 11px;
color: #7b6c42;
font-size: 9px;
line-height: 1.35;
}
.independent-note::before {
content: "✦";
color: var(--gold);
font-size: 13px;
}
.condition {
display: grid;
grid-template-columns: 25px 1fr auto;
align-items: center;
gap: 9px;
padding: 8px 0;
}
.condition-icon {
width: 25px;
height: 25px;
display: grid;
place-items: center;
border-radius: 8px;
background: rgba(168, 201, 87, 0.18);
color: var(--green);
font-size: 12px;
}
.condition-name {
font-size: 10px;
font-weight: 800;
}
.condition-value {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.condition-check {
color: #5c8c49;
font-size: 11px;
font-weight: 900;
}
.condition-meter {
grid-column: 2 / 4;
height: 3px;
margin-top: -4px;
overflow: hidden;
border-radius: 4px;
background: rgba(47, 107, 79, 0.1);
}
.condition-meter span {
display: block;
width: var(--meter);
height: 100%;
border-radius: inherit;
background: var(--green);
}
.route-options {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin: 10px 0;
}
.route-button {
padding: 10px 4px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.55);
color: var(--muted);
cursor: pointer;
transition: 150ms ease;
}
.route-button span {
display: block;
margin-bottom: 3px;
font-size: 16px;
}
.route-button b {
font-size: 9px;
}
.route-button:hover {
transform: translateY(-2px);
}
.route-button.active {
border-color: rgba(47, 107, 79, 0.24);
background: var(--green);
color: white;
box-shadow: 0 7px 16px rgba(47, 107, 79, 0.18);
}
.route-action {
width: 100%;
padding: 12px;
border: 0;
border-radius: 13px;
background: var(--ink);
color: white;
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
.route-action:hover {
background: #24493c;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.station-tag {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: 118px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.64);
border-radius: 13px;
background: rgba(248, 246, 234, 0.88);
backdrop-filter: blur(10px);
box-shadow: 0 10px 25px rgba(31, 48, 39, 0.12);
color: var(--ink);
text-align: left;
transform: translate(-50%, -50%);
pointer-events: auto;
cursor: pointer;
}
.station-tag:hover,
.station-tag.active {
border-color: rgba(47, 107, 79, 0.34);
}
.station-tag .tag-icon {
width: 25px;
height: 25px;
display: grid;
place-items: center;
border-radius: 8px;
background: var(--tag-color, var(--green));
color: white;
font-size: 12px;
}
.station-tag b {
display: block;
font-size: 10px;
}
.station-tag small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
#hint {
position: fixed;
z-index: 4;
left: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 14px;
background: rgba(248, 246, 234, 0.85);
backdrop-filter: blur(12px);
box-shadow: var(--shadow);
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
.hint-icon {
color: var(--green);
font-size: 17px;
}
#toast {
position: fixed;
z-index: 10;
left: 50%;
bottom: 28px;
max-width: min(430px, calc(100vw - 40px));
padding: 12px 16px;
border-radius: 14px;
background: var(--ink);
color: white;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 700;
opacity: 0;
transform: translate(-50%, 15px);
transition: 220ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 800px) {
header {
top: 14px;
left: 14px;
right: 14px;
}
.brand-mark,
.status-pill {
display: none;
}
.reset-button {
padding: 9px 11px;
}
#panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 43vh;
border-radius: 20px;
}
#hint {
display: none;
}
.station-tag {
min-width: 94px;
padding: 6px 8px;
}
.station-tag small {
display: none;
}
#toast {
bottom: calc(43vh + 24px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly avocado workshop"></canvas>
<div id="vignette"></div>
<header>
<div class="brand">
<div class="brand-mark">◒</div>
<div>
<p class="eyebrow">Botanical workshop / Station 03</p>
<h1>Avocado Parts Lab</h1>
</div>
</div>
<div class="header-actions">
<div class="status-pill">Workshop live</div>
<button class="reset-button" id="resetView">Reset view</button>
</div>
</header>
<div id="labels">
<button class="station-tag" id="tag-serving" data-station="serving">
<span class="tag-icon" style="--tag-color:#b47b43">◆</span>
<span>
<b>Serving</b>
<small id="count-serving">0 parts received</small>
</span>
</button>
<button class="station-tag" id="tag-compost" data-station="compost">
<span class="tag-icon" style="--tag-color:#6d7546">↻</span>
<span>
<b>Compost</b>
<small id="count-compost">0 parts received</small>
</span>
</button>
<button class="station-tag" id="tag-observation" data-station="observation">
<span class="tag-icon" style="--tag-color:#397159">◎</span>
<span>
<b>Observation</b>
<small id="count-observation">0 parts received</small>
</span>
</button>
</div>
<section id="panel" aria-label="Selected seed controls and fruit routing">
<div class="specimen">
<div class="seed-icon">●</div>
<div>
<div class="specimen-title">Seed A-07</div>
<div class="specimen-sub" id="specimenLocation">Selected on cutting board</div>
</div>
<button class="focus-button" id="focusSeed" title="Focus selected seed" aria-label="Focus selected seed">
◎
</button>
</div>
<section class="section">
<div class="section-heading">
<h2>Growth timeline</h2>
<span class="small-label">Selected specimen</span>
</div>
<div class="timeline" id="timeline">
<button class="time-step active" data-stage="0">
<span class="dot">00</span>
<span class="name">Seed</span>
</button>
<button class="time-step" data-stage="1">
<span class="dot">07</span>
<span class="name">Root</span>
</button>
<button class="time-step" data-stage="2">
<span class="dot">21</span>
<span class="name">Sprout</span>
</button>
<button class="time-step" data-stage="3">
<span class="dot">35</span>
<span class="name">Shoot</span>
</button>
<button class="time-step" data-stage="4">
<span class="dot">56</span>
<span class="name">Sapling</span>
</button>
</div>
<div class="stage-card">
<div class="stage-top">
<span class="stage-name" id="stageName">Dormant seed</span>
<span class="stage-day" id="stageDay">Day 0</span>
</div>
<p class="stage-copy" id="stageCopy">
The selected seed is intact. Moving along the timeline transfers it to the propagation case.
</p>
</div>
</section>
<section class="section">
<div class="section-heading">
<h2>Required conditions</h2>
<span class="small-label">4 / 4 met</span>
</div>
<div class="independent-note">
Conditions are shown separately from the simplified growth timeline.
</div>
<div class="condition">
<div class="condition-icon">°</div>
<div>
<div class="condition-name">Temperature</div>
<div class="condition-value">20–30°C · warm and stable</div>
</div>
<div class="condition-check">✓</div>
<div class="condition-meter"><span style="--meter:74%"></span></div>
</div>
<div class="condition">
<div class="condition-icon">☼</div>
<div>
<div class="condition-name">Light</div>
<div class="condition-value">6–8 hours · bright indirect</div>
</div>
<div class="condition-check">✓</div>
<div class="condition-meter"><span style="--meter:68%"></span></div>
</div>
<div class="condition">
<div class="condition-icon">≈</div>
<div>
<div class="condition-name">Water</div>
<div class="condition-value">Evenly moist · never saturated</div>
</div>
<div class="condition-check">✓</div>
<div class="condition-meter"><span style="--meter:62%"></span></div>
</div>
<div class="condition">
<div class="condition-icon">⋮</div>
<div>
<div class="condition-name">Drainage</div>
<div class="condition-value">Free-draining soil · visible air space</div>
</div>
<div class="condition-check">✓</div>
<div class="condition-meter"><span style="--meter:78%"></span></div>
</div>
</section>
<section class="section">
<div class="section-heading">
<h2>Route fruit parts</h2>
<span class="small-label">Selected destination</span>
</div>
<div class="route-options" id="routeOptions">
<button class="route-button active" data-station="serving">
<span>◆</span>
<b>Serving</b>
</button>
<button class="route-button" data-station="compost">
<span>↻</span>
<b>Compost</b>
</button>
<button class="route-button" data-station="observation">
<span>◎</span>
<b>Observation</b>
</button>
</div>
<button class="route-action" id="routeNext">Route the next fruit part</button>
</section>
</section>
<div id="hint">
<span class="hint-icon">↔</span>
<span>Drag to orbit · Scroll to zoom · Click fruit to route</span>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const panel = document.getElementById("panel");
const toast = document.getElementById("toast");
const stageName = document.getElementById("stageName");
const stageDay = document.getElementById("stageDay");
const stageCopy = document.getElementById("stageCopy");
const specimenLocation = document.getElementById("specimenLocation");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe8dc);
scene.fog = new THREE.Fog(0xdfe8dc, 17, 32);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(0, 1.25, -0.6),
radius: 15.5,
theta: 0.48,
phi: 0.98
};
let cameraTween = null;
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf4f1d8, 0x71836d, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc5, 3.1);
sun.position.set(-5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d8ce, 1.1);
fill.position.set(8, 5, -4);
scene.add(fill);
const palette = {
ink: 0x19332b,
wall: 0xe9e7d7,
wallDark: 0xd7d9c8,
floor: [0xc8a978, 0xd2b383, 0xbda071, 0xd8bd8f, 0xc5a677],
wood: 0x98704b,
woodLight: 0xb98a5d,
woodDark: 0x694a35,
cream: 0xf4efdc,
green: 0x36674d,
greenLight: 0x7ca85a,
lime: 0xa8c957,
avocadoSkin: 0x344b2e,
avocadoFlesh: 0xb6c968,
avocadoInner: 0xcbd87c,
seed: 0x815a3e,
seedDark: 0x4e3327,
soil: 0x584433,
metal: 0x78847c,
blue: 0xa8cdd0
};
const materials = {};
function makeMaterial(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...extra
});
}
function assignMaterials() {
Object.entries(palette).forEach(([key, color]) => {
if (Array.isArray(color)) return;
materials[key] = makeMaterial(color);
});
materials.wall = makeMaterial(palette.wall);
materials.wallDark = makeMaterial(palette.wallDark);
materials.wood = makeMaterial(palette.wood);
materials.woodLight = makeMaterial(palette.woodLight);
materials.woodDark = makeMaterial(palette.woodDark);
materials.cream = makeMaterial(palette.cream);
materials.green = makeMaterial(palette.green);
materials.greenLight = makeMaterial(palette.greenLight);
materials.lime = makeMaterial(palette.lime);
materials.avocadoSkin = makeMaterial(palette.avocadoSkin);
materials.avocadoFlesh = makeMaterial(palette.avocadoFlesh);
materials.avocadoInner = makeMaterial(palette.avocadoInner);
materials.seed = makeMaterial(palette.seed);
materials.seedDark = makeMaterial(palette.seedDark);
materials.soil = makeMaterial(palette.soil);
materials.metal = makeMaterial(palette.metal, { roughness: 0.55, metalness: 0.28 });
materials.glass = makeMaterial(0xd8eee7, {
transparent: true,
opacity: 0.12,
depthWrite: false,
roughness: 0.25
});
materials.light = makeMaterial(0xe9f2bc, {
emissive: 0xb9d66c,
emissiveIntensity: 0.7,
roughness: 0.4
});
materials.blue = makeMaterial(palette.blue, {
emissive: 0x6f9eaa,
emissiveIntensity: 0.24
});
}
assignMaterials();
function setShadow(mesh, cast = true, receive = true) {
mesh.castShadow = cast;
mesh.receiveShadow = receive;
return mesh;
}
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = setShadow(new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material));
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, segments, material, x, y, z, parent = scene) {
const mesh = setShadow(new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material
));
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function sphere(r, segments, material, x, y, z, parent = scene) {
const mesh = setShadow(new THREE.Mesh(
new THREE.SphereGeometry(r, segments, Math.max(4, Math.floor(segments / 2))),
material
));
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = setShadow(new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.72, radius, length, 6),
material
));
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
parent.add(mesh);
return mesh;
}
function buildRoom() {
box(18, 0.25, 14, makeMaterial(0xb79a72), 0, -0.18, 0);
for (let i = 0; i < 13; i++) {
const color = palette.floor[i % palette.floor.length];
const plank = box(
18,
0.12,
1.02,
makeMaterial(color),
0,
-0.02,
-6.05 + i * 1.02
);
plank.receiveShadow = true;
}
box(18, 6.2, 0.24, materials.wall, 0, 3.0, -6.72);
box(0.24, 6.2, 14, materials.wallDark, -9.0, 3.0, 0);
box(18, 0.26, 0.18, materials.woodDark, 0, 0.12, -6.53);
box(0.18, 0.26, 14, materials.woodDark, -8.82, 0.12, 0);
// Window
box(3.15, 2.4, 0.12, materials.woodDark, -4.8, 3.7, -6.52);
box(2.86, 2.12, 0.08, materials.blue, -4.8, 3.7, -6.43);
box(0.12, 2.25, 0.14, materials.cream, -4.8, 3.7, -6.34);
box(3.0, 0.12, 0.14, materials.cream, -4.8, 3.7, -6.34);
box(3.45, 0.16, 0.48, materials.woodLight, -4.8, 2.45, -6.28);
// Pegboard and tools
box(2.55, 1.72, 0.12, materials.woodLight, 4.55, 3.65, -6.49);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 7; col++) {
const hole = cylinder(
0.026,
0.026,
0.015,
8,
materials.woodDark,
3.58 + col * 0.32,
3.05 + row * 0.3,
-6.41
);
hole.rotation.x = Math.PI / 2;
}
}
for (let i = 0; i < 5; i++) {
const x = 3.65 + i * 0.43;
cylinderBetween(
new THREE.Vector3(x, 3.72, -6.25),
new THREE.Vector3(x + 0.06, 3.08, -6.22),
0.025,
materials.metal
);
const toolHead = box(
0.18 + (i % 2) * 0.08,
0.14,
0.06,
materials.metal,
x + 0.04,
3.07,
-6.18
);
toolHead.rotation.z = (i - 2) * 0.08;
}
// Shelves
box(3.5, 0.18, 0.72, materials.wood, 6.5, 4.3, -6.16);
box(3.5, 0.18, 0.72, materials.wood, 6.5, 2.75, -6.16);
for (const x of [5.15, 7.85]) {
box(0.14, 1.0, 0.5, materials.woodDark, x, 4.84, -6.21);
}
// Clock
const clock = cylinder(0.48, 0.48, 0.09, 16, materials.cream, 0.2, 4.55, -6.44);
clock.rotation.x = Math.PI / 2;
const clockHandA = box(0.035, 0.31, 0.03, materials.ink, 0.2, 4.62, -6.37);
clockHandA.rotation.z = -0.55;
const clockHandB = box(0.25, 0.035, 0.03, materials.ink, 0.27, 4.55, -6.36);
clockHandB.rotation.z = 0.15;
// Overhead string lights
const lightPoints = [
new THREE.Vector3(-6.5, 5.3, -5.8),
new THREE.Vector3(-3.3, 4.85, -5.4),
new THREE.Vector3(0, 4.6, -5.2),
new THREE.Vector3(3.4, 4.85, -5.4),
new THREE.Vector3(6.7, 5.25, -5.8)
];
for (let i = 0; i < lightPoints.length - 1; i++) {
cylinderBetween(
lightPoints[i],
lightPoints[i + 1],
0.015,
materials.woodDark
);
}
lightPoints.forEach((p, index) => {
cylinder(0.035, 0.035, 0.13, 8, materials.woodDark, p.x, p.y - 0.08, p.z);
sphere(0.095, 8, materials.light, p.x, p.y - 0.19, p.z);
if (index % 2 === 0) {
const point = new THREE.PointLight(0xffdf9e, 0.22, 3);
point.position.copy(p).add(new THREE.Vector3(0, -0.2, 0));
scene.add(point);
}
});
}
buildRoom();
function makeTable(x, z, width, depth, topY, material = materials.wood) {
box(width, 0.2, depth, material, x, topY, z);
const legHeight = topY - 0.12;
const legX = width * 0.42;
const legZ = depth * 0.38;
for (const dx of [-legX, legX]) {
for (const dz of [-legZ, legZ]) {
box(0.2, legHeight, 0.2, materials.woodDark, x + dx, legHeight / 2, z + dz);
}
}
}
function buildWorkbench() {
makeTable(0, 1.2, 5.8, 2.55, 1.3, materials.woodLight);
box(2.95, 0.08, 1.72, materials.woodDark, 0, 1.44, 1.2);
for (let i = 0; i < 4; i++) {
box(0.16, 0.015, 0.9, materials.wood, -0.9 + i * 0.6, 1.49, 1.2);
}
// Knives and board tools
const knifeBlade = box(0.62, 0.035, 0.11, materials.metal, 1.55, 1.5, 0.46);
knifeBlade.rotation.y = -0.32;
const knifeHandle = box(0.3, 0.08, 0.13, materials.seedDark, 1.94, 1.52, 0.54);
knifeHandle.rotation.y = -0.32;
cylinder(0.24, 0.2, 0.36, 10, materials.cream, -2.2, 1.68, 0.55);
cylinder(0.2, 0.2, 0.025, 10, materials.greenLight, -2.2, 1.88, 0.55);
}
buildWorkbench();
const interactive = [];
const fruitParts = [];
let partSerial = 1;
function createFruitPart(type, x, y, z, scale = 1) {
const geometry = type === "skin"
? new THREE.DodecahedronGeometry(0.19, 0)
: new THREE.IcosahedronGeometry(0.19, 0);
const material = type === "skin"
? materials.avocadoSkin
: (partSerial % 2 ? materials.avocadoFlesh : materials.avocadoInner);
const mesh = setShadow(new THREE.Mesh(geometry, material));
mesh.position.set(x, y, z);
mesh.rotation.set(
Math.random() * 0.7,
Math.random() * Math.PI,
Math.random() * 0.5
);
mesh.scale.set(scale * 1.05, scale * 0.62, scale * 1.28);
mesh.userData.partType = type;
mesh.userData.partId = partSerial++;
mesh.userData.routed = false;
mesh.userData.baseScale = mesh.scale.clone();
scene.add(mesh);
fruitParts.push(mesh);
interactive.push(mesh);
return mesh;
}
// Main cut avocado half
const half = sphere(0.79, 12, materials.avocadoSkin, -0.65, 1.7, 1.2);
half.scale.set(1, 0.62, 1.12);
const flesh = cylinder(0.69, 0.72, 0.13, 14, materials.avocadoFlesh, -0.65, 2.03, 1.2);
flesh.scale.z = 1.12;
const innerFlesh = cylinder(0.55, 0.56, 0.055, 14, materials.avocadoInner, -0.65, 2.105, 1.2);
innerFlesh.scale.z = 1.08;
const pitRing = new THREE.Mesh(
new THREE.TorusGeometry(0.37, 0.055, 5, 14),
materials.seedDark
);
pitRing.rotation.x = Math.PI / 2;
pitRing.position.set(-0.65, 2.135, 1.2);
pitRing.scale.z = 1.1;
setShadow(pitRing);
scene.add(pitRing);
// Second half
const halfTwo = sphere(0.7, 12, materials.avocadoSkin, 0.9, 1.67, 1.43);
halfTwo.scale.set(0.9, 0.56, 1.05);
const fleshTwo = cylinder(0.57, 0.6, 0.1, 12, materials.avocadoFlesh, 0.9, 1.98, 1.43);
fleshTwo.scale.z = 1.08;
createFruitPart("flesh", -1.7, 1.61, 0.72, 0.92);
createFruitPart("flesh", -1.28, 1.61, 1.83, 0.78);
createFruitPart("flesh", 0.12, 1.61, 0.68, 1.0);
createFruitPart("flesh", 1.55, 1.61, 1.93, 0.83);
createFruitPart("flesh", 1.72, 1.61, 0.77, 0.9);
createFruitPart("skin", -2.08, 1.57, 1.38, 0.8);
createFruitPart("skin", 0.2, 1.57, 1.88, 0.68);
createFruitPart("skin", 2.05, 1.58, 1.3, 0.75);
// Selected hero seed
const heroSeed = new THREE.Group();
heroSeed.position.set(-0.65, 2.17, 1.2);
heroSeed.userData.inObservation = false;
scene.add(heroSeed);
const seedMesh = setShadow(new THREE.Mesh(
new THREE.DodecahedronGeometry(0.5, 1),
materials.seed
));
seedMesh.scale.set(0.72, 0.5, 0.86);
seedMesh.userData.partType = "seed";
seedMesh.userData.partId = "A-07";
heroSeed.add(seedMesh);
interactive.push(seedMesh);
const crack = box(0.027, 0.018, 0.5, materials.seedDark, 0.04, 0.247, 0, heroSeed);
crack.rotation.y = 0.28;
crack.visible = false;
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.51, 0.022, 6, 28),
new THREE.MeshBasicMaterial({ color: 0xe4b85c })
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.position.y = 0.02;
heroSeed.add(selectionRing);
const growthRoots = new THREE.Group();
heroSeed.add(growthRoots);
const rootMaterial = makeMaterial(0xd5c59b);
const rootPaths = [
[new THREE.Vector3(0, -0.12, 0), new THREE.Vector3(0.04, -0.25, 0.03)],
[new THREE.Vector3(0.04, -0.25, 0.03), new THREE.Vector3(0.14, -0.39, 0.08)],
[new THREE.Vector3(0.04, -0.25, 0.03), new THREE.Vector3(-0.12, -0.37, 0.05)],
[new THREE.Vector3(0.04, -0.25, 0.03), new THREE.Vector3(0.03, -0.45, -0.05)],
[new THREE.Vector3(0.14, -0.39, 0.08), new THREE.Vector3(0.24, -0.47, 0.13)],
[new THREE.Vector3(-0.12, -0.37, 0.05), new THREE.Vector3(-0.22, -0.46, 0.02)]
];
rootPaths.forEach((path) => {
cylinderBetween(path[0], path[1], 0.024, rootMaterial, growthRoots);
});
const growthShoot = new THREE.Group();
heroSeed.add(growthShoot);
cylinderBetween(
new THREE.Vector3(0, 0.17, 0),
new THREE.Vector3(0, 0.92, 0),
0.045,
materials.greenLight,
growthShoot
);
const earlyLeaves = new THREE.Group();
const mainLeaves = new THREE.Group();
growthShoot.add(earlyLeaves, mainLeaves);
function leaf(parent, x, y, z, rx, rz, scale = 1) {
const mesh = setShadow(new THREE.Mesh(
new THREE.IcosahedronGeometry(0.24, 0),
materials.lime
));
mesh.position.set(x, y, z);
mesh.scale.set(1.0 * scale, 0.18 * scale, 0.42 * scale);
mesh.rotation.set(rx, 0, rz);
parent.add(mesh);
return mesh;
}
leaf(earlyLeaves, 0.22, 0.51, 0, 0.2, -0.75, 1.0);
leaf(earlyLeaves, -0.2, 0.57, 0.03, -0.2, 0.78, 0.9);
leaf(mainLeaves, 0.29, 0.76, 0.02, 0.12, -0.95, 1.12);
leaf(mainLeaves, -0.29, 0.82, -0.02, -0.1, 0.95, 1.08);
leaf(mainLeaves, 0.18, 0.92, 0.16, 0.48, -0.42, 0.9);
leaf(mainLeaves, -0.16, 0.98, -0.15, -0.45, 0.42, 0.92);
growthRoots.scale.setScalar(0.001);
growthShoot.scale.setScalar(0.001);
earlyLeaves.scale.setScalar(0.001);
mainLeaves.scale.setScalar(0.001);
function buildServingStation() {
makeTable(-5.25, 1.0, 3.35, 2.05, 1.12, materials.woodLight);
cylinder(0.57, 0.52, 0.07, 14, materials.cream, -5.45, 1.26, 0.96);
cylinder(0.42, 0.42, 0.045, 14, materials.cream, -5.45, 1.31, 0.96);
box(0.85, 0.12, 0.62, makeMaterial(0xc98e54), -5.45, 1.42, 0.96);
box(0.68, 0.1, 0.5, materials.avocadoFlesh, -5.45, 1.51, 0.96);
box(0.52, 0.08, 0.39, materials.avocadoInner, -5.45, 1.56, 0.96);
cylinder(0.23, 0.19, 0.42, 10, materials.cream, -4.15, 1.35, 0.55);
cylinder(0.2, 0.2, 0.025, 10, materials.greenLight, -4.15, 1.57, 0.55);
for (let i = 0; i < 3; i++) {
const plate = cylinder(0.24, 0.22, 0.04, 10, materials.cream, -6.28 + i * 0.48, 1.28, 1.52);
plate.rotation.x = 0.05;
}
// Folded cloth
box(0.65, 0.035, 0.45, makeMaterial(0xb6c7ad), -6.0, 1.25, 0.45);
box(0.55, 0.035, 0.37, makeMaterial(0xc9d7bf), -6.0, 1.275, 0.45);
}
function buildCompostStation() {
box(2.15, 0.18, 1.8, materials.woodDark, 5.15, 0.18, 1.0);
box(2.05, 1.1, 0.14, materials.wood, 5.15, 0.76, 0.16);
box(2.05, 1.1, 0.14, materials.wood, 5.15, 0.76, 1.84);
box(0.14, 1.1, 1.8, materials.wood, 4.12, 0.76, 1.0);
box(0.14, 1.1, 1.8, materials.wood, 6.18, 0.76, 1.0);
cylinder(1.82, 1.82, 0.18, 14, materials.soil, 5.15, 1.12, 1.0);
const leafMaterial = makeMaterial(0x71804a);
const dryMaterial = makeMaterial(0x9c8652);
for (let i = 0; i < 15; i++) {
const chunk = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13 + (i % 3) * 0.025, 0),
i % 3 ? leafMaterial : dryMaterial
);
chunk.position.set(
4.45 + Math.random() * 1.4,
1.25 + Math.random() * 0.16,
0.45 + Math.random() * 1.05
);
chunk.rotation.set(Math.random(), Math.random(), Math.random());
setShadow(chunk);
scene.add(chunk);
}
// Pitchfork
cylinderBetween(
new THREE.Vector3(6.58, 0.25, 1.55),
new THREE.Vector3(6.72, 2.55, 1.55),
0.035,
materials.wood
);
for (let i = 0; i < 3; i++) {
cylinderBetween(
new THREE.Vector3(6.72, 2.52, 1.55),
new THREE.Vector3(6.72 + (i - 1) * 0.16, 2.23, 1.55),
0.028,
materials.metal
);
}
}
function buildObservationStation() {
makeTable(0, -4.35, 3.75, 1.75, 0.76, materials.woodLight);
const soilMaterial = makeMaterial(palette.soil, {
transparent: true,
opacity: 0.76,
depthWrite: false
});
box(2.72, 0.22, 1.12, soilMaterial, 0, 0.97, -4.25);
// Propagation case
box(0.035, 1.85, 1.18, materials.glass, -1.38, 1.77, -4.25);
box(0.035, 1.85, 1.18, materials.glass, 1.38, 1.77, -4.25);
box(2.8, 1.85, 0.035, materials.glass, 0, 1.77, -4.86);
box(2.8, 1.85, 0.025, materials.glass, 0, 1.77, -3.65);
box(2.86, 0.07, 1.22, materials.metal, 0, 2.7, -4.25);
box(0.07, 1.87, 0.07, materials.metal, -1.39, 1.77, -3.64);
box(0.07, 1.87, 0.07, materials.metal, 1.39, 1.77, -3.64);
// Grow-light frame
box(0.08, 1.95, 0.08, materials.metal, -1.57, 1.74, -4.77);
box(0.08, 1.95, 0.08, materials.metal, 1.57, 1.74, -4.77);
box(3.15, 0.08, 0.08, materials.metal, 0, 2.72, -4.77);
box(2.45, 0.07, 0.25, materials.light, 0, 2.63, -4.69);
const growLight = new THREE.PointLight(0xd9ee92, 1.1, 4.4);
growLight.position.set(0, 2.45, -4.48);
scene.add(growLight);
// Labels and tools on the observation bench
box(0.5, 0.28, 0.08, materials.cream, -1.58, 1.05, -3.95);
box(0.24, 0.12, 0.4, materials.greenLight, 1.58, 0.91, -3.93);
cylinder(0.13, 0.11, 0.24, 8, materials.cream, 1.2, 0.95, -3.75);
}
buildServingStation();
buildCompostStation();
buildObservationStation();
function buildShelfDecor() {
function pottedPlant(x, y, z, scale = 1) {
cylinder(0.25 * scale, 0.18 * scale, 0.36 * scale, 8, makeMaterial(0xb77954), x, y, z);
cylinder(0.21 * scale, 0.21 * scale, 0.035 * scale, 8, materials.soil, x, y + 0.19 * scale, z);
cylinderBetween(
new THREE.Vector3(x, y + 0.19 * scale, z),
new THREE.Vector3(x, y + 0.72 * scale, z),
0.025 * scale,
materials.green
);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const leafMesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.2 * scale, 0),
i % 2 ? materials.greenLight : materials.green
);
leafMesh.position.set(
x + Math.cos(angle) * 0.15 * scale,
y + (0.47 + i * 0.055) * scale,
z + Math.sin(angle) * 0.15 * scale
);
leafMesh.scale.set(1, 0.2, 0.45);
leafMesh.rotation.set(0.25, angle, angle * 0.25);
setShadow(leafMesh);
scene.add(leafMesh);
}
}
pottedPlant(5.25, 4.51, -6.08, 0.8);
pottedPlant(7.62, 4.51, -6.08, 0.68);
box(0.72, 0.65, 0.62, makeMaterial(0xb8a477), 6.35, 4.66, -6.08);
box(0.66, 0.56, 0.56, makeMaterial(0xc4b58c), 6.35, 4.65, -6.06);
for (let i = 0; i < 3; i++) {
cylinder(0.18, 0.16, 0.44, 8, materials.cream, 5.2 + i * 0.56, 3.0, -6.05);
cylinder(0.19, 0.19, 0.035, 8, materials.greenLight, 5.2 + i * 0.56, 3.24, -6.05);
}
// Hanging plant near the window
cylinderBetween(
new THREE.Vector3(-6.6, 5.2, -5.4),
new THREE.Vector3(-6.6, 3.9, -5.4),
0.018,
materials.woodDark
);
cylinder(0.33, 0.23, 0.4, 8, makeMaterial(0x9c7458), -6.6, 3.78, -5.4);
for (let i = 0; i < 6; i++) {
const vine = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.19, 0),
i % 2 ? materials.green : materials.greenLight
);
vine.position.set(-6.85 + i * 0.1, 3.3 - (i % 3) * 0.25, -5.35);
vine.scale.set(0.7, 0.24, 0.4);
setShadow(vine);
scene.add(vine);
}
}
buildShelfDecor();
// Dust motes
const motePositions = new Float32Array(90 * 3);
for (let i = 0; i < 90; i++) {
motePositions[i * 3] = (Math.random() - 0.5) * 16;
motePositions[i * 3 + 1] = Math.random() * 5.5 + 0.5;
motePositions[i * 3 + 2] = (Math.random() - 0.5) * 11;
}
const moteGeometry = new THREE.BufferGeometry();
moteGeometry.setAttribute("position", new THREE.BufferAttribute(motePositions, 3));
const motes = new THREE.Points(
moteGeometry,
new THREE.PointsMaterial({
color: 0xf5e9bc,
size: 0.035,
transparent: true,
opacity: 0.52,
depthWrite: false
})
);
scene.add(motes);
const stationTargets = {
serving: new THREE.Vector3(-5.35, 1.62, 0.96),
compost: new THREE.Vector3(5.15, 1.45, 1.0),
observation: new THREE.Vector3(0, 1.2, -4.25)
};
const stationColors = {
serving: 0xb47b43,
compost: 0x6d7546,
observation: 0x397159
};
const movingParts = [];
const pulses = [];
const stationCounts = { serving: 0, compost: 0, observation: 0 };
let destination = "serving";
let toastTimer = null;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2600);
}
function updateStationCounts() {
Object.entries(stationCounts).forEach(([key, count]) => {
document.getElementById(`count-${key}`).textContent =
`${count} part${count === 1 ? "" : "s"} received`;
});
}
function setDestination(nextDestination) {
destination = nextDestination;
document.querySelectorAll(".route-button").forEach((button) => {
button.classList.toggle("active", button.dataset.station === destination);
});
document.querySelectorAll(".station-tag").forEach((button) => {
button.classList.toggle("active", button.dataset.station === destination);
});
showToast(`Destination set to ${destination}. Click a fruit part to route it.`);
}
function createPulse(target, color) {
const pulse = new THREE.Mesh(
new THREE.RingGeometry(0.18, 0.25, 24),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.8,
side: THREE.DoubleSide,
depthWrite: false
})
);
pulse.rotation.x = -Math.PI / 2;
pulse.position.copy(target).add(new THREE.Vector3(0, 0.035, 0));
scene.add(pulse);
pulses.push(pulse);
}
function routePart(part, targetStation = destination) {
if (!part || part.userData.routed) return;
part.userData.routed = true;
const start = part.position.clone();
const end = stationTargets[targetStation].clone();
const middleA = start.clone().lerp(end, 0.32);
middleA.y = Math.max(start.y, end.y) + 1.45;
const middleB = start.clone().lerp(end, 0.72);
middleB.y = Math.max(start.y, end.y) + 1.65;
const curve = new THREE.CatmullRomCurve3([
start,
middleA,
middleB,
end
]);
movingParts.push({
mesh: part,
curve,
t: 0,
duration: 1.55 + Math.random() * 0.45,
targetStation
});
showToast(
`${part.userData.partType === "skin" ? "Skin" : "Flesh"} part sent to ${targetStation}.`
);
}
function routeNextPart() {
let part = fruitParts.find((item) => !item.userData.routed);
if (!part) {
const positions = [
[-1.75, 1.61, 0.8],
[0.18, 1.61, 0.68],
[1.65, 1.61, 1.87]
];
const pos = positions[partSerial % positions.length];
part = createFruitPart("flesh", ...pos, 0.9);
}
routePart(part, destination);
}
const stages = [
{
name: "Dormant seed",
day: "Day 0",
copy: "The selected seed is intact. Moving along the timeline transfers it to the propagation case."
},
{
name: "Radicle emergence",
day: "Day 7",
copy: "The first root appears from the pointed end. Moisture is steady, but oxygen around the seed remains available."
},
{
name: "Young sprout",
day: "Day 21",
copy: "An upright shoot and two small cotyledons emerge. Light remains bright and indirect."
},
{
name: "Developing shoot",
day: "Day 35",
copy: "The stem lengthens and the first true leaves expand. The growing tip remains protected."
},
{
name: "Young sapling",
day: "Day 56",
copy: "Multiple leaves surround a compact stem. The simplified sapling is ready for continued observation."
}
];
let currentStage = 0;
let pendingStage = 0;
let movingSeed = null;
function setStage(stageIndex) {
currentStage = THREE.MathUtils.clamp(stageIndex, 0, stages.length - 1);
const stage = stages[currentStage];
stageName.textContent = stage.name;
stageDay.textContent = stage.day;
stageCopy.textContent = stage.copy;
document.querySelectorAll(".time-step").forEach((button) => {
button.classList.toggle("active", Number(button.dataset.stage) === currentStage);
});
specimenLocation.textContent = heroSeed.userData.inObservation
? "Tracked in propagation case"
: "Selected on cutting board";
}
function moveSeedToObservation(stageIndex) {
pendingStage = stageIndex;
if (heroSeed.userData.inObservation) {
setStage(stageIndex);
return;
}
if (movingSeed) return;
const from = heroSeed.position.clone();
const to = stationTargets.observation.clone();
const control = from.clone().lerp(to, 0.5);
control.y += 2.1;
movingSeed = {
from,
to,
control,
t: 0,
duration: 1.9
};
showToast("Seed A-07 is moving to the observation case.");
}
function focusObject(position, radius = 8.2) {
cameraTween = {
t: 0,
duration: 0.85,
fromTarget: cameraState.target.clone(),
toTarget: position.clone(),
fromRadius: cameraState.radius,
toRadius: radius,
fromTheta: cameraState.theta,
toTheta: 0.15,
fromPhi: cameraState.phi,
toPhi: 1.02
};
}
function resetCamera() {
cameraTween = {
t: 0,
duration: 0.85,
fromTarget: cameraState.target.clone(),
toTarget: new THREE.Vector3(0, 1.25, -0.6),
fromRadius: cameraState.radius,
toRadius: 15.5,
fromTheta: cameraState.theta,
toTheta: 0.48,
fromPhi: cameraState.phi,
toPhi: 0.98
};
}
document.getElementById("resetView").addEventListener("click", resetCamera);
document.getElementById("focusSeed").addEventListener("click", () => {
focusObject(heroSeed.position.clone().add(new THREE.Vector3(0, 0.2, 0)), 7.6);
});
document.getElementById("routeNext").addEventListener("click", routeNextPart);
document.querySelectorAll(".route-button").forEach((button) => {
button.addEventListener("click", () => setDestination(button.dataset.station));
});
document.querySelectorAll(".station-tag").forEach((button) => {
button.addEventListener("click", () => setDestination(button.dataset.station));
});
document.querySelectorAll(".time-step").forEach((button) => {
button.addEventListener("click", () => {
const stageIndex = Number(button.dataset.stage);
moveSeedToObservation(stageIndex);
});
});
// Ray picking
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
function pickAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointerNdc.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
return raycaster.intersectObjects(interactive, false)[0];
}
// Custom orbit/pan/zoom controls, implemented without addons.
const pointer = {
down: false,
startX: 0,
startY: 0,
previousX: 0,
previousY: 0,
moved: false,
button: 0
};
canvas.addEventListener("pointerdown", (event) => {
pointer.down = true;
pointer.moved = false;
pointer.startX = pointer.previousX = event.clientX;
pointer.startY = pointer.previousY = event.clientY;
pointer.button = event.button;
canvas.setPointerCapture(event.pointerId);
cameraTween = null;
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.down) return;
const dx = event.clientX - pointer.previousX;
const dy = event.clientY - pointer.previousY;
if (Math.abs(event.clientX - pointer.startX) + Math.abs(event.clientY - pointer.startY) > 5) {
pointer.moved = true;
}
if (pointer.button === 2 || event.shiftKey) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
const panScale = cameraState.radius * 0.0013;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(up, dy * panScale);
cameraState.target.y = THREE.MathUtils.clamp(cameraState.target.y, 0.3, 4.5);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.5,
1.42
);
}
pointer.previousX = event.clientX;
pointer.previousY = event.clientY;
});
canvas.addEventListener("pointerup", (event) => {
pointer.down = false;
if (!pointer.moved && event.button === 0) {
const hit = pickAt(event.clientX, event.clientY);
if (hit) {
const object = hit.object;
if (object.userData.partType === "seed") {
setStage(currentStage);
showToast("Seed A-07 selected. Choose a timeline stage to follow it.");
} else {
routePart(object, destination);
}
}
}
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointer.down = false;
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraTween = null;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.5,
24
);
}, { passive: false });
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
if (event.key === "1") setDestination("serving");
if (event.key === "2") setDestination("compost");
if (event.key === "3") setDestination("observation");
});
const tagPositions = {
serving: new THREE.Vector3(-5.25, 2.55, 1.0),
compost: new THREE.Vector3(5.15, 2.52, 1.0),
observation: new THREE.Vector3(0, 3.08, -4.25)
};
const stationTags = {
serving: document.getElementById("tag-serving"),
compost: document.getElementById("tag-compost"),
observation: document.getElementById("tag-observation")
};
function updateStationLabels() {
Object.entries(tagPositions).forEach(([key, position]) => {
const projected = position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
stationTags[key].style.display = visible ? "flex" : "none";
stationTags[key].style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
stationTags[key].style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
});
}
const clock = new THREE.Clock();
const tempVector = new THREE.Vector3();
const tempVector2 = new THREE.Vector3();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Camera tween
if (cameraTween) {
cameraTween.t += delta / cameraTween.duration;
const t = Math.min(cameraTween.t, 1);
const eased = t * t * (3 - 2 * t);
cameraState.target.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
eased
);
cameraState.radius = THREE.MathUtils.lerp(
cameraTween.fromRadius,
cameraTween.toRadius,
eased
);
cameraState.theta = THREE.MathUtils.lerp(
cameraTween.fromTheta,
cameraTween.toTheta,
eased
);
cameraState.phi = THREE.MathUtils.lerp(
cameraTween.fromPhi,
cameraTween.toPhi,
eased
);
if (t >= 1) cameraTween = null;
}
updateCamera();
// Moving seed
if (movingSeed) {
movingSeed.t += delta / movingSeed.duration;
const t = Math.min(movingSeed.t, 1);
const eased = t * t * (3 - 2 * t);
const oneMinus = 1 - eased;
heroSeed.position.set(0, 0, 0)
.addScaledVector(movingSeed.from, oneMinus * oneMinus)
.addScaledVector(movingSeed.control, 2 * oneMinus * eased)
.addScaledVector(movingSeed.to, eased * eased);
heroSeed.rotation.y = eased * Math.PI * 0.7;
if (t >= 1) {
heroSeed.position.copy(movingSeed.to);
heroSeed.rotation.set(0, 0, 0);
heroSeed.userData.inObservation = true;
movingSeed = null;
setStage(pendingStage);
createPulse(stationTargets.observation, stationColors.observation);
showToast("Seed A-07 is now under observation.");
}
}
// Routed fruit pieces
for (let i = movingParts.length - 1; i >= 0; i--) {
const item = movingParts[i];
item.t += delta / item.duration;
const t = Math.min(item.t, 1);
const eased = t * t * (3 - 2 * t);
item.curve.getPoint(eased, tempVector);
item.mesh.position.copy(tempVector);
item.mesh.rotation.x += delta * 3.2;
item.mesh.rotation.y += delta * 4.6;
item.mesh.scale.copy(item.mesh.userData.baseScale).multiplyScalar(1 - eased * 0.86);
if (t >= 1) {
stationCounts[item.targetStation]++;
updateStationCounts();
createPulse(stationTargets[item.targetStation], stationColors[item.targetStation]);
scene.remove(item.mesh);
item.mesh.geometry.dispose();
movingParts.splice(i, 1);
}
}
// Growth stages
const rootTargets = [0.001, 0.26, 0.5, 0.76, 1];
const shootTargets = [0.001, 0.001, 0.34, 0.65, 1];
const earlyLeafTargets = [0.001, 0.001, 0.72, 1, 1];
const mainLeafTargets = [0.001, 0.001, 0.001, 0.72, 1];
const rootScale = THREE.MathUtils.lerp(
growthRoots.scale.x,
rootTargets[currentStage],
0.075
);
const shootScale = THREE.MathUtils.lerp(
growthShoot.scale.x,
shootTargets[currentStage],
0.075
);
const earlyScale = THREE.MathUtils.lerp(
earlyLeaves.scale.x,
earlyLeafTargets[currentStage],
0.08
);
const mainScale = THREE.MathUtils.lerp(
mainLeaves.scale.x,
mainLeafTargets[currentStage],
0.08
);
growthRoots.scale.setScalar(rootScale);
growthShoot.scale.setScalar(shootScale);
earlyLeaves.scale.setScalar(earlyScale);
mainLeaves.scale.setScalar(mainScale);
crack.visible = currentStage >= 1;
// Pulsing selection ring
const ringPulse = 1 + Math.sin(elapsed * 3.2) * 0.055;
selectionRing.scale.setScalar(ringPulse);
selectionRing.material.opacity = 0.82 + Math.sin(elapsed * 3.2) * 0.12;
// Arrival pulses
for (let i = pulses.length - 1; i >= 0; i--) {
const pulse = pulses[i];
pulse.t = (pulse.t || 0) + delta * 1.8;
pulse.scale.setScalar(1 + pulse.t * 2.8);
pulse.material.opacity = Math.max(0, 0.75 - pulse.t * 0.75);
if (pulse.t >= 1) {
scene.remove(pulse);
pulse.geometry.dispose();
pulse.material.dispose();
pulses.splice(i, 1);
}
}
// Ambient motion
motes.rotation.y = elapsed * 0.015;
motes.position.y = Math.sin(elapsed * 0.25) * 0.07;
updateStationLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
updateStationCounts();
setStage(0);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```