Prompt specification
Build or customize the Three.js 3D scene "Seedling classroom observation shelf" 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: Seedling classroom observation shelf
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/seedling-classroom-observation-shelf-x0787
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: seedling classroom observation shelf. Compose transparent germination containers, dated cards, seedlings, and a lamp; a timeline compares stages while maintaining the identity of each original seed. Return one self-contained HTML file.
Working Three.js Starter (seedling-classroom-observation-shelf-x0787):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seedling Classroom Observation Shelf</title>
<style>
:root {
--ink: #263b36;
--muted: #66736d;
--paper: #f7f3e9;
--accent: #e2a83b;
--line: rgba(38, 59, 54, 0.14);
--shadow: 0 18px 50px rgba(53, 45, 35, 0.15);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e4d8;
color: var(--ink);
font-family: "Trebuchet MS", "Avenir Next", Avenir, system-ui, sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
border: 0;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.grain {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
opacity: 0.18;
background-image:
radial-gradient(circle at 15% 25%, rgba(48,55,44,.16) 0 1px, transparent 1px),
radial-gradient(circle at 70% 60%, rgba(48,55,44,.11) 0 1px, transparent 1px);
background-size: 7px 7px, 11px 11px;
mix-blend-mode: multiply;
}
#ui {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.header {
position: absolute;
top: 25px;
left: 28px;
max-width: 540px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: #50655f;
font-size: 11px;
font-weight: 800;
letter-spacing: .19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(255,255,255,.25);
}
h1 {
margin: 0;
max-width: 500px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4.2vw, 60px);
font-weight: 500;
line-height: .94;
letter-spacing: -.045em;
}
.subtitle {
margin: 12px 0 0;
max-width: 460px;
color: #52615b;
font-size: 13px;
line-height: 1.55;
}
.pill-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 7px 10px;
border: 1px solid rgba(255,255,255,.52);
border-radius: 999px;
background: rgba(250,247,239,.63);
box-shadow: 0 5px 18px rgba(74,60,43,.07);
backdrop-filter: blur(10px);
color: #52615c;
font-size: 10px;
font-weight: 800;
letter-spacing: .09em;
text-transform: uppercase;
}
.pill i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
}
.focus-panel {
position: absolute;
top: 25px;
right: 25px;
width: 292px;
padding: 17px;
border: 1px solid rgba(255,255,255,.65);
border-radius: 18px;
background: rgba(248,245,236,.77);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.15);
pointer-events: auto;
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
color: #77817c;
font-size: 9px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.panel-kicker button {
width: 27px;
height: 27px;
border-radius: 50%;
background: rgba(38,59,54,.07);
cursor: pointer;
transition: .2s ease;
}
.panel-kicker button:hover {
background: rgba(38,59,54,.14);
transform: rotate(-12deg);
}
.spec-tabs {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin: 15px 0 17px;
}
.spec-tab {
position: relative;
padding: 9px 2px 8px;
border-radius: 10px;
background: rgba(38,59,54,.055);
cursor: pointer;
transition: .2s ease;
}
.spec-tab:hover { transform: translateY(-2px); }
.spec-tab.active {
background: var(--ink);
box-shadow: 0 7px 16px rgba(38,59,54,.2);
color: white;
}
.spec-tab .dot {
display: block;
width: 9px;
height: 9px;
margin: 0 auto 5px;
border-radius: 50%;
background: var(--tab-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--tab-color), transparent 72%);
}
.spec-tab span:last-child {
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
}
.spec-title {
display: flex;
align-items: center;
gap: 11px;
}
.spec-number {
display: grid;
place-items: center;
flex: 0 0 43px;
height: 43px;
border: 1px solid color-mix(in srgb, var(--accent), transparent 48%);
border-radius: 50%;
background: color-mix(in srgb, var(--accent), white 81%);
color: color-mix(in srgb, var(--accent), #263b36 45%);
font-family: Georgia, serif;
font-size: 17px;
font-style: italic;
}
.spec-title h2 {
margin: 0 0 3px;
font-family: Georgia, serif;
font-size: 21px;
font-weight: 500;
letter-spacing: -.02em;
}
.spec-title p {
margin: 0;
color: #7b817c;
font-size: 10px;
font-style: italic;
}
.spec-data {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 16px 0 11px;
}
.data-cell {
padding: 10px;
border-radius: 10px;
background: rgba(255,255,255,.46);
box-shadow: inset 0 0 0 1px rgba(38,59,54,.065);
}
.data-cell small {
display: block;
margin-bottom: 4px;
color: #8a8f8b;
font-size: 8px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
}
.data-cell strong {
font-size: 12px;
font-weight: 700;
}
.continuity {
display: flex;
align-items: center;
gap: 7px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #53645e;
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.continuity i {
width: 7px;
height: 7px;
border-radius: 50%;
background: #65a36f;
box-shadow: 0 0 0 3px rgba(101,163,111,.15);
}
.note {
margin: 10px 0 0;
color: #6e7873;
font-family: Georgia, serif;
font-size: 12px;
font-style: italic;
line-height: 1.45;
}
.timeline-panel {
position: absolute;
left: 50%;
bottom: 21px;
width: min(980px, calc(100% - 44px));
transform: translateX(-50%);
padding: 14px 16px 13px;
border: 1px solid rgba(255,255,255,.68);
border-radius: 20px;
background: rgba(248,245,237,.82);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(1.15);
pointer-events: auto;
}
.timeline-top {
display: flex;
align-items: center;
gap: 13px;
margin-bottom: 11px;
}
.play {
display: grid;
place-items: center;
flex: 0 0 39px;
width: 39px;
height: 39px;
border-radius: 50%;
background: var(--ink);
color: white;
cursor: pointer;
box-shadow: 0 6px 14px rgba(38,59,54,.2);
transition: .2s ease;
}
.play:hover { transform: scale(1.06); }
.timeline-title {
min-width: 175px;
}
.timeline-title strong {
display: block;
font-family: Georgia, serif;
font-size: 16px;
font-weight: 500;
}
.timeline-title small {
color: #818883;
font-size: 9px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
.range-wrap {
position: relative;
flex: 1;
display: flex;
align-items: center;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
appearance: none;
border-radius: 99px;
outline: none;
background: linear-gradient(to right, var(--ink) 0 var(--progress, 57%), rgba(38,59,54,.12) var(--progress, 57%) 100%);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 4px solid var(--paper);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 8px rgba(38,59,54,.25);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 4px solid var(--paper);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 8px rgba(38,59,54,.25);
}
.day-readout {
flex: 0 0 83px;
text-align: right;
}
.day-readout strong {
display: block;
color: var(--ink);
font-family: Georgia, serif;
font-size: 20px;
font-weight: 500;
}
.day-readout small {
color: #8b8f8b;
font-size: 8px;
font-weight: 800;
letter-spacing: .11em;
}
.stage-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.stage-btn {
position: relative;
display: grid;
grid-template-columns: 34px 1fr;
grid-template-rows: auto auto;
column-gap: 8px;
align-items: center;
min-height: 54px;
padding: 8px 10px;
border: 1px solid rgba(38,59,54,.08);
border-radius: 12px;
background: rgba(255,255,255,.38);
text-align: left;
cursor: pointer;
transition: .2s ease;
}
.stage-btn:hover {
background: rgba(255,255,255,.72);
transform: translateY(-1px);
}
.stage-btn.active {
border-color: color-mix(in srgb, var(--accent), transparent 35%);
background: color-mix(in srgb, var(--accent), white 84%);
box-shadow: 0 5px 14px rgba(77,67,49,.08);
}
.stage-btn svg {
grid-row: 1 / 3;
width: 32px;
height: 38px;
color: #64736d;
}
.stage-btn.active svg { color: var(--ink); }
.stage-btn .date {
color: #848b87;
font-size: 8px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
.stage-btn strong {
margin-top: 2px;
font-family: Georgia, serif;
font-size: 13px;
font-weight: 500;
}
.instructions {
position: absolute;
right: 25px;
bottom: 211px;
padding: 8px 11px;
border-radius: 999px;
background: rgba(248,245,237,.62);
color: #68736e;
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 700;
letter-spacing: .05em;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #e9e4d8;
transition: opacity .6s ease, visibility .6s ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
color: #52635d;
font-size: 10px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.loader i {
width: 20px;
height: 20px;
border: 2px solid rgba(38,59,54,.15);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 850px) {
.header { top: 18px; left: 18px; max-width: 470px; }
h1 { font-size: clamp(30px, 7vw, 48px); }
.subtitle { max-width: 390px; font-size: 12px; }
.focus-panel { top: 16px; right: 16px; width: 248px; padding: 14px; }
.note { display: none; }
.timeline-panel { bottom: 12px; width: calc(100% - 24px); padding: 11px; }
.stage-btn { grid-template-columns: 1fr; grid-template-rows: auto; text-align: center; }
.stage-btn svg { display: none; }
.stage-btn .date { display: block; }
.instructions { display: none; }
}
@media (max-width: 610px) {
.header { max-width: calc(100% - 36px); }
.header .subtitle, .pill-row { display: none; }
h1 { max-width: 330px; font-size: 32px; }
.focus-panel {
top: auto;
right: 12px;
bottom: 180px;
width: 205px;
padding: 11px;
border-radius: 14px;
}
.spec-tabs { margin: 9px 0 11px; }
.spec-data { margin: 10px 0 8px; }
.data-cell { padding: 7px; }
.continuity { padding-top: 7px; }
.timeline-title { min-width: 112px; }
.timeline-title small { display: none; }
.day-readout { flex-basis: 65px; }
.day-readout strong { font-size: 17px; }
.stage-grid { gap: 5px; }
.stage-btn { min-height: 46px; padding: 6px 3px; }
.stage-btn strong { font-size: 11px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="grain"></div>
<div id="ui">
<header class="header">
<div class="eyebrow">Classroom science · Observation shelf 07</div>
<h1>From seed<br>to seedling.</h1>
<p class="subtitle">Four original seeds, one shared timeline. Scrub through the growing season while every plant keeps its identity, date card, and visible seed.</p>
<div class="pill-row">
<span class="pill"><i></i>4 seed lineages</span>
<span class="pill"><i></i>14 day study</span>
<span class="pill"><i></i>Live comparison</span>
</div>
</header>
<aside class="focus-panel">
<div class="panel-kicker">
<span>Specimen focus</span>
<button id="reset-camera" title="Reset camera" aria-label="Reset camera">↺</button>
</div>
<div class="spec-tabs" id="spec-tabs"></div>
<div class="spec-title">
<div class="spec-number" id="spec-number">S–01</div>
<div>
<h2 id="spec-name">Sunflower</h2>
<p id="spec-latin">Helianthus annuus</p>
</div>
</div>
<div class="spec-data">
<div class="data-cell">
<small>Observation</small>
<strong id="spec-date">11 May</strong>
</div>
<div class="data-cell">
<small>Shoot height</small>
<strong id="spec-height">8.2 cm</strong>
</div>
</div>
<div class="continuity"><i></i>Original seed remains in soil</div>
<p class="note" id="spec-note">Cotyledons are unfolding; the first true leaves are beginning to separate.</p>
</aside>
<div class="instructions">Drag to orbit · Scroll to zoom · Click a container</div>
<section class="timeline-panel" aria-label="Seedling growth comparison timeline">
<div class="timeline-top">
<button class="play" id="play" aria-label="Play timeline">▶</button>
<div class="timeline-title">
<strong>Growth timeline</strong>
<small>Compare every seed at the same day</small>
</div>
<div class="range-wrap">
<input id="timeline" type="range" min="0" max="14" step="0.1" value="8" aria-label="Observation day">
</div>
<div class="day-readout">
<strong id="day-value">Day 08</strong>
<small id="date-value">11 May 2024</small>
</div>
</div>
<div class="stage-grid">
<button class="stage-btn" data-day="0">
<svg viewBox="0 0 34 40" aria-hidden="true">
<path d="M10 26c0-6 4-10 9-11 5 2 8 5 8 10-5 5-12 6-17 1Z" fill="none" stroke="currentColor" stroke-width="1.8"/>
<path d="M14 24c3 1 6 1 9 0" stroke="currentColor" stroke-width="1.5"/>
</svg>
<span class="date">Day 00 · 03 May</span>
<strong>Seed</strong>
</button>
<button class="stage-btn" data-day="4">
<svg viewBox="0 0 34 40" aria-hidden="true">
<path d="M18 12c-2 5-1 9 3 12" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
<path d="M20 24c-2 4-5 5-8 4M21 25c2 3 5 4 8 2" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/>
</svg>
<span class="date">Day 04 · 07 May</span>
<strong>Radicle</strong>
</button>
<button class="stage-btn active" data-day="8">
<svg viewBox="0 0 34 40" aria-hidden="true">
<path d="M17 34V12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
<path d="M17 23c-5 0-8-2-10-6 5-1 9 1 10 6ZM17 20c5 0 8-2 10-6-5-1-9 1-10 6ZM17 13c-3-1-5-3-5-6 4 0 6 2 5 6Z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/>
</svg>
<span class="date">Day 08 · 11 May</span>
<strong>First leaves</strong>
</button>
<button class="stage-btn" data-day="14">
<svg viewBox="0 0 34 40" aria-hidden="true">
<path d="M17 35V8" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
<path d="M17 29c-6 0-9-3-11-7 6-1 10 2 11 7ZM17 25c6 0 9-3 11-7-6-1-10 2-11 7ZM17 18c-5-1-8-4-9-8 6 0 9 3 9 8ZM17 15c5-1 8-4 9-8-6 0-9 3-9 8ZM17 8c-3-1-4-3-4-6 3 0 5 2 4 6Z" fill="none" stroke="currentColor" stroke-width="1.55" stroke-linejoin="round"/>
</svg>
<span class="date">Day 14 · 17 May</span>
<strong>True leaves</strong>
</button>
</div>
</section>
</div>
<div id="loading">
<div class="loader"><i></i>Preparing observation shelf</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
const $ = id => document.getElementById(id);
const specimens = [
{
code: 'S–01',
name: 'Sunflower',
latin: 'Helianthus annuus',
color: '#e3aa37',
leaf: '#6e9a51',
seed: '#5a3a28',
maxHeight: 1.46,
leaves: 4,
leafLength: 0.52,
leafWidth: 1.22,
notes: [
'The seed has absorbed water; the coat is beginning to loosen.',
'A small radicle curves downward and searches through the soil.',
'Cotyledons are unfolding; the first true leaves are beginning to separate.',
'True leaves are expanding and the seedling is ready for a sunny position.'
]
},
{
code: 'S–02',
name: 'Bean',
latin: 'Phaseolus vulgaris',
color: '#b96f52',
leaf: '#4f8356',
seed: '#7b4d31',
maxHeight: 1.58,
leaves: 4,
leafLength: 0.58,
leafWidth: 1.28,
notes: [
'The bean is swollen and the dated card confirms the original sowing.',
'The radicle has emerged, slightly curled toward the damp soil.',
'Paired cotyledons are opening above the soil line.',
'Broad leaves are filling out while the original bean remains below.'
]
},
{
code: 'S–03',
name: 'Pea',
latin: 'Pisum sativum',
color: '#66a47b',
leaf: '#5f9166',
seed: '#789258',
maxHeight: 1.49,
leaves: 6,
leafLength: 0.43,
leafWidth: .95,
notes: [
'The pea seed is plump and clearly visible at the soil surface.',
'A delicate root tip is extending beneath the original seed.',
'The first small leaves and growing tip have emerged.',
'Several paired leaves now climb above the container rim.'
]
},
{
code: 'S–04',
name: 'Basil',
latin: 'Ocimum basilicum',
color: '#568a78',
leaf: '#3f795b',
seed: '#4d563b',
maxHeight: 1.34,
leaves: 8,
leafLength: .36,
leafWidth: .86,
notes: [
'The basil seed is resting at the recorded sowing point.',
'A pale root begins to lengthen under the soil.',
'Opposite cotyledons open as a delicate pair.',
'Multiple opposite leaf pairs have formed along the upright stem.'
]
}
];
const stageButtons = [...document.querySelectorAll('.stage-btn')];
const specTabs = $('spec-tabs');
specimens.forEach((spec, index) => {
const button = document.createElement('button');
button.className = 'spec-tab';
button.style.setProperty('--tab-color', spec.color);
button.setAttribute('aria-label', `Select ${spec.name}`);
button.innerHTML = `<span class="dot"></span><span>${spec.code.replace('–', '')}</span>`;
button.addEventListener('click', () => selectSpecimen(index));
specTabs.appendChild(button);
});
const scene = new THREE.Scene();
scene.background = new THREE.Color('#e9e4d8');
scene.fog = new THREE.Fog('#e9e4d8', 17, 30);
const camera = new THREE.PerspectiveCamera(37, innerWidth / innerHeight, .1, 80);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: 'high-performance' });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
$('scene').appendChild(renderer.domElement);
const clock = new THREE.Clock();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pickRoots = [];
const plantAssets = [];
const cardAssets = [];
const seedAssets = [];
const glassAssets = [];
const ringAssets = [];
let selectedSpecimen = 0;
let currentDay = 8;
let isPlaying = false;
let lastIntegerDay = -1;
let lastFrameTime = 0;
const cameraTarget = new THREE.Vector3(0, 2.28, .05);
const desiredCamera = { theta: .12, phi: 1.29, radius: 14.7 };
const currentCamera = { ...desiredCamera };
function fitCamera() {
const aspect = innerWidth / innerHeight;
const fitted = aspect < .75 ? 19.5 : aspect < 1.1 ? 16.7 : 14.7;
if (Math.abs(desiredCamera.radius - fitted) < .5 || !userMovedCamera) {
desiredCamera.radius = fitted;
currentCamera.radius = fitted;
}
}
let userMovedCamera = false;
const hemisphere = new THREE.HemisphereLight(0xfff9ec, 0x8b7b66, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4d6, 2.25);
keyLight.position.set(-5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = .5;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc6dbe0, .55);
fillLight.position.set(8, 5, 6);
scene.add(fillLight);
const wood = new THREE.MeshStandardMaterial({ color: 0x966c4c, roughness: .82 });
const darkWood = new THREE.MeshStandardMaterial({ color: 0x76513a, roughness: .86 });
const paleWood = new THREE.MeshStandardMaterial({ color: 0xb58b66, roughness: .9 });
const wallMaterial = new THREE.MeshStandardMaterial({ color: 0xded8ca, roughness: 1 });
const floorMaterial = new THREE.MeshStandardMaterial({ color: 0xc9bca8, roughness: .95 });
function mesh(geometry, material, position, parent = scene) {
const object = new THREE.Mesh(geometry, material);
if (position) object.position.set(...position);
parent.add(object);
return object;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function observationDate(day) {
const date = new Date(2024, 4, 3 + Math.round(day));
return {
short: date.toLocaleDateString('en-GB', { day: '2-digit', month: 'short' }).toUpperCase(),
long: date.toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' })
};
}
function createPosterTexture() {
const canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 340;
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#f4eedf';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#31534c';
ctx.fillRect(0, 0, 16, canvas.height);
ctx.fillStyle = '#6f7b74';
ctx.font = '700 25px Trebuchet MS';
ctx.fillText('CLASSROOM FIELD NOTE / 07', 58, 58);
ctx.fillStyle = '#263b36';
ctx.font = '52px Georgia';
ctx.fillText('Observe. Document. Compare.', 56, 126);
ctx.strokeStyle = '#d4b56f';
ctx.lineWidth = 4;
ctx.beginPath();
ctx.moveTo(57, 157);
ctx.lineTo(782, 157);
ctx.stroke();
ctx.fillStyle = '#52635d';
ctx.font = '22px Trebuchet MS';
ctx.fillText('Same seed. Same record. New stage.', 58, 201);
ctx.fillText('Date every observation.', 58, 238);
ctx.strokeStyle = '#75916d';
ctx.lineWidth = 6;
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(886, 282);
ctx.lineTo(886, 123);
ctx.moveTo(886, 201);
ctx.bezierCurveTo(849, 195, 826, 170, 831, 147);
ctx.bezierCurveTo(863, 151, 883, 170, 886, 201);
ctx.moveTo(886, 167);
ctx.bezierCurveTo(921, 161, 944, 137, 939, 113);
ctx.bezierCurveTo(907, 117, 890, 136, 886, 167);
ctx.stroke();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createRegisterTexture() {
const canvas = document.createElement('canvas');
canvas.width = 640;
canvas.height = 390;
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#e8dfca';
ctx.fillRect(0, 0, 640, 390);
ctx.fillStyle = '#304e48';
ctx.fillRect(0, 0, 640, 67);
ctx.fillStyle = '#f6f0e1';
ctx.font = '700 24px Trebuchet MS';
ctx.fillText('SEED REGISTER', 31, 42);
specimens.forEach((spec, i) => {
const y = 82 + i * 73;
ctx.fillStyle = i % 2 ? 'rgba(255,255,255,.22)' : 'rgba(255,255,255,.5)';
roundedRect(ctx, 21, y, 598, 56, 10);
ctx.fill();
ctx.fillStyle = spec.color;
ctx.beginPath();
ctx.arc(55, y + 28, 15, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = '#31463f';
ctx.font = '700 20px Trebuchet MS';
ctx.fillText(spec.code.replace('–', ' — '), 87, y + 23);
ctx.fillStyle = '#65716b';
ctx.font = '17px Georgia';
ctx.fillText(spec.name, 87, y + 44);
ctx.fillStyle = '#65716b';
ctx.font = '700 13px Trebuchet MS';
ctx.fillText('PLANTED 03 MAY', 417, y + 24);
ctx.fillStyle = '#8b6b48';
ctx.fillText('ORIGINAL SEED', 417, y + 43);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
// Classroom wall and floor.
const wall = mesh(new THREE.BoxGeometry(17, 9, .18), wallMaterial, [0, 3.55, -1.35]);
wall.receiveShadow = true;
const floor = mesh(new THREE.PlaneGeometry(30, 30), floorMaterial, [0, -.16, 2]);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
const baseboard = mesh(new THREE.BoxGeometry(17, .28, .12), paleWood, [0, -.01, -1.22]);
baseboard.castShadow = true;
baseboard.receiveShadow = true;
// Shelf structure.
const shelf = new THREE.Group();
scene.add(shelf);
const backPanel = mesh(new THREE.BoxGeometry(12.25, 5.2, .16), paleWood, [0, 2.64, -1.08], shelf);
backPanel.receiveShadow = true;
[-6.02, 6.02].forEach(x => {
const side = mesh(new THREE.BoxGeometry(.22, 5.35, 2.24), wood, [x, 2.6, 0], shelf);
side.castShadow = true;
side.receiveShadow = true;
});
const lowerShelf = mesh(new THREE.BoxGeometry(12.3, .24, 2.26), wood, [0, .81, 0], shelf);
lowerShelf.castShadow = true;
lowerShelf.receiveShadow = true;
const upperShelf = mesh(new THREE.BoxGeometry(12.3, .24, 2.26), wood, [0, 3.43, 0], shelf);
upperShelf.castShadow = true;
upperShelf.receiveShadow = true;
const lowerLip = mesh(new THREE.BoxGeometry(12.28, .15, .1), darkWood, [0, .67, 1.13], shelf);
lowerLip.castShadow = true;
const upperLip = mesh(new THREE.BoxGeometry(12.28, .15, .1), darkWood, [0, 3.29, 1.13], shelf);
upperLip.castShadow = true;
const grainMaterial = new THREE.LineBasicMaterial({ color: 0x66472f, transparent: true, opacity: .25 });
for (let i = 0; i < 25; i++) {
const y = .72 + Math.random() * .12;
const x = -5.9 + Math.random() * 11.8;
const length = .35 + Math.random() * 1.5;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, y, 1.137),
new THREE.Vector3(Math.min(x + length, 6.0), y + (Math.random() - .5) * .025, 1.137)
]);
shelf.add(new THREE.Line(geometry, grainMaterial));
}
const poster = mesh(
new THREE.PlaneGeometry(4.6, 1.53),
new THREE.MeshStandardMaterial({ map: createPosterTexture(), roughness: .92 }),
[-3.55, 4.65, -.985],
shelf
);
poster.receiveShadow = true;
const register = mesh(
new THREE.PlaneGeometry(2.65, 1.61),
new THREE.MeshStandardMaterial({ map: createRegisterTexture(), roughness: .9 }),
[3.92, 4.64, -.982],
shelf
);
register.receiveShadow = true;
// Small classroom ruler.
const rulerMaterial = new THREE.MeshStandardMaterial({ color: 0xe0c487, roughness: .65 });
const ruler = mesh(new THREE.BoxGeometry(.16, .08, 2.0), rulerMaterial, [5.47, .99, .05], shelf);
ruler.castShadow = true;
for (let i = 0; i < 12; i++) {
const tick = mesh(
new THREE.BoxGeometry(i % 2 === 0 ? .15 : .09, .008, .018),
new THREE.MeshBasicMaterial({ color: 0x745d3e }),
[5.47, 1.035, -.75 + i * .145],
shelf
);
}
// Articulated task lamp.
const lamp = new THREE.Group();
scene.add(lamp);
const lampMetal = new THREE.MeshStandardMaterial({ color: 0x315b55, roughness: .48, metalness: .35 });
const lampDark = new THREE.MeshStandardMaterial({ color: 0x26443f, roughness: .5, metalness: .28 });
function cylinderBetween(a, b, radius, material, parent, radialSegments = 12) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const geometry = new THREE.CylinderGeometry(radius, radius, direction.length(), radialSegments);
const object = new THREE.Mesh(geometry, material);
object.position.copy(start).add(end).multiplyScalar(.5);
object.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction.clone().normalize());
object.castShadow = true;
parent.add(object);
return object;
}
const lampBase = mesh(new THREE.CylinderGeometry(.58, .64, .14, 32), lampDark, [0, 3.61, -.42], lamp);
lampBase.castShadow = true;
cylinderBetween([0, 3.66, -.42], [0, 4.83, -.42], .055, lampMetal, lamp);
const elbow = mesh(new THREE.SphereGeometry(.13, 20, 12), lampDark, [0, 4.83, -.42], lamp);
elbow.castShadow = true;
cylinderBetween([0, 4.83, -.42], [0, 5.00, .12], .052, lampMetal, lamp);
const shade = mesh(new THREE.CylinderGeometry(.18, .49, .54, 32, 1, true), lampMetal, [0, 4.70, .16], lamp);
shade.castShadow = true;
const shadeRim = mesh(new THREE.TorusGeometry(.49, .026, 8, 40), lampDark, [0, 4.43, .16], lamp);
shadeRim.rotation.x = Math.PI / 2;
const bulb = mesh(
new THREE.SphereGeometry(.13, 20, 12),
new THREE.MeshStandardMaterial({ color: 0xffefbf, emissive: 0xffbd64, emissiveIntensity: 3.2 }),
[0, 4.47, .16],
lamp
);
const lightCone = mesh(
new THREE.ConeGeometry(2.9, 4.08, 40, 1, true),
new THREE.MeshBasicMaterial({
color: 0xffd58a,
transparent: true,
opacity: .045,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending
}),
[0, 2.4, .16],
lamp
);
lightCone.renderOrder = 1;
const spotTarget = new THREE.Object3D();
spotTarget.position.set(0, 1.55, .08);
scene.add(spotTarget);
const spotLight = new THREE.SpotLight(0xffd28a, 44, 13, Math.PI * .29, .68, 1.25);
spotLight.position.set(0, 4.39, .16);
spotLight.target = spotTarget;
spotLight.castShadow = true;
spotLight.shadow.mapSize.set(1024, 1024);
spotLight.shadow.bias = -.0003;
scene.add(spotLight);
// Shared leaf geometry.
const leafShape = new THREE.Shape();
leafShape.moveTo(0, 0);
leafShape.bezierCurveTo(-.34, .18, -.43, .72, 0, 1);
leafShape.bezierCurveTo(.43, .72, .34, .18, 0, 0);
const leafGeometry = new THREE.ShapeGeometry(leafShape, 16);
function makePlant(spec, index) {
const group = new THREE.Group();
group.position.set(.18, .435, .11);
const stemMaterial = new THREE.MeshStandardMaterial({ color: 0x507447, roughness: .78 });
const branchMaterial = new THREE.MeshStandardMaterial({ color: 0x60864d, roughness: .8 });
const leafMaterial = new THREE.MeshStandardMaterial({
color: spec.leaf,
roughness: .68,
side: THREE.DoubleSide
});
const veinMaterial = new THREE.MeshStandardMaterial({ color: 0xa1b66c, roughness: .8 });
const curve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(index % 2 ? -.09 : .08, spec.maxHeight * .54, .03),
new THREE.Vector3(index % 2 ? .04 : -.025, spec.maxHeight, .01)
);
const stemSegments = 12;
for (let i = 0; i < stemSegments; i++) {
const a = curve.getPoint(i / stemSegments);
const b = curve.getPoint((i + 1) / stemSegments);
cylinderBetween(a.toArray(), b.toArray(), .034 - i * .0004, stemMaterial, group, 8);
}
const leaves = [];
const up = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < spec.leaves; i++) {
const t = .22 + (i / Math.max(1, spec.leaves - 1)) * .61;
const start = curve.getPoint(t);
const angle = i * 2.38 + (index * .53);
const branchLength = spec.leafLength * (.48 + t * .13);
const end = start.clone().add(new THREE.Vector3(
Math.sin(angle) * branchLength,
.055 + t * .035,
-Math.cos(angle) * branchLength
));
cylinderBetween(start.toArray(), end.toArray(), .016, branchMaterial, group, 7);
const leafGroup = new THREE.Group();
leafGroup.position.copy(end);
const axis = end.clone().sub(start).normalize();
leafGroup.quaternion.setFromUnitVectors(up, axis);
leafGroup.rotateY(i % 2 ? .34 : -.34);
leafGroup.scale.set(
spec.leafWidth * (1 - i * .025),
spec.leafLength * (1 - i * .018),
1
);
const leaf = new THREE.Mesh(leafGeometry, leafMaterial);
leaf.castShadow = true;
leaf.receiveShadow = true;
leafGroup.add(leaf);
const vein = new THREE.Mesh(new THREE.CylinderGeometry(.006, .009, .88, 6), veinMaterial);
vein.position.set(0, .45, .012);
leafGroup.add(vein);
group.add(leafGroup);
leaves.push({ group: leafGroup, threshold: .12 + i * .105 });
}
const apex = new THREE.Mesh(
new THREE.SphereGeometry(.085, 14, 9),
new THREE.MeshStandardMaterial({ color: index === 0 ? 0xd9a432 : spec.leaf, roughness: .8 })
);
apex.scale.set(.8, 1.45, .8);
apex.position.copy(curve.getPoint(1));
apex.castShadow = true;
group.add(apex);
group.userData.specimenIndex = index;
return { group, leaves, apex, spec };
}
function createCard(spec, index) {
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext('2d');
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
function draw(day) {
const date = observationDate(day);
ctx.clearRect(0, 0, 512, 256);
ctx.fillStyle = '#f3eddd';
roundedRect(ctx, 8, 8, 496, 240, 20);
ctx.fill();
ctx.strokeStyle = 'rgba(55,68,59,.17)';
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = spec.color;
roundedRect(ctx, 8, 8, 496, 34, 18);
ctx.fill();
ctx.fillRect(8, 29, 496, 13);
ctx.fillStyle = '#263b36';
ctx.font = '700 24px Trebuchet MS';
ctx.fillText(spec.code.replace('–', ' — '), 30, 76);
ctx.font = '700 31px Georgia';
ctx.fillText(spec.name.toUpperCase(), 30, 117);
ctx.fillStyle = '#6f7973';
ctx.font = '700 17px Trebuchet MS';
ctx.fillText('PLANTED 03 MAY', 30, 159);
ctx.fillStyle = '#263b36';
ctx.font = '700 20px Trebuchet MS';
ctx.fillText(`OBS. ${date.short} / DAY ${String(Math.round(day)).padStart(2, '0')}`, 30, 199);
ctx.fillStyle = spec.color;
ctx.beginPath();
ctx.arc(457, 91, 18, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = '#ffffff';
ctx.lineWidth = 4;
ctx.beginPath();
ctx.arc(457, 91, 12, 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = '#7c837f';
ctx.font = 'italic 18px Georgia';
ctx.fillText(spec.latin, 30, 229);
texture.needsUpdate = true;
}
draw(currentDay);
return { canvas, ctx, texture, draw };
}
function createBadge(spec) {
const canvas = document.createElement('canvas');
canvas.width = 160;
canvas.height = 160;
const ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.arc(80, 80, 58, 0, Math.PI * 2);
ctx.fillStyle = '#f7f2e5';
ctx.fill();
ctx.lineWidth = 8;
ctx.strokeStyle = spec.color;
ctx.stroke();
ctx.fillStyle = '#30443e';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.font = '700 38px Trebuchet MS';
ctx.fillText(spec.code.replace('–', ''), 80, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({ map: texture, transparent: true, depthTest: false });
const sprite = new THREE.Sprite(material);
sprite.scale.set(.48, .48, 1);
sprite.renderOrder = 10;
return sprite;
}
const xPositions = [-4.25, -1.42, 1.42, 4.25];
const shelfTop = .935;
specimens.forEach((spec, index) => {
const container = new THREE.Group();
container.position.set(xPositions[index], shelfTop, .12);
container.userData.specimenIndex = index;
scene.add(container);
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd4ebe5,
roughness: .08,
metalness: 0,
transmission: .38,
transparent: true,
opacity: .27,
thickness: .08,
ior: 1.45,
side: THREE.DoubleSide,
depthWrite: false,
emissive: new THREE.Color(spec.color),
emissiveIntensity: 0
});
const glass = mesh(new THREE.CylinderGeometry(.71, .71, 2.22, 40, 1, true), glassMaterial, [0, 1.11, 0], container);
glass.renderOrder = 3;
const bottom = mesh(
new THREE.CylinderGeometry(.69, .69, .065, 40),
new THREE.MeshPhysicalMaterial({
color: 0xd4ebe5,
roughness: .08,
transmission: .35,
transparent: true,
opacity: .32,
thickness: .08,
depthWrite: false
}),
[0, .035, 0],
container
);
bottom.renderOrder = 3;
const rimMaterial = new THREE.MeshStandardMaterial({ color: 0xa9c4bd, roughness: .35, transparent: true, opacity: .8 });
const rim = mesh(new THREE.TorusGeometry(.708, .024, 8, 44), rimMaterial, [0, 2.22, 0], container);
rim.rotation.x = Math.PI / 2;
const soilMaterial = new THREE.MeshStandardMaterial({ color: index % 2 ? 0x49382b : 0x554030, roughness: 1 });
const soil = mesh(new THREE.CylinderGeometry(.63, .63, .34, 36), soilMaterial, [0, .22, 0], container);
soil.castShadow = true;
soil.receiveShadow = true;
const pebbleMaterial = new THREE.MeshStandardMaterial({ color: 0x79614a, roughness: 1 });
for (let p = 0; p < 9; p++) {
const angle = p * 2.4 + index;
const radius = .16 + (p % 3) * .13;
const pebble = mesh(
new THREE.DodecahedronGeometry(.035 + (p % 2) * .014, 0),
pebbleMaterial,
[Math.cos(angle) * radius, .402, Math.sin(angle) * radius],
container
);
pebble.scale.y = .5;
pebble.rotation.set(p, p * .7, p * .3);
}
const plant = makePlant(spec, index);
container.add(plant.group);
plantAssets.push(plant);
const seedMaterial = new THREE.MeshStandardMaterial({
color: spec.seed,
roughness: .72,
emissive: new THREE.Color(spec.color),
emissiveIntensity: 0
});
const seed = mesh(new THREE.SphereGeometry(1, 20, 14), seedMaterial, [.18, .46, .11], container);
if (index === 0) {
seed.scale.set(.085, .15, .067);
seed.rotation.z = -.35;
} else if (index === 1) {
seed.scale.set(.145, .10, .105);
seed.rotation.z = .25;
} else if (index === 2) {
seed.scale.set(.105, .10, .095);
} else {
seed.scale.set(.08, .075, .115);
seed.rotation.z = -.2;
}
seed.castShadow = true;
seedAssets.push(seed);
const seedHalo = mesh(
new THREE.TorusGeometry(index === 1 ? .19 : .16, .013, 7, 32),
new THREE.MeshBasicMaterial({ color: spec.color, transparent: true, opacity: .88, depthTest: false }),
[.18, .46, .115],
container
);
seedHalo.renderOrder = 9;
seedHalo.visible = false;
seedAssets[seedAssets.length - 1].halo = seedHalo;
const card = createCard(spec, index);
const cardMesh = mesh(
new THREE.PlaneGeometry(1.40, .70),
new THREE.MeshStandardMaterial({ map: card.texture, roughness: .88, side: THREE.DoubleSide }),
[0, .31, .79],
container
);
cardMesh.rotation.x = -.13;
cardMesh.castShadow = true;
cardAssets.push(card);
const cardBack = mesh(
new THREE.BoxGeometry(1.47, .75, .035),
new THREE.MeshStandardMaterial({ color: 0xd9c9a7, roughness: .9 }),
[0, .31, .77],
container
);
cardBack.rotation.x = -.13;
cardBack.castShadow = true;
const badge = createBadge(spec);
badge.position.set(-.56, 1.78, .56);
container.add(badge);
const ring = mesh(
new THREE.TorusGeometry(.43, .026, 8, 42),
new THREE.MeshBasicMaterial({ color: spec.color, transparent: true, opacity: .9 }),
[xPositions[index], .947, 1.01],
scene
);
ring.rotation.x = Math.PI / 2;
ring.visible = false;
ringAssets.push(ring);
glassAssets.push(glassMaterial);
pickRoots.push(container);
});
function growthAt(day) {
const points = [
[0, 0],
[2, .035],
[4, .15],
[7, .43],
[10, .72],
[14, 1]
];
if (day <= points[0][0]) return points[0][1];
for (let i = 1; i < points.length; i++) {
if (day <= points[i][0]) {
const [x0, y0] = points[i - 1];
const [x1, y1] = points[i];
const t = (day - x0) / (x1 - x0);
const eased = t * t * (3 - 2 * t);
return y0 + (y1 - y0) * eased;
}
}
return 1;
}
function stageIndex(day) {
if (day < 3) return 0;
if (day < 6) return 1;
if (day < 10) return 2;
return 3;
}
const stageNames = ['Seed', 'Radicle', 'First leaves', 'True leaves'];
function selectSpecimen(index) {
selectedSpecimen = index;
const spec = specimens[index];
document.documentElement.style.setProperty('--accent', spec.color);
[...specTabs.children].forEach((button, i) => button.classList.toggle('active', i === index));
ringAssets.forEach((ring, i) => ring.visible = i === index);
seedAssets.forEach((asset, i) => {
asset.material.emissiveIntensity = i === index ? .34 : 0;
asset.halo.visible = i === index;
});
glassAssets.forEach((material, i) => {
material.emissiveIntensity = i === index ? .025 : 0;
});
$('spec-number').textContent = spec.code;
$('spec-name').textContent = spec.name;
$('spec-latin').textContent = spec.latin;
updateInterface();
}
function updateInterface() {
const spec = specimens[selectedSpecimen];
const day = currentDay;
const growth = growthAt(day);
const date = observationDate(day);
const index = stageIndex(day);
$('timeline').value = day;
$('timeline').style.setProperty('--progress', `${(day / 14) * 100}%`);
$('day-value').textContent = `Day ${String(Math.round(day)).padStart(2, '0')}`;
$('date-value').textContent = date.long;
$('spec-date').textContent = date.short.charAt(0) + date.short.slice(1).toLowerCase();
$('spec-height').textContent = `${(spec.maxHeight * growth * 10).toFixed(1)} cm`;
$('spec-note').textContent = spec.notes[index];
const nearest = [0, 4, 8, 14].reduce((best, value) =>
Math.abs(value - day) < Math.abs(best - day) ? value : best
);
stageButtons.forEach(button => {
button.classList.toggle('active', Number(button.dataset.day) === nearest);
});
const integerDay = Math.round(day);
if (integerDay !== lastIntegerDay) {
cardAssets.forEach(card => card.draw(integerDay));
lastIntegerDay = integerDay;
}
}
function setPlaying(value) {
isPlaying = value;
$('play').textContent = isPlaying ? 'Ⅱ' : '▶';
$('play').setAttribute('aria-label', isPlaying ? 'Pause timeline' : 'Play timeline');
}
$('play').addEventListener('click', () => {
if (!isPlaying && currentDay >= 14) currentDay = 0;
setPlaying(!isPlaying);
});
$('timeline').addEventListener('input', event => {
currentDay = Number(event.target.value);
setPlaying(false);
updateInterface();
});
stageButtons.forEach(button => {
button.addEventListener('click', () => {
currentDay = Number(button.dataset.day);
setPlaying(false);
updateInterface();
});
});
$('reset-camera').addEventListener('click', () => {
desiredCamera.theta = .12;
desiredCamera.phi = 1.29;
desiredCamera.radius = innerWidth / innerHeight < .75 ? 19.5 : innerWidth / innerHeight < 1.1 ? 16.7 : 14.7;
userMovedCamera = false;
});
window.addEventListener('keydown', event => {
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLButtonElement) return;
if (event.code === 'Space') {
event.preventDefault();
if (!isPlaying && currentDay >= 14) currentDay = 0;
setPlaying(!isPlaying);
}
if (event.code === 'ArrowRight') {
currentDay = Math.min(14, currentDay + 1);
setPlaying(false);
updateInterface();
}
if (event.code === 'ArrowLeft') {
currentDay = Math.max(0, currentDay - 1);
setPlaying(false);
updateInterface();
}
});
// Direct camera controls, implemented without addons.
let pointerDown = false;
let pointerMoved = false;
let previousPointer = { x: 0, y: 0 };
let activePointerId = null;
renderer.domElement.addEventListener('pointerdown', event => {
pointerDown = true;
pointerMoved = false;
activePointerId = event.pointerId;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', event => {
if (pointerDown) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
desiredCamera.theta -= dx * .0048;
desiredCamera.phi = THREE.MathUtils.clamp(desiredCamera.phi + dy * .0042, .68, 1.48);
userMovedCamera = true;
previousPointer = { x: event.clientX, y: event.clientY };
} else {
pointer.x = (event.clientX / innerWidth) * 2 - 1;
pointer.y = -(event.clientY / innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickRoots, true);
renderer.domElement.style.cursor = hits.length ? 'pointer' : 'grab';
}
});
renderer.domElement.addEventListener('pointerup', event => {
if (pointerDown && !pointerMoved) {
pointer.x = (event.clientX / innerWidth) * 2 - 1;
pointer.y = -(event.clientY / innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickRoots, true);
if (hits.length) {
let object = hits[0].object;
while (object && object.userData.specimenIndex === undefined) object = object.parent;
if (object) selectSpecimen(object.userData.specimenIndex);
}
}
pointerDown = false;
if (activePointerId !== null && renderer.domElement.hasPointerCapture(activePointerId)) {
renderer.domElement.releasePointerCapture(activePointerId);
}
activePointerId = null;
});
renderer.domElement.addEventListener('pointercancel', () => {
pointerDown = false;
activePointerId = null;
});
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(desiredCamera.radius + event.deltaY * .009, 10.5, 22);
userMovedCamera = true;
}, { passive: false });
renderer.domElement.addEventListener('dblclick', () => {
desiredCamera.theta = .12;
desiredCamera.phi = 1.29;
desiredCamera.radius = innerWidth / innerHeight < .75 ? 19.5 : 14.7;
userMovedCamera = false;
});
function updateCamera(delta) {
const smoothing = 1 - Math.pow(.001, delta);
currentCamera.theta += (desiredCamera.theta - currentCamera.theta) * smoothing;
currentCamera.phi += (desiredCamera.phi - currentCamera.phi) * smoothing;
currentCamera.radius += (desiredCamera.radius - currentCamera.radius) * smoothing;
const sinPhi = Math.sin(currentCamera.phi);
camera.position.set(
cameraTarget.x + currentCamera.radius * sinPhi * Math.sin(currentCamera.theta),
cameraTarget.y + currentCamera.radius * Math.cos(currentCamera.phi),
cameraTarget.z + currentCamera.radius * sinPhi * Math.cos(currentCamera.theta)
);
camera.lookAt(cameraTarget);
}
function updatePlants(time) {
const growth = growthAt(currentDay);
plantAssets.forEach((asset, index) => {
asset.group.visible = growth > .012;
const scale = Math.max(.001, growth);
asset.group.scale.setScalar(scale);
asset.group.rotation.z = Math.sin(time * .72 + index * 1.4) * .016 * growth;
asset.leaves.forEach(leaf => {
leaf.group.visible = growth >= leaf.threshold;
});
asset.apex.visible = growth > .82;
});
ringAssets.forEach((ring, index) => {
if (index === selectedSpecimen) {
const pulse = 1 + Math.sin(time * 2.3) * .045;
ring.scale.setScalar(pulse);
ring.material.opacity = .74 + Math.sin(time * 2.3) * .12;
}
});
seedAssets.forEach((asset, index) => {
if (index === selectedSpecimen) {
asset.halo.scale.setScalar(1 + Math.sin(time * 2.1) * .06);
}
});
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), .05);
const time = clock.elapsedTime;
if (isPlaying) {
currentDay += delta * .75;
if (currentDay >= 14) {
currentDay = 14;
setPlaying(false);
}
updateInterface();
}
updateCamera(delta);
updatePlants(time);
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
fitCamera();
}
window.addEventListener('resize', resize);
fitCamera();
selectSpecimen(0);
updateInterface();
animate();
requestAnimationFrame(() => {
$('loading').classList.add('hidden');
});
</script>
</body>
</html>
```