Prompt specification
Build or customize the Three.js 3D scene "Mangrove propagule anchoring section" 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: Mangrove propagule anchoring section
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mangrove-propagule-anchoring-section-x0749
Scene Description Prompt:
Show a stylized mangrove propagule anchored in sediment beside a seedling and tide line, using a verified species form. Three.js from cdnjs, one HTML file.
Working Three.js Starter (mangrove-propagule-anchoring-section-x0749):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Rhizophora mangle — Mangrove Propagule Study</title>
<style>
:root {
--ink: #17342f;
--muted: #55716a;
--paper: rgba(246, 249, 243, 0.84);
--line: rgba(31, 69, 59, 0.16);
--accent: #b56a3c;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e1;
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%;
cursor: grab;
touch-action: none;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 28px;
left: 30px;
width: min(390px, calc(100vw - 60px));
padding: 19px 22px 18px;
border: 1px solid rgba(255,255,255,0.7);
border-radius: 17px;
background: var(--paper);
box-shadow: 0 16px 45px rgba(35, 70, 59, 0.12);
backdrop-filter: blur(13px);
}
.eyebrow {
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3.4vw, 39px);
font-style: italic;
font-weight: 500;
letter-spacing: -0.035em;
line-height: 1;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 13px;
}
.badge {
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255,255,255,0.36);
color: #38584f;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.morphology {
position: absolute;
left: 30px;
bottom: 28px;
width: min(530px, calc(100vw - 60px));
padding: 15px 18px;
border: 1px solid rgba(255,255,255,0.68);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(35, 70, 59, 0.1);
backdrop-filter: blur(13px);
}
.morphology-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.verified-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #4b8064;
box-shadow: 0 0 0 4px rgba(75,128,100,0.12);
}
.traits {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 15px;
}
.trait {
padding-right: 13px;
border-right: 1px solid var(--line);
}
.trait:last-child {
padding-right: 0;
border-right: 0;
}
.trait strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
font-weight: 750;
}
.trait span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.controls {
position: absolute;
top: 28px;
right: 30px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.control-button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(255,255,255,0.72);
border-radius: 999px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 25px rgba(35, 70, 59, 0.1);
backdrop-filter: blur(12px);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
.control-button:hover {
background: rgba(255,255,255,0.96);
}
.hint {
position: absolute;
right: 31px;
bottom: 31px;
color: rgba(25, 58, 50, 0.68);
font-size: 10px;
letter-spacing: 0.04em;
text-align: right;
}
.label {
position: absolute;
padding: 6px 9px;
border: 1px solid rgba(255,255,255,0.75);
border-radius: 8px;
background: rgba(248, 250, 246, 0.86);
box-shadow: 0 6px 18px rgba(30, 66, 56, 0.1);
color: #315249;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.075em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 120ms linear;
}
.label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 18px;
background: linear-gradient(rgba(42,83,71,0.55), rgba(42,83,71,0));
}
.label::before {
content: "";
position: absolute;
top: calc(100% + 16px);
left: calc(50% - 3px);
width: 6px;
height: 6px;
border: 1px solid rgba(42,83,71,0.72);
border-radius: 50%;
background: rgba(248,250,246,0.85);
}
@media (max-width: 720px) {
.title-card {
top: 15px;
left: 15px;
width: calc(100vw - 30px);
padding: 15px 17px;
}
h1 { font-size: 28px; }
.subtitle { font-size: 11px; }
.morphology {
left: 15px;
bottom: 15px;
width: calc(100vw - 30px);
padding: 12px 14px;
}
.traits {
grid-template-columns: 1fr;
gap: 5px;
}
.trait {
padding: 0;
border: 0;
}
.trait:nth-child(n+2) { display: none; }
.controls {
top: 130px;
right: 15px;
}
.hint { display: none; }
.label { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Field plate 01 · mangrove establishment</div>
<h1>Rhizophora mangle</h1>
<p class="subtitle">
Red mangrove — a viviparous propagule anchored at the sediment surface,
beside an emerging seedling and the recent tidal swash line.
</p>
<div class="badges">
<span class="badge">Viviparous propagule</span>
<span class="badge">Pencil-form hypocotyl</span>
<span class="badge">Prop-rooted seedling</span>
</div>
</section>
<section class="morphology">
<div class="morphology-title">
<span class="verified-dot"></span>
Verified species form
</div>
<div class="traits">
<div class="trait">
<strong>Elongate hypocotyl</strong>
<span>Green-brown, cylindrical and pencil-like rather than a broad seed.</span>
</div>
<div class="trait">
<strong>Diagnostic ends</strong>
<span>Tapered radicle tip below; swollen cotyledonary crown above.</span>
</div>
<div class="trait">
<strong>Seedling characters</strong>
<span>Opposite, entire leaves with arching prop roots entering sediment.</span>
</div>
</div>
</section>
<div class="controls">
<button class="control-button" id="reset" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · scroll to zoom · double-click to reset</div>
<div class="label" id="label-cotyledon">Swollen cotyledonary end</div>
<div class="label" id="label-radicle">Tapered radicle · anchored</div>
<div class="label" id="label-tide">Tidal swash line</div>
</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 and camera */
/* -------------------------------------------------------------------------- */
const mount = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional study of a red mangrove propagule and seedling"
);
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce8e1");
scene.fog = new THREE.Fog("#dce8e1", 8.5, 17);
const camera = new THREE.PerspectiveCamera(
34,
window.innerWidth / window.innerHeight,
0.1,
40
);
const cameraTarget = new THREE.Vector3(0.1, 1.02, 0.15);
const initialView = {
azimuth: 0.54,
polar: 1.17,
radius: 7.1
};
const desiredView = { ...initialView };
const currentView = { ...initialView };
function updateCamera() {
const { azimuth, polar, radius } = currentView;
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + radius * sinPolar * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
/* -------------------------------------------------------------------------- */
/* Lighting */
/* -------------------------------------------------------------------------- */
const hemisphere = new THREE.HemisphereLight("#eff8ee", "#665e4d", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff3d8", 3.2);
sun.position.set(-4.5, 8.5, 5.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -6;
sun.shadow.camera.right = 6;
sun.shadow.camera.top = 6;
sun.shadow.camera.bottom = -6;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 18;
sun.shadow.bias = -0.0005;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#a9ced0", 1.05);
fill.position.set(5, 3, -4);
scene.add(fill);
/* -------------------------------------------------------------------------- */
/* Deterministic helpers */
/* -------------------------------------------------------------------------- */
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
const random = seededRandom(27041);
function hash2(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453;
return value - Math.floor(value);
}
function mix(a, b, t) {
return a + (b - a) * t;
}
function edgeZ(x) {
return (
0.58 +
0.13 * Math.sin(x * 1.16) +
0.055 * Math.sin(x * 2.75 + 0.7)
);
}
/* -------------------------------------------------------------------------- */
/* Sediment */
/* -------------------------------------------------------------------------- */
const groundGeometry = new THREE.PlaneGeometry(18, 12, 90, 60);
groundGeometry.rotateX(-Math.PI / 2);
const groundPosition = groundGeometry.attributes.position;
const groundColors = [];
const sedimentDark = new THREE.Color("#655e52");
const sedimentLight = new THREE.Color("#928573");
const sedimentGreen = new THREE.Color("#737a68");
for (let i = 0; i < groundPosition.count; i++) {
const x = groundPosition.getX(i);
const z = groundPosition.getZ(i);
const broad = Math.sin(x * 0.64 + z * 0.21) * 0.5 + 0.5;
const small = Math.sin(x * 2.1 - z * 1.6) * 0.5 + 0.5;
const y =
0.024 +
0.034 * Math.sin(x * 0.7) * Math.sin(z * 0.82) +
0.012 * Math.cos(x * 2.0 + z * 1.3);
groundPosition.setY(i, y);
const color = sedimentDark.clone().lerp(sedimentLight, broad * 0.62);
color.lerp(sedimentGreen, Math.max(0, z + 1.0) * 0.025);
color.multiplyScalar(0.91 + small * 0.13);
groundColors.push(color.r, color.g, color.b);
}
groundGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(groundColors, 3)
);
groundGeometry.computeVertexNormals();
const ground = new THREE.Mesh(
groundGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.98,
metalness: 0
})
);
ground.receiveShadow = true;
scene.add(ground);
/* -------------------------------------------------------------------------- */
/* Water and tide line */
/* -------------------------------------------------------------------------- */
function makeWaterGeometry() {
const columns = 90;
const rows = 18;
const positions = [];
const colors = [];
const indices = [];
const shallow = new THREE.Color("#87b4ad");
const deep = new THREE.Color("#427e79");
for (let row = 0; row <= rows; row++) {
const t = row / rows;
for (let column = 0; column <= columns; column++) {
const x = mix(-9, 9, column / columns);
const back = edgeZ(x);
const z = mix(back, 6.2, t);
const y =
0.104 +
0.008 * Math.sin(x * 1.7 + t * 4.1) +
0.004 * Math.cos(z * 2.3 - x * 0.7);
positions.push(x, y, z);
const color = shallow.clone().lerp(deep, Math.pow(t, 0.72));
color.multiplyScalar(0.96 + 0.06 * hash2(x, z));
colors.push(color.r, color.g, color.b);
}
}
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const a = row * (columns + 1) + column;
const b = a + columns + 1;
const c = b + 1;
const d = a + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const water = new THREE.Mesh(
makeWaterGeometry(),
new THREE.MeshPhysicalMaterial({
vertexColors: true,
transparent: true,
opacity: 0.57,
roughness: 0.22,
metalness: 0.03,
clearcoat: 0.85,
clearcoatRoughness: 0.18,
depthWrite: false,
side: THREE.DoubleSide
})
);
water.receiveShadow = true;
scene.add(water);
function makeRibbon(frontOffset, backOffset, material) {
const positions = [];
const indices = [];
const segments = 120;
for (let i = 0; i <= segments; i++) {
const x = mix(-9, 9, i / segments);
const edge = edgeZ(x);
const y = 0.128;
positions.push(x, y, edge + backOffset);
positions.push(x, y, edge + frontOffset);
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
makeRibbon(
0.17,
-0.015,
new THREE.MeshStandardMaterial({
color: "#315f59",
transparent: true,
opacity: 0.63,
roughness: 0.72,
depthWrite: false,
side: THREE.DoubleSide
})
);
makeRibbon(
-0.015,
-0.36,
new THREE.MeshStandardMaterial({
color: "#3f5148",
transparent: true,
opacity: 0.16,
roughness: 0.66,
depthWrite: false,
side: THREE.DoubleSide
})
);
/* Foam fragments along the tide line. */
const foamGeometry = new THREE.SphereGeometry(0.035, 7, 5);
const foamMaterial = new THREE.MeshStandardMaterial({
color: "#e7eee4",
transparent: true,
opacity: 0.72,
roughness: 0.8,
depthWrite: false
});
const foam = new THREE.InstancedMesh(foamGeometry, foamMaterial, 70);
const foamDummy = new THREE.Object3D();
for (let i = 0; i < 70; i++) {
const x = mix(-7.8, 7.8, random());
const z = edgeZ(x) + mix(-0.025, 0.14, random());
foamDummy.position.set(x, 0.139 + random() * 0.008, z);
foamDummy.scale.set(
mix(0.45, 1.8, random()),
mix(0.22, 0.5, random()),
mix(0.4, 1.25, random())
);
foamDummy.rotation.set(0, random() * Math.PI, 0);
foamDummy.updateMatrix();
foam.setMatrixAt(i, foamDummy.matrix);
}
foam.instanceMatrix.needsUpdate = true;
scene.add(foam);
/* A few pale, curved tidal ripples. */
const rippleMaterial = new THREE.LineBasicMaterial({
color: "#dcebe2",
transparent: true,
opacity: 0.26
});
for (let i = 0; i < 8; i++) {
const points = [];
const startX = mix(-7.5, 5.5, random());
const startZ = mix(1.0, 4.8, random());
const length = mix(0.8, 2.6, random());
for (let j = 0; j <= 20; j++) {
const t = j / 20;
points.push(
new THREE.Vector3(
startX + t * length,
0.123 + Math.sin(t * Math.PI) * 0.004,
startZ + Math.sin(t * Math.PI * 1.3) * 0.13
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
scene.add(new THREE.Line(geometry, rippleMaterial));
}
/* -------------------------------------------------------------------------- */
/* Organic tube builder */
/* -------------------------------------------------------------------------- */
function createOrganicTube({
curve,
segments = 48,
radialSegments = 12,
radius,
color,
roughness = 0.74
}) {
const frames = curve.computeFrenetFrames(segments, false);
const positions = [];
const colors = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const center = curve.getPoint(t);
const normal = frames.normals[i];
const binormal = frames.binormals[i];
const r = radius(t);
for (let j = 0; j <= radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const offset = normal.clone().multiplyScalar(cos * r);
offset.addScaledVector(binormal, sin * r);
positions.push(
center.x + offset.x,
center.y + offset.y,
center.z + offset.z
);
const vertexColor = color(t, angle, center);
colors.push(vertexColor.r, vertexColor.g, vertexColor.b);
}
}
for (let i = 0; i < segments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * (radialSegments + 1) + j;
const b = a + radialSegments + 1;
indices.push(a, b, a + 1, b, b + 1, a + 1);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness,
metalness: 0
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
/* -------------------------------------------------------------------------- */
/* Anchored R. mangle propagule */
/* -------------------------------------------------------------------------- */
const propaguleCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.72, -0.035, -0.18),
new THREE.Vector3(-0.70, 0.28, -0.17),
new THREE.Vector3(-0.63, 0.82, -0.13),
new THREE.Vector3(-0.54, 1.42, -0.08),
new THREE.Vector3(-0.49, 1.98, -0.025),
new THREE.Vector3(-0.47, 2.48, 0.02)
]);
const propaguleBottom = new THREE.Color("#4f4131");
const propaguleMiddle = new THREE.Color("#65764b");
const propaguleTop = new THREE.Color("#807044");
const propaguleWarm = new THREE.Color("#968052");
const propagule = createOrganicTube({
curve: propaguleCurve,
segments: 72,
radialSegments: 14,
radius(t) {
if (t < 0.16) {
return mix(0.022, 0.103, Math.pow(t / 0.16, 0.72));
}
if (t < 0.84) {
return mix(0.103, 0.112, (t - 0.16) / 0.68);
}
return mix(0.112, 0.15, (t - 0.84) / 0.16);
},
color(t, angle) {
const base = new THREE.Color();
if (t < 0.16) {
base.copy(propaguleBottom).lerp(propaguleMiddle, t / 0.16);
} else if (t < 0.82) {
base.copy(propaguleMiddle);
} else {
base
.copy(propaguleMiddle)
.lerp(propaguleTop, (t - 0.82) / 0.18);
}
const longitudinal = Math.sin(angle * 5 + t * 2.4) * 0.022;
base.offsetHSL(0, 0, longitudinal);
if (t > 0.93) {
base.lerp(propaguleWarm, (t - 0.93) / 0.07);
}
return base;
},
roughness: 0.78
});
scene.add(propagule);
/* Swollen, folded cotyledonary crown. */
const crown = new THREE.Group();
crown.position.copy(propaguleCurve.getPoint(1));
scene.add(crown);
const crownMaterial = new THREE.MeshStandardMaterial({
color: "#7d7042",
roughness: 0.68
});
for (const side of [-1, 1]) {
const lobe = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 18, 12),
crownMaterial
);
lobe.scale.set(0.72, 1.45, 0.72);
lobe.position.set(side * 0.055, 0.105, 0);
lobe.rotation.z = side * -0.22;
lobe.castShadow = true;
crown.add(lobe);
}
const crownSeam = new THREE.Mesh(
new THREE.SphereGeometry(0.028, 10, 8),
new THREE.MeshStandardMaterial({ color: "#4f4a2d", roughness: 0.8 })
);
crownSeam.scale.set(0.45, 2.1, 0.6);
crownSeam.position.set(0, 0.11, 0.103);
crown.add(crownSeam);
/* A small primary root entering the sediment at the tapered end. */
const rootCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.72, 0.035, -0.18),
new THREE.Vector3(-0.79, 0.025, -0.24),
new THREE.Vector3(-0.87, 0.015, -0.30),
new THREE.Vector3(-0.98, -0.025, -0.35)
]);
const root = createOrganicTube({
curve: rootCurve,
segments: 24,
radialSegments: 8,
radius: t => mix(0.025, 0.009, t),
color: () => new THREE.Color("#b7aa87"),
roughness: 0.9
});
scene.add(root);
/* Mud collar and contact shadow. */
const mudCollar = new THREE.Mesh(
new THREE.SphereGeometry(0.18, 20, 10),
new THREE.MeshStandardMaterial({
color: "#5d5547",
roughness: 1,
transparent: true,
opacity: 0.84
})
);
mudCollar.scale.set(1, 0.16, 0.8);
mudCollar.position.set(-0.72, 0.047, -0.18);
mudCollar.receiveShadow = true;
scene.add(mudCollar);
const propaguleShadow = new THREE.Mesh(
new THREE.CircleGeometry(0.43, 40),
new THREE.MeshBasicMaterial({
color: "#28372e",
transparent: true,
opacity: 0.11,
depthWrite: false
})
);
propaguleShadow.rotation.x = -Math.PI / 2;
propaguleShadow.scale.set(1.15, 0.62, 1);
propaguleShadow.position.set(-0.72, 0.069, -0.18);
scene.add(propaguleShadow);
/* -------------------------------------------------------------------------- */
/* Leaf geometry */
/* -------------------------------------------------------------------------- */
function leafPoint(t, u, length, width) {
const halfWidth =
width *
0.5 *
Math.pow(Math.sin(Math.PI * t), 0.72) *
(1 - 0.06 * t);
const x = u * halfWidth;
const y = length * t;
const z =
length * 0.055 * Math.sin(Math.PI * t) * (1 - u * u) +
length * 0.035 * t * t;
return new THREE.Vector3(x, y, z);
}
function createLeaf(length, width, color) {
const rows = 18;
const columns = 6;
const positions = [];
const indices = [];
for (let row = 0; row <= rows; row++) {
const t = row / rows;
for (let column = 0; column <= columns; column++) {
const u = mix(-1, 1, column / columns);
const point = leafPoint(t, u, length, width);
positions.push(point.x, point.y, point.z);
}
}
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const a = row * (columns + 1) + column;
const b = a + columns + 1;
indices.push(a, b, a + 1, b, b + 1, a + 1);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color,
roughness: 0.48,
metalness: 0.01,
side: THREE.DoubleSide
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
const group = new THREE.Group();
group.add(mesh);
const veinPoints = [];
for (let i = 0; i <= 18; i++) {
const t = i / 18;
const point = leafPoint(t, 0, length, width);
point.z += 0.004;
veinPoints.push(point);
}
const vein = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(veinPoints),
new THREE.LineBasicMaterial({
color: "#aebd78",
transparent: true,
opacity: 0.82
})
);
group.add(vein);
return group;
}
/* -------------------------------------------------------------------------- */
/* Seedling */
/* -------------------------------------------------------------------------- */
const seedlingCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.02, -0.025, -0.55),
new THREE.Vector3(1.03, 0.38, -0.53),
new THREE.Vector3(1.00, 0.83, -0.49),
new THREE.Vector3(1.05, 1.22, -0.46),
new THREE.Vector3(1.08, 1.49, -0.44)
]);
const seedlingStem = createOrganicTube({
curve: seedlingCurve,
segments: 44,
radialSegments: 10,
radius: t => mix(0.051, 0.026, t),
color: t => {
const color = new THREE.Color("#596b43");
if (t < 0.2) color.lerp(new THREE.Color("#79664a"), 0.7);
return color;
},
roughness: 0.76
});
scene.add(seedlingStem);
/* Characteristic arching prop roots. */
const propRootPaths = [
[
new THREE.Vector3(1.02, 0.30, -0.54),
new THREE.Vector3(1.27, 0.22, -0.40),
new THREE.Vector3(1.49, 0.07, -0.27),
new THREE.Vector3(1.56, 0.015, -0.18)
],
[
new THREE.Vector3(1.03, 0.23, -0.54),
new THREE.Vector3(0.84, 0.16, -0.40),
new THREE.Vector3(0.68, 0.04, -0.30),
new THREE.Vector3(0.61, -0.02, -0.22)
],
[
new THREE.Vector3(1.04, 0.43, -0.52),
new THREE.Vector3(1.36, 0.38, -0.67),
new THREE.Vector3(1.62, 0.16, -0.73),
new THREE.Vector3(1.72, 0.01, -0.74)
]
];
for (const path of propRootPaths) {
const curve = new THREE.CatmullRomCurve3(path);
const propRoot = createOrganicTube({
curve,
segments: 32,
radialSegments: 8,
radius: t => mix(0.024, 0.010, t),
color: t => new THREE.Color("#6e6847").lerp(new THREE.Color("#8e8968"), t),
roughness: 0.88
});
scene.add(propRoot);
}
const lowerLeafPosition = seedlingCurve.getPoint(0.83);
const upperLeafPosition = seedlingCurve.getPoint(0.995);
const leafPairs = [
{
position: lowerLeafPosition,
length: 0.49,
width: 0.19,
color: "#315c43",
spread: 1.03,
roll: 0.22
},
{
position: upperLeafPosition,
length: 0.43,
width: 0.17,
color: "#3d6b4b",
spread: 0.84,
roll: -0.20
}
];
for (const pair of leafPairs) {
for (const side of [-1, 1]) {
const leaf = createLeaf(pair.length, pair.width, pair.color);
leaf.position.copy(pair.position);
leaf.rotation.set(
pair.roll + side * 0.08,
side * 0.16,
side * pair.spread
);
scene.add(leaf);
}
}
/* Small terminal shoot bud. */
const bud = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 12, 9),
new THREE.MeshStandardMaterial({
color: "#627549",
roughness: 0.7
})
);
bud.scale.set(0.65, 1.5, 0.65);
bud.position.set(1.08, 1.53, -0.44);
bud.castShadow = true;
scene.add(bud);
/* -------------------------------------------------------------------------- */
/* Sediment details, wrack and pebbles */
/* -------------------------------------------------------------------------- */
const pebbleGeometry = new THREE.DodecahedronGeometry(0.055, 0);
const pebbleMaterial = new THREE.MeshStandardMaterial({
color: "#81796b",
roughness: 0.96
});
const pebbles = new THREE.InstancedMesh(pebbleGeometry, pebbleMaterial, 54);
const pebbleDummy = new THREE.Object3D();
for (let i = 0; i < 54; i++) {
let x = mix(-7.5, 7.5, random());
let z = mix(-4.0, 5.5, random());
if (Math.abs(x + 0.7) < 0.7 && Math.abs(z + 0.2) < 0.7) {
x += 1.4;
}
if (Math.abs(x - 1.0) < 0.55 && Math.abs(z + 0.5) < 0.55) {
x += 1.0;
}
const scale = mix(0.35, 1.2, random());
pebbleDummy.position.set(x, 0.066, z);
pebbleDummy.scale.set(scale, scale * mix(0.35, 0.72, random()), scale);
pebbleDummy.rotation.set(random(), random() * Math.PI, random());
pebbleDummy.updateMatrix();
pebbles.setMatrixAt(i, pebbleDummy.matrix);
}
pebbles.instanceMatrix.needsUpdate = true;
pebbles.castShadow = true;
pebbles.receiveShadow = true;
scene.add(pebbles);
/* Small brown leaf fragments in the wrack line. */
const wrackMaterial = new THREE.MeshStandardMaterial({
color: "#735238",
roughness: 1,
side: THREE.DoubleSide
});
for (let i = 0; i < 13; i++) {
const x = mix(-6.8, 6.8, random());
const z = edgeZ(x) - mix(0.05, 0.28, random());
const fragment = createLeaf(
mix(0.13, 0.28, random()),
mix(0.045, 0.09, random()),
wrackMaterial.color
);
fragment.rotation.set(
mix(-0.15, 0.15, random()),
random() * Math.PI,
mix(-0.2, 0.2, random())
);
fragment.position.set(x, 0.137, z);
scene.add(fragment);
}
/* -------------------------------------------------------------------------- */
/* Screen-space labels */
/* -------------------------------------------------------------------------- */
const labelDefinitions = [
{
element: document.getElementById("label-cotyledon"),
position: new THREE.Vector3(-0.47, 2.68, 0.03)
},
{
element: document.getElementById("label-radicle"),
position: new THREE.Vector3(-0.72, 0.18, -0.18)
},
{
element: document.getElementById("label-tide"),
position: new THREE.Vector3(2.55, 0.16, edgeZ(2.55))
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const definition of labelDefinitions) {
const projected = definition.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
definition.element.style.opacity = visible ? "1" : "0";
definition.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
definition.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
/* -------------------------------------------------------------------------- */
/* Direct camera controls — no addons */
/* -------------------------------------------------------------------------- */
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== pointerId) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredView.azimuth -= deltaX * 0.006;
desiredView.polar = THREE.MathUtils.clamp(
desiredView.polar + deltaY * 0.005,
0.56,
1.43
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
if (renderer.domElement.hasPointerCapture(pointerId)) {
renderer.domElement.releasePointerCapture(pointerId);
}
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius + event.deltaY * 0.0045,
4.3,
11.5
);
},
{ passive: false }
);
function resetView() {
desiredView.azimuth = initialView.azimuth;
desiredView.polar = initialView.polar;
desiredView.radius = initialView.radius;
}
document.getElementById("reset").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
/* -------------------------------------------------------------------------- */
/* Resize and render loop */
/* -------------------------------------------------------------------------- */
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
const smoothing = 1 - Math.pow(0.001, Math.min(clock.getDelta(), 0.05));
currentView.azimuth = THREE.MathUtils.lerp(
currentView.azimuth,
desiredView.azimuth,
smoothing
);
currentView.polar = THREE.MathUtils.lerp(
currentView.polar,
desiredView.polar,
smoothing
);
currentView.radius = THREE.MathUtils.lerp(
currentView.radius,
desiredView.radius,
smoothing
);
updateCamera();
updateLabels();
water.material.opacity = 0.55 + Math.sin(elapsed * 0.45) * 0.025;
rippleMaterial.opacity = 0.22 + Math.sin(elapsed * 0.7) * 0.055;
renderer.render(scene, camera);
});
</script>
</body>
</html>
```