Prompt specification
Build or customize the Three.js 3D scene "Pollen transfer between flowers" 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: Pollen transfer between flowers
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pollen-transfer-between-flowers-x0654
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: pollen transfer between flowers. Animate a bee visiting two compatible flower models; symbolic pollen grains move from anthers onto the bee and then to a stigma at the next visit. Return one self-contained HTML file.
Working Three.js Starter (pollen-transfer-between-flowers-x0654):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dceee1" />
<title>Pollen Link — Voxel Pollination</title>
<style>
:root {
--ink: #173f35;
--muted: #638177;
--panel: rgba(255, 255, 248, 0.86);
--line: rgba(23, 63, 53, 0.14);
--gold: #f5b82e;
--magenta: #c94b9a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 78% 16%, rgba(255, 249, 207, 0.9), transparent 28%),
linear-gradient(180deg, #cce9ea 0%, #e9f3dc 54%, #d3e7c7 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#world {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.brand {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
pointer-events: none;
user-select: none;
}
.brand-row {
display: flex;
align-items: center;
gap: 12px;
}
.brand-icon {
position: relative;
width: 42px;
height: 42px;
flex: 0 0 auto;
filter: drop-shadow(0 5px 8px rgba(23, 63, 53, 0.12));
}
.brand-icon i {
position: absolute;
width: 13px;
height: 13px;
background: var(--magenta);
border: 2px solid rgba(255, 255, 255, 0.9);
}
.brand-icon i:nth-child(1) { left: 2px; top: 14px; }
.brand-icon i:nth-child(2) { left: 14px; top: 2px; }
.brand-icon i:nth-child(3) { left: 26px; top: 14px; }
.brand-icon i:nth-child(4) { left: 14px; top: 26px; }
.brand-icon::after {
content: "";
position: absolute;
width: 12px;
height: 12px;
left: 15px;
top: 15px;
background: var(--gold);
border: 2px solid rgba(255, 255, 255, 0.9);
z-index: 2;
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1;
letter-spacing: 0.12em;
font-weight: 850;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.match-card {
position: fixed;
top: 24px;
right: 26px;
z-index: 5;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 15px;
background: rgba(255, 255, 248, 0.72);
box-shadow: 0 12px 32px rgba(40, 87, 67, 0.1);
backdrop-filter: blur(12px);
user-select: none;
}
.match-copy {
line-height: 1.1;
}
.match-copy strong {
display: block;
font-size: 11px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.match-copy span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.match-icon {
width: 24px;
height: 24px;
display: grid;
place-items: center;
border-radius: 8px;
color: #fff;
background: #4e9b73;
font-size: 14px;
font-weight: 900;
}
.flower-pair {
display: flex;
align-items: center;
gap: 5px;
}
.mini-flower {
position: relative;
width: 20px;
height: 20px;
}
.mini-flower::before,
.mini-flower::after {
content: "";
position: absolute;
inset: 5px;
background: var(--magenta);
box-shadow:
-6px 0 0 var(--magenta),
6px 0 0 var(--magenta),
0 -6px 0 var(--magenta),
0 6px 0 var(--magenta);
}
.mini-flower::after {
inset: 7px;
background: var(--gold);
box-shadow: none;
}
.pair-link {
width: 12px;
height: 2px;
background: #72a98d;
position: relative;
}
.pair-link::after {
content: "";
position: absolute;
right: -1px;
top: -3px;
width: 0;
height: 0;
border-left: 5px solid #72a98d;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
}
.marker {
position: fixed;
z-index: 4;
pointer-events: none;
transform: translate(-50%, -100%);
min-width: 126px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 11px;
background: rgba(255, 255, 248, 0.85);
box-shadow: 0 8px 24px rgba(23, 63, 53, 0.12);
backdrop-filter: blur(8px);
transition: opacity 180ms ease;
white-space: nowrap;
}
.marker::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 10px;
height: 10px;
transform: translateX(-50%) rotate(45deg);
background: rgba(255, 255, 248, 0.9);
border-right: 1px solid rgba(255, 255, 255, 0.85);
border-bottom: 1px solid rgba(255, 255, 255, 0.85);
}
.marker strong {
display: block;
font-size: 10px;
letter-spacing: 0.12em;
}
.marker span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.marker.a strong { color: #b74286; }
.marker.b strong { color: #8768b4; }
.control-panel {
position: fixed;
z-index: 8;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
width: min(820px, calc(100vw - 28px));
display: grid;
grid-template-columns: auto minmax(240px, 1fr) auto;
gap: 16px;
align-items: center;
padding: 14px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 52px rgba(35, 77, 59, 0.16);
backdrop-filter: blur(16px);
}
.transport {
display: flex;
gap: 8px;
align-items: center;
}
.icon-button,
.small-button {
border: 1px solid var(--line);
color: var(--ink);
background: rgba(255, 255, 255, 0.72);
cursor: pointer;
transition: transform 150ms ease, background 150ms ease, color 150ms ease;
}
.icon-button:hover,
.small-button:hover {
transform: translateY(-1px);
background: #fff;
}
.icon-button {
width: 42px;
height: 42px;
border-radius: 12px;
font-size: 17px;
font-weight: 850;
}
.small-button {
height: 34px;
padding: 0 12px;
border-radius: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.small-button.active {
color: #fff;
border-color: transparent;
background: #367c5b;
}
.timeline {
min-width: 0;
}
.timeline-head {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 8px;
}
.phase-kicker {
color: #4e8c69;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.phase-title {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 13px;
font-weight: 760;
}
.time {
flex: 0 0 auto;
color: var(--muted);
font-variant-numeric: tabular-nums;
font-size: 10px;
}
.progress-track {
position: relative;
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(23, 63, 53, 0.1);
}
.progress-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0%;
border-radius: inherit;
background: linear-gradient(90deg, #cf4b98 0 44%, #f2b62f 44% 72%, #56a475 72% 100%);
}
.camera-actions {
display: flex;
gap: 7px;
}
.legend {
position: fixed;
left: 26px;
bottom: 113px;
z-index: 5;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border-radius: 10px;
color: var(--muted);
background: rgba(255, 255, 248, 0.68);
border: 1px solid rgba(255, 255, 255, 0.66);
backdrop-filter: blur(8px);
font-size: 10px;
pointer-events: none;
}
.pollen-key {
width: 10px;
height: 10px;
background: var(--gold);
box-shadow: 0 0 0 3px rgba(245, 184, 46, 0.2);
transform: rotate(45deg);
}
.gesture-hint {
position: fixed;
right: 26px;
bottom: 113px;
z-index: 5;
color: rgba(23, 63, 53, 0.65);
font-size: 10px;
letter-spacing: 0.05em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dceee1;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hide {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 16px;
}
.brand p,
.match-copy span,
.gesture-hint {
display: none;
}
.match-card {
top: 16px;
right: 16px;
padding: 9px 10px;
}
.match-copy strong {
font-size: 9px;
}
.control-panel {
bottom: 12px;
grid-template-columns: auto 1fr;
gap: 11px;
padding: 11px;
}
.camera-actions {
grid-column: 1 / -1;
justify-content: flex-end;
}
.legend {
left: 14px;
bottom: 145px;
}
.marker {
min-width: 106px;
padding: 7px 8px;
}
.marker span {
display: none;
}
}
@media (max-width: 470px) {
.brand-icon {
display: none;
}
.brand h1 {
font-size: 14px;
}
.match-copy {
display: none;
}
.phase-title {
font-size: 11px;
}
.time {
display: none;
}
}
</style>
</head>
<body>
<canvas id="world" aria-label="Interactive voxel pollination scene"></canvas>
<header class="brand">
<div class="brand-row">
<div class="brand-icon" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<h1>POLLEN LINK</h1>
<p>Voxel pollination study</p>
</div>
</div>
</header>
<aside class="match-card" aria-label="Compatible flower pairing">
<div class="flower-pair" aria-hidden="true">
<span class="mini-flower"></span>
<span class="pair-link"></span>
<span class="mini-flower"></span>
</div>
<div class="match-copy">
<strong>Compatible pair</strong>
<span>Matching petal & pollen profile</span>
</div>
<div class="match-icon" aria-hidden="true">✓</div>
</aside>
<div class="marker a" id="markerA">
<strong>FLOWER A</strong>
<span>Anther source</span>
</div>
<div class="marker b" id="markerB">
<strong>FLOWER B</strong>
<span>Stigma target</span>
</div>
<div class="legend"><span class="pollen-key"></span> Gold voxels represent symbolic pollen</div>
<div class="gesture-hint">Drag to orbit · Scroll to zoom · Space to pause</div>
<section class="control-panel" aria-label="Animation controls">
<div class="transport">
<button class="icon-button" id="play" type="button" aria-label="Pause animation" title="Play or pause">Ⅱ</button>
<button class="icon-button" id="restart" type="button" aria-label="Restart animation" title="Restart">↺</button>
</div>
<div class="timeline">
<div class="timeline-head">
<div>
<span class="phase-kicker" id="phaseKicker">01 / ARRIVAL</span>
<strong class="phase-title" id="phaseTitle" aria-live="polite">Bee approaches Flower A</strong>
</div>
<span class="time" id="time">00:00 / 00:15</span>
</div>
<div class="progress-track">
<div class="progress-fill" id="progress"></div>
</div>
</div>
<div class="camera-actions">
<button class="small-button" id="follow" type="button">Follow bee</button>
<button class="small-button" id="resetCamera" type="button">Reset view</button>
</div>
</section>
<div id="loading">Growing the voxel meadow…</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("#world");
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);
renderer.setClearColor(0x000000, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xdcebd5, 17, 34);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
70
);
const world = new THREE.Group();
scene.add(world);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
}
function box(parent, size, position, material, castShadow = true, receiveShadow = false) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
const palette = {
grass: standardMaterial(0x84b66b),
grassDark: standardMaterial(0x5e955b),
grassLight: standardMaterial(0xa5ca78),
soil: standardMaterial(0x8a654a),
soilDark: standardMaterial(0x684b3d),
stem: standardMaterial(0x3f8752),
stemLight: standardMaterial(0x62a95c),
leaf: standardMaterial(0x4b9c5b),
petalA: standardMaterial(0xc94b9a),
petalB: standardMaterial(0xe167ad),
petalC: standardMaterial(0xa93983),
petalD: standardMaterial(0xf08cc1),
center: standardMaterial(0x7d2866),
path: standardMaterial(0xd9c79e),
pathDark: standardMaterial(0xbda980),
cloud: standardMaterial(0xf8fbf1, { roughness: 1 }),
hill: standardMaterial(0x78a96e),
hillDark: standardMaterial(0x639569),
beeYellow: standardMaterial(0xf4c52d),
beeBrown: standardMaterial(0x6f4626),
beeBlack: standardMaterial(0x202724),
beeWhite: standardMaterial(0xfffdf2),
wing: standardMaterial(0xe9fbff, {
transparent: true,
opacity: 0.55,
depthWrite: false,
roughness: 0.25
})
};
// Lighting
scene.add(new THREE.HemisphereLight(0xe8fbff, 0x66855c, 2.05));
const sun = new THREE.DirectionalLight(0xfff4cf, 3.0);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0007;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xb8e9ff, 0.85);
rimLight.position.set(8, 6, -8);
scene.add(rimLight);
// Seeded randomness keeps the composition stable.
let seed = 928371;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function randomRange(min, max) {
return min + (max - min) * random();
}
// Ground and soil layers
box(world, [20, 0.38, 13], [0, -0.2, 0], palette.grass, false, true);
box(world, [20.35, 0.42, 13.35], [0, -0.59, 0], palette.soil, false, true);
box(world, [20.55, 0.25, 13.55], [0, -0.88, 0], palette.soilDark, false, true);
// Uneven voxel grass patches.
for (let i = 0; i < 42; i++) {
const x = randomRange(-9.5, 9.5);
const z = randomRange(-6.1, 6.1);
const w = randomRange(0.35, 1.35);
const d = randomRange(0.3, 1.15);
const material = random() > 0.5 ? palette.grassLight : palette.grassDark;
box(world, [w, 0.025, d], [x, 0.012, z], material, false, true);
}
// A soft voxel path between the two flowers.
for (let i = 0; i < 13; i++) {
const x = -4.9 + i * 0.78;
const z = 0.1 + Math.sin(i * 0.58) * 0.72;
const stone = box(
world,
[0.62, 0.10, 0.48],
[x, 0.065, z],
i % 3 === 0 ? palette.pathDark : palette.path,
false,
true
);
stone.rotation.y = (random() - 0.5) * 0.3;
}
// Background voxel hills.
for (let i = 0; i < 15; i++) {
const x = -10 + i * 1.45;
const height = randomRange(0.7, 2.3);
const width = randomRange(1.5, 2.8);
box(
world,
[width, height, 1.5],
[x, height * 0.5 - 0.04, -7.3 + randomRange(-0.35, 0.35)],
i % 2 ? palette.hill : palette.hillDark,
false,
true
);
}
// Block clouds.
function makeCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
world.add(cloud);
box(cloud, [1.55, 0.48, 0.72], [0, 0, 0], palette.cloud, false);
box(cloud, [0.72, 0.72, 0.72], [-0.47, 0.25, 0], palette.cloud, false);
box(cloud, [0.92, 0.88, 0.72], [0.30, 0.31, 0], palette.cloud, false);
box(cloud, [0.55, 0.55, 0.72], [0.93, 0.06, 0], palette.cloud, false);
}
makeCloud(-5.6, 6.2, -7.6, 1.2);
makeCloud(5.8, 5.4, -8.2, 0.9);
makeCloud(0.1, 7.3, -10.5, 0.72);
// Grass blades and small decorative flowers.
function makeTinyFlower(x, z, colorMaterial) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
box(group, [0.065, 0.26, 0.065], [0, 0.13, 0], palette.stem, false);
box(group, [0.17, 0.08, 0.17], [0, 0.27, 0], colorMaterial, false);
box(group, [0.17, 0.08, 0.17], [0.12, 0.27, 0], colorMaterial, false);
box(group, [0.17, 0.08, 0.17], [-0.12, 0.27, 0], colorMaterial, false);
box(group, [0.08, 0.08, 0.16], [0, 0.27, 0.12], colorMaterial, false);
box(group, [0.08, 0.08, 0.16], [0, 0.27, -0.12], colorMaterial, false);
box(group, [0.10, 0.07, 0.10], [0, 0.33, 0], palette.center, false);
}
for (let i = 0; i < 38; i++) {
const x = randomRange(-9.3, 9.3);
const z = randomRange(-5.8, 5.8);
if (Math.abs(x + 3.4) < 1.1 && Math.abs(z + 0.9) < 1.0) continue;
if (Math.abs(x - 3.2) < 1.1 && Math.abs(z - 0.8) < 1.0) continue;
const bladeHeight = randomRange(0.15, 0.38);
const blade = box(
world,
[0.055, bladeHeight, 0.055],
[x, bladeHeight * 0.5, z],
random() > 0.5 ? palette.stemLight : palette.grassDark,
false
);
blade.rotation.z = randomRange(-0.22, 0.22);
}
for (let i = 0; i < 18; i++) {
const x = randomRange(-9.2, 9.2);
const z = randomRange(-5.9, 5.8);
if (Math.abs(x + 3.4) < 1.2 || Math.abs(x - 3.2) < 1.2) continue;
const petalMaterial = [palette.beeWhite, palette.petalB, palette.petalD][i % 3];
makeTinyFlower(x, z, petalMaterial);
}
function createFlower(x, z, phaseOffset) {
const root = new THREE.Group();
root.position.set(x, 0, z);
world.add(root);
// Soil collar.
box(root, [0.84, 0.10, 0.84], [0, 0.04, 0], palette.soilDark, false, true);
box(root, [0.62, 0.10, 0.62], [0, 0.11, 0], palette.soil, false, true);
// Segmented voxel stem.
for (let i = 0; i < 6; i++) {
box(
root,
[0.18, 0.27, 0.18],
[Math.sin(i * 0.9) * 0.025, 0.13 + i * 0.26, Math.cos(i * 0.7) * 0.02],
i % 2 ? palette.stem : palette.stemLight
);
}
// Leaves.
const leafA = box(root, [0.48, 0.12, 0.20], [0.27, 0.57, 0.02], palette.leaf);
leafA.rotation.z = -0.28;
const leafB = box(root, [0.46, 0.12, 0.20], [-0.25, 0.95, -0.02], palette.stemLight);
leafB.rotation.z = 0.31;
const head = new THREE.Group();
head.position.y = 1.56;
root.add(head);
// Central receptacle.
box(head, [0.48, 0.20, 0.48], [0, 0, 0], palette.center);
const cardinal = [
[1, 0], [1, 1], [0, 1], [-1, 1],
[-1, 0], [-1, -1], [0, -1], [1, -1]
];
// Three cube petals in each radial direction.
cardinal.forEach(([dx, dz], petalIndex) => {
const length = Math.abs(dx) === 1 && Math.abs(dz) === 1 ? 0.38 : 0.42;
for (let j = 0; j < 3; j++) {
const radius = length + j * 0.215;
const px = dx * radius;
const pz = dz * radius;
const petalMaterial = [
palette.petalA,
palette.petalB,
palette.petalC,
palette.petalD
][(petalIndex + j) % 4];
const petal = box(
head,
[j === 2 ? 0.27 : 0.30, 0.15, j === 2 ? 0.27 : 0.30],
[px, -j * 0.012, pz],
petalMaterial
);
petal.rotation.y = (dx + dz) * 0.035;
}
});
// Anthers: golden pollen-bearing structures.
const antherMaterial = standardMaterial(0xf2a82c, {
emissive: 0x7f3c00,
emissiveIntensity: 0.22,
roughness: 0.55
});
const antherMeshes = [];
cardinal.forEach(([dx, dz]) => {
const px = dx * 0.17;
const pz = dz * 0.17;
antherMeshes.push(
box(head, [0.105, 0.16, 0.105], [px, 0.17, pz], antherMaterial)
);
});
// Central stigma, built as a pale voxel cross.
const stigmaMaterial = standardMaterial(0xf3dfef, {
emissive: 0x8860aa,
emissiveIntensity: 0.12,
roughness: 0.58
});
const stigmaMeshes = [
box(head, [0.12, 0.28, 0.12], [0, 0.22, 0], stigmaMaterial),
box(head, [0.31, 0.08, 0.12], [0, 0.29, 0], stigmaMaterial),
box(head, [0.12, 0.08, 0.31], [0, 0.29, 0], stigmaMaterial)
];
return {
root,
head,
antherMeshes,
stigmaMeshes,
antherMaterial,
stigmaMaterial,
phaseOffset
};
}
const flowerA = createFlower(-3.4, -0.9, 0.0);
const flowerB = createFlower(3.2, 0.8, 1.7);
const sourceLight = new THREE.PointLight(0xffbe37, 0, 2.2);
const targetLight = new THREE.PointLight(0xdda0ff, 0, 2.2);
scene.add(sourceLight, targetLight);
// Voxel bee.
const bee = new THREE.Group();
bee.scale.setScalar(1.16);
bee.rotation.order = "YXZ";
scene.add(bee);
box(bee, [0.58, 0.36, 0.38], [-0.23, 0, 0], palette.beeYellow);
box(bee, [0.07, 0.385, 0.405], [-0.42, 0, 0], palette.beeBlack);
box(bee, [0.07, 0.385, 0.405], [-0.21, 0, 0], palette.beeBlack);
box(bee, [0.07, 0.385, 0.405], [0.00, 0, 0], palette.beeBlack);
box(bee, [0.36, 0.40, 0.39], [0.23, 0.015, 0], palette.beeBrown);
box(bee, [0.31, 0.32, 0.33], [0.49, 0.015, 0], palette.beeBlack);
// Eyes and antennae.
box(bee, [0.025, 0.085, 0.085], [0.652, 0.07, 0.095], palette.beeWhite);
box(bee, [0.025, 0.085, 0.085], [0.652, 0.07, -0.095], palette.beeWhite);
const antennaA = box(bee, [0.035, 0.19, 0.035], [0.66, 0.23, 0.075], palette.beeBlack);
antennaA.rotation.z = -0.48;
const antennaB = box(bee, [0.035, 0.19, 0.035], [0.66, 0.23, -0.075], palette.beeBlack);
antennaB.rotation.z = -0.48;
// Legs.
[-0.25, 0.05, 0.31].forEach((legX, index) => {
[-0.22, 0.22].forEach((legZ) => {
const leg = box(
bee,
[0.045, 0.25, 0.045],
[legX, -0.22, legZ],
palette.beeBlack
);
leg.rotation.x = legZ > 0 ? -0.28 : 0.28;
leg.rotation.z = (index - 1) * 0.08;
});
});
// Flapping wings.
const wingPivots = [];
[-1, 1].forEach((side) => {
const pivot = new THREE.Group();
pivot.position.set(0.15, 0.24, side * 0.17);
bee.add(pivot);
const wing = box(
pivot,
[0.44, 0.045, 0.24],
[0, 0, side * 0.13],
palette.wing,
false
);
wing.castShadow = false;
wingPivots.push({ pivot, side });
});
const attachmentPoints = [
new THREE.Vector3(-0.34, 0.225, 0.105),
new THREE.Vector3(-0.23, 0.225, -0.12),
new THREE.Vector3(-0.12, 0.225, 0.12),
new THREE.Vector3(-0.03, 0.22, -0.09),
new THREE.Vector3(-0.29, 0.205, -0.12),
new THREE.Vector3(-0.10, 0.205, -0.12)
];
// Symbolic pollen grains.
const pollenGrains = [];
for (let i = 0; i < 6; i++) {
const material = standardMaterial(0xffc52f, {
emissive: 0xff8a00,
emissiveIntensity: 0.62,
roughness: 0.4,
transparent: true,
opacity: 1
});
const grain = new THREE.Mesh(unitBox, material);
grain.scale.setScalar(0.085);
grain.castShadow = true;
scene.add(grain);
pollenGrains.push(grain);
}
// A dotted golden route appears during the flight.
const routeDots = [];
const routeMaterial = standardMaterial(0xf6bd36, {
emissive: 0xff9300,
emissiveIntensity: 0.45,
transparent: true,
opacity: 0,
depthWrite: false
});
for (let i = 0; i < 24; i++) {
const dot = new THREE.Mesh(unitBox, routeMaterial);
dot.scale.setScalar(0.045);
dot.visible = false;
scene.add(dot);
routeDots.push(dot);
}
// Ambient meadow motes.
const motes = [];
const moteMaterial = standardMaterial(0xfff7cf, {
emissive: 0xffedb0,
emissiveIntensity: 0.25,
transparent: true,
opacity: 0.48,
depthWrite: false
});
for (let i = 0; i < 26; i++) {
const mote = new THREE.Mesh(unitBox, moteMaterial);
const size = randomRange(0.025, 0.055);
mote.scale.setScalar(size);
mote.position.set(
randomRange(-9, 9),
randomRange(0.35, 4.5),
randomRange(-6, 6)
);
scene.add(mote);
motes.push({
mesh: mote,
baseX: mote.position.x,
baseY: mote.position.y,
baseZ: mote.position.z,
phase: randomRange(0, Math.PI * 2),
speed: randomRange(0.15, 0.4)
});
}
// Custom orbit controls: no addons are used.
const orbit = {
theta: 0.70,
phi: 1.04,
radius: 13.2,
target: new THREE.Vector3(0, 1.25, 0),
currentTarget: new THREE.Vector3(0, 1.25, 0),
currentRadius: 13.2,
follow: false,
followZoom: 0
};
const pointers = new Map();
let dragged = false;
let lastPointer = { x: 0, y: 0 };
let lastPinchDistance = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
canvas.setPointerCapture(event.pointerId);
if (pointers.size === 1) {
dragged = true;
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && dragged) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.42, 1.43);
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
if (orbit.follow) {
orbit.followZoom = THREE.MathUtils.clamp(
orbit.followZoom + (lastPinchDistance - distance) * 0.012,
-2.2,
5.5
);
} else {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + (lastPinchDistance - distance) * 0.018,
6,
22
);
}
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
if (pointers.size === 0) dragged = false;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
if (orbit.follow) {
orbit.followZoom = THREE.MathUtils.clamp(orbit.followZoom + event.deltaY * 0.006, -2.2, 5.5);
} else {
orbit.radius = THREE.MathUtils.clamp(orbit.radius + event.deltaY * 0.009, 6, 22);
}
}, { passive: false });
// Animation state.
const DURATION = 15;
let simTime = 0;
let visualTime = 0;
let playing = true;
let lastFrame = performance.now();
let lastPhase = -1;
const startPosition = new THREE.Vector3(-6.1, 3.35, 4.25);
const phaseData = [
{ at: 0, kicker: "01 / ARRIVAL", title: "Bee approaches Flower A" },
{ at: 1.8, kicker: "02 / COLLECTION", title: "Pollen lifts from the anthers" },
{ at: 3.8, kicker: "03 / TRANSFER", title: "Pollen rides to a compatible bloom" },
{ at: 7.6, kicker: "04 / DEPOSITION", title: "Pollen settles onto the stigma" },
{ at: 9.6, kicker: "05 / RETURN", title: "The bee completes the pollination loop" },
{ at: 12.8, kicker: "06 / READY", title: "The next compatible pairing is ready" }
];
const phaseKicker = document.querySelector("#phaseKicker");
const phaseTitle = document.querySelector("#phaseTitle");
const progress = document.querySelector("#progress");
const timeLabel = document.querySelector("#time");
const playButton = document.querySelector("#play");
const followButton = document.querySelector("#follow");
function easeInOutCubic(t) {
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function easeOutCubic(t) {
return 1 - Math.pow(1 - t, 3);
}
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function bezierPoint(points, t) {
const u = 1 - t;
return new THREE.Vector3()
.addScaledVector(points[0], u * u * u)
.addScaledVector(points[1], 3 * u * u * t)
.addScaledVector(points[2], 3 * u * t * t)
.addScaledVector(points[3], t * t * t);
}
function bezierTangent(points, t) {
const u = 1 - t;
return new THREE.Vector3()
.addScaledVector(
points[1].clone().sub(points[0]),
3 * u * u
)
.addScaledVector(
points[2].clone().sub(points[1]),
6 * u * t
)
.addScaledVector(
points[3].clone().sub(points[2]),
3 * t * t
)
.normalize();
}
function horizontalDirection(from, to) {
const direction = to.clone().sub(from);
direction.y = 0;
if (direction.lengthSq() < 0.0001) direction.set(1, 0, 0);
return direction.normalize();
}
function yawFromDirection(direction) {
return Math.atan2(-direction.z, direction.x);
}
function setBeePose(position, direction, roll = 0) {
bee.position.copy(position);
bee.rotation.y = yawFromDirection(direction);
bee.rotation.z = roll;
}
function updateCamera() {
const desiredTarget = orbit.follow
? bee.position.clone().add(new THREE.Vector3(0, 0.08, 0))
: orbit.target;
const desiredRadius = orbit.follow
? 6.4 + orbit.followZoom
: orbit.radius;
const smoothing = 1 - Math.pow(0.001, 1 / 60);
orbit.currentTarget.lerp(desiredTarget, smoothing);
orbit.currentRadius = THREE.MathUtils.lerp(
orbit.currentRadius,
desiredRadius,
smoothing
);
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
const offset = new THREE.Vector3(
sinPhi * Math.sin(orbit.theta) * orbit.currentRadius,
cosPhi * orbit.currentRadius,
sinPhi * Math.cos(orbit.theta) * orbit.currentRadius
);
camera.position.copy(orbit.currentTarget).add(offset);
camera.lookAt(orbit.currentTarget);
}
function projectMarker(element, position, opacity = 1) {
const projected = position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = `${opacity}`;
}
const markerA = document.querySelector("#markerA");
const markerB = document.querySelector("#markerB");
function updatePollen(t, centers) {
pollenGrains.forEach((grain, index) => {
const source = flowerA.antherMeshes[index % flowerA.antherMeshes.length]
.getWorldPosition(new THREE.Vector3());
source.y += 0.065;
const attachment = attachmentPoints[index];
const destination = bee.localToWorld(attachment.clone());
const target = flowerB.stigmaMeshes[index % flowerB.stigmaMeshes.length]
.getWorldPosition(new THREE.Vector3());
target.y += 0.09;
const pickupStart = 1.90 + index * 0.11;
const pickupDuration = 0.72;
const depositStart = 7.70 + index * 0.11;
const depositDuration = 0.75;
if (t < pickupStart) {
grain.visible = true;
grain.position.copy(source);
grain.scale.setScalar(0.085 * 0.78);
} else if (t < pickupStart + pickupDuration) {
const u = clamp01((t - pickupStart) / pickupDuration);
const eased = easeInOutCubic(u);
grain.visible = true;
grain.position.lerpVectors(source, destination, eased);
grain.position.y += Math.sin(u * Math.PI) * 0.48;
grain.scale.setScalar(0.085 * (0.78 + 0.22 * eased));
} else if (t < depositStart) {
grain.visible = true;
grain.position.copy(destination);
grain.scale.setScalar(0.085);
} else if (t < depositStart + depositDuration) {
const u = clamp01((t - depositStart) / depositDuration);
const eased = easeInOutCubic(u);
grain.visible = true;
grain.position.lerpVectors(destination, target, eased);
grain.position.y += Math.sin(u * Math.PI) * 0.38;
grain.scale.setScalar(0.085);
} else {
const fade = clamp01(
1 - (t - depositStart - depositDuration) / 0.24
);
grain.visible = fade > 0;
grain.position.copy(target);
grain.scale.setScalar(0.085 * Math.max(0.001, fade));
}
});
}
function updateRoute(t, flightPoints) {
const fadeIn = clamp01((t - 3.8) / 0.65);
const fadeOut = clamp01((7.6 - t) / 0.65);
const opacity = Math.min(fadeIn, fadeOut) * 0.42;
const visible = opacity > 0.01;
routeMaterial.opacity = opacity;
routeDots.forEach((dot, index) => {
dot.visible = visible;
if (!visible) return;
const u = index / (routeDots.length - 1);
const position = bezierPoint(flightPoints, u);
position.y += Math.sin((u * 13 + t * 1.6) * Math.PI) * 0.08;
dot.position.copy(position);
dot.rotation.set(t * 0.8, u * Math.PI * 2, t * 0.4);
});
}
function updatePhase(t) {
let phaseIndex = 0;
for (let i = 0; i < phaseData.length; i++) {
if (t >= phaseData[i].at) phaseIndex = i;
}
if (phaseIndex !== lastPhase) {
phaseKicker.textContent = phaseData[phaseIndex].kicker;
phaseTitle.textContent = phaseData[phaseIndex].title;
lastPhase = phaseIndex;
}
progress.style.width = `${(t / DURATION) * 100}%`;
const seconds = Math.floor(t);
timeLabel.textContent = `00:${String(seconds).padStart(2, "0")} / 00:15`;
}
function updateScene(t) {
// Gentle independent flower movement.
flowerA.head.rotation.z = Math.sin(visualTime * 1.15 + flowerA.phaseOffset) * 0.022;
flowerA.head.rotation.x = Math.cos(visualTime * 0.91) * 0.012;
flowerB.head.rotation.z = Math.sin(visualTime * 1.08 + flowerB.phaseOffset) * 0.024;
flowerB.head.rotation.x = Math.cos(visualTime * 0.86 + 0.7) * 0.012;
scene.updateMatrixWorld(true);
const centerA = flowerA.head.getWorldPosition(new THREE.Vector3());
const centerB = flowerB.head.getWorldPosition(new THREE.Vector3());
const visitA = centerA.clone().add(new THREE.Vector3(0.66, 0.69, 0.30));
const visitB = centerB.clone().add(new THREE.Vector3(-0.53, 0.71, 0.29));
const dirA = horizontalDirection(visitA, centerA);
const dirB = horizontalDirection(visitB, centerB);
const dirStart = horizontalDirection(startPosition, visitA);
const approachPoints = [
startPosition.clone(),
startPosition.clone().addScaledVector(dirStart, 1.7).add(new THREE.Vector3(0, 0.22, 0)),
visitA.clone().addScaledVector(dirA, -1.0),
visitA.clone()
];
const flightPoints = [
visitA.clone(),
visitA.clone().addScaledVector(dirA, 1.35).add(new THREE.Vector3(0, 1.05, 0)),
visitB.clone().addScaledVector(dirB, -1.70).add(new THREE.Vector3(0, 1.05, 0)),
visitB.clone()
];
const returnPoints = [
visitB.clone(),
visitB.clone().addScaledVector(dirB, 1.55).add(new THREE.Vector3(0, 1.1, 0)),
startPosition.clone().addScaledVector(dirStart, -2.15).add(new THREE.Vector3(0, 0.65, 0)),
startPosition.clone()
];
let beePosition;
let beeDirection;
let beeRoll = 0;
if (t < 1.8) {
const u = easeInOutCubic(clamp01(t / 1.8));
beePosition = bezierPoint(approachPoints, u);
beeDirection = bezierTangent(approachPoints, u);
beeRoll = Math.sin(u * Math.PI) * 0.10;
} else if (t < 3.8) {
const u = (t - 1.8) / 2.0;
beePosition = visitA.clone();
beePosition.y += Math.sin(u * Math.PI * 4) * 0.045;
beeDirection = dirA.clone();
beeRoll = Math.sin(u * Math.PI * 3) * 0.035;
} else if (t < 7.6) {
const u = easeInOutCubic(clamp01((t - 3.8) / 3.8));
beePosition = bezierPoint(flightPoints, u);
beeDirection = bezierTangent(flightPoints, u);
beeRoll = Math.sin(u * Math.PI * 2) * 0.09;
} else if (t < 9.6) {
const u = (t - 7.6) / 2.0;
beePosition = visitB.clone();
beePosition.y += Math.sin(u * Math.PI * 4) * 0.045;
beeDirection = dirB.clone();
beeRoll = Math.sin(u * Math.PI * 3) * 0.035;
} else if (t < 12.8) {
const u = easeInOutCubic(clamp01((t - 9.6) / 3.2));
beePosition = bezierPoint(returnPoints, u);
beeDirection = bezierTangent(returnPoints, u);
beeRoll = Math.sin(u * Math.PI * 2) * 0.10;
} else {
const u = (t - 12.8) / 2.2;
beePosition = startPosition.clone();
beePosition.y += Math.sin(u * Math.PI * 2) * 0.10;
beeDirection = dirStart.clone();
beeRoll = Math.sin(u * Math.PI * 2) * 0.04;
}
setBeePose(beePosition, beeDirection, beeRoll);
scene.updateMatrixWorld(true);
// Wing motion is faster during flight.
const flightAmount = t >= 3.8 && t < 7.6 ? 1 : 0;
const flap = 0.24 + flightAmount * 0.14 + Math.sin(visualTime * 39) * (0.34 + flightAmount * 0.16);
wingPivots.forEach(({ pivot, side }) => {
pivot.rotation.x = -side * flap;
});
updatePollen(t, { centerA, centerB });
updateRoute(t, flightPoints);
// Active-source and active-target illumination.
const collecting = t >= 1.8 && t < 3.8;
const depositing = t >= 7.6 && t < 9.6;
const pulse = 0.5 + 0.5 * Math.sin(visualTime * 8);
flowerA.antherMaterial.emissiveIntensity = collecting
? 0.65 + pulse * 1.55
: 0.22;
flowerB.stigmaMaterial.emissiveIntensity = depositing
? 0.55 + pulse * 1.45
: 0.12;
sourceLight.position.copy(centerA).add(new THREE.Vector3(0, 0.35, 0));
sourceLight.intensity = collecting ? 1.6 + pulse * 1.1 : 0;
targetLight.position.copy(centerB).add(new THREE.Vector3(0, 0.38, 0));
targetLight.intensity = depositing ? 1.45 + pulse * 1.0 : 0;
// Floating meadow motes.
motes.forEach((mote) => {
mote.mesh.position.x = mote.baseX + Math.sin(visualTime * mote.speed + mote.phase) * 0.35;
mote.mesh.position.y = mote.baseY + Math.sin(visualTime * mote.speed * 1.4 + mote.phase) * 0.22;
mote.mesh.position.z = mote.baseZ + Math.cos(visualTime * mote.speed * 0.8 + mote.phase) * 0.25;
mote.mesh.rotation.y = visualTime * 0.2 + mote.phase;
});
updatePhase(t);
updateCamera();
const markerAPosition = flowerA.antherMeshes[0]
.getWorldPosition(new THREE.Vector3())
.add(new THREE.Vector3(0, 0.65, 0));
const markerBPosition = flowerB.stigmaMeshes[0]
.getWorldPosition(new THREE.Vector3())
.add(new THREE.Vector3(0, 0.67, 0));
projectMarker(markerA, markerAPosition, collecting ? 1 : 0.72);
projectMarker(markerB, markerBPosition, depositing ? 1 : 0.72);
}
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastFrame) / 1000, 0.05);
lastFrame = now;
if (playing) {
simTime = (simTime + delta) % DURATION;
visualTime += delta;
}
updateScene(simTime);
renderer.render(scene, camera);
}
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Ⅱ" : "▶";
playButton.setAttribute("aria-label", playing ? "Pause animation" : "Play animation");
});
document.querySelector("#restart").addEventListener("click", () => {
simTime = 0;
playing = true;
playButton.textContent = "Ⅱ";
playButton.setAttribute("aria-label", "Pause animation");
});
followButton.addEventListener("click", () => {
orbit.follow = !orbit.follow;
followButton.classList.toggle("active", orbit.follow);
followButton.textContent = orbit.follow ? "Following" : "Follow bee";
});
document.querySelector("#resetCamera").addEventListener("click", () => {
orbit.follow = false;
orbit.followZoom = 0;
orbit.theta = 0.70;
orbit.phi = 1.04;
orbit.radius = 13.2;
followButton.classList.remove("active");
followButton.textContent = "Follow bee";
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.key.toLowerCase() === "r") {
document.querySelector("#restart").click();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Initial camera placement.
updateCamera();
updateScene(0);
requestAnimationFrame(animate);
setTimeout(() => {
document.querySelector("#loading").classList.add("hide");
}, 450);
</script>
</body>
</html>
```