Prompt specification
Build or customize the Three.js 3D scene "Three-node kelp food-web diagram" 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: Three-node kelp food-web diagram
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/three-node-kelp-food-web-diagram-x0706
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: three-node kelp food-web diagram. Animate symbolic connections from otter to urchin and urchin to kelp; arrows indicate who consumes whom, avoiding any unsupported quantitative population response. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (three-node-kelp-food-web-diagram-x0706):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Low-Poly Kelp Food Web</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 18%, #165766 0%, #083945 45%, #052b35 100%);
color: #e9fbf7;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.overlay {
position: fixed;
z-index: 10;
pointer-events: none;
}
.title-card {
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 17px 19px 16px;
border: 1px solid rgba(174, 232, 224, 0.2);
border-radius: 16px;
background: rgba(4, 31, 38, 0.76);
box-shadow: 0 14px 38px rgba(0, 16, 22, 0.22);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 6px;
color: #87d6ca;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1.02;
}
.subtitle {
margin: 8px 0 0;
color: rgba(226, 247, 243, 0.72);
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(218, 249, 243, 0.12);
color: rgba(232, 250, 246, 0.86);
font-size: 11px;
font-weight: 650;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
}
.legend-arrow {
position: relative;
width: 29px;
height: 2px;
border-radius: 2px;
}
.legend-arrow::after {
position: absolute;
top: -4px;
right: -1px;
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 8px solid currentColor;
content: "";
}
.otter-link {
color: #ffb56b;
background: currentColor;
}
.urchin-link {
color: #62e3bd;
background: currentColor;
}
.note {
left: 22px;
bottom: 20px;
width: min(510px, calc(100vw - 44px));
padding: 12px 14px;
border: 1px solid rgba(174, 232, 224, 0.16);
border-radius: 13px;
background: rgba(4, 31, 38, 0.78);
color: rgba(229, 248, 244, 0.78);
font-size: 11px;
line-height: 1.5;
backdrop-filter: blur(10px);
}
.note strong {
color: #effffc;
font-weight: 750;
}
.controls {
right: 22px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid rgba(174, 232, 224, 0.14);
border-radius: 999px;
background: rgba(4, 31, 38, 0.68);
color: rgba(230, 248, 244, 0.65);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
backdrop-filter: blur(10px);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #062f3a;
color: #bce9e1;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
display: none;
}
.legend {
margin-top: 9px;
padding-top: 9px;
}
.note {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.controls {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<header class="overlay title-card">
<div class="eyebrow">Low-poly marine diagram</div>
<h1>Kelp food web</h1>
<p class="subtitle">Three nodes connected by directional feeding relationships.</p>
<div class="legend" aria-label="Connection legend">
<span class="legend-item">
<i class="legend-arrow otter-link"></i>
otter eats urchin
</span>
<span class="legend-item">
<i class="legend-arrow urchin-link"></i>
urchin eats kelp
</span>
</div>
</header>
<aside class="overlay note">
<strong>Reading the arrows:</strong> consumer → what it consumes.
Moving glints reveal direction only; they do not encode abundance,
population change, or any quantitative population response.
</aside>
<div class="overlay controls">Drag to orbit · Scroll to zoom</div>
<div id="loading">Building the food web…</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("app");
const loading = document.getElementById("loading");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// ---------------------------------------------------------------------
// Renderer, camera, and scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x062f3a);
scene.fog = new THREE.Fog(0x062f3a, 16, 34);
const camera = new THREE.OrthographicCamera(-8, 8, 4.25, -4.25, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.95, 0);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly three-node kelp food web: otter, urchin, and kelp."
);
container.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbceff0, 0x15363d, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4ad, 3.25);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0008;
sun.target.position.set(0, 1, 0);
scene.add(sun, sun.target);
const fill = new THREE.DirectionalLight(0x62d8e5, 1.1);
fill.position.set(7, 4, -6);
scene.add(fill);
// ---------------------------------------------------------------------
// Utilities
// ---------------------------------------------------------------------
function seededRandom(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(7319);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
flatShading: true,
...options
});
}
function addMesh(parent, geometry, material, position, scale, rotation) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
if (scale) mesh.scale.copy(scale);
if (rotation) mesh.rotation.set(rotation.x, rotation.y, rotation.z);
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, start, end, startRadius, endRadius, material, sides = 6) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
endRadius,
startRadius,
length,
sides,
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;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel(text, accent, scale = new THREE.Vector3(1.8, 0.46, 1)) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 5, 5, 758, 150, 27);
ctx.fillStyle = "rgba(4, 28, 35, 0.90)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
ctx.beginPath();
ctx.arc(45, 80, 8, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#effffc";
ctx.font = "750 54px Inter, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 392, 83);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.copy(scale);
sprite.renderOrder = 30;
return sprite;
}
// ---------------------------------------------------------------------
// Faceted seafloor and distant rocks
// ---------------------------------------------------------------------
const floorGeometry = new THREE.PlaneGeometry(30, 24, 16, 12);
floorGeometry.rotateX(-Math.PI / 2);
const facetedFloor = floorGeometry.toNonIndexed();
floorGeometry.dispose();
const floorPositions = facetedFloor.attributes.position;
const floorColors = [];
for (let i = 0; i < floorPositions.count; i += 3) {
const color = new THREE.Color(0x245e61).multiplyScalar(
0.78 + random() * 0.32
);
for (let vertex = 0; vertex < 3; vertex++) {
floorColors.push(color.r, color.g, color.b);
}
}
facetedFloor.setAttribute(
"color",
new THREE.Float32BufferAttribute(floorColors, 3)
);
facetedFloor.computeVertexNormals();
const floor = new THREE.Mesh(
facetedFloor,
standardMaterial(0xffffff, {
vertexColors: true,
roughness: 1
})
);
floor.position.y = -0.08;
floor.receiveShadow = true;
scene.add(floor);
const rockGeometry = new THREE.IcosahedronGeometry(1, 1);
const rockMaterials = [
standardMaterial(0x315e5d),
standardMaterial(0x3d6c68),
standardMaterial(0x294f53)
];
for (let i = 0; i < 24; i++) {
const rock = new THREE.Mesh(
rockGeometry,
rockMaterials[i % rockMaterials.length]
);
const side = i % 2 === 0 ? -1 : 1;
rock.position.set(
side * (7 + random() * 7),
0.05 + random() * 0.18,
-9 + random() * 15
);
const size = 0.35 + random() * 1.45;
rock.scale.set(
size * (0.75 + random() * 0.65),
size * (0.35 + random() * 0.38),
size * (0.7 + random() * 0.6)
);
rock.rotation.set(random(), random() * Math.PI, random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// ---------------------------------------------------------------------
// Otter node
// ---------------------------------------------------------------------
const otter = new THREE.Group();
otter.position.set(-4.25, 2.62, 0.05);
otter.rotation.z = -0.055;
scene.add(otter);
const otterFur = standardMaterial(0x8e5937);
const otterFurLight = standardMaterial(0xc08a58);
const otterCream = standardMaterial(0xe5c59b);
const otterDark = standardMaterial(0x292426);
const otterNose = standardMaterial(0x17191b);
const otterBody = addMesh(
otter,
new THREE.IcosahedronGeometry(1, 2),
otterFur,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(1.16, 0.57, 0.52),
new THREE.Euler(0, 0, 0.04)
);
otterBody.castShadow = true;
const otterBelly = addMesh(
otter,
new THREE.IcosahedronGeometry(1, 1),
otterCream,
new THREE.Vector3(0.13, -0.24, 0.09),
new THREE.Vector3(0.83, 0.29, 0.45),
new THREE.Euler(0, 0, 0.04)
);
otterBelly.castShadow = true;
const otterHead = addMesh(
otter,
new THREE.IcosahedronGeometry(1, 2),
otterFurLight,
new THREE.Vector3(0.97, 0.13, 0),
new THREE.Vector3(0.56, 0.53, 0.5),
new THREE.Euler(0, 0, -0.06)
);
otterHead.castShadow = true;
const muzzle = addMesh(
otter,
new THREE.IcosahedronGeometry(1, 1),
otterCream,
new THREE.Vector3(1.42, -0.06, 0),
new THREE.Vector3(0.34, 0.23, 0.31)
);
muzzle.castShadow = true;
const nose = addMesh(
otter,
new THREE.IcosahedronGeometry(1, 1),
otterNose,
new THREE.Vector3(1.73, -0.025, 0),
new THREE.Vector3(0.11, 0.085, 0.12)
);
nose.castShadow = true;
for (const side of [-1, 1]) {
const eye = addMesh(
otter,
new THREE.SphereGeometry(0.065, 7, 5),
otterDark,
new THREE.Vector3(1.18, 0.28, side * 0.43)
);
eye.castShadow = true;
const ear = addMesh(
otter,
new THREE.IcosahedronGeometry(1, 1),
otterFur,
new THREE.Vector3(0.72, 0.61, side * 0.27),
new THREE.Vector3(0.13, 0.16, 0.11)
);
ear.castShadow = true;
const frontFlipper = addMesh(
otter,
new THREE.IcosahedronGeometry(1, 1),
otterFur,
new THREE.Vector3(0.53, -0.31, side * 0.4),
new THREE.Vector3(0.38, 0.14, 0.23),
new THREE.Euler(0.08, side * 0.2, -0.12)
);
frontFlipper.castShadow = true;
const rearFlipper = addMesh(
otter,
new THREE.IcosahedronGeometry(1, 1),
otterFur,
new THREE.Vector3(-0.55, -0.28, side * 0.38),
new THREE.Vector3(0.34, 0.13, 0.22),
new THREE.Euler(0, side * 0.18, 0.12)
);
rearFlipper.castShadow = true;
}
cylinderBetween(
otter,
new THREE.Vector3(-1.02, -0.02, 0),
new THREE.Vector3(-1.43, -0.16, 0.03),
0.29,
0.19,
otterFur
);
cylinderBetween(
otter,
new THREE.Vector3(-1.43, -0.16, 0.03),
new THREE.Vector3(-1.88, -0.28, 0.06),
0.19,
0.07,
otterFurLight
);
const whiskerMaterial = new THREE.LineBasicMaterial({
color: 0x302b29,
transparent: true,
opacity: 0.8
});
for (const side of [-1, 1]) {
for (let i = 0; i < 3; i++) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(1.58, -0.04 + (i - 1) * 0.035, side * 0.18),
new THREE.Vector3(
1.96,
-0.02 + (i - 1) * 0.11,
side * (0.37 + i * 0.04)
)
]);
otter.add(new THREE.Line(geometry, whiskerMaterial));
}
}
const otterLabel = makeLabel(
"OTTER",
"#ffb56b",
new THREE.Vector3(1.7, 0.44, 1)
);
otterLabel.position.set(-4.25, 4.03, 0.25);
scene.add(otterLabel);
// ---------------------------------------------------------------------
// Urchin node
// ---------------------------------------------------------------------
const urchin = new THREE.Group();
urchin.position.set(0, 0.77, 0.6);
scene.add(urchin);
const urchinBodyMaterial = standardMaterial(0x49304d);
const urchinSpineMaterial = standardMaterial(0x765071);
const urchinTipMaterial = standardMaterial(0x9b7394);
const urchinBody = addMesh(
urchin,
new THREE.IcosahedronGeometry(0.62, 1),
urchinBodyMaterial,
new THREE.Vector3(),
new THREE.Vector3(1, 0.91, 1)
);
urchinBody.castShadow = true;
const spikeCount = 25;
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
for (let i = 0; i < spikeCount; i++) {
const y = 1 - (i / (spikeCount - 1)) * 2;
const radial = Math.sqrt(Math.max(0, 1 - y * y));
const theta = goldenAngle * i;
const direction = new THREE.Vector3(
Math.cos(theta) * radial,
y,
Math.sin(theta) * radial
).normalize();
const length = 0.34 + (i % 4) * 0.045;
const spike = new THREE.Mesh(
new THREE.ConeGeometry(0.075, length, 5),
i % 5 === 0 ? urchinTipMaterial : urchinSpineMaterial
);
spike.position.copy(direction).multiplyScalar(0.58 + length * 0.5);
spike.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
spike.castShadow = true;
urchin.add(spike);
}
const urchinLabel = makeLabel(
"URCHIN",
"#62e3bd",
new THREE.Vector3(1.85, 0.46, 1)
);
urchinLabel.position.set(0, 2.35, 0.8);
scene.add(urchinLabel);
// ---------------------------------------------------------------------
// Kelp node
// ---------------------------------------------------------------------
const kelp = new THREE.Group();
kelp.position.set(4.15, 0, -0.05);
scene.add(kelp);
const kelpStemMaterial = standardMaterial(0x8b7437);
const kelpLeafMaterials = [
standardMaterial(0x4f9b57, { side: THREE.DoubleSide }),
standardMaterial(0x6aaa55, { side: THREE.DoubleSide }),
standardMaterial(0x3f8550, { side: THREE.DoubleSide })
];
function createLeafGeometry(length, width) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0, 0, 0,
-width * 0.5, length * 0.44, 0,
0, length, 0,
width * 0.5, length * 0.44, 0,
0, length * 0.46, width * 0.18
],
3
)
);
geometry.setIndex([
0, 1, 4,
1, 2, 4,
2, 3, 4,
3, 0, 4
]);
geometry.computeVertexNormals();
return geometry;
}
const stemDefinitions = [
{
points: [
new THREE.Vector3(-0.2, 0, 0),
new THREE.Vector3(-0.11, 0.88, 0.02),
new THREE.Vector3(-0.25, 1.72, 0.05),
new THREE.Vector3(-0.08, 2.65, 0.02),
new THREE.Vector3(0.06, 3.72, 0)
],
radii: [0.09, 0.075, 0.06, 0.047, 0.025]
},
{
points: [
new THREE.Vector3(0.28, 0, 0.12),
new THREE.Vector3(0.36, 0.72, 0.14),
new THREE.Vector3(0.25, 1.46, 0.12),
new THREE.Vector3(0.43, 2.24, 0.08),
new THREE.Vector3(0.36, 3.15, 0.04)
],
radii: [0.075, 0.064, 0.052, 0.038, 0.021]
},
{
points: [
new THREE.Vector3(-0.37, 0, -0.12),
new THREE.Vector3(-0.43, 0.64, -0.1),
new THREE.Vector3(-0.31, 1.26, -0.08),
new THREE.Vector3(-0.48, 1.92, -0.04)
],
radii: [0.068, 0.055, 0.043, 0.022]
}
];
stemDefinitions.forEach((stem, stemIndex) => {
for (let i = 0; i < stem.points.length - 1; i++) {
cylinderBetween(
kelp,
stem.points[i],
stem.points[i + 1],
stem.radii[i],
stem.radii[i + 1],
kelpStemMaterial
);
}
for (let i = 1; i < stem.points.length; i++) {
const base = stem.points[i];
const side = (i + stemIndex) % 2 === 0 ? 1 : -1;
const length = 0.58 + random() * 0.37;
const width = 0.23 + random() * 0.12;
const leaf = new THREE.Mesh(
createLeafGeometry(length, width),
kelpLeafMaterials[(i + stemIndex) % kelpLeafMaterials.length]
);
leaf.position.copy(base);
leaf.rotation.set(
(random() - 0.5) * 0.22,
(random() - 0.5) * 1.05,
side * (0.78 + random() * 0.34)
);
leaf.castShadow = true;
leaf.receiveShadow = true;
kelp.add(leaf);
}
});
const holdfast = addMesh(
kelp,
new THREE.IcosahedronGeometry(1, 1),
standardMaterial(0x3b625b),
new THREE.Vector3(0, 0.08, 0),
new THREE.Vector3(0.72, 0.24, 0.55)
);
holdfast.castShadow = true;
const kelpLabel = makeLabel(
"KELP",
"#9edf75",
new THREE.Vector3(1.65, 0.44, 1)
);
kelpLabel.position.set(4.15, 4.38, 0.05);
scene.add(kelpLabel);
// ---------------------------------------------------------------------
// Symbolic feeding links: consumer -> food
// ---------------------------------------------------------------------
const links = [];
function createFeedingLink(curve, color, text, phase) {
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 80, 0.047, 6, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.74,
depthTest: false,
depthWrite: false,
fog: false
})
);
tube.renderOrder = 10;
scene.add(tube);
const end = curve.getPointAt(1);
const tangent = curve.getTangentAt(1).normalize();
const arrowHeight = 0.38;
const arrowhead = new THREE.Mesh(
new THREE.ConeGeometry(0.145, arrowHeight, 7),
new THREE.MeshBasicMaterial({
color,
depthTest: false,
depthWrite: false,
fog: false
})
);
arrowhead.position.copy(end).addScaledVector(tangent, -arrowHeight * 0.5);
arrowhead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrowhead.renderOrder = 12;
scene.add(arrowhead);
const marker = new THREE.Group();
const crystal = new THREE.Mesh(
new THREE.OctahedronGeometry(0.105),
new THREE.MeshBasicMaterial({
color: 0xffffff,
depthTest: false,
depthWrite: false,
fog: false
})
);
crystal.renderOrder = 14;
marker.add(crystal);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.17, 0.018, 6, 22),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92,
depthTest: false,
depthWrite: false,
fog: false
})
);
halo.renderOrder = 13;
marker.add(halo);
scene.add(marker);
const label = makeLabel(
text,
color,
new THREE.Vector3(2.75, 0.56, 1)
);
const labelPosition = curve.getPointAt(0.52);
labelPosition.y += 0.14;
labelPosition.z += 0.28;
label.position.copy(labelPosition);
scene.add(label);
links.push({
curve,
tube,
marker,
crystal,
halo,
phase
});
}
const otterToUrchin = new THREE.CubicBezierCurve3(
new THREE.Vector3(-2.67, 2.62, 0.28),
new THREE.Vector3(-2.18, 4.35, 1.1),
new THREE.Vector3(-0.48, 3.42, 1.28),
new THREE.Vector3(-0.42, 1.45, 0.8)
);
const urchinToKelp = new THREE.CubicBezierCurve3(
new THREE.Vector3(0.43, 1.43, 0.82),
new THREE.Vector3(1.05, 3.12, 1.36),
new THREE.Vector3(2.78, 4.08, 1.02),
new THREE.Vector3(3.68, 2.47, 0.08)
);
createFeedingLink(
otterToUrchin,
0xffb56b,
"OTTER EATS URCHIN",
0.0
);
createFeedingLink(
urchinToKelp,
0x62e3bd,
"URCHIN EATS KELP",
0.34
);
// ---------------------------------------------------------------------
// Direct, dependency-free orbit and zoom controls
// ---------------------------------------------------------------------
const orbit = {
theta: 0.34,
phi: 1.22,
zoom: 1
};
const desiredOrbit = {
theta: orbit.theta,
phi: orbit.phi,
zoom: orbit.zoom
};
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredOrbit.theta -= deltaX * 0.006;
desiredOrbit.phi = THREE.MathUtils.clamp(
desiredOrbit.phi + deltaY * 0.005,
0.68,
1.49
);
});
function endDrag(event) {
dragging = false;
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();
desiredOrbit.zoom = THREE.MathUtils.clamp(
desiredOrbit.zoom * Math.exp(-event.deltaY * 0.001),
0.66,
1.75
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") desiredOrbit.theta -= 0.08;
if (event.key === "ArrowRight") desiredOrbit.theta += 0.08;
if (event.key === "ArrowUp") {
desiredOrbit.phi = Math.max(0.68, desiredOrbit.phi - 0.06);
}
if (event.key === "ArrowDown") {
desiredOrbit.phi = Math.min(1.49, desiredOrbit.phi + 0.06);
}
if (event.key === "+" || event.key === "=") {
desiredOrbit.zoom = Math.min(1.75, desiredOrbit.zoom + 0.08);
}
if (event.key === "-") {
desiredOrbit.zoom = Math.max(0.66, desiredOrbit.zoom - 0.08);
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(8.5, 12.8 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const up = new THREE.Vector3(0, 1, 0);
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const damping = 0.095;
orbit.theta += (desiredOrbit.theta - orbit.theta) * damping;
orbit.phi += (desiredOrbit.phi - orbit.phi) * damping;
orbit.zoom += (desiredOrbit.zoom - orbit.zoom) * damping;
const radius = 14.2;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + radius * Math.cos(orbit.phi),
cameraTarget.z + radius * sinPhi * Math.cos(orbit.theta)
);
camera.zoom = orbit.zoom;
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
links.forEach((link, index) => {
const speed = reducedMotion ? 0.045 : 0.19 + index * 0.025;
const t = (elapsed * speed + link.phase) % 1;
link.marker.position.copy(link.curve.getPointAt(t));
// Keep the ring facing the camera while the crystal rotates.
link.halo.quaternion.copy(camera.quaternion);
link.crystal.rotation.set(elapsed * 0.8, elapsed * 1.1, 0);
link.tube.material.opacity =
0.68 + Math.sin(elapsed * 1.3 + index) * 0.08;
});
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```