Prompt specification
Build or customize the Three.js 3D scene "Flower depth and pollinator reach models" 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: Flower depth and pollinator reach models
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/flower-depth-and-pollinator-reach-models-x0889
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts geometric fit between flowers and pollinator mouthparts. Build several schematic flowers and pollinator mouthpart lengths on matching stands; show geometric fit while labeling the pairing hypothetical rather than a real species claim. Low-poly.
Working Three.js Starter (flower-depth-and-pollinator-reach-models-x0889):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hypothetical Floral Geometry Study</title>
<style>
:root {
--ink: #24363a;
--muted: #607276;
--paper: #f4f1e8;
--glass: rgba(249, 248, 242, 0.9);
--line: rgba(44, 70, 74, 0.18);
--green: #188f78;
--cyan: #2caeaa;
--coral: #ee7470;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7ece8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#app canvas {
touch-action: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 44%, transparent 48%, rgba(34, 55, 58, 0.07) 100%),
linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 26%);
z-index: 2;
}
.topbar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 24px;
padding: 24px 28px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
font-size: 11px;
line-height: 1;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
color: var(--green);
}
h1 {
margin: 0;
max-width: 560px;
font-size: clamp(23px, 3vw, 42px);
line-height: 1.03;
letter-spacing: -0.045em;
font-weight: 750;
}
.subtitle {
margin: 9px 0 0;
max-width: 560px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.disclaimer {
max-width: 310px;
padding: 12px 14px;
border: 1px solid rgba(30, 76, 71, 0.2);
border-radius: 10px;
background: rgba(246, 247, 240, 0.78);
box-shadow: 0 8px 25px rgba(34, 59, 60, 0.07);
backdrop-filter: blur(9px);
font-size: 11px;
line-height: 1.45;
}
.disclaimer strong {
display: block;
margin-bottom: 3px;
color: var(--green);
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.station-card {
position: absolute;
width: 252px;
padding: 13px 14px 12px;
transform: translate(-50%, -100%);
border: 1px solid var(--line);
border-radius: 12px;
background: var(--glass);
box-shadow: 0 12px 30px rgba(35, 57, 60, 0.1);
backdrop-filter: blur(10px);
transition:
border-color 180ms ease,
box-shadow 180ms ease;
}
.station-card::after {
content: "";
position: absolute;
left: 50%;
bottom: -11px;
width: 1px;
height: 11px;
background: rgba(44, 70, 74, 0.28);
}
.station-card.is-aligned {
border-color: rgba(24, 143, 120, 0.42);
box-shadow:
0 12px 30px rgba(35, 57, 60, 0.1),
0 0 0 2px rgba(24, 143, 120, 0.05);
}
.card-kicker {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--pair-color, var(--coral));
}
.station-card h2 {
margin: 0 0 10px;
font-size: 16px;
line-height: 1.15;
letter-spacing: -0.02em;
}
.pair-meta {
display: grid;
gap: 5px;
padding-top: 8px;
border-top: 1px solid var(--line);
}
.pair-meta div {
display: flex;
justify-content: space-between;
gap: 12px;
font-size: 10px;
}
.pair-meta span {
color: var(--muted);
}
.pair-meta b {
font-variant-numeric: tabular-nums;
font-weight: 750;
}
.result {
margin-top: 9px;
padding: 7px 8px;
border-radius: 7px;
background: rgba(24, 143, 120, 0.09);
color: #176f60;
font-size: 10px;
font-weight: 700;
line-height: 1.3;
}
.result .check {
margin-right: 4px;
}
.card-note {
margin-top: 6px;
color: #7b898b;
font-size: 9px;
}
.measure-label {
position: absolute;
transform: translate(-50%, -50%);
padding: 4px 7px;
border: 1px solid rgba(24, 143, 120, 0.22);
border-radius: 999px;
background: rgba(247, 248, 241, 0.9);
color: #167461;
white-space: nowrap;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
box-shadow: 0 5px 15px rgba(35, 57, 60, 0.07);
}
#controls {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 12;
display: flex;
align-items: center;
gap: 9px;
transform: translateX(-50%);
padding: 7px;
border: 1px solid rgba(39, 68, 71, 0.18);
border-radius: 13px;
background: rgba(248, 248, 242, 0.86);
box-shadow: 0 12px 35px rgba(31, 52, 55, 0.13);
backdrop-filter: blur(12px);
}
button {
appearance: none;
border: 0;
border-radius: 9px;
padding: 10px 14px;
background: #294448;
color: #f7f6ef;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
background: #1f383c;
transform: translateY(-1px);
}
button.secondary {
background: transparent;
color: #53686b;
}
button.secondary:hover {
background: rgba(44, 71, 75, 0.08);
}
#legend {
position: fixed;
left: 26px;
bottom: 24px;
z-index: 10;
padding: 11px 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(248, 248, 242, 0.76);
backdrop-filter: blur(9px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
line-height: 1.8;
}
.swatch {
width: 13px;
height: 6px;
border-radius: 2px;
background: var(--coral);
}
.swatch.mouth {
background: var(--cyan);
}
.swatch.target {
background: #e7b947;
}
.swatch.dashed {
height: 0;
border-top: 2px dashed var(--green);
border-radius: 0;
background: transparent;
}
#status {
position: fixed;
right: 26px;
bottom: 28px;
z-index: 10;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
text-align: right;
}
#status::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin: 0 7px 1px 0;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(24, 143, 120, 0.1);
}
#mobilePairs {
display: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e7ece8;
color: #496266;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 900px) {
.topbar {
padding: 18px;
}
.disclaimer {
max-width: 245px;
}
#legend {
display: none;
}
#status {
right: 18px;
bottom: 84px;
}
}
@media (max-width: 700px) {
.topbar {
display: block;
}
h1 {
max-width: 360px;
font-size: 25px;
}
.subtitle {
max-width: 330px;
font-size: 11px;
}
.disclaimer {
margin-top: 12px;
max-width: 330px;
font-size: 9px;
}
.station-card,
.measure-label {
display: none !important;
}
#controls {
bottom: 14px;
width: calc(100% - 24px);
justify-content: center;
}
button {
flex: 1;
padding: 10px 8px;
font-size: 10px;
}
#status {
display: none;
}
#mobilePairs {
position: fixed;
left: 12px;
right: 12px;
bottom: 70px;
z-index: 10;
display: flex;
gap: 6px;
pointer-events: none;
}
.mobile-pair {
flex: 1;
padding: 8px 7px;
border: 1px solid rgba(39, 68, 71, 0.15);
border-radius: 9px;
background: rgba(249, 248, 242, 0.84);
color: #53686b;
font-size: 8px;
line-height: 1.35;
text-align: center;
}
.mobile-pair strong {
display: block;
margin-bottom: 2px;
color: var(--ink);
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="vignette"></div>
<div id="labels"></div>
<header class="topbar">
<div>
<p class="eyebrow">Field geometry / schematic study</p>
<h1>Floral depth × mouthpart length</h1>
<p class="subtitle">
Three low-poly pairings test whether a stylized mouthpart can reach a
stylized nectar target while remaining narrower than the floral opening.
</p>
</div>
<aside class="disclaimer">
<strong>Hypothetical pairing only</strong>
These are synthetic geometry exercises, not observations of real flowers,
pollinators, co-evolution, or species-specific relationships.
</aside>
</header>
<div id="controls">
<button id="fitToggle" type="button" aria-pressed="true">Separate pairs</button>
<button id="resetView" class="secondary" type="button">Reset view</button>
</div>
<aside id="legend">
<div class="legend-row">
<span class="swatch"></span> Floral envelope
</div>
<div class="legend-row">
<span class="swatch mouth"></span> Schematic mouthpart
</div>
<div class="legend-row">
<span class="swatch target"></span> Nectar target
</div>
<div class="legend-row">
<span class="swatch dashed"></span> Shared depth / length datum
</div>
</aside>
<div id="status" aria-live="polite">Geometric fit view</div>
<div id="mobilePairs"></div>
<div id="loading">Building low-poly geometry…</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, camera, and lighting
// ------------------------------------------------------------
const app = document.getElementById("app");
const labelLayer = document.getElementById("labels");
const mobilePairs = document.getElementById("mobilePairs");
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ece8);
scene.fog = new THREE.Fog(0xe7ece8, 18, 36);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 1.55, 0);
const desiredCamera = {
theta: 0.08,
phi: 1.29,
radius: window.innerWidth < 700 ? 29 : 17.4
};
const actualCamera = { ...desiredCamera };
const cameraSpherical = new THREE.Spherical();
function updateCamera(dt) {
const damping = 1 - Math.exp(-dt * 9);
actualCamera.theta +=
(desiredCamera.theta - actualCamera.theta) * damping;
actualCamera.phi +=
(desiredCamera.phi - actualCamera.phi) * damping;
actualCamera.radius +=
(desiredCamera.radius - actualCamera.radius) * damping;
cameraSpherical.set(
actualCamera.radius,
actualCamera.phi,
actualCamera.theta
);
camera.position
.setFromSpherical(cameraSpherical)
.add(cameraTarget);
camera.lookAt(cameraTarget);
}
const hemisphere = new THREE.HemisphereLight(
0xf9fcff,
0x728078,
2.1
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff5df, 3.2);
keyLight.position.set(6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8e6ed, 1.15);
fillLight.position.set(-8, 5, -6);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xdfe6e1,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.13;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(32, 32, 0xaab9b4, 0xc2ceca);
grid.position.y = -0.122;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
// ------------------------------------------------------------
// Reusable low-poly materials
// ------------------------------------------------------------
const standMaterial = new THREE.MeshStandardMaterial({
color: 0x3d565a,
roughness: 0.82,
metalness: 0.04,
flatShading: true
});
const standBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x263f43,
roughness: 0.88,
flatShading: true
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xf1eee4,
roughness: 0.95,
flatShading: true
});
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x4f8268,
roughness: 0.95,
flatShading: true
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x74a66c,
roughness: 0.95,
flatShading: true
});
const mouthMaterial = new THREE.MeshStandardMaterial({
color: 0x2caeaa,
roughness: 0.6,
metalness: 0.03,
flatShading: true
});
const mouthTipMaterial = new THREE.MeshStandardMaterial({
color: 0x176d70,
roughness: 0.72,
flatShading: true
});
const nectarMaterial = new THREE.MeshStandardMaterial({
color: 0xe7b947,
emissive: 0x8a5a0c,
emissiveIntensity: 0.32,
roughness: 0.6,
flatShading: true
});
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function createFunnelGeometry(rings, radialSegments = 10) {
const positions = [];
const indices = [];
for (const ring of rings) {
for (let segment = 0; segment < radialSegments; segment++) {
const angle = (segment / radialSegments) * Math.PI * 2;
positions.push(
ring.x,
Math.cos(angle) * ring.radius,
Math.sin(angle) * ring.radius
);
}
}
for (let ringIndex = 0; ringIndex < rings.length - 1; ringIndex++) {
for (let segment = 0; segment < radialSegments; segment++) {
const next = (segment + 1) % radialSegments;
const a = ringIndex * radialSegments + segment;
const b = ringIndex * radialSegments + next;
const c = (ringIndex + 1) * radialSegments + segment;
const d = (ringIndex + 1) * radialSegments + next;
indices.push(a, c, b);
indices.push(b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createPedestal(x, z = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.47, 0.14, 12),
standBaseMaterial
);
base.position.y = 0.07;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.07, 1.98, 8),
standMaterial
);
shaft.position.y = 1.13;
shaft.castShadow = true;
group.add(shaft);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.095, 0.12, 8),
standMaterial
);
collar.position.y = 2.15;
collar.castShadow = true;
group.add(collar);
return group;
}
function createHorizontalCylinder(length, radius, material, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.rotation.z = Math.PI / 2;
return mesh;
}
function createTorus(radius, tube, material) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 5, 12),
material
);
mesh.rotation.y = Math.PI / 2;
return mesh;
}
function createLine(points, color, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const material = dashed
? new THREE.LineDashedMaterial({
color,
dashSize: 0.07,
gapSize: 0.05,
transparent: true,
opacity: 0.82
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.68
});
const line = new THREE.Line(geometry, material);
if (dashed) line.computeLineDistances();
return line;
}
// ------------------------------------------------------------
// Synthetic pair data. All values are arbitrary demonstration units.
// ------------------------------------------------------------
const pairings = [
{
title: "Wide opening · short reach",
color: 0xee7470,
depth: 0.65,
openingDiameter: 0.72,
mouthpartDiameter: 0.18,
x: -4.6
},
{
title: "Medium opening · medium reach",
color: 0xefad49,
depth: 0.95,
openingDiameter: 0.42,
mouthpartDiameter: 0.14,
x: 0
},
{
title: "Narrow opening · deep reach",
color: 0x9882df,
depth: 1.35,
openingDiameter: 0.24,
mouthpartDiameter: 0.12,
x: 4.6
}
];
const stations = [];
// ------------------------------------------------------------
// Build each station
// ------------------------------------------------------------
for (const pairing of pairings) {
const station = new THREE.Group();
station.position.x = pairing.x;
scene.add(station);
const depth = pairing.depth;
const openingRadius = pairing.openingDiameter / 2;
const mouthpartRadius = pairing.mouthpartDiameter / 2;
const backX = -depth - 0.18;
const flowerY = 2.42;
// Shared display plinth.
const platform = new THREE.Mesh(
new THREE.BoxGeometry(4.35, 0.12, 1.62),
platformMaterial
);
platform.position.set(0.3, -0.06, 0);
platform.receiveShadow = true;
station.add(platform);
const platformEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(platform.geometry),
new THREE.LineBasicMaterial({
color: 0x9ba9a3,
transparent: true,
opacity: 0.25
})
);
platformEdges.position.copy(platform.position);
station.add(platformEdges);
// Matching pedestal designs on either side of each comparison.
const flowerStand = createPedestal(backX, 0);
const mouthStand = createPedestal(2.05, 0);
station.add(flowerStand, mouthStand);
// Botanical stem and leaves around the flower support.
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.05, 2.05, 6),
stemMaterial
);
stem.position.set(backX + 0.035, 1.17, 0.11);
stem.castShadow = true;
station.add(stem);
for (const side of [-1, 1]) {
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(1, 5, 3),
leafMaterial
);
leaf.scale.set(0.18, 0.07, 0.28);
leaf.position.set(
backX + side * 0.08,
1.02 + side * 0.17,
0.13
);
leaf.rotation.z = side * 0.55;
leaf.castShadow = true;
station.add(leaf);
}
// The floral envelope is a low-poly funnel, open along the X axis.
const tubeMaterial = new THREE.MeshStandardMaterial({
color: pairing.color,
roughness: 0.78,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide,
depthWrite: false
});
const contactRadius = Math.min(openingRadius * 0.55, 0.21);
const middleRadius = Math.max(openingRadius * 0.72, contactRadius + 0.03);
const rings = [
{ x: backX, radius: 0.085 },
{ x: -depth, radius: contactRadius },
{ x: -depth * 0.48, radius: middleRadius },
{ x: -Math.min(0.16, depth * 0.16), radius: openingRadius },
{ x: 0, radius: openingRadius }
];
const tubeGeometry = createFunnelGeometry(rings, 10);
const tube = new THREE.Mesh(tubeGeometry, tubeMaterial);
tube.position.y = flowerY;
station.add(tube);
const tubeEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(tubeGeometry, 24),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.28
})
);
tubeEdges.position.y = flowerY;
station.add(tubeEdges);
// Low-poly petals around the mouth.
const petalMaterial = new THREE.MeshStandardMaterial({
color: pairing.color,
roughness: 0.82,
flatShading: true
});
const petalAccentMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(pairing.color).lerp(
new THREE.Color(0xffffff),
0.18
),
roughness: 0.85,
flatShading: true
});
const petalCount = 7;
for (let index = 0; index < petalCount; index++) {
const angle = (index / petalCount) * Math.PI * 2;
const petal = new THREE.Mesh(
new THREE.SphereGeometry(1, 5, 3),
index % 2 === 0 ? petalMaterial : petalAccentMaterial
);
petal.scale.set(
0.34,
0.135,
0.115
);
petal.position.set(
0.08,
flowerY + Math.cos(angle) * (openingRadius + 0.075),
Math.sin(angle) * (openingRadius + 0.075)
);
petal.rotation.x = angle;
petal.castShadow = true;
station.add(petal);
}
// Mouth rim.
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0xf7e8cf,
roughness: 0.75,
flatShading: true
});
const mouthRim = createTorus(
openingRadius,
Math.max(0.018, openingRadius * 0.065),
rimMaterial
);
mouthRim.position.set(0, flowerY, 0);
station.add(mouthRim);
// Nectar target at the exact geometric contact point.
const nectarTarget = new THREE.Mesh(
new THREE.OctahedronGeometry(0.075, 0),
nectarMaterial
);
nectarTarget.position.set(-depth, flowerY, 0);
station.add(nectarTarget);
// The right pedestal supports a horizontal rail and sliding carriage.
const rail = createHorizontalCylinder(
2.28,
0.027,
standMaterial,
8
);
rail.position.set(0.965, 2.17, 0);
station.add(rail);
const railStop = new THREE.Mesh(
new THREE.BoxGeometry(0.08, 0.13, 0.13),
standMaterial
);
railStop.position.set(-0.19, 2.17, 0);
station.add(railStop);
// The carriage and mouthpart slide together.
const carriage = new THREE.Group();
carriage.position.y = 2.42;
station.add(carriage);
const carriageBlock = new THREE.Mesh(
new THREE.BoxGeometry(0.2, 0.14, 0.17),
standMaterial
);
carriageBlock.position.y = -0.25;
carriageBlock.castShadow = true;
carriage.add(carriageBlock);
const connector = new THREE.Mesh(
new THREE.CylinderGeometry(0.028, 0.028, 0.22, 6),
standMaterial
);
connector.position.y = -0.13;
carriage.add(connector);
// Open, tapered tube. Its length is exactly equal to floral depth.
const mouthpart = new THREE.Mesh(
new THREE.CylinderGeometry(
mouthpartRadius * 0.54,
mouthpartRadius,
depth,
8,
1,
true
),
mouthMaterial
);
mouthpart.rotation.z = Math.PI / 2;
mouthpart.position.x = -depth / 2;
mouthpart.castShadow = true;
carriage.add(mouthpart);
const mouthpartEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(mouthpart.geometry, 18),
new THREE.LineBasicMaterial({
color: 0xb9f0e7,
transparent: true,
opacity: 0.42
})
);
mouthpartEdges.rotation.z = Math.PI / 2;
mouthpartEdges.position.x = -depth / 2;
carriage.add(mouthpartEdges);
const rearCollar = new THREE.Mesh(
new THREE.SphereGeometry(mouthpartRadius * 1.15, 8, 5),
mouthTipMaterial
);
rearCollar.scale.x = 0.65;
carriage.add(rearCollar);
const tipRing = createTorus(
mouthpartRadius * 0.54,
Math.max(0.012, mouthpartRadius * 0.13),
mouthTipMaterial
);
tipRing.position.x = -depth;
carriage.add(tipRing);
for (const fraction of [0.3, 0.62]) {
const ring = createTorus(
mouthpartRadius * (1 - fraction * 0.38),
Math.max(0.009, mouthpartRadius * 0.09),
mouthTipMaterial
);
ring.position.x = -depth * fraction;
carriage.add(ring);
}
// Green alignment halo appears around the flower mouth during fit.
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0x37b28d,
transparent: true,
opacity: 0,
depthWrite: false
});
const halo = createTorus(
openingRadius + 0.14,
0.018,
haloMaterial
);
halo.position.set(0.025, flowerY, 0);
station.add(halo);
// Shared depth / length datum beneath the flower.
const bracket = createLine(
[
[-depth, 1.58, 0.48],
[0, 1.58, 0.48]
],
0x188f78,
true
);
station.add(bracket);
const ticks = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-depth, 1.49, 0.48),
new THREE.Vector3(-depth, 1.67, 0.48),
new THREE.Vector3(0, 1.49, 0.48),
new THREE.Vector3(0, 1.67, 0.48)
]),
new THREE.LineBasicMaterial({
color: 0x188f78,
transparent: true,
opacity: 0.72
})
);
station.add(ticks);
// A dotted connector links the target to its dimension bracket.
const targetGuide = createLine(
[
[-depth, 1.58, 0.48],
[-depth, flowerY, 0.48]
],
0x188f78,
true
);
station.add(targetGuide);
// HTML label projected from the 3D scene.
const card = document.createElement("article");
card.className = "station-card";
card.style.setProperty("--pair-color", `#${new THREE.Color(pairing.color).getHexString()}`);
const clearance =
(pairing.openingDiameter - pairing.mouthpartDiameter) / 2;
card.innerHTML = `
<div class="card-kicker">
<span class="dot"></span>
Hypothetical pair ${String(stations.length + 1).padStart(2, "0")}
</div>
<h2>${pairing.title}</h2>
<div class="pair-meta">
<div><span>Floral tube depth</span><b>${depth.toFixed(2)} u</b></div>
<div><span>Mouthpart length</span><b>${depth.toFixed(2)} u</b></div>
<div><span>Opening diameter</span><b>${pairing.openingDiameter.toFixed(2)} u</b></div>
<div><span>Mouthpart diameter</span><b>${pairing.mouthpartDiameter.toFixed(2)} u</b></div>
</div>
<div class="result">
<span class="check">✓</span>
Equal depth / length · clearance ${clearance.toFixed(2)} u
</div>
<div class="card-note">Synthetic dimensions only</div>
`;
labelLayer.appendChild(card);
const measureLabel = document.createElement("div");
measureLabel.className = "measure-label";
measureLabel.textContent = `D = L = ${depth.toFixed(2)} u`;
labelLayer.appendChild(measureLabel);
const mobilePair = document.createElement("div");
mobilePair.className = "mobile-pair";
mobilePair.innerHTML = `
<strong>Pair ${String(stations.length + 1).padStart(2, "0")}</strong>
D = L = ${depth.toFixed(2)} u<br>
${pairing.title}
`;
mobilePairs.appendChild(mobilePair);
stations.push({
pairing,
carriage,
halo,
haloMaterial,
nectarTarget,
card,
measureLabel,
cardAnchor: new THREE.Vector3(pairing.x - 0.12, 3.78, 0),
measureAnchor: new THREE.Vector3(
pairing.x - depth / 2,
1.39,
0.48
),
explodedRear: depth + 0.28
});
}
// ------------------------------------------------------------
// Fit animation
// ------------------------------------------------------------
let targetFit = 1;
let fitProgress = 0;
const fitToggle = document.getElementById("fitToggle");
const status = document.getElementById("status");
function updateModeUI() {
fitToggle.textContent = targetFit ? "Separate pairs" : "Show geometric fit";
fitToggle.setAttribute("aria-pressed", String(targetFit === 1));
status.textContent = targetFit
? "Geometric fit view"
: "Exploded comparison view";
for (const station of stations) {
station.card.classList.toggle("is-aligned", targetFit === 1);
}
}
fitToggle.addEventListener("click", () => {
targetFit = targetFit ? 0 : 1;
updateModeUI();
});
updateModeUI();
// ------------------------------------------------------------
// Screen projection for labels
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
element.style.visibility = visible ? "visible" : "hidden";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// ------------------------------------------------------------
// Custom orbit controls: pointer drag, wheel zoom, and keyboard.
// No Three.js examples/addons are used.
// ------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.68,
1.49
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
10,
38
);
},
{ passive: false }
);
function resetCamera() {
desiredCamera.theta = 0.08;
desiredCamera.phi = 1.29;
desiredCamera.radius = window.innerWidth < 700 ? 29 : 17.4;
}
document.getElementById("resetView").addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
targetFit = targetFit ? 0 : 1;
updateModeUI();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const fitDamping = 1 - Math.exp(-dt * 4.5);
fitProgress += (targetFit - fitProgress) * fitDamping;
for (const station of stations) {
// At fit, the rear of the mouthpart is exactly at the floral mouth.
// Its tip then reaches the nectar target at x = -depth.
station.carriage.position.x =
station.explodedRear * (1 - fitProgress);
station.haloMaterial.opacity = fitProgress * 0.82;
const pulse = 1 + Math.sin(performance.now() * 0.003) * 0.025;
station.halo.scale.setScalar(pulse);
station.nectarTarget.material.emissiveIntensity =
0.32 + fitProgress * 0.48;
station.card.classList.toggle(
"is-aligned",
fitProgress > 0.93
);
}
updateCamera(dt);
for (const station of stations) {
positionLabel(station.card, station.cardAnchor);
positionLabel(station.measureLabel, station.measureAnchor);
}
renderer.render(scene, camera);
}
document.getElementById("loading").remove();
animate();
</script>
</body>
</html>
```