Prompt specification
Build or customize the Three.js 3D scene "Mixed meadow pollination scene" 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: Mixed meadow pollination scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mixed-meadow-pollination-scene-x0767
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts flower pollination pathways. Compose grasses, flowering herbs, pollinators, and a light breeze; selectable overlays reveal different transfer routes while the meadow remains a readable coherent habitat. Voxel style.
Working Three.js Starter (mixed-meadow-pollination-scene-x0767):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#dfe9dd">
<title>Pollination Pathways — Voxel Meadow</title>
<style>
:root {
--ink: #20352c;
--muted: #66776c;
--paper: rgba(252, 250, 241, 0.91);
--line: rgba(41, 68, 53, 0.14);
--wind: #52ad9f;
--bee: #dda62d;
--butterfly: #d46f9c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe9dd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.masthead {
position: fixed;
top: 30px;
left: 34px;
width: min(370px, calc(100vw - 68px));
z-index: 5;
pointer-events: none;
text-shadow: 0 1px 16px rgba(245, 248, 236, 0.65);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #486356;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 29px;
height: 2px;
content: "";
background: #62846d;
}
h1 {
margin: 0;
color: #20372c;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 4.2vw, 61px);
font-weight: 500;
line-height: 0.94;
letter-spacing: -0.045em;
}
h1 span {
color: #587461;
font-style: italic;
}
.intro {
max-width: 320px;
margin: 16px 0 0;
color: #52685a;
font-size: 13px;
line-height: 1.55;
}
.weather {
position: fixed;
top: 28px;
right: 30px;
z-index: 6;
display: flex;
align-items: center;
gap: 11px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 13px;
background: rgba(250, 250, 240, 0.72);
box-shadow: 0 8px 30px rgba(49, 75, 57, 0.08);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
color: #476052;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.weather-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #65a979;
box-shadow: 0 0 0 4px rgba(101, 169, 121, 0.14);
animation: breathe 2.3s ease-in-out infinite;
}
.weather-divider {
width: 1px;
height: 16px;
background: rgba(49, 78, 60, 0.16);
}
#motion-toggle {
padding: 0;
border: 0;
background: transparent;
color: #476052;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel {
position: fixed;
left: 50%;
bottom: 25px;
z-index: 10;
width: min(780px, calc(100vw - 32px));
padding: 15px;
transform: translateX(-50%);
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 21px;
background: var(--paper);
box-shadow:
0 18px 60px rgba(39, 65, 47, 0.16),
inset 0 0 0 1px rgba(42, 69, 51, 0.04);
backdrop-filter: blur(18px) saturate(1.08);
-webkit-backdrop-filter: blur(18px) saturate(1.08);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
margin: 0 3px 11px;
}
.panel-kicker {
margin: 0;
color: #7a887e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#layer-summary {
margin: 3px 0 0;
color: #52665a;
font-size: 11px;
line-height: 1.35;
}
#clear-routes {
flex: 0 0 auto;
padding: 6px 9px;
border: 0;
border-radius: 8px;
background: transparent;
color: #66776c;
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
transition: background 160ms ease, color 160ms ease;
}
#clear-routes:hover:not(:disabled) {
background: #e8eee3;
color: #294536;
}
#clear-routes:disabled {
cursor: default;
opacity: 0.35;
}
.route-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 9px;
}
.route-button {
--accent: #657d6a;
position: relative;
display: flex;
align-items: center;
min-width: 0;
padding: 12px 13px;
overflow: hidden;
border: 1px solid rgba(50, 76, 58, 0.11);
border-radius: 13px;
background: rgba(255, 255, 255, 0.48);
color: var(--ink);
cursor: pointer;
text-align: left;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.route-button:hover {
transform: translateY(-2px);
border-color: color-mix(in srgb, var(--accent) 50%, white);
background: rgba(255, 255, 255, 0.8);
}
.route-button[aria-pressed="true"] {
border-color: var(--accent);
background: color-mix(in srgb, var(--accent) 10%, #fffdf7);
box-shadow: inset 0 0 0 1px var(--accent);
}
.route-button[data-route="wind"] {
--accent: var(--wind);
}
.route-button[data-route="bee"] {
--accent: var(--bee);
}
.route-button[data-route="butterfly"] {
--accent: var(--butterfly);
}
.route-swatch {
flex: 0 0 auto;
width: 11px;
height: 11px;
margin-right: 10px;
border: 2px solid color-mix(in srgb, var(--accent) 70%, #20352c);
border-radius: 3px;
background: color-mix(in srgb, var(--accent) 48%, transparent);
transform: rotate(45deg);
}
.route-copy {
min-width: 0;
}
.route-copy strong,
.route-copy small {
display: block;
}
.route-copy strong {
overflow: hidden;
font-size: 12px;
font-weight: 800;
letter-spacing: -0.01em;
text-overflow: ellipsis;
white-space: nowrap;
}
.route-copy small {
margin-top: 2px;
overflow: hidden;
color: #728077;
font-size: 9px;
line-height: 1.2;
text-overflow: ellipsis;
white-space: nowrap;
}
.route-check {
position: absolute;
top: 9px;
right: 9px;
width: 8px;
height: 8px;
border-radius: 2px;
background: transparent;
transition: background 160ms ease, transform 160ms ease;
}
.route-button[aria-pressed="true"] .route-check {
background: var(--accent);
transform: rotate(45deg);
}
.camera-hint {
position: fixed;
right: 31px;
bottom: 30px;
z-index: 5;
display: flex;
align-items: center;
gap: 8px;
color: rgba(42, 66, 51, 0.72);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
.camera-hint svg {
width: 18px;
height: 18px;
opacity: 0.7;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
min-width: 145px;
padding: 8px 11px 8px 13px;
transform: translate(-50%, -115%);
border: 1px solid rgba(255, 255, 255, 0.15);
border-left: 3px solid var(--accent);
border-radius: 9px;
background: rgba(28, 48, 37, 0.9);
box-shadow: 0 8px 25px rgba(31, 52, 39, 0.18);
color: #f8f5e9;
opacity: 0;
transition: opacity 180ms ease;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.world-label.visible {
opacity: 1;
}
.world-label strong,
.world-label small {
display: block;
}
.world-label strong {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
}
.world-label small {
margin-top: 2px;
color: rgba(248, 245, 233, 0.65);
font-size: 8px;
letter-spacing: 0.02em;
}
.corner-index {
position: fixed;
bottom: 28px;
left: 32px;
z-index: 4;
color: rgba(40, 64, 49, 0.55);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
pointer-events: none;
}
@keyframes breathe {
0%, 100% { transform: scale(0.85); opacity: 0.72; }
50% { transform: scale(1); opacity: 1; }
}
@media (max-width: 900px) {
.camera-hint,
.corner-index {
display: none;
}
.masthead {
top: 22px;
left: 24px;
}
.weather {
top: 20px;
right: 20px;
}
.weather .weather-detail,
.weather .weather-divider {
display: none;
}
}
@media (max-width: 650px) {
.masthead {
top: 19px;
left: 18px;
width: calc(100vw - 36px);
}
.eyebrow {
margin-bottom: 7px;
font-size: 8px;
}
h1 {
max-width: 245px;
font-size: 38px;
}
.intro {
display: none;
}
.weather {
top: 17px;
right: 15px;
padding: 9px 10px;
}
.panel {
bottom: 12px;
width: calc(100vw - 20px);
padding: 11px;
border-radius: 17px;
}
.panel-heading {
margin-bottom: 9px;
}
#layer-summary {
max-width: 245px;
font-size: 9px;
}
.route-grid {
gap: 6px;
}
.route-button {
padding: 11px 8px;
}
.route-swatch {
width: 8px;
height: 8px;
margin-right: 7px;
}
.route-copy strong {
font-size: 10px;
}
.route-copy small {
display: none;
}
.world-label {
min-width: 120px;
padding: 6px 8px;
}
.world-label small {
display: none;
}
}
@media (max-height: 620px) {
.intro,
.camera-hint,
.corner-index {
display: none;
}
.masthead {
top: 16px;
}
h1 {
font-size: 36px;
}
.panel {
bottom: 10px;
padding: 10px;
}
.panel-heading {
margin-bottom: 7px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel meadow showing pollination pathways"></main>
<header class="masthead">
<div class="eyebrow">Living field study · No. 04</div>
<h1>Pollination<br><span>pathways</span></h1>
<p class="intro">
One meadow, many routes. Reveal how airborne grains, bees, and butterflies
move between plants without losing the habitat beneath them.
</p>
</header>
<aside class="weather" aria-label="Meadow conditions">
<span class="weather-dot" aria-hidden="true"></span>
<span>Meadow live</span>
<span class="weather-divider" aria-hidden="true"></span>
<span class="weather-detail">2.4 km/h breeze</span>
<button id="motion-toggle" type="button" aria-pressed="false">
<span id="motion-label">Pause</span>
</button>
</aside>
<section class="panel" aria-label="Pollination pathway overlays">
<div class="panel-heading">
<div>
<p class="panel-kicker">Pathway overlays</p>
<p id="layer-summary" aria-live="polite">
Habitat view · follow pollen, bees, and butterflies in the breeze.
</p>
</div>
<button id="clear-routes" type="button" disabled>Clear</button>
</div>
<div class="route-grid" role="group" aria-label="Choose pathway layers">
<button class="route-button" data-route="wind" type="button" aria-pressed="false">
<span class="route-swatch" aria-hidden="true"></span>
<span class="route-copy">
<strong>Windborne</strong>
<small>Pollen over grasses</small>
</span>
<span class="route-check" aria-hidden="true"></span>
</button>
<button class="route-button" data-route="bee" type="button" aria-pressed="true">
<span class="route-swatch" aria-hidden="true"></span>
<span class="route-copy">
<strong>Bee relay</strong>
<small>Nearby flower handoffs</small>
</span>
<span class="route-check" aria-hidden="true"></span>
</button>
<button class="route-button" data-route="butterfly" type="button" aria-pressed="false">
<span class="route-swatch" aria-hidden="true"></span>
<span class="route-copy">
<strong>Butterfly bridge</strong>
<small>Long-range herb visits</small>
</span>
<span class="route-check" aria-hidden="true"></span>
</button>
</div>
</section>
<div id="labels" aria-hidden="true"></div>
<div class="camera-hint">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<rect x="7" y="2" width="10" height="18" rx="5"></rect>
<path d="M12 6v4"></path>
<path d="M5 9H2M22 9h-3M5 15H2M22 15h-3"></path>
</svg>
<span>Drag to orbit · Scroll to zoom</span>
</div>
<div class="corner-index">Field model / 31 × 22 tiles</div>
<noscript>This scene requires JavaScript and access to the Three.js CDN.</noscript>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const mount = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe9dd);
scene.fog = new THREE.Fog(0xdfe9dd, 38, 78);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
mount.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 140);
const cameraTarget = new THREE.Vector3(0, 0.4, 0);
const cameraState = {
yaw: 0.62,
pitch: 0.66,
zoom: 1,
targetZoom: 1
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const zAxis = new THREE.Vector3(0, 0, 1);
const mat = {
soil: new THREE.MeshStandardMaterial({ color: 0x715b47, roughness: 1 }),
soilDark: new THREE.MeshStandardMaterial({ color: 0x574638, roughness: 1 }),
stem: new THREE.MeshStandardMaterial({ color: 0x527347, roughness: 0.92 }),
stemDark: new THREE.MeshStandardMaterial({ color: 0x3f6541, roughness: 0.95 }),
leaf: new THREE.MeshStandardMaterial({ color: 0x5d874d, roughness: 0.9 }),
leafLight: new THREE.MeshStandardMaterial({ color: 0x78a158, roughness: 0.9 }),
rock: new THREE.MeshStandardMaterial({ color: 0x9b9c86, roughness: 1 }),
rockLight: new THREE.MeshStandardMaterial({ color: 0xb6b19a, roughness: 1 }),
mushroom: new THREE.MeshStandardMaterial({ color: 0xf2e8c9, roughness: 0.9 }),
cap: new THREE.MeshStandardMaterial({ color: 0xc96451, roughness: 0.9 }),
wood: new THREE.MeshStandardMaterial({ color: 0x8a6849, roughness: 1 }),
cloud: new THREE.MeshLambertMaterial({
color: 0xf6f4e7,
transparent: true,
opacity: 0.68,
depthWrite: false
}),
bee: new THREE.MeshStandardMaterial({ color: 0xe5ad2e, roughness: 0.72 }),
beeDark: new THREE.MeshStandardMaterial({ color: 0x37382f, roughness: 0.72 }),
wing: new THREE.MeshStandardMaterial({
color: 0xf7fbef,
transparent: true,
opacity: 0.72,
roughness: 0.45,
depthWrite: false
}),
butterflyA: new THREE.MeshStandardMaterial({
color: 0xd86f9a,
roughness: 0.7,
side: THREE.DoubleSide
}),
butterflyB: new THREE.MeshStandardMaterial({
color: 0x8f75bf,
roughness: 0.7,
side: THREE.DoubleSide
})
};
function box(width, height, depth, material, parent, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf7fbff, 0x667447, 2.15);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffe4b8, 3.2);
sunlight.position.set(-12, 23, 15);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(1024, 1024);
sunlight.shadow.camera.left = -23;
sunlight.shadow.camera.right = 23;
sunlight.shadow.camera.top = 20;
sunlight.shadow.camera.bottom = -20;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 60;
sunlight.shadow.bias = -0.0004;
scene.add(sunlight);
const coolFill = new THREE.DirectionalLight(0xb9d6ed, 0.9);
coolFill.position.set(15, 9, -12);
scene.add(coolFill);
// -------------------------------------------------------------------------
// Deterministic random values and helpers
// -------------------------------------------------------------------------
let seed = 1947;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function range(min, max) {
return min + (max - min) * random();
}
function distance2D(ax, az, bx, bz) {
return Math.hypot(ax - bx, az - bz);
}
// -------------------------------------------------------------------------
// Voxel meadow island
// -------------------------------------------------------------------------
box(31.1, 1.22, 23.1, mat.soil, scene, 0, -0.82, 0);
box(31.7, 0.34, 23.7, mat.soilDark, scene, 0, -1.52, 0);
const columns = 30;
const rows = 22;
const tileCount = columns * rows;
const tileGeometry = new THREE.BoxGeometry(0.96, 1, 0.96);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
tiles.receiveShadow = true;
tiles.castShadow = false;
const greenPalette = [0x78985a, 0x86a561, 0x6f9155, 0x91ad69, 0x789e5a];
const pathPalette = [0xc6bd82, 0xcfc18b, 0xbeb37b];
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const index = row * columns + col;
const x = -14.5 + col;
const z = -10.5 + row;
const pathCenter = Math.sin(x * 0.28) * 1.1 - 0.2;
const onPath = Math.abs(z - pathCenter) < 0.82;
const height = onPath ? range(0.15, 0.19) : range(0.17, 0.24);
dummy.position.set(x, -height / 2, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.96, height, 0.96);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
const palette = onPath ? pathPalette : greenPalette;
tiles.setColorAt(index, new THREE.Color(palette[Math.floor(random() * palette.length)]));
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
new THREE.ShadowMaterial({ opacity: 0.13 })
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -1.72;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
// -------------------------------------------------------------------------
// Route anchors: these are also the locations of important flowers
// -------------------------------------------------------------------------
const routeAnchors = {
wind: [
[-12.2, -3.1],
[-8.6, -2.2],
[-5.0, -1.0],
[-1.0, 0.2],
[3.0, -0.6]
],
bee: [
[-5.7, -6.3],
[-2.8, -5.4],
[0.5, -4.8],
[3.5, -5.4],
[6.0, -3.8]
],
butterfly: [
[9.0, -1.0],
[6.2, 1.8],
[2.3, 4.1],
[-2.6, 5.2],
[-7.0, 4.1]
]
};
const allAnchors = Object.values(routeAnchors).flat();
function isPath(x, z) {
const pathCenter = Math.sin(x * 0.28) * 1.1 - 0.2;
return Math.abs(z - pathCenter) < 1.05;
}
function nearAnchor(x, z, radius = 1.35) {
return allAnchors.some(([ax, az]) => distance2D(x, z, ax, az) < radius);
}
// -------------------------------------------------------------------------
// Grass blades
// -------------------------------------------------------------------------
const grassCount = 430;
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const grass = new THREE.InstancedMesh(unitBox, grassMaterial, grassCount);
grass.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
grass.frustumCulled = false;
grass.castShadow = true;
grass.receiveShadow = true;
const grassData = [];
const grassPalette = [0x4f7943, 0x5f874a, 0x6d9150, 0x769953, 0x446f43];
for (let i = 0; i < grassCount; i++) {
let x;
let z;
do {
x = range(-14.5, 14.5);
z = range(-10.5, 10.5);
} while (isPath(x, z) || nearAnchor(x, z, 1.35));
grassData.push({
x,
z,
height: range(0.28, 0.78),
width: range(0.045, 0.085),
rotationY: range(0, Math.PI * 2),
phase: range(0, Math.PI * 2),
strength: range(0.025, 0.07)
});
grass.setColorAt(i, new THREE.Color(grassPalette[Math.floor(random() * grassPalette.length)]));
}
grass.instanceColor.needsUpdate = true;
scene.add(grass);
// -------------------------------------------------------------------------
// Voxel flowers
// -------------------------------------------------------------------------
const flowerMaterials = {
coral: {
petal: new THREE.MeshStandardMaterial({ color: 0xef7f67, roughness: 0.83 }),
center: new THREE.MeshStandardMaterial({ color: 0xf4c654, roughness: 0.85 })
},
violet: {
petal: new THREE.MeshStandardMaterial({ color: 0x9b78c3, roughness: 0.83 }),
center: new THREE.MeshStandardMaterial({ color: 0xf4d16d, roughness: 0.85 })
},
gold: {
petal: new THREE.MeshStandardMaterial({ color: 0xe8b84e, roughness: 0.83 }),
center: new THREE.MeshStandardMaterial({ color: 0x8b5b32, roughness: 0.9 })
},
blue: {
petal: new THREE.MeshStandardMaterial({ color: 0x70a9c6, roughness: 0.83 }),
center: new THREE.MeshStandardMaterial({ color: 0xf0ce5f, roughness: 0.85 })
},
pink: {
petal: new THREE.MeshStandardMaterial({ color: 0xdf829f, roughness: 0.83 }),
center: new THREE.MeshStandardMaterial({ color: 0xf2d38a, roughness: 0.85 })
}
};
const flowers = [];
function createFlower(x, z, type, scale = 1, height = null) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
const h = height ?? range(0.82, 1.42);
const material = flowerMaterials[type];
box(0.075, h, 0.075, mat.stemDark, group, 0, h / 2, 0);
const leafA = box(0.34, 0.085, 0.14, mat.leaf, group, -0.12, h * 0.38, 0);
leafA.rotation.z = -0.28;
leafA.rotation.y = 0.3;
const leafB = box(0.29, 0.075, 0.13, mat.leafLight, group, 0.12, h * 0.58, 0);
leafB.rotation.z = 0.32;
leafB.rotation.y = -0.45;
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const petal = box(
0.27,
0.115,
0.15,
material.petal,
group,
Math.cos(angle) * 0.19,
h,
Math.sin(angle) * 0.19
);
petal.rotation.y = -angle;
}
box(0.19, 0.16, 0.19, material.center, group, 0, h + 0.03, 0);
flowers.push({
group,
phase: range(0, Math.PI * 2),
strength: range(0.018, 0.042),
speed: range(0.8, 1.25),
baseHeight: h
});
return group;
}
const windTypes = ["gold", "gold", "violet"];
const beeTypes = ["coral", "violet", "coral", "gold", "coral"];
const butterflyTypes = ["blue", "pink", "blue", "violet", "pink"];
function createPatch(anchors, types, fillerCount) {
anchors.forEach(([x, z], i) => {
createFlower(x, z, types[i % types.length], range(0.9, 1.12), range(1.0, 1.34));
});
for (let i = 0; i < fillerCount; i++) {
const anchor = anchors[Math.floor(random() * anchors.length)];
const angle = range(0, Math.PI * 2);
const radius = range(0.75, 1.55);
const x = THREE.MathUtils.clamp(anchor[0] + Math.cos(angle) * radius, -14, 14);
const z = THREE.MathUtils.clamp(anchor[1] + Math.sin(angle) * radius, -10, 10);
if (!isPath(x, z) && !nearAnchor(x, z, 0.45)) {
createFlower(x, z, types[Math.floor(random() * types.length)], range(0.62, 0.93));
}
}
}
createPatch(routeAnchors.wind, windTypes, 13);
createPatch(routeAnchors.bee, beeTypes, 15);
createPatch(routeAnchors.butterfly, butterflyTypes, 15);
// -------------------------------------------------------------------------
// Reeds, stones, mushrooms, shrubs, and a small field sign
// -------------------------------------------------------------------------
const reeds = [];
for (let i = 0; i < 14; i++) {
const x = range(-13.8, -10.6);
const z = range(-5.2, -0.5);
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const height = range(1.25, 2.05);
box(0.07, height, 0.07, mat.stem, group, 0, height / 2, 0);
box(0.18, 0.34, 0.16, flowerMaterials.gold.petal, group, 0, height + 0.12, 0);
box(0.14, 0.18, 0.13, flowerMaterials.gold.petal, group, 0.03, height + 0.36, 0);
group.rotation.y = range(0, Math.PI * 2);
reeds.push({ group, phase: range(0, Math.PI * 2) });
}
const rockCount = 30;
const rocks = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 1 }),
rockCount
);
rocks.castShadow = true;
rocks.receiveShadow = true;
for (let i = 0; i < rockCount; i++) {
const edge = Math.floor(random() * 4);
let x;
let z;
if (edge === 0) {
x = range(-14, 14);
z = range(-10.5, -9.4);
} else if (edge === 1) {
x = range(-14, 14);
z = range(9.4, 10.5);
} else if (edge === 2) {
x = range(-14.5, -13.4);
z = range(-10, 10);
} else {
x = range(13.4, 14.5);
z = range(-10, 10);
}
dummy.position.set(x, 0.12, z);
dummy.rotation.set(range(-0.12, 0.12), range(0, Math.PI), range(-0.12, 0.12));
dummy.scale.set(range(0.25, 0.65), range(0.2, 0.45), range(0.25, 0.65));
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
rocks.setColorAt(i, new THREE.Color(random() > 0.5 ? 0x999b87 : 0xb2ae96));
}
rocks.instanceMatrix.needsUpdate = true;
rocks.instanceColor.needsUpdate = true;
scene.add(rocks);
for (let i = 0; i < 10; i++) {
const x = range(-13, 13);
const z = range(-9.4, 9.4);
if (isPath(x, z)) continue;
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(0.09, 0.42, 0.09, mat.mushroom, group, 0, 0.21, 0);
box(0.38, 0.17, 0.35, mat.cap, group, 0, 0.43, 0);
box(0.16, 0.06, 0.13, mat.mushroom, group, 0, 0.53, 0);
}
const shrubMaterial = new THREE.MeshStandardMaterial({ color: 0x5f824b, roughness: 1 });
const shrubLight = new THREE.MeshStandardMaterial({ color: 0x78995a, roughness: 1 });
for (let i = 0; i < 8; i++) {
const group = new THREE.Group();
const side = i % 2 === 0 ? -1 : 1;
group.position.set(side * range(13.2, 14.3), 0, range(-8.5, 8.5));
scene.add(group);
box(0.75, 0.65, 0.75, shrubMaterial, group, 0, 0.35, 0);
box(0.55, 0.65, 0.55, shrubLight, group, 0.45, 0.38, 0.18);
box(0.48, 0.52, 0.48, shrubMaterial, group, -0.38, 0.3, -0.25);
box(0.5, 0.55, 0.5, shrubLight, group, 0.05, 0.72, 0);
}
const sign = new THREE.Group();
sign.position.set(-10.7, 0, 8.3);
sign.rotation.y = -0.25;
scene.add(sign);
box(0.12, 1.1, 0.12, mat.wood, sign, 0, 0.55, 0);
box(1.1, 0.48, 0.12, mat.wood, sign, 0, 1.02, 0);
box(0.55, 0.055, 0.145, flowerMaterials.gold.petal, sign, 0, 1.03, 0.01);
// -------------------------------------------------------------------------
// Voxel clouds
// -------------------------------------------------------------------------
const clouds = [];
for (let i = 0; i < 5; i++) {
const group = new THREE.Group();
group.position.set(-18 + i * 9, range(7.6, 10.8), range(-19, -15));
scene.add(group);
box(1.7, 0.65, 0.8, mat.cloud, group, 0, 0, 0);
box(1.1, 0.9, 0.85, mat.cloud, group, -0.75, 0.08, 0);
box(1.2, 1.05, 0.8, mat.cloud, group, 0.55, 0.18, 0.08);
box(1.1, 0.55, 0.75, mat.cloud, group, 1.25, -0.05, 0);
clouds.push({
group,
baseX: group.position.x,
phase: range(0, Math.PI * 2),
speed: range(0.07, 0.13)
});
}
// -------------------------------------------------------------------------
// Polluters: bees and butterflies
// -------------------------------------------------------------------------
function createBee() {
const group = new THREE.Group();
scene.add(group);
box(0.23, 0.19, 0.38, mat.bee, group, 0, 0, 0);
box(0.24, 0.2, 0.065, mat.beeDark, group, 0, 0, -0.09);
box(0.24, 0.2, 0.065, mat.beeDark, group, 0, 0, 0.08);
box(0.19, 0.18, 0.18, mat.beeDark, group, 0, 0.015, 0.25);
const leftWing = new THREE.Group();
const rightWing = new THREE.Group();
leftWing.position.x = -0.055;
rightWing.position.x = 0.055;
group.add(leftWing, rightWing);
box(0.27, 0.025, 0.19, mat.wing, leftWing, -0.14, 0.1, -0.015);
box(0.27, 0.025, 0.19, mat.wing, rightWing, 0.14, 0.1, -0.015);
return { group, leftWing, rightWing };
}
function createButterfly() {
const group = new THREE.Group();
scene.add(group);
box(0.1, 0.35, 0.13, mat.beeDark, group, 0, 0, 0);
box(0.11, 0.11, 0.12, mat.beeDark, group, 0, 0.2, 0.03);
const leftWing = new THREE.Group();
const rightWing = new THREE.Group();
leftWing.position.set(-0.045, 0.06, 0);
rightWing.position.set(0.045, 0.06, 0);
group.add(leftWing, rightWing);
box(0.42, 0.045, 0.29, mat.butterflyA, leftWing, -0.22, 0, 0.05);
box(0.3, 0.04, 0.23, mat.butterflyB, leftWing, -0.16, -0.015, -0.15);
box(0.42, 0.045, 0.29, mat.butterflyB, rightWing, 0.22, 0, 0.05);
box(0.3, 0.04, 0.23, mat.butterflyA, rightWing, 0.16, -0.015, -0.15);
return { group, leftWing, rightWing };
}
const beePaths = [
[
[-5.7, -6.3], [-3.2, -6.4], [0.4, -4.8],
[3.6, -5.5], [5.9, -3.8], [-2.8, -5.4]
],
[
[-4.8, -7.0], [-1.8, -6.6], [1.4, -4.5],
[4.8, -4.8], [5.8, -3.1], [-2.4, -5.2]
],
[
[-6.3, -5.4], [-3.3, -5.0], [0.8, -4.3],
[4.1, -5.0], [6.4, -4.3], [-1.5, -5.8]
]
];
const bees = [];
for (let i = 0; i < 6; i++) {
const bee = createBee();
const path = beePaths[i % beePaths.length].map(([x, z], index) =>
new THREE.Vector3(x, 1.35 + (index % 2) * 0.16, z)
);
const curve = new THREE.CatmullRomCurve3(path, true, "catmullrom", 0.45);
bees.push({
...bee,
curve,
offset: i / 6,
speed: 0.035 + i * 0.0022,
phase: i * 1.3
});
}
const butterflyPaths = [
[
[9.0, -1.0], [6.2, 1.8], [2.3, 4.1],
[-2.6, 5.2], [-7.0, 4.1]
],
[
[8.3, -1.8], [5.4, 1.0], [1.2, 3.5],
[-3.5, 4.6], [-6.4, 3.7]
],
[
[9.6, 0.1], [6.8, 2.5], [3.3, 4.8],
[-1.4, 5.8], [-6.2, 4.8]
]
];
const butterflies = [];
for (let i = 0; i < 4; i++) {
const butterfly = createButterfly();
const path = butterflyPaths[i % butterflyPaths.length].map(([x, z], index) =>
new THREE.Vector3(x, 1.45 + (index % 2) * 0.35, z)
);
const curve = new THREE.CatmullRomCurve3(path, false, "catmullrom", 0.38);
butterflies.push({
...butterfly,
curve,
offset: i / 4,
speed: 0.026 + i * 0.002,
phase: i * 0.9
});
}
// -------------------------------------------------------------------------
// Airborne pollen and visible breeze streaks
// -------------------------------------------------------------------------
const pollenCount = 48;
const pollen = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.72,
depthWrite: false
}),
pollenCount
);
pollen.frustumCulled = false;
const pollenData = [];
for (let i = 0; i < pollenCount; i++) {
pollenData.push({
x: range(-15, 15),
y: range(0.45, 3.8),
z: range(-10, 10),
speed: range(0.32, 0.72),
size: range(0.035, 0.085),
phase: range(0, Math.PI * 2)
});
pollen.setColorAt(i, new THREE.Color(i % 3 === 0 ? 0xfff0a0 : 0xf5e8b1));
}
pollen.instanceColor.needsUpdate = true;
scene.add(pollen);
const streakCount = 13;
const streaks = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({
color: 0xf4f7e9,
transparent: true,
opacity: 0.32,
depthWrite: false
}),
streakCount
);
streaks.frustumCulled = false;
const streakData = [];
for (let i = 0; i < streakCount; i++) {
streakData.push({
x: range(-15, 15),
y: range(0.5, 2.8),
z: range(-9, 9),
speed: range(0.8, 1.4),
length: range(0.5, 1.25),
phase: range(0, Math.PI * 2)
});
}
scene.add(streaks);
// -------------------------------------------------------------------------
// Pathway overlays
// -------------------------------------------------------------------------
const routeConfigs = {
wind: {
color: 0x52ad9f,
label: "Wind-borne pollen",
detail: "grasses → open blooms",
summary: "Windborne pollen drifts from tall grasses into the first open flowers.",
speed: 0.035,
dashCount: 34,
dashLength: 0.28,
y: [1.4, 1.75, 1.48, 1.7, 1.42]
},
bee: {
color: 0xdda62d,
label: "Bee relay",
detail: "bloom → bloom → bloom",
summary: "Bees make short, frequent handoffs between neighboring flowers.",
speed: 0.052,
dashCount: 38,
dashLength: 0.24,
y: [1.36, 1.58, 1.38, 1.55, 1.35]
},
butterfly: {
color: 0xd46f9c,
label: "Butterfly bridge",
detail: "patch → distant patch",
summary: "Butterflies link isolated herb patches across the wider meadow.",
speed: 0.028,
dashCount: 44,
dashLength: 0.3,
y: [1.45, 1.95, 2.15, 1.9, 1.6]
}
};
const activeRoutes = new Set(["bee"]);
const routeObjects = {};
const labelContainer = document.querySelector("#labels");
for (const [id, config] of Object.entries(routeConfigs)) {
const points = routeAnchors[id].map(([x, z], index) =>
new THREE.Vector3(x, config.y[index % config.y.length], z)
);
const curve = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.42);
const dashMaterial = new THREE.MeshBasicMaterial({
color: config.color,
transparent: true,
opacity: 0.82,
depthTest: false,
depthWrite: false
});
const dashes = new THREE.InstancedMesh(unitBox, dashMaterial, config.dashCount);
dashes.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
dashes.frustumCulled = false;
dashes.renderOrder = 20;
dashes.visible = activeRoutes.has(id);
scene.add(dashes);
const packet = new THREE.Mesh(
unitBox,
new THREE.MeshBasicMaterial({
color: config.color,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
packet.scale.set(0.27, 0.27, 0.27);
packet.renderOrder = 21;
packet.visible = activeRoutes.has(id);
scene.add(packet);
const endpointMaterial = new THREE.MeshBasicMaterial({
color: config.color,
transparent: true,
opacity: 0.8,
depthTest: false,
depthWrite: false
});
const startMarker = new THREE.Mesh(unitBox, endpointMaterial);
const endMarker = new THREE.Mesh(unitBox, endpointMaterial);
startMarker.scale.setScalar(0.22);
endMarker.scale.setScalar(0.22);
startMarker.position.copy(curve.getPointAt(0));
endMarker.position.copy(curve.getPointAt(1));
startMarker.renderOrder = 22;
endMarker.renderOrder = 22;
startMarker.visible = activeRoutes.has(id);
endMarker.visible = activeRoutes.has(id);
scene.add(startMarker, endMarker);
const label = document.createElement("div");
label.className = "world-label";
label.style.setProperty("--accent", `#${new THREE.Color(config.color).getHexString()}`);
label.innerHTML = `
<strong>${config.label}</strong>
<small>${config.detail}</small>
`;
labelContainer.appendChild(label);
routeObjects[id] = {
curve,
dashes,
packet,
startMarker,
endMarker,
label,
labelPosition: curve.getPointAt(0.58).add(new THREE.Vector3(0, 0.65, 0)),
config
};
}
// -------------------------------------------------------------------------
// Route controls
// -------------------------------------------------------------------------
const routeButtons = [...document.querySelectorAll(".route-button")];
const clearButton = document.querySelector("#clear-routes");
const layerSummary = document.querySelector("#layer-summary");
function updateRouteUI() {
for (const button of routeButtons) {
button.setAttribute("aria-pressed", String(activeRoutes.has(button.dataset.route)));
}
clearButton.disabled = activeRoutes.size === 0;
if (activeRoutes.size === 0) {
layerSummary.textContent = "Habitat view · follow pollen, bees, and butterflies in the breeze.";
} else if (activeRoutes.size === 1) {
const id = [...activeRoutes][0];
layerSummary.textContent = routeConfigs[id].summary;
} else {
layerSummary.textContent = `${activeRoutes.size} pathways layered · compare short handoffs with wider travel.`;
}
}
function toggleRoute(id) {
if (activeRoutes.has(id)) {
activeRoutes.delete(id);
} else {
activeRoutes.add(id);
}
updateRouteUI();
}
routeButtons.forEach((button) => {
button.addEventListener("click", () => toggleRoute(button.dataset.route));
});
clearButton.addEventListener("click", () => {
activeRoutes.clear();
updateRouteUI();
});
window.addEventListener("keydown", (event) => {
const keyMap = { "1": "wind", "2": "bee", "3": "butterfly" };
if (keyMap[event.key]) {
toggleRoute(keyMap[event.key]);
}
});
updateRouteUI();
// -------------------------------------------------------------------------
// Camera controls implemented without addons
// -------------------------------------------------------------------------
const pointers = new Map();
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.32,
1.22
);
} else if (pointers.size === 2) {
const entries = [...pointers.values()];
const oldDistance = Math.hypot(
entries[0].x - entries[1].x,
entries[0].y - entries[1].y
);
previous.x = event.clientX;
previous.y = event.clientY;
const updated = [...pointers.values()];
const newDistance = Math.hypot(
updated[0].x - updated[1].x,
updated[0].y - updated[1].y
);
if (oldDistance > 0 && newDistance > 0) {
cameraState.targetZoom = THREE.MathUtils.clamp(
cameraState.targetZoom * (oldDistance / newDistance),
0.65,
1.75
);
}
return;
}
previous.x = event.clientX;
previous.y = event.clientY;
});
function releasePointer(event) {
pointers.delete(event.pointerId);
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.targetZoom = THREE.MathUtils.clamp(
cameraState.targetZoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.75
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.62;
cameraState.pitch = 0.66;
cameraState.targetZoom = 1;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(29, 34 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let simulationTime = 0;
let paused = false;
const motionToggle = document.querySelector("#motion-toggle");
const motionLabel = document.querySelector("#motion-label");
motionToggle.addEventListener("click", () => {
paused = !paused;
motionToggle.setAttribute("aria-pressed", String(paused));
motionLabel.textContent = paused ? "Resume" : "Pause";
});
function updateGrass(time) {
for (let i = 0; i < grassData.length; i++) {
const blade = grassData[i];
const sway = Math.sin(time * 1.55 + blade.phase) * blade.strength;
dummy.position.set(blade.x, blade.height / 2, blade.z);
dummy.rotation.set(
Math.sin(time * 0.75 + blade.phase) * blade.strength * 0.4,
blade.rotationY,
sway
);
dummy.scale.set(blade.width, blade.height, blade.width * 0.8);
dummy.updateMatrix();
grass.setMatrixAt(i, dummy.matrix);
}
grass.instanceMatrix.needsUpdate = true;
}
function updateFlowers(time) {
for (const flower of flowers) {
flower.group.rotation.z =
Math.sin(time * flower.speed + flower.phase) * flower.strength;
flower.group.rotation.x =
Math.cos(time * flower.speed * 0.73 + flower.phase) * flower.strength * 0.45;
}
for (const reed of reeds) {
reed.group.rotation.z =
Math.sin(time * 1.1 + reed.phase) * 0.045;
reed.group.rotation.x =
Math.cos(time * 0.78 + reed.phase) * 0.018;
}
}
function updateBees(time) {
for (const bee of bees) {
const t = (bee.offset + time * bee.speed) % 1;
const position = bee.curve.getPointAt(t);
const tangent = bee.curve.getTangentAt(t);
bee.group.position.copy(position);
bee.group.position.y += Math.sin(time * 6 + bee.phase) * 0.08;
bee.group.rotation.y = Math.atan2(tangent.x, tangent.z);
const flap = Math.sin(time * 27 + bee.phase) * 0.62;
bee.leftWing.rotation.z = flap;
bee.rightWing.rotation.z = -flap;
}
}
function updateButterflies(time) {
for (const butterfly of butterflies) {
let t = (butterfly.offset + time * butterfly.speed) % 1;
if (t > 0.5) t = 1 - t;
const position = butterfly.curve.getPointAt(t);
const tangent = butterfly.curve.getTangentAt(t);
butterfly.group.position.copy(position);
butterfly.group.position.y += Math.sin(time * 4.2 + butterfly.phase) * 0.15;
butterfly.group.rotation.y = Math.atan2(tangent.x, tangent.z);
butterfly.group.rotation.z = Math.sin(time * 2.3 + butterfly.phase) * 0.09;
const flap = Math.sin(time * 13 + butterfly.phase) * 0.72;
butterfly.leftWing.rotation.y = flap;
butterfly.rightWing.rotation.y = -flap;
}
}
function updateAir(time, delta) {
for (let i = 0; i < pollenData.length; i++) {
const particle = pollenData[i];
particle.x += delta * particle.speed;
particle.z += Math.sin(time * 0.7 + particle.phase) * delta * 0.08;
if (particle.x > 15.5) {
particle.x = -15.5;
particle.z = range(-10, 10);
}
dummy.position.set(
particle.x,
particle.y + Math.sin(time * 1.2 + particle.phase) * 0.12,
particle.z
);
dummy.rotation.set(time * 0.4 + particle.phase, time * 0.25, 0);
dummy.scale.setScalar(particle.size);
dummy.updateMatrix();
pollen.setMatrixAt(i, dummy.matrix);
}
pollen.instanceMatrix.needsUpdate = true;
for (let i = 0; i < streakData.length; i++) {
const streak = streakData[i];
streak.x += delta * streak.speed;
if (streak.x > 16) {
streak.x = -16;
streak.y = range(0.4, 2.8);
streak.z = range(-9, 9);
}
dummy.position.set(
streak.x,
streak.y + Math.sin(time + streak.phase) * 0.06,
streak.z
);
dummy.rotation.set(0, 0.1, 0);
dummy.scale.set(streak.length, 0.014, 0.014);
dummy.updateMatrix();
streaks.setMatrixAt(i, dummy.matrix);
}
streaks.instanceMatrix.needsUpdate = true;
}
function updateRoutes(time) {
for (const [id, object] of Object.entries(routeObjects)) {
const visible = activeRoutes.has(id);
object.dashes.visible = visible;
object.packet.visible = visible;
object.startMarker.visible = visible;
object.endMarker.visible = visible;
object.label.classList.toggle("visible", visible);
if (!visible) continue;
const { curve, dashes, packet, config } = object;
for (let i = 0; i < config.dashCount; i++) {
const t = (i / config.dashCount + time * config.speed) % 1;
const position = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
dummy.position.copy(position);
dummy.quaternion.setFromUnitVectors(zAxis, tangent);
dummy.scale.set(0.095, 0.075, config.dashLength);
dummy.updateMatrix();
dashes.setMatrixAt(i, dummy.matrix);
}
dashes.instanceMatrix.needsUpdate = true;
const packetT = (time * config.speed * 1.35) % 1;
packet.position.copy(curve.getPointAt(packetT));
packet.rotation.set(time * 0.7, time * 1.1, 0.35);
packet.scale.setScalar(0.24 + Math.sin(time * 5) * 0.035);
const pulse = 1 + Math.sin(time * 3.2) * 0.18;
object.startMarker.scale.setScalar(0.22 * pulse);
object.endMarker.scale.setScalar(0.22 * pulse);
object.startMarker.rotation.y = time * 0.4;
object.endMarker.rotation.y = -time * 0.4;
}
}
function updateClouds(time) {
for (const cloud of clouds) {
cloud.group.position.x =
cloud.baseX + Math.sin(time * cloud.speed + cloud.phase) * 1.4;
}
}
const projected = new THREE.Vector3();
function updateLabels() {
for (const object of Object.values(routeObjects)) {
if (!activeRoutes.has(object.dashes.userData.routeId) &&
!object.dashes.visible) {
object.label.classList.remove("visible");
continue;
}
projected.copy(object.labelPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
object.label.classList.toggle("visible", visible);
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
object.label.style.left = `${x}px`;
object.label.style.top = `${y}px`;
}
}
}
function updateCamera() {
cameraState.zoom +=
(cameraState.targetZoom - cameraState.zoom) * 0.11;
camera.zoom = cameraState.zoom;
const radius = 46;
const cosPitch = Math.cos(cameraState.pitch);
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraState.yaw) * cosPitch,
cameraTarget.y + radius * Math.sin(cameraState.pitch),
cameraTarget.z + radius * Math.cos(cameraState.yaw) * cosPitch
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) simulationTime += delta;
updateCamera();
updateGrass(simulationTime);
updateFlowers(simulationTime);
updateBees(simulationTime);
updateButterflies(simulationTime);
updateAir(simulationTime, paused ? 0 : delta);
updateRoutes(simulationTime);
updateClouds(simulationTime);
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```