Prompt specification
Build or customize the Three.js 3D scene "Gliding forms on independent branches" 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: Gliding forms on independent branches
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/gliding-forms-on-independent-branches-x0894
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows convergent evolution. Show fictional gliding organisms from separate branches with similar aerodynamic surfaces; label the scenario illustrative and avoid treating resemblance as proof of close relationship. Stylized solid forms.
Working Three.js Starter (gliding-forms-on-independent-branches-x0894):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Convergent Evolution — Illustrative Gliding Organisms</title>
<style>
:root {
--ink: #18323a;
--muted: #53666b;
--paper: rgba(250, 248, 241, 0.91);
--line: rgba(24, 50, 58, 0.16);
--teal: #287d78;
--coral: #b85e72;
--gold: #d9913d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #f1eee5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 5;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.82);
box-shadow: 0 14px 38px rgba(35, 55, 58, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: currentColor;
border-radius: 2px;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
line-height: 1.03;
letter-spacing: -0.035em;
}
.intro p {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.scenario {
top: 22px;
right: 22px;
width: min(340px, calc(100vw - 44px));
padding: 16px 18px;
border-radius: 16px;
border-left: 4px solid var(--coral);
}
.scenario strong {
display: block;
margin-bottom: 5px;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scenario p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.comparison {
left: 50%;
bottom: 20px;
transform: translateX(-50%);
width: min(720px, calc(100vw - 32px));
display: grid;
grid-template-columns: 1fr 1px 1fr;
align-items: center;
gap: 18px;
padding: 14px 20px;
border-radius: 17px;
}
.comparison > .divider {
align-self: stretch;
background: var(--line);
}
.comparison small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.comparison strong {
font-size: 13px;
line-height: 1.4;
}
.comparison .similar strong {
color: #287d78;
}
.comparison .different strong {
color: #9a4c61;
}
.controls {
position: fixed;
z-index: 6;
right: 22px;
bottom: 20px;
display: flex;
gap: 8px;
}
.controls button {
appearance: none;
border: 1px solid rgba(24, 50, 58, 0.14);
border-radius: 12px;
padding: 10px 13px;
background: rgba(250, 248, 241, 0.94);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 24px rgba(35, 55, 58, 0.1);
transition: transform 150ms ease, background 150ms ease;
}
.controls button:hover {
transform: translateY(-1px);
background: #fffdf8;
}
.controls button:focus-visible {
outline: 3px solid rgba(40, 125, 120, 0.28);
outline-offset: 2px;
}
.hint {
position: fixed;
z-index: 4;
left: 22px;
bottom: 22px;
max-width: 270px;
color: rgba(24, 50, 58, 0.68);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
pointer-events: none;
}
.float-label {
position: fixed;
z-index: 3;
min-width: 160px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.88);
border-radius: 11px;
background: rgba(250, 248, 241, 0.88);
box-shadow: 0 8px 24px rgba(35, 55, 58, 0.1);
backdrop-filter: blur(9px);
-webkit-backdrop-filter: blur(9px);
transform: translate(-50%, -100%);
pointer-events: none;
transition: opacity 160ms ease;
}
.float-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 10px;
height: 10px;
transform: translateX(-50%) rotate(45deg);
background: rgba(250, 248, 241, 0.88);
border-right: 1px solid rgba(255, 255, 255, 0.88);
border-bottom: 1px solid rgba(255, 255, 255, 0.88);
}
.float-label .tag {
display: block;
margin-bottom: 3px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.float-label strong {
display: block;
font-size: 12px;
}
.float-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.label-a .tag {
color: var(--teal);
}
.label-b .tag {
color: var(--coral);
}
.branch-label {
position: fixed;
z-index: 3;
transform: translate(-50%, -50%);
color: var(--ink);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-align: center;
text-transform: uppercase;
pointer-events: none;
text-shadow: 0 1px 5px #f1eee5;
}
.branch-label::before {
content: "";
display: block;
width: 7px;
height: 7px;
margin: 0 auto 5px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.55);
}
.branch-a {
color: var(--teal);
}
.branch-b {
color: var(--coral);
}
.ancestor-label {
color: #6b6257;
}
.air-label {
position: fixed;
z-index: 2;
transform: translate(-50%, -50%);
color: rgba(40, 105, 116, 0.58);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #f1eee5;
color: var(--muted);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.intro {
width: min(330px, calc(100vw - 44px));
padding: 16px 18px;
}
.intro p {
display: none;
}
.scenario {
top: auto;
right: 16px;
bottom: 82px;
width: min(310px, calc(100vw - 32px));
}
.comparison {
bottom: 16px;
grid-template-columns: 1fr;
gap: 8px;
padding: 11px 15px;
}
.comparison > .divider {
display: none;
}
.controls {
top: 20px;
right: 16px;
bottom: auto;
}
.hint {
display: none;
}
.float-label {
min-width: 130px;
padding: 7px 9px;
}
.float-label small {
display: none;
}
}
@media (max-width: 600px) {
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 112px);
}
.intro h1 {
font-size: 23px;
}
.scenario {
right: 12px;
bottom: 76px;
width: calc(100vw - 24px);
}
.comparison {
display: none;
}
.controls button {
padding: 9px 10px;
}
.branch-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D illustration of two independently evolved gliding organisms"></div>
<header class="panel intro">
<div class="eyebrow">Evolution / Visual analogy</div>
<h1>Convergent<br />Evolution</h1>
<p>
Two fictional lineages independently evolve broad, swept gliding surfaces.
Their wings look alike, while their bodies and tails remain distinctly different.
</p>
</header>
<aside class="panel scenario">
<strong>Illustrative scenario</strong>
<p>
Similarity can evolve under similar selective pressures. This resemblance is
not evidence that the organisms are close relatives, and the scene is not a
phylogenetic reconstruction.
</p>
</aside>
<div id="labelA" class="float-label label-a">
<span class="tag">Branch I</span>
<strong>Reed-Membrane Glider</strong>
<small>Flexible ribs · split tail</small>
</div>
<div id="labelB" class="float-label label-b">
<span class="tag">Branch II</span>
<strong>Stone-Skinned Glider</strong>
<small>Armored body · fan tail</small>
</div>
<div id="branchA" class="branch-label branch-a">Distant reed-finned lineage</div>
<div id="branchB" class="branch-label branch-b">Distant stone-skinned lineage</div>
<div id="ancestor" class="branch-label ancestor-label">Older common ancestor</div>
<div id="airLabel" class="air-label">Shared open-air habitat · similar gliding challenge</div>
<section class="panel comparison">
<div class="similar">
<small>Similar aerodynamic solution</small>
<strong>Broad, swept membrane for stable gliding</strong>
</div>
<div class="divider"></div>
<div class="different">
<small>Different biological construction</small>
<strong>Flexible versus armored supports; split versus fan tail</strong>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Click a glider to focus</div>
<div class="controls">
<button id="reset" type="button" title="Reset camera (R)">Reset view</button>
<button id="pause" type="button" title="Pause or resume animation (Space)">Pause motion</button>
</div>
<div id="loading">Building the evolutionary scene…</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.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf1eee5);
scene.fog = new THREE.Fog(0xf1eee5, 16, 31);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
loading.textContent = "WebGL is required to view this illustration.";
throw error;
}
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;
container.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x8fa7a3, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3dc, 3.25);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x98cad1, 1.25);
rimLight.position.set(7, 4, -8);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 30),
new THREE.ShadowMaterial({ color: 0x526565, opacity: 0.12 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.62;
floor.receiveShadow = true;
scene.add(floor);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.02,
flatShading: true,
...options
});
}
function cylinderBetween(start, end, radius, material, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
return mesh;
}
// The two wings intentionally share the same aerodynamic planform.
// Their supports, bodies, colors and tails remain visibly distinct.
function createWing(side, membraneMaterial, supportMaterial) {
const wing = new THREE.Group();
const edgeY = 0.015;
const bottomY = -0.055;
const outline = [
[0.14 * side, edgeY, 0.72],
[1.54 * side, edgeY, 0.38],
[1.72 * side, edgeY, -0.23],
[0.16 * side, edgeY, -0.78]
];
const positions = [];
const indices = [];
for (const point of outline) positions.push(...point);
positions.push(0.76 * side, 0.19, -0.06);
for (let i = 0; i < 4; i++) {
indices.push(4, i, (i + 1) % 4);
}
const bottomStart = positions.length / 3;
for (const point of outline) {
positions.push(point[0], bottomY, point[2]);
}
positions.push(0.76 * side, 0.005, -0.06);
for (let i = 0; i < 4; i++) {
indices.push(
bottomStart + 4,
bottomStart + ((i + 1) % 4),
bottomStart + i
);
}
for (let i = 0; i < 4; i++) {
const next = (i + 1) % 4;
indices.push(
i,
bottomStart + i,
bottomStart + next,
i,
bottomStart + next,
next
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const membrane = new THREE.Mesh(
geometry,
membraneMaterial.clone()
);
membrane.material.side = THREE.DoubleSide;
membrane.castShadow = true;
membrane.receiveShadow = true;
wing.add(membrane);
const strutPairs = [
[
new THREE.Vector3(0.1 * side, 0.1, 0.42),
new THREE.Vector3(1.47 * side, 0.11, 0.31)
],
[
new THREE.Vector3(0.1 * side, 0.1, 0.18),
new THREE.Vector3(1.65 * side, 0.11, -0.18)
],
[
new THREE.Vector3(0.1 * side, 0.1, -0.25),
new THREE.Vector3(1.43 * side, 0.11, -0.51)
]
];
for (const [start, end] of strutPairs) {
wing.add(cylinderBetween(start, end, 0.022, supportMaterial, 5));
}
return wing;
}
function createGlider({
bodyColor,
bodyScale,
bellyColor,
wingColor,
supportColor,
tailStyle,
phase
}) {
const root = new THREE.Group();
root.userData.phase = phase;
const bodyMaterial = standardMaterial(bodyColor);
const bellyMaterial = standardMaterial(bellyColor);
const membraneMaterial = standardMaterial(wingColor, {
roughness: 0.82,
side: THREE.DoubleSide
});
const supportMaterial = standardMaterial(supportColor, {
roughness: 0.82
});
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.72, 1),
bodyMaterial
);
body.scale.set(...bodyScale);
body.castShadow = true;
body.receiveShadow = true;
root.add(body);
const belly = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.63, 1),
bellyMaterial
);
belly.scale.set(
bodyScale[0] * 0.86,
bodyScale[1] * 0.56,
bodyScale[2] * 0.92
);
belly.position.set(0, -0.18, 0.02);
belly.castShadow = true;
root.add(belly);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.34, 1),
bodyMaterial
);
head.scale.set(1, 0.86, 1.05);
head.position.set(0, 0.08, 0.7);
head.castShadow = true;
root.add(head);
const eyeMaterial = standardMaterial(0x172428, {
roughness: 0.32
});
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.06, 8, 6),
eyeMaterial
);
eye.position.set(side * 0.17, 0.12, 0.985);
root.add(eye);
const glint = new THREE.Mesh(
new THREE.SphereGeometry(0.016, 6, 4),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
glint.position.set(side * 0.19, 0.145, 1.027);
root.add(glint);
}
const leftWing = createWing(-1, membraneMaterial, supportMaterial);
const rightWing = createWing(1, membraneMaterial, supportMaterial);
root.add(leftWing, rightWing);
root.userData.leftWing = leftWing;
root.userData.rightWing = rightWing;
// Distinct tail architectures emphasize independent ancestry.
const tailMaterial = supportMaterial;
if (tailStyle === "split") {
const tailOffsets = [-0.19, 0, 0.19];
const tailLengths = [0.68, 0.82, 0.68];
for (let i = 0; i < 3; i++) {
const tail = new THREE.Mesh(
new THREE.ConeGeometry(0.105, tailLengths[i], 4),
tailMaterial
);
tail.rotation.x = -Math.PI / 2;
tail.position.set(tailOffsets[i], 0.02, -1.07 - tailLengths[i] * 0.18);
tail.scale.x = 0.78;
tail.castShadow = true;
root.add(tail);
}
} else {
for (const side of [-1, 1]) {
const tail = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.86, 4),
tailMaterial
);
tail.rotation.x = -Math.PI / 2;
tail.rotation.z = side * 0.16;
tail.position.set(side * 0.22, 0.015, -1.13);
tail.scale.x = 0.72;
tail.castShadow = true;
root.add(tail);
}
const centralTail = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.56, 4),
tailMaterial
);
centralTail.rotation.x = -Math.PI / 2;
centralTail.position.set(0, -0.03, -0.92);
centralTail.scale.x = 0.72;
centralTail.castShadow = true;
root.add(centralTail);
}
// Small dorsal structures further distinguish the two organisms.
if (tailStyle === "split") {
for (let i = 0; i < 3; i++) {
const spine = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.22, 4),
supportMaterial
);
spine.position.set(0, bodyScale[1] * 0.85, 0.25 - i * 0.31);
root.add(spine);
}
} else {
for (let i = 0; i < 3; i++) {
const plate = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.16, 0),
bellyMaterial
);
plate.scale.set(1.25, 0.55, 1.15);
plate.position.set(0, bodyScale[1] * 0.84, 0.27 - i * 0.34);
plate.rotation.y = i * 0.3;
plate.castShadow = true;
root.add(plate);
}
}
root.traverse((object) => {
if (object.isMesh) object.userData.glider = root;
});
return root;
}
const gliderA = createGlider({
bodyColor: 0x287d78,
bodyScale: [0.56, 0.44, 1.12],
bellyColor: 0x8dc2a4,
wingColor: 0xe3a24d,
supportColor: 0x795034,
tailStyle: "split",
phase: 0
});
const gliderB = createGlider({
bodyColor: 0x504b7c,
bodyScale: [0.68, 0.50, 1.02],
bellyColor: 0x9a91ae,
wingColor: 0xd77989,
supportColor: 0x654359,
tailStyle: "fan",
phase: 1.8
});
gliderA.position.set(-2.48, 1.08, 0.15);
gliderA.rotation.y = -0.11;
gliderA.rotation.z = -0.025;
gliderB.position.set(2.48, 1.08, 0.08);
gliderB.rotation.y = 0.13;
gliderB.rotation.z = 0.025;
scene.add(gliderA, gliderB);
// A stylized phylogenetic tree below the organisms.
function createBranch(points, color, radius = 0.09) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const geometry = new THREE.TubeGeometry(curve, 64, radius, 8, false);
const mesh = new THREE.Mesh(
geometry,
standardMaterial(color, { roughness: 0.85 })
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
const trunk = createBranch(
[
[0, -3.48, -1.55],
[0, -3.12, -1.55],
[0, -2.65, -1.55]
],
0x756959,
0.12
);
const branchACurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, -2.65, -1.55),
new THREE.Vector3(-0.82, -2.24, -1.55),
new THREE.Vector3(-1.68, -1.64, -1.55),
new THREE.Vector3(-2.48, -0.72, -1.55)
]);
const branchBCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, -2.65, -1.55),
new THREE.Vector3(0.82, -2.24, -1.55),
new THREE.Vector3(1.68, -1.64, -1.55),
new THREE.Vector3(2.48, -0.72, -1.55)
]);
const branchAMesh = new THREE.Mesh(
new THREE.TubeGeometry(branchACurve, 64, 0.09, 8, false),
standardMaterial(0x287d78, { roughness: 0.85 })
);
const branchBMesh = new THREE.Mesh(
new THREE.TubeGeometry(branchBCurve, 64, 0.09, 8, false),
standardMaterial(0xb85e72, { roughness: 0.85 })
);
branchAMesh.castShadow = true;
branchBMesh.castShadow = true;
scene.add(branchAMesh, branchBMesh);
const nodeMaterialA = standardMaterial(0x287d78);
const nodeMaterialB = standardMaterial(0xb85e72);
const nodeMaterialRoot = standardMaterial(0x756959);
function addNode(position, material, scale = 1) {
const node = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13 * scale, 1),
material
);
node.position.copy(position);
node.castShadow = true;
scene.add(node);
return node;
}
addNode(new THREE.Vector3(0, -3.48, -1.55), nodeMaterialRoot, 1.05);
addNode(new THREE.Vector3(0, -2.65, -1.55), nodeMaterialRoot, 1.08);
addNode(new THREE.Vector3(-2.48, -0.72, -1.55), nodeMaterialA, 1.22);
addNode(new THREE.Vector3(2.48, -0.72, -1.55), nodeMaterialB, 1.22);
// Air-current lines make the shared gliding environment legible.
const flowCurves = [];
const flowParticles = [];
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const flowMaterial = new THREE.LineBasicMaterial({
color: 0x80b8bd,
transparent: true,
opacity: 0.23,
depthWrite: false
});
for (let row = 0; row < 5; row++) {
const y = 0.28 + row * 0.33;
const z = -0.85 + row * 0.34;
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-5.6, y + 0.12, z),
new THREE.Vector3(-2.4, y, z),
new THREE.Vector3(0, y + 0.08, z),
new THREE.Vector3(2.4, y, z),
new THREE.Vector3(5.6, y + 0.12, z)
]);
flowCurves.push(curve);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(90)
);
flowGroup.add(new THREE.Line(geometry, flowMaterial));
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0xb9dde0,
transparent: true,
opacity: 0.68,
depthWrite: false
});
for (let j = 0; j < 2; j++) {
const particle = new THREE.Mesh(
new THREE.SphereGeometry(0.035 + row * 0.002, 7, 5),
particleMaterial
);
flowGroup.add(particle);
flowParticles.push({
mesh: particle,
curve,
offset: j * 0.46 + row * 0.13,
speed: 0.055 + row * 0.006
});
}
}
// Directional markers.
const arrowMaterial = standardMaterial(0x8dbdc1, {
transparent: true,
opacity: 0.48
});
for (const x of [-4.6, -1.2, 1.2, 4.6]) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.24, 5),
arrowMaterial
);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(x, 0.94 + Math.sin(x * 0.7) * 0.18, -0.36);
flowGroup.add(arrow);
}
// Camera and direct pointer controls, implemented without addons.
const cameraState = {
yaw: 0.08,
pitch: 0.39,
radius: 12.3
};
const desiredCamera = {
yaw: cameraState.yaw,
pitch: cameraState.pitch,
radius: cameraState.radius
};
const cameraTarget = new THREE.Vector3(0, 0.25, 0);
const desiredTarget = cameraTarget.clone();
function updateCamera() {
const horizontal = cameraState.radius * Math.cos(cameraState.pitch);
camera.position.set(
cameraTarget.x + Math.sin(cameraState.yaw) * horizontal,
cameraTarget.y + Math.sin(cameraState.pitch) * cameraState.radius,
cameraTarget.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const drag = {
active: false,
mode: "orbit",
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
moved: false
};
const rendererCanvas = renderer.domElement;
rendererCanvas.addEventListener("pointerdown", (event) => {
drag.active = true;
drag.mode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
drag.startX = event.lastX;
drag.startY = event.lastY;
drag.lastX = event.lastX;
drag.lastY = event.lastY;
drag.moved = false;
rendererCanvas.setPointerCapture(event.pointerId);
});
rendererCanvas.addEventListener("pointermove", (event) => {
if (!drag.active) return;
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
if (
Math.abs(event.clientX - drag.startX) +
Math.abs(event.clientY - drag.startY) >
4
) {
drag.moved = true;
}
if (drag.mode === "orbit") {
desiredCamera.yaw -= dx * 0.0052;
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch + dy * 0.0042,
0.12,
0.86
);
} else {
const scale = desiredCamera.radius * 0.0015;
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
desiredTarget.addScaledVector(right, -dx * scale);
desiredTarget.addScaledVector(up, dy * scale);
desiredTarget.x = THREE.MathUtils.clamp(desiredTarget.x, -4, 4);
desiredTarget.y = THREE.MathUtils.clamp(desiredTarget.y, -1.8, 3);
desiredTarget.z = THREE.MathUtils.clamp(desiredTarget.z, -2, 2);
}
});
rendererCanvas.addEventListener("pointerup", (event) => {
drag.active = false;
if (rendererCanvas.hasPointerCapture(event.pointerId)) {
rendererCanvas.releasePointerCapture(event.pointerId);
}
if (!drag.moved) {
const rect = rendererCanvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
[gliderA, gliderB],
true
);
if (hits.length) {
const selected = hits[0].object.userData.glider;
if (selected) {
desiredTarget.copy(selected.position);
desiredTarget.y -= 0.05;
desiredCamera.radius = 7.2;
}
}
}
});
rendererCanvas.addEventListener("pointercancel", () => {
drag.active = false;
});
rendererCanvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
rendererCanvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius + event.deltaY * 0.008,
6.3,
18
);
},
{ passive: false }
);
rendererCanvas.addEventListener("dblclick", resetView);
function resetView() {
desiredCamera.yaw = 0.08;
desiredCamera.pitch = 0.39;
desiredCamera.radius = 12.3;
desiredTarget.set(0, 0.25, 0);
}
document.getElementById("reset").addEventListener("click", resetView);
let paused = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const pauseButton = document.getElementById("pause");
function updatePauseButton() {
pauseButton.textContent = paused ? "Resume motion" : "Pause motion";
pauseButton.setAttribute("aria-pressed", String(paused));
}
pauseButton.addEventListener("click", () => {
paused = !paused;
updatePauseButton();
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.code === "Space") {
event.preventDefault();
paused = !paused;
updatePauseButton();
}
});
updatePauseButton();
const labels = {
a: document.getElementById("labelA"),
b: document.getElementById("labelB"),
branchA: document.getElementById("branchA"),
branchB: document.getElementById("branchB"),
ancestor: document.getElementById("ancestor"),
air: document.getElementById("airLabel")
};
const fixedAnchors = {
branchA: new THREE.Vector3(-2.48, -0.42, -1.55),
branchB: new THREE.Vector3(2.48, -0.42, -1.55),
ancestor: new THREE.Vector3(0, -3.48, -1.55),
air: new THREE.Vector3(0, 2.72, -0.15)
};
const projectionVector = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projectionVector.copy(worldPosition).project(camera);
const visible =
projectionVector.z > -1 &&
projectionVector.z < 1 &&
Math.abs(projectionVector.x) < 1.2 &&
Math.abs(projectionVector.y) < 1.2;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projectionVector.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projectionVector.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function updateLabels() {
const labelAPosition = new THREE.Vector3(0, 1.05, 0);
gliderA.localToWorld(labelAPosition);
positionLabel(labels.a, labelAPosition);
const labelBPosition = new THREE.Vector3(0, 1.05, 0);
gliderB.localToWorld(labelBPosition);
positionLabel(labels.b, labelBPosition);
positionLabel(labels.branchA, fixedAnchors.branchA);
positionLabel(labels.branchB, fixedAnchors.branchB);
positionLabel(labels.ancestor, fixedAnchors.ancestor);
positionLabel(labels.air, fixedAnchors.air);
}
function handleResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", handleResize);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const animationTime = paused ? 0 : elapsed;
cameraState.yaw = THREE.MathUtils.lerp(
cameraState.yaw,
desiredCamera.yaw,
0.075
);
cameraState.pitch = THREE.MathUtils.lerp(
cameraState.pitch,
desiredCamera.pitch,
0.075
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
desiredCamera.radius,
0.075
);
cameraTarget.lerp(desiredTarget, 0.075);
updateCamera();
const baseY = 1.08;
gliderA.position.y = baseY + Math.sin(animationTime * 0.85) * 0.11;
gliderB.position.y = baseY + Math.sin(animationTime * 0.85 + 1.8) * 0.11;
gliderA.rotation.x = Math.sin(animationTime * 0.62) * 0.018;
gliderB.rotation.x = Math.sin(animationTime * 0.62 + 1.1) * 0.018;
const wingFlexA = Math.sin(animationTime * 0.9) * 0.012;
const wingFlexB = Math.sin(animationTime * 0.9 + 1.3) * 0.012;
gliderA.userData.leftWing.rotation.z = -wingFlexA;
gliderA.userData.rightWing.rotation.z = wingFlexA;
gliderB.userData.leftWing.rotation.z = -wingFlexB;
gliderB.userData.rightWing.rotation.z = wingFlexB;
for (const particle of flowParticles) {
const t = (animationTime * particle.speed + particle.offset) % 1;
particle.mesh.position.copy(particle.curve.getPoint(t));
}
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
}
}
animate();
</script>
</body>
</html>
```