Prompt specification
Build or customize the Three.js 3D scene "Grass blade basal growth diagram" 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: Grass blade basal growth diagram
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/grass-blade-basal-growth-diagram-x0737
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: grass blade basal growth diagram. Display a grass shoot with labeled basal growth region beside a contrasting generic broadleaf shoot; explain that the illustrated growth organization is a selected comparative example. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (grass-blade-basal-growth-diagram-x0737):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Grass Basal Growth — Comparative Three.js Diagram</title>
<style>
:root {
--ink: #1f3028;
--muted: #607068;
--paper: rgba(250, 250, 242, 0.88);
--line: rgba(42, 65, 53, 0.16);
--grass: #d6a62f;
--grass-dark: #8c6818;
--leaf: #258c84;
--leaf-dark: #17645f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background:
radial-gradient(circle at 50% 42%, #f8f7ed 0%, #ececdf 48%, #dfe3d7 100%);
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background-image: radial-gradient(rgba(31, 48, 40, 0.055) 0.7px, transparent 0.7px);
background-size: 18px 18px;
opacity: 0.4;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.hero {
position: fixed;
z-index: 5;
top: 34px;
left: 42px;
width: min(405px, calc(100vw - 84px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: #577064;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
border-radius: 99px;
background: var(--grass);
}
h1 {
margin: 0;
max-width: 390px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 4.2vw, 64px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.045em;
}
.subtitle {
margin: 17px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.model-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 17px;
padding: 8px 11px;
border: 1px solid rgba(74, 97, 84, 0.17);
border-radius: 999px;
color: #50645a;
background: rgba(255, 255, 250, 0.62);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.model-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--leaf);
box-shadow: 0 0 0 4px rgba(37, 140, 132, 0.12);
}
.toolbar {
position: fixed;
z-index: 8;
top: 30px;
right: 38px;
display: flex;
align-items: center;
gap: 5px;
padding: 5px;
border: 1px solid rgba(55, 75, 64, 0.13);
border-radius: 999px;
background: rgba(252, 252, 246, 0.72);
box-shadow: 0 12px 35px rgba(49, 65, 54, 0.08);
backdrop-filter: blur(12px);
}
.toolbar button {
appearance: none;
border: 0;
border-radius: 999px;
padding: 9px 14px;
color: #5d6d65;
background: transparent;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.035em;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.toolbar button:hover {
color: var(--ink);
background: rgba(44, 78, 59, 0.07);
}
.toolbar button:focus-visible {
outline: 2px solid var(--leaf);
outline-offset: 2px;
}
.toolbar button.active {
color: #fff;
background: #294b3d;
box-shadow: 0 4px 12px rgba(41, 75, 61, 0.2);
}
.toolbar button:active {
transform: scale(0.97);
}
#leaders {
position: fixed;
z-index: 3;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
.leader {
fill: none;
stroke-width: 1.5;
stroke-dasharray: 5 6;
opacity: 0.72;
}
.anchor-ring {
fill: rgba(255, 255, 255, 0.9);
stroke-width: 2;
}
.anchor-dot {
stroke: white;
stroke-width: 1.5;
}
.callout {
position: fixed;
z-index: 4;
width: 274px;
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--paper);
box-shadow: 0 17px 48px rgba(37, 55, 45, 0.12);
backdrop-filter: blur(13px);
pointer-events: none;
}
.callout::before {
content: "";
position: absolute;
top: 18px;
bottom: 18px;
width: 3px;
border-radius: 99px;
}
#grass-callout {
top: 48%;
left: 42px;
}
#grass-callout::before {
left: 0;
background: var(--grass);
}
#broadleaf-callout {
top: 25%;
right: 42px;
}
#broadleaf-callout::before {
right: 0;
background: var(--leaf);
}
.callout .tag {
margin-bottom: 8px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#grass-callout .tag {
color: var(--grass-dark);
}
#broadleaf-callout .tag {
color: var(--leaf-dark);
}
.callout h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 500;
line-height: 1.05;
letter-spacing: -0.025em;
}
.callout p {
margin: 9px 0 0;
color: #66746d;
font-size: 11.5px;
line-height: 1.52;
}
.note {
position: fixed;
z-index: 5;
right: 42px;
bottom: 27px;
width: min(465px, calc(100vw - 84px));
padding: 17px 19px 18px;
border: 1px solid rgba(50, 73, 60, 0.15);
border-radius: 17px;
color: #5e6d65;
background: rgba(248, 249, 240, 0.82);
box-shadow: 0 14px 45px rgba(38, 59, 47, 0.08);
backdrop-filter: blur(14px);
pointer-events: none;
}
.note strong {
color: #344b3f;
}
.note-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #344b3f;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.note-title::before {
content: "";
width: 17px;
height: 2px;
border-radius: 99px;
background: var(--leaf);
}
.note p {
margin: 0;
font-size: 11.5px;
line-height: 1.55;
}
.gesture {
position: fixed;
z-index: 5;
left: 42px;
bottom: 31px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(51, 71, 60, 0.65);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
pointer-events: none;
}
.gesture::before {
content: "";
width: 19px;
height: 19px;
border: 1px solid rgba(51, 71, 60, 0.28);
border-radius: 50%;
background:
linear-gradient(90deg, transparent 45%, rgba(51, 71, 60, 0.45) 46% 54%, transparent 55%),
linear-gradient(0deg, transparent 45%, rgba(51, 71, 60, 0.45) 46% 54%, transparent 55%);
}
@media (max-width: 820px) {
.hero {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
h1 {
max-width: 330px;
font-size: 42px;
}
.subtitle {
max-width: 310px;
font-size: 12px;
}
.toolbar {
top: auto;
right: 16px;
bottom: 16px;
}
.toolbar button {
padding: 8px 11px;
font-size: 10px;
}
.callout {
width: 205px;
padding: 13px 14px;
}
.callout p {
display: none;
}
.callout h2 {
font-size: 19px;
}
#grass-callout {
top: 48%;
left: 16px;
}
#broadleaf-callout {
top: 31%;
right: 16px;
}
.note {
right: 16px;
bottom: 70px;
width: calc(100vw - 32px);
padding: 13px 15px;
}
.note p {
font-size: 10.5px;
}
.gesture {
display: none;
}
}
@media (max-width: 520px) {
.hero {
top: 17px;
}
.eyebrow {
margin-bottom: 8px;
font-size: 9px;
}
h1 {
max-width: 265px;
font-size: 36px;
}
.subtitle {
display: none;
}
.model-badge {
margin-top: 11px;
padding: 7px 9px;
font-size: 8px;
}
.toolbar {
bottom: 12px;
}
.note {
bottom: 63px;
max-height: 125px;
overflow: hidden;
}
.note-title {
font-size: 9px;
}
.callout {
width: 177px;
border-radius: 13px;
}
.callout .tag {
margin-bottom: 5px;
font-size: 8px;
}
.callout h2 {
font-size: 17px;
}
#grass-callout {
top: 49%;
}
#broadleaf-callout {
top: 34%;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional comparison of a grass shoot with basal growth and a generic broadleaf shoot with apical growth"
></canvas>
<header class="hero">
<div class="eyebrow">Plant growth organization</div>
<h1>Grass grows from the base.</h1>
<p class="subtitle">
A comparative view of an intercalary growth region in a grass blade
and the shoot apex of a generic broadleaf plant.
</p>
<div class="model-badge">Selected comparative example</div>
</header>
<nav class="toolbar" aria-label="Diagram focus">
<button type="button" class="active" data-focus="both" aria-pressed="true">Both</button>
<button type="button" data-focus="grass" aria-pressed="false">Grass</button>
<button type="button" data-focus="broadleaf" aria-pressed="false">Broadleaf</button>
</nav>
<svg id="leaders" aria-hidden="true">
<path id="grass-leader" class="leader" stroke="#a87819"></path>
<circle id="grass-ring" class="anchor-ring" stroke="#a87819"></circle>
<circle id="grass-dot" class="anchor-dot" fill="#d6a62f"></circle>
<path id="broadleaf-leader" class="leader" stroke="#237f78"></path>
<circle id="broadleaf-ring" class="anchor-ring" stroke="#237f78"></circle>
<circle id="broadleaf-dot" class="anchor-dot" fill="#258c84"></circle>
</svg>
<section id="grass-callout" class="callout" aria-label="Grass basal growth region">
<div class="tag">Grass blade</div>
<h2>Basal growth region</h2>
<p>
An intercalary meristem near the blade base supports continued
elongation, even if the upper blade is clipped or grazed.
</p>
</section>
<section id="broadleaf-callout" class="callout" aria-label="Generic broadleaf shoot apex">
<div class="tag">Generic broadleaf</div>
<h2>Shoot apex</h2>
<p>
New shoot organs form near the apical meristem, while leaves expand
around the growing tip.
</p>
</section>
<aside class="note" aria-live="polite">
<div class="note-title">Scope of this illustration</div>
<p>
<strong>This is a selected comparative example, not a universal rule.</strong>
It deliberately simplifies two common growth organizations. Grasses vary
in meristem placement, and broadleaf shoots may also exhibit cambial or
intercalary growth depending on species, organ, age, and environment.
</p>
</aside>
<div class="gesture">Drag to orbit · Scroll to zoom</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.querySelector("#scene");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe9eadf, 10, 21);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
60
);
const hemisphere = new THREE.HemisphereLight(0xfffdf1, 0x71806b, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff7df, 3.1);
keyLight.position.set(-4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb9e7db, 1.35);
rimLight.position.set(6, 4, -5);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xf0d58b, 12, 9, 2);
fillLight.position.set(-3, 2.6, 3.2);
scene.add(fillLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe7e7da,
roughness: 0.98,
metalness: 0
});
const ground = new THREE.Mesh(new THREE.CircleGeometry(9, 96), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.085;
ground.receiveShadow = true;
scene.add(ground);
const divider = new THREE.Mesh(
new THREE.BoxGeometry(0.012, 0.008, 4.1),
new THREE.MeshBasicMaterial({
color: 0x9ba69b,
transparent: true,
opacity: 0.24
})
);
divider.position.set(0, -0.072, -0.15);
scene.add(divider);
function makePlatform(radius, height, color, edgeColor) {
const group = new THREE.Group();
const side = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.04, height, 64),
new THREE.MeshStandardMaterial({
color,
roughness: 0.94
})
);
side.position.y = -0.035;
side.castShadow = true;
side.receiveShadow = true;
group.add(side);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(radius * 0.96, 0.018, 8, 96),
new THREE.MeshStandardMaterial({
color: edgeColor,
roughness: 0.8
})
);
rim.rotation.x = Math.PI / 2;
rim.position.y = height * 0.48 - 0.025;
group.add(rim);
return group;
}
function makeRibbonGeometry(centerAt, widthAt, edgeColor, centerColor, fold = 0.08) {
const segments = 22;
const positions = [];
const colors = [];
const indices = [];
const edge = new THREE.Color(edgeColor);
const middle = new THREE.Color(centerColor);
for (let row = 0; row <= segments; row++) {
const t = row / segments;
const center = centerAt(t);
const before = centerAt(Math.max(0, t - 0.002));
const after = centerAt(Math.min(1, t + 0.002));
const tangent = after.clone().sub(before).normalize();
let side = new THREE.Vector3(-tangent.z, 0, tangent.x);
if (side.lengthSq() < 0.0001) side.set(1, 0, 0);
side.normalize();
const normal = new THREE.Vector3().crossVectors(side, tangent).normalize();
const width = widthAt(t);
for (let column = 0; column < 3; column++) {
const u = column - 1;
const position = center.clone()
.addScaledVector(side, u * width * 0.5)
.addScaledVector(normal, fold * width * (1 - u * u));
positions.push(position.x, position.y, position.z);
const color = column === 1 ? middle : edge;
colors.push(color.r, color.g, color.b);
}
}
for (let row = 0; row < segments; row++) {
for (let column = 0; column < 2; column++) {
const a = row * 3 + column;
const b = a + 1;
const c = a + 3;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function makeBladeGeometry(height, width, angle, spread, phase) {
const centerAt = (t) =>
new THREE.Vector3(
Math.cos(angle) * spread * Math.pow(t, 1.48) +
Math.sin(phase + t * 4.1) * 0.022 * t,
height * (1.88 * t - 0.88 * t * t),
Math.sin(angle) * spread * Math.pow(t, 1.56) +
Math.cos(phase + t * 3.3) * 0.026 * t
);
const widthAt = (t) =>
width *
Math.pow(Math.max(0, Math.sin(Math.PI * Math.pow(t, 0.84))), 0.68) *
(1 - 0.12 * t);
return makeRibbonGeometry(
centerAt,
widthAt,
0x466e20,
0xa9cf4e,
0.11
);
}
function makeLeafGeometry(base, angle, length, width, rise, droop) {
const direction = new THREE.Vector3(Math.cos(angle), 0, Math.sin(angle));
const centerAt = (t) => {
const point = base.clone().addScaledVector(direction, length * t);
point.y += rise * Math.sin(Math.PI * t) - droop * Math.pow(t, 1.72);
return point;
};
const widthAt = (t) =>
width *
Math.pow(Math.max(0, Math.sin(Math.PI * Math.pow(t, 0.91))), 0.72) *
(1 - 0.1 * t);
return makeRibbonGeometry(
centerAt,
widthAt,
0x22583f,
0x62a474,
0.055
);
}
function addLeaf(parent, base, angle, length, width, rise, droop) {
const direction = new THREE.Vector3(Math.cos(angle), 0, Math.sin(angle));
const leafBase = base.clone().addScaledVector(direction, 0.15);
leafBase.y += 0.025;
const petioleCurve = new THREE.CatmullRomCurve3([
base.clone(),
base.clone().addScaledVector(direction, 0.075).add(new THREE.Vector3(0, 0.025, 0)),
leafBase.clone()
]);
const petiole = new THREE.Mesh(
new THREE.TubeGeometry(petioleCurve, 10, 0.025, 7, false),
new THREE.MeshStandardMaterial({
color: 0x3f7750,
roughness: 0.8
})
);
petiole.castShadow = true;
parent.add(petiole);
const leaf = new THREE.Mesh(
makeLeafGeometry(leafBase, angle, length, width, rise, droop),
new THREE.MeshStandardMaterial({
vertexColors: true,
side: THREE.DoubleSide,
roughness: 0.75,
metalness: 0
})
);
leaf.castShadow = true;
leaf.receiveShadow = true;
parent.add(leaf);
return leaf;
}
// Grass shoot
const grassRoot = new THREE.Group();
grassRoot.position.set(-1.58, 0.055, 0.08);
scene.add(grassRoot);
const grassPlatform = makePlatform(1.06, 0.13, 0x68573b, 0x9b8049);
grassPlatform.position.y = 0;
grassRoot.add(grassPlatform);
const grassSway = new THREE.Group();
grassRoot.add(grassSway);
const bladeMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
side: THREE.DoubleSide,
roughness: 0.72,
metalness: 0
});
const bladeSpecs = [
[3.28, 0.18, 0.22, 0.28, 0.2],
[2.92, 0.16, 1.02, 0.48, 1.4],
[2.68, 0.15, 2.04, 0.58, 2.7],
[2.88, 0.16, -0.72, 0.52, 0.9],
[2.44, 0.14, -1.58, 0.64, 3.3],
[2.28, 0.13, 2.73, 0.7, 4.0],
[2.02, 0.12, -2.38, 0.67, 5.1],
[2.42, 0.135, 1.72, 0.76, 2.1]
];
for (const spec of bladeSpecs) {
const blade = new THREE.Mesh(
makeBladeGeometry(...spec),
bladeMaterial
);
blade.castShadow = true;
blade.receiveShadow = true;
grassSway.add(blade);
}
for (let i = 0; i < 9; i++) {
const angle = (i / 9) * Math.PI * 2 + 0.2;
const shortBlade = new THREE.Mesh(
makeBladeGeometry(
0.48 + (i % 3) * 0.12,
0.09,
angle,
0.38 + (i % 2) * 0.16,
i * 0.83
),
bladeMaterial
);
shortBlade.position.set(
Math.cos(angle) * 0.12,
0.02,
Math.sin(angle) * 0.12
);
shortBlade.castShadow = true;
grassSway.add(shortBlade);
}
const crown = new THREE.Mesh(
new THREE.SphereGeometry(0.29, 24, 16),
new THREE.MeshStandardMaterial({
color: 0x78942f,
roughness: 0.78
})
);
crown.scale.set(1.15, 0.62, 1);
crown.position.y = 0.16;
crown.castShadow = true;
grassSway.add(crown);
const growthRing = new THREE.Mesh(
new THREE.TorusGeometry(0.45, 0.035, 12, 72),
new THREE.MeshStandardMaterial({
color: 0xf1c64e,
emissive: 0xb97913,
emissiveIntensity: 0.75,
roughness: 0.34
})
);
growthRing.rotation.x = Math.PI / 2;
growthRing.position.y = 0.22;
grassSway.add(growthRing);
const growthRingOuter = new THREE.Mesh(
new THREE.TorusGeometry(0.54, 0.012, 8, 72),
new THREE.MeshBasicMaterial({
color: 0xe6b83e,
transparent: true,
opacity: 0.58
})
);
growthRingOuter.rotation.x = Math.PI / 2;
growthRingOuter.position.y = 0.205;
grassSway.add(growthRingOuter);
const growthBeads = new THREE.Group();
growthBeads.position.y = 0.23;
grassSway.add(growthBeads);
const beadGeometry = new THREE.SphereGeometry(0.026, 10, 8);
const beadMaterial = new THREE.MeshBasicMaterial({ color: 0xffdc70 });
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const bead = new THREE.Mesh(beadGeometry, beadMaterial);
bead.position.set(
Math.cos(angle) * 0.45,
Math.sin(i * 1.7) * 0.014,
Math.sin(angle) * 0.45
);
growthBeads.add(bead);
}
const grassArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(-0.58, 0.24, 0.18),
0.85,
0xd8a62e,
0.17,
0.095
);
grassSway.add(grassArrow);
// Generic broadleaf shoot
const broadleafRoot = new THREE.Group();
broadleafRoot.position.set(1.52, 0.055, -0.03);
scene.add(broadleafRoot);
const broadleafPlatform = makePlatform(1.06, 0.13, 0x68786a, 0x8fa08d);
broadleafRoot.add(broadleafPlatform);
const broadleafSway = new THREE.Group();
broadleafRoot.add(broadleafSway);
const stemCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0.08, 0),
new THREE.Vector3(-0.07, 0.75, 0.02),
new THREE.Vector3(0.075, 1.42, -0.025),
new THREE.Vector3(-0.055, 2.13, 0.025),
new THREE.Vector3(0, 2.77, 0)
]);
const stem = new THREE.Mesh(
new THREE.TubeGeometry(stemCurve, 50, 0.066, 12, false),
new THREE.MeshStandardMaterial({
color: 0x477451,
roughness: 0.78
})
);
stem.castShadow = true;
stem.receiveShadow = true;
broadleafSway.add(stem);
const leafPairs = [
[new THREE.Vector3(-0.04, 0.72, 0.015), 0.34, 1.22, 0.46, 0.2, 0.34],
[new THREE.Vector3(-0.04, 0.72, 0.015), Math.PI + 0.34, 1.22, 0.46, 0.2, 0.34],
[new THREE.Vector3(0.055, 1.32, -0.015), -0.18, 1.43, 0.51, 0.25, 0.42],
[new THREE.Vector3(0.055, 1.32, -0.015), Math.PI - 0.18, 1.43, 0.51, 0.25, 0.42],
[new THREE.Vector3(-0.025, 1.88, 0.015), 0.53, 1.18, 0.44, 0.24, 0.39],
[new THREE.Vector3(-0.025, 1.88, 0.015), Math.PI + 0.53, 1.18, 0.44, 0.24, 0.39],
[new THREE.Vector3(-0.035, 2.34, 0.012), 0.05, 0.78, 0.29, 0.18, 0.2],
[new THREE.Vector3(-0.035, 2.34, 0.012), Math.PI + 0.05, 0.78, 0.29, 0.18, 0.2]
];
for (const [base, angle, length, width, rise, droop] of leafPairs) {
addLeaf(broadleafSway, base, angle, length, width, rise, droop);
}
const nodeGeometry = new THREE.SphereGeometry(0.083, 16, 12);
const nodeMaterial = new THREE.MeshStandardMaterial({
color: 0x557c51,
roughness: 0.78
});
for (const y of [0.72, 1.32, 1.88, 2.34]) {
const node = new THREE.Mesh(nodeGeometry, nodeMaterial);
node.position.set(0, y, 0);
node.scale.set(1, 0.82, 1);
node.castShadow = true;
broadleafSway.add(node);
}
const apicalBud = new THREE.Mesh(
new THREE.SphereGeometry(0.145, 20, 16),
new THREE.MeshStandardMaterial({
color: 0x77ad68,
roughness: 0.64
})
);
apicalBud.position.set(0, 2.73, 0);
apicalBud.scale.set(0.85, 1.25, 0.85);
apicalBud.castShadow = true;
broadleafSway.add(apicalBud);
addLeaf(
broadleafSway,
new THREE.Vector3(0, 2.63, 0),
0.65,
0.52,
0.13,
0.24,
0.015
);
addLeaf(
broadleafSway,
new THREE.Vector3(0, 2.63, 0),
2.65,
0.5,
0.13,
0.24,
0.015
);
addLeaf(
broadleafSway,
new THREE.Vector3(0, 2.63, 0),
4.65,
0.47,
0.12,
0.23,
0.01
);
const apexHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.245, 0.012, 8, 64),
new THREE.MeshBasicMaterial({
color: 0x42b4aa,
transparent: true,
opacity: 0.72
})
);
apexHalo.position.set(0, 2.76, 0);
broadleafSway.add(apexHalo);
const broadleafArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0.48, 2.38, 0.04),
0.66,
0x258c84,
0.14,
0.085
);
broadleafSway.add(broadleafArrow);
// Camera and direct controls, implemented without addons.
const cameraState = {
theta: 0.09,
phi: 1.27,
radius: 8.25,
thetaGoal: 0.09,
phiGoal: 1.27,
radiusGoal: 8.25
};
const target = new THREE.Vector3(0, 1.42, 0);
const targetGoal = new THREE.Vector3(0, 1.42, 0);
function fitRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.72) return 13.2;
if (aspect < 1) return 10.3;
return 8.25;
}
cameraState.radius = fitRadius();
cameraState.radiusGoal = fitRadius();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.thetaGoal -= dx * 0.006;
cameraState.phiGoal = THREE.MathUtils.clamp(
cameraState.phiGoal - dy * 0.005,
0.72,
1.48
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
canvas.style.cursor = "grab";
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.style.cursor = "grab";
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radiusGoal = THREE.MathUtils.clamp(
cameraState.radiusGoal * Math.exp(event.deltaY * 0.001),
4.1,
18
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraState.thetaGoal -= 0.1;
if (event.key === "ArrowRight") cameraState.thetaGoal += 0.1;
if (event.key === "ArrowUp") {
cameraState.phiGoal = THREE.MathUtils.clamp(cameraState.phiGoal - 0.08, 0.72, 1.48);
}
if (event.key === "ArrowDown") {
cameraState.phiGoal = THREE.MathUtils.clamp(cameraState.phiGoal + 0.08, 0.72, 1.48);
}
if (event.key === "+" || event.key === "=") {
cameraState.radiusGoal = Math.max(4.1, cameraState.radiusGoal - 0.5);
}
if (event.key === "-") {
cameraState.radiusGoal = Math.min(18, cameraState.radiusGoal + 0.5);
}
});
const focusButtons = [...document.querySelectorAll("[data-focus]")];
function setFocus(focus) {
const narrowScale = window.innerWidth / window.innerHeight < 0.8 ? 1.75 : 1;
if (focus === "grass") {
targetGoal.set(-1.45, 1.48, 0);
cameraState.radiusGoal = 5.65 * narrowScale;
cameraState.thetaGoal = 0.03;
cameraState.phiGoal = 1.26;
} else if (focus === "broadleaf") {
targetGoal.set(1.38, 1.5, 0);
cameraState.radiusGoal = 5.55 * narrowScale;
cameraState.thetaGoal = 0.11;
cameraState.phiGoal = 1.27;
} else {
targetGoal.set(0, 1.42, 0);
cameraState.radiusGoal = fitRadius();
cameraState.thetaGoal = 0.09;
cameraState.phiGoal = 1.27;
}
for (const button of focusButtons) {
const selected = button.dataset.focus === focus;
button.classList.toggle("active", selected);
button.setAttribute("aria-pressed", String(selected));
}
}
for (const button of focusButtons) {
button.addEventListener("click", () => setFocus(button.dataset.focus));
}
const grassCallout = document.querySelector("#grass-callout");
const broadleafCallout = document.querySelector("#broadleaf-callout");
const grassLeader = document.querySelector("#grass-leader");
const broadleafLeader = document.querySelector("#broadleaf-leader");
const grassRing = document.querySelector("#grass-ring");
const grassDot = document.querySelector("#grass-dot");
const broadleafRing = document.querySelector("#broadleaf-ring");
const broadleafDot = document.querySelector("#broadleaf-dot");
function projectToScreen(point) {
const projected = point.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight
};
}
function updateLeader(callout, leader, ring, dot, anchor, side) {
const box = callout.getBoundingClientRect();
const start = {
x: side === "left" ? box.right - 8 : box.left + 8,
y: box.top + box.height * 0.55
};
const end = projectToScreen(anchor);
const bend =
side === "left"
? Math.max(start.x + 38, (start.x + end.x) * 0.5)
: Math.min(start.x - 38, (start.x + end.x) * 0.5);
leader.setAttribute(
"d",
`M ${start.x} ${start.y} C ${bend} ${start.y}, ${bend} ${end.y}, ${end.x} ${end.y}`
);
for (const element of [ring, dot]) {
element.setAttribute("cx", end.x);
element.setAttribute("cy", end.y);
}
}
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
const selected = document.querySelector("[data-focus].active")?.dataset.focus;
if (selected === "both") cameraState.radiusGoal = fitRadius();
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-delta * 5.2);
cameraState.theta +=
(cameraState.thetaGoal - cameraState.theta) * damping;
cameraState.phi +=
(cameraState.phiGoal - cameraState.phi) * damping;
cameraState.radius +=
(cameraState.radiusGoal - cameraState.radius) * damping;
target.lerp(targetGoal, damping);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
target.y + cameraState.radius * Math.cos(cameraState.phi),
target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(target);
if (!reducedMotion) {
grassSway.rotation.z = Math.sin(elapsed * 0.85) * 0.012;
grassSway.rotation.x = Math.sin(elapsed * 0.58 + 0.7) * 0.008;
broadleafSway.rotation.z = Math.sin(elapsed * 0.62 + 1.3) * 0.009;
broadleafSway.rotation.x = Math.sin(elapsed * 0.47) * 0.006;
growthRing.scale.setScalar(1 + Math.sin(elapsed * 2.1) * 0.045);
growthRingOuter.scale.setScalar(1 + Math.sin(elapsed * 2.1 + 0.4) * 0.06);
growthBeads.rotation.y = elapsed * 0.22;
apexHalo.rotation.z = elapsed * 0.28;
apexHalo.scale.setScalar(1 + Math.sin(elapsed * 2.0) * 0.035);
}
scene.updateMatrixWorld(true);
const grassAnchor = grassSway.localToWorld(new THREE.Vector3(0, 0.22, 0));
const broadleafAnchor = broadleafSway.localToWorld(
new THREE.Vector3(0, 2.76, 0)
);
updateLeader(
grassCallout,
grassLeader,
grassRing,
grassDot,
grassAnchor,
"left"
);
updateLeader(
broadleafCallout,
broadleafLeader,
broadleafRing,
broadleafDot,
broadleafAnchor,
"right"
);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```