Prompt specification
Build or customize the Three.js 3D scene "Seagrass roots rhizome and blades" 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: Seagrass roots rhizome and blades
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/seagrass-roots-rhizome-and-blades-x0773
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Show a seagrass patch in a sediment cutaway with upright blades, horizontal rhizome, and roots; distinguish the flowering plant structure from nearby unattached algae.
Working Three.js Starter (seagrass-roots-rhizome-and-blades-x0773):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Seagrass Patch — Botanical Cutaway</title>
<style>
:root {
--ink: #eaf7f4;
--muted: #a6c0bd;
--glass: rgba(7, 29, 34, 0.78);
--line: rgba(190, 232, 224, 0.2);
--green: #80d66e;
--algae: #a69b48;
--root: #e1c99b;
--flower: #e6b6de;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 38%, #16444a 0%, #0b2b33 43%, #061a22 100%);
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%;
outline: none;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(180deg, rgba(1, 14, 20, 0.18), transparent 24%),
radial-gradient(circle at 50% 45%, transparent 45%, rgba(0, 10, 15, 0.48));
}
.intro {
position: fixed;
top: 25px;
left: 27px;
z-index: 5;
width: min(390px, calc(100vw - 110px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #87c8bd;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 50px);
font-weight: 570;
line-height: 0.98;
letter-spacing: -0.045em;
text-shadow: 0 3px 22px rgba(0, 0, 0, 0.24);
}
.intro p {
max-width: 355px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.reset {
position: fixed;
top: 25px;
right: 25px;
z-index: 7;
display: grid;
place-items: center;
width: 42px;
height: 42px;
border: 1px solid var(--line);
border-radius: 50%;
background: var(--glass);
color: var(--ink);
cursor: pointer;
backdrop-filter: blur(12px);
transition: 160ms ease;
}
.reset:hover {
border-color: rgba(190, 232, 224, 0.55);
background: rgba(18, 56, 62, 0.9);
transform: rotate(-12deg);
}
.reset svg {
width: 18px;
height: 18px;
}
.legend {
position: fixed;
left: 25px;
bottom: 24px;
z-index: 5;
display: flex;
flex-wrap: wrap;
gap: 9px 16px;
max-width: min(650px, calc(100vw - 50px));
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--glass);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #c9ddda;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: 0 0 10px currentColor;
}
.hint {
position: fixed;
right: 25px;
bottom: 26px;
z-index: 5;
color: rgba(211, 235, 231, 0.62);
font-size: 10px;
letter-spacing: 0.06em;
pointer-events: none;
}
#leaders {
position: fixed;
inset: 0;
z-index: 3;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke-width: 1;
stroke-dasharray: 3 4;
opacity: 0.68;
}
.callout {
position: fixed;
z-index: 4;
min-width: 115px;
padding: 8px 10px 8px 11px;
border: 1px solid var(--line);
border-left: 3px solid var(--accent, var(--green));
border-radius: 7px;
background: rgba(6, 27, 33, 0.86);
box-shadow: 0 8px 26px rgba(0, 0, 0, 0.2);
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
pointer-events: none;
transition: opacity 120ms linear;
}
.callout strong {
display: block;
color: var(--accent, var(--green));
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.callout span {
display: block;
margin-top: 3px;
color: #bfd1cf;
font-size: 10px;
line-height: 1.35;
}
@media (max-width: 700px) {
.intro {
top: 18px;
left: 18px;
}
.intro p {
max-width: 280px;
font-size: 11px;
}
.reset {
top: 18px;
right: 18px;
}
.legend {
left: 14px;
bottom: 14px;
gap: 8px 11px;
padding: 9px 11px;
}
.legend-item {
font-size: 8px;
}
.hint {
display: none;
}
.callout {
min-width: 92px;
padding: 6px 7px;
}
.callout span {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="intro">
<div class="eyebrow">Subtidal botany / cutaway 01</div>
<h1>Seagrass patch</h1>
<p>
A flowering monocot, connected from upright leaf blades and flowers
to a horizontal rhizome and roots. Nearby olive-brown algae remain loose
and unattached.
</p>
</header>
<button id="reset" class="reset" aria-label="Reset camera" title="Reset camera">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path
d="M4 11a8 8 0 1 1 2.3 5.7M4 11V5m0 6h6"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</button>
<svg id="leaders" aria-hidden="true"></svg>
<div id="callouts">
<div class="callout" id="label-plant" style="--accent: var(--green)">
<strong>Flowering seagrass</strong>
<span>Connected vascular shoot</span>
</div>
<div class="callout" id="label-flower" style="--accent: var(--flower)">
<strong>Flower</strong>
<span>Reproductive structure</span>
</div>
<div class="callout" id="label-rhizome" style="--accent: #d8b46c">
<strong>Horizontal rhizome</strong>
<span>Underground stem</span>
</div>
<div class="callout" id="label-roots" style="--accent: var(--root)">
<strong>Roots</strong>
<span>Anchoring and uptake</span>
</div>
<div class="callout" id="label-algae" style="--accent: var(--algae)">
<strong>Unattached algae</strong>
<span>No rhizome or roots</span>
</div>
</div>
<div class="legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch" style="color: var(--green); background: var(--green)"></span>
Flowering seagrass
</div>
<div class="legend-item">
<span class="swatch" style="color: var(--algae); background: var(--algae)"></span>
Unattached algae
</div>
<div class="legend-item">
<span class="swatch" style="color: #8c6c4d; background: #8c6c4d"></span>
Sediment cutaway
</div>
</div>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0x08252d);
scene.fog = new THREE.FogExp2(0x08252d, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive 3D seagrass cutaway");
container.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xa4e5df, 0x3b271b, 2.15));
const keyLight = new THREE.DirectionalLight(0xffefd1, 3.2);
keyLight.position.set(-4.5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x6dc8dc, 1.1);
fillLight.position.set(8, 3, -7);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0x94f3d2, 12, 16, 2);
rimLight.position.set(-3, 1.5, 5);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Deterministic helpers
// ---------------------------------------------------------------------
let randomSeed = 7319;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6d2b79f5) | 0;
let t = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
function cylinderBetween(a, b, radius, material, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius * 1.03,
length,
radialSegments,
1
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// A folded, tapering ribbon used for seagrass leaves and algal blades.
function createRibbon({
base = new THREE.Vector3(),
height = 1.6,
width = 0.18,
bend = 0.4,
angle = 0,
color = 0x64bb55,
segments = 14,
wave = 0,
ridge = 0.025
}) {
const positions = [];
const indices = [];
const centerLine = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const eased = t * t;
const center = new THREE.Vector3(
base.x + Math.cos(angle) * bend * eased,
base.y + height * t,
base.z + Math.sin(angle) * bend * eased
);
center.x += Math.sin(t * Math.PI * 3.0) * wave * t;
center.z += Math.cos(t * Math.PI * 2.4) * wave * t;
const taper = Math.pow(
Math.max(0.025, Math.sin(Math.PI * Math.min(0.98, t + 0.035))),
0.52
);
const halfWidth = (width * taper * (1 - 0.18 * t)) / 2;
const side = new THREE.Vector3(-Math.sin(angle), 0, Math.cos(angle));
for (let col = -1; col <= 1; col++) {
const vertex = center.clone().addScaledVector(side, col * halfWidth);
if (col === 0) {
vertex.y += Math.sin(Math.PI * t) * ridge;
}
positions.push(vertex.x, vertex.y, vertex.z);
}
centerLine.push(
center.x,
center.y + Math.sin(Math.PI * t) * ridge + 0.004,
center.z
);
}
for (let i = 0; i < segments; i++) {
for (let col = 0; col < 2; col++) {
const a = i * 3 + col;
const b = a + 3;
const c = a + 1;
const d = b + 1;
indices.push(a, b, c, c, b, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
const veinGeometry = new THREE.BufferGeometry();
veinGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(centerLine, 3)
);
const vein = new THREE.Line(
veinGeometry,
new THREE.LineBasicMaterial({
color: 0xc1df72,
transparent: true,
opacity: 0.42
})
);
mesh.add(vein);
return mesh;
}
// ---------------------------------------------------------------------
// Sediment cutaway
// ---------------------------------------------------------------------
const sedimentGroup = new THREE.Group();
scene.add(sedimentGroup);
const sedimentLayers = [
{ height: 0.55, color: 0x8a7953, y: -0.275 },
{ height: 0.92, color: 0x75583d, y: -1.01 },
{ height: 1.18, color: 0x8c6948, y: -2.06 },
{ height: 0.85, color: 0x594638, y: -3.075 }
];
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x34261d,
transparent: true,
opacity: 0.46
});
for (const layer of sedimentLayers) {
const geometry = new THREE.BoxGeometry(13.8, layer.height, 6.6);
const material = new THREE.MeshStandardMaterial({
color: layer.color,
roughness: 0.97,
metalness: 0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, layer.y, -1.05);
mesh.receiveShadow = true;
mesh.castShadow = true;
sedimentGroup.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
edgeMaterial
);
edges.position.copy(mesh.position);
sedimentGroup.add(edges);
}
// Fine sediment grains embedded in the exposed vertical face.
const faceGrainGeometry = new THREE.IcosahedronGeometry(0.028, 0);
const faceGrainMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const faceGrains = new THREE.InstancedMesh(
faceGrainGeometry,
faceGrainMaterial,
520
);
const dummy = new THREE.Object3D();
const grainColor = new THREE.Color();
for (let i = 0; i < 520; i++) {
dummy.position.set(
range(-6.8, 6.8),
range(-3.45, -0.05),
2.255 + range(-0.005, 0.015)
);
dummy.rotation.set(random() * 3, random() * 3, random() * 3);
dummy.scale.set(
range(0.35, 1.4),
range(0.25, 0.9),
range(0.25, 0.7)
);
dummy.updateMatrix();
faceGrains.setMatrixAt(i, dummy.matrix);
grainColor.setHSL(range(0.07, 0.12), range(0.16, 0.34), range(0.3, 0.58));
faceGrains.setColorAt(i, grainColor);
}
faceGrains.instanceMatrix.needsUpdate = true;
faceGrains.instanceColor.needsUpdate = true;
sedimentGroup.add(faceGrains);
// Pebbles and shell fragments resting on the sediment surface.
const pebbleGeometry = new THREE.IcosahedronGeometry(0.09, 0);
const pebbleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95
});
const pebbles = new THREE.InstancedMesh(
pebbleGeometry,
pebbleMaterial,
105
);
for (let i = 0; i < 105; i++) {
dummy.position.set(
range(-6.75, 6.75),
range(0.025, 0.07),
range(-4.15, 2.1)
);
dummy.rotation.set(random() * 3, random() * 3, random() * 3);
dummy.scale.set(
range(0.35, 1.8),
range(0.25, 0.85),
range(0.45, 1.7)
);
dummy.updateMatrix();
pebbles.setMatrixAt(i, dummy.matrix);
grainColor.setHSL(
range(0.06, 0.13),
range(0.08, 0.28),
range(0.35, 0.68)
);
pebbles.setColorAt(i, grainColor);
}
pebbles.instanceMatrix.needsUpdate = true;
pebbles.instanceColor.needsUpdate = true;
pebbles.castShadow = true;
pebbles.receiveShadow = true;
sedimentGroup.add(pebbles);
// ---------------------------------------------------------------------
// Flowering seagrass: rhizome, nodes, roots, shoots, leaves, and flowers
// ---------------------------------------------------------------------
const seagrass = new THREE.Group();
scene.add(seagrass);
const rhizomeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-4.75, -0.18, 2.30),
new THREE.Vector3(-2.7, -0.12, 2.31),
new THREE.Vector3(-0.45, -0.24, 2.30),
new THREE.Vector3(1.7, -0.15, 2.31),
new THREE.Vector3(4.05, -0.22, 2.30)
]);
const rhizomeMaterial = new THREE.MeshStandardMaterial({
color: 0x85904c,
roughness: 0.75
});
const rhizome = new THREE.Mesh(
new THREE.TubeGeometry(rhizomeCurve, 140, 0.095, 9, false),
rhizomeMaterial
);
rhizome.castShadow = true;
rhizome.receiveShadow = true;
seagrass.add(rhizome);
const nodeMaterial = new THREE.MeshStandardMaterial({
color: 0xb2ae63,
roughness: 0.72
});
const rootMaterial = new THREE.MeshStandardMaterial({
color: 0xd9c39a,
roughness: 0.92
});
const shootMaterial = new THREE.MeshStandardMaterial({
color: 0x4c9b42,
roughness: 0.72
});
const shootGroups = [];
const rootAnchors = [];
const nodePositions = [];
const leafColors = [
0x55b94e,
0x63c653,
0x429d48,
0x78ca58,
0x4eae58
];
const petalMaterial = new THREE.MeshStandardMaterial({
color: 0xe9c3e4,
roughness: 0.48,
emissive: 0x321c30,
emissiveIntensity: 0.1
});
const flowerCenterMaterial = new THREE.MeshStandardMaterial({
color: 0xe4c45d,
roughness: 0.5
});
const petalGeometry = new THREE.SphereGeometry(0.105, 10, 7);
const flowerCenterGeometry = new THREE.SphereGeometry(0.055, 10, 8);
function createFlower(scale = 1) {
const flower = new THREE.Group();
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const petal = new THREE.Mesh(petalGeometry, petalMaterial);
petal.position.set(
Math.cos(angle) * 0.105,
0,
Math.sin(angle) * 0.105
);
petal.rotation.y = -angle;
petal.scale.set(1.4, 0.38, 0.72);
petal.castShadow = true;
flower.add(petal);
}
const center = new THREE.Mesh(
flowerCenterGeometry,
flowerCenterMaterial
);
center.castShadow = true;
flower.add(center);
flower.scale.setScalar(scale);
return flower;
}
function createShoot(nodePosition, index) {
const group = new THREE.Group();
group.position.copy(nodePosition);
const stemHeight = range(0.28, 0.55);
const depth = -range(0.25, 0.62);
const stemCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(
range(-0.045, 0.045),
stemHeight * 0.52,
depth * 0.35
),
new THREE.Vector3(0, stemHeight, depth)
]);
const stem = new THREE.Mesh(
new THREE.TubeGeometry(stemCurve, 18, 0.035, 7, false),
shootMaterial
);
stem.castShadow = true;
group.add(stem);
const leafCount = 5 + (index % 2);
for (let leafIndex = 0; leafIndex < leafCount; leafIndex++) {
const angle =
(leafIndex / leafCount) * Math.PI * 2 +
range(-0.42, 0.42);
const leafBase = new THREE.Vector3(
range(-0.035, 0.035),
stemHeight * range(0.18, 0.92),
depth * range(0.1, 0.9)
);
const leaf = createRibbon({
base: leafBase,
height: range(1.05, 2.2),
width: range(0.13, 0.23),
bend: range(0.28, 0.8),
angle,
color: leafColors[(index + leafIndex) % leafColors.length],
segments: 16,
wave: range(0.015, 0.065),
ridge: 0.025
});
group.add(leaf);
}
// Several mature shoots carry visible flowers.
if (index === 3 || index === 7) {
const flowerStemCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, stemHeight * 0.72, depth * 0.65),
new THREE.Vector3(
range(-0.08, 0.08),
stemHeight + 0.72,
depth - 0.08
),
new THREE.Vector3(
range(-0.12, 0.12),
stemHeight + 1.32,
depth - 0.12
)
]);
const flowerStem = new THREE.Mesh(
new THREE.TubeGeometry(flowerStemCurve, 28, 0.018, 6, false),
shootMaterial
);
flowerStem.castShadow = true;
group.add(flowerStem);
for (let f = 0; f < 4; f++) {
const t = 0.48 + f * 0.15;
const point = flowerStemCurve.getPoint(t);
const flower = createFlower(range(0.76, 1.05));
flower.position.copy(point);
flower.position.x += range(-0.11, 0.11);
flower.position.z += range(-0.09, 0.09);
flower.rotation.y = random() * Math.PI;
group.add(flower);
}
}
shootGroups.push({
group,
phase: random() * Math.PI * 2,
amplitude: range(0.006, 0.018)
});
return group;
}
const nodeCount = 11;
for (let i = 0; i < nodeCount; i++) {
const t = 0.055 + (i / (nodeCount - 1)) * 0.89;
const nodePosition = rhizomeCurve.getPointAt(t);
nodePositions.push(nodePosition);
const node = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 10, 7),
nodeMaterial
);
node.position.copy(nodePosition);
node.scale.set(1.25, 0.88, 0.92);
node.castShadow = true;
seagrass.add(node);
const shoot = createShoot(nodePosition, i);
seagrass.add(shoot);
// Exposed roots descend down the cut face.
const direction = i % 2 === 0 ? 1 : -1;
const length = range(0.9, 2.05);
const rootCurve = new THREE.CatmullRomCurve3([
nodePosition.clone(),
new THREE.Vector3(
nodePosition.x + direction * range(0.05, 0.18),
nodePosition.y - length * 0.25,
2.315
),
new THREE.Vector3(
nodePosition.x + direction * range(0.18, 0.42),
nodePosition.y - length * 0.67,
2.325
),
new THREE.Vector3(
nodePosition.x + direction * range(0.22, 0.58),
nodePosition.y - length,
2.31
)
]);
const root = new THREE.Mesh(
new THREE.TubeGeometry(rootCurve, 34, range(0.019, 0.029), 6, false),
rootMaterial
);
root.castShadow = true;
seagrass.add(root);
// Secondary rootlets.
const branchStart = rootCurve.getPointAt(range(0.38, 0.64));
const branchDirection = -direction * range(0.28, 0.62);
const branchCurve = new THREE.CatmullRomCurve3([
branchStart,
new THREE.Vector3(
branchStart.x + branchDirection * 0.28,
branchStart.y - range(0.15, 0.35),
2.33
),
new THREE.Vector3(
branchStart.x + branchDirection * range(0.4, 0.7),
branchStart.y - range(0.35, 0.75),
2.315
)
]);
const branch = new THREE.Mesh(
new THREE.TubeGeometry(branchCurve, 24, 0.014, 5, false),
rootMaterial
);
branch.castShadow = true;
seagrass.add(branch);
rootAnchors.push(nodePosition.clone());
}
// A few fine surface roots show the branching network near the rhizome.
for (let i = 0; i < 8; i++) {
const node = nodePositions[i];
const fineCurve = new THREE.CatmullRomCurve3([
node.clone(),
new THREE.Vector3(
node.x + range(-0.3, 0.3),
node.y - range(0.14, 0.32),
2.34
),
new THREE.Vector3(
node.x + range(-0.5, 0.5),
node.y - range(0.3, 0.55),
2.33
)
]);
const fineRoot = new THREE.Mesh(
new THREE.TubeGeometry(fineCurve, 20, 0.01, 5, false),
rootMaterial
);
seagrass.add(fineRoot);
}
// ---------------------------------------------------------------------
// Nearby unattached algae: irregular olive-brown fronds, no root system
// ---------------------------------------------------------------------
const algaeGroups = [];
const algaeMaterials = [
new THREE.MeshStandardMaterial({
color: 0x77763a,
roughness: 0.86,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x8b7838,
roughness: 0.88,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x536c4b,
roughness: 0.9,
side: THREE.DoubleSide
})
];
function createAlgaeClump(position, scale, phase) {
const group = new THREE.Group();
group.position.copy(position);
group.scale.setScalar(scale);
const algaeStemMaterial = new THREE.MeshStandardMaterial({
color: 0x555c31,
roughness: 0.9
});
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2 + range(-0.35, 0.35);
const height = range(0.34, 0.84);
const frond = createRibbon({
base: new THREE.Vector3(
range(-0.1, 0.1),
range(-0.03, 0.08),
range(-0.1, 0.1)
),
height,
width: range(0.07, 0.16),
bend: range(0.16, 0.48),
angle,
color: [0x77763a, 0x8b7838, 0x536c4b][i % 3],
segments: 12,
wave: range(0.025, 0.08),
ridge: 0.008
});
group.add(frond);
const stemEnd = new THREE.Vector3(
Math.cos(angle) * range(0.12, 0.32),
height * 0.68,
Math.sin(angle) * range(0.12, 0.32)
);
const stem = cylinderBetween(
new THREE.Vector3(0, 0, 0),
stemEnd,
0.012,
algaeStemMaterial,
5
);
group.add(stem);
}
// A loose tangle visually separates the algae from a rooted plant.
const tangle = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.014, 5, 22),
algaeStemMaterial
);
tangle.position.set(0.06, 0.035, 0.02);
tangle.rotation.set(1.1, 0.3, 0.4);
group.add(tangle);
algaeGroups.push({
group,
phase,
amplitude: range(0.035, 0.075)
});
scene.add(group);
return group;
}
createAlgaeClump(
new THREE.Vector3(4.85, 0.66, 1.15),
1.05,
0.4
);
createAlgaeClump(
new THREE.Vector3(5.45, 0.2, 0.38),
0.78,
2.3
);
createAlgaeClump(
new THREE.Vector3(4.42, 0.1, 2.0),
0.56,
4.1
);
// ---------------------------------------------------------------------
// Suspended particles and soft underwater depth cues
// ---------------------------------------------------------------------
const particleCount = 430;
const particlePositions = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount; i++) {
particlePositions[i * 3] = range(-8, 8);
particlePositions[i * 3 + 1] = range(-2.5, 5.2);
particlePositions[i * 3 + 2] = range(-5, 4);
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0xb9e4dc,
size: 0.026,
transparent: true,
opacity: 0.33,
depthWrite: false
})
);
scene.add(particles);
// A few faint, sloping shafts of light in the water.
const lightShaftMaterial = new THREE.MeshBasicMaterial({
color: 0x9de5dc,
transparent: true,
opacity: 0.025,
depthWrite: false,
side: THREE.DoubleSide
});
for (let i = 0; i < 3; i++) {
const shaft = new THREE.Mesh(
new THREE.PlaneGeometry(1.5, 9),
lightShaftMaterial
);
shaft.position.set(-4 + i * 4.2, 2.2, -3.8 - i * 0.25);
shaft.rotation.z = -0.25;
scene.add(shaft);
}
// ---------------------------------------------------------------------
// World-space callout anchors
// ---------------------------------------------------------------------
function addAnchor(position) {
const object = new THREE.Object3D();
object.position.copy(position);
scene.add(object);
return object;
}
const calloutData = [
{
element: document.getElementById("label-plant"),
anchor: addAnchor(new THREE.Vector3(-1.3, 1.55, 1.68)),
offset: new THREE.Vector2(-118, -64),
color: "#80d66e"
},
{
element: document.getElementById("label-flower"),
anchor: addAnchor(new THREE.Vector3(1.05, 2.35, 1.75)),
offset: new THREE.Vector2(102, -34),
color: "#e6b6de"
},
{
element: document.getElementById("label-rhizome"),
anchor: addAnchor(new THREE.Vector3(0.45, -0.25, 2.31)),
offset: new THREE.Vector2(108, 38),
color: "#d8b46c"
},
{
element: document.getElementById("label-roots"),
anchor: addAnchor(new THREE.Vector3(-2.35, -1.4, 2.33)),
offset: new THREE.Vector2(-112, 20),
color: "#e1c99b"
},
{
element: document.getElementById("label-algae"),
anchor: addAnchor(new THREE.Vector3(4.85, 0.72, 1.15)),
offset: new THREE.Vector2(102, -20),
color: "#a69b48"
}
];
const svg = document.getElementById("leaders");
for (const item of calloutData) {
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("stroke", item.color);
svg.appendChild(line);
item.line = line;
}
const projected = new THREE.Vector3();
const worldPosition = new THREE.Vector3();
function updateCallouts() {
const width = innerWidth;
const height = innerHeight;
for (const item of calloutData) {
item.anchor.getWorldPosition(worldPosition);
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
item.element.style.opacity = visible ? "1" : "0";
item.line.style.opacity = visible ? "0.68" : "0";
if (!visible) continue;
const screenX = (projected.x * 0.5 + 0.5) * width;
const screenY = (-projected.y * 0.5 + 0.5) * height;
const labelX = screenX + item.offset.x;
const labelY = screenY + item.offset.y;
item.element.style.left = `${labelX}px`;
item.element.style.top = `${labelY}px`;
item.line.setAttribute("x1", screenX);
item.line.setAttribute("y1", screenY);
item.line.setAttribute("x2", labelX);
item.line.setAttribute("y2", labelY);
}
}
// ---------------------------------------------------------------------
// Custom camera controls: orbit, pinch zoom, wheel zoom, and reset
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, -0.55, -0.15);
const defaultCamera = {
theta: 0.65,
phi: 1.16,
radius: 15.4
};
let theta = defaultCamera.theta;
let phi = defaultCamera.phi;
let radius = defaultCamera.radius;
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
theta = defaultCamera.theta;
phi = defaultCamera.phi;
radius = defaultCamera.radius;
updateCamera();
}
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
theta -= deltaX * 0.006;
phi -= deltaY * 0.005;
phi = THREE.MathUtils.clamp(phi, 0.35, 1.48);
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
radius *= previousPinchDistance / distance;
radius = THREE.MathUtils.clamp(radius, 7.5, 24);
}
previousPinchDistance = distance;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius *= Math.exp(event.deltaY * 0.001);
radius = THREE.MathUtils.clamp(radius, 7.5, 24);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
updateCamera();
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
svg.setAttribute("width", innerWidth);
svg.setAttribute("height", innerHeight);
}
addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const shoot of shootGroups) {
shoot.group.rotation.z =
Math.sin(elapsed * 0.72 + shoot.phase) * shoot.amplitude;
shoot.group.rotation.x =
Math.cos(elapsed * 0.58 + shoot.phase) * shoot.amplitude * 0.55;
}
for (const algae of algaeGroups) {
algae.group.rotation.z =
Math.sin(elapsed * 0.83 + algae.phase) * algae.amplitude;
algae.group.rotation.x =
Math.cos(elapsed * 0.61 + algae.phase) * algae.amplitude * 0.55;
algae.group.position.y +=
Math.sin(elapsed * 0.7 + algae.phase) * 0.00055;
}
particles.rotation.y = elapsed * 0.008;
particles.position.y = Math.sin(elapsed * 0.15) * 0.09;
updateCallouts();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```