Prompt specification
Build or customize the Three.js 3D scene "Orchard pollinator corridor" 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: Orchard pollinator corridor
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/orchard-pollinator-corridor-x0655
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows bee foraging and pollination. Compose flowering trees, wildflower strip, and a distant hive; bees follow short varied routes between blossoms while the garden structure remains more prominent than particle effects. Stylized solid forms.
Working Three.js Starter (orchard-pollinator-corridor-x0655):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pollinator Garden</title>
<style>
:root {
color-scheme: light;
--ink: #243c32;
--muted: #5e7468;
--cream: #fffaf0;
--accent: #d77791;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfe5df;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.intro {
position: fixed;
top: 24px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 18px 20px;
color: var(--ink);
background: rgba(255, 250, 240, 0.88);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
box-shadow: 0 14px 45px rgba(44, 77, 61, 0.15);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 34px);
font-weight: 500;
line-height: 1.05;
letter-spacing: -0.025em;
}
.intro p:last-child {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 10px 9px 14px;
color: var(--ink);
background: rgba(255, 250, 240, 0.86);
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 999px;
box-shadow: 0 10px 35px rgba(44, 77, 61, 0.13);
backdrop-filter: blur(10px);
font-size: 12px;
user-select: none;
}
.controls span {
white-space: nowrap;
}
button {
appearance: none;
border: 0;
border-radius: 999px;
padding: 9px 13px;
color: var(--cream);
background: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
background: #365849;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(215, 119, 145, 0.45);
outline-offset: 2px;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #cfe5df;
font-size: 13px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 640px) {
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.intro p:last-child { display: none; }
.controls {
right: 14px;
bottom: 14px;
}
.controls span { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="intro" aria-label="Scene description">
<p class="eyebrow">Pollinator garden</p>
<h1>A garden in motion</h1>
<p>
Bees weave between flowering trees, a bright wildflower strip,
and the distant hive.
</p>
</section>
<div class="controls" aria-label="Camera controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset-view" type="button">Reset view</button>
</div>
<div id="loading">Growing the garden…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfe5df);
scene.fog = new THREE.Fog(0xcfe5df, 18, 42);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
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;
document.querySelector("#scene").appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
const hemi = new THREE.HemisphereLight(0xf3fbff, 0x6f8054, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2cc, 3.0);
sun.position.set(-9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9ff, 0.75);
fill.position.set(10, 7, -10);
scene.add(fill);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true,
...options
});
const materials = {
outerGround: standard(0x9eb68d),
meadow: standard(0x91ae79),
pathEdge: standard(0xc9b68a),
path: standard(0xe4d1a7),
soil: standard(0x705846),
wood: standard(0x8d6748),
woodLight: standard(0xb28252),
hive: standard(0xe8b94f),
hiveDark: standard(0xa87431),
entrance: standard(0x3e3025),
trunk: standard(0x75503d),
leaf: standard(0x55764e),
leafLight: standard(0x6d8c58),
shrub: standard(0x648452),
stone: standard(0xa6afa2)
};
// -------------------------------------------------------------------------
// Small geometry helpers
// -------------------------------------------------------------------------
function cylinderBetween(a, b, radiusTop, radiusBottom, material, segments = 7) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
length,
segments
),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeRibbon(curve, width, y, material) {
const count = 80;
const positions = [];
const indices = [];
const point = new THREE.Vector3();
const tangent = new THREE.Vector3();
const side = new THREE.Vector3();
for (let i = 0; i <= count; i++) {
const t = i / count;
curve.getPoint(t, point);
curve.getTangent(t, tangent).normalize();
side.set(-tangent.z, 0, tangent.x).normalize();
positions.push(
point.x + side.x * width * 0.5,
y,
point.z + side.z * width * 0.5
);
positions.push(
point.x - side.x * width * 0.5,
y,
point.z - side.z * width * 0.5
);
if (i < count) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
return mesh;
}
// -------------------------------------------------------------------------
// Garden ground and path
// -------------------------------------------------------------------------
const outerGround = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
materials.outerGround
);
outerGround.rotation.x = -Math.PI / 2;
outerGround.position.y = -0.28;
outerGround.receiveShadow = true;
scene.add(outerGround);
const meadow = new THREE.Mesh(
new THREE.CylinderGeometry(11.8, 12, 0.26, 64),
materials.meadow
);
meadow.scale.set(1.17, 1, 0.92);
meadow.position.y = -0.13;
meadow.receiveShadow = true;
scene.add(meadow);
const pathCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-2.8, 0, 8.0),
new THREE.Vector3(-1.5, 0, 5.8),
new THREE.Vector3(-1.9, 0, 3.6),
new THREE.Vector3(-0.4, 0, 1.5),
new THREE.Vector3(-0.2, 0, -1.4),
new THREE.Vector3(0.6, 0, -4.4),
new THREE.Vector3(0.8, 0, -7.4)
],
false,
"catmullrom",
0.42
);
scene.add(makeRibbon(pathCurve, 1.55, 0.012, materials.pathEdge));
scene.add(makeRibbon(pathCurve, 1.08, 0.025, materials.path));
// -------------------------------------------------------------------------
// Wildflower strip
// -------------------------------------------------------------------------
const bedX = 3.15;
const bedZ = 2.35;
const bedWidth = 7.0;
const bedDepth = 2.35;
const bedBaseY = 0.12;
const bed = new THREE.Mesh(
new THREE.BoxGeometry(bedWidth, 0.16, bedDepth),
materials.soil
);
bed.position.set(bedX, 0.035, bedZ);
bed.receiveShadow = true;
scene.add(bed);
const borderPieces = [
[bedX, bedZ - bedDepth / 2, bedWidth + 0.16, 0.13],
[bedX, bedZ + bedDepth / 2, bedWidth + 0.16, 0.13],
[bedX - bedWidth / 2, bedZ, 0.13, bedDepth],
[bedX + bedWidth / 2, bedZ, 0.13, bedDepth]
];
for (const [x, z, w, d] of borderPieces) {
const edge = new THREE.Mesh(
new THREE.BoxGeometry(w, 0.17, d),
materials.woodLight
);
edge.position.set(x, 0.055, z);
edge.castShadow = true;
edge.receiveShadow = true;
scene.add(edge);
}
const flowerCount = 76;
const petalCount = flowerCount * 5;
const stemMesh = new THREE.InstancedMesh(
new THREE.CylinderGeometry(1, 1, 1, 5),
standard(0x4e794a),
flowerCount
);
const leafMesh = new THREE.InstancedMesh(
new THREE.SphereGeometry(1, 6, 4),
standard(0x63884d),
flowerCount * 2
);
const centerMesh = new THREE.InstancedMesh(
new THREE.OctahedronGeometry(1, 0),
standard(0xe7a936),
flowerCount
);
const petalMesh = new THREE.InstancedMesh(
new THREE.SphereGeometry(1, 6, 4),
standard(0xffffff),
petalCount
);
stemMesh.castShadow = true;
petalMesh.castShadow = true;
centerMesh.castShadow = true;
const dummy = new THREE.Object3D();
const stripBlossoms = [];
const petalPalette = [
new THREE.Color(0xf08ca5),
new THREE.Color(0xf5c85b),
new THREE.Color(0xf5f0d4),
new THREE.Color(0xa78bc7),
new THREE.Color(0xf49a62),
new THREE.Color(0xffffff)
];
for (let i = 0; i < flowerCount; i++) {
const x = bedX - bedWidth * 0.45 + Math.random() * bedWidth * 0.9;
const z = bedZ - bedDepth * 0.39 + Math.random() * bedDepth * 0.78;
const height = 0.34 + Math.random() * 0.58;
const topY = bedBaseY + height;
const petalColor =
petalPalette[Math.floor(Math.random() * petalPalette.length)];
dummy.position.set(x, bedBaseY + height * 0.5, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.013, height, 0.013);
dummy.updateMatrix();
stemMesh.setMatrixAt(i, dummy.matrix);
for (let leaf = 0; leaf < 2; leaf++) {
const side = leaf === 0 ? -1 : 1;
dummy.position.set(
x + side * 0.055,
bedBaseY + height * (0.35 + leaf * 0.16),
z + (Math.random() - 0.5) * 0.04
);
dummy.rotation.set(0, Math.random() * Math.PI, side * 0.25);
dummy.scale.set(0.052, 0.014, 0.15);
dummy.updateMatrix();
leafMesh.setMatrixAt(i * 2 + leaf, dummy.matrix);
}
dummy.position.set(x, topY, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.048, 0.036, 0.048);
dummy.updateMatrix();
centerMesh.setMatrixAt(i, dummy.matrix);
for (let p = 0; p < 5; p++) {
const angle = (p / 5) * Math.PI * 2 + Math.random() * 0.18;
const radius = 0.068;
dummy.position.set(
x + Math.sin(angle) * radius,
topY,
z + Math.cos(angle) * radius
);
dummy.rotation.set(0, angle, 0);
dummy.scale.set(0.074, 0.027, 0.115);
dummy.updateMatrix();
petalMesh.setMatrixAt(i * 5 + p, dummy.matrix);
petalMesh.setColorAt(i * 5 + p, petalColor);
}
stripBlossoms.push(new THREE.Vector3(x, topY + 0.025, z));
}
stemMesh.instanceMatrix.needsUpdate = true;
leafMesh.instanceMatrix.needsUpdate = true;
centerMesh.instanceMatrix.needsUpdate = true;
petalMesh.instanceMatrix.needsUpdate = true;
petalMesh.instanceColor.needsUpdate = true;
scene.add(stemMesh, leafMesh, centerMesh, petalMesh);
// -------------------------------------------------------------------------
// Flowering trees
// -------------------------------------------------------------------------
const blossomGeometry = new THREE.IcosahedronGeometry(0.095, 0);
const treeBlossomMaterials = [
standard(0xfff0cf),
standard(0xf2a0b6),
standard(0xffe7e4)
];
function createTree(x, z, scale, palette) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
const trunk = cylinderBetween(
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0.08, 2.65, 0),
0.17,
0.29,
materials.trunk,
7
);
group.add(trunk);
const clusterDefinitions = [
{ p: [-0.72, 2.72, 0.05], s: [1.13, 0.98, 1.05] },
{ p: [0.62, 2.82, 0.02], s: [1.30, 1.08, 1.10] },
{ p: [0.02, 3.47, -0.05], s: [1.18, 1.00, 1.02] },
{ p: [0.05, 2.72, 0.66], s: [1.06, 0.92, 1.04] }
];
const clusterCenters = clusterDefinitions.map(c => new THREE.Vector3(...c.p));
for (let i = 0; i < clusterCenters.length; i++) {
const branchStart = new THREE.Vector3(0.02, 1.65 + i * 0.18, 0);
const branchEnd = clusterCenters[i].clone().multiplyScalar(0.72);
branchEnd.y -= 0.25;
group.add(
cylinderBetween(
branchStart,
branchEnd,
0.07,
0.13,
materials.trunk,
6
)
);
}
const canopyGeometry = new THREE.IcosahedronGeometry(1, 1);
const blossomPositions = [];
clusterDefinitions.forEach((cluster, clusterIndex) => {
const center = new THREE.Vector3(...cluster.p);
const size = new THREE.Vector3(...cluster.s);
const color = palette[clusterIndex % palette.length];
const foliage = new THREE.Mesh(
canopyGeometry,
standard(color, { flatShading: true })
);
foliage.position.copy(center);
foliage.scale.copy(size);
foliage.rotation.set(
0.08 * clusterIndex,
0.43 * clusterIndex,
0.05 * clusterIndex
);
foliage.castShadow = true;
foliage.receiveShadow = true;
group.add(foliage);
for (let b = 0; b < 9; b++) {
const direction = new THREE.Vector3(
Math.random() * 2 - 1,
Math.random() * 1.25 - 0.35,
Math.random() * 2 - 1
).normalize();
const point = center.clone().add(
new THREE.Vector3(
direction.x * size.x,
direction.y * size.y,
direction.z * size.z
).multiplyScalar(0.97 + Math.random() * 0.08)
);
const blossom = new THREE.Mesh(
blossomGeometry,
treeBlossomMaterials[(b + clusterIndex) % treeBlossomMaterials.length]
);
blossom.position.copy(point);
const blossomScale = 0.72 + Math.random() * 0.45;
blossom.scale.setScalar(blossomScale);
blossom.castShadow = true;
group.add(blossom);
group.updateMatrixWorld(true);
blossomPositions.push(group.localToWorld(point.clone()));
}
});
scene.add(group);
return blossomPositions;
}
const leftBlossoms = createTree(
-5.0,
-1.6,
1.02,
[0xeaa0b4, 0xf3b5c2, 0xe992aa]
);
const rightBlossoms = createTree(
4.8,
-2.9,
1.08,
[0xf3d8dd, 0xeca1b7, 0xf7e5e8]
);
const backBlossoms = createTree(
-5.7,
-7.2,
0.78,
[0xf0c2c7, 0xe8a9b8, 0xf5d7d5]
);
// -------------------------------------------------------------------------
// Distant hive, stand, and fence
// -------------------------------------------------------------------------
const hive = new THREE.Group();
hive.position.set(0.8, 0, -7.55);
scene.add(hive);
const hivePlatform = new THREE.Mesh(
new THREE.BoxGeometry(1.65, 0.16, 1.35),
materials.wood
);
hivePlatform.position.y = 0.08;
hivePlatform.castShadow = true;
hivePlatform.receiveShadow = true;
hive.add(hivePlatform);
for (const x of [-0.58, 0.58]) {
for (const z of [-0.43, 0.43]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.9, 0.13),
materials.wood
);
leg.position.set(x, 0.53, z);
leg.castShadow = true;
hive.add(leg);
}
}
const lowerBox = new THREE.Mesh(
new THREE.BoxGeometry(1.02, 0.55, 0.82),
materials.hive
);
lowerBox.position.y = 1.18;
lowerBox.castShadow = true;
hive.add(lowerBox);
const upperBox = new THREE.Mesh(
new THREE.BoxGeometry(0.94, 0.43, 0.76),
materials.hiveDark
);
upperBox.position.y = 1.66;
upperBox.castShadow = true;
hive.add(upperBox);
for (let i = 0; i < 3; i++) {
const band = new THREE.Mesh(
new THREE.BoxGeometry(1.045, 0.055, 0.845),
materials.woodLight
);
band.position.y = 1.0 + i * 0.19;
hive.add(band);
}
const roof = new THREE.Mesh(
new THREE.ConeGeometry(0.79, 0.38, 4),
materials.wood
);
roof.position.y = 2.06;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.88;
roof.castShadow = true;
hive.add(roof);
const entrance = new THREE.Mesh(
new THREE.BoxGeometry(0.54, 0.12, 0.025),
materials.entrance
);
entrance.position.set(0, 1.08, 0.423);
hive.add(entrance);
const landingBoard = new THREE.Mesh(
new THREE.BoxGeometry(0.78, 0.07, 0.38),
materials.woodLight
);
landingBoard.position.set(0, 0.91, 0.55);
landingBoard.castShadow = true;
hive.add(landingBoard);
const fence = new THREE.Group();
fence.position.set(0.8, 0, -9.0);
scene.add(fence);
for (let i = 0; i < 9; i++) {
const picket = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 1.35, 0.13),
materials.woodLight
);
picket.position.set(-3.0 + i * 0.75, 0.66, 0);
picket.castShadow = true;
fence.add(picket);
}
for (const y of [0.42, 0.88]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(6.1, 0.11, 0.11),
materials.wood
);
rail.position.set(0, y, -0.02);
rail.castShadow = true;
fence.add(rail);
}
// -------------------------------------------------------------------------
// Bench and low shrubs for garden structure
// -------------------------------------------------------------------------
function createBench(x, z, rotation) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
for (const bx of [-0.82, 0.82]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.75, 0.55),
materials.wood
);
leg.position.set(bx, 0.38, 0);
leg.castShadow = true;
bench.add(leg);
}
for (let i = 0; i < 3; i++) {
const plank = new THREE.Mesh(
new THREE.BoxGeometry(2.05, 0.09, 0.17),
materials.woodLight
);
plank.position.set(0, 0.76, -0.22 + i * 0.2);
plank.castShadow = true;
bench.add(plank);
}
for (let i = 0; i < 2; i++) {
const back = new THREE.Mesh(
new THREE.BoxGeometry(2.05, 0.14, 0.09),
materials.woodLight
);
back.position.set(0, 1.0 + i * 0.27, -0.29);
back.castShadow = true;
bench.add(back);
}
scene.add(bench);
}
createBench(-3.55, 4.4, -0.14);
const shrubGeometry = new THREE.IcosahedronGeometry(1, 1);
function createShrub(x, z, scale) {
const shrub = new THREE.Group();
shrub.position.set(x, 0, z);
for (let i = 0; i < 4; i++) {
const leaf = new THREE.Mesh(
shrubGeometry,
materials.shrub
);
leaf.position.set(
(Math.random() - 0.5) * 0.55,
0.35 + Math.random() * 0.28,
(Math.random() - 0.5) * 0.5
);
leaf.scale.set(
0.48 * scale,
0.48 * scale,
0.46 * scale
);
leaf.castShadow = true;
leaf.receiveShadow = true;
shrub.add(leaf);
}
scene.add(shrub);
}
createShrub(-7.5, 4.5, 1.15);
createShrub(7.4, 4.1, 1.0);
createShrub(-7.7, -4.9, 0.95);
createShrub(7.5, -5.4, 1.15);
const stoneGeometry = new THREE.DodecahedronGeometry(0.2, 0);
for (let i = 0; i < 12; i++) {
const point = pathCurve.getPoint(0.12 + Math.random() * 0.7);
const side = Math.random() > 0.5 ? 1 : -1;
const tangent = pathCurve.getTangent(0.12 + Math.random() * 0.7);
const offset = new THREE.Vector3(-tangent.z, 0, tangent.x)
.multiplyScalar(side * (0.8 + Math.random() * 0.65));
const stone = new THREE.Mesh(stoneGeometry, materials.stone);
stone.position.set(
point.x + offset.x,
0.08,
point.z + offset.z
);
stone.scale.set(
0.7 + Math.random() * 0.5,
0.45 + Math.random() * 0.3,
0.7 + Math.random() * 0.5
);
stone.rotation.set(Math.random(), Math.random(), Math.random());
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
}
// -------------------------------------------------------------------------
// Bees
// -------------------------------------------------------------------------
const beeYellow = standard(0xf2b62f);
const beeBlack = standard(0x302d28);
const beeWing = standard(0xf5f0d9);
const beeEye = standard(0x151817);
const abdomenGeometry = new THREE.SphereGeometry(1, 10, 7);
const stripeGeometry = new THREE.TorusGeometry(0.079, 0.016, 5, 12);
const headGeometry = new THREE.SphereGeometry(1, 8, 6);
const wingGeometry = new THREE.SphereGeometry(1, 7, 4);
function createBee() {
const group = new THREE.Group();
const abdomen = new THREE.Mesh(abdomenGeometry, beeYellow);
abdomen.scale.set(0.102, 0.086, 0.158);
abdomen.castShadow = true;
group.add(abdomen);
for (const z of [-0.055, 0.035]) {
const stripe = new THREE.Mesh(stripeGeometry, beeBlack);
stripe.position.z = z;
stripe.scale.y = 0.9;
group.add(stripe);
}
const thorax = new THREE.Mesh(abdomenGeometry, beeYellow);
thorax.position.z = 0.105;
thorax.scale.set(0.092, 0.087, 0.09);
thorax.castShadow = true;
group.add(thorax);
const head = new THREE.Mesh(headGeometry, beeBlack);
head.position.set(0, 0.015, 0.19);
head.scale.setScalar(0.073);
head.castShadow = true;
group.add(head);
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(headGeometry, beeEye);
eye.position.set(side * 0.045, 0.035, 0.222);
eye.scale.set(0.025, 0.028, 0.018);
group.add(eye);
const wing = new THREE.Mesh(wingGeometry, beeWing);
wing.position.set(side * 0.105, 0.09, 0.025);
wing.scale.set(0.105, 0.014, 0.073);
wing.rotation.z = side * 0.28;
wing.castShadow = true;
group.add(wing);
group.userData[`wing${side}`] = wing;
group.userData[`wingSide${side}`] = side;
}
const antennaMaterial = beeBlack;
for (const side of [-1, 1]) {
const antenna = cylinderBetween(
new THREE.Vector3(side * 0.025, 0.05, 0.22),
new THREE.Vector3(side * 0.055, 0.095, 0.29),
0.006,
0.008,
antennaMaterial,
4
);
group.add(antenna);
}
group.scale.setScalar(1.22);
scene.add(group);
return group;
}
const bees = [];
const pools = [
{ points: leftBlossoms, count: 4 },
{ points: rightBlossoms, count: 4 },
{ points: stripBlossoms, count: 4 },
{ points: backBlossoms, count: 2 }
];
let beeId = 0;
for (const pool of pools) {
for (let i = 0; i < pool.count; i++) {
const mesh = createBee();
const startIndex = Math.floor(Math.random() * pool.points.length);
const start = pool.points[startIndex].clone();
mesh.position.copy(start);
bees.push({
id: beeId++,
mesh,
pool: pool.points,
current: start,
target: start.clone(),
lastIndex: startIndex,
segment: null,
pause: 0.1 + Math.random() * 0.6,
phase: Math.random() * Math.PI * 2
});
}
}
function chooseNextBlossom(bee) {
const candidates = [];
bee.pool.forEach((point, index) => {
if (index === bee.lastIndex) return;
const distance = point.distanceTo(bee.current);
if (distance < 0.22) return;
candidates.push({
index,
point,
distance,
score: distance * (0.72 + Math.random() * 0.56)
});
});
if (!candidates.length) {
bee.lastIndex = Math.floor(Math.random() * bee.pool.length);
return bee.pool[bee.lastIndex].clone();
}
candidates.sort((a, b) => a.score - b.score);
const shortlist = candidates.slice(0, Math.min(7, candidates.length));
const weightedIndex = Math.floor(
Math.pow(Math.random(), 1.65) * shortlist.length
);
const choice = shortlist[weightedIndex];
bee.lastIndex = choice.index;
return choice.point.clone();
}
function beginFlight(bee) {
const start = bee.current.clone();
const end = chooseNextBlossom(bee);
const direction = end.clone().sub(start);
const distance = direction.length();
const side = new THREE.Vector3().crossVectors(
direction,
new THREE.Vector3(0, 1, 0)
);
if (side.lengthSq() < 0.001) side.set(1, 0, 0);
side.normalize();
const bend = (Math.random() * 2 - 1) * Math.min(0.38, distance * 0.2);
const liftA = 0.18 + Math.random() * 0.48;
const liftB = 0.18 + Math.random() * 0.48;
const controlA = start.clone()
.lerp(end, 0.32)
.addScaledVector(side, bend);
controlA.y += liftA;
const controlB = start.clone()
.lerp(end, 0.7)
.addScaledVector(side, bend * 0.35);
controlB.y += liftB;
bee.segment = {
start,
controlA,
controlB,
end,
time: 0,
duration: THREE.MathUtils.clamp(distance * 0.72, 0.72, 2.45)
};
bee.target.copy(end);
}
const cubicPosition = new THREE.Vector3();
const cubicTangent = new THREE.Vector3();
const lookPoint = new THREE.Vector3();
function cubic(out, a, b, c, d, t) {
const oneMinus = 1 - t;
const a3 = oneMinus * oneMinus * oneMinus;
const b3 = 3 * oneMinus * oneMinus * t;
const c3 = 3 * oneMinus * t * t;
const d3 = t * t * t;
out.set(
a.x * a3 + b.x * b3 + c.x * c3 + d.x * d3,
a.y * a3 + b.y * b3 + c.y * c3 + d.y * d3,
a.z * a3 + b.z * b3 + c.z * d3 + d.z * d3
);
}
function cubicDerivative(out, a, b, c, d, t) {
const oneMinus = 1 - t;
const a3 = 3 * oneMinus * oneMinus;
const b3 = 6 * oneMinus * t;
const c3 = 3 * t * t;
out.set(
(b.x - a.x) * a3 +
(c.x - b.x) * b3 +
(d.x - c.x) * c3,
(b.y - a.y) * a3 +
(c.y - b.y) * b3 +
(d.y - c.y) * c3,
(b.z - a.z) * a3 +
(c.z - b.z) * b3 +
(d.z - c.z) * c3
);
}
function updateBees(delta, elapsed) {
for (const bee of bees) {
if (!bee.segment) {
if (bee.pause > 0) {
bee.pause -= delta;
} else {
beginFlight(bee);
}
}
if (bee.segment) {
const segment = bee.segment;
segment.time = Math.min(1, segment.time + delta / segment.duration);
const rawT = segment.time;
const t = rawT * rawT * (3 - 2 * rawT);
cubic(
cubicPosition,
segment.start,
segment.controlA,
segment.controlB,
segment.end,
t
);
cubicDerivative(
cubicTangent,
segment.start,
segment.controlA,
segment.controlB,
segment.end,
t
);
const flutter = Math.sin(elapsed * 10 + bee.phase) * 0.025;
cubicPosition.y += flutter;
bee.mesh.position.copy(cubicPosition);
if (cubicTangent.lengthSq() > 0.000001) {
lookPoint.copy(cubicPosition).add(cubicTangent);
bee.mesh.lookAt(lookPoint);
}
if (segment.time >= 1) {
bee.current.copy(segment.end);
bee.target.copy(segment.end);
bee.segment = null;
bee.pause = 0.22 + Math.random() * 0.72;
}
} else {
bee.mesh.position.copy(bee.current);
bee.mesh.position.y += Math.sin(elapsed * 3 + bee.phase) * 0.018;
}
for (const side of [-1, 1]) {
const wing = bee.mesh.userData[`wing${side}`];
const baseAngle = side * 0.28;
wing.rotation.z =
baseAngle + side * Math.sin(elapsed * 43 + bee.phase) * 0.47;
wing.rotation.x = Math.sin(elapsed * 37 + bee.phase) * 0.13;
}
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, touch, and keyboard
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 1.45, -1.0),
yaw: 0.38,
polar: 1.05,
radius: 21,
currentYaw: 0.38,
currentPolar: 1.05,
currentRadius: 21
};
const resetView = () => {
orbit.yaw = 0.38;
orbit.polar = 1.05;
orbit.radius = 21;
};
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 8);
orbit.currentYaw = THREE.MathUtils.lerp(
orbit.currentYaw,
orbit.yaw,
smoothing
);
orbit.currentPolar = THREE.MathUtils.lerp(
orbit.currentPolar,
orbit.polar,
smoothing
);
orbit.currentRadius = THREE.MathUtils.lerp(
orbit.currentRadius,
orbit.radius,
smoothing
);
const sinPolar = Math.sin(orbit.currentPolar);
camera.position.set(
orbit.target.x +
orbit.currentRadius * sinPolar * Math.sin(orbit.currentYaw),
orbit.target.y +
orbit.currentRadius * Math.cos(orbit.currentPolar),
orbit.target.z +
orbit.currentRadius * sinPolar * Math.cos(orbit.currentYaw)
);
camera.lookAt(orbit.target);
}
const pointer = {
active: false,
id: null,
x: 0,
y: 0
};
renderer.domElement.addEventListener("pointerdown", event => {
if (event.pointerType === "mouse" && event.button !== 0) return;
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus();
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
orbit.yaw -= dx * 0.005;
orbit.polar = THREE.MathUtils.clamp(
orbit.polar - dy * 0.0042,
0.48,
1.36
);
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
11,
29
);
},
{ passive: false }
);
addEventListener("keydown", event => {
if (event.key === "ArrowLeft") orbit.yaw += 0.09;
if (event.key === "ArrowRight") orbit.yaw -= 0.09;
if (event.key === "ArrowUp") {
orbit.polar = THREE.MathUtils.clamp(orbit.polar - 0.07, 0.48, 1.36);
}
if (event.key === "ArrowDown") {
orbit.polar = THREE.MathUtils.clamp(orbit.polar + 0.07, 0.48, 1.36);
}
if (event.key === "+" || event.key === "=") {
orbit.radius = Math.max(11, orbit.radius - 1);
}
if (event.key === "-") {
orbit.radius = Math.min(29, orbit.radius + 1);
}
});
document.querySelector("#reset-view").addEventListener("click", resetView);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
let firstFrame = true;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
updateBees(delta, elapsed);
updateCamera(delta);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.querySelector("#loading")?.remove();
}
});
</script>
</body>
</html>
```