Prompt specification
Build or customize the Three.js 3D scene "Kelp holdfast and grazer model" 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: Kelp holdfast and grazer model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/kelp-holdfast-and-grazer-model-x0705
Scene Description Prompt:
A stylized kelp, sea urchin, and otter exhibit separating plant structures from feeding relationships. Make one HTML file using Three.js from cdnjs.
Working Three.js Starter (kelp-holdfast-and-grazer-model-x0705):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Kelp, Sea Urchin & Otter — Interactive Exhibit</title>
<style>
:root {
--mint: #89f0bd;
--cyan: #70e4ef;
--amber: #ffc275;
--ink: #eafcff;
--muted: #9fc5cc;
--panel: rgba(4, 34, 45, 0.78);
--line: rgba(171, 237, 242, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 15%, rgba(35, 119, 135, 0.38), transparent 36%),
linear-gradient(180deg, #0b4a62 0%, #073747 48%, #052b37 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(2, 22, 31, 0.28), transparent 24%, transparent 72%, rgba(2, 18, 25, 0.4)),
radial-gradient(ellipse at center, transparent 48%, rgba(1, 17, 24, 0.35) 100%);
}
header {
position: fixed;
top: 30px;
left: 34px;
z-index: 10;
max-width: 470px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 20, 28, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 34px;
height: 2px;
content: "";
background: var(--mint);
border-radius: 4px;
}
h1 {
margin: 0;
font-size: clamp(32px, 4.2vw, 62px);
font-weight: 750;
letter-spacing: -0.055em;
line-height: 0.98;
}
header p {
max-width: 440px;
margin: 14px 0 0;
color: #b8d8dd;
font-size: 14px;
line-height: 1.55;
}
.mode-switch {
position: fixed;
z-index: 20;
top: 30px;
right: 32px;
display: flex;
gap: 5px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(4, 34, 45, 0.72);
box-shadow: 0 14px 40px rgba(0, 16, 24, 0.22);
backdrop-filter: blur(16px);
}
.mode-switch button {
min-width: 105px;
padding: 10px 14px;
border: 0;
border-radius: 11px;
background: transparent;
color: #a9c9cf;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: 180ms ease;
}
.mode-switch button:hover {
color: white;
background: rgba(255, 255, 255, 0.06);
}
.mode-switch button.active {
color: #052e37;
background: var(--mint);
box-shadow: 0 5px 18px rgba(82, 220, 157, 0.2);
}
#labels,
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 8;
}
#leaders {
overflow: visible;
}
.callout {
position: absolute;
min-width: 138px;
padding: 10px 12px 11px;
border: 1px solid rgba(137, 240, 189, 0.34);
border-radius: 12px;
background: rgba(4, 36, 46, 0.86);
box-shadow: 0 12px 35px rgba(0, 18, 25, 0.3);
transform: translate(-50%, -50%);
backdrop-filter: blur(12px);
white-space: nowrap;
}
.callout.relation {
border-color: rgba(255, 194, 117, 0.38);
}
.callout span {
display: block;
margin-bottom: 4px;
color: var(--mint);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.callout.relation span {
color: var(--amber);
}
.callout strong {
display: block;
color: white;
font-size: 13px;
font-weight: 800;
}
.callout small {
display: block;
margin-top: 3px;
color: #a8c9cf;
font-size: 10px;
font-weight: 500;
}
.guide-panel {
position: fixed;
z-index: 15;
right: 30px;
bottom: 28px;
width: 255px;
padding: 16px 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 48px rgba(0, 17, 25, 0.25);
backdrop-filter: blur(18px);
}
.guide-heading {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 13px;
color: #d9f6fa;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#view-status {
color: var(--mint);
font-size: 9px;
letter-spacing: 0.12em;
}
.key-row {
display: flex;
align-items: center;
gap: 10px;
margin: 10px 0;
}
.key-row i {
display: block;
width: 25px;
height: 3px;
flex: 0 0 auto;
border-radius: 4px;
background: var(--mint);
box-shadow: 0 0 12px rgba(137, 240, 189, 0.45);
}
.key-row i.feeding {
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 194, 117, 0.45);
}
.key-row b,
.key-row small {
display: block;
}
.key-row b {
color: #f2feff;
font-size: 12px;
}
.key-row small {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.guide-panel p {
margin: 13px 0 0;
padding-top: 12px;
border-top: 1px solid rgba(171, 237, 242, 0.14);
color: #9fbfc5;
font-size: 10px;
line-height: 1.5;
}
.hint {
position: fixed;
z-index: 12;
left: 34px;
bottom: 30px;
display: flex;
align-items: center;
gap: 10px;
color: rgba(218, 246, 249, 0.72);
font-size: 11px;
pointer-events: none;
}
.mouse {
position: relative;
width: 18px;
height: 27px;
border: 1px solid rgba(218, 246, 249, 0.55);
border-radius: 10px;
}
.mouse::after {
position: absolute;
top: 5px;
left: 7px;
width: 2px;
height: 6px;
content: "";
border-radius: 3px;
background: var(--mint);
}
@media (max-width: 800px) {
header {
top: 20px;
left: 20px;
max-width: 58%;
}
header p {
display: none;
}
.mode-switch {
top: 18px;
right: 16px;
flex-direction: column;
}
.mode-switch button {
min-width: 92px;
padding: 9px 10px;
}
.guide-panel {
right: 16px;
bottom: 16px;
width: 210px;
padding: 13px;
}
.hint {
left: 20px;
bottom: 20px;
}
.callout {
min-width: 112px;
padding: 8px 9px;
}
.callout small {
display: none;
}
}
@media (max-width: 560px) {
header {
max-width: 52%;
}
h1 {
font-size: 30px;
}
.eyebrow {
font-size: 8px;
}
.mode-switch button {
min-width: 78px;
font-size: 10px;
}
.guide-panel {
display: none;
}
.callout {
min-width: 96px;
padding: 7px 8px;
}
.callout span {
font-size: 7px;
}
.callout strong {
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-live="polite"></div>
<div class="vignette"></div>
<header>
<div class="eyebrow">Interactive coastal field guide</div>
<h1>Kelp, urchin,<br />otter.</h1>
<p>
Explore the kelp’s physical anatomy, then trace the feeding relationships
connecting this underwater forest to a swimming predator.
</p>
</header>
<nav class="mode-switch" aria-label="Exhibit views">
<button type="button" data-mode="anatomy">Plant anatomy</button>
<button type="button" data-mode="feeding">Food web</button>
<button type="button" data-mode="overview" class="active">Full scene</button>
</nav>
<aside class="guide-panel">
<div class="guide-heading">
Reading the exhibit
<span id="view-status">Overview</span>
</div>
<div class="key-row">
<i></i>
<div>
<b>Plant structures</b>
<small>Solid mint callouts</small>
</div>
</div>
<div class="key-row">
<i class="feeding"></i>
<div>
<b>Feeding relationships</b>
<small>Dashed directional arrows</small>
</div>
</div>
<p>
Arrows point from food to consumer: kelp → urchin → otter. The anatomical
labels describe parts of the kelp, not who eats it.
</p>
</aside>
<div class="hint">
<span class="mouse"></span>
Drag to orbit · Scroll or pinch to zoom
</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 container = document.getElementById("scene");
const labelLayer = document.getElementById("labels");
const leaderLayer = document.getElementById("leaders");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.setClearColor(0x000000, 0);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x073747, 0.035);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xc9f8ff, 0x173c38, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xe8fbff, 3.4);
sun.position.set(-4, 10, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -5;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0007;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x58c7d8, 1.4);
rim.position.set(7, 4, -6);
scene.add(rim);
const warmFill = new THREE.PointLight(0xffd4a0, 16, 9, 2);
warmFill.position.set(3.5, 2.5, 3.5);
scene.add(warmFill);
// -------------------------------------------------------------------------
// Reusable helpers
// -------------------------------------------------------------------------
function standardMaterial(color, roughness = 0.78, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
function branchBetween(start, end, radiusBottom, radiusTop, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
length,
8,
1
);
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;
return mesh;
}
function makeTube(points, radius, material, segments = 42) {
const curve = new THREE.CatmullRomCurve3(points);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 8, false),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeBlade(length, width, material) {
const segments = 14;
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const w = width * Math.pow(Math.sin(Math.PI * t), 0.72);
const z = 0.15 * Math.sin(Math.PI * t);
positions.push(-w, t * length, z);
positions.push(w, t * length, z);
uvs.push(0, t, 1, t);
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
indices.push(a, a + 1, a + 2);
indices.push(a + 1, a + 3, a + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// -------------------------------------------------------------------------
// Sea floor and rocks
// -------------------------------------------------------------------------
const floorMaterial = standardMaterial(0x155d59, 0.96);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 28),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.08;
floor.receiveShadow = true;
scene.add(floor);
const rockMaterial = standardMaterial(0x345b5b, 0.98);
const darkRockMaterial = standardMaterial(0x274747, 0.96);
function addRock(x, y, z, sx, sy, sz, material = rockMaterial) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(1, 0),
material
);
rock.position.set(x, y, z);
rock.scale.set(sx, sy, sz);
rock.rotation.set(
Math.random() * 0.7,
Math.random() * Math.PI,
Math.random() * 0.5
);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
return rock;
}
addRock(-5.7, 0.08, 0.2, 0.75, 0.42, 0.6);
addRock(-3.2, 0.02, 0.1, 0.48, 0.3, 0.46, darkRockMaterial);
addRock(-0.6, 0.08, 0.12, 0.82, 0.44, 0.68);
addRock(1.4, -0.01, -0.65, 0.62, 0.27, 0.5, darkRockMaterial);
addRock(5.2, -0.02, -0.3, 0.9, 0.32, 0.72);
addRock(-1.8, -0.02, -1.2, 0.52, 0.22, 0.45);
// -------------------------------------------------------------------------
// Procedural kelp
// -------------------------------------------------------------------------
const kelpDark = standardMaterial(0x245f40, 0.88);
const kelpMid = standardMaterial(0x3f8c4b, 0.82);
const kelpLight = standardMaterial(0x72b957, 0.76);
const bladderMaterial = standardMaterial(0xa8cf67, 0.68);
const kelpPlants = [];
function createKelp(x, z, height, phase) {
const group = new THREE.Group();
group.position.set(x, -0.01, z);
// Holdfast: branching root-like anchors.
const holdfastMaterial = kelpDark;
const rootEnds = [
new THREE.Vector3(-0.5, 0.02, 0.18),
new THREE.Vector3(0.44, 0.015, 0.24),
new THREE.Vector3(-0.24, 0.02, -0.48),
new THREE.Vector3(0.28, 0.015, -0.4),
new THREE.Vector3(0.03, 0.02, 0.58)
];
for (const end of rootEnds) {
group.add(
branchBetween(
new THREE.Vector3(0, 0.18, 0),
end,
0.09,
0.018,
holdfastMaterial
)
);
}
// Main stipe.
const stipePoints = [
new THREE.Vector3(0, 0.15, 0),
new THREE.Vector3(0.08, height * 0.25, 0.02),
new THREE.Vector3(-0.12, height * 0.51, -0.04),
new THREE.Vector3(0.1, height * 0.76, 0.04),
new THREE.Vector3(-0.04, height, 0.01)
];
group.add(makeTube(stipePoints, 0.052, kelpMid));
// Blades and their pneumatocysts.
const bladeSpecs = [
{ y: height * 0.31, side: 1, length: 0.92, width: 0.2 },
{ y: height * 0.47, side: -1, length: 1.03, width: 0.23 },
{ y: height * 0.63, side: 1, length: 0.9, width: 0.21 },
{ y: height * 0.78, side: -1, length: 0.78, width: 0.18 }
];
bladeSpecs.forEach((spec, index) => {
const pivot = new THREE.Group();
pivot.position.set(0, spec.y, 0);
pivot.rotation.z = spec.side * (0.88 + index * 0.035);
pivot.rotation.y = spec.side * 0.34;
const blade = makeBlade(
spec.length,
spec.width,
index % 2 === 0 ? kelpLight : kelpMid
);
pivot.add(blade);
const bladder = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 12, 9),
bladderMaterial
);
bladder.scale.set(0.8, 1.35, 0.8);
bladder.position.set(0, 0.035, 0);
bladder.castShadow = true;
pivot.add(bladder);
group.add(pivot);
});
// Terminal float.
const terminalFloat = new THREE.Mesh(
new THREE.SphereGeometry(0.14, 16, 12),
bladderMaterial
);
terminalFloat.scale.set(0.8, 1.45, 0.8);
terminalFloat.position.set(-0.04, height, 0.01);
terminalFloat.castShadow = true;
group.add(terminalFloat);
group.userData.phase = phase;
group.userData.baseRotation = (Math.random() - 0.5) * 0.04;
scene.add(group);
kelpPlants.push(group);
return group;
}
createKelp(-4.5, -0.1, 4.45, 0.2);
createKelp(-5.45, 0.2, 3.55, 1.8);
createKelp(-3.55, 0.16, 3.85, 3.1);
createKelp(-4.85, -0.75, 3.15, 4.6);
// -------------------------------------------------------------------------
// Sea urchin
// -------------------------------------------------------------------------
function createUrchin(radius = 0.52, spineScale = 1) {
const group = new THREE.Group();
const bodyMaterial = standardMaterial(0x59235f, 0.82);
const spineMaterial = standardMaterial(0x753774, 0.68);
const body = new THREE.Mesh(
new THREE.SphereGeometry(radius, 24, 18),
bodyMaterial
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const count = 90;
const spineHeight = radius * 0.9 * spineScale;
const spineGeometry = new THREE.ConeGeometry(
radius * 0.065,
spineHeight,
5
);
spineGeometry.translate(0, spineHeight * 0.5, 0);
const spines = new THREE.InstancedMesh(
spineGeometry,
spineMaterial,
count
);
spines.castShadow = true;
spines.receiveShadow = true;
const dummy = new THREE.Object3D();
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
const axis = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < count; i++) {
const y = 1 - 2 * ((i + 0.5) / count);
const ringRadius = Math.sqrt(1 - y * y);
const theta = goldenAngle * i;
const direction = new THREE.Vector3(
Math.cos(theta) * ringRadius,
y,
Math.sin(theta) * ringRadius
);
dummy.position.copy(direction).multiplyScalar(radius * 0.82);
dummy.quaternion.setFromUnitVectors(axis, direction.normalize());
dummy.scale.setScalar(0.82 + (i % 7) * 0.035);
dummy.updateMatrix();
spines.setMatrixAt(i, dummy.matrix);
}
spines.instanceMatrix.needsUpdate = true;
group.add(spines);
return group;
}
const urchin = createUrchin(0.54, 1);
urchin.position.set(-0.55, 0.61, 0.12);
scene.add(urchin);
// -------------------------------------------------------------------------
// Sea otter
// -------------------------------------------------------------------------
const otter = new THREE.Group();
otter.position.set(3.05, 1.5, 0.28);
otter.rotation.z = 0.075;
const fur = standardMaterial(0x855238, 0.96);
const furLight = standardMaterial(0xb98358, 0.98);
const cream = standardMaterial(0xdcc09a, 0.95);
const dark = standardMaterial(0x171b1d, 0.6);
function addEllipsoid(parent, material, position, scale) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(1, 24, 18),
material
);
mesh.position.copy(position);
mesh.scale.copy(scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Floating body and lighter belly.
addEllipsoid(
otter,
fur,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(1.12, 0.58, 0.72)
);
addEllipsoid(
otter,
furLight,
new THREE.Vector3(-0.02, -0.12, 0.43),
new THREE.Vector3(0.88, 0.42, 0.33)
);
// Head, muzzle, ears, eyes, and nose.
addEllipsoid(
otter,
fur,
new THREE.Vector3(-0.94, 0.18, 0.06),
new THREE.Vector3(0.55, 0.52, 0.53)
);
addEllipsoid(
otter,
cream,
new THREE.Vector3(-1.39, 0.08, 0.34),
new THREE.Vector3(0.34, 0.24, 0.27)
);
const nose = addEllipsoid(
otter,
dark,
new THREE.Vector3(-1.65, 0.14, 0.49),
new THREE.Vector3(0.11, 0.085, 0.08)
);
nose.castShadow = false;
addEllipsoid(
otter,
dark,
new THREE.Vector3(-1.08, 0.35, 0.48),
new THREE.Vector3(0.065, 0.075, 0.045)
);
addEllipsoid(
otter,
dark,
new THREE.Vector3(-1.08, 0.35, -0.37),
new THREE.Vector3(0.06, 0.07, 0.04)
);
addEllipsoid(
otter,
fur,
new THREE.Vector3(-0.68, 0.63, 0.36),
new THREE.Vector3(0.18, 0.2, 0.12)
);
addEllipsoid(
otter,
fur,
new THREE.Vector3(-0.68, 0.63, -0.36),
new THREE.Vector3(0.18, 0.2, 0.12)
);
// Hind feet.
addEllipsoid(
otter,
furLight,
new THREE.Vector3(0.42, -0.36, 0.42),
new THREE.Vector3(0.35, 0.17, 0.18)
);
addEllipsoid(
otter,
furLight,
new THREE.Vector3(0.42, -0.36, -0.42),
new THREE.Vector3(0.35, 0.17, 0.18)
);
// Long tapered-looking tail.
const tail = makeTube(
[
new THREE.Vector3(0.82, -0.05, -0.02),
new THREE.Vector3(1.38, -0.13, -0.08),
new THREE.Vector3(1.95, -0.03, -0.1),
new THREE.Vector3(2.48, 0.12, -0.04)
],
0.18,
fur,
36
);
otter.add(tail);
// A small urchin held between the paws.
const heldUrchin = createUrchin(0.18, 0.72);
heldUrchin.position.set(-0.76, 0.66, 0.72);
heldUrchin.rotation.z = 0.35;
otter.add(heldUrchin);
addEllipsoid(
otter,
furLight,
new THREE.Vector3(-0.48, 0.65, 0.74),
new THREE.Vector3(0.23, 0.13, 0.12)
);
addEllipsoid(
otter,
furLight,
new THREE.Vector3(-0.99, 0.57, 0.72),
new THREE.Vector3(0.21, 0.13, 0.12)
);
// Whiskers.
const whiskerMaterial = new THREE.LineBasicMaterial({
color: 0xe4f0df,
transparent: true,
opacity: 0.65
});
for (let i = 0; i < 3; i++) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.48, 0.08 + i * 0.045, 0.58),
new THREE.Vector3(-1.85, 0.01 + i * 0.09, 0.72 + i * 0.015)
]);
otter.add(new THREE.Line(geometry, whiskerMaterial));
}
scene.add(otter);
// -------------------------------------------------------------------------
// Feeding relationship arrows: food → consumer
// -------------------------------------------------------------------------
const relationshipGroup = new THREE.Group();
scene.add(relationshipGroup);
function createRelationshipArrow(start, end, color) {
const midpoint = start.clone().lerp(end, 0.5);
midpoint.y += 0.3;
const curve = new THREE.QuadraticBezierCurve3(start, midpoint, end);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(48)
);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.16,
gapSize: 0.1,
transparent: true,
opacity: 0.9,
depthTest: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 20;
relationshipGroup.add(line);
const direction = end.clone().sub(midpoint).normalize();
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.34, 12),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
arrowHead.position.copy(end);
arrowHead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
arrowHead.renderOrder = 21;
relationshipGroup.add(arrowHead);
}
createRelationshipArrow(
new THREE.Vector3(-2.8, 1.38, 0.45),
new THREE.Vector3(-1.25, 1.18, 0.38),
0x70e4ef
);
createRelationshipArrow(
new THREE.Vector3(0.16, 1.24, 0.42),
new THREE.Vector3(1.85, 1.82, 0.35),
0xffc275
);
// -------------------------------------------------------------------------
// Bubbles and suspended particles
// -------------------------------------------------------------------------
const bubbleMaterial = new THREE.MeshBasicMaterial({
color: 0xc6f8ff,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const bubbleGeometry = new THREE.SphereGeometry(1, 10, 8);
const bubbles = [];
for (let i = 0; i < 26; i++) {
const bubble = new THREE.Mesh(bubbleGeometry, bubbleMaterial);
const radius = 0.025 + Math.random() * 0.055;
bubble.scale.setScalar(radius);
bubble.position.set(
-6 + Math.random() * 12,
Math.random() * 5.5,
-1.5 + Math.random() * 4
);
scene.add(bubble);
bubbles.push({
mesh: bubble,
speed: 0.16 + Math.random() * 0.28,
baseX: bubble.position.x,
phase: Math.random() * Math.PI * 2
});
}
// -------------------------------------------------------------------------
// Screen-space annotations and leader lines
// -------------------------------------------------------------------------
const annotations = [];
function addAnnotation({
category,
title,
description,
anchor,
offset,
color
}) {
const element = document.createElement("div");
element.className = `callout ${category === "relation" ? "relation" : ""}`;
element.innerHTML = `
<span>${category === "relation" ? "Feeding relationship" : "Plant structure"}</span>
<strong>${title}</strong>
<small>${description}</small>
`;
labelLayer.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("stroke", color);
line.setAttribute("stroke-width", "1.3");
line.setAttribute("stroke-opacity", "0.72");
line.setAttribute("stroke-dasharray", category === "relation" ? "4 5" : "none");
leaderLayer.appendChild(line);
const dot = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
dot.setAttribute("r", "3.2");
dot.setAttribute("fill", color);
leaderLayer.appendChild(dot);
const annotation = {
category,
element,
line,
dot,
anchor: anchor.clone(),
offset
};
annotations.push(annotation);
return annotation;
}
addAnnotation({
category: "structure",
title: "Holdfast",
description: "Anchors the kelp to the rocky seabed",
anchor: new THREE.Vector3(-4.5, 0.18, 0.05),
offset: [92, 40],
color: "#89f0bd"
});
addAnnotation({
category: "structure",
title: "Stipe",
description: "Flexible stem that supports the blades",
anchor: new THREE.Vector3(-4.38, 2.05, 0),
offset: [-108, -34],
color: "#89f0bd"
});
addAnnotation({
category: "structure",
title: "Blade",
description: "Broad photosynthetic tissue",
anchor: new THREE.Vector3(-5.28, 2.8, 0.12),
offset: [-92, -12],
color: "#89f0bd"
});
addAnnotation({
category: "structure",
title: "Pneumatocyst",
description: "Gas bladder that keeps the blade afloat",
anchor: new THREE.Vector3(-4.08, 3.63, 0.12),
offset: [102, -42],
color: "#89f0bd"
});
addAnnotation({
category: "relation",
title: "Urchin grazes kelp",
description: "Food → consumer",
anchor: new THREE.Vector3(-2.05, 1.72, 0.46),
offset: [0, -47],
color: "#70e4ef"
});
addAnnotation({
category: "relation",
title: "Otter eats urchin",
description: "Food → consumer",
anchor: new THREE.Vector3(1.03, 1.92, 0.4),
offset: [0, -50],
color: "#ffc275"
});
// -------------------------------------------------------------------------
// Custom camera controls — no external controls addon
// -------------------------------------------------------------------------
const cameraRig = {
target: new THREE.Vector3(-0.35, 2.0, 0),
desiredTarget: new THREE.Vector3(-0.35, 2.0, 0),
yaw: 0.06,
desiredYaw: 0.06,
pitch: 0.22,
desiredPitch: 0.22,
distance: 11.4,
desiredDistance: 11.4
};
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 dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraRig.desiredYaw -= dx * 0.006;
cameraRig.desiredPitch = THREE.MathUtils.clamp(
cameraRig.desiredPitch + dy * 0.004,
-0.08,
0.72
);
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRig.desiredDistance = THREE.MathUtils.clamp(
cameraRig.desiredDistance * Math.exp(event.deltaY * 0.001),
5.2,
16
);
},
{ passive: false }
);
// Basic two-pointer pinch zoom.
const activePointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const nextDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
cameraRig.desiredDistance = THREE.MathUtils.clamp(
cameraRig.desiredDistance * (pinchDistance / nextDistance),
5.2,
16
);
}
pinchDistance = nextDistance;
}
});
function removePointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
if (activePointers.size === 0) dragging = false;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
function updateCamera() {
cameraRig.target.lerp(cameraRig.desiredTarget, 0.075);
cameraRig.yaw = THREE.MathUtils.lerp(
cameraRig.yaw,
cameraRig.desiredYaw,
0.08
);
cameraRig.pitch = THREE.MathUtils.lerp(
cameraRig.pitch,
cameraRig.desiredPitch,
0.08
);
cameraRig.distance = THREE.MathUtils.lerp(
cameraRig.distance,
cameraRig.desiredDistance,
0.08
);
const horizontalDistance =
Math.cos(cameraRig.pitch) * cameraRig.distance;
camera.position.set(
cameraRig.target.x + Math.sin(cameraRig.yaw) * horizontalDistance,
cameraRig.target.y + Math.sin(cameraRig.pitch) * cameraRig.distance,
cameraRig.target.z + Math.cos(cameraRig.yaw) * horizontalDistance
);
camera.lookAt(cameraRig.target);
}
// -------------------------------------------------------------------------
// Exhibit modes
// -------------------------------------------------------------------------
const modeButtons = [...document.querySelectorAll("[data-mode]")];
const status = document.getElementById("view-status");
let currentMode = "overview";
function setMode(mode) {
currentMode = mode;
modeButtons.forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
if (mode === "anatomy") {
status.textContent = "Anatomy";
cameraRig.desiredTarget.set(-4.45, 2.05, 0);
cameraRig.desiredDistance = 7.1;
cameraRig.desiredYaw = 0.02;
cameraRig.desiredPitch = 0.12;
} else if (mode === "feeding") {
status.textContent = "Food web";
cameraRig.desiredTarget.set(-0.3, 1.65, 0);
cameraRig.desiredDistance = 8.8;
cameraRig.desiredYaw = 0.12;
cameraRig.desiredPitch = 0.18;
} else {
status.textContent = "Overview";
cameraRig.desiredTarget.set(-0.35, 2.0, 0);
cameraRig.desiredDistance = 11.4;
cameraRig.desiredYaw = 0.06;
cameraRig.desiredPitch = 0.22;
}
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
// -------------------------------------------------------------------------
// Annotation projection
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
annotations.forEach((annotation) => {
const visible =
currentMode === "overview" ||
(currentMode === "anatomy" && annotation.category === "structure") ||
(currentMode === "feeding" && annotation.category === "relation");
annotation.element.style.display = visible ? "block" : "none";
annotation.line.style.display = visible ? "block" : "none";
annotation.dot.style.display = visible ? "block" : "none";
if (!visible) return;
projected.copy(annotation.anchor).project(camera);
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const labelX = THREE.MathUtils.clamp(
anchorX + annotation.offset[0],
85,
width - 85
);
const labelY = THREE.MathUtils.clamp(
anchorY + annotation.offset[1],
70,
height - 85
);
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
annotation.line.setAttribute("x1", anchorX);
annotation.line.setAttribute("y1", anchorY);
annotation.line.setAttribute("x2", labelX);
annotation.line.setAttribute("y2", labelY);
annotation.dot.setAttribute("cx", anchorX);
annotation.dot.setAttribute("cy", anchorY);
});
}
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.04);
// Gentle current bends the kelp around the anchored base.
kelpPlants.forEach((plant) => {
plant.rotation.z =
plant.userData.baseRotation +
Math.sin(elapsed * 0.72 + plant.userData.phase) * 0.035;
plant.rotation.x =
Math.sin(elapsed * 0.48 + plant.userData.phase) * 0.014;
});
urchin.rotation.y += delta * 0.16;
urchin.position.y = 0.61 + Math.sin(elapsed * 1.4) * 0.025;
heldUrchin.rotation.y -= delta * 0.5;
otter.position.y = 1.5 + Math.sin(elapsed * 1.1) * 0.035;
otter.rotation.z = 0.075 + Math.sin(elapsed * 0.8) * 0.012;
bubbles.forEach((bubble) => {
bubble.mesh.position.y += bubble.speed * delta;
bubble.mesh.position.x =
bubble.baseX + Math.sin(elapsed * 0.8 + bubble.phase) * 0.08;
if (bubble.mesh.position.y > 6) {
bubble.mesh.position.y = 0.05;
bubble.baseX = -6 + Math.random() * 12;
bubble.mesh.position.x = bubble.baseX;
}
});
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
setMode("overview");
animate();
</script>
</body>
</html>
```