Prompt specification
Build or customize the Three.js 3D scene "Wind and visitor flower comparison" 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: Wind and visitor flower comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wind-and-visitor-flower-comparison-x0765
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring flower pollination pathways. Display a grass-like flowering head beside a broad insect-visited flower, with enlarged anthers and stigmas; label these as selected examples rather than universal flower categories. Voxel style.
Working Three.js Starter (wind-and-visitor-flower-comparison-x0765):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Pollination Pathways</title>
<style>
:root {
color-scheme: dark;
--ink: #eef8ef;
--muted: #a9c2b7;
--panel: rgba(8, 27, 29, 0.88);
--line: rgba(205, 239, 220, 0.2);
--mint: #7be4c1;
--gold: #ffc857;
--coral: #f47f61;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07191c;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#app,
#scene,
#scene canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
outline: none;
}
.hud {
position: absolute;
z-index: 5;
pointer-events: none;
}
header {
top: 24px;
left: 26px;
max-width: 430px;
}
.eyebrow {
display: block;
margin-bottom: 7px;
color: var(--mint);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.65rem, 3vw, 2.65rem);
line-height: 1;
letter-spacing: -0.045em;
}
header p {
max-width: 390px;
margin: 11px 0 0;
color: var(--muted);
font-size: 0.88rem;
line-height: 1.5;
}
.legend {
top: 24px;
right: 24px;
width: 240px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.legend-title {
margin-bottom: 10px;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 8px 0;
color: #d8e9df;
font-size: 0.76rem;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: 0 0 12px currentColor;
}
.swatch.wind {
color: var(--mint);
background: var(--mint);
}
.swatch.insect {
color: var(--gold);
background: var(--gold);
}
.swatch.anther {
color: var(--coral);
background: var(--coral);
}
.swatch.stigma {
color: #b6f28a;
background: #b6f28a;
}
.legend-note {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 0.69rem;
line-height: 1.45;
}
.controls {
right: 24px;
bottom: 24px;
display: flex;
gap: 7px;
pointer-events: auto;
}
button {
min-width: 38px;
height: 36px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(8, 27, 29, 0.9);
color: var(--ink);
font: inherit;
font-size: 0.75rem;
cursor: pointer;
transition: border-color 150ms, background 150ms, transform 150ms;
}
button:hover,
button:focus-visible {
border-color: var(--mint);
background: rgba(30, 67, 59, 0.95);
outline: none;
transform: translateY(-1px);
}
.hint {
left: 50%;
bottom: 28px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(205, 239, 220, 0.12);
border-radius: 999px;
background: rgba(8, 27, 29, 0.72);
color: var(--muted);
font-size: 0.7rem;
white-space: nowrap;
}
.caveat {
left: 24px;
bottom: 24px;
max-width: 420px;
padding: 10px 13px;
border-left: 3px solid var(--mint);
border-radius: 0 8px 8px 0;
background: rgba(8, 27, 29, 0.8);
color: #bfd2c8;
font-size: 0.7rem;
line-height: 1.45;
}
.caveat strong {
color: var(--ink);
}
#leaders {
position: absolute;
z-index: 2;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke: rgba(185, 222, 202, 0.5);
stroke-width: 1;
stroke-dasharray: 3 4;
}
#leaders circle {
fill: #e9f7ed;
stroke: rgba(8, 27, 29, 0.9);
stroke-width: 2;
}
.callout {
position: absolute;
z-index: 4;
min-width: 125px;
padding: 9px 11px;
border: 1px solid rgba(220, 244, 229, 0.22);
border-radius: 9px;
background: rgba(8, 27, 29, 0.91);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
transform: translate(-50%, -100%);
pointer-events: none;
backdrop-filter: blur(8px);
}
.callout.selected {
border-color: rgba(123, 228, 193, 0.5);
}
.callout.selected.warm {
border-color: rgba(255, 200, 87, 0.52);
}
.callout .eyebrow {
margin-bottom: 4px;
font-size: 0.53rem;
letter-spacing: 0.13em;
}
.callout strong {
display: block;
font-size: 0.78rem;
line-height: 1.25;
}
.callout .sub {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.63rem;
}
.callout.mini {
display: flex;
align-items: center;
gap: 7px;
min-width: 0;
padding: 6px 8px;
border-radius: 7px;
color: #dbe9e0;
font-size: 0.61rem;
white-space: nowrap;
}
.callout.mini b {
color: white;
}
.key-dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--coral);
box-shadow: 0 0 8px currentColor;
}
.callout.stigma .key-dot {
background: #b6f28a;
}
@media (max-width: 760px) {
header {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
header p {
max-width: 300px;
font-size: 0.76rem;
}
.legend {
top: auto;
right: 12px;
bottom: 64px;
width: 185px;
padding: 10px 12px;
}
.legend-title {
margin-bottom: 6px;
}
.legend-row {
margin: 5px 0;
font-size: 0.66rem;
}
.legend-note {
display: none;
}
.caveat {
left: 12px;
bottom: 64px;
max-width: calc(100vw - 220px);
font-size: 0.61rem;
}
.controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
.callout.selected {
min-width: 112px;
max-width: 145px;
}
.callout.selected strong {
font-size: 0.67rem;
}
.callout.mini {
font-size: 0.54rem;
}
}
</style>
</head>
<body>
<div id="app">
<div id="scene" aria-label="Interactive voxel scene of two selected pollination examples"></div>
<svg id="leaders" aria-hidden="true"></svg>
<header class="hud">
<span class="eyebrow">Interactive botanical study</span>
<h1>Pollination Pathways</h1>
<p>
Two selected voxel examples showing pollen transfer by wind and by a
visiting insect. Drag to orbit; scroll to zoom.
</p>
</header>
<aside class="legend hud" aria-label="Scene legend">
<div class="legend-title">Path key</div>
<div class="legend-row">
<span class="swatch wind"></span>
Windborne pollen route
</div>
<div class="legend-row">
<span class="swatch insect"></span>
Insect-carried pollen route
</div>
<div class="legend-row">
<span class="swatch anther"></span>
Enlarged anthers
</div>
<div class="legend-row">
<span class="swatch stigma"></span>
Enlarged stigma
</div>
<div class="legend-note">
Structures are visually enlarged for clarity. The moving dots indicate
illustrative routes rather than measured trajectories.
</div>
</aside>
<div id="label-grass" class="callout selected">
<span class="eyebrow">Selected example 01</span>
<strong>Grass-like flowering head</strong>
<span class="sub">Windborne transfer shown</span>
</div>
<div id="label-broad" class="callout selected warm">
<span class="eyebrow">Selected example 02</span>
<strong>Broad insect-visited flower</strong>
<span class="sub">Insect-mediated transfer shown</span>
</div>
<div id="label-grass-anther" class="callout mini">
<span class="key-dot"></span><span><b>Anthers</b> · enlarged</span>
</div>
<div id="label-grass-stigma" class="callout mini stigma">
<span class="key-dot"></span><span><b>Stigma</b> · enlarged</span>
</div>
<div id="label-broad-anther" class="callout mini">
<span class="key-dot"></span><span><b>Anthers</b> · enlarged</span>
</div>
<div id="label-broad-stigma" class="callout mini stigma">
<span class="key-dot"></span><span><b>Stigma</b> · enlarged</span>
</div>
<div class="caveat hud">
<strong>Selected examples, not universal flower categories.</strong>
Pollination mechanisms vary and can overlap between plants.
</div>
<div class="hint hud">Drag to orbit · Scroll to zoom</div>
<div class="controls hud">
<button type="button" data-control="left" aria-label="Rotate left">↶</button>
<button type="button" data-control="right" aria-label="Rotate right">↷</button>
<button type="button" data-control="in" aria-label="Zoom in">+</button>
<button type="button" data-control="out" aria-label="Zoom out">−</button>
<button type="button" data-control="reset">Reset</button>
<button type="button" data-control="pause">Pause</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.querySelector("#scene");
const leaderLayer = document.querySelector("#leaders");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07191c);
scene.fog = new THREE.Fog(0x07191c, 17, 34);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 60);
const hemisphere = new THREE.HemisphereLight(0xd9fff0, 0x17352b, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd2, 3.1);
sun.position.set(5, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const mintLight = new THREE.PointLight(0x64f0cf, 13, 8, 2);
mintLight.position.set(-4, 4, 1);
scene.add(mintLight);
const goldLight = new THREE.PointLight(0xffc857, 15, 8, 2);
goldLight.position.set(3.5, 4, 1);
scene.add(goldLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function cube(
x, y, z,
sx, sy, sz,
color,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
unitBox,
color && color.isMaterial ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function branchBetween(start, end, width, color, parent = scene, steps = 12) {
for (let i = 0; i <= steps; i++) {
const p = new THREE.Vector3().lerpVectors(start, end, i / steps);
cube(p.x, p.y, p.z, width, width, width, color, parent);
}
}
// Voxel terrain.
const soilColors = [0x183e34, 0x1c473b, 0x214d40, 0x17392f];
for (let x = -13; x <= 13; x++) {
for (let z = -9; z <= 9; z++) {
const height = 0.18 + Math.random() * 0.19;
const color = soilColors[Math.floor(Math.random() * soilColors.length)];
cube(
x + (Math.random() - 0.5) * 0.05,
-height / 2,
z + (Math.random() - 0.5) * 0.05,
0.98,
height,
0.98,
color,
scene,
false
);
}
}
// Small voxel tufts around the perimeter.
for (let i = 0; i < 95; i++) {
const x = -12 + Math.random() * 24;
const z = -8 + Math.random() * 16;
if (x > -6 && x < 6 && Math.abs(z) < 3) continue;
const h = 0.25 + Math.random() * 0.4;
const green = Math.random() > 0.5 ? 0x2f7750 : 0x3a8958;
cube(x, h / 2, z, 0.07, h, 0.07, green);
if (Math.random() > 0.5) {
cube(x + 0.08, h * 0.45, z, 0.06, h * 0.75, 0.06, 0x286846);
}
}
// ------------------------------------------------------------
// Selected example 01: grass-like flowering head
// ------------------------------------------------------------
const grass = new THREE.Group();
scene.add(grass);
const gx = -4.0;
const gz = 0.0;
const stemTop = new THREE.Vector3(gx, 2.42, gz);
for (let i = 0; i < 18; i++) {
cube(
gx,
0.12 + i * 0.135,
gz,
0.12,
0.18,
0.12,
i % 3 === 0 ? 0x3a8b58 : 0x4a9c61,
grass
);
}
// Stepped grass leaves.
for (let i = 0; i < 6; i++) {
cube(gx - 0.13 - i * 0.09, 0.48 + i * 0.12, gz, 0.09, 0.17, 0.11, 0x4d9d5b, grass);
cube(gx + 0.13 + i * 0.08, 0.36 + i * 0.1, gz + 0.03, 0.08, 0.16, 0.1, 0x3f8e52, grass);
}
const grassSpikeletTips = [
new THREE.Vector3(gx + 0.44, 2.88, gz + 0.24),
new THREE.Vector3(gx - 0.68, 3.16, gz - 0.28),
new THREE.Vector3(gx + 0.03, 3.48, gz + 0.48),
new THREE.Vector3(gx - 0.12, 3.36, gz - 0.55),
new THREE.Vector3(gx + 0.63, 3.22, gz - 0.08)
];
const spikeletColors = [0xc8c08b, 0xded29b, 0xb6ae78];
grassSpikeletTips.forEach((tip, tipIndex) => {
branchBetween(
new THREE.Vector3(gx, 2.24 + tipIndex * 0.025, gz),
tip,
0.075,
0x438c50,
grass,
9
);
for (let j = 0; j < 5; j++) {
cube(
tip.x + (j % 2 ? 0.07 : -0.05),
tip.y - 0.22 + j * 0.105,
tip.z + (j % 3 === 0 ? 0.05 : -0.03),
0.14,
0.13,
0.14,
spikeletColors[(j + tipIndex) % spikeletColors.length],
grass
);
}
});
// Enlarged exposed anthers.
const grassAntherPoints = [
grassSpikeletTips[0],
grassSpikeletTips[1],
grassSpikeletTips[4]
];
grassAntherPoints.forEach((p, i) => {
cube(p.x, p.y - 0.18, p.z, 0.08, 0.25, 0.08, 0xd8d789, grass);
cube(
p.x + (i - 1) * 0.035,
p.y - 0.34,
p.z,
0.23,
0.27,
0.19,
0xf47f61,
grass
);
cube(
p.x + (i - 1) * 0.035,
p.y - 0.34,
p.z + 0.105,
0.11,
0.12,
0.035,
0xffad79,
grass
);
});
// Enlarged feathery stigma.
const grassStigma = new THREE.Vector3(gx - 0.74, 3.34, gz - 0.33);
cube(grassStigma.x, grassStigma.y - 0.22, grassStigma.z, 0.1, 0.34, 0.1, 0xd6d5a4, grass);
cube(grassStigma.x, grassStigma.y, grassStigma.z, 0.18, 0.16, 0.18, 0xd6d5a4, grass);
for (let i = 0; i < 5; i++) {
const angle = (i / 4 - 0.5) * 1.65;
const length = 0.36 + (i % 2) * 0.08;
branchBetween(
grassStigma,
new THREE.Vector3(
grassStigma.x + Math.sin(angle) * length,
grassStigma.y + Math.cos(angle) * length,
grassStigma.z - 0.03
),
0.045,
0xb6f28a,
grass,
5
);
}
// ------------------------------------------------------------
// Selected example 02: broad insect-visited flower
// ------------------------------------------------------------
const broad = new THREE.Group();
scene.add(broad);
const bx = 3.4;
const bz = 0.0;
const flowerY = 2.08;
for (let i = 0; i < 14; i++) {
cube(
bx,
0.12 + i * 0.135,
bz,
0.17,
0.18,
0.17,
i % 3 === 0 ? 0x347d48 : 0x489355,
broad
);
}
for (let i = 0; i < 7; i++) {
cube(bx - 0.18 - i * 0.09, 0.5 + i * 0.11, bz + 0.03, 0.1, 0.16, 0.12, 0x4b9859, broad);
cube(bx + 0.17 + i * 0.08, 0.44 + i * 0.1, bz - 0.02, 0.1, 0.15, 0.11, 0x3c884c, broad);
}
const petalColors = [0xf06f87, 0xf78398, 0xe95f7c, 0xff9aad];
// Petals are assembled from small voxel tiles.
for (let petal = 0; petal < 10; petal++) {
const angle = (petal / 10) * Math.PI * 2;
const radialX = Math.cos(angle);
const radialZ = Math.sin(angle);
const tangentX = -radialZ;
const tangentZ = radialX;
for (let row = 0; row < 6; row++) {
const width = row < 2 ? 3 : row < 4 ? 2 : 1;
const radius = 0.25 + row * 0.22;
for (let col = -width; col <= width; col++) {
if (row > 3 && Math.abs(col) > 0) continue;
const lateral = col * 0.18;
const px = bx + radialX * radius + tangentX * lateral;
const pz = bz + radialZ * radius + tangentZ * lateral;
const py = flowerY + row * row * 0.012;
cube(
px,
py,
pz,
0.19,
0.14,
0.19,
petalColors[(petal + row + col + 8) % petalColors.length],
broad
);
}
}
}
// Central golden disk.
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) {
if (Math.abs(x) + Math.abs(z) > 4) continue;
cube(
bx + x * 0.13,
flowerY + 0.12,
bz + z * 0.13,
0.135,
0.14,
0.135,
(x + z) % 2 === 0 ? 0xf3bd3f : 0xffd15b,
broad
);
}
}
// Enlarged anthers on visible filaments.
const broadAntherPositions = [
new THREE.Vector3(bx - 0.48, 2.67, bz + 0.16),
new THREE.Vector3(bx + 0.46, 2.68, bz + 0.10),
new THREE.Vector3(bx - 0.10, 2.70, bz - 0.42),
new THREE.Vector3(bx + 0.22, 2.66, bz + 0.38)
];
broadAntherPositions.forEach((p, i) => {
cube(p.x, p.y - 0.23, p.z, 0.065, 0.34, 0.065, 0xd7e0a2, broad);
cube(p.x, p.y, p.z, 0.25, 0.28, 0.22, 0xf47f61, broad);
cube(p.x, p.y + 0.03, p.z + 0.12, 0.13, 0.15, 0.035, 0xffae78, broad);
});
// Enlarged stigma with three lobes.
const broadStigma = new THREE.Vector3(bx + 0.16, 3.05, bz - 0.08);
cube(broadStigma.x, broadStigma.y - 0.27, broadStigma.z, 0.11, 0.42, 0.11, 0xdce0a8, broad);
cube(broadStigma.x, broadStigma.y - 0.02, broadStigma.z, 0.16, 0.15, 0.16, 0xdce0a8, broad);
cube(broadStigma.x - 0.13, broadStigma.y + 0.06, broadStigma.z, 0.21, 0.17, 0.19, 0xb6f28a, broad);
cube(broadStigma.x + 0.13, broadStigma.y + 0.08, broadStigma.z + 0.02, 0.21, 0.18, 0.2, 0xc9f6a1, broad);
cube(broadStigma.x, broadStigma.y + 0.14, broadStigma.z - 0.12, 0.2, 0.18, 0.2, 0xb6f28a, broad);
// ------------------------------------------------------------
// Pollination routes
// ------------------------------------------------------------
const pathAnimations = [];
function addVoxelPath(points, color, particleCount, speed, particleSize = 0.075) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => p.clone()),
false,
"catmullrom",
0.4
);
const pathGroup = new THREE.Group();
scene.add(pathGroup);
const dashMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.27,
depthWrite: false
});
for (let i = 0; i < particleCount * 2; i++) {
const t = (i + 0.35) / (particleCount * 2);
const p = curve.getPointAt(t);
cube(
p.x, p.y, p.z,
0.045, 0.045, 0.045,
dashMaterial,
pathGroup,
false
);
}
const particleMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.8,
roughness: 0.55,
flatShading: true
});
const particles = [];
for (let i = 0; i < particleCount; i++) {
const particle = cube(
0, 0, 0,
particleSize,
particleSize,
particleSize,
particleMaterial,
scene,
false
);
particles.push(particle);
}
// A block-built directional chevron.
const marker = new THREE.Group();
const markerMaterial = new THREE.MeshBasicMaterial({ color });
cube(0, 0, 0, 0.05, 0.05, 0.23, markerMaterial, marker, false);
cube(-0.07, 0, 0.13, 0.05, 0.05, 0.13, markerMaterial, marker, false);
cube(0.07, 0, 0.13, 0.05, 0.05, 0.13, markerMaterial, marker, false);
const markerT = 0.78;
marker.position.copy(curve.getPointAt(markerT));
marker.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
curve.getTangentAt(markerT).normalize()
);
scene.add(marker);
pathAnimations.push({ curve, particles, speed, particleSize });
return curve;
}
const windPath = addVoxelPath(
[
grassAntherPoints[0].clone().add(new THREE.Vector3(0, -0.18, 0)),
new THREE.Vector3(gx + 0.25, 3.25, gz + 0.18),
new THREE.Vector3(gx - 0.2, 3.63, gz - 0.05),
grassStigma.clone().add(new THREE.Vector3(0, 0.12, 0))
],
0x65e6d0,
12,
0.17,
0.09
);
const insectPath = addVoxelPath(
[
broadAntherPositions[0].clone().add(new THREE.Vector3(0, -0.05, 0)),
new THREE.Vector3(2.55, 3.18, 0.6),
new THREE.Vector3(3.12, 3.44, 0.32),
broadStigma.clone().add(new THREE.Vector3(0, 0.04, 0)),
new THREE.Vector3(4.35, 3.28, 0.3),
new THREE.Vector3(5.2, 3.85, 1.1),
new THREE.Vector3(2.1, 4.0, 1.25)
],
0xffc857,
15,
0.13,
0.08
);
// ------------------------------------------------------------
// Voxel visiting insect
// ------------------------------------------------------------
const bee = new THREE.Group();
scene.add(bee);
const beeBody = cube(0, 0, 0, 0.34, 0.28, 0.52, 0xe3a928, bee);
beeBody.castShadow = true;
cube(0, 0, -0.11, 0.36, 0.3, 0.1, 0x26352f, bee);
cube(0, 0, 0.12, 0.36, 0.3, 0.09, 0x26352f, bee);
cube(0, 0, 0.34, 0.3, 0.27, 0.25, 0x28352f, bee);
cube(-0.09, 0.12, 0.43, 0.06, 0.06, 0.19, 0x17221f, bee);
cube(0.09, 0.12, 0.43, 0.06, 0.06, 0.19, 0x17221f, bee);
const wingMaterial = new THREE.MeshStandardMaterial({
color: 0xc7efff,
transparent: true,
opacity: 0.62,
roughness: 0.25,
depthWrite: false
});
const leftWing = cube(-0.3, 0.2, -0.02, 0.45, 0.035, 0.25, wingMaterial, bee);
const rightWing = cube(0.3, 0.2, -0.02, 0.45, 0.035, 0.25, wingMaterial, bee);
// Visible pollen loads.
cube(-0.2, -0.2, 0.04, 0.09, 0.1, 0.12, 0xffc857, bee);
cube(0.2, -0.2, 0.04, 0.09, 0.1, 0.12, 0xffc857, bee);
const beeCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(2.92, 3.02, 0.35),
new THREE.Vector3(2.45, 3.36, 0.72),
new THREE.Vector3(3.2, 3.55, 0.4),
broadStigma.clone().add(new THREE.Vector3(0.02, 0.14, 0.02)),
new THREE.Vector3(4.55, 3.42, 0.35),
new THREE.Vector3(5.35, 4.0, 1.15),
new THREE.Vector3(2.3, 4.15, 1.35),
new THREE.Vector3(1.95, 3.6, 0.75)
],
true,
"catmullrom",
0.38
);
// ------------------------------------------------------------
// Direct camera controls
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 1.65, 0);
let yaw = 0.55;
let pitch = 1.08;
let radius = 12.5;
let dragging = false;
let lastX = 0;
let lastY = 0;
function updateCamera() {
camera.position.set(
target.x + radius * Math.sin(pitch) * Math.sin(yaw),
target.y + radius * Math.cos(pitch),
target.z + radius * Math.sin(pitch) * Math.cos(yaw)
);
camera.lookAt(target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, 0.48, 1.42);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", () => {
if (dragging) endDrag();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(radius + event.deltaY * 0.008, 8.2, 18);
updateCamera();
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
let paused = false;
document.querySelectorAll("[data-control]").forEach((button) => {
button.addEventListener("click", () => {
const action = button.dataset.control;
if (action === "left") yaw += 0.18;
if (action === "right") yaw -= 0.18;
if (action === "in") radius = Math.max(8.2, radius - 1);
if (action === "out") radius = Math.min(18, radius + 1);
if (action === "reset") {
yaw = 0.55;
pitch = 1.08;
radius = 12.5;
}
if (action === "pause") {
paused = !paused;
button.textContent = paused ? "Resume" : "Pause";
}
updateCamera();
});
});
// ------------------------------------------------------------
// Projected HTML labels and SVG leader lines
// ------------------------------------------------------------
const labels = [];
function registerLabel(id, anchor, dx, dy, below = false) {
const element = document.getElementById(id);
const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circle.setAttribute("r", "3.5");
leaderLayer.append(line, circle);
labels.push({ element, anchor, dx, dy, below, line, circle });
}
registerLabel(
"label-grass",
new THREE.Vector3(gx - 0.1, 3.85, gz),
-54,
-8
);
registerLabel(
"label-broad",
new THREE.Vector3(bx, 3.72, bz),
55,
-6
);
registerLabel(
"label-grass-anther",
grassAntherPoints[0].clone().add(new THREE.Vector3(0, -0.2, 0)),
90,
24,
true
);
registerLabel(
"label-grass-stigma",
grassStigma,
-90,
-10
);
registerLabel(
"label-broad-anther",
broadAntherPositions[0],
-86,
24,
true
);
registerLabel(
"label-broad-stigma",
broadStigma,
90,
-8
);
const projected = new THREE.Vector3();
function updateLabels() {
const width = container.clientWidth;
const height = container.clientHeight;
labels.forEach((label) => {
projected.copy(label.anchor).project(camera);
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const labelX = anchorX + label.dx;
const labelY = anchorY + label.dy;
label.element.style.left = `${labelX}px`;
label.element.style.top = `${labelY}px`;
label.element.style.visibility =
projected.z > -1 && projected.z < 1 ? "visible" : "hidden";
const attachmentY = label.below
? labelY
: labelY - label.element.offsetHeight;
label.line.setAttribute("x1", anchorX);
label.line.setAttribute("y1", anchorY);
label.line.setAttribute("x2", labelX);
label.line.setAttribute("y2", attachmentY);
label.circle.setAttribute("cx", anchorX);
label.circle.setAttribute("cy", anchorY);
});
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = container.clientWidth;
const height = container.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
leaderLayer.setAttribute("viewBox", `0 0 ${width} ${height}`);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
let simulationTime = 0;
let previousTime = performance.now();
function animate(now) {
const delta = THREE.MathUtils.clamp((now - previousTime) / 1000, 0, 0.05);
previousTime = now;
if (!paused) simulationTime += delta;
pathAnimations.forEach((path, pathIndex) => {
path.particles.forEach((particle, index) => {
const t = (index / path.particles.length + simulationTime * path.speed) % 1;
particle.position.copy(path.curve.getPointAt(t));
const pulse = 0.85 + Math.sin(simulationTime * 7 + index * 0.7) * 0.18;
particle.scale.setScalar(path.particleSize * pulse);
});
});
const beeT = (simulationTime * 0.075) % 1;
const beePosition = beeCurve.getPointAt(beeT);
const beeNext = beeCurve.getPointAt((beeT + 0.012) % 1);
bee.position.copy(beePosition);
bee.lookAt(beeNext);
const flap = Math.sin(simulationTime * 36);
leftWing.rotation.z = 0.18 + flap * 0.55;
rightWing.rotation.z = -0.18 - flap * 0.55;
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```